LLVM  4.0.0
Macros | Functions | Variables
PeepholeOptimizer.cpp File Reference
#include "llvm/CodeGen/Passes.h"
#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/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.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 MachineInstrinsertPHI (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...
 

Variables

static cl::opt< boolAggressive ("aggressive-ext-opt", cl::Hidden, cl::desc("Aggressive extension optimization"))
 
static cl::opt< boolDisablePeephole ("disable-peephole", cl::Hidden, cl::init(false), cl::desc("Disable the peephole optimizer"))
 
static cl::opt< boolDisableAdvCopyOpt ("disable-adv-copy-opt", cl::Hidden, cl::init(false), cl::desc("Disable advanced copy optimization"))
 
static cl::opt< boolDisableNAPhysCopyOpt ("disable-non-allocatable-phys-copy-opt", cl::Hidden, cl::init(false), cl::desc("Disable non-allocatable physical register copy optimization"))
 
static cl::opt< unsignedRewritePHILimit ("rewrite-phi-limit", cl::Hidden, cl::init(10), cl::desc("Limit the length of PHI chains to lookup"))
 
 DEBUG_TYPE
 
Peephole Optimizations
 
Peephole false
 

Macro Definition Documentation

#define DEBUG_TYPE   "peephole-opt"

Definition at line 97 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 1166 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 729 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().

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 415 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 415 of file PeepholeOptimizer.cpp.

Peephole Optimizations

Definition at line 415 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