57 using namespace llvm::gvn;
58 using namespace llvm::VNCoercion;
59 using namespace PatternMatch;
61 #define DEBUG_TYPE "gvn"
63 STATISTIC(NumGVNInstr,
"Number of instructions deleted");
64 STATISTIC(NumGVNLoad,
"Number of loads deleted");
65 STATISTIC(NumGVNPRE,
"Number of instructions PRE'd");
66 STATISTIC(NumGVNBlocks,
"Number of blocks merged");
67 STATISTIC(NumGVNSimpl,
"Number of instructions simplified");
68 STATISTIC(NumGVNEqProp,
"Number of equalities propagated");
69 STATISTIC(NumPRELoad,
"Number of loads PRE'd");
78 cl::desc(
"Max recurse depth (default = 1000)"));
88 if (opcode != other.
opcode)
90 if (opcode == ~0U || opcode == ~1U)
92 if (type != other.
type)
143 Res.
Val.setPointer(V);
144 Res.
Val.setInt(SimpleVal);
151 Res.
Val.setPointer(MI);
152 Res.
Val.setInt(MemIntrin);
159 Res.
Val.setPointer(LI);
160 Res.
Val.setInt(LoadVal);
167 Res.
Val.setPointer(
nullptr);
168 Res.
Val.setInt(UndefVal);
179 assert(isSimpleValue() &&
"Wrong accessor");
180 return Val.getPointer();
184 assert(isCoercedLoadValue() &&
"Wrong accessor");
185 return cast<LoadInst>(Val.getPointer());
189 assert(isMemIntrinValue() &&
"Wrong accessor");
190 return cast<MemIntrinsic>(Val.getPointer());
211 Res.
AV = std::move(AV);
226 return AV.MaterializeAdjustedValue(LI, BB->getTerminator(), gvn);
240 e.varargs.push_back(lookupOrAdd(*OI));
247 if (e.varargs[0] > e.varargs[1])
251 if (
CmpInst *
C = dyn_cast<CmpInst>(I)) {
254 if (e.varargs[0] > e.varargs[1]) {
258 e.opcode = (
C->getOpcode() << 8) | Predicate;
262 e.varargs.push_back(*II);
271 assert((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) &&
272 "Not a comparison!");
275 e.varargs.push_back(lookupOrAdd(LHS));
276 e.varargs.push_back(lookupOrAdd(RHS));
279 if (e.varargs[0] > e.varargs[1]) {
283 e.opcode = (Opcode << 8) | Predicate;
288 assert(EI &&
"Not an ExtractValueInst?");
299 case Intrinsic::sadd_with_overflow:
300 case Intrinsic::uadd_with_overflow:
303 case Intrinsic::ssub_with_overflow:
304 case Intrinsic::usub_with_overflow:
305 e.opcode = Instruction::Sub;
307 case Intrinsic::smul_with_overflow:
308 case Intrinsic::umul_with_overflow:
309 e.opcode = Instruction::Mul;
318 "Expect two args for recognised intrinsics.");
330 e.varargs.push_back(lookupOrAdd(*OI));
334 e.varargs.push_back(*II);
350 valueNumbering.insert(std::make_pair(V, num));
354 if (AA->doesNotAccessMemory(C)) {
356 uint32_t &e = expressionNumbering[exp];
357 if (!e) e = nextValueNumber++;
358 valueNumbering[
C] = e;
360 }
else if (AA->onlyReadsMemory(C)) {
361 Expression exp = createExpr(C);
362 uint32_t &e = expressionNumbering[exp];
364 e = nextValueNumber++;
365 valueNumbering[
C] = e;
369 e = nextValueNumber++;
370 valueNumbering[
C] = e;
377 valueNumbering[
C] = nextValueNumber;
378 return nextValueNumber++;
381 if (local_dep.
isDef()) {
385 valueNumbering[
C] = nextValueNumber;
386 return nextValueNumber++;
393 valueNumbering[
C] = nextValueNumber;
394 return nextValueNumber++;
398 uint32_t v = lookupOrAdd(local_cdep);
399 valueNumbering[
C] = v;
411 for (
unsigned i = 0, e = deps.size(); i != e; ++i) {
426 cdep = NonLocalDepCall;
435 valueNumbering[
C] = nextValueNumber;
436 return nextValueNumber++;
440 valueNumbering[
C] = nextValueNumber;
441 return nextValueNumber++;
447 valueNumbering[
C] = nextValueNumber;
448 return nextValueNumber++;
453 valueNumbering[
C] = v;
457 valueNumbering[
C] = nextValueNumber;
458 return nextValueNumber++;
469 if (VI != valueNumbering.end())
472 if (!isa<Instruction>(V)) {
473 valueNumbering[V] = nextValueNumber;
474 return nextValueNumber++;
481 return lookupOrAddCall(cast<CallInst>(I));
483 case Instruction::FAdd:
484 case Instruction::Sub:
485 case Instruction::FSub:
486 case Instruction::Mul:
487 case Instruction::FMul:
488 case Instruction::UDiv:
489 case Instruction::SDiv:
490 case Instruction::FDiv:
491 case Instruction::URem:
492 case Instruction::SRem:
493 case Instruction::FRem:
494 case Instruction::Shl:
495 case Instruction::LShr:
496 case Instruction::AShr:
497 case Instruction::And:
498 case Instruction::Or:
499 case Instruction::Xor:
500 case Instruction::ICmp:
501 case Instruction::FCmp:
502 case Instruction::Trunc:
503 case Instruction::ZExt:
504 case Instruction::SExt:
505 case Instruction::FPToUI:
506 case Instruction::FPToSI:
507 case Instruction::UIToFP:
508 case Instruction::SIToFP:
509 case Instruction::FPTrunc:
510 case Instruction::FPExt:
511 case Instruction::PtrToInt:
512 case Instruction::IntToPtr:
513 case Instruction::BitCast:
515 case Instruction::ExtractElement:
516 case Instruction::InsertElement:
517 case Instruction::ShuffleVector:
518 case Instruction::InsertValue:
519 case Instruction::GetElementPtr:
522 case Instruction::ExtractValue:
523 exp = createExtractvalueExpr(cast<ExtractValueInst>(I));
526 valueNumbering[V] = nextValueNumber;
527 return nextValueNumber++;
530 uint32_t& e = expressionNumbering[exp];
531 if (!e) e = nextValueNumber++;
532 valueNumbering[V] = e;
540 assert(VI != valueNumbering.end() &&
"Value not numbered?");
551 Expression exp = createCmpExpr(Opcode, Predicate, LHS, RHS);
552 uint32_t& e = expressionNumbering[exp];
553 if (!e) e = nextValueNumber++;
559 valueNumbering.clear();
560 expressionNumbering.clear();
566 valueNumbering.erase(V);
573 I = valueNumbering.begin(),
E = valueNumbering.end(); I !=
E; ++
I) {
574 assert(I->first != V &&
"Inst still occurs in value numbering map!");
594 bool Changed = runImpl(F, AC, DT, TLI, AA, &MemDep, LI, &ORE);
604 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
608 E = d.
end(); I !=
E; ++
I) {
609 errs() << I->first <<
"\n";
634 std::pair<DenseMap<BasicBlock*, char>::iterator,
char> IV =
635 FullyAvailableBlocks.
insert(std::make_pair(BB, 2));
641 if (IV.first->second == 2)
642 IV.first->second = 3;
643 return IV.first->second != 0;
651 goto SpeculationFailure;
653 for (; PI != PE; ++PI)
658 goto SpeculationFailure;
666 char &BBVal = FullyAvailableBlocks[BB];
684 char &EntryVal = FullyAvailableBlocks[Entry];
685 if (EntryVal == 0)
continue;
691 }
while (!BBWorklist.
empty());
707 if (ValuesPerBlock.
size() == 1 &&
710 assert(!ValuesPerBlock[0].AV.isUndefValue() &&
711 "Dead BB dominate this block");
712 return ValuesPerBlock[0].MaterializeAdjustedValue(LI, gvn);
739 if (isSimpleValue()) {
740 Res = getSimpleValue();
741 if (Res->
getType() != LoadTy) {
745 << *getSimpleValue() <<
'\n'
746 << *Res <<
'\n' <<
"\n\n\n");
748 }
else if (isCoercedLoadValue()) {
760 DEBUG(
dbgs() <<
"GVN COERCED NONLOCAL LOAD:\nOffset: " << Offset <<
" "
761 << *getCoercedLoadValue() <<
'\n'
765 }
else if (isMemIntrinValue()) {
769 <<
" " << *getMemIntrinValue() <<
'\n'
770 << *Res <<
'\n' <<
"\n\n\n");
772 assert(isUndefValue() &&
"Should be UndefVal");
773 DEBUG(
dbgs() <<
"GVN COERCED NONLOCAL Undef:\n";);
776 assert(Res &&
"failed to materialize?");
782 return II->getIntrinsicID() == Intrinsic::lifetime_start;
792 User *OtherAccess =
nullptr;
795 R <<
"load of type " <<
NV(
"Type", LI->
getType()) <<
" not eliminated"
799 if (U != LI && (isa<LoadInst>(U) || isa<StoreInst>(U)) &&
800 DT->
dominates(cast<Instruction>(U), LI)) {
805 OtherAccess =
nullptr;
811 R <<
" in favor of " <<
NV(
"OtherAccess", OtherAccess);
813 R <<
" because it is clobbered by " <<
NV(
"ClobberedBy", DepInfo.
getInst());
822 "expected a local dependence");
833 if (Address && LI->
isAtomic() <= DepSI->isAtomic()) {
837 Res = AvailableValue::get(DepSI->getValueOperand(),
Offset);
851 if (DepLI != LI && Address && LI->
isAtomic() <= DepLI->isAtomic()) {
856 Res = AvailableValue::getLoad(DepLI, Offset);
869 Res = AvailableValue::getMI(DepMI, Offset);
877 dbgs() <<
"GVN: load ";
880 dbgs() <<
" is clobbered by " << *I <<
'\n';
906 if (
StoreInst *S = dyn_cast<StoreInst>(DepInst)) {
910 if (S->getValueOperand()->getType() != LI->
getType() &&
919 Res = AvailableValue::get(S->getValueOperand());
923 if (
LoadInst *
LD = dyn_cast<LoadInst>(DepInst)) {
935 Res = AvailableValue::getLoad(
LD);
942 dbgs() <<
"GVN: load ";
944 dbgs() <<
" has unknown def " << *DepInst <<
'\n';
949 void GVN::AnalyzeLoadAvailability(
LoadInst *LI, LoadDepVect &Deps,
950 AvailValInBlkVect &ValuesPerBlock,
951 UnavailBlkVect &UnavailableBlocks) {
957 unsigned NumDeps = Deps.size();
958 for (
unsigned i = 0, e = NumDeps; i != e; ++i) {
962 if (DeadBlocks.count(DepBB)) {
965 ValuesPerBlock.push_back(AvailableValueInBlock::getUndef(DepBB));
970 UnavailableBlocks.push_back(DepBB);
977 Value *Address = Deps[i].getAddress();
980 if (AnalyzeLoadAvailability(LI, DepInfo, Address, AV)) {
984 ValuesPerBlock.push_back(AvailableValueInBlock::get(DepBB,
987 UnavailableBlocks.push_back(DepBB);
991 assert(NumDeps == ValuesPerBlock.size() + UnavailableBlocks.size() &&
992 "post condition violation");
995 bool GVN::PerformLoadPRE(
LoadInst *LI, AvailValInBlkVect &ValuesPerBlock,
996 UnavailBlkVect &UnavailableBlocks) {
1006 UnavailableBlocks.end());
1015 if (TmpBB == LoadBB)
1017 if (Blockers.count(TmpBB))
1037 FullyAvailableBlocks[AV.BB] =
true;
1038 for (
BasicBlock *UnavailableBB : UnavailableBlocks)
1039 FullyAvailableBlocks[UnavailableBB] =
false;
1045 if (Pred->getTerminator()->isEHPad()) {
1047 <<
"COULD NOT PRE LOAD BECAUSE OF AN EH PAD PREDECESSOR '"
1048 << Pred->getName() <<
"': " << *LI <<
'\n');
1056 if (Pred->getTerminator()->getNumSuccessors() != 1) {
1057 if (isa<IndirectBrInst>(Pred->getTerminator())) {
1058 DEBUG(
dbgs() <<
"COULD NOT PRE LOAD BECAUSE OF INDBR CRITICAL EDGE '"
1059 << Pred->getName() <<
"': " << *LI <<
'\n');
1063 if (LoadBB->isEHPad()) {
1065 <<
"COULD NOT PRE LOAD BECAUSE OF AN EH PAD CRITICAL EDGE '"
1066 << Pred->getName() <<
"': " << *LI <<
'\n');
1073 PredLoads[Pred] =
nullptr;
1078 unsigned NumUnavailablePreds = PredLoads.
size() + CriticalEdgePred.
size();
1079 assert(NumUnavailablePreds != 0 &&
1080 "Fully available value should already be eliminated!");
1086 if (NumUnavailablePreds != 1)
1090 for (
BasicBlock *OrigPred : CriticalEdgePred) {
1091 BasicBlock *NewPred = splitCriticalEdges(OrigPred, LoadBB);
1092 assert(!PredLoads.
count(OrigPred) &&
"Split edges shouldn't be in map!");
1093 PredLoads[NewPred] =
nullptr;
1094 DEBUG(
dbgs() <<
"Split critical edge " << OrigPred->getName() <<
"->"
1095 << LoadBB->getName() <<
'\n');
1099 bool CanDoPRE =
true;
1102 for (
auto &PredLoad : PredLoads) {
1103 BasicBlock *UnavailablePred = PredLoad.first;
1112 Value *LoadPtr =
nullptr;
1113 LoadPtr = Address.PHITranslateWithInsertion(LoadBB, UnavailablePred,
1119 DEBUG(
dbgs() <<
"COULDN'T INSERT PHI TRANSLATED VALUE OF: "
1125 PredLoad.second = LoadPtr;
1129 while (!NewInsts.
empty()) {
1136 return !CriticalEdgePred.empty();
1142 DEBUG(
dbgs() <<
"GVN REMOVING PRE LOAD: " << *LI <<
'\n');
1144 dbgs() <<
"INSERTED " << NewInsts.
size() <<
" INSTS: "
1145 << *NewInsts.
back() <<
'\n');
1163 for (
const auto &PredLoad : PredLoads) {
1164 BasicBlock *UnavailablePred = PredLoad.first;
1165 Value *LoadPtr = PredLoad.second;
1177 NewLoad->setAAMetadata(Tags);
1193 ValuesPerBlock.push_back(AvailableValueInBlock::get(UnavailablePred,
1196 DEBUG(
dbgs() <<
"GVN INSERTED " << *NewLoad <<
'\n');
1202 if (isa<PHINode>(V))
1210 <<
"load eliminated by PRE");
1217 using namespace ore;
1219 <<
"load of type " <<
NV(
"Type", LI->
getType()) <<
" eliminated"
1221 <<
NV(
"InfavorOfValue", AvailableValue));
1226 bool GVN::processNonLocalLoad(
LoadInst *LI) {
1238 unsigned NumDeps = Deps.size();
1245 !Deps[0].getResult().isDef() && !Deps[0].getResult().isClobber()) {
1247 dbgs() <<
"GVN: non-local load ";
1249 dbgs() <<
" has unknown dependencies\n";
1257 OE =
GEP->idx_end();
1259 if (
Instruction *I = dyn_cast<Instruction>(OI->get()))
1260 performScalarPRE(I);
1264 AvailValInBlkVect ValuesPerBlock;
1265 UnavailBlkVect UnavailableBlocks;
1266 AnalyzeLoadAvailability(LI, Deps, ValuesPerBlock, UnavailableBlocks);
1270 if (ValuesPerBlock.empty())
1278 if (UnavailableBlocks.empty()) {
1279 DEBUG(
dbgs() <<
"GVN REMOVING NONLOCAL LOAD: " << *LI <<
'\n');
1285 if (isa<PHINode>(V))
1305 return PerformLoadPRE(LI, ValuesPerBlock, UnavailableBlocks);
1308 bool GVN::processAssumeIntrinsic(
IntrinsicInst *IntrinsicI) {
1310 "This function can only be called with llvm.assume intrinsic");
1313 if (
ConstantInt *Cond = dyn_cast<ConstantInt>(V)) {
1314 if (Cond->isZero()) {
1328 bool Changed =
false;
1335 Changed |= propagateEquality(V, True, Edge,
false);
1341 ReplaceWithConstMap[V] = True;
1347 if (
auto *CmpI = dyn_cast<CmpInst>(V)) {
1348 if (CmpI->getPredicate() == CmpInst::Predicate::ICMP_EQ ||
1349 CmpI->getPredicate() == CmpInst::Predicate::FCMP_OEQ ||
1350 (CmpI->getPredicate() == CmpInst::Predicate::FCMP_UEQ &&
1351 CmpI->getFastMathFlags().noNaNs())) {
1352 Value *CmpLHS = CmpI->getOperand(0);
1353 Value *CmpRHS = CmpI->getOperand(1);
1354 if (isa<Constant>(CmpLHS))
1359 if (RHSConst !=
nullptr && !isa<Constant>(CmpLHS))
1360 ReplaceWithConstMap[CmpLHS] = RHSConst;
1377 if (!isa<LoadInst>(I))
1389 static const unsigned KnownIDs[] = {
1422 return processNonLocalLoad(L);
1429 dbgs() <<
"GVN: load ";
1431 dbgs() <<
" has unknown dependence\n";
1461 LeaderTableEntry Vals = LeaderTable[num];
1462 if (!Vals.Val)
return nullptr;
1464 Value *Val =
nullptr;
1467 if (isa<Constant>(Val))
return Val;
1470 LeaderTableEntry* Next = Vals.Next;
1473 if (isa<Constant>(Next->Val))
return Next->Val;
1474 if (!Val) Val = Next->Val;
1495 "No edge between these basic blocks!");
1496 return Pred !=
nullptr;
1501 bool GVN::replaceOperandsWithConsts(
Instruction *Instr)
const {
1502 bool Changed =
false;
1503 for (
unsigned OpNum = 0; OpNum < Instr->
getNumOperands(); ++OpNum) {
1505 auto it = ReplaceWithConstMap.find(Operand);
1506 if (it != ReplaceWithConstMap.end()) {
1507 assert(!isa<Constant>(Operand) &&
1508 "Replacing constants with constants is invalid");
1509 DEBUG(
dbgs() <<
"GVN replacing: " << *Operand <<
" with " << *it->second
1510 <<
" in instruction " << *Instr <<
'\n');
1524 bool DominatesByEdge) {
1526 Worklist.
push_back(std::make_pair(LHS, RHS));
1527 bool Changed =
false;
1532 while (!Worklist.
empty()) {
1533 std::pair<Value*, Value*> Item = Worklist.
pop_back_val();
1534 LHS = Item.first; RHS = Item.second;
1541 if (isa<Constant>(LHS) && isa<Constant>(RHS))
1545 if (isa<Constant>(LHS) || (isa<Argument>(LHS) && !isa<Constant>(RHS)))
1547 assert((isa<Argument>(LHS) || isa<Instruction>(LHS)) &&
"Unexpected value!");
1554 if ((isa<Argument>(LHS) && isa<Argument>(RHS)) ||
1555 (isa<Instruction>(LHS) && isa<Instruction>(RHS))) {
1574 if (RootDominatesEnd && !isa<Instruction>(RHS))
1575 addToLeaderTable(LVN, RHS, Root.
getEnd());
1581 unsigned NumReplacements =
1584 : replaceDominatedUsesWith(LHS, RHS, *DT, Root.getStart());
1586 Changed |= NumReplacements > 0;
1587 NumGVNEqProp += NumReplacements;
1603 bool isKnownFalse = !isKnownTrue;
1610 Worklist.
push_back(std::make_pair(A, RHS));
1611 Worklist.
push_back(std::make_pair(B, RHS));
1618 if (
CmpInst *Cmp = dyn_cast<CmpInst>(LHS)) {
1619 Value *Op0 = Cmp->getOperand(0), *Op1 = Cmp->getOperand(1);
1625 Worklist.
push_back(std::make_pair(Op0, Op1));
1639 if (isa<ConstantFP>(Op1) && !cast<ConstantFP>(Op1)->
isZero())
1640 Worklist.
push_back(std::make_pair(Op0, Op1));
1653 if (Num < NextNum) {
1655 if (NotCmp && isa<Instruction>(NotCmp)) {
1656 unsigned NumReplacements =
1659 : replaceDominatedUsesWith(NotCmp, NotVal, *DT,
1661 Changed |= NumReplacements > 0;
1662 NumGVNEqProp += NumReplacements;
1669 if (RootDominatesEnd)
1670 addToLeaderTable(Num, NotVal, Root.
getEnd());
1683 if (isa<DbgInfoIntrinsic>(I))
1692 bool Changed =
false;
1702 if (MD && V->getType()->isPtrOrPtrVectorTy())
1711 return processAssumeIntrinsic(IntrinsicI);
1713 if (
LoadInst *LI = dyn_cast<LoadInst>(I)) {
1714 if (processLoad(LI))
1718 addToLeaderTable(Num, LI, LI->
getParent());
1724 if (
BranchInst *BI = dyn_cast<BranchInst>(I)) {
1725 if (!BI->isConditional())
1728 if (isa<Constant>(BI->getCondition()))
1729 return processFoldableCondBr(BI);
1731 Value *BranchCond = BI->getCondition();
1735 if (TrueSucc == FalseSucc)
1739 bool Changed =
false;
1743 Changed |= propagateEquality(BranchCond, TrueVal, TrueE,
true);
1747 Changed |= propagateEquality(BranchCond, FalseVal, FalseE,
true);
1753 if (
SwitchInst *SI = dyn_cast<SwitchInst>(I)) {
1754 Value *SwitchCond =
SI->getCondition();
1756 bool Changed =
false;
1760 for (
unsigned i = 0, n =
SI->getNumSuccessors(); i != n; ++i)
1761 ++SwitchEdges[
SI->getSuccessor(i)];
1767 if (SwitchEdges.
lookup(Dst) == 1) {
1769 Changed |= propagateEquality(SwitchCond, i->getCaseValue(),
E,
true);
1785 if (isa<AllocaInst>(I) || isa<TerminatorInst>(I) || isa<PHINode>(I)) {
1786 addToLeaderTable(Num, I, I->
getParent());
1793 if (Num >= NextNum) {
1794 addToLeaderTable(Num, I, I->
getParent());
1803 addToLeaderTable(Num, I, I->
getParent());
1805 }
else if (Repl == I) {
1833 bool Changed =
false;
1834 bool ShouldContinue =
true;
1845 Changed |= removedBlock;
1848 unsigned Iteration = 0;
1849 while (ShouldContinue) {
1850 DEBUG(
dbgs() <<
"GVN iteration: " << Iteration <<
"\n");
1851 ShouldContinue = iterateOnFunction(F);
1852 Changed |= ShouldContinue;
1859 assignValNumForDeadCode();
1860 bool PREChanged =
true;
1861 while (PREChanged) {
1862 PREChanged = performPRE(F);
1863 Changed |= PREChanged;
1872 cleanupGlobalSets();
1883 assert(InstrsToErase.empty() &&
1884 "We expect InstrsToErase to be empty across iterations");
1885 if (DeadBlocks.count(BB))
1889 ReplaceWithConstMap.clear();
1890 bool ChangedFunction =
false;
1894 if (!ReplaceWithConstMap.empty())
1895 ChangedFunction |= replaceOperandsWithConsts(&*BI);
1896 ChangedFunction |= processInstruction(&*BI);
1898 if (InstrsToErase.empty()) {
1904 NumGVNInstr += InstrsToErase.size();
1907 bool AtStart = BI == BB->
begin();
1912 E = InstrsToErase.end(); I !=
E; ++
I) {
1913 DEBUG(
dbgs() <<
"GVN removed: " << **I <<
'\n');
1915 DEBUG(verifyRemoved(*I));
1916 (*I)->eraseFromParent();
1918 InstrsToErase.clear();
1926 return ChangedFunction;
1931 unsigned int ValNo) {
1939 if (isa<Argument>(Op) || isa<Constant>(Op) || isa<GlobalValue>(Op))
1966 VN.
add(Instr, ValNo);
1969 addToLeaderTable(ValNo, Instr, Pred);
1973 bool GVN::performScalarPRE(
Instruction *CurInst) {
1974 if (isa<AllocaInst>(CurInst) || isa<TerminatorInst>(CurInst) ||
1977 isa<DbgInfoIntrinsic>(CurInst))
1984 if (isa<CmpInst>(CurInst))
1988 if (
CallInst *CallI = dyn_cast<CallInst>(CurInst))
1989 if (CallI->isInlineAsm())
2000 unsigned NumWith = 0;
2001 unsigned NumWithout = 0;
2010 if (
P == CurrentBlock) {
2018 Value *predV = findLeader(
P, ValNo);
2020 predMap.
push_back(std::make_pair(static_cast<Value *>(
nullptr),
P));
2023 }
else if (predV == CurInst) {
2035 if (NumWithout > 1 || NumWith == 0)
2043 if (NumWithout != 0) {
2053 toSplit.push_back(std::make_pair(PREPred->
getTerminator(), SuccNum));
2057 PREInstr = CurInst->
clone();
2058 if (!performScalarPREInsertion(PREInstr, PREPred, ValNo)) {
2060 DEBUG(verifyRemoved(PREInstr));
2068 assert (PREInstr !=
nullptr || NumWithout == 0);
2075 CurInst->
getName() +
".pre-phi", &CurrentBlock->
front());
2076 for (
unsigned i = 0, e = predMap.
size(); i != e; ++i) {
2084 addToLeaderTable(ValNo, Phi, CurrentBlock);
2090 removeFromLeaderTable(ValNo, CurInst, CurrentBlock);
2092 DEBUG(
dbgs() <<
"GVN PRE removed: " << *CurInst <<
'\n');
2095 DEBUG(verifyRemoved(CurInst));
2104 bool GVN::performPRE(
Function &F) {
2105 bool Changed =
false;
2116 BE = CurrentBlock->
end();
2119 Changed |= performScalarPRE(CurInst);
2123 if (splitCriticalEdges())
2141 bool GVN::splitCriticalEdges() {
2142 if (toSplit.empty())
2145 std::pair<TerminatorInst*, unsigned> Edge = toSplit.pop_back_val();
2148 }
while (!toSplit.empty());
2154 bool GVN::iterateOnFunction(
Function &F) {
2155 cleanupGlobalSets();
2158 bool Changed =
false;
2164 Changed |= processBlock(BB);
2169 void GVN::cleanupGlobalSets() {
2171 LeaderTable.
clear();
2172 TableAllocator.
Reset();
2177 void GVN::verifyRemoved(
const Instruction *Inst)
const {
2183 I = LeaderTable.
begin(),
E = LeaderTable.
end(); I !=
E; ++
I) {
2184 const LeaderTableEntry *Node = &I->second;
2185 assert(Node->Val != Inst &&
"Inst still in value numbering scope!");
2187 while (Node->Next) {
2189 assert(Node->Val != Inst &&
"Inst still in value numbering scope!");
2203 while (!NewDead.
empty()) {
2205 if (DeadBlocks.count(D))
2211 DeadBlocks.insert(Dom.
begin(), Dom.
end());
2216 if (DeadBlocks.count(S))
2219 bool AllPredDead =
true;
2221 if (!DeadBlocks.count(
P)) {
2222 AllPredDead =
false;
2245 if (DeadBlocks.count(B))
2250 if (!DeadBlocks.count(
P))
2255 DeadBlocks.insert(
P = S);
2259 PHINode &Phi = cast<PHINode>(*II);
2280 bool GVN::processFoldableCondBr(
BranchInst *BI) {
2294 if (DeadBlocks.count(DeadRoot))
2298 DeadRoot = splitCriticalEdges(BI->
getParent(), DeadRoot);
2300 addDeadBlock(DeadRoot);
2308 void GVN::assignValNumForDeadCode() {
2312 addToLeaderTable(ValNum, &Inst, BB);
2326 if (skipFunction(F))
2329 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
2331 return Impl.runImpl(
2332 F, getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F),
2333 getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
2334 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(),
2335 getAnalysis<AAResultsWrapperPass>().getAAResults(),
2337 : &getAnalysis<MemoryDependenceWrapperPass>().
getMemDep(),
2338 LIWP ? &LIWP->getLoopInfo() :
nullptr,
2339 &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE());
Legacy wrapper pass to provide the GlobalsAAResult object.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
void setDomTree(DominatorTree *D)
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
FunctionPass * createGVNPass(bool NoLoads=false)
Create a legacy GVN pass.
static cl::opt< bool > EnableLoadPRE("enable-load-pre", cl::init(true))
void push_back(const T &Elt)
void invalidateCachedPointerInfo(Value *Ptr)
Invalidates cached information about the specified pointer, because it may be too conservative in mem...
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
void invalidateCachedPredecessors()
Clears the PredIteratorCache info.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
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.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Helper class for SSA formation on a set of values defined in multiple blocks.
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
int analyzeLoadFromClobberingLoad(Type *LoadTy, Value *LoadPtr, LoadInst *DepLI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the load at De...
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static AvailableValue getMI(MemIntrinsic *MI, unsigned Offset=0)
unsigned Offset
Offset - The byte offset in Val that is interesting for the load query.
DiagnosticInfoOptimizationBase::Argument NV
bool isDef() const
Tests if this MemDepResult represents a query that is an instruction definition dependency.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
STATISTIC(NumFunctions,"Total number of functions")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Value * MaterializeAdjustedValue(LoadInst *LI, Instruction *InsertPt, GVN &gvn) const
Emit code at the specified insertion point to adjust the value defined here to the specified type...
bool isUndefValue() const
This is the interface for a simple mod/ref and alias analysis over globals.
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
uint32_t lookupOrAddCmp(unsigned Opcode, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
Returns the value number of the given comparison, assigning it a new number if it did not have one be...
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
const BasicBlock * getStart() const
unsigned getNumOperands() const
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
This class represents a function call, abstracting a target machine's calling convention.
An immutable pass that tracks lazily created AssumptionCache objects.
LoadInst * getCoercedLoadValue() const
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
A cache of .assume calls within a function.
bool exists(Value *V) const
Returns true if a value number exists for the specified value.
void setAliasAnalysis(AliasAnalysis *A)
1 1 1 0 True if unordered or not equal
void deleteValue()
Delete a pointer to a generic Value.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
This class implements a map that also provides access to all stored values in a deterministic order...
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
const Instruction & front() const
Analysis pass which computes a DominatorTree.
An instruction for reading from memory.
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge)
Replace each use of 'From' with 'To' if that use is dominated by the given edge.
iterator end()
Get an iterator to the end of the SetVector.
Value * getMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingMemInst returned an offset, this function can be used to actually perform...
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
bool isClobber() const
Tests if this MemDepResult represents a query that is an instruction clobber dependency.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool match(Val *V, const Pattern &P)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isUnconditional() const
static cl::opt< uint32_t > MaxRecurseDepth("max-recurse-depth", cl::Hidden, cl::init(1000), cl::ZeroOrMore, cl::desc("Max recurse depth (default = 1000)"))
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static cl::opt< bool > EnablePRE("enable-pre", cl::init(true), cl::Hidden)
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
Option class for critical edge splitting.
void clear()
Remove all entries from the ValueTable.
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
A Use represents the edge between a Value definition and its users.
int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr, MemIntrinsic *DepMI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the memory int...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
unsigned getNumArgOperands() const
Return the number of call arguments.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void getNonLocalPointerDependency(Instruction *QueryInst, SmallVectorImpl< NonLocalDepResult > &Result)
Perform a full dependency query for an access to the QueryInst's specified memory location...
An analysis that produces MemoryDependenceResults for a function.
void setName(const Twine &Name)
Change the name of the value.
std::vector< NonLocalDepEntry > NonLocalDepInfo
Analysis pass that exposes the LoopInfo for a function.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
LLVM_NODISCARD bool empty() const
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...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static void patchReplacementInstruction(Instruction *I, Value *Repl)
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
void getDescendants(NodeT *R, SmallVectorImpl< NodeT * > &Result) const
Get all nodes dominated by R, including R itself.
bool isSimpleValue() const
The core GVN pass object.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy, const DataLayout &DL)
Return true if CoerceAvailableValueToLoadType would succeed if it was called.
Expression(uint32_t o=~2U)
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
BasicBlock * getSuccessor(unsigned i) const
iterator begin()
Get an iterator to the beginning of the SetVector.
DiagnosticInfoOptimizationBase::setExtraArgs setExtraArgs
static AvailableValue getLoad(LoadInst *LI, unsigned Offset=0)
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
static GVN::Expression getEmptyKey()
An instruction for storing to memory.
void add(Value *V, uint32_t num)
add - Insert a value into the table with a specified value number.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Value * getSimpleValue() const
void takeName(Value *V)
Transfer the name from V to this value.
static unsigned getHashValue(const GVN::Expression &e)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
Interval::succ_iterator succ_end(Interval *I)
int analyzeLoadFromClobberingStore(Type *LoadTy, Value *LoadPtr, StoreInst *DepSI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the store at D...
void initializeGVNLegacyPassPass(PassRegistry &)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Function Alias Analysis false
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.
initializer< Ty > init(const Ty &Val)
Value * GetValueInMiddleOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live in the middle of the specified block...
SmallVector< uint32_t, 4 > varargs
bool operator==(const Expression &other) const
const NonLocalDepInfo & getNonLocalCallDependency(CallSite QueryCS)
Perform a full dependency query for the specified call, returning the set of blocks that the value is...
A set of analyses that are preserved following a run of a transformation pass.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
PointerIntPair - This class implements a pair of a pointer and small integer.
PHITransAddr - An address value which tracks and handles phi translation.
The instances of the Type class are immutable: once they are created, they are never changed...
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
This class holds the mapping between values and value numbers.
Conditional or Unconditional Branch instruction.
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
static GVN::Expression getTombstoneKey()
static Value * ConstructSSAForLoadSet(LoadInst *LI, SmallVectorImpl< AvailableValueInBlock > &ValuesPerBlock, GVN &gvn)
Given a set of loads specified by ValuesPerBlock, construct SSA form, allowing us to eliminate LI...
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static bool isEqual(const GVN::Expression &LHS, const GVN::Expression &RHS)
A manager for alias analyses.
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
Return the debug location for this node as a DebugLoc.
Represent the analysis usage information of a pass.
BasicBlock * getBB() const
Analysis pass providing a never-invalidated alias analysis result.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
PointerIntPair< Value *, 2, ValType > Val
V - The value that is live out of the block.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
Value * getPointerOperand()
bool isCommutative() const
Return true if the instruction is commutative:
const MemDepResult & getResult() const
bool HasValueForBlock(BasicBlock *BB) const
Return true if the SSAUpdater already has a value for the specified block.
Value * getLoadValueForLoad(LoadInst *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingLoad returned an offset, this function can be used to actually perform th...
GVNLegacyPass(bool NoLoads=false)
static void reportLoadElim(LoadInst *LI, Value *AvailableValue, OptimizationRemarkEmitter *ORE)
DominatorTree & getDominatorTree() const
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance...
A memory dependence query can return one of three different answers.
const BasicBlock * getEnd() const
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
static void reportMayClobberedLoad(LoadInst *LI, MemDepResult DepInfo, DominatorTree *DT, OptimizationRemarkEmitter *ORE)
Try to locate the three instruction involved in a missed load-elimination case that is due to an inte...
void markInstructionForDeletion(Instruction *I)
This removes the specified instruction from our various maps and marks it for deletion.
A function analysis which provides an AssumptionCache.
A SetVector that performs no allocations if smaller than a certain size.
This is the common base class for memset/memcpy/memmove.
Iterator for intrusive lists based on ilist_node.
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.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
void verifyRemoved(const Value *) const
verifyRemoved - Verify that the value is removed from all internal data structures.
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.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
LLVM_NODISCARD T pop_back_val()
bool isNonLocal() const
Tests if this MemDepResult represents a query that is transparent to the start of the block...
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
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.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
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...
pred_range predecessors(BasicBlock *BB)
const BasicBlock & getEntryBlock() const
static ConstantInt * getTrue(LLVMContext &Context)
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
void setOperand(unsigned i, Value *Val)
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 * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
size_type count(const KeyT &Key) const
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Represents an AvailableValue which can be rematerialized at the end of the associated BasicBlock...
bool isIntegerTy() const
True if this is an instance of IntegerType.
typename SuperClass::iterator iterator
iterator_range< user_iterator > users()
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such ...
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
void erase(Value *v)
Remove a value from the value numbering.
bool isCoercedLoadValue() const
static bool isLifetimeStart(const Instruction *Inst)
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.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Instruction * getInst() const
If this is a normal dependency, returns the instruction that is depended on.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Value * getCondition() const
unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
bool MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemoryDependenceResults *MemDep=nullptr)
Attempts to merge a block into its predecessor, if possible.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Value * getStoreValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingStore returned an offset, this function can be used to actually perform t...
unsigned getAlignment() const
Return the alignment of the access that is being performed.
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
static AvailableValue get(Value *V, unsigned Offset=0)
void setMemDep(MemoryDependenceResults *M)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void preserve()
Mark an analysis as preserved.
friend hash_code hash_value(const Expression &Value)
uint32_t lookupOrAdd(Value *V)
lookup_or_add - Returns the value number for the specified value, assigning it a new number if it did...
Analysis pass providing the TargetLibraryInfo.
bool isMemIntrinValue() const
iterator_range< df_iterator< T > > depth_first(const T &G)
uint32_t lookup(Value *V) const
Returns the value number of the specified value.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents a particular available value that we know how to materialize.
LLVMContext & getContext() const
Get the context in which this basic block lives.
uint32_t getNextUnusedValueNumber()
static bool IsValueFullyAvailableInBlock(BasicBlock *BB, DenseMap< BasicBlock *, char > &FullyAvailableBlocks, uint32_t RecurseDepth)
Return true if we can prove that the value we're analyzing is fully available in the specified block...
0 0 0 1 True if ordered and equal
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.
succ_range successors(BasicBlock *BB)
static AvailableValueInBlock getUndef(BasicBlock *BB)
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
This is an entry in the NonLocalDepInfo cache.
A container for analyses that lazily runs them and caches their results.
BasicBlock * BB
BB - The basic block in question.
static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl)
Legacy analysis pass which computes a DominatorTree.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Value * MaterializeAdjustedValue(LoadInst *LI, GVN &gvn) const
Emit code at the end of this block to adjust the value defined here to the specified type...
void setIncomingValue(unsigned i, Value *V)
AvailableValue AV
AV - The actual available value.
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
static IntegerType * getInt8Ty(LLVMContext &C)
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs)
Combine the metadata of two instructions so that K can replace J.
const BasicBlock * getParent() const
static AvailableValue getUndef()
static bool isOnlyReachableViaThisEdge(const BasicBlockEdge &E, DominatorTree *DT)
There is an edge from 'Src' to 'Dst'.
MemIntrinsic * getMemIntrinValue() const
A wrapper class for inspecting calls to intrinsic functions.
bool isVoidTy() const
Return true if this is 'void'.
This instruction inserts a struct field of array element value into an aggregate value.
MemoryDependenceResults & getMemDep() const
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.
bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.
MemDepResult getDependency(Instruction *QueryInst)
Returns the instruction on which a memory operation depends.