|
LLVM
4.0.0
|
#include "llvm/CodeGen/Passes.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/SmallSet.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/BlockFrequencyInfo.h"#include "llvm/Analysis/BranchProbabilityInfo.h"#include "llvm/Analysis/InstructionSimplify.h"#include "llvm/Analysis/LoopInfo.h"#include "llvm/Analysis/ProfileSummaryInfo.h"#include "llvm/Analysis/TargetLibraryInfo.h"#include "llvm/Analysis/TargetTransformInfo.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/Analysis/MemoryBuiltins.h"#include "llvm/CodeGen/Analysis.h"#include "llvm/IR/CallSite.h"#include "llvm/IR/Constants.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/Function.h"#include "llvm/IR/GetElementPtrTypeIterator.h"#include "llvm/IR/IRBuilder.h"#include "llvm/IR/InlineAsm.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/MDBuilder.h"#include "llvm/IR/PatternMatch.h"#include "llvm/IR/Statepoint.h"#include "llvm/IR/ValueHandle.h"#include "llvm/IR/ValueMap.h"#include "llvm/Pass.h"#include "llvm/Support/BranchProbability.h"#include "llvm/Support/CommandLine.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Target/TargetLowering.h"#include "llvm/Target/TargetSubtargetInfo.h"#include "llvm/Transforms/Utils/BasicBlockUtils.h"#include "llvm/Transforms/Utils/BuildLibCalls.h"#include "llvm/Transforms/Utils/BypassSlowDivision.h"#include "llvm/Transforms/Utils/Local.h"#include "llvm/Transforms/Utils/SimplifyLibCalls.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "codegenprepare" |
Functions | |
| STATISTIC (NumBlocksElim,"Number of blocks eliminated") | |
| STATISTIC (NumPHIsElim,"Number of trivial PHIs eliminated") | |
| STATISTIC (NumGEPsElim,"Number of GEPs converted to casts") | |
| STATISTIC (NumCmpUses,"Number of uses of Cmp expressions replaced with uses of ""sunken Cmps") | |
| STATISTIC (NumCastUses,"Number of uses of Cast expressions replaced with uses ""of sunken Casts") | |
| STATISTIC (NumMemoryInsts,"Number of memory instructions whose address ""computations were sunk") | |
| STATISTIC (NumExtsMoved,"Number of [s|z]ext instructions combined with loads") | |
| STATISTIC (NumExtUses,"Number of uses of [s|z]ext instructions optimized") | |
| STATISTIC (NumAndsAdded,"Number of and mask instructions added to form ext loads") | |
| STATISTIC (NumAndUses,"Number of uses of and mask instructions optimized") | |
| STATISTIC (NumRetsDup,"Number of return instructions duplicated") | |
| STATISTIC (NumDbgValueMoved,"Number of debug value instructions moved") | |
| STATISTIC (NumSelectsExpanded,"Number of selects turned into branches") | |
| STATISTIC (NumAndCmpsMoved,"Number of and/cmp's pushed into branches") | |
| STATISTIC (NumStoreExtractExposed,"Number of store(extractelement) exposed") | |
| INITIALIZE_TM_PASS_BEGIN (CodeGenPrepare,"codegenprepare","Optimize for code generation", false, false) INITIALIZE_TM_PASS_END(CodeGenPrepare | |
| static void | computeBaseDerivedRelocateMap (const SmallVectorImpl< GCRelocateInst * > &AllRelocateCalls, DenseMap< GCRelocateInst *, SmallVector< GCRelocateInst *, 2 >> &RelocateInstMap) |
| static bool | getGEPSmallConstantIntOffsetV (GetElementPtrInst *GEP, SmallVectorImpl< Value * > &OffsetV) |
| static bool | simplifyRelocatesOffABase (GCRelocateInst *RelocatedBase, const SmallVectorImpl< GCRelocateInst * > &Targets) |
| static bool | SinkCast (CastInst *CI) |
| SinkCast - Sink the specified cast instruction into its user blocks. More... | |
| static bool | OptimizeNoopCopyExpression (CastInst *CI, const TargetLowering &TLI, const DataLayout &DL) |
| If the specified cast instruction is a noop copy (e.g. More... | |
| static bool | CombineUAddWithOverflow (CmpInst *CI) |
| Try to combine CI into a call to the llvm.uadd.with.overflow intrinsic if possible. More... | |
| static bool | SinkCmpExpression (CmpInst *CI, const TargetLowering *TLI) |
| Sink the given CmpInst into user blocks to reduce the number of virtual registers that must be created and coalesced. More... | |
| static bool | OptimizeCmpExpression (CmpInst *CI, const TargetLowering *TLI) |
| static bool | isExtractBitsCandidateUse (Instruction *User) |
| Check if the candidates could be combined with a shift instruction, which includes: More... | |
| static bool | SinkShiftAndTruncate (BinaryOperator *ShiftI, Instruction *User, ConstantInt *CI, DenseMap< BasicBlock *, BinaryOperator * > &InsertedShifts, const TargetLowering &TLI, const DataLayout &DL) |
| Sink both shift and truncate instruction to the use of truncate's BB. More... | |
| static bool | OptimizeExtractBits (BinaryOperator *ShiftI, ConstantInt *CI, const TargetLowering &TLI, const DataLayout &DL) |
| Sink the shift right instruction into user blocks if the uses could potentially be combined with this shift instruction and generate BitExtract instruction. More... | |
| static void | scalarizeMaskedLoad (CallInst *CI) |
| static void | scalarizeMaskedStore (CallInst *CI) |
| static void | scalarizeMaskedGather (CallInst *CI) |
| static void | scalarizeMaskedScatter (CallInst *CI) |
| static bool | despeculateCountZeros (IntrinsicInst *CountZeros, const TargetLowering *TLI, const DataLayout *DL, bool &ModifiedDT) |
| If counting leading or trailing zeros is an expensive operation and a zero input is defined, add a check for zero to avoid calling the intrinsic. More... | |
| static bool | IsNonLocalValue (Value *V, BasicBlock *BB) |
| Return true if the specified values are defined in a different basic block than BB. More... | |
| static bool | hasSameExtUse (Instruction *Inst, const TargetLowering &TLI) |
Check if all the uses of Inst are equivalent (or free) zero or sign extensions. More... | |
Variables | |
| static cl::opt< bool > | DisableBranchOpts ("disable-cgp-branch-opts", cl::Hidden, cl::init(false), cl::desc("Disable branch optimizations in CodeGenPrepare")) |
| static cl::opt< bool > | DisableGCOpts ("disable-cgp-gc-opts", cl::Hidden, cl::init(false), cl::desc("Disable GC optimizations in CodeGenPrepare")) |
| static cl::opt< bool > | DisableSelectToBranch ("disable-cgp-select2branch", cl::Hidden, cl::init(false), cl::desc("Disable select to branch conversion.")) |
| static cl::opt< bool > | AddrSinkUsingGEPs ("addr-sink-using-gep", cl::Hidden, cl::init(false), cl::desc("Address sinking in CGP using GEPs.")) |
| static cl::opt< bool > | EnableAndCmpSinking ("enable-andcmp-sinking", cl::Hidden, cl::init(true), cl::desc("Enable sinkinig and/cmp into branches.")) |
| static cl::opt< bool > | DisableStoreExtract ("disable-cgp-store-extract", cl::Hidden, cl::init(false), cl::desc("Disable store(extract) optimizations in CodeGenPrepare")) |
| static cl::opt< bool > | StressStoreExtract ("stress-cgp-store-extract", cl::Hidden, cl::init(false), cl::desc("Stress test store(extract) optimizations in CodeGenPrepare")) |
| static cl::opt< bool > | DisableExtLdPromotion ("disable-cgp-ext-ld-promotion", cl::Hidden, cl::init(false), cl::desc("Disable ext(promotable(ld)) -> promoted(ext(ld)) optimization in ""CodeGenPrepare")) |
| static cl::opt< bool > | StressExtLdPromotion ("stress-cgp-ext-ld-promotion", cl::Hidden, cl::init(false), cl::desc("Stress test ext(promotable(ld)) -> promoted(ext(ld)) ""optimization in CodeGenPrepare")) |
| static cl::opt< bool > | DisablePreheaderProtect ("disable-preheader-prot", cl::Hidden, cl::init(false), cl::desc("Disable protection against removing loop preheaders")) |
| static cl::opt< bool > | ProfileGuidedSectionPrefix ("profile-guided-section-prefix", cl::Hidden, cl::init(true), cl::desc("Use profile info to add section prefix for hot/cold functions")) |
| static cl::opt< unsigned > | FreqRatioToSkipMerge ("cgp-freq-ratio-to-skip-merge", cl::Hidden, cl::init(2), cl::desc("Skip merging empty blocks if (frequency of empty block) / ""(frequency of destination block) is greater than this ratio")) |
| static cl::opt< bool > | ForceSplitStore ("force-split-store", cl::Hidden, cl::init(false), cl::desc("Force store splitting no matter what the target query says.")) |
| codegenprepare | |
| Optimize for code | generation |
| Optimize for code | false |
| #define DEBUG_TYPE "codegenprepare" |
Definition at line 61 of file CodeGenPrepare.cpp.
Try to combine CI into a call to the llvm.uadd.with.overflow intrinsic if possible.
Return true if any changes were made.
Definition at line 977 of file CodeGenPrepare.cpp.
References A, assert(), B, llvm::CallInst::Create(), llvm::ExtractValueInst::Create(), llvm::Instruction::eraseFromParent(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getModule(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_UAddWithOverflow(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Value::replaceAllUsesWith(), and llvm::Value::user_begin().
Referenced by OptimizeCmpExpression().
|
static |
Definition at line 689 of file CodeGenPrepare.cpp.
References I, and llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::insert().
|
static |
If counting leading or trailing zeros is an expensive operation and a zero input is defined, add a check for zero to avoid calling the intrinsic.
We want to transform: z = call i64 .cttz.i64(i64 A, i1 false)
into: entry: cmpz = icmp eq i64 A, 0 br i1 cmpz, label cond.end, label cond.false cond.false: z = call i64 .cttz.i64(i64 A, i1 true) br label cond.end cond.end: ctz = phi i64 [ 64, entry ], [ z, cond.false ]
If the transform is performed, return true and set ModifiedDT to true.
Definition at line 1811 of file CodeGenPrepare.cpp.
References llvm::PHINode::addIncoming(), llvm::Instruction::eraseFromParent(), llvm::BasicBlock::front(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::IntrinsicInst::getIntrinsicID(), llvm::DataLayout::getLargestLegalIntTypeSizeInBits(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Type::getPrimitiveSizeInBits(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::TargetLoweringBase::isCheapToSpeculateCtlz(), llvm::TargetLoweringBase::isCheapToSpeculateCttz(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_One(), llvm::PatternMatch::match(), llvm::Value::replaceAllUsesWith(), llvm::CallInst::setArgOperand(), llvm::IRBuilderBase::SetInsertPoint(), llvm::BasicBlock::splitBasicBlock(), and Zero.
|
static |
Definition at line 724 of file CodeGenPrepare.cpp.
References llvm::dyn_cast(), llvm::User::getNumOperands(), llvm::User::getOperand(), i, and llvm::SmallVectorTemplateBase< T, isPodLike >::push_back().
Referenced by simplifyRelocatesOffABase().
|
static |
Check if all the uses of Inst are equivalent (or free) zero or sign extensions.
Definition at line 4190 of file CodeGenPrepare.cpp.
References assert(), llvm::Type::getIntegerBitWidth(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::TargetLoweringBase::isZExtFree(), llvm::Value::use_empty(), llvm::Value::user_begin(), and llvm::Value::users().
| INITIALIZE_TM_PASS_BEGIN | ( | CodeGenPrepare | , |
| "codegenprepare" | , | ||
| "Optimize for code generation" | , | ||
| false | , | ||
| false | |||
| ) |
|
static |
Check if the candidates could be combined with a shift instruction, which includes:
Definition at line 1098 of file CodeGenPrepare.cpp.
References llvm::APIntOps::And(), llvm::Instruction::getOpcode(), and llvm::User::getOperand().
Referenced by OptimizeExtractBits().
|
static |
Return true if the specified values are defined in a different basic block than BB.
Definition at line 3804 of file CodeGenPrepare.cpp.
References llvm::Instruction::getParent().
|
static |
Definition at line 1083 of file CodeGenPrepare.cpp.
References CombineUAddWithOverflow(), and SinkCmpExpression().
|
static |
Sink the shift right instruction into user blocks if the uses could potentially be combined with this shift instruction and generate BitExtract instruction.
It will only be applied if the architecture supports BitExtract instruction. Here is an example: BB1: x.extract.shift = lshr i64 arg1, 32 BB2: x.extract.trunc = trunc i64 x.extract.shift to i16 ==>
BB2: x.extract.shift.1 = lshr i64 arg1, 32 x.extract.trunc = trunc i64 x.extract.shift.1 to i16
CodeGen will recoginze the pattern in BB2 and generate BitExtract instruction. Return true if any changes are made.
Only insert instructions in each block once.
Definition at line 1201 of file CodeGenPrepare.cpp.
References assert(), E, llvm::BasicBlock::end(), llvm::Instruction::eraseFromParent(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::TargetLoweringBase::getValueType(), isExtractBitsCandidateUse(), llvm::TargetLoweringBase::isTypeLegal(), SinkShiftAndTruncate(), llvm::Value::use_empty(), llvm::Value::user_begin(), and llvm::Value::user_end().
|
static |
If the specified cast instruction is a noop copy (e.g.
it's casting from one pointer type to another, i32->i8 on PPC), sink it into user blocks to reduce the number of virtual registers that must be created and coalesced.
Return true if any changes are made.
Definition at line 934 of file CodeGenPrepare.cpp.
References llvm::EVT::bitsLT(), llvm::Value::getContext(), llvm::User::getOperand(), llvm::Value::getType(), llvm::TargetLoweringBase::getTypeAction(), llvm::TargetLoweringBase::getTypeToTransformTo(), llvm::TargetLoweringBase::getValueType(), llvm::TargetLoweringBase::isCheapAddrSpaceCast(), llvm::EVT::isInteger(), SinkCast(), and llvm::TargetLoweringBase::TypePromoteInteger.
|
static |
Definition at line 1581 of file CodeGenPrepare.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::BranchInst::Create(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::CallInst::getArgOperand(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::SequentialType::getNumElements(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::SPII::Load, llvm::BitmaskEnumDetail::Mask(), Ptr, llvm::Value::replaceAllUsesWith(), and llvm::BasicBlock::splitBasicBlock().
|
static |
Definition at line 1316 of file CodeGenPrepare.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::BranchInst::Create(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::CallInst::getArgOperand(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::SequentialType::getNumElements(), llvm::Instruction::getParent(), llvm::Type::getPointerTo(), llvm::Type::getScalarSizeInBits(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Type::getVectorElementType(), llvm::CmpInst::ICMP_EQ, llvm::SPII::Load, llvm::BitmaskEnumDetail::Mask(), fuzzer::min(), Ptr, llvm::Value::replaceAllUsesWith(), and llvm::BasicBlock::splitBasicBlock().
|
static |
Definition at line 1716 of file CodeGenPrepare.cpp.
References assert(), llvm::BranchInst::Create(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::CallInst::getArgOperand(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Type::getVectorElementType(), llvm::Type::getVectorNumElements(), llvm::CmpInst::ICMP_EQ, llvm::BitmaskEnumDetail::Mask(), Ptr, and llvm::BasicBlock::splitBasicBlock().
|
static |
Definition at line 1462 of file CodeGenPrepare.cpp.
References assert(), llvm::BranchInst::Create(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::CallInst::getArgOperand(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::SequentialType::getElementType(), llvm::SequentialType::getNumElements(), llvm::Instruction::getParent(), llvm::Type::getPointerTo(), llvm::Type::getScalarSizeInBits(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::BitmaskEnumDetail::Mask(), Ptr, and llvm::BasicBlock::splitBasicBlock().
|
static |
Definition at line 741 of file CodeGenPrepare.cpp.
References assert(), llvm::dyn_cast(), llvm::GCRelocateInst::getBasePtrIndex(), getGEPSmallConstantIntOffsetV(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::Value::getType(), llvm::makeArrayRef(), llvm::Value::replaceAllUsesWith(), llvm::IRBuilderBase::SetCurrentDebugLocation(), and llvm::Value::takeName().
SinkCast - Sink the specified cast instruction into its user blocks.
InsertedCasts - Only insert a cast in each block once.
Definition at line 867 of file CodeGenPrepare.cpp.
References assert(), llvm::CastInst::Create(), E, llvm::BasicBlock::end(), llvm::Instruction::eraseFromParent(), llvm::BasicBlock::getFirstInsertionPt(), llvm::PHINode::getIncomingBlock(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Instruction::isEHPad(), llvm::Value::use_empty(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by OptimizeNoopCopyExpression().
|
static |
Sink the given CmpInst into user blocks to reduce the number of virtual registers that must be created and coalesced.
This is a clear win except on targets with multiple condition code registers (PowerPC), where it might lose; some adjustment may be wanted there.
Return true if any changes are made.
Definition at line 1026 of file CodeGenPrepare.cpp.
References assert(), llvm::CmpInst::Create(), E, llvm::BasicBlock::end(), llvm::Instruction::eraseFromParent(), llvm::Instruction::getDebugLoc(), llvm::BasicBlock::getFirstInsertionPt(), llvm::CmpInst::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::CmpInst::getPredicate(), llvm::Instruction::setDebugLoc(), llvm::Value::use_empty(), llvm::Value::user_begin(), llvm::Value::user_end(), and llvm::TargetLoweringBase::useSoftFloat().
Referenced by OptimizeCmpExpression().
|
static |
Sink both shift and truncate instruction to the use of truncate's BB.
Definition at line 1114 of file CodeGenPrepare.cpp.
References assert(), llvm::CastInst::Create(), llvm::dyn_cast(), llvm::BasicBlock::end(), llvm::BasicBlock::getFirstInsertionPt(), llvm::Instruction::getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::TargetLoweringBase::getValueType(), llvm::TargetLoweringBase::InstructionOpcodeToISD(), llvm::TargetLoweringBase::isOperationLegalOrCustom(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by OptimizeExtractBits().
| STATISTIC | ( | NumBlocksElim | , |
| "Number of blocks eliminated" | |||
| ) |
| STATISTIC | ( | NumPHIsElim | , |
| "Number of trivial PHIs eliminated" | |||
| ) |
| STATISTIC | ( | NumGEPsElim | , |
| "Number of GEPs converted to casts" | |||
| ) |
| STATISTIC | ( | NumCmpUses | , |
| "Number of uses of Cmp expressions replaced with uses of ""sunken Cmps" | |||
| ) |
| STATISTIC | ( | NumCastUses | , |
| "Number of uses of Cast expressions replaced with uses ""of sunken Casts" | |||
| ) |
| STATISTIC | ( | NumMemoryInsts | , |
| "Number of memory instructions whose address ""computations were sunk" | |||
| ) |
| STATISTIC | ( | NumExtsMoved | , |
| "Number of ext instructions combined with loads" | [s|z] | ||
| ) |
| STATISTIC | ( | NumExtUses | , |
| "Number of uses of ext instructions optimized" | [s|z] | ||
| ) |
| STATISTIC | ( | NumAndsAdded | , |
| "Number of and mask instructions added to form ext loads" | |||
| ) |
| STATISTIC | ( | NumAndUses | , |
| "Number of uses of and mask instructions optimized" | |||
| ) |
| STATISTIC | ( | NumRetsDup | , |
| "Number of return instructions duplicated" | |||
| ) |
| STATISTIC | ( | NumDbgValueMoved | , |
| "Number of debug value instructions moved" | |||
| ) |
| STATISTIC | ( | NumSelectsExpanded | , |
| "Number of selects turned into branches" | |||
| ) |
| STATISTIC | ( | NumAndCmpsMoved | , |
| "Number of and/cmp's pushed into branches" | |||
| ) |
| STATISTIC | ( | NumStoreExtractExposed | , |
| "Number of store(extractelement) exposed" | |||
| ) |
|
static |
| codegenprepare |
Definition at line 232 of file CodeGenPrepare.cpp.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| Optimize for code false |
Definition at line 232 of file CodeGenPrepare.cpp.
|
static |
|
static |
| Optimize for code generation |
Definition at line 232 of file CodeGenPrepare.cpp.
|
static |
|
static |
1.8.6