14 #define DEBUG_TYPE "jump-threading"
41 STATISTIC(NumThreads,
"Number of jumps threaded");
42 STATISTIC(NumFolds,
"Number of terminators folded");
43 STATISTIC(NumDupes,
"Number of branch blocks duplicated to eliminate phi");
47 cl::desc(
"Max block size to duplicate for jump threading"),
90 struct RecursionSetRemover {
92 std::pair<Value*, BasicBlock*> ThePair;
94 RecursionSetRemover(
DenseSet<std::pair<Value*, BasicBlock*> > &S,
95 std::pair<Value*, BasicBlock*>
P)
96 : TheSet(S), ThePair(P) { }
98 ~RecursionSetRemover() {
99 TheSet.erase(ThePair);
120 bool DuplicateCondBranchOnPHIIntoPred(
BasicBlock *BB,
124 PredValueInfo &Result,
129 bool ProcessBranchOnPHI(
PHINode *PN);
132 bool SimplifyPartiallyRedundantLoad(
LoadInst *
LI);
139 "Jump Threading",
false,
false)
150 bool JumpThreading::runOnFunction(
Function &
F) {
152 TD = getAnalysisIfAvailable<DataLayout>();
153 TLI = &getAnalysis<TargetLibraryInfo>();
154 LVI = &getAnalysis<LazyValueInfo>();
158 bool Changed, EverChanged =
false;
164 while (ProcessBlock(BB))
175 LoopHeaders.erase(BB);
194 bool ErasedFromLoopHeaders = LoopHeaders.erase(BB);
209 if (ErasedFromLoopHeaders)
210 LoopHeaders.insert(BB);
213 EverChanged |= Changed;
233 for (; !isa<TerminatorInst>(
I); ++
I) {
236 if (Size > Threshold)
240 if (isa<DbgInfoIntrinsic>(I))
continue;
243 if (isa<BitCastInst>(I) && I->getType()->isPointerTy())
253 if (
const CallInst *CI = dyn_cast<CallInst>(I)) {
258 else if (!isa<IntrinsicInst>(CI))
260 else if (!CI->getType()->isVectorTy())
267 if (isa<SwitchInst>(I))
268 Size = Size > 6 ? Size-6 : 0;
271 if (isa<IndirectBrInst>(I))
272 Size = Size > 8 ? Size-8 : 0;
292 void JumpThreading::FindLoopHeaders(
Function &F) {
296 for (
unsigned i = 0, e = Edges.
size(); i != e; ++i)
297 LoopHeaders.insert(const_cast<BasicBlock*>(Edges[i].second));
310 if (
UndefValue *U = dyn_cast<UndefValue>(Val))
313 if (Preference == WantBlockAddress)
327 ComputeValueKnownInPredecessors(
Value *V,
BasicBlock *BB, PredValueInfo &Result,
333 if (!RecursionSet.insert(std::make_pair(V, BB)).second)
338 RecursionSetRemover remover(RecursionSet, std::make_pair(V, BB));
343 Result.push_back(std::make_pair(KC, *PI));
370 Constant *PredCst = LVI->getConstantOnEdge(V, P, BB);
372 Result.push_back(std::make_pair(KC, P));
375 return !Result.empty();
379 if (
PHINode *PN = dyn_cast<PHINode>(I)) {
380 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
381 Value *InVal = PN->getIncomingValue(i);
383 Result.push_back(std::make_pair(KC, PN->getIncomingBlock(i)));
385 Constant *CI = LVI->getConstantOnEdge(InVal,
386 PN->getIncomingBlock(i), BB);
388 Result.push_back(std::make_pair(KC, PN->getIncomingBlock(i)));
392 return !Result.empty();
395 PredValueInfoTy LHSVals, RHSVals;
399 assert(Preference == WantInteger &&
"One-bit non-integer type?");
404 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, LHSVals,
406 ComputeValueKnownInPredecessors(I->
getOperand(1), BB, RHSVals,
409 if (LHSVals.empty() && RHSVals.empty())
422 for (
unsigned i = 0, e = LHSVals.size(); i != e; ++i)
423 if (LHSVals[i].first == InterestingVal ||
424 isa<UndefValue>(LHSVals[i].first)) {
425 Result.push_back(LHSVals[i]);
426 Result.back().first = InterestingVal;
427 LHSKnownBBs.insert(LHSVals[i].second);
429 for (
unsigned i = 0, e = RHSVals.size(); i != e; ++i)
430 if (RHSVals[i].first == InterestingVal ||
431 isa<UndefValue>(RHSVals[i].first)) {
434 if (!LHSKnownBBs.count(RHSVals[i].second)) {
435 Result.push_back(RHSVals[i]);
436 Result.back().first = InterestingVal;
440 return !Result.empty();
446 cast<ConstantInt>(I->
getOperand(1))->isOne()) {
447 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, Result,
453 for (
unsigned i = 0, e = Result.size(); i != e; ++i)
461 assert(Preference != WantBlockAddress
462 &&
"A binary operator creating a block address?");
463 if (
ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1))) {
464 PredValueInfoTy LHSVals;
465 ComputeValueKnownInPredecessors(BO->getOperand(0), BB, LHSVals,
469 for (
unsigned i = 0, e = LHSVals.size(); i != e; ++i) {
474 Result.push_back(std::make_pair(KC, LHSVals[i].second));
478 return !Result.empty();
482 if (
CmpInst *Cmp = dyn_cast<CmpInst>(I)) {
483 assert(Preference == WantInteger &&
"Compares only produce integers");
495 if (!isa<Constant>(RHS))
499 ResT = LVI->getPredicateOnEdge(Cmp->getPredicate(), LHS,
500 cast<Constant>(RHS), PredBB, BB);
507 Result.push_back(std::make_pair(KC, PredBB));
510 return !Result.empty();
516 if (isa<Constant>(Cmp->getOperand(1)) && Cmp->getType()->isIntegerTy()) {
517 if (!isa<Instruction>(Cmp->getOperand(0)) ||
518 cast<Instruction>(Cmp->getOperand(0))->
getParent() != BB) {
519 Constant *RHSCst = cast<Constant>(Cmp->getOperand(1));
526 LVI->getPredicateOnEdge(Cmp->getPredicate(), Cmp->getOperand(0),
532 Result.push_back(std::make_pair(ResC, P));
535 return !Result.empty();
540 if (
Constant *CmpConst = dyn_cast<Constant>(Cmp->getOperand(1))) {
541 PredValueInfoTy LHSVals;
542 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, LHSVals,
545 for (
unsigned i = 0, e = LHSVals.size(); i != e; ++i) {
550 Result.push_back(std::make_pair(KC, LHSVals[i].second));
553 return !Result.empty();
558 if (
SelectInst *SI = dyn_cast<SelectInst>(I)) {
563 PredValueInfoTy Conds;
564 if ((TrueVal || FalseVal) &&
565 ComputeValueKnownInPredecessors(SI->getCondition(), BB, Conds,
567 for (
unsigned i = 0, e = Conds.size(); i != e; ++i) {
572 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Cond)) {
574 KnownCond = CI->isOne();
576 assert(isa<UndefValue>(Cond) &&
"Unexpected condition value");
580 KnownCond = (TrueVal != 0);
584 if (
Constant *Val = KnownCond ? TrueVal : FalseVal)
585 Result.push_back(std::make_pair(Val, Conds[i].second));
588 return !Result.empty();
593 Constant *CI = LVI->getConstant(V, BB);
596 Result.push_back(std::make_pair(KC, *PI));
599 return !Result.empty();
612 unsigned MinSucc = 0;
619 if (NumPreds < MinNumPreds) {
621 MinNumPreds = NumPreds;
640 bool JumpThreading::ProcessBlock(
BasicBlock *BB) {
652 if (SinglePred->getTerminator()->getNumSuccessors() == 1 &&
655 if (LoopHeaders.erase(SinglePred))
656 LoopHeaders.insert(BB);
660 bool isEntry = SinglePred == &SinglePred->getParent()->getEntryBlock();
661 LVI->eraseBlock(SinglePred);
677 if (
BranchInst *BI = dyn_cast<BranchInst>(Terminator)) {
681 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(Terminator)) {
682 Condition = SI->getCondition();
683 }
else if (
IndirectBrInst *IB = dyn_cast<IndirectBrInst>(Terminator)) {
685 if (IB->getNumSuccessors() == 0)
return false;
687 Preference = WantBlockAddress;
694 if (
Instruction *I = dyn_cast<Instruction>(Condition)) {
699 Condition = SimpleVal;
705 if (isa<UndefValue>(Condition)) {
711 if (i == BestSucc)
continue;
716 <<
"' folding undef terminator: " << *BBTerm <<
'\n');
727 <<
"' folding terminator: " << *BB->
getTerminator() <<
'\n');
738 if (ProcessThreadableEdges(Condition, BB, Preference))
744 if (
CmpInst *CondCmp = dyn_cast<CmpInst>(CondInst)) {
751 if (CondBr && CondConst && CondBr->
isConditional() && PI != PE &&
752 (!isa<Instruction>(CondCmp->getOperand(0)) ||
753 cast<Instruction>(CondCmp->getOperand(0))->
getParent() != BB)) {
759 LVI->getPredicateOnEdge(CondCmp->getPredicate(), CondCmp->getOperand(0),
765 LVI->getPredicateOnEdge(CondCmp->getPredicate(),
766 CondCmp->getOperand(0), CondConst, *PI, BB);
767 if (Ret != Baseline)
break;
783 if (CondBr && CondConst && TryToUnfoldSelect(CondCmp, BB))
792 Value *SimplifyValue = CondInst;
793 if (
CmpInst *CondCmp = dyn_cast<CmpInst>(SimplifyValue))
794 if (isa<Constant>(CondCmp->getOperand(1)))
795 SimplifyValue = CondCmp->getOperand(0);
799 if (
LoadInst *
LI = dyn_cast<LoadInst>(SimplifyValue))
800 if (SimplifyPartiallyRedundantLoad(
LI))
808 if (ProcessThreadableEdges(CondInst, BB, Preference))
813 if (
PHINode *PN = dyn_cast<PHINode>(CondInst))
815 return ProcessBranchOnPHI(PN);
821 return ProcessBranchOnXOR(cast<BinaryOperator>(CondInst));
834 bool JumpThreading::SimplifyPartiallyRedundantLoad(
LoadInst *
LI) {
854 if (
Instruction *PtrOp = dyn_cast<Instruction>(LoadedPtr))
855 if (PtrOp->getParent() == LoadBB)
862 if (
Value *AvailableVal =
879 if (BBIt != LoadBB->
begin())
888 AvailablePredsTy AvailablePreds;
898 if (!PredsScanned.
insert(PredBB))
902 BBIt = PredBB->
end();
906 if (!PredAvailable) {
907 OneUnavailablePred = PredBB;
912 if (TBAATag != ThisTBAATag) TBAATag = 0;
916 AvailablePreds.push_back(std::make_pair(PredBB, PredAvailable));
921 if (AvailablePreds.empty())
return false;
933 if (PredsScanned.
size() == AvailablePreds.size()+1 &&
935 UnavailablePred = OneUnavailablePred;
936 }
else if (PredsScanned.
size() != AvailablePreds.size()) {
942 for (
unsigned i = 0, e = AvailablePreds.size(); i != e; ++i)
943 AvailablePredSet.
insert(AvailablePreds[i].first);
953 if (!AvailablePredSet.
count(P))
965 if (UnavailablePred) {
967 "Can't handle critical edge here!");
975 AvailablePreds.push_back(std::make_pair(UnavailablePred, NewVal));
993 AvailablePredsTy::iterator I =
994 std::lower_bound(AvailablePreds.begin(), AvailablePreds.end(),
995 std::make_pair(P, (
Value*)0));
997 assert(I != AvailablePreds.end() && I->first == P &&
998 "Didn't find entry for predecessor!");
1018 assert(!PredToDestList.empty());
1025 for (
unsigned i = 0, e = PredToDestList.size(); i != e; ++i)
1026 if (PredToDestList[i].second)
1027 DestPopularity[PredToDestList[i].second]++;
1032 unsigned Popularity = DPI->second;
1035 for (++DPI; DPI != DestPopularity.
end(); ++DPI) {
1038 if (DPI->second < Popularity)
1040 else if (DPI->second == Popularity) {
1045 SamePopularity.
clear();
1046 MostPopularDest = DPI->first;
1047 Popularity = DPI->second;
1055 if (!SamePopularity.
empty()) {
1056 SamePopularity.
push_back(MostPopularDest);
1058 for (
unsigned i = 0; ; ++i) {
1061 if (std::find(SamePopularity.
begin(), SamePopularity.
end(),
1071 return MostPopularDest;
1074 bool JumpThreading::ProcessThreadableEdges(
Value *Cond,
BasicBlock *BB,
1078 if (LoopHeaders.count(BB))
1081 PredValueInfoTy PredValues;
1082 if (!ComputeValueKnownInPredecessors(Cond, BB, PredValues, Preference))
1085 assert(!PredValues.empty() &&
1086 "ComputeValueKnownInPredecessors returned true with no values");
1089 for (
unsigned i = 0, e = PredValues.size(); i != e; ++i) {
1090 dbgs() <<
" BB '" << BB->
getName() <<
"': FOUND condition = "
1091 << *PredValues[i].first
1092 <<
" for pred '" << PredValues[i].second->getName() <<
"'.\n";
1105 for (
unsigned i = 0, e = PredValues.size(); i != e; ++i) {
1107 if (!SeenPreds.insert(Pred))
1115 Constant *Val = PredValues[i].first;
1118 if (isa<UndefValue>(Val))
1123 DestBB = SI->findCaseValue(cast<ConstantInt>(Val)).getCaseSuccessor();
1126 &&
"Unexpected terminator");
1127 DestBB = cast<BlockAddress>(Val)->getBasicBlock();
1131 if (PredToDestList.
empty())
1133 else if (OnlyDest != DestBB)
1134 OnlyDest = MultipleDestSentinel;
1136 PredToDestList.
push_back(std::make_pair(Pred, DestBB));
1140 if (PredToDestList.
empty())
1149 if (MostPopularDest == MultipleDestSentinel)
1155 for (
unsigned i = 0, e = PredToDestList.
size(); i != e; ++i)
1156 if (PredToDestList[i].second == MostPopularDest) {
1170 if (MostPopularDest == 0)
1175 return ThreadEdge(BB, PredsToFactor, MostPopularDest);
1182 bool JumpThreading::ProcessBranchOnPHI(
PHINode *PN) {
1197 if (PredBr->isUnconditional()) {
1198 PredBBs[0] = PredBB;
1200 if (DuplicateCondBranchOnPHIIntoPred(BB, PredBBs))
1223 if (!isa<PHINode>(BB->
front()))
1244 PredValueInfoTy XorOpValues;
1246 if (!ComputeValueKnownInPredecessors(BO->
getOperand(0), BB, XorOpValues,
1248 assert(XorOpValues.empty());
1249 if (!ComputeValueKnownInPredecessors(BO->
getOperand(1), BB, XorOpValues,
1255 assert(!XorOpValues.empty() &&
1256 "ComputeValueKnownInPredecessors returned true with no values");
1260 unsigned NumTrue = 0, NumFalse = 0;
1261 for (
unsigned i = 0, e = XorOpValues.size(); i != e; ++i) {
1262 if (isa<UndefValue>(XorOpValues[i].first))
1265 if (cast<ConstantInt>(XorOpValues[i].first)->isZero())
1273 if (NumTrue > NumFalse)
1275 else if (NumTrue != 0 || NumFalse != 0)
1281 for (
unsigned i = 0, e = XorOpValues.size(); i != e; ++i) {
1282 if (XorOpValues[i].first != SplitVal &&
1283 !isa<UndefValue>(XorOpValues[i].first))
1286 BlocksToFoldInto.
push_back(XorOpValues[i].second);
1291 if (BlocksToFoldInto.size() ==
1292 cast<PHINode>(BB->
front()).getNumIncomingValues()) {
1293 if (SplitVal == 0) {
1297 }
else if (SplitVal->
isZero()) {
1310 return DuplicateCondBranchOnPHIIntoPred(BB, BlocksToFoldInto);
1328 if (
Instruction *Inst = dyn_cast<Instruction>(IV)) {
1330 if (I != ValueMap.
end())
1341 bool JumpThreading::ThreadEdge(
BasicBlock *BB,
1347 <<
"' - would thread to self!\n");
1353 if (LoopHeaders.count(BB)) {
1355 <<
"' to dest BB '" << SuccBB->
getName()
1356 <<
"' - it might create an irreducible loop!\n");
1363 <<
"' - Cost is too high: " << JumpThreadCost <<
"\n");
1369 if (PredBBs.
size() == 1)
1370 PredBB = PredBBs[0];
1373 <<
" common predecessors.\n");
1379 << SuccBB->
getName() <<
"' with cost: " << JumpThreadCost
1380 <<
", across block:\n "
1383 LVI->threadEdge(PredBB, BB, SuccBB);
1401 for (; !isa<TerminatorInst>(BI); ++BI) {
1405 ValueMapping[BI] = New;
1411 if (I != ValueMapping.
end())
1437 if (
PHINode *UserPN = dyn_cast<PHINode>(User)) {
1438 if (UserPN->getIncomingBlock(UI) == BB)
1447 if (UsesToRename.
empty())
1450 DEBUG(
dbgs() <<
"JT: Renaming non-local uses of: " << *I <<
"\n");
1455 SSAUpdate.
Initialize(I->getType(), I->getName());
1459 while (!UsesToRename.
empty())
1490 bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(
BasicBlock *BB,
1492 assert(!PredBBs.
empty() &&
"Can't handle an empty set");
1497 if (LoopHeaders.count(BB)) {
1499 <<
"' into predecessor block '" << PredBBs[0]->getName()
1500 <<
"' - it might create an irreducible loop!\n");
1507 <<
"' - Cost is too high: " << DuplicationCost <<
"\n");
1513 if (PredBBs.
size() == 1)
1514 PredBB = PredBBs[0];
1517 <<
" common predecessors.\n");
1523 DEBUG(
dbgs() <<
" Duplicating block '" << BB->
getName() <<
"' into end of '"
1524 << PredBB->
getName() <<
"' to eliminate branch on phi. Cost: "
1525 << DuplicationCost <<
" block is:" << *BB <<
"\n");
1531 if (OldPredBranch == 0 || !OldPredBranch->isUnconditional()) {
1546 for (; BI != BB->
end(); ++BI) {
1553 if (I != ValueMapping.
end())
1562 ValueMapping[BI] = IV;
1567 ValueMapping[BI] = New;
1591 if (
PHINode *UserPN = dyn_cast<PHINode>(User)) {
1592 if (UserPN->getIncomingBlock(UI) == BB)
1601 if (UsesToRename.
empty())
1604 DEBUG(
dbgs() <<
"JT: Renaming non-local uses of: " << *I <<
"\n");
1609 SSAUpdate.Initialize(I->getType(), I->getName());
1610 SSAUpdate.AddAvailableValue(BB, I);
1611 SSAUpdate.AddAvailableValue(PredBB, ValueMapping[I]);
1613 while (!UsesToRename.
empty())
1623 OldPredBranch->eraseFromParent();
1647 CondLHS->getParent() != BB)
1650 for (
unsigned I = 0, E = CondLHS->getNumIncomingValues(); I != E; ++
I) {
1651 BasicBlock *Pred = CondLHS->getIncomingBlock(I);
1674 LHSFolds != RHSFolds) {
void push_back(const T &Elt)
static ConstantInt * getFalse(LLVMContext &Context)
Abstract base class of comparison instructions.
AnalysisUsage & addPreserved()
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, Pass *P)
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)
static PassRegistry * getPassRegistry()
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
void initializeJumpThreadingPass(PassRegistry &)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getNumOperands() const
void DeleteDeadBlock(BasicBlock *BB)
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, Pass *P=0)
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
MDNode - a tuple of other values.
static cl::opt< unsigned > Threshold("jump-threading-threshold", cl::desc("Max block size to duplicate for jump threading"), cl::init(6), cl::Hidden)
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
INITIALIZE_PASS_BEGIN(JumpThreading,"jump-threading","Jump Threading", false, false) INITIALIZE_PASS_END(JumpThreading
LoopInfoBase< BlockT, LoopT > * LI
StringRef getName() const
Instruction * getFirstNonPHIOrDbg()
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
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)
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=0)
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc. to it.
void setName(const Twine &Name)
ID
LLVM Calling Convention Representation.
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, Pass *P=0)
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
BasicBlock * getSuccessor(unsigned i) const
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0)
void setSuccessor(unsigned idx, BasicBlock *B)
void replaceAllUsesWith(Value *V)
static Constant * getKnownConstant(Value *Val, ConstantPreference Preference)
unsigned getNumIncomingValues() const
bool SimplifyInstructionsInBlock(BasicBlock *BB, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0)
unsigned getNumSuccessors() const
initializer< Ty > init(const Ty &Val)
void array_pod_sort(IteratorTy Start, IteratorTy End)
FunctionPass * createJumpThreadingPass()
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB)
static BlockAddress * get(Function *F, BasicBlock *BB)
get - Return a BlockAddress for the specified function and basic block.
LLVM Constant Representation.
const Value * getCondition() const
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Interval::pred_iterator pred_begin(Interval *I)
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
BasicBlock * getIncomingBlock(unsigned i) const
const InstListType & getInstList() const
Return the underlying instruction list container.
iterator insert(iterator where, NodeTy *New)
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
Predicate getPredicate() const
Return the predicate for this instruction.
static Constant * getNot(Constant *C)
static UndefValue * get(Type *T)
Value * SimplifyInstruction(Instruction *I, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
Call cannot be duplicated.
static unsigned GetBestDestForJumpOnUndef(BasicBlock *BB)
Tristate
Tristate - This is used to return true/false/dunno results.
bool isTerminator() const
bool isConditional() const
static bool isZero(Value *V, DataLayout *DL)
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
void FindFunctionBackedges(const Function &F, SmallVectorImpl< std::pair< const BasicBlock *, const BasicBlock * > > &Result)
Class for constant integers.
Value * FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=6, AliasAnalysis *AA=0, MDNode **TBAATag=0)
Value * getIncomingValue(unsigned i) const
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
MDNode * getMetadata(unsigned KindID) const
Value * stripPointerCasts()
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
const BasicBlock & getEntryBlock() const
Value * SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=0)
static ConstantInt * getTrue(LLVMContext &Context)
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB, unsigned Threshold)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getSinglePredecessor()
Return this block if it has a single predecessor block. Otherwise return a null pointer.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Value * getCondition() const
unsigned getAlignment() const
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.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=0, BasicBlock *InsertBefore=0)
Creates a new BasicBlock.
unsigned getPrimitiveSizeInBits() const
static BasicBlock * FindMostPopularDest(BasicBlock *BB, const SmallVectorImpl< std::pair< BasicBlock *, BasicBlock * > > &PredToDestList)
LLVMContext & getContext() const
Get the context in which this basic block lives.
void removeDeadConstantUsers() const
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)
const Value * getFalseValue() const
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2)
Return an ICmp or FCmp comparison operator constant expression.
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
iterator find(const KeyT &Val)
static bool hasAddressTakenAndUsed(BasicBlock *BB)
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
const BasicBlock * getParent() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
STATISTIC(NumThreads,"Number of jumps threaded")