44 #define DEBUG_TYPE "sccp"
46 STATISTIC(NumInstRemoved,
"Number of instructions removed");
47 STATISTIC(NumDeadBlocks ,
"Number of basic blocks unreachable");
49 STATISTIC(IPNumInstRemoved,
"Number of instructions removed by IPSCCP");
50 STATISTIC(IPNumArgsElimed ,
"Number of arguments constant propagated by IPSCCP");
51 STATISTIC(IPNumGlobalConst,
"Number of globals found to be constant by IPSCCP");
80 LatticeValueTy getLatticeValue()
const {
85 LatticeVal() : Val(nullptr, undefined) {}
87 bool isUndefined()
const {
return getLatticeValue() == undefined; }
88 bool isConstant()
const {
89 return getLatticeValue() == constant || getLatticeValue() == forcedconstant;
91 bool isOverdefined()
const {
return getLatticeValue() == overdefined; }
94 assert(isConstant() &&
"Cannot get the constant of a non-constant!");
95 return Val.getPointer();
99 bool markOverdefined() {
103 Val.setInt(overdefined);
109 if (getLatticeValue() == constant) {
110 assert(getConstant() == V &&
"Marking constant with different value");
115 Val.setInt(constant);
116 assert(V &&
"Marking constant with NULL");
119 assert(getLatticeValue() == forcedconstant &&
120 "Cannot move from overdefined to constant!");
122 if (V == getConstant())
return false;
127 Val.setInt(overdefined);
140 void markForcedConstant(
Constant *V) {
141 assert(isUndefined() &&
"Can't force a defined value!");
142 Val.setInt(forcedconstant);
156 class SCCPSolver :
public InstVisitor<SCCPSolver> {
206 typedef std::pair<BasicBlock*, BasicBlock*> Edge;
210 : DL(DL), TLI(tli) {}
217 if (!BBExecutable.insert(BB).second)
220 BBWorkList.push_back(BB);
231 LatticeVal &IV = TrackedGlobals[GV];
243 MRVFunctionsTracked.insert(F);
244 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
245 TrackedMultipleRetVals.insert(std::make_pair(std::make_pair(F, i),
248 TrackedRetVals.insert(std::make_pair(F, LatticeVal()));
251 void AddArgumentTrackedFunction(
Function *F) {
252 TrackingIncomingArguments.insert(F);
266 bool isBlockExecutable(
BasicBlock *BB)
const {
267 return BBExecutable.count(BB);
270 LatticeVal getLatticeValueFor(
Value *V)
const {
272 assert(I != ValueState.
end() &&
"V is not in valuemap!");
279 return TrackedRetVals;
285 return TrackedGlobals;
288 void markOverdefined(
Value *V) {
290 markOverdefined(ValueState[V], V);
295 void markAnythingOverdefined(
Value *V) {
297 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
298 markOverdefined(getStructValueState(V, i), V);
309 if (!IV.markConstant(C))
return;
310 DEBUG(
dbgs() <<
"markConstant: " << *C <<
": " << *V <<
'\n');
311 if (IV.isOverdefined())
312 OverdefinedInstWorkList.push_back(V);
314 InstWorkList.push_back(V);
319 markConstant(ValueState[V], V, C);
324 LatticeVal &IV = ValueState[V];
325 IV.markForcedConstant(C);
326 DEBUG(
dbgs() <<
"markForcedConstant: " << *C <<
": " << *V <<
'\n');
327 if (IV.isOverdefined())
328 OverdefinedInstWorkList.push_back(V);
330 InstWorkList.push_back(V);
337 void markOverdefined(LatticeVal &IV,
Value *V) {
338 if (!IV.markOverdefined())
return;
341 if (
Function *F = dyn_cast<Function>(V))
344 dbgs() << *V <<
'\n');
346 OverdefinedInstWorkList.push_back(V);
349 void mergeInValue(LatticeVal &IV,
Value *V, LatticeVal MergeWithV) {
350 if (IV.isOverdefined() || MergeWithV.isUndefined())
352 if (MergeWithV.isOverdefined())
353 markOverdefined(IV, V);
354 else if (IV.isUndefined())
355 markConstant(IV, V, MergeWithV.getConstant());
356 else if (IV.getConstant() != MergeWithV.getConstant())
357 markOverdefined(IV, V);
360 void mergeInValue(
Value *V, LatticeVal MergeWithV) {
362 mergeInValue(ValueState[V], V, MergeWithV);
369 LatticeVal &getValueState(
Value *V) {
372 std::pair<DenseMap<Value*, LatticeVal>::iterator,
bool> I =
373 ValueState.
insert(std::make_pair(V, LatticeVal()));
374 LatticeVal &LV = I.first->second;
379 if (
Constant *C = dyn_cast<Constant>(V)) {
381 if (!isa<UndefValue>(V))
392 LatticeVal &getStructValueState(
Value *V,
unsigned i) {
394 assert(i < cast<StructType>(V->
getType())->getNumElements() &&
395 "Invalid element #");
397 std::pair<DenseMap<std::pair<Value*, unsigned>, LatticeVal>::iterator,
398 bool> I = StructValueState.insert(
399 std::make_pair(std::make_pair(V, i), LatticeVal()));
400 LatticeVal &LV = I.first->second;
405 if (
Constant *C = dyn_cast<Constant>(V)) {
409 LV.markOverdefined();
410 else if (isa<UndefValue>(Elt))
413 LV.markConstant(Elt);
424 if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)
427 if (!MarkBlockExecutable(Dest)) {
432 <<
" -> " << Dest->
getName() <<
'\n');
481 void visitLandingPadInst(
LandingPadInst &I) { markAnythingOverdefined(&I); }
492 visitTerminatorInst(II);
499 markAnythingOverdefined(&I);
501 void visitAtomicRMWInst (
AtomicRMWInst &I) { markOverdefined(&I); }
502 void visitAllocaInst (
Instruction &I) { markOverdefined(&I); }
503 void visitVAArgInst (
Instruction &I) { markAnythingOverdefined(&I); }
507 dbgs() <<
"SCCP: Don't know how to handle: " << I <<
'\n';
508 markAnythingOverdefined(&I);
521 if (
BranchInst *BI = dyn_cast<BranchInst>(&TI)) {
522 if (BI->isUnconditional()) {
527 LatticeVal BCValue = getValueState(BI->getCondition());
532 if (!BCValue.isUndefined())
533 Succs[0] = Succs[1] =
true;
538 Succs[CI->isZero()] =
true;
542 if (isa<InvokeInst>(TI)) {
544 Succs[0] = Succs[1] =
true;
549 if (!
SI->getNumCases()) {
553 LatticeVal SCValue = getValueState(
SI->getCondition());
558 if (!SCValue.isUndefined())
563 Succs[
SI->findCaseValue(CI).getSuccessorIndex()] =
true;
568 if (isa<IndirectBrInst>(&TI)) {
575 dbgs() <<
"Unknown terminator instruction: " << TI <<
'\n';
585 assert(BBExecutable.count(To) &&
"Dest should always be alive!");
588 if (!BBExecutable.count(From))
return false;
592 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
593 if (BI->isUnconditional())
596 LatticeVal BCValue = getValueState(BI->getCondition());
602 return !BCValue.isUndefined();
605 return BI->getSuccessor(CI->isZero()) == To;
609 if (isa<InvokeInst>(TI))
613 if (
SI->getNumCases() < 1)
616 LatticeVal SCValue = getValueState(
SI->getCondition());
620 return !SCValue.isUndefined();
622 return SI->findCaseValue(CI).getCaseSuccessor() == To;
627 if (isa<IndirectBrInst>(TI))
631 dbgs() <<
"Unknown terminator instruction: " << *TI <<
'\n';
654 void SCCPSolver::visitPHINode(
PHINode &PN) {
658 return markAnythingOverdefined(&PN);
660 if (getValueState(&PN).isOverdefined())
666 return markOverdefined(&PN);
677 if (IV.isUndefined())
continue;
682 if (IV.isOverdefined())
683 return markOverdefined(&PN);
686 OperandVal = IV.getConstant();
696 if (IV.getConstant() != OperandVal)
697 return markOverdefined(&PN);
706 markConstant(&PN, OperandVal);
709 void SCCPSolver::visitReturnInst(
ReturnInst &I) {
718 TrackedRetVals.
find(F);
719 if (TFRVI != TrackedRetVals.
end()) {
720 mergeInValue(TFRVI->second, F, getValueState(ResultOp));
726 if (!TrackedMultipleRetVals.empty()) {
728 if (MRVFunctionsTracked.count(F))
729 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
730 mergeInValue(TrackedMultipleRetVals[std::make_pair(F, i)],
F,
731 getStructValueState(ResultOp, i));
738 getFeasibleSuccessors(TI, SuccFeasible);
743 for (
unsigned i = 0, e = SuccFeasible.
size(); i != e; ++i)
748 void SCCPSolver::visitCastInst(
CastInst &I) {
749 LatticeVal OpSt = getValueState(I.
getOperand(0));
750 if (OpSt.isOverdefined())
752 else if (OpSt.isConstant())
754 OpSt.getConstant(), I.
getType()));
762 return markAnythingOverdefined(&EVI);
766 return markOverdefined(&EVI);
771 LatticeVal EltVal = getStructValueState(AggVal, i);
772 mergeInValue(getValueState(&EVI), &EVI, EltVal);
775 return markOverdefined(&EVI);
782 return markOverdefined(&IVI);
787 return markAnythingOverdefined(&IVI);
796 LatticeVal EltVal = getStructValueState(Aggr, i);
797 mergeInValue(getStructValueState(&IVI, i), &IVI, EltVal);
804 markOverdefined(getStructValueState(&IVI, i), &IVI);
806 LatticeVal InVal = getValueState(Val);
807 mergeInValue(getStructValueState(&IVI, i), &IVI, InVal);
812 void SCCPSolver::visitSelectInst(
SelectInst &I) {
816 return markAnythingOverdefined(&I);
819 if (CondValue.isUndefined())
822 if (
ConstantInt *CondCB = CondValue.getConstantInt()) {
824 mergeInValue(&I, getValueState(OpVal));
835 if (TVal.isConstant() && FVal.isConstant() &&
836 TVal.getConstant() == FVal.getConstant())
837 return markConstant(&I, FVal.getConstant());
839 if (TVal.isUndefined())
840 return mergeInValue(&I, FVal);
841 if (FVal.isUndefined())
842 return mergeInValue(&I, TVal);
847 void SCCPSolver::visitBinaryOperator(
Instruction &I) {
848 LatticeVal V1State = getValueState(I.
getOperand(0));
849 LatticeVal V2State = getValueState(I.
getOperand(1));
851 LatticeVal &IV = ValueState[&
I];
852 if (IV.isOverdefined())
return;
854 if (V1State.isConstant() && V2State.isConstant())
855 return markConstant(IV, &I,
857 V2State.getConstant()));
860 if (!V1State.isOverdefined() && !V2State.isOverdefined())
869 LatticeVal *NonOverdefVal =
nullptr;
870 if (!V1State.isOverdefined())
871 NonOverdefVal = &V1State;
872 else if (!V2State.isOverdefined())
873 NonOverdefVal = &V2State;
876 if (NonOverdefVal->isUndefined()) {
890 if (NonOverdefVal->getConstant()->isNullValue())
891 return markConstant(IV, &I, NonOverdefVal->getConstant());
893 if (
ConstantInt *CI = NonOverdefVal->getConstantInt())
894 if (CI->isAllOnesValue())
895 return markConstant(IV, &I, NonOverdefVal->getConstant());
905 void SCCPSolver::visitCmpInst(
CmpInst &I) {
906 LatticeVal V1State = getValueState(I.
getOperand(0));
907 LatticeVal V2State = getValueState(I.
getOperand(1));
909 LatticeVal &IV = ValueState[&
I];
910 if (IV.isOverdefined())
return;
912 if (V1State.isConstant() && V2State.isConstant())
914 V1State.getConstant(),
915 V2State.getConstant()));
918 if (!V1State.isOverdefined() && !V2State.isOverdefined())
926 return markOverdefined(&I);
929 LatticeVal &ValState = getValueState(I.
getOperand(0));
930 LatticeVal &IdxState = getValueState(I.
getOperand(1));
932 if (ValState.isOverdefined() || IdxState.isOverdefined())
934 else if(ValState.isConstant() && IdxState.isConstant())
936 IdxState.getConstant()));
942 return markOverdefined(&I);
944 LatticeVal &ValState = getValueState(I.
getOperand(0));
945 LatticeVal &EltState = getValueState(I.
getOperand(1));
946 LatticeVal &IdxState = getValueState(I.
getOperand(2));
948 if (ValState.isOverdefined() || EltState.isOverdefined() ||
949 IdxState.isOverdefined())
951 else if(ValState.isConstant() && EltState.isConstant() &&
952 IdxState.isConstant())
954 EltState.getConstant(),
955 IdxState.getConstant()));
956 else if (ValState.isUndefined() && EltState.isConstant() &&
957 IdxState.isConstant())
959 EltState.getConstant(),
960 IdxState.getConstant()));
966 return markOverdefined(&I);
968 LatticeVal &V1State = getValueState(I.
getOperand(0));
969 LatticeVal &V2State = getValueState(I.
getOperand(1));
970 LatticeVal &MaskState = getValueState(I.
getOperand(2));
972 if (MaskState.isUndefined() ||
973 (V1State.isUndefined() && V2State.isUndefined()))
976 if (V1State.isOverdefined() || V2State.isOverdefined() ||
977 MaskState.isOverdefined()) {
981 Constant *V1 = V1State.isConstant() ?
985 Constant *Mask = MaskState.isConstant() ?
996 if (ValueState[&I].isOverdefined())
return;
1002 LatticeVal State = getValueState(I.
getOperand(i));
1003 if (State.isUndefined())
1006 if (State.isOverdefined())
1007 return markOverdefined(&I);
1009 assert(State.isConstant() &&
"Unknown state!");
1010 Operands.
push_back(State.getConstant());
1024 if (TrackedGlobals.empty() || !isa<GlobalVariable>(SI.
getOperand(1)))
1029 if (I == TrackedGlobals.end() || I->second.isOverdefined())
return;
1032 mergeInValue(I->second, GV, getValueState(SI.
getOperand(0)));
1033 if (I->second.isOverdefined())
1034 TrackedGlobals.erase(I);
1040 void SCCPSolver::visitLoadInst(
LoadInst &I) {
1043 return markAnythingOverdefined(&I);
1045 LatticeVal PtrVal = getValueState(I.
getOperand(0));
1046 if (PtrVal.isUndefined())
return;
1048 LatticeVal &IV = ValueState[&
I];
1049 if (IV.isOverdefined())
return;
1052 return markOverdefined(IV, &I);
1054 Constant *Ptr = PtrVal.getConstant();
1062 if (!TrackedGlobals.empty()) {
1065 TrackedGlobals.
find(GV);
1066 if (It != TrackedGlobals.
end()) {
1067 mergeInValue(IV, &I, It->second);
1075 return markConstant(IV, &I, C);
1079 markOverdefined(IV, &I);
1082 void SCCPSolver::visitCallSite(
CallSite CS) {
1102 LatticeVal State = getValueState(*AI);
1104 if (State.isUndefined())
1106 if (State.isOverdefined())
1107 return markOverdefined(I);
1108 assert(State.isConstant() &&
"Unknown state!");
1109 Operands.
push_back(State.getConstant());
1112 if (getValueState(I).isOverdefined())
1118 return markConstant(I, C);
1122 return markAnythingOverdefined(I);
1128 if (!TrackingIncomingArguments.empty() && TrackingIncomingArguments.count(F)){
1129 MarkBlockExecutable(F->
begin());
1134 AI != E; ++AI, ++CAI) {
1138 markOverdefined(AI);
1142 if (
StructType *STy = dyn_cast<StructType>(AI->getType())) {
1144 LatticeVal
CallArg = getStructValueState(*CAI, i);
1145 mergeInValue(getStructValueState(AI, i), AI, CallArg);
1148 mergeInValue(AI, getValueState(*CAI));
1155 if (!MRVFunctionsTracked.count(F))
1156 goto CallOverdefined;
1161 mergeInValue(getStructValueState(I, i),
I,
1162 TrackedMultipleRetVals[std::make_pair(F, i)]);
1165 if (TFRVI == TrackedRetVals.
end())
1166 goto CallOverdefined;
1169 mergeInValue(I, TFRVI->second);
1173 void SCCPSolver::Solve() {
1175 while (!BBWorkList.empty() || !InstWorkList.empty() ||
1176 !OverdefinedInstWorkList.empty()) {
1179 while (!OverdefinedInstWorkList.empty()) {
1180 Value *I = OverdefinedInstWorkList.pop_back_val();
1182 DEBUG(
dbgs() <<
"\nPopped off OI-WL: " << *I <<
'\n');
1193 OperandChangedState(UI);
1197 while (!InstWorkList.empty()) {
1198 Value *I = InstWorkList.pop_back_val();
1200 DEBUG(
dbgs() <<
"\nPopped off I-WL: " << *I <<
'\n');
1212 OperandChangedState(UI);
1216 while (!BBWorkList.empty()) {
1218 BBWorkList.pop_back();
1220 DEBUG(
dbgs() <<
"\nPopped off BBWL: " << *BB <<
'\n');
1247 bool SCCPSolver::ResolvedUndefsIn(
Function &F) {
1249 if (!BBExecutable.count(BB))
1262 if (MRVFunctionsTracked.count(F))
1267 if (isa<ExtractValueInst>(I) || isa<InsertValueInst>(
I))
1273 LatticeVal &LV = getStructValueState(I, i);
1274 if (LV.isUndefined())
1275 markOverdefined(LV, I);
1280 LatticeVal &LV = getValueState(I);
1281 if (!LV.isUndefined())
continue;
1284 if (isa<ExtractValueInst>(I))
1294 LatticeVal Op0LV = getValueState(I->getOperand(0));
1296 if (I->getNumOperands() == 2) {
1302 Op1LV = getValueState(I->getOperand(1));
1307 switch (I->getOpcode()) {
1308 case Instruction::Add:
1309 case Instruction::Sub:
1310 case Instruction::Trunc:
1311 case Instruction::FPTrunc:
1312 case Instruction::BitCast:
1314 case Instruction::FSub:
1315 case Instruction::FAdd:
1316 case Instruction::FMul:
1317 case Instruction::FDiv:
1318 case Instruction::FRem:
1320 if (Op0LV.isUndefined() && Op1LV.isUndefined())
1325 case Instruction::ZExt:
1326 case Instruction::SExt:
1327 case Instruction::FPToUI:
1328 case Instruction::FPToSI:
1329 case Instruction::FPExt:
1330 case Instruction::PtrToInt:
1331 case Instruction::IntToPtr:
1332 case Instruction::SIToFP:
1333 case Instruction::UIToFP:
1337 case Instruction::Mul:
1340 if (Op0LV.isUndefined() && Op1LV.isUndefined())
1349 if (Op0LV.isUndefined() && Op1LV.isUndefined())
1359 if (Op0LV.isUndefined() && Op1LV.isUndefined()) {
1366 case Instruction::SDiv:
1367 case Instruction::UDiv:
1368 case Instruction::SRem:
1369 case Instruction::URem:
1372 if (Op1LV.isUndefined())
break;
1379 case Instruction::AShr:
1381 if (Op1LV.isUndefined())
break;
1386 case Instruction::LShr:
1387 case Instruction::Shl:
1390 if (Op1LV.isUndefined())
break;
1397 Op1LV = getValueState(I->getOperand(1));
1399 if (Op0LV.isUndefined()) {
1400 if (!Op1LV.isConstant())
1401 Op1LV = getValueState(I->getOperand(2));
1402 }
else if (Op1LV.isUndefined()) {
1404 Op1LV = getValueState(I->getOperand(2));
1405 if (Op1LV.isUndefined())
1412 if (Op1LV.isConstant())
1413 markForcedConstant(I, Op1LV.getConstant());
1422 case Instruction::ICmp:
1424 if (cast<ICmpInst>(I)->isEquality())
1429 case Instruction::Invoke: {
1436 if (TrackedRetVals.count(F))
1456 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
1457 if (!BI->isConditional())
continue;
1458 if (!getValueState(BI->getCondition()).isUndefined())
1463 if (isa<UndefValue>(BI->getCondition())) {
1472 markForcedConstant(BI->getCondition(),
1477 if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
1478 if (!SI->getNumCases())
1480 if (!getValueState(SI->getCondition()).isUndefined())
1485 if (isa<UndefValue>(SI->getCondition())) {
1486 SI->setCondition(SI->case_begin().getCaseValue());
1487 markEdgeExecutable(BB, SI->case_begin().getCaseSuccessor());
1491 markForcedConstant(SI->getCondition(), SI->case_begin().getCaseValue());
1518 bool runOnFunction(
Function &F)
override;
1524 "Sparse Conditional Constant Propagation",
false,
false)
1532 DEBUG(
dbgs() <<
" BasicBlock Dead:" << *BB);
1536 if (isa<TerminatorInst>(BB->
begin()))
1542 while (EndInst != BB->
begin()) {
1548 if (isa<LandingPadInst>(Inst)) {
1560 bool SCCP::runOnFunction(
Function &F) {
1561 if (skipOptnoneFunction(F))
1567 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1568 SCCPSolver Solver(DL, TLI);
1571 Solver.MarkBlockExecutable(F.
begin());
1575 Solver.markAnythingOverdefined(AI);
1578 bool ResolvedUndefs =
true;
1579 while (ResolvedUndefs) {
1582 ResolvedUndefs = Solver.ResolvedUndefsIn(F);
1585 bool MadeChanges =
false;
1592 if (!Solver.isBlockExecutable(BB)) {
1610 LatticeVal IV = Solver.getLatticeValueFor(Inst);
1611 if (IV.isOverdefined())
1616 DEBUG(
dbgs() <<
" Constant: " << *Const <<
" = " << *Inst <<
'\n');
1647 bool runOnModule(
Module &M)
override;
1653 "Interprocedural Sparse Conditional Constant Propagation",
1662 return new IPSCCP();
1670 for (
const Use &U : GV->
uses()) {
1671 const User *UR = U.getUser();
1672 if (
const StoreInst *SI = dyn_cast<StoreInst>(UR)) {
1675 }
else if (isa<InvokeInst>(UR) || isa<CallInst>(UR)) {
1680 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(UR)) {
1681 if (LI->isVolatile())
1683 }
else if (isa<BlockAddress>(UR)) {
1693 bool IPSCCP::runOnModule(
Module &M) {
1696 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1697 SCCPSolver Solver(DL, TLI);
1716 Solver.AddTrackedFunction(F);
1723 AddressTakenFunctions.
insert(F);
1725 Solver.AddArgumentTrackedFunction(F);
1731 Solver.MarkBlockExecutable(F->
begin());
1736 Solver.markAnythingOverdefined(AI);
1745 Solver.TrackValueOfGlobalVariable(
G);
1748 bool ResolvedUndefs =
true;
1749 while (ResolvedUndefs) {
1753 ResolvedUndefs =
false;
1755 ResolvedUndefs |= Solver.ResolvedUndefsIn(*F);
1758 bool MadeChanges =
false;
1766 if (Solver.isBlockExecutable(F->
begin())) {
1769 if (AI->use_empty() || AI->getType()->isStructTy())
continue;
1774 LatticeVal IV = Solver.getLatticeValueFor(AI);
1775 if (IV.isOverdefined())
continue;
1779 DEBUG(
dbgs() <<
"*** Arg " << *AI <<
" = " << *CST <<
"\n");
1783 AI->replaceAllUsesWith(CST);
1789 if (!Solver.isBlockExecutable(BB)) {
1796 if (!Succ->
empty() && isa<PHINode>(Succ->
begin()))
1804 if (&*BB != &F->
front())
1817 LatticeVal IV = Solver.getLatticeValueFor(Inst);
1818 if (IV.isOverdefined())
1823 DEBUG(
dbgs() <<
" Constant: " << *Const <<
" = " << *Inst <<
'\n');
1830 if (!isa<CallInst>(Inst) && !isa<TerminatorInst>(Inst))
1842 for (
unsigned i = 0, e = BlocksToErase.
size(); i != e; ++i) {
1851 do { ++UI; }
while (UI != UE && *UI == I);
1862 if (
BranchInst *BI = dyn_cast<BranchInst>(I)) {
1863 assert(BI->isConditional() && isa<UndefValue>(BI->getCondition()) &&
1864 "Branch should be foldable!");
1865 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(I)) {
1866 assert(isa<UndefValue>(SI->getCondition()) &&
"Switch should fold");
1888 BlocksToErase.
clear();
1906 E = RV.
end(); I != E; ++
I) {
1917 if (!isa<UndefValue>(RI->getOperand(0)))
1922 for (
unsigned i = 0, e = ReturnsToZap.
size(); i != e; ++i) {
1923 Function *F = ReturnsToZap[i]->getParent()->getParent();
1931 E = TG.
end(); I != E; ++
I) {
1933 assert(!I->second.isOverdefined() &&
1934 "Overdefined values should have been taken out of the map!");
ReturnInst - Return a value (possibly void), from a function.
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)
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
This class is the base class for the comparison instructions.
iterator_range< use_iterator > uses()
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Base class for instruction visitors.
Value * getAggregateOperand()
const Instruction & back() const
Type * getSourceElementType() const
STATISTIC(NumFunctions,"Total number of functions")
bool isVolatile() const
isVolatile - Return true if this is a store to a volatile memory location.
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
bool canConstantFoldCallTo(const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
A Module instance is used to store all the information related to an LLVM module. ...
FenceInst - an instruction for ordering other memory operations.
InstrTy * getInstruction() const
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
static bool AddressIsTaken(const GlobalValue *GV)
DenseSet - This implements a dense probed hash-table based set.
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
unsigned getNumOperands() const
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.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions...
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
static void DeleteInstructionInBlock(BasicBlock *BB)
Type * getReturnType() const
unsigned getNumIndices() const
const Function * getParent() const
Return the enclosing method, or null if none.
LoadInst - an instruction for reading from memory.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
User::op_iterator arg_iterator
arg_iterator - The type of iterator to use when looping over actual arguments at this call site...
void reserve(size_type N)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getNullValue(Type *Ty)
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
bool isSingleValueType() const
isSingleValueType - Return true if the type is a valid type for a register in codegen.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
SelectInst - This class represents the LLVM 'select' instruction.
This is the base class for all instructions that perform data casts.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
Constant * ConstantFoldLoadFromConstPtr(Constant *C, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
global_iterator global_begin()
void assign(size_type NumElts, const T &Elt)
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. ...
user_iterator_impl< User > user_iterator
VectorType * getType() const
getType - Overload to return most specific vector type.
Value * getInsertedValueOperand()
StoreInst - an instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Type * getElementType() const
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
Subclasses of this class are all able to terminate a basic block.
LLVM Basic Block Representation.
PointerIntPair - This class implements a pair of a pointer and small integer.
The instances of the Type class are immutable: once they are created, they are never changed...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
static bool mayBeOverridden(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time...
BranchInst - Conditional or Unconditional Branch instruction.
void initializeSCCPPass(PassRegistry &)
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
UnreachableInst - This function has undefined behavior.
This is an important base class in LLVM.
const Value * getCondition() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
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.
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
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.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
void initializeIPSCCPPass(PassRegistry &)
Predicate getPredicate() const
Return the predicate for this instruction.
Constant * getAggregateElement(unsigned Elt) const
getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to th...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
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
iterator erase(iterator where)
Interprocedural Sparse Conditional Constant Propagation
global_iterator global_end()
idx_iterator idx_begin() const
const BasicBlockListType & getBasicBlockList() const
Interprocedural Sparse Conditional Constant false
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
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.
bool isVolatile() const
isVolatile - Return true if this is a load from a volatile memory location.
bool isCallee(Value::const_user_iterator UI) const
isCallee - Determine whether the passed iterator points to the callee operand's Use.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
VectorType - Class to represent vector types.
iterator_range< user_iterator > users()
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
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.
bool isStructTy() const
isStructTy - True if this is an instance of StructType.
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
FunctionPass * createSCCPPass()
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
ImmutableCallSite - establish a view to a call site for examination.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static Function * getCalledFunction(const Value *V, bool LookThroughBitCast)
iterator find(const KeyT &Val)
VectorType * getType() const
getType - Overload to return most specific vector type.
bool hasLocalLinkage() const
SwitchInst - Multiway switch.
user_iterator user_begin()
const BasicBlock & front() const
void removeDeadConstantUsers() const
removeDeadConstantUsers - If there are any dead constant users dangling off of this constant...
INITIALIZE_PASS_BEGIN(IPSCCP,"ipsccp","Interprocedural Sparse Conditional Constant Propagation", false, false) INITIALIZE_PASS_END(IPSCCP
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
INITIALIZE_PASS(SCCP,"sccp","Sparse Conditional Constant Propagation", false, false) FunctionPass *llvm
InvokeInst - Invoke instruction.
IterTy arg_begin() const
arg_begin/arg_end - Return iterators corresponding to the actual argument list for a call site...
const Value * getFalseValue() const
unsigned getNumElements() const
Random access to the elements.
const BasicBlock * getParent() const
Constant * ConstantFoldCall(Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
LLVMContext & getContext() const
Get the global data context.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...