41 #define DEBUG_TYPE "jump-threading"
43 STATISTIC(NumThreads,
"Number of jumps threaded");
44 STATISTIC(NumFolds,
"Number of terminators folded");
45 STATISTIC(NumDupes,
"Number of branch blocks duplicated to eliminate phi");
49 cl::desc(
"Max block size to duplicate for jump threading"),
90 unsigned BBDupThreshold;
93 struct RecursionSetRemover {
95 std::pair<Value*, BasicBlock*> ThePair;
97 RecursionSetRemover(
DenseSet<std::pair<Value*, BasicBlock*> > &S,
98 std::pair<Value*, BasicBlock*>
P)
99 : TheSet(S), ThePair(P) { }
101 ~RecursionSetRemover() {
102 TheSet.erase(ThePair);
112 bool runOnFunction(
Function &
F)
override;
124 bool DuplicateCondBranchOnPHIIntoPred(
BasicBlock *BB,
128 PredValueInfo &Result,
135 bool ProcessBranchOnPHI(
PHINode *PN);
138 bool SimplifyPartiallyRedundantLoad(
LoadInst *LI);
145 "Jump Threading",
false,
false)
156 bool JumpThreading::runOnFunction(
Function &
F) {
157 if (skipOptnoneFunction(F))
161 TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
162 LVI = &getAnalysis<LazyValueInfo>();
175 bool Changed, EverChanged =
false;
181 while (ProcessBlock(BB))
192 LoopHeaders.erase(BB);
211 bool ErasedFromLoopHeaders = LoopHeaders.erase(BB);
226 if (ErasedFromLoopHeaders)
227 LoopHeaders.insert(BB);
230 EverChanged |= Changed;
250 for (; !isa<TerminatorInst>(
I); ++
I) {
253 if (Size > Threshold)
257 if (isa<DbgInfoIntrinsic>(I))
continue;
260 if (isa<BitCastInst>(I) && I->getType()->isPointerTy())
270 if (
const CallInst *CI = dyn_cast<CallInst>(I)) {
271 if (CI->cannotDuplicate())
275 else if (!isa<IntrinsicInst>(CI))
277 else if (!CI->getType()->isVectorTy())
284 if (isa<SwitchInst>(I))
285 Size = Size > 6 ? Size-6 : 0;
288 if (isa<IndirectBrInst>(I))
289 Size = Size > 8 ? Size-8 : 0;
309 void JumpThreading::FindLoopHeaders(
Function &F) {
313 for (
unsigned i = 0, e = Edges.
size(); i != e; ++i)
314 LoopHeaders.insert(const_cast<BasicBlock*>(Edges[i].second));
327 if (
UndefValue *U = dyn_cast<UndefValue>(Val))
330 if (Preference == WantBlockAddress)
344 ComputeValueKnownInPredecessors(
Value *V,
BasicBlock *BB, PredValueInfo &Result,
351 if (!RecursionSet.insert(std::make_pair(V, BB)).second)
356 RecursionSetRemover remover(RecursionSet, std::make_pair(V, BB));
361 Result.push_back(std::make_pair(KC, *PI));
388 Constant *PredCst = LVI->getConstantOnEdge(V, P, BB, CxtI);
390 Result.push_back(std::make_pair(KC, P));
393 return !Result.empty();
397 if (
PHINode *PN = dyn_cast<PHINode>(I)) {
398 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
399 Value *InVal = PN->getIncomingValue(i);
401 Result.push_back(std::make_pair(KC, PN->getIncomingBlock(i)));
403 Constant *CI = LVI->getConstantOnEdge(InVal,
404 PN->getIncomingBlock(i),
407 Result.push_back(std::make_pair(KC, PN->getIncomingBlock(i)));
411 return !Result.empty();
414 PredValueInfoTy LHSVals, RHSVals;
418 assert(Preference == WantInteger &&
"One-bit non-integer type?");
423 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, LHSVals,
425 ComputeValueKnownInPredecessors(I->
getOperand(1), BB, RHSVals,
428 if (LHSVals.empty() && RHSVals.empty())
441 for (
unsigned i = 0, e = LHSVals.size(); i != e; ++i)
442 if (LHSVals[i].first == InterestingVal ||
443 isa<UndefValue>(LHSVals[i].first)) {
444 Result.push_back(LHSVals[i]);
445 Result.back().first = InterestingVal;
446 LHSKnownBBs.insert(LHSVals[i].second);
448 for (
unsigned i = 0, e = RHSVals.size(); i != e; ++i)
449 if (RHSVals[i].first == InterestingVal ||
450 isa<UndefValue>(RHSVals[i].first)) {
453 if (!LHSKnownBBs.count(RHSVals[i].second)) {
454 Result.push_back(RHSVals[i]);
455 Result.back().first = InterestingVal;
459 return !Result.empty();
465 cast<ConstantInt>(I->
getOperand(1))->isOne()) {
466 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, Result,
472 for (
unsigned i = 0, e = Result.size(); i != e; ++i)
480 assert(Preference != WantBlockAddress
481 &&
"A binary operator creating a block address?");
482 if (
ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1))) {
483 PredValueInfoTy LHSVals;
484 ComputeValueKnownInPredecessors(BO->getOperand(0), BB, LHSVals,
488 for (
unsigned i = 0, e = LHSVals.size(); i != e; ++i) {
493 Result.push_back(std::make_pair(KC, LHSVals[i].second));
497 return !Result.empty();
501 if (
CmpInst *Cmp = dyn_cast<CmpInst>(I)) {
502 assert(Preference == WantInteger &&
"Compares only produce integers");
515 if (!isa<Constant>(RHS))
519 ResT = LVI->getPredicateOnEdge(Cmp->getPredicate(), LHS,
520 cast<Constant>(RHS), PredBB, BB,
528 Result.push_back(std::make_pair(KC, PredBB));
531 return !Result.empty();
536 if (isa<Constant>(Cmp->getOperand(1)) && Cmp->getType()->isIntegerTy()) {
537 if (!isa<Instruction>(Cmp->getOperand(0)) ||
538 cast<Instruction>(Cmp->getOperand(0))->
getParent() != BB) {
539 Constant *RHSCst = cast<Constant>(Cmp->getOperand(1));
546 LVI->getPredicateOnEdge(Cmp->getPredicate(), Cmp->getOperand(0),
547 RHSCst,
P, BB, CxtI ? CxtI : Cmp);
552 Result.push_back(std::make_pair(ResC, P));
555 return !Result.empty();
560 if (
Constant *CmpConst = dyn_cast<Constant>(Cmp->getOperand(1))) {
561 PredValueInfoTy LHSVals;
562 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, LHSVals,
565 for (
unsigned i = 0, e = LHSVals.size(); i != e; ++i) {
570 Result.push_back(std::make_pair(KC, LHSVals[i].second));
573 return !Result.empty();
578 if (
SelectInst *SI = dyn_cast<SelectInst>(I)) {
583 PredValueInfoTy Conds;
584 if ((TrueVal || FalseVal) &&
585 ComputeValueKnownInPredecessors(
SI->getCondition(), BB, Conds,
586 WantInteger, CxtI)) {
587 for (
unsigned i = 0, e = Conds.size(); i != e; ++i) {
592 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Cond)) {
594 KnownCond = CI->isOne();
596 assert(isa<UndefValue>(Cond) &&
"Unexpected condition value");
600 KnownCond = (TrueVal !=
nullptr);
604 if (
Constant *Val = KnownCond ? TrueVal : FalseVal)
605 Result.push_back(std::make_pair(Val, Conds[i].second));
608 return !Result.empty();
613 Constant *CI = LVI->getConstant(V, BB, CxtI);
616 Result.push_back(std::make_pair(KC, *PI));
619 return !Result.empty();
632 unsigned MinSucc = 0;
639 if (NumPreds < MinNumPreds) {
641 MinNumPreds = NumPreds;
660 bool JumpThreading::ProcessBlock(
BasicBlock *BB) {
672 if (SinglePred->getTerminator()->getNumSuccessors() == 1 &&
675 if (LoopHeaders.erase(SinglePred))
676 LoopHeaders.insert(BB);
678 LVI->eraseBlock(SinglePred);
692 if (
BranchInst *BI = dyn_cast<BranchInst>(Terminator)) {
696 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(Terminator)) {
697 Condition =
SI->getCondition();
698 }
else if (
IndirectBrInst *IB = dyn_cast<IndirectBrInst>(Terminator)) {
700 if (IB->getNumSuccessors() == 0)
return false;
702 Preference = WantBlockAddress;
709 if (
Instruction *I = dyn_cast<Instruction>(Condition)) {
715 Condition = SimpleVal;
721 if (isa<UndefValue>(Condition)) {
727 if (i == BestSucc)
continue;
732 <<
"' folding undef terminator: " << *BBTerm <<
'\n');
743 <<
"' folding terminator: " << *BB->
getTerminator() <<
'\n');
754 if (ProcessThreadableEdges(Condition, BB, Preference, Terminator))
760 if (
CmpInst *CondCmp = dyn_cast<CmpInst>(CondInst)) {
769 LVI->getPredicateAt(CondCmp->getPredicate(), CondCmp->getOperand(0),
777 if (CondCmp->use_empty())
778 CondCmp->eraseFromParent();
779 else if (CondCmp->getParent() == BB) {
786 CondCmp->eraseFromParent();
792 if (CondBr && CondConst && TryToUnfoldSelect(CondCmp, BB))
801 Value *SimplifyValue = CondInst;
802 if (
CmpInst *CondCmp = dyn_cast<CmpInst>(SimplifyValue))
803 if (isa<Constant>(CondCmp->getOperand(1)))
804 SimplifyValue = CondCmp->getOperand(0);
808 if (
LoadInst *LI = dyn_cast<LoadInst>(SimplifyValue))
809 if (SimplifyPartiallyRedundantLoad(LI))
817 if (ProcessThreadableEdges(CondInst, BB, Preference, Terminator))
822 if (
PHINode *PN = dyn_cast<PHINode>(CondInst))
824 return ProcessBranchOnPHI(PN);
830 return ProcessBranchOnXOR(cast<BinaryOperator>(CondInst));
843 bool JumpThreading::SimplifyPartiallyRedundantLoad(
LoadInst *LI) {
863 if (
Instruction *PtrOp = dyn_cast<Instruction>(LoadedPtr))
864 if (PtrOp->getParent() == LoadBB)
871 if (
Value *AvailableVal =
880 if (AvailableVal->getType() != LI->
getType())
891 if (BBIt != LoadBB->
begin())
901 AvailablePredsTy AvailablePreds;
911 if (!PredsScanned.
insert(PredBB).second)
915 BBIt = PredBB->
end();
918 nullptr, &ThisAATags);
919 if (!PredAvailable) {
920 OneUnavailablePred = PredBB;
925 if (AATags != ThisAATags) AATags =
AAMDNodes();
929 AvailablePreds.push_back(std::make_pair(PredBB, PredAvailable));
934 if (AvailablePreds.empty())
return false;
946 if (PredsScanned.
size() == AvailablePreds.size()+1 &&
948 UnavailablePred = OneUnavailablePred;
949 }
else if (PredsScanned.
size() != AvailablePreds.size()) {
955 for (
unsigned i = 0, e = AvailablePreds.size(); i != e; ++i)
956 AvailablePredSet.
insert(AvailablePreds[i].first);
966 if (!AvailablePredSet.
count(P))
978 if (UnavailablePred) {
980 "Can't handle critical edge here!");
986 NewVal->setAAMetadata(AATags);
988 AvailablePreds.push_back(std::make_pair(UnavailablePred, NewVal));
1006 AvailablePredsTy::iterator I =
1007 std::lower_bound(AvailablePreds.begin(), AvailablePreds.end(),
1008 std::make_pair(P, (
Value*)
nullptr));
1010 assert(I != AvailablePreds.end() && I->first == P &&
1011 "Didn't find entry for predecessor!");
1017 Value *&PredV = I->second;
1018 if (PredV->getType() != LI->
getType())
1040 assert(!PredToDestList.empty());
1047 for (
unsigned i = 0, e = PredToDestList.size(); i != e; ++i)
1048 if (PredToDestList[i].second)
1049 DestPopularity[PredToDestList[i].second]++;
1054 unsigned Popularity = DPI->second;
1057 for (++DPI; DPI != DestPopularity.
end(); ++DPI) {
1060 if (DPI->second < Popularity)
1062 else if (DPI->second == Popularity) {
1067 SamePopularity.
clear();
1068 MostPopularDest = DPI->first;
1069 Popularity = DPI->second;
1077 if (!SamePopularity.
empty()) {
1078 SamePopularity.
push_back(MostPopularDest);
1080 for (
unsigned i = 0; ; ++i) {
1083 if (std::find(SamePopularity.
begin(), SamePopularity.
end(),
1093 return MostPopularDest;
1096 bool JumpThreading::ProcessThreadableEdges(
Value *Cond,
BasicBlock *BB,
1101 if (LoopHeaders.count(BB))
1104 PredValueInfoTy PredValues;
1105 if (!ComputeValueKnownInPredecessors(Cond, BB, PredValues, Preference, CxtI))
1108 assert(!PredValues.empty() &&
1109 "ComputeValueKnownInPredecessors returned true with no values");
1112 for (
unsigned i = 0, e = PredValues.size(); i != e; ++i) {
1113 dbgs() <<
" BB '" << BB->
getName() <<
"': FOUND condition = "
1114 << *PredValues[i].first
1115 <<
" for pred '" << PredValues[i].second->getName() <<
"'.\n";
1128 for (
unsigned i = 0, e = PredValues.size(); i != e; ++i) {
1130 if (!SeenPreds.insert(Pred).second)
1138 Constant *Val = PredValues[i].first;
1141 if (isa<UndefValue>(Val))
1146 DestBB =
SI->findCaseValue(cast<ConstantInt>(Val)).getCaseSuccessor();
1149 &&
"Unexpected terminator");
1150 DestBB = cast<BlockAddress>(Val)->getBasicBlock();
1154 if (PredToDestList.
empty())
1156 else if (OnlyDest != DestBB)
1157 OnlyDest = MultipleDestSentinel;
1159 PredToDestList.
push_back(std::make_pair(Pred, DestBB));
1163 if (PredToDestList.
empty())
1172 if (MostPopularDest == MultipleDestSentinel)
1178 for (
unsigned i = 0, e = PredToDestList.
size(); i != e; ++i)
1179 if (PredToDestList[i].second == MostPopularDest) {
1193 if (!MostPopularDest)
1198 return ThreadEdge(BB, PredsToFactor, MostPopularDest);
1205 bool JumpThreading::ProcessBranchOnPHI(
PHINode *PN) {
1220 if (PredBr->isUnconditional()) {
1221 PredBBs[0] = PredBB;
1223 if (DuplicateCondBranchOnPHIIntoPred(BB, PredBBs))
1246 if (!isa<PHINode>(BB->
front()))
1267 PredValueInfoTy XorOpValues;
1269 if (!ComputeValueKnownInPredecessors(BO->
getOperand(0), BB, XorOpValues,
1271 assert(XorOpValues.empty());
1272 if (!ComputeValueKnownInPredecessors(BO->
getOperand(1), BB, XorOpValues,
1278 assert(!XorOpValues.empty() &&
1279 "ComputeValueKnownInPredecessors returned true with no values");
1283 unsigned NumTrue = 0, NumFalse = 0;
1284 for (
unsigned i = 0, e = XorOpValues.size(); i != e; ++i) {
1285 if (isa<UndefValue>(XorOpValues[i].first))
1288 if (cast<ConstantInt>(XorOpValues[i].first)->isZero())
1296 if (NumTrue > NumFalse)
1298 else if (NumTrue != 0 || NumFalse != 0)
1304 for (
unsigned i = 0, e = XorOpValues.size(); i != e; ++i) {
1305 if (XorOpValues[i].first != SplitVal &&
1306 !isa<UndefValue>(XorOpValues[i].first))
1309 BlocksToFoldInto.
push_back(XorOpValues[i].second);
1314 if (BlocksToFoldInto.size() ==
1315 cast<PHINode>(BB->
front()).getNumIncomingValues()) {
1320 }
else if (SplitVal->
isZero()) {
1333 return DuplicateCondBranchOnPHIIntoPred(BB, BlocksToFoldInto);
1351 if (
Instruction *Inst = dyn_cast<Instruction>(IV)) {
1353 if (I != ValueMap.
end())
1364 bool JumpThreading::ThreadEdge(
BasicBlock *BB,
1370 <<
"' - would thread to self!\n");
1376 if (LoopHeaders.count(BB)) {
1378 <<
"' to dest BB '" << SuccBB->
getName()
1379 <<
"' - it might create an irreducible loop!\n");
1384 if (JumpThreadCost > BBDupThreshold) {
1386 <<
"' - Cost is too high: " << JumpThreadCost <<
"\n");
1392 if (PredBBs.
size() == 1)
1393 PredBB = PredBBs[0];
1396 <<
" common predecessors.\n");
1402 << SuccBB->
getName() <<
"' with cost: " << JumpThreadCost
1403 <<
", across block:\n "
1406 LVI->threadEdge(PredBB, BB, SuccBB);
1424 for (; !isa<TerminatorInst>(BI); ++BI) {
1428 ValueMapping[BI] = New;
1434 if (I != ValueMapping.
end())
1457 for (
Use &U : I->uses()) {
1459 if (
PHINode *UserPN = dyn_cast<PHINode>(User)) {
1460 if (UserPN->getIncomingBlock(U) == BB)
1469 if (UsesToRename.
empty())
1472 DEBUG(
dbgs() <<
"JT: Renaming non-local uses of: " << *I <<
"\n");
1477 SSAUpdate.
Initialize(I->getType(), I->getName());
1481 while (!UsesToRename.
empty())
1512 bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(
BasicBlock *BB,
1514 assert(!PredBBs.
empty() &&
"Can't handle an empty set");
1519 if (LoopHeaders.count(BB)) {
1521 <<
"' into predecessor block '" << PredBBs[0]->getName()
1522 <<
"' - it might create an irreducible loop!\n");
1527 if (DuplicationCost > BBDupThreshold) {
1529 <<
"' - Cost is too high: " << DuplicationCost <<
"\n");
1535 if (PredBBs.
size() == 1)
1536 PredBB = PredBBs[0];
1539 <<
" common predecessors.\n");
1545 DEBUG(
dbgs() <<
" Duplicating block '" << BB->
getName() <<
"' into end of '"
1546 << PredBB->
getName() <<
"' to eliminate branch on phi. Cost: "
1547 << DuplicationCost <<
" block is:" << *BB <<
"\n");
1553 if (!OldPredBranch || !OldPredBranch->isUnconditional()) {
1567 for (; BI != BB->
end(); ++BI) {
1574 if (I != ValueMapping.
end())
1584 ValueMapping[BI] = IV;
1589 ValueMapping[BI] = New;
1610 for (
Use &U : I->uses()) {
1611 Instruction *User = cast<Instruction>(U.getUser());
1612 if (
PHINode *UserPN = dyn_cast<PHINode>(User)) {
1613 if (UserPN->getIncomingBlock(U) == BB)
1622 if (UsesToRename.
empty())
1625 DEBUG(
dbgs() <<
"JT: Renaming non-local uses of: " << *I <<
"\n");
1630 SSAUpdate.Initialize(I->getType(), I->getName());
1631 SSAUpdate.AddAvailableValue(BB, I);
1632 SSAUpdate.AddAvailableValue(PredBB, ValueMapping[I]);
1634 while (!UsesToRename.
empty())
1644 OldPredBranch->eraseFromParent();
1668 CondLHS->getParent() != BB)
1671 for (
unsigned I = 0, E = CondLHS->getNumIncomingValues(); I != E; ++
I) {
1672 BasicBlock *Pred = CondLHS->getIncomingBlock(I);
1689 CondRHS, Pred, BB, CondCmp);
1692 CondRHS, Pred, BB, CondCmp);
1695 LHSFolds != RHSFolds) {
1706 BB->getParent(), BB);
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
This class is the base class for the comparison instructions.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
static IntegerType * getInt1Ty(LLVMContext &C)
Helper class for SSA formation on a set of values defined in multiple blocks.
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")
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
void initializeJumpThreadingPass(PassRegistry &)
DenseSet - This implements a dense probed hash-table based set.
unsigned getNumOperands() const
void DeleteDeadBlock(BasicBlock *BB)
DeleteDeadBlock - Delete the specified block, which must have no predecessors.
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
CallInst - This class represents a function call, abstracting a target machine's calling convention...
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr)
MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its predecessor is known to have...
const Function * getParent() const
Return the enclosing method, or null if none.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
SimplifyInstructionsInBlock - Scan the specified basic block and try to simplify any instructions in ...
const Instruction & front() const
LoadInst - an instruction for reading from memory.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
INITIALIZE_PASS_BEGIN(JumpThreading,"jump-threading","Jump Threading", false, false) INITIALIZE_PASS_END(JumpThreading
FunctionPass * createJumpThreadingPass(int Threshold=-1)
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
Instruction * getFirstNonPHIOrDbg()
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
BlockAddress - The address of a basic block.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isUnconditional() const
void push_back(NodeTy *val)
static void AddPHINodeEntriesForMappedBlock(BasicBlock *PHIBB, BasicBlock *OldPred, BasicBlock *NewPred, DenseMap< Instruction *, Value * > &ValueMap)
AddPHINodeEntriesForMappedBlock - We're adding 'NewPred' as a new predecessor to the PHIBB block...
SelectInst - This class represents the LLVM 'select' instruction.
static cl::opt< unsigned > BBDuplicateThreshold("jump-threading-threshold", cl::desc("Max block size to duplicate for jump threading"), cl::init(6), cl::Hidden)
UndefValue - 'undef' values are things that do not have specified contents.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
A Use represents the edge between a Value definition and its users.
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldTerminator - If a terminator instruction is predicated on a constant value, convert it into an unconditional branch to the constant destination.
#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...
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
void setName(const Twine &Name)
Change the name of the value.
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible. ...
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
BasicBlock * getSuccessor(unsigned i) const
void setSuccessor(unsigned idx, BasicBlock *B)
Update the specified successor to point at the provided block.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
static Constant * getKnownConstant(Value *Val, ConstantPreference Preference)
getKnownConstant - Helper method to determine if we can thread over a terminator with the given value...
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
initializer< Ty > init(const Ty &Val)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Subclasses of this class are all able to terminate a basic block.
void setDebugLoc(DebugLoc Loc)
setDebugLoc - Set the debug location information for this instruction.
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB)
TryToSimplifyUncondBranchFromEmptyBlock - BB is known to contain an unconditional branch...
BranchInst - Conditional or Unconditional Branch instruction.
static BlockAddress * get(Function *F, BasicBlock *BB)
get - Return a BlockAddress for the specified function and basic block.
This is an important base class in LLVM.
const Value * getCondition() const
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
IndirectBrInst - Indirect Branch Instruction.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
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...
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
getIncomingBlock - Return incoming basic block number i.
const InstListType & getInstList() const
Return the underlying instruction list container.
iterator insert(iterator where, NodeTy *New)
FunctionPass class - This class is used to implement most global optimizations.
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.
Predicate getPredicate() const
Return the predicate for this instruction.
bool pred_empty(const BasicBlock *BB)
static Constant * getNot(Constant *C)
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
static unsigned GetBestDestForJumpOnUndef(BasicBlock *BB)
GetBestDestForBranchOnUndef - If we determine that the specified block ends in an undefined jump...
Tristate
This is used to return true/false/dunno results.
bool isTerminator() const
bool isConditional() const
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void FindFunctionBackedges(const Function &F, SmallVectorImpl< std::pair< const BasicBlock *, const BasicBlock * > > &Result)
Analyze the specified function to find all of the loop backedges in the function and return them...
This is the shared class of boolean and integer constants.
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
Translate PHI node to its predecessor from the given basic block.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
Value * SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyCmpInst - Given operands for a CmpInst, see if we can fold the result.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
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)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
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...
const BasicBlock & getEntryBlock() const
static ConstantInt * getTrue(LLVMContext &Context)
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB, unsigned Threshold)
getJumpThreadDuplicationCost - Return the cost of duplicating this block to thread across it...
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getSinglePredecessor()
Return the predecessor of this block if it has a single predecessor block.
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)
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing basic block, but does not delete it...
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Value * getCondition() const
unsigned getAlignment() const
getAlignment - Return the alignment of the access that is being performed
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
getAAMetadata - Fills the AAMDNodes structure with AA metadata from this instruction.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool isLandingPad() const
Return true if this basic block is a landing pad.
bool hasOneUse() const
Return true if there is exactly one user of this value.
iterator find(const KeyT &Val)
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
SwitchInst - Multiway switch.
This pass computes, caches, and vends lazy value constraint information.
static BasicBlock * FindMostPopularDest(BasicBlock *BB, const SmallVectorImpl< std::pair< BasicBlock *, BasicBlock * > > &PredToDestList)
FindMostPopularDest - The specified list contains multiple possible threadable destinations.
Value * FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=6, AliasAnalysis *AA=nullptr, AAMDNodes *AATags=nullptr)
FindAvailableLoadedValue - Scan the ScanBB block backwards (starting at the instruction before ScanFr...
LLVMContext & getContext() const
Get the context in which this basic block lives.
void removeDeadConstantUsers() const
removeDeadConstantUsers - If there are any dead constant users dangling off of this constant...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static const Function * getParent(const Value *V)
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
SplitEdge - Split the edge connecting specified block.
const Value * getFalseValue() const
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...
bool removeUnreachableBlocks(Function &F)
Remove all blocks that can not be reached from the function's entry.
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.
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
static bool hasAddressTakenAndUsed(BasicBlock *BB)
const BasicBlock * getParent() const