LLVM  5.0.0
Macros | Functions | Variables
PeepholeOptimizer.cpp File Reference
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <cassert>
#include <cstdint>
#include <memory>
#include <utility>
Include dependency graph for PeepholeOptimizer.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "peephole-opt"
 

Functions

 STATISTIC (NumReuse,"Number of extension results reused")
 
 STATISTIC (NumCmps,"Number of compares eliminated")
 
 STATISTIC (NumImmFold,"Number of move immediate folded")
 
 STATISTIC (NumLoadFold,"Number of loads folded")
 
 STATISTIC (NumSelects,"Number of selects optimized")
 
 STATISTIC (NumUncoalescableCopies,"Number of uncoalescable copies optimized")
 
 STATISTIC (NumRewrittenCopies,"Number of copies rewritten")
 
 STATISTIC (NumNAPhysCopies,"Number of non-allocatable physical copies removed")
 
 INITIALIZE_PASS_BEGIN (PeepholeOptimizer, DEBUG_TYPE,"Peephole Optimizations", false, false) INITIALIZE_PASS_END(PeepholeOptimizer
 
static MachineInstr * insertPHI (MachineRegisterInfo *MRI, const TargetInstrInfo *TII, const SmallVectorImpl< TargetInstrInfo::RegSubRegPair > &SrcRegs, MachineInstr *OrigPHI)
 Insert a PHI instruction with incoming edges SrcRegs that are guaranteed to have the same register class. More...
 
static CopyRewriter * getCopyRewriter (MachineInstr &MI, const TargetInstrInfo &TII, MachineRegisterInfo &MRI)
 Get the appropriated CopyRewriter for MI. More...
 
static bool isVirtualRegisterOperand (MachineOperand &MO)
 Returns true if MO is a virtual register operand. More...
 

Variables

static cl::opt< bool > Aggressive ("aggressive-ext-opt", cl::Hidden, cl::desc("Aggressive extension optimization"))
 
static cl::opt< bool > DisablePeephole ("disable-peephole", cl::Hidden, cl::init(false), cl::desc("Disable the peephole optimizer"))
 
static cl::opt< bool > DisableAdvCopyOpt ("disable-adv-copy-opt", cl::Hidden, cl::init(false), cl::desc("Disable advanced copy optimization"))
 
static cl::opt< bool > DisableNAPhysCopyOpt ("disable-non-allocatable-phys-copy-opt", cl::Hidden, cl::init(false), cl::desc("Disable non-allocatable physical register copy optimization"))
 
static cl::opt< unsigned > RewritePHILimit ("rewrite-phi-limit", cl::Hidden, cl::init(10), cl::desc("Limit the length of PHI chains to lookup"))
 
static cl::opt< unsigned > MaxRecurrenceChain ("recurrence-chain-limit", cl::Hidden, cl::init(3), cl::desc("Maximum length of recurrence chain when evaluating the benefit ""of commuting operands"))
 
 DEBUG_TYPE
 
Peephole Optimizations
 
Peephole false
 

Macro Definition Documentation

#define DEBUG_TYPE   "peephole-opt"

Definition at line 98 of file PeepholeOptimizer.cpp.

Function Documentation

static CopyRewriter* getCopyRewriter ( MachineInstr &  MI,
const TargetInstrInfo &  TII,
MachineRegisterInfo &  MRI 
)
static

Get the appropriated CopyRewriter for MI.

Returns
A pointer to a dynamically allocated CopyRewriter or nullptr if no rewriter works for MI.

Definition at line 1213 of file PeepholeOptimizer.cpp.

References llvm::MachineInstr::getOpcode(), llvm::MachineInstr::isBitcast(), llvm::MachineInstr::isExtractSubregLike(), llvm::MachineInstr::isInsertSubregLike(), llvm::MachineInstr::isRegSequenceLike(), and llvm_unreachable().

INITIALIZE_PASS_BEGIN ( PeepholeOptimizer  ,
DEBUG_TYPE  ,
"Peephole Optimizations"  ,
false  ,
false   
)
static MachineInstr* insertPHI ( MachineRegisterInfo *  MRI,
const TargetInstrInfo *  TII,
const SmallVectorImpl< TargetInstrInfo::RegSubRegPair > &  SrcRegs,
MachineInstr *  OrigPHI 
)
static

Insert a PHI instruction with incoming edges SrcRegs that are guaranteed to have the same register class.

This is necessary whenever we successfully traverse a PHI instruction and find suitable sources coming from its edges. By inserting a new PHI, we provide a rewritten PHI def suitable to be used in a new COPY instruction.

Definition at line 776 of file PeepholeOptimizer.cpp.

References llvm::MachineInstrBuilder::addMBB(), llvm::MachineInstrBuilder::addReg(), assert(), llvm::BuildMI(), llvm::MachineRegisterInfo::clearKillFlags(), llvm::MachineRegisterInfo::createVirtualRegister(), llvm::SmallVectorBase::empty(), llvm::MCInstrInfo::get(), llvm::MachineInstr::getDebugLoc(), llvm::MachineOperand::getMBB(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getParent(), and llvm::MachineRegisterInfo::getRegClass().

static bool isVirtualRegisterOperand ( MachineOperand &  MO)
static

Returns true if MO is a virtual register operand.

Definition at line 1538 of file PeepholeOptimizer.cpp.

References llvm::MachineOperand::getReg(), llvm::MachineOperand::isReg(), and llvm::TargetRegisterInfo::isVirtualRegister().

STATISTIC ( NumReuse  ,
"Number of extension results reused"   
)
STATISTIC ( NumCmps  ,
"Number of compares eliminated"   
)
STATISTIC ( NumImmFold  ,
"Number of move immediate folded"   
)
STATISTIC ( NumLoadFold  ,
"Number of loads folded"   
)
STATISTIC ( NumSelects  ,
"Number of selects optimized"   
)
STATISTIC ( NumUncoalescableCopies  ,
"Number of uncoalescable copies optimized"   
)
STATISTIC ( NumRewrittenCopies  ,
"Number of copies rewritten"   
)
STATISTIC ( NumNAPhysCopies  ,
"Number of non-allocatable physical copies removed"   
)

Variable Documentation

cl::opt<bool> Aggressive("aggressive-ext-opt", cl::Hidden, cl::desc("Aggressive extension optimization"))
static
DEBUG_TYPE

Definition at line 462 of file PeepholeOptimizer.cpp.

cl::opt<bool> DisableAdvCopyOpt("disable-adv-copy-opt", cl::Hidden, cl::init(false), cl::desc("Disable advanced copy optimization"))
static
cl::opt<bool> DisableNAPhysCopyOpt("disable-non-allocatable-phys-copy-opt", cl::Hidden, cl::init(false), cl::desc("Disable non-allocatable physical register copy optimization"))
static
cl::opt<bool> DisablePeephole("disable-peephole", cl::Hidden, cl::init(false), cl::desc("Disable the peephole optimizer"))
static
Peephole false

Definition at line 462 of file PeepholeOptimizer.cpp.

cl::opt<unsigned> MaxRecurrenceChain("recurrence-chain-limit", cl::Hidden, cl::init(3), cl::desc("Maximum length of recurrence chain when evaluating the benefit ""of commuting operands"))
static
Peephole Optimizations

Definition at line 462 of file PeepholeOptimizer.cpp.

cl::opt<unsigned> RewritePHILimit("rewrite-phi-limit", cl::Hidden, cl::init(10), cl::desc("Limit the length of PHI chains to lookup"))
static