64 #define DEBUG_TYPE "loop-unswitch"
66 STATISTIC(NumBranches,
"Number of branches unswitched");
67 STATISTIC(NumSwitches,
"Number of switches unswitched");
68 STATISTIC(NumGuards,
"Number of guards unswitched");
69 STATISTIC(NumSelects ,
"Number of selects unswitched");
70 STATISTIC(NumTrivial ,
"Number of unswitches that are trivial");
71 STATISTIC(NumSimplify,
"Number of simplifications of unswitched code");
72 STATISTIC(TotalInsts,
"Total number of instructions analyzed");
83 cl::desc(
"Enable the use of the block frequency analysis to access PGO "
84 "heuristics to minimize code growth in cold regions."));
88 cl::desc(
"Coldness threshold in percentage. The loop header frequency "
89 "(relative to the entry frequency) is compared with this "
90 "threshold to determine if non-trivial unswitching should be "
95 class LUAnalysisCache {
100 typedef UnswitchedValsMap::iterator UnswitchedValsIt;
102 struct LoopProperties {
103 unsigned CanBeUnswitchedCount;
104 unsigned WasUnswitchedCount;
105 unsigned SizeEstimation;
106 UnswitchedValsMap UnswitchedVals;
111 typedef std::map<const Loop*, LoopProperties> LoopPropsMap;
112 typedef LoopPropsMap::iterator LoopPropsMapIt;
114 LoopPropsMap LoopsProperties;
115 UnswitchedValsMap *CurLoopInstructions;
116 LoopProperties *CurrentLoopProperties;
136 : CurLoopInstructions(nullptr), CurrentLoopProperties(nullptr),
145 void forgetLoop(
const Loop *
L);
157 bool CostAllowsUnswitching();
162 void cloneData(
const Loop *NewLoop,
const Loop *OldLoop,
166 class LoopUnswitch :
public LoopPass {
173 std::vector<Loop*> LoopProcessWorklist;
175 LUAnalysisCache BranchesInfo;
184 bool OptimizeForSize;
198 std::vector<BasicBlock*> LoopBlocks;
200 std::vector<BasicBlock*> NewBlocks;
204 explicit LoopUnswitch(
bool Os =
false) :
206 currentLoop(nullptr), DT(nullptr), loopHeader(nullptr),
207 loopPreheader(nullptr) {
212 bool processCurrentLoop();
213 bool isUnreachableDueToPreviousUnswitching(
BasicBlock *);
225 void releaseMemory()
override {
226 BranchesInfo.forgetLoop(currentLoop);
229 void initLoopData() {
230 loopHeader = currentLoop->getHeader();
231 loopPreheader = currentLoop->getLoopPreheader();
236 void SplitExitEdges(
Loop *
L,
239 bool TryTrivialLoopUnswitch(
bool &Changed);
248 void RewriteLoopBodyWithConditionConstant(
Loop *
L,
Value *LIC,
251 void EmitPreheaderBranchOnCondition(
Value *LIC,
Constant *Val,
257 void SimplifyCode(std::vector<Instruction*> &Worklist,
Loop *
L);
266 LoopPropsMapIt PropsIt;
268 std::tie(PropsIt, Inserted) =
269 LoopsProperties.insert(std::make_pair(L, LoopProperties()));
271 LoopProperties &Props = PropsIt->second;
292 Props.SizeEstimation = Metrics.
NumInsts;
293 Props.CanBeUnswitchedCount = MaxSize / (Props.SizeEstimation);
294 Props.WasUnswitchedCount = 0;
295 MaxSize -= Props.SizeEstimation * Props.CanBeUnswitchedCount;
299 << L->
getHeader()->getName() <<
", contents cannot be "
306 CurrentLoopProperties = &Props;
307 CurLoopInstructions = &Props.UnswitchedVals;
313 void LUAnalysisCache::forgetLoop(
const Loop *L) {
315 LoopPropsMapIt LIt = LoopsProperties.find(L);
317 if (LIt != LoopsProperties.end()) {
318 LoopProperties &Props = LIt->second;
319 MaxSize += (Props.CanBeUnswitchedCount + Props.WasUnswitchedCount) *
320 Props.SizeEstimation;
321 LoopsProperties.erase(LIt);
324 CurrentLoopProperties =
nullptr;
325 CurLoopInstructions =
nullptr;
331 void LUAnalysisCache::setUnswitched(
const SwitchInst *SI,
const Value *V) {
332 (*CurLoopInstructions)[SI].insert(V);
336 bool LUAnalysisCache::isUnswitched(
const SwitchInst *SI,
const Value *V) {
337 return (*CurLoopInstructions)[SI].count(V);
340 bool LUAnalysisCache::CostAllowsUnswitching() {
341 return CurrentLoopProperties->CanBeUnswitchedCount > 0;
347 void LUAnalysisCache::cloneData(
const Loop *NewLoop,
const Loop *OldLoop,
350 LoopProperties &NewLoopProps = LoopsProperties[NewLoop];
351 LoopProperties &OldLoopProps = *CurrentLoopProperties;
352 UnswitchedValsMap &Insts = OldLoopProps.UnswitchedVals;
356 --OldLoopProps.CanBeUnswitchedCount;
357 ++OldLoopProps.WasUnswitchedCount;
358 NewLoopProps.WasUnswitchedCount = 0;
359 unsigned Quota = OldLoopProps.CanBeUnswitchedCount;
360 NewLoopProps.CanBeUnswitchedCount = Quota / 2;
361 OldLoopProps.CanBeUnswitchedCount = Quota - Quota / 2;
363 NewLoopProps.SizeEstimation = OldLoopProps.SizeEstimation;
368 for (UnswitchedValsIt
I = Insts.begin();
I != Insts.end(); ++
I) {
371 const SwitchInst *NewInst = cast_or_null<SwitchInst>(NewI);
372 assert(NewInst &&
"All instructions that are in SrcBB must be in VMap.");
374 NewLoopProps.UnswitchedVals[NewInst] = OldLoopProps.UnswitchedVals[OldInst];
388 return new LoopUnswitch(Os);
395 auto CacheIt = Cache.
find(Cond);
396 if (CacheIt != Cache.
end())
397 return CacheIt->second;
407 if (isa<Constant>(Cond))
return nullptr;
435 Cache[Cond] =
nullptr;
448 AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
450 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
452 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
454 Function *
F = currentLoop->getHeader()->getParent();
473 bool Changed =
false;
475 assert(currentLoop->isLCSSAForm(*DT));
477 Changed |= processCurrentLoop();
488 bool LoopUnswitch::isUnreachableDueToPreviousUnswitching(
BasicBlock *BB) {
489 auto *Node = DT->getNode(BB)->getIDom();
491 while (currentLoop->contains(DomBB)) {
494 Node = DT->getNode(DomBB)->getIDom();
495 DomBB = Node->getBlock();
501 if (!isa<ConstantInt>(Cond))
509 if (DT->dominates(UnreachableSucc, BB))
516 bool LoopUnswitch::processCurrentLoop() {
517 bool Changed =
false;
526 if (!currentLoop->isSafeToClone())
530 if (!currentLoop->hasDedicatedExits())
536 if (!BranchesInfo.countLoop(
537 currentLoop, getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
538 *currentLoop->getHeader()->getParent()),
543 if (TryTrivialLoopUnswitch(Changed)) {
563 for (
const auto BB : currentLoop->blocks()) {
564 for (
auto &
I : *BB) {
569 if (
auto *II = dyn_cast<InvokeInst>(&
I))
570 if (!II->getUnwindDest()->canSplitPredecessors())
572 if (
auto *II = dyn_cast<IntrinsicInst>(&
I))
573 if (II->getIntrinsicID() == Intrinsic::experimental_guard)
580 if (OptimizeForSize ||
581 loopHeader->getParent()->hasFnAttribute(Attribute::OptimizeForSize))
590 if (LoopEntryFreq < ColdEntryFreq)
611 E = currentLoop->block_end();
I !=
E; ++
I) {
620 if (SanitizeMemory &&
624 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
628 if (isUnreachableDueToPreviousUnswitching(*
I))
633 if (BI->isConditional()) {
637 currentLoop, Changed);
644 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
646 currentLoop, Changed);
648 if (LoopCond && NumCases) {
659 Constant *UnswitchValCandidate =
i.getCaseValue();
660 if (!BranchesInfo.isUnswitched(SI, UnswitchValCandidate)) {
661 UnswitchVal = UnswitchValCandidate;
669 if (UnswitchIfProfitable(LoopCond, UnswitchVal)) {
679 if (
SelectInst *SI = dyn_cast<SelectInst>(BBI)) {
681 currentLoop, Changed);
682 if (LoopCond && UnswitchIfProfitable(LoopCond,
700 std::set<BasicBlock*> &Visited) {
701 if (!Visited.insert(BB).second) {
709 if (ExitBB)
return false;
724 if (
I.mayHaveSideEffects())
734 std::set<BasicBlock*> Visited;
745 bool LoopUnswitch::UnswitchIfProfitable(
Value *LoopCond,
Constant *Val,
748 if (!BranchesInfo.CostAllowsUnswitching()) {
750 << currentLoop->getHeader()->getName()
751 <<
" at non-trivial condition '" << *Val
752 <<
"' == " << *LoopCond <<
"\n"
753 <<
". Cost too high.\n");
757 UnswitchNontrivialCondition(LoopCond, Val, currentLoop, TI);
782 void LoopUnswitch::EmitPreheaderBranchOnCondition(
Value *LIC,
Constant *Val,
789 Value *BranchVal = LIC;
790 bool Swapped =
false;
791 if (!isa<ConstantInt>(Val) ||
802 IRBuilder<>(InsertPt).CreateCondBr(BranchVal, TrueDest, FalseDest, TI);
821 DEBUG(
dbgs() <<
"loop-unswitch: Trivial-Unswitch loop %"
822 << loopHeader->getName() <<
" [" << L->
getBlocks().size()
823 <<
" blocks] in Function "
824 << L->
getHeader()->getParent()->getName() <<
" on cond: " << *Val
825 <<
" == " << *Cond <<
"\n");
845 EmitPreheaderBranchOnCondition(Cond, Val, NewExit, NewPH,
846 loopPreheader->getTerminator(), TI);
847 LPM->deleteSimpleAnalysisValue(loopPreheader->getTerminator(),
L);
856 RewriteLoopBodyWithConditionConstant(L, Cond, Val,
false);
866 bool LoopUnswitch::TryTrivialLoopUnswitch(
bool &Changed) {
867 BasicBlock *CurrentBB = currentLoop->getHeader();
892 if (!currentLoop->contains(CurrentBB) || !Visited.
insert(CurrentBB).second)
899 if (
I.mayHaveSideEffects())
903 if (
BranchInst *BI = dyn_cast<BranchInst>(CurrentTerm)) {
918 CurrentTerm = CurrentBB->getTerminator();
926 if (
BranchInst *BI = dyn_cast<BranchInst>(CurrentTerm)) {
932 currentLoop, Changed);
953 if (!LoopExitBB || isa<PHINode>(LoopExitBB->
begin()))
956 UnswitchTrivialCondition(currentLoop, LoopCond, CondVal, LoopExitBB,
960 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(CurrentTerm)) {
963 currentLoop, Changed);
980 i.getCaseSuccessor()))) {
986 if (BranchesInfo.isUnswitched(SI, CaseVal))
988 LoopExitBB = LoopExitCandidate;
996 if (!LoopExitBB || isa<PHINode>(LoopExitBB->
begin()))
999 UnswitchTrivialCondition(currentLoop, LoopCond, CondVal, LoopExitBB,
1009 void LoopUnswitch::SplitExitEdges(
Loop *L,
1012 for (
unsigned i = 0, e = ExitBlocks.
size();
i != e; ++
i) {
1027 void LoopUnswitch::UnswitchNontrivialCondition(
Value *LIC,
Constant *Val,
1030 DEBUG(
dbgs() <<
"loop-unswitch: Unswitching loop %"
1031 << loopHeader->getName() <<
" [" << L->
getBlocks().size()
1032 <<
" blocks] in Function " << F->
getName()
1033 <<
" when '" << *Val <<
"' == " << *LIC <<
"\n");
1035 if (
auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>())
1036 SEWP->getSE().forgetLoop(L);
1044 LoopBlocks.push_back(NewPreheader);
1054 SplitExitEdges(L, ExitBlocks);
1061 LoopBlocks.insert(LoopBlocks.end(), ExitBlocks.
begin(), ExitBlocks.
end());
1066 NewBlocks.reserve(LoopBlocks.size());
1068 for (
unsigned i = 0, e = LoopBlocks.size();
i != e; ++
i) {
1071 NewBlocks.push_back(NewBB);
1072 VMap[LoopBlocks[
i]] = NewBB;
1073 LPM->cloneBasicBlockSimpleAnalysis(LoopBlocks[
i], NewBB, L);
1080 NewBlocks[0]->getIterator(), F->
end());
1087 BranchesInfo.cloneData(NewLoop, L, VMap);
1096 for (
unsigned i = 0, e = ExitBlocks.
size();
i != e; ++
i) {
1097 BasicBlock *NewExit = cast<BasicBlock>(VMap[ExitBlocks[
i]]);
1099 if (
Loop *ExitBBLoop = LI->getLoopFor(ExitBlocks[
i]))
1100 ExitBBLoop->addBasicBlockToLoop(NewExit, *LI);
1103 "Exit block should have been split to have one successor!");
1118 &*ExitSucc->getFirstInsertionPt());
1131 for (
unsigned i = 0, e = NewBlocks.size(); i != e; ++
i) {
1135 if (
auto *II = dyn_cast<IntrinsicInst>(&
I))
1136 if (II->getIntrinsicID() == Intrinsic::assume)
1142 BranchInst *OldBR = cast<BranchInst>(loopPreheader->getTerminator());
1144 "Preheader splitting did not work correctly!");
1147 EmitPreheaderBranchOnCondition(LIC, Val, NewBlocks[0], LoopBlocks[0], OldBR,
1149 LPM->deleteSimpleAnalysisValue(OldBR, L);
1163 RewriteLoopBodyWithConditionConstant(L, LIC, Val,
false);
1168 if (!LoopProcessWorklist.empty() && LoopProcessWorklist.back() == NewLoop &&
1169 LICHandle && !isa<Constant>(LICHandle))
1170 RewriteLoopBodyWithConditionConstant(NewLoop, LICHandle, Val,
true);
1175 std::vector<Instruction*> &Worklist) {
1177 Worklist.erase(
std::remove(Worklist.begin(), Worklist.end(),
I),
1184 std::vector<Instruction*> &Worklist,
1186 DEBUG(
dbgs() <<
"Replace with '" << *V <<
"': " << *I);
1191 Worklist.push_back(
Use);
1195 Worklist.push_back(cast<Instruction>(U));
1206 void LoopUnswitch::RewriteLoopBodyWithConditionConstant(
Loop *L,
Value *LIC,
1209 assert(!isa<Constant>(LIC) &&
"Why are we unswitching on a constant?");
1220 std::vector<Instruction*> Worklist;
1225 if (IsEqual || (isa<ConstantInt>(Val) &&
1232 !cast<ConstantInt>(Val)->getZExtValue());
1238 Worklist.push_back(UI);
1244 SimplifyCode(Worklist, L);
1256 Worklist.push_back(UI);
1263 if (!SI || !isa<ConstantInt>(Val))
continue;
1277 BranchesInfo.setUnswitched(SI, Val);
1283 if (Latch && DT->dominates(SISucc, Latch))
1315 DT->addNewBlock(Abort, NewSISucc);
1318 SimplifyCode(Worklist, L);
1329 void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist,
Loop *L) {
1331 while (!Worklist.empty()) {
1333 Worklist.pop_back();
1337 DEBUG(
dbgs() <<
"Remove dead instruction '" << *I);
1342 Worklist.push_back(
Use);
1343 LPM->deleteSimpleAnalysisValue(I, L);
1354 if (LI->replacementPreservesLCSSAForm(I, V)) {
1360 if (
BranchInst *BI = dyn_cast<BranchInst>(I)) {
1367 if (!SinglePred)
continue;
1368 assert(SinglePred == Pred &&
"CFG broken");
1384 LPM->deleteSimpleAnalysisValue(BI, L);
1389 LI->removeBlock(Succ);
1390 LPM->deleteSimpleAnalysisValue(Succ, L);
Pass interface - Implemented by all 'passes'.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
void initializeLoopUnswitchPass(PassRegistry &)
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
This is the interface for a simple mod/ref and alias analysis over globals.
INITIALIZE_PASS_BEGIN(LoopUnswitch,"loop-unswitch","Unswitch loops", false, false) INITIALIZE_PASS_END(LoopUnswitch
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
unsigned getNumOperands() const
An immutable pass that tracks lazily created AssumptionCache objects.
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
A cache of .assume calls within a function.
LoopT * getParentLoop() const
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
bool notDuplicatable
True if this function cannot be duplicated.
Loop & addLoop(Loop *ParentLoop)
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
BlockT * getHeader() const
ConstantInt * findCaseDest(BasicBlock *BB)
Finds the unique case value for a given successor.
StringRef getName() const
Return a constant reference to the value's name.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isUnconditional() const
static Loop * CloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM, LoopInfo *LI, LPPassManager *LPM)
Recursively clone the specified loop and all of its children, mapping the blocks with the specified m...
This class represents the LLVM 'select' instruction.
Option class for critical edge splitting.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *)
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
static bool isEqual(const Function &Caller, const Function &Callee)
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
Value handle that is nullable, but tries to track the Value.
Pass * createLoopUnswitchPass(bool OptimizeForSize=false)
BasicBlock * getSuccessor(unsigned i) const
iterator find(const KeyT &Val)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Interval::succ_iterator succ_end(Interval *I)
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
static void RemoveFromWorklist(Instruction *I, std::vector< Instruction * > &Worklist)
Remove all instances of I from the worklist vector specified.
BasicBlock * SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
If this edge is a critical edge, insert a new node to split the critical edge.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
initializer< Ty > init(const Ty &Val)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Subclasses of this class are all able to terminate a basic block.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
bool isVectorTy() const
True if this is an instance of VectorType.
This function has undefined behavior.
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
LandingPadInst * getLandingPadInst()
Return the landingpad instruction associated with the landing pad.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Represent the analysis usage information of a pass.
void splice(iterator where, iplist_impl &L2)
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
const InstListType & getInstList() const
Return the underlying instruction list container.
This instruction compares its operands according to the predicate given to the constructor.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
Return all unique successor blocks of this loop.
LLVMContext & getContext() const
All values hold a context through their type.
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
bool isConditional() const
void deleteSimpleAnalysisValue(Value *V, Loop *L)
deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes that implement simple anal...
Iterator for intrusive lists based on ilist_node.
machine trace Machine Trace Metrics
const BasicBlockListType & getBasicBlockList() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
bool makeLoopInvariant(Value *V, bool &Changed, Instruction *InsertPt=nullptr) const
If the given value is an instruction inside of the loop and it can be hoisted, do so to make it trivi...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Utility to calculate the size and a few similar metrics for a set of basic blocks.
CriticalEdgeSplittingOptions & setPreserveLCSSA()
BasicBlockTy * getCaseSuccessor()
Resolves successor for current case.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static Value * FindLIVLoopCondition(Value *Cond, Loop *L, bool &Changed, DenseMap< Value *, Value * > &Cache)
Cond is a condition that occurs in L.
CaseIt findCaseValue(const ConstantInt *C)
Search all of the case values for the specified constant.
static ConstantInt * getTrue(LLVMContext &Context)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
void push_back(pointer val)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
bool isIntegerTy() const
True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
BasicBlock * getSinglePredecessor()
Return the predecessor of this block if it has a single predecessor block.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Convert the instruction operands from referencing the current values into those specified by VM...
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
std::vector< BlockT * >::const_iterator block_iterator
Value * getCondition() const
static cl::opt< unsigned > ColdnessThreshold("loop-unswitch-coldness-threshold", cl::init(1), cl::Hidden, cl::desc("Coldness threshold in percentage. The loop header frequency ""(relative to the entry frequency) is compared with this ""threshold to determine if non-trivial unswitching should be ""enabled."))
If this flag is set, the remapper ignores missing function-local entries (Argument, Instruction, BasicBlock) that are not in the value map.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static bool isTrivialLoopExitBlockHelper(Loop *L, BasicBlock *BB, BasicBlock *&ExitBB, std::set< BasicBlock * > &Visited)
Check to see if all paths from BB exit the loop with no side effects (including infinite loops)...
block_iterator block_end() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Value * getCondition() const
Analysis providing branch probability information.
Captures loop safety information.
void registerAssumption(CallInst *CI)
Add an .assume intrinsic to this function's cache.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Represents a single loop in the control flow graph.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
static cl::opt< bool > LoopUnswitchWithBlockFrequency("loop-unswitch-with-block-frequency", cl::init(false), cl::Hidden, cl::desc("Enable the use of the block frequency analysis to access PGO ""heuristics to minimize code growth in cold regions."))
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
iterator find(const KeyT &Val)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
CaseIt case_default()
Returns an iterator that points to the default case.
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value * > &EphValues)
Add information about a block to the current state.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVMContext & getContext() const
Get the context in which this basic block lives.
Module * getParent()
Get the module that this global value is contained inside of...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
static void ReplaceUsesOfWith(Instruction *I, Value *V, std::vector< Instruction * > &Worklist, Loop *L, LPPassManager *LPM)
When we find that I really equals V, remove I from the program, replacing all uses with V and update ...
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the edge connecting specified block.
block_iterator block_begin() const
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
See if we can compute a simplified version of this instruction.
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop)...
void setIncomingValue(unsigned i, Value *V)
unsigned NumInsts
Number of instructions in the analyzed blocks.
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo)
Returns true if the instruction in a loop is guaranteed to execute at least once. ...
static BasicBlock * isTrivialLoopExitBlock(Loop *L, BasicBlock *BB)
Return true if the specified block unconditionally leads to an exit from the specified loop...
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr)
CloneBasicBlock - Return a copy of the specified basic block, but without embedding the block into a ...
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
const BasicBlock * getParent() const
A wrapper class for inspecting calls to intrinsic functions.