20 #define DEBUG_TYPE "sccp"
45 STATISTIC(NumInstRemoved,
"Number of instructions removed");
46 STATISTIC(NumDeadBlocks ,
"Number of basic blocks unreachable");
48 STATISTIC(IPNumInstRemoved,
"Number of instructions removed by IPSCCP");
49 STATISTIC(IPNumArgsElimed ,
"Number of arguments constant propagated by IPSCCP");
50 STATISTIC(IPNumGlobalConst,
"Number of globals found to be constant by IPSCCP");
79 LatticeValueTy getLatticeValue()
const {
84 LatticeVal() : Val(0, undefined) {}
86 bool isUndefined()
const {
return getLatticeValue() == undefined; }
87 bool isConstant()
const {
88 return getLatticeValue() == constant || getLatticeValue() == forcedconstant;
90 bool isOverdefined()
const {
return getLatticeValue() == overdefined; }
93 assert(isConstant() &&
"Cannot get the constant of a non-constant!");
94 return Val.getPointer();
98 bool markOverdefined() {
102 Val.setInt(overdefined);
108 if (getLatticeValue() == constant) {
109 assert(getConstant() == V &&
"Marking constant with different value");
114 Val.setInt(constant);
115 assert(V &&
"Marking constant with NULL");
118 assert(getLatticeValue() == forcedconstant &&
119 "Cannot move from overdefined to constant!");
121 if (V == getConstant())
return false;
126 Val.setInt(overdefined);
139 void markForcedConstant(
Constant *V) {
140 assert(isUndefined() &&
"Can't force a defined value!");
141 Val.setInt(forcedconstant);
155 class SCCPSolver :
public InstVisitor<SCCPSolver> {
205 typedef std::pair<BasicBlock*, BasicBlock*> Edge;
209 :
TD(td), TLI(tli) {}
216 if (!BBExecutable.insert(BB))
return false;
218 BBWorkList.push_back(BB);
229 LatticeVal &IV = TrackedGlobals[GV];
241 MRVFunctionsTracked.insert(F);
242 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
243 TrackedMultipleRetVals.insert(std::make_pair(std::make_pair(F, i),
246 TrackedRetVals.insert(std::make_pair(F, LatticeVal()));
249 void AddArgumentTrackedFunction(
Function *F) {
250 TrackingIncomingArguments.insert(F);
264 bool isBlockExecutable(
BasicBlock *BB)
const {
265 return BBExecutable.count(BB);
268 LatticeVal getLatticeValueFor(
Value *V)
const {
270 assert(I != ValueState.
end() &&
"V is not in valuemap!");
277 return TrackedRetVals;
283 return TrackedGlobals;
286 void markOverdefined(
Value *V) {
288 markOverdefined(ValueState[V], V);
293 void markAnythingOverdefined(
Value *V) {
295 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
296 markOverdefined(getStructValueState(V, i), V);
307 if (!IV.markConstant(C))
return;
308 DEBUG(
dbgs() <<
"markConstant: " << *C <<
": " << *V <<
'\n');
309 if (IV.isOverdefined())
310 OverdefinedInstWorkList.push_back(V);
312 InstWorkList.push_back(V);
317 markConstant(ValueState[V], V, C);
322 LatticeVal &IV = ValueState[V];
323 IV.markForcedConstant(C);
324 DEBUG(
dbgs() <<
"markForcedConstant: " << *C <<
": " << *V <<
'\n');
325 if (IV.isOverdefined())
326 OverdefinedInstWorkList.push_back(V);
328 InstWorkList.push_back(V);
335 void markOverdefined(LatticeVal &IV,
Value *V) {
336 if (!IV.markOverdefined())
return;
339 if (
Function *F = dyn_cast<Function>(V))
342 dbgs() << *V <<
'\n');
344 OverdefinedInstWorkList.push_back(V);
347 void mergeInValue(LatticeVal &IV,
Value *V, LatticeVal MergeWithV) {
348 if (IV.isOverdefined() || MergeWithV.isUndefined())
350 if (MergeWithV.isOverdefined())
351 markOverdefined(IV, V);
352 else if (IV.isUndefined())
353 markConstant(IV, V, MergeWithV.getConstant());
354 else if (IV.getConstant() != MergeWithV.getConstant())
355 markOverdefined(IV, V);
358 void mergeInValue(
Value *V, LatticeVal MergeWithV) {
360 mergeInValue(ValueState[V], V, MergeWithV);
367 LatticeVal &getValueState(
Value *V) {
370 std::pair<DenseMap<Value*, LatticeVal>::iterator,
bool> I =
371 ValueState.
insert(std::make_pair(V, LatticeVal()));
372 LatticeVal &LV = I.first->second;
377 if (
Constant *C = dyn_cast<Constant>(V)) {
379 if (!isa<UndefValue>(V))
390 LatticeVal &getStructValueState(
Value *V,
unsigned i) {
392 assert(i < cast<StructType>(V->
getType())->getNumElements() &&
393 "Invalid element #");
395 std::pair<DenseMap<std::pair<Value*, unsigned>, LatticeVal>::iterator,
396 bool> I = StructValueState.insert(
397 std::make_pair(std::make_pair(V, i), LatticeVal()));
398 LatticeVal &LV = I.first->second;
403 if (
Constant *C = dyn_cast<Constant>(V)) {
407 LV.markOverdefined();
408 else if (isa<UndefValue>(Elt))
411 LV.markConstant(Elt);
422 if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)
425 if (!MarkBlockExecutable(Dest)) {
430 <<
" -> " << Dest->
getName() <<
'\n');
479 void visitLandingPadInst(
LandingPadInst &I) { markAnythingOverdefined(&I); }
490 visitTerminatorInst(II);
498 void visitAtomicRMWInst (
AtomicRMWInst &I) { markOverdefined(&I); }
499 void visitAllocaInst (
Instruction &I) { markOverdefined(&I); }
500 void visitVAArgInst (
Instruction &I) { markAnythingOverdefined(&I); }
504 dbgs() <<
"SCCP: Don't know how to handle: " << I <<
'\n';
505 markAnythingOverdefined(&I);
518 if (
BranchInst *BI = dyn_cast<BranchInst>(&TI)) {
519 if (BI->isUnconditional()) {
524 LatticeVal BCValue = getValueState(BI->getCondition());
529 if (!BCValue.isUndefined())
530 Succs[0] = Succs[1] =
true;
535 Succs[CI->isZero()] =
true;
539 if (isa<InvokeInst>(TI)) {
541 Succs[0] = Succs[1] =
true;
545 if (
SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
546 if (!SI->getNumCases()) {
550 LatticeVal SCValue = getValueState(SI->getCondition());
555 if (!SCValue.isUndefined())
560 Succs[SI->findCaseValue(CI).getSuccessorIndex()] =
true;
565 if (isa<IndirectBrInst>(&TI)) {
572 dbgs() <<
"Unknown terminator instruction: " << TI <<
'\n';
582 assert(BBExecutable.count(To) &&
"Dest should always be alive!");
585 if (!BBExecutable.count(From))
return false;
589 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
590 if (BI->isUnconditional())
593 LatticeVal BCValue = getValueState(BI->getCondition());
599 return !BCValue.isUndefined();
602 return BI->getSuccessor(CI->isZero()) == To;
606 if (isa<InvokeInst>(TI))
609 if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
610 if (SI->getNumCases() < 1)
613 LatticeVal SCValue = getValueState(SI->getCondition());
617 return !SCValue.isUndefined();
619 return SI->findCaseValue(CI).getCaseSuccessor() == To;
624 if (isa<IndirectBrInst>(TI))
628 dbgs() <<
"Unknown terminator instruction: " << *TI <<
'\n';
651 void SCCPSolver::visitPHINode(
PHINode &PN) {
655 return markAnythingOverdefined(&PN);
657 if (getValueState(&PN).isOverdefined())
663 return markOverdefined(&PN);
674 if (IV.isUndefined())
continue;
679 if (IV.isOverdefined())
680 return markOverdefined(&PN);
682 if (OperandVal == 0) {
683 OperandVal = IV.getConstant();
693 if (IV.getConstant() != OperandVal)
694 return markOverdefined(&PN);
703 markConstant(&PN, OperandVal);
706 void SCCPSolver::visitReturnInst(
ReturnInst &I) {
715 TrackedRetVals.
find(F);
716 if (TFRVI != TrackedRetVals.
end()) {
717 mergeInValue(TFRVI->second, F, getValueState(ResultOp));
723 if (!TrackedMultipleRetVals.empty()) {
725 if (MRVFunctionsTracked.count(F))
726 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
727 mergeInValue(TrackedMultipleRetVals[std::make_pair(F, i)],
F,
728 getStructValueState(ResultOp, i));
735 getFeasibleSuccessors(TI, SuccFeasible);
740 for (
unsigned i = 0, e = SuccFeasible.
size(); i != e; ++i)
745 void SCCPSolver::visitCastInst(
CastInst &I) {
746 LatticeVal OpSt = getValueState(I.
getOperand(0));
747 if (OpSt.isOverdefined())
749 else if (OpSt.isConstant())
751 OpSt.getConstant(), I.
getType()));
759 return markAnythingOverdefined(&EVI);
763 return markOverdefined(&EVI);
768 LatticeVal EltVal = getStructValueState(AggVal, i);
769 mergeInValue(getValueState(&EVI), &EVI, EltVal);
772 return markOverdefined(&EVI);
779 return markOverdefined(&IVI);
784 return markAnythingOverdefined(&IVI);
793 LatticeVal EltVal = getStructValueState(Aggr, i);
794 mergeInValue(getStructValueState(&IVI, i), &IVI, EltVal);
801 markOverdefined(getStructValueState(&IVI, i), &IVI);
803 LatticeVal InVal = getValueState(Val);
804 mergeInValue(getStructValueState(&IVI, i), &IVI, InVal);
809 void SCCPSolver::visitSelectInst(
SelectInst &I) {
813 return markAnythingOverdefined(&I);
816 if (CondValue.isUndefined())
819 if (
ConstantInt *CondCB = CondValue.getConstantInt()) {
821 mergeInValue(&I, getValueState(OpVal));
832 if (TVal.isConstant() && FVal.isConstant() &&
833 TVal.getConstant() == FVal.getConstant())
834 return markConstant(&I, FVal.getConstant());
836 if (TVal.isUndefined())
837 return mergeInValue(&I, FVal);
838 if (FVal.isUndefined())
839 return mergeInValue(&I, TVal);
844 void SCCPSolver::visitBinaryOperator(
Instruction &I) {
845 LatticeVal V1State = getValueState(I.
getOperand(0));
846 LatticeVal V2State = getValueState(I.
getOperand(1));
848 LatticeVal &IV = ValueState[&
I];
849 if (IV.isOverdefined())
return;
851 if (V1State.isConstant() && V2State.isConstant())
852 return markConstant(IV, &I,
854 V2State.getConstant()));
857 if (!V1State.isOverdefined() && !V2State.isOverdefined())
866 LatticeVal *NonOverdefVal = 0;
867 if (!V1State.isOverdefined())
868 NonOverdefVal = &V1State;
869 else if (!V2State.isOverdefined())
870 NonOverdefVal = &V2State;
873 if (NonOverdefVal->isUndefined()) {
887 if (NonOverdefVal->getConstant()->isNullValue())
888 return markConstant(IV, &I, NonOverdefVal->getConstant());
890 if (
ConstantInt *CI = NonOverdefVal->getConstantInt())
891 if (CI->isAllOnesValue())
892 return markConstant(IV, &I, NonOverdefVal->getConstant());
902 void SCCPSolver::visitCmpInst(
CmpInst &I) {
903 LatticeVal V1State = getValueState(I.
getOperand(0));
904 LatticeVal V2State = getValueState(I.
getOperand(1));
906 LatticeVal &IV = ValueState[&
I];
907 if (IV.isOverdefined())
return;
909 if (V1State.isConstant() && V2State.isConstant())
911 V1State.getConstant(),
912 V2State.getConstant()));
915 if (!V1State.isOverdefined() && !V2State.isOverdefined())
923 return markOverdefined(&I);
926 LatticeVal &ValState = getValueState(I.
getOperand(0));
927 LatticeVal &IdxState = getValueState(I.
getOperand(1));
929 if (ValState.isOverdefined() || IdxState.isOverdefined())
931 else if(ValState.isConstant() && IdxState.isConstant())
933 IdxState.getConstant()));
939 return markOverdefined(&I);
941 LatticeVal &ValState = getValueState(I.
getOperand(0));
942 LatticeVal &EltState = getValueState(I.
getOperand(1));
943 LatticeVal &IdxState = getValueState(I.
getOperand(2));
945 if (ValState.isOverdefined() || EltState.isOverdefined() ||
946 IdxState.isOverdefined())
948 else if(ValState.isConstant() && EltState.isConstant() &&
949 IdxState.isConstant())
951 EltState.getConstant(),
952 IdxState.getConstant()));
953 else if (ValState.isUndefined() && EltState.isConstant() &&
954 IdxState.isConstant())
956 EltState.getConstant(),
957 IdxState.getConstant()));
963 return markOverdefined(&I);
965 LatticeVal &V1State = getValueState(I.
getOperand(0));
966 LatticeVal &V2State = getValueState(I.
getOperand(1));
967 LatticeVal &MaskState = getValueState(I.
getOperand(2));
969 if (MaskState.isUndefined() ||
970 (V1State.isUndefined() && V2State.isUndefined()))
973 if (V1State.isOverdefined() || V2State.isOverdefined() ||
974 MaskState.isOverdefined()) {
978 Constant *V1 = V1State.isConstant() ?
982 Constant *Mask = MaskState.isConstant() ?
993 if (ValueState[&I].isOverdefined())
return;
999 LatticeVal State = getValueState(I.
getOperand(i));
1000 if (State.isUndefined())
1003 if (State.isOverdefined())
1004 return markOverdefined(&I);
1006 assert(State.isConstant() &&
"Unknown state!");
1007 Operands.
push_back(State.getConstant());
1015 void SCCPSolver::visitStoreInst(
StoreInst &SI) {
1020 if (TrackedGlobals.empty() || !isa<GlobalVariable>(SI.
getOperand(1)))
1025 if (I == TrackedGlobals.end() || I->second.isOverdefined())
return;
1028 mergeInValue(I->second, GV, getValueState(SI.
getOperand(0)));
1029 if (I->second.isOverdefined())
1030 TrackedGlobals.erase(I);
1036 void SCCPSolver::visitLoadInst(
LoadInst &I) {
1039 return markAnythingOverdefined(&I);
1041 LatticeVal PtrVal = getValueState(I.
getOperand(0));
1042 if (PtrVal.isUndefined())
return;
1044 LatticeVal &IV = ValueState[&
I];
1045 if (IV.isOverdefined())
return;
1048 return markOverdefined(IV, &I);
1050 Constant *Ptr = PtrVal.getConstant();
1058 if (!TrackedGlobals.empty()) {
1061 TrackedGlobals.
find(GV);
1062 if (It != TrackedGlobals.
end()) {
1063 mergeInValue(IV, &I, It->second);
1071 return markConstant(IV, &I, C);
1075 markOverdefined(IV, &I);
1078 void SCCPSolver::visitCallSite(
CallSite CS) {
1098 LatticeVal State = getValueState(*AI);
1100 if (State.isUndefined())
1102 if (State.isOverdefined())
1103 return markOverdefined(I);
1104 assert(State.isConstant() &&
"Unknown state!");
1105 Operands.
push_back(State.getConstant());
1111 return markConstant(I, C);
1115 return markAnythingOverdefined(I);
1121 if (!TrackingIncomingArguments.empty() && TrackingIncomingArguments.count(F)){
1122 MarkBlockExecutable(F->
begin());
1127 AI != E; ++AI, ++CAI) {
1131 markOverdefined(AI);
1135 if (
StructType *STy = dyn_cast<StructType>(AI->getType())) {
1137 LatticeVal
CallArg = getStructValueState(*CAI, i);
1138 mergeInValue(getStructValueState(AI, i), AI, CallArg);
1141 mergeInValue(AI, getValueState(*CAI));
1148 if (!MRVFunctionsTracked.count(F))
1149 goto CallOverdefined;
1154 mergeInValue(getStructValueState(I, i),
I,
1155 TrackedMultipleRetVals[std::make_pair(F, i)]);
1158 if (TFRVI == TrackedRetVals.
end())
1159 goto CallOverdefined;
1162 mergeInValue(I, TFRVI->second);
1166 void SCCPSolver::Solve() {
1168 while (!BBWorkList.empty() || !InstWorkList.empty() ||
1169 !OverdefinedInstWorkList.empty()) {
1172 while (!OverdefinedInstWorkList.empty()) {
1173 Value *I = OverdefinedInstWorkList.pop_back_val();
1175 DEBUG(
dbgs() <<
"\nPopped off OI-WL: " << *I <<
'\n');
1187 OperandChangedState(I);
1191 while (!InstWorkList.empty()) {
1192 Value *I = InstWorkList.pop_back_val();
1194 DEBUG(
dbgs() <<
"\nPopped off I-WL: " << *I <<
'\n');
1207 OperandChangedState(I);
1211 while (!BBWorkList.empty()) {
1213 BBWorkList.pop_back();
1215 DEBUG(
dbgs() <<
"\nPopped off BBWL: " << *BB <<
'\n');
1242 bool SCCPSolver::ResolvedUndefsIn(
Function &F) {
1244 if (!BBExecutable.count(BB))
1257 if (MRVFunctionsTracked.count(F))
1262 if (isa<ExtractValueInst>(I) || isa<InsertValueInst>(
I))
1268 LatticeVal &LV = getStructValueState(I, i);
1269 if (LV.isUndefined())
1270 markOverdefined(LV, I);
1275 LatticeVal &LV = getValueState(I);
1276 if (!LV.isUndefined())
continue;
1279 if (isa<ExtractValueInst>(I))
1289 LatticeVal Op0LV = getValueState(I->getOperand(0));
1291 if (I->getNumOperands() == 2) {
1297 Op1LV = getValueState(I->getOperand(1));
1302 switch (I->getOpcode()) {
1303 case Instruction::Add:
1304 case Instruction::Sub:
1305 case Instruction::Trunc:
1306 case Instruction::FPTrunc:
1307 case Instruction::BitCast:
1309 case Instruction::FSub:
1310 case Instruction::FAdd:
1311 case Instruction::FMul:
1312 case Instruction::FDiv:
1313 case Instruction::FRem:
1315 if (Op0LV.isUndefined() && Op1LV.isUndefined())
1320 case Instruction::ZExt:
1321 case Instruction::SExt:
1322 case Instruction::FPToUI:
1323 case Instruction::FPToSI:
1324 case Instruction::FPExt:
1325 case Instruction::PtrToInt:
1326 case Instruction::IntToPtr:
1327 case Instruction::SIToFP:
1328 case Instruction::UIToFP:
1332 case Instruction::Mul:
1335 if (Op0LV.isUndefined() && Op1LV.isUndefined())
1344 if (Op0LV.isUndefined() && Op1LV.isUndefined())
1354 if (Op0LV.isUndefined() && Op1LV.isUndefined()) {
1361 case Instruction::SDiv:
1362 case Instruction::UDiv:
1363 case Instruction::SRem:
1364 case Instruction::URem:
1367 if (Op1LV.isUndefined())
break;
1374 case Instruction::AShr:
1376 if (Op1LV.isUndefined())
break;
1381 case Instruction::LShr:
1382 case Instruction::Shl:
1385 if (Op1LV.isUndefined())
break;
1392 Op1LV = getValueState(I->getOperand(1));
1394 if (Op0LV.isUndefined()) {
1395 if (!Op1LV.isConstant())
1396 Op1LV = getValueState(I->getOperand(2));
1397 }
else if (Op1LV.isUndefined()) {
1399 Op1LV = getValueState(I->getOperand(2));
1400 if (Op1LV.isUndefined())
1407 if (Op1LV.isConstant())
1408 markForcedConstant(I, Op1LV.getConstant());
1417 case Instruction::ICmp:
1419 if (cast<ICmpInst>(I)->isEquality())
1424 case Instruction::Invoke: {
1431 if (TrackedRetVals.count(F))
1451 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
1452 if (!BI->isConditional())
continue;
1453 if (!getValueState(BI->getCondition()).isUndefined())
1458 if (isa<UndefValue>(BI->getCondition())) {
1467 markForcedConstant(BI->getCondition(),
1472 if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
1473 if (!SI->getNumCases())
1475 if (!getValueState(SI->getCondition()).isUndefined())
1480 if (isa<UndefValue>(SI->getCondition())) {
1481 SI->setCondition(SI->case_begin().getCaseValue());
1482 markEdgeExecutable(BB, SI->case_begin().getCaseSuccessor());
1486 markForcedConstant(SI->getCondition(), SI->case_begin().getCaseValue());
1519 "Sparse Conditional Constant Propagation",
false,
false)
1527 DEBUG(
dbgs() <<
" BasicBlock Dead:" << *BB);
1531 if (isa<TerminatorInst>(BB->
begin()))
1537 while (EndInst != BB->
begin()) {
1543 if (isa<LandingPadInst>(Inst)) {
1555 bool SCCP::runOnFunction(
Function &F) {
1557 const DataLayout *
TD = getAnalysisIfAvailable<DataLayout>();
1559 SCCPSolver Solver(TD, TLI);
1562 Solver.MarkBlockExecutable(F.
begin());
1566 Solver.markAnythingOverdefined(AI);
1569 bool ResolvedUndefs =
true;
1570 while (ResolvedUndefs) {
1573 ResolvedUndefs = Solver.ResolvedUndefsIn(F);
1576 bool MadeChanges =
false;
1583 if (!Solver.isBlockExecutable(BB)) {
1601 LatticeVal IV = Solver.getLatticeValueFor(Inst);
1602 if (IV.isOverdefined())
1607 DEBUG(
dbgs() <<
" Constant: " << *Const <<
" = " << *Inst <<
'\n');
1638 bool runOnModule(
Module &M);
1644 "Interprocedural Sparse Conditional Constant Propagation",
1653 return new IPSCCP();
1663 const User *U = *UI;
1664 if (
const StoreInst *SI = dyn_cast<StoreInst>(U)) {
1667 }
else if (isa<InvokeInst>(U) || isa<CallInst>(U)) {
1672 }
else if (
const LoadInst *
LI = dyn_cast<LoadInst>(U)) {
1673 if (
LI->isVolatile())
1675 }
else if (isa<BlockAddress>(U)) {
1685 bool IPSCCP::runOnModule(
Module &M) {
1686 const DataLayout *TD = getAnalysisIfAvailable<DataLayout>();
1688 SCCPSolver Solver(TD, TLI);
1707 Solver.AddTrackedFunction(F);
1714 AddressTakenFunctions.
insert(F);
1716 Solver.AddArgumentTrackedFunction(F);
1722 Solver.MarkBlockExecutable(F->
begin());
1727 Solver.markAnythingOverdefined(AI);
1736 Solver.TrackValueOfGlobalVariable(
G);
1739 bool ResolvedUndefs =
true;
1740 while (ResolvedUndefs) {
1744 ResolvedUndefs =
false;
1746 ResolvedUndefs |= Solver.ResolvedUndefsIn(*F);
1749 bool MadeChanges =
false;
1757 if (Solver.isBlockExecutable(F->
begin())) {
1760 if (AI->use_empty() || AI->getType()->isStructTy())
continue;
1765 LatticeVal IV = Solver.getLatticeValueFor(AI);
1766 if (IV.isOverdefined())
continue;
1770 DEBUG(
dbgs() <<
"*** Arg " << *AI <<
" = " << *CST <<
"\n");
1774 AI->replaceAllUsesWith(CST);
1780 if (!Solver.isBlockExecutable(BB)) {
1787 if (!Succ->
empty() && isa<PHINode>(Succ->
begin()))
1794 if (&*BB != &F->
front())
1809 LatticeVal IV = Solver.getLatticeValueFor(Inst);
1810 if (IV.isOverdefined())
1815 DEBUG(
dbgs() <<
" Constant: " << *Const <<
" = " << *Inst <<
'\n');
1822 if (!isa<CallInst>(Inst) && !isa<TerminatorInst>(Inst))
1834 for (
unsigned i = 0, e = BlocksToErase.
size(); i != e; ++i) {
1842 do { ++UI; }
while (UI != UE && *UI == I);
1853 if (
BranchInst *BI = dyn_cast<BranchInst>(I)) {
1854 assert(BI->isConditional() && isa<UndefValue>(BI->getCondition()) &&
1855 "Branch should be foldable!");
1856 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(I)) {
1857 assert(isa<UndefValue>(SI->getCondition()) &&
"Switch should fold");
1879 BlocksToErase.
clear();
1897 E = RV.
end(); I != E; ++
I) {
1908 if (!isa<UndefValue>(RI->getOperand(0)))
1913 for (
unsigned i = 0, e = ReturnsToZap.
size(); i != e; ++i) {
1914 Function *F = ReturnsToZap[i]->getParent()->getParent();
1922 E = TG.
end(); I != E; ++
I) {
1924 assert(!I->second.isOverdefined() &&
1925 "Overdefined values should have been taken out of the map!");
void push_back(const T &Elt)
static ConstantInt * getFalse(LLVMContext &Context)
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Abstract base class of comparison instructions.
bool isCallee(value_use_iterator< UserTy > UI) const
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask)
static PassRegistry * getPassRegistry()
Base class for instruction visitors.
Value * getAggregateOperand()
const Instruction & back() const
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
bool canConstantFoldCallTo(const Function *F)
The main container class for the LLVM Intermediate Representation.
static bool AddressIsTaken(const GlobalValue *GV)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
unsigned getNumOperands() const
static Constant * getGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false)
ModulePass * createIPSCCPPass()
static Constant * getExtractElement(Constant *Vec, Constant *Idx)
static void DeleteInstructionInBlock(BasicBlock *BB)
Type * getReturnType() const
unsigned getNumIndices() const
const Function * getParent() const
Return the enclosing method, or null if none.
const Constant * getInitializer() const
LoopInfoBase< BlockT, LoopT > * LI
static Constant * getNullValue(Type *Ty)
StringRef getName() const
bool isSingleValueType() const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
Base class of casting instructions.
#define llvm_unreachable(msg)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=0)
void assign(unsigned NumElts, const T &Elt)
ID
LLVM Calling Convention Representation.
global_iterator global_begin()
VectorType * getType() const
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
STATISTIC(NumInstRemoved,"Number of instructions removed")
Value * getInsertedValueOperand()
void replaceAllUsesWith(Value *V)
Type * getElementType() const
unsigned getNumIncomingValues() const
Constant * ConstantFoldCall(Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=0)
User::op_iterator arg_iterator
unsigned getNumSuccessors() const
LLVM Basic Block Representation.
InstrTy * getInstruction() const
BasicBlock * getSuccessor(unsigned idx) const
static bool mayBeOverridden(LinkageTypes Linkage)
void initializeSCCPPass(PassRegistry &)
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.
BasicBlock * getIncomingBlock(unsigned i) const
const InstListType & getInstList() const
Return the underlying instruction list container.
Value * getOperand(unsigned i) const
void initializeIPSCCPPass(PassRegistry &)
Predicate getPredicate() const
Return the predicate for this instruction.
Constant * ConstantFoldLoadFromConstPtr(Constant *C, const DataLayout *TD=0)
Constant * getAggregateElement(unsigned Elt) const
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
static UndefValue * get(Type *T)
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()
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
idx_iterator idx_begin() const
const BasicBlockListType & getBasicBlockList() const
Interprocedural Sparse Conditional Constant false
Class for constant integers.
Value * getIncomingValue(unsigned i) const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=0)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
PointerType * getType() const
getType - Global values are always pointers.
FunctionPass * createSCCPPass()
bool isDeclaration() const
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...
static Function * getCalledFunction(const Value *V, bool LookThroughBitCast)
VectorType * getType() const
bool hasLocalLinkage() const
const BasicBlock & front() const
void removeDeadConstantUsers() const
INITIALIZE_PASS_BEGIN(IPSCCP,"ipsccp","Interprocedural Sparse Conditional Constant Propagation", false, false) INITIALIZE_PASS_END(IPSCCP
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
const Value * getFalseValue() const
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2)
Return an ICmp or FCmp comparison operator constant expression.
unsigned getNumElements() const
Random access to the elements.
iterator find(const KeyT &Val)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty)
const BasicBlock * getParent() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx)
LLVMContext & getContext() const
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
FunTy * getCalledFunction() const