LLVM  6.0.0svn
Macros | Functions | Variables
PeepholeOptimizer.cpp File Reference
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.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/MachineFunctionPass.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/MC/LaneBitmask.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Pass.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/TargetOpcodes.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...
 
static bool isVirtualRegisterOperand (MachineOperand &MO)
 Returns true if MO is a virtual register operand. 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"))
 
static cl::opt< unsignedMaxRecurrenceChain ("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

◆ DEBUG_TYPE

#define DEBUG_TYPE   "peephole-opt"

Definition at line 102 of file PeepholeOptimizer.cpp.

Function Documentation

◆ getCopyRewriter()

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

References assert(), llvm::MachineInstr::canFoldAsLoad(), llvm::MachineRegisterInfo::clearKillFlags(), llvm::SmallSet< T, N, C >::count(), llvm::dbgs(), DEBUG, llvm::tgtok::Def, DisableNAPhysCopyOpt, llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::erase(), llvm::MachineInstr::eraseFromParent(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::TargetInstrInfo::FoldImmediate(), llvm::MachineInstr::getDesc(), llvm::MCInstrDesc::getNumDefs(), llvm::MCInstrDesc::getNumOperands(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineOperand::getSubReg(), llvm::MachineRegisterInfo::hasOneNonDBGUse(), llvm::SmallSet< T, N, C >::insert(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::MachineRegisterInfo::isAllocatable(), llvm::MachineInstr::isBitcast(), llvm::MachineInstr::isCopy(), llvm::MachineOperand::isDead(), llvm::MachineOperand::isDef(), llvm::MachineInstr::isExtractSubregLike(), llvm::MachineOperand::isImplicit(), llvm::MachineInstr::isInsertSubregLike(), llvm::MachineInstr::isMoveImmediate(), llvm::TargetRegisterInfo::isPhysicalRegister(), llvm::MachineOperand::isReg(), llvm::MachineInstr::isRegSequenceLike(), llvm::TargetRegisterInfo::isVirtualRegister(), llvm_unreachable, llvm::MachineInstr::mayLoad(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::TargetInstrInfo::RegSubRegPair::Reg, llvm::MachineRegisterInfo::replaceRegWith(), SubReg, and llvm::TargetInstrInfo::RegSubRegPair::SubReg.

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( PeepholeOptimizer  ,
DEBUG_TYPE  ,
"Peephole Optimizations ,
false  ,
false   
)

◆ insertPHI()

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

References llvm::MachineInstrBuilder::addMBB(), llvm::MachineInstrBuilder::addReg(), assert(), llvm::BuildMI(), llvm::MachineRegisterInfo::clearKillFlags(), llvm::MachineRegisterInfo::createVirtualRegister(), llvm::dbgs(), DEBUG, llvm::SmallVectorBase::empty(), llvm::MCInstrInfo::get(), llvm::MachineInstr::getDebugLoc(), llvm::MachineInstr::getDesc(), llvm::MachineOperand::getMBB(), llvm::MCInstrDesc::getNumDefs(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getParent(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineOperand::getSubReg(), llvm::MachineInstr::isCopy(), llvm::MachineInstr::isExtractSubreg(), llvm::MachineInstr::isInsertSubreg(), llvm::TargetRegisterInfo::isPhysicalRegister(), llvm::MachineInstr::isRegSequence(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), MRI, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::TargetInstrInfo::RegSubRegPair::Reg, llvm::MachineRegisterInfo::replaceRegWith(), llvm::MachineOperand::setIsUndef(), llvm::MachineOperand::setReg(), llvm::MachineOperand::setSubReg(), llvm::TargetInstrInfo::RegSubRegPair::SubReg, and TII.

◆ isVirtualRegisterOperand()

static bool isVirtualRegisterOperand ( MachineOperand MO)
static

Returns true if MO is a virtual register operand.

Definition at line 1558 of file PeepholeOptimizer.cpp.

References Aggressive, assert(), llvm::MachineBasicBlock::begin(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::SmallSet< T, N, C >::clear(), llvm::MachineOperand::clobbersPhysReg(), llvm::TargetInstrInfo::CommuteAnyOperandIndex, llvm::TargetInstrInfo::commuteInstruction(), llvm::SmallSet< T, N, C >::count(), llvm::HexagonISD::CP, llvm::dbgs(), DEBUG, llvm::MachineRegisterInfo::def_begin(), DefMI, DisablePeephole, llvm::SmallSet< T, N, C >::empty(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::MachineBasicBlock::end(), llvm::SmallSet< T, N, C >::erase(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::erase(), llvm::SmallPtrSetImpl< PtrType >::erase(), llvm::MachineInstr::eraseFromParent(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::TargetInstrInfo::findCommutedOpIndices(), llvm::MachineInstr::findRegisterUseOperandIdx(), llvm::MachineInstr::getDesc(), llvm::TargetInstrInfo::getExtractSubregInputs(), llvm::MachineFunction::getFunction(), llvm::MachineOperand::getImm(), llvm::TargetInstrInfo::getInsertSubregInputs(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::MachineFunction::getName(), llvm::MCInstrDesc::getNumDefs(), llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOperand(), llvm::MachineRegisterInfo::defusechain_iterator< ReturnUses, ReturnDefs, SkipDebug, ByOperand, ByInstr, ByBundle >::getOperandNo(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineFunction::getRegInfo(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::TargetInstrInfo::getRegSequenceInputs(), llvm::MachineOperand::getSubReg(), llvm::TargetRegisterInfo::getSubRegIndexLaneMask(), llvm::MachineFunction::getSubtarget(), llvm::MachineRegisterInfo::getTargetRegisterInfo(), llvm::MachineRegisterInfo::getVRegDef(), llvm::MachineRegisterInfo::hasOneNonDBGUse(), llvm::MachineInstr::hasUnmodeledSideEffects(), llvm::SmallSet< T, N, C >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::MachineInstr::isBitcast(), llvm::MachineInstr::isCompare(), llvm::MachineInstr::isConditionalBranch(), llvm::MachineInstr::isCopy(), llvm::MachineOperand::isDead(), llvm::MachineInstr::isDebugValue(), llvm::MachineOperand::isDef(), llvm::MachineInstr::isExtractSubreg(), llvm::MachineInstr::isExtractSubregLike(), llvm::MachineOperand::isImplicit(), llvm::MachineInstr::isImplicitDef(), llvm::MachineInstr::isInlineAsm(), llvm::MachineInstr::isInsertSubreg(), llvm::MachineInstr::isInsertSubregLike(), llvm::MachineInstr::isKill(), llvm::MachineInstr::isLoadFoldBarrier(), llvm::MachineInstr::isPHI(), llvm::TargetRegisterInfo::isPhysicalRegister(), llvm::MachineInstr::isPosition(), llvm::MachineOperand::isReg(), llvm::MachineInstr::isRegSequence(), llvm::MachineInstr::isRegSequenceLike(), llvm::MachineInstr::isRegTiedToUseOperand(), llvm::MachineInstr::isSelect(), llvm::MachineInstr::isSubregToReg(), llvm::MCInstrDesc::isVariadic(), llvm::TargetRegisterInfo::isVirtualRegister(), llvm::MachineRegisterInfo::markUsesInDebugValueAsUndef(), MaxRecurrenceChain, MI, llvm::MachineInstr::operands(), llvm::TargetInstrInfo::optimizeLoadInstr(), llvm::TargetInstrInfo::RegSubRegPair::Reg, llvm::TargetInstrInfo::RegSubRegPairAndIdx::SubIdx, llvm::TargetInstrInfo::RegSubRegPair::SubReg, llvm::MachineRegisterInfo::use_instr_nodbg_begin(), llvm::MachineRegisterInfo::use_nodbg_instructions(), and UseMI.

◆ STATISTIC() [1/8]

STATISTIC ( NumReuse  ,
"Number of extension results reused"   
)

◆ STATISTIC() [2/8]

STATISTIC ( NumCmps  ,
"Number of compares eliminated"   
)

◆ STATISTIC() [3/8]

STATISTIC ( NumImmFold  ,
"Number of move immediate folded"   
)

◆ STATISTIC() [4/8]

STATISTIC ( NumLoadFold  ,
"Number of loads folded"   
)

◆ STATISTIC() [5/8]

STATISTIC ( NumSelects  ,
"Number of selects optimized"   
)

◆ STATISTIC() [6/8]

STATISTIC ( NumUncoalescableCopies  ,
"Number of uncoalescable copies optimized"   
)

◆ STATISTIC() [7/8]

STATISTIC ( NumRewrittenCopies  ,
"Number of copies rewritten"   
)

◆ STATISTIC() [8/8]

STATISTIC ( NumNAPhysCopies  ,
"Number of non-allocatable physical copies removed"   
)

Variable Documentation

◆ Aggressive

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

◆ DEBUG_TYPE

DEBUG_TYPE

Definition at line 482 of file PeepholeOptimizer.cpp.

◆ DisableAdvCopyOpt

cl::opt<bool> DisableAdvCopyOpt("disable-adv-copy-opt", cl::Hidden, cl::init(false), cl::desc("Disable advanced copy optimization"))
static

◆ DisableNAPhysCopyOpt

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

Referenced by getCopyRewriter().

◆ DisablePeephole

cl::opt<bool> DisablePeephole("disable-peephole", cl::Hidden, cl::init(false), cl::desc("Disable the peephole optimizer"))
static

◆ false

Peephole false

Definition at line 482 of file PeepholeOptimizer.cpp.

◆ MaxRecurrenceChain

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

◆ Optimizations

Peephole Optimizations

Definition at line 482 of file PeepholeOptimizer.cpp.

◆ RewritePHILimit

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