58 #define DEBUG_TYPE "loop-unswitch"
60 STATISTIC(NumBranches,
"Number of branches unswitched");
61 STATISTIC(NumSwitches,
"Number of switches unswitched");
62 STATISTIC(NumSelects ,
"Number of selects unswitched");
63 STATISTIC(NumTrivial ,
"Number of unswitches that are trivial");
64 STATISTIC(NumSimplify,
"Number of simplifications of unswitched code");
65 STATISTIC(TotalInsts,
"Total number of instructions analyzed");
75 class LUAnalysisCache {
80 typedef UnswitchedValsMap::iterator UnswitchedValsIt;
82 struct LoopProperties {
83 unsigned CanBeUnswitchedCount;
84 unsigned WasUnswitchedCount;
85 unsigned SizeEstimation;
86 UnswitchedValsMap UnswitchedVals;
91 typedef std::map<const Loop*, LoopProperties> LoopPropsMap;
92 typedef LoopPropsMap::iterator LoopPropsMapIt;
94 LoopPropsMap LoopsProperties;
95 UnswitchedValsMap *CurLoopInstructions;
96 LoopProperties *CurrentLoopProperties;
116 : CurLoopInstructions(nullptr), CurrentLoopProperties(nullptr),
125 void forgetLoop(
const Loop *L);
137 bool CostAllowsUnswitching();
142 void cloneData(
const Loop *NewLoop,
const Loop *OldLoop,
146 class LoopUnswitch :
public LoopPass {
153 std::vector<Loop*> LoopProcessWorklist;
155 LUAnalysisCache BranchesInfo;
157 bool OptimizeForSize;
168 std::vector<BasicBlock*> LoopBlocks;
170 std::vector<BasicBlock*> NewBlocks;
174 explicit LoopUnswitch(
bool Os =
false) :
176 currentLoop(nullptr), DT(nullptr), loopHeader(nullptr),
177 loopPreheader(nullptr) {
182 bool processCurrentLoop();
202 void releaseMemory()
override {
203 BranchesInfo.forgetLoop(currentLoop);
206 void initLoopData() {
207 loopHeader = currentLoop->getHeader();
208 loopPreheader = currentLoop->getLoopPreheader();
222 void RewriteLoopBodyWithConditionConstant(
Loop *L,
Value *LIC,
225 void EmitPreheaderBranchOnCondition(
Value *LIC,
Constant *Val,
231 void SimplifyCode(std::vector<Instruction*> &Worklist,
Loop *L);
232 bool IsTrivialUnswitchCondition(
Value *Cond,
Constant **Val =
nullptr,
243 LoopPropsMapIt PropsIt;
245 std::tie(PropsIt, Inserted) =
246 LoopsProperties.insert(std::make_pair(L, LoopProperties()));
248 LoopProperties &Props = PropsIt->second;
269 Props.SizeEstimation = Metrics.
NumInsts;
270 Props.CanBeUnswitchedCount = MaxSize / (Props.SizeEstimation);
271 Props.WasUnswitchedCount = 0;
272 MaxSize -= Props.SizeEstimation * Props.CanBeUnswitchedCount;
276 << L->
getHeader()->getName() <<
", contents cannot be "
283 CurrentLoopProperties = &Props;
284 CurLoopInstructions = &Props.UnswitchedVals;
290 void LUAnalysisCache::forgetLoop(
const Loop *L) {
292 LoopPropsMapIt LIt = LoopsProperties.find(L);
294 if (LIt != LoopsProperties.end()) {
295 LoopProperties &Props = LIt->second;
296 MaxSize += (Props.CanBeUnswitchedCount + Props.WasUnswitchedCount) *
297 Props.SizeEstimation;
298 LoopsProperties.erase(LIt);
301 CurrentLoopProperties =
nullptr;
302 CurLoopInstructions =
nullptr;
308 void LUAnalysisCache::setUnswitched(
const SwitchInst *SI,
const Value *V) {
309 (*CurLoopInstructions)[SI].insert(V);
313 bool LUAnalysisCache::isUnswitched(
const SwitchInst *SI,
const Value *V) {
314 return (*CurLoopInstructions)[SI].count(V);
317 bool LUAnalysisCache::CostAllowsUnswitching() {
318 return CurrentLoopProperties->CanBeUnswitchedCount > 0;
324 void LUAnalysisCache::cloneData(
const Loop *NewLoop,
const Loop *OldLoop,
327 LoopProperties &NewLoopProps = LoopsProperties[NewLoop];
328 LoopProperties &OldLoopProps = *CurrentLoopProperties;
329 UnswitchedValsMap &Insts = OldLoopProps.UnswitchedVals;
333 --OldLoopProps.CanBeUnswitchedCount;
334 ++OldLoopProps.WasUnswitchedCount;
335 NewLoopProps.WasUnswitchedCount = 0;
336 unsigned Quota = OldLoopProps.CanBeUnswitchedCount;
337 NewLoopProps.CanBeUnswitchedCount = Quota / 2;
338 OldLoopProps.CanBeUnswitchedCount = Quota - Quota / 2;
340 NewLoopProps.SizeEstimation = OldLoopProps.SizeEstimation;
345 for (UnswitchedValsIt
I = Insts.begin();
I != Insts.end(); ++
I) {
348 const SwitchInst *NewInst = cast_or_null<SwitchInst>(NewI);
349 assert(NewInst &&
"All instructions that are in SrcBB must be in VMap.");
351 NewLoopProps.UnswitchedVals[NewInst] = OldLoopProps.UnswitchedVals[OldInst];
367 return new LoopUnswitch(Os);
383 if (isa<Constant>(Cond))
return nullptr;
407 if (skipOptnoneFunction(L))
410 AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
412 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
415 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
418 Function *
F = currentLoop->getHeader()->getParent();
419 bool Changed =
false;
421 assert(currentLoop->isLCSSAForm(*DT));
423 Changed |= processCurrentLoop();
436 bool LoopUnswitch::processCurrentLoop() {
437 bool Changed =
false;
446 if (!currentLoop->isSafeToClone())
450 if (!currentLoop->hasDedicatedExits())
457 if (!BranchesInfo.countLoop(
458 currentLoop, getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
459 *currentLoop->getHeader()->getParent()),
467 E = currentLoop->block_end();
I != E; ++
I) {
469 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
472 if (BI->isConditional()) {
476 currentLoop, Changed);
483 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
485 currentLoop, Changed);
487 if (LoopCond && NumCases) {
498 Constant *UnswitchValCandidate = i.getCaseValue();
499 if (!BranchesInfo.isUnswitched(SI, UnswitchValCandidate)) {
500 UnswitchVal = UnswitchValCandidate;
508 if (UnswitchIfProfitable(LoopCond, UnswitchVal)) {
518 if (
SelectInst *SI = dyn_cast<SelectInst>(BBI)) {
520 currentLoop, Changed);
521 if (LoopCond && UnswitchIfProfitable(LoopCond,
539 std::set<BasicBlock*> &Visited) {
540 if (!Visited.insert(BB).second) {
548 if (ExitBB)
return false;
563 if (
I->mayHaveSideEffects())
573 std::set<BasicBlock*> Visited;
593 bool LoopUnswitch::IsTrivialUnswitchCondition(
Value *Cond,
Constant **Val,
595 BasicBlock *Header = currentLoop->getHeader();
600 if (
BranchInst *BI = dyn_cast<BranchInst>(HeaderTerm)) {
603 if (!BI->isConditional() || BI->getCondition() != Cond)
611 BI->getSuccessor(0)))) {
614 BI->getSuccessor(1)))) {
617 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(HeaderTerm)) {
631 i.getCaseSuccessor()))) {
637 if (BranchesInfo.isUnswitched(SI, CaseVal))
639 LoopExitBB = LoopExitCandidate;
640 if (Val) *Val = CaseVal;
648 if (!LoopExitBB || isa<PHINode>(LoopExitBB->
begin()))
651 if (LoopExit) *LoopExit = LoopExitBB;
659 if (
I->mayHaveSideEffects())
667 bool LoopUnswitch::UnswitchIfProfitable(
Value *LoopCond,
Constant *Val,
673 if (IsTrivialUnswitchCondition(LoopCond, &CondVal, &ExitBlock)) {
676 UnswitchTrivialCondition(currentLoop, LoopCond, CondVal, ExitBlock, TI);
681 if (!BranchesInfo.CostAllowsUnswitching()) {
683 << currentLoop->getHeader()->getName()
684 <<
" at non-trivial condition '" << *Val
685 <<
"' == " << *LoopCond <<
"\n"
686 <<
". Cost too high.\n");
694 UnswitchNontrivialCondition(LoopCond, Val, currentLoop, TI);
725 for (
auto &MD : MDs) {
730 if (Swapped && MD.second->getNumOperands() == 3 &&
731 isa<MDString>(MD.second->getOperand(0))) {
732 MDString *MDName = cast<MDString>(MD.second->getOperand(0));
733 if (MDName->
getString() ==
"branch_weights") {
734 auto *ValT = cast_or_null<ConstantAsMetadata>(
735 MD.second->getOperand(1))->getValue();
736 auto *ValF = cast_or_null<ConstantAsMetadata>(
737 MD.second->getOperand(2))->getValue();
738 assert(ValT && ValF &&
"Invalid Operands of branch_weights");
741 .createBranchWeights(cast<ConstantInt>(ValF)->getZExtValue(),
742 cast<ConstantInt>(ValT)->getZExtValue());
756 void LoopUnswitch::EmitPreheaderBranchOnCondition(
Value *LIC,
Constant *Val,
763 Value *BranchVal = LIC;
764 bool Swapped =
false;
765 if (!isa<ConstantInt>(Val) ||
793 DEBUG(
dbgs() <<
"loop-unswitch: Trivial-Unswitch loop %"
794 << loopHeader->getName() <<
" [" << L->
getBlocks().size()
795 <<
" blocks] in Function "
796 << L->
getHeader()->getParent()->getName() <<
" on cond: " << *Val
797 <<
" == " << *Cond <<
"\n");
812 assert(!L->
contains(ExitBlock) &&
"Exit block is in the loop?");
817 EmitPreheaderBranchOnCondition(Cond, Val, NewExit, NewPH,
818 loopPreheader->getTerminator(), TI);
819 LPM->deleteSimpleAnalysisValue(loopPreheader->getTerminator(), L);
828 RewriteLoopBodyWithConditionConstant(L, Cond, Val,
false);
834 void LoopUnswitch::SplitExitEdges(
Loop *L,
837 for (
unsigned i = 0, e = ExitBlocks.
size(); i != e; ++i) {
853 void LoopUnswitch::UnswitchNontrivialCondition(
Value *LIC,
Constant *Val,
856 DEBUG(
dbgs() <<
"loop-unswitch: Unswitching loop %"
857 << loopHeader->getName() <<
" [" << L->
getBlocks().size()
858 <<
" blocks] in Function " << F->
getName()
859 <<
" when '" << *Val <<
"' == " << *LIC <<
"\n");
870 LoopBlocks.push_back(NewPreheader);
880 SplitExitEdges(L, ExitBlocks);
887 LoopBlocks.insert(LoopBlocks.end(), ExitBlocks.
begin(), ExitBlocks.
end());
892 NewBlocks.reserve(LoopBlocks.size());
894 for (
unsigned i = 0, e = LoopBlocks.size(); i != e; ++i) {
897 NewBlocks.push_back(NewBB);
898 VMap[LoopBlocks[i]] = NewBB;
899 LPM->cloneBasicBlockSimpleAnalysis(LoopBlocks[i], NewBB, L);
905 NewBlocks[0], F->
end());
916 BranchesInfo.cloneData(NewLoop, L, VMap);
925 for (
unsigned i = 0, e = ExitBlocks.
size(); i != e; ++i) {
926 BasicBlock *NewExit = cast<BasicBlock>(VMap[ExitBlocks[i]]);
928 if (
Loop *ExitBBLoop = LI->getLoopFor(ExitBlocks[i]))
929 ExitBBLoop->addBasicBlockToLoop(NewExit, *LI);
932 "Exit block should have been split to have one successor!");
947 ExitSucc->getFirstInsertionPt());
960 for (
unsigned i = 0, e = NewBlocks.size(); i != e; ++i)
962 E = NewBlocks[i]->
end();
I != E; ++
I)
966 BranchInst *OldBR = cast<BranchInst>(loopPreheader->getTerminator());
968 "Preheader splitting did not work correctly!");
971 EmitPreheaderBranchOnCondition(LIC, Val, NewBlocks[0], LoopBlocks[0], OldBR,
973 LPM->deleteSimpleAnalysisValue(OldBR, L);
987 RewriteLoopBodyWithConditionConstant(L, LIC, Val,
false);
992 if (!LoopProcessWorklist.empty() && LoopProcessWorklist.back() == NewLoop &&
993 LICHandle && !isa<Constant>(LICHandle))
994 RewriteLoopBodyWithConditionConstant(NewLoop, LICHandle, Val,
true);
1000 std::vector<Instruction*> &Worklist) {
1002 Worklist.erase(
std::remove(Worklist.begin(), Worklist.end(),
I),
1009 std::vector<Instruction*> &Worklist,
1011 DEBUG(
dbgs() <<
"Replace with '" << *V <<
"': " << *I);
1016 Worklist.push_back(
Use);
1020 Worklist.push_back(cast<Instruction>(U));
1031 void LoopUnswitch::RewriteLoopBodyWithConditionConstant(
Loop *L,
Value *LIC,
1034 assert(!isa<Constant>(LIC) &&
"Why are we unswitching on a constant?");
1045 std::vector<Instruction*> Worklist;
1050 if (IsEqual || (isa<ConstantInt>(Val) &&
1057 !cast<ConstantInt>(Val)->getZExtValue());
1063 Worklist.push_back(UI);
1066 for (std::vector<Instruction*>::iterator UI = Worklist.begin(),
1067 UE = Worklist.end(); UI != UE; ++UI)
1070 SimplifyCode(Worklist, L);
1082 Worklist.push_back(UI);
1089 if (!SI || !isa<ConstantInt>(Val))
continue;
1103 BranchesInfo.setUnswitched(SI, Val);
1109 if (Latch && DT->dominates(SISucc, Latch))
1142 DT->addNewBlock(Abort, NewSISucc);
1145 SimplifyCode(Worklist, L);
1157 void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist,
Loop *L) {
1159 while (!Worklist.empty()) {
1161 Worklist.pop_back();
1165 DEBUG(
dbgs() <<
"Remove dead instruction '" << *I);
1170 Worklist.push_back(
Use);
1171 LPM->deleteSimpleAnalysisValue(I, L);
1182 if (LI->replacementPreservesLCSSAForm(I, V)) {
1188 if (
BranchInst *BI = dyn_cast<BranchInst>(I)) {
1195 if (!SinglePred)
continue;
1196 assert(SinglePred == Pred &&
"CFG broken");
1212 LPM->deleteSimpleAnalysisValue(BI, L);
1217 LI->removeBlock(Succ);
1218 LPM->deleteSimpleAnalysisValue(Succ, L);
Pass interface - Implemented by all 'passes'.
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
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.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
addIncoming - 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)
SplitBlock - Split the specified block at the specified instruction - every thing before SplitPt stay...
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
ScalarEvolution - This class is the main scalar evolution driver.
An immutable pass that tracks lazily created AssumptionCache objects.
CaseIt case_begin()
Returns a read/write iterator that points to the first case in SwitchInst.
A cache of .assume calls within a function.
const_iterator begin(StringRef path)
Get begin iterator over path.
LoopT * getParentLoop() const
const Function * getParent() const
Return the enclosing method, or null if none.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
getAllMetadata - Get all metadata attached to this Instruction.
LoopT * getLoopFor(const BlockT *BB) const
getLoopFor - Return the inner most loop that BB lives in.
bool notDuplicatable
True if this function cannot be duplicated.
const std::vector< BlockT * > & getBlocks() const
getBlocks - Get a list of the basic blocks which make up this loop.
BlockT * getHeader() const
ConstantInt * findCaseDest(BasicBlock *BB)
findCaseDest - Finds the unique case value for a given successor.
StringRef getName() const
Return a constant reference to the value's name.
BlockT * getLoopLatch() const
getLoopLatch - If there is a single latch block for this loop, return it.
iterator begin()
Instruction iterator methods.
static void copyMetadata(Instruction *DstInst, const Instruction *SrcInst, bool Swapped)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isUnconditional() const
void push_back(NodeTy *val)
static Loop * CloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM, LoopInfo *LI, LPPassManager *LPM)
CloneLoop - Recursively clone the specified loop and all of its children, mapping the blocks with the...
SelectInst - 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.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
DominatorTree & getDomTree()
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 addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
addBasicBlockToLoop - This method is used by other analyses to update loop information.
static Value * FindLIVLoopCondition(Value *Cond, Loop *L, bool &Changed)
FindLIVLoopCondition - Cond is a condition that occurs in L.
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)
AnalysisUsage & addPreservedID(const void *ID)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
RF_NoModuleLevelChanges - If this flag is set, the remapper knows that only local values within a fun...
RF_IgnoreMissingEntries - If this flag is set, the remapper ignores entries that are not in the value...
Interval::succ_iterator succ_end(Interval *I)
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, SmallPtrSetImpl< const Value * > &EphValues)
Add information about a block to the current state.
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
static void RemoveFromWorklist(Instruction *I, std::vector< Instruction * > &Worklist)
RemoveFromWorklist - Remove all instances of I from the worklist vector specified.
void clear()
Clear the cache of .assume intrinsics for a function.
BasicBlock * SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
SplitCriticalEdge - If this edge is a critical edge, insert a new node to split the critical edge...
initializer< Ty > init(const Ty &Val)
friend const_iterator end(StringRef path)
Get end iterator over path.
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
Subclasses of this class are all able to terminate a basic block.
void insertLoop(Loop *L, Loop *ParentLoop)
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.
BranchInst - Conditional or Unconditional Branch instruction.
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
UnreachableInst - This function has undefined behavior.
This is an important base class in LLVM.
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...
bool hasMetadata() const
hasMetadata() - Return true if this instruction has any metadata attached to it.
Represent the analysis usage information of a pass.
bool contains(const LoopT *L) const
contains - 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.
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.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
getUniqueExitBlocks - Return all unique successor blocks of this loop.
LLVMContext & getContext() const
All values hold a context through their type.
void setMetadata(unsigned KindID, MDNode *Node)
setMetadata - Set the metadata of the specified kind to the specified node.
StringRef getString() const
void deleteSimpleAnalysisValue(Value *V, Loop *L)
deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes that implement simple anal...
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
getIncomingValue - Return incoming value number x
bool makeLoopInvariant(Value *V, bool &Changed, Instruction *InsertPt=nullptr) const
makeLoopInvariant - If the given value is an instruction inside of the loop and it can be hoisted...
AnalysisUsage & addRequiredID(const void *ID)
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...
CaseIt findCaseValue(const ConstantInt *C)
findCaseValue - Search all of the case values for the specified constant.
static ConstantInt * getTrue(LLVMContext &Context)
void splice(iterator where, iplist &L2)
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.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
bool isIntegerTy() const
isIntegerTy - 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)
RemapInstruction - Convert the instruction operands from referencing the current values into those sp...
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
std::vector< BlockT * >::const_iterator block_iterator
Value * getCondition() const
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)
isTrivialLoopExitBlock - Check to see if all paths from BB exit the loop with no side effects (includ...
block_iterator block_end() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
iplist< 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...
CaseIt case_default()
Returns an iterator that points to the default case.
unsigned getNumCases() const
getNumCases - return the number of 'cases' in this switch instruction, except the default case ...
SwitchInst - Multiway switch.
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)
isInstructionTriviallyDead - Return true if the result produced by the instruction is not used...
LLVM Value Representation.
static void ReplaceUsesOfWith(Instruction *I, Value *V, std::vector< Instruction * > &Worklist, Loop *L, LPPassManager *LPM)
ReplaceUsesOfWith - When we find that I really equals V, remove I from the program, replacing all uses with V and update the worklist.
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
SplitEdge - Split the edge connecting specified block.
block_iterator block_begin() const
The legacy pass manager's analysis pass to compute loop information.
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, AliasAnalysis *AA=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
SplitBlockPredecessors - This method introduces at least one new basic block into the function and mo...
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
SimplifyInstruction - See if we can compute a simplified version of this instruction.
Legacy analysis pass which computes a DominatorTree.
std::vector< LoopT * >::const_iterator iterator
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.
static BasicBlock * isTrivialLoopExitBlock(Loop *L, BasicBlock *BB)
isTrivialLoopExitBlock - Return true if the specified block unconditionally leads to an exit from the...
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
getBasicBlockIndex - Return the first index of the specified basic block in the value list for this P...
const BasicBlock * getParent() const