30
30
#include " llvm/Analysis/ConstantFolding.h"
31
31
#include " llvm/Analysis/GlobalsModRef.h"
32
32
#include " llvm/Analysis/TargetLibraryInfo.h"
33
- #include " llvm/Analysis/ValueLattice.h"
34
33
#include " llvm/Analysis/ValueLatticeUtils.h"
35
34
#include " llvm/IR/BasicBlock.h"
36
35
#include " llvm/IR/CallSite.h"
@@ -71,8 +70,6 @@ STATISTIC(NumDeadBlocks , "Number of basic blocks unreachable");
71
70
STATISTIC (IPNumInstRemoved, " Number of instructions removed by IPSCCP" );
72
71
STATISTIC (IPNumArgsElimed ," Number of arguments constant propagated by IPSCCP" );
73
72
STATISTIC (IPNumGlobalConst, " Number of globals found to be constant by IPSCCP" );
74
- STATISTIC (IPNumRangeInfoUsed, " Number of times constant range info was used by"
75
- " IPSCCP" );
76
73
77
74
namespace {
78
75
@@ -177,14 +174,6 @@ class LatticeVal {
177
174
Val.setInt (forcedconstant);
178
175
Val.setPointer (V);
179
176
}
180
-
181
- ValueLatticeElement toValueLattice () const {
182
- if (isOverdefined ())
183
- return ValueLatticeElement::getOverdefined ();
184
- if (isConstant ())
185
- return ValueLatticeElement::get (getConstant ());
186
- return ValueLatticeElement ();
187
- }
188
177
};
189
178
190
179
// ===----------------------------------------------------------------------===//
@@ -197,8 +186,6 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
197
186
const TargetLibraryInfo *TLI;
198
187
SmallPtrSet<BasicBlock *, 8 > BBExecutable; // The BBs that are executable.
199
188
DenseMap<Value *, LatticeVal> ValueState; // The state each value is in.
200
- // The state each parameter is in.
201
- DenseMap<Value *, ValueLatticeElement> ParamState;
202
189
203
190
// / StructValueState - This maintains ValueState for values that have
204
191
// / StructType, for example for formal arguments, calls, insertelement, etc.
@@ -325,18 +312,10 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
325
312
return StructValues;
326
313
}
327
314
328
- ValueLatticeElement getLatticeValueFor (Value *V) {
329
- std::pair<DenseMap<Value*, ValueLatticeElement>::iterator, bool >
330
- PI = ParamState.insert (std::make_pair (V, ValueLatticeElement ()));
331
- ValueLatticeElement &LV = PI.first ->second ;
332
- if (PI.second ) {
333
- DenseMap<Value*, LatticeVal>::const_iterator I = ValueState.find (V);
334
- assert (I != ValueState.end () &&
335
- " V not found in ValueState nor Paramstate map!" );
336
- LV = I->second .toValueLattice ();
337
- }
338
-
339
- return LV;
315
+ LatticeVal getLatticeValueFor (Value *V) const {
316
+ DenseMap<Value*, LatticeVal>::const_iterator I = ValueState.find (V);
317
+ assert (I != ValueState.end () && " V is not in valuemap!" );
318
+ return I->second ;
340
319
}
341
320
342
321
// / getTrackedRetVals - Get the inferred return value map.
@@ -465,18 +444,6 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
465
444
return LV;
466
445
}
467
446
468
- ValueLatticeElement &getParamState (Value *V) {
469
- assert (!V->getType ()->isStructTy () && " Should use getStructValueState" );
470
-
471
- std::pair<DenseMap<Value*, ValueLatticeElement>::iterator, bool >
472
- PI = ParamState.insert (std::make_pair (V, ValueLatticeElement ()));
473
- ValueLatticeElement &LV = PI.first ->second ;
474
- if (PI.second )
475
- LV = getValueState (V).toValueLattice ();
476
-
477
- return LV;
478
- }
479
-
480
447
// / getStructValueState - Return the LatticeVal object that corresponds to the
481
448
// / value/field pair. This function handles the case when the value hasn't
482
449
// / been seen yet by properly seeding constants etc.
@@ -1203,9 +1170,6 @@ void SCCPSolver::visitCallSite(CallSite CS) {
1203
1170
mergeInValue (getStructValueState (&*AI, i), &*AI, CallArg);
1204
1171
}
1205
1172
} else {
1206
- // Most other parts of the Solver still only use the simpler value
1207
- // lattice, so we propagate changes for parameters to both lattices.
1208
- getParamState (&*AI).mergeIn (getValueState (*CAI).toValueLattice (), DL);
1209
1173
mergeInValue (&*AI, getValueState (*CAI));
1210
1174
}
1211
1175
}
@@ -1596,43 +1560,6 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
1596
1560
return false ;
1597
1561
}
1598
1562
1599
- static bool tryToReplaceWithConstantRange (SCCPSolver &Solver, Value *V) {
1600
- bool Changed = false ;
1601
-
1602
- const ValueLatticeElement &IV = Solver.getLatticeValueFor (V);
1603
- if (IV.isOverdefined ())
1604
- return false ;
1605
-
1606
- // Currently we only use range information for integer values.
1607
- if (!(V->getType ()->isIntegerTy () && IV.isConstantRange ()))
1608
- return false ;
1609
-
1610
- for (auto UI = V->uses ().begin (), E = V->uses ().end (); UI != E;) {
1611
- const Use &U = *UI++;
1612
- auto *Icmp = dyn_cast<ICmpInst>(U.getUser ());
1613
- if (!Icmp || !Solver.isBlockExecutable (Icmp->getParent ()))
1614
- continue ;
1615
-
1616
- auto A = Solver.getLatticeValueFor (Icmp->getOperand (0 ));
1617
- auto B = Solver.getLatticeValueFor (Icmp->getOperand (1 ));
1618
- Constant *C = nullptr ;
1619
- if (A.satisfiesPredicate (Icmp->getPredicate (), B))
1620
- C = ConstantInt::getTrue (Icmp->getType ());
1621
- else if (A.satisfiesPredicate (Icmp->getInversePredicate (), B))
1622
- C = ConstantInt::getFalse (Icmp->getType ());
1623
-
1624
- if (C) {
1625
- Icmp->replaceAllUsesWith (C);
1626
- DEBUG (dbgs () << " Replacing " << *Icmp << " with " << *C
1627
- << " , because of range information " << A << " " << B
1628
- << " \n " );
1629
- Icmp->eraseFromParent ();
1630
- Changed = true ;
1631
- }
1632
- }
1633
- return Changed;
1634
- }
1635
-
1636
1563
static bool tryToReplaceWithConstant (SCCPSolver &Solver, Value *V) {
1637
1564
Constant *Const = nullptr ;
1638
1565
if (V->getType ()->isStructTy ()) {
@@ -1650,19 +1577,10 @@ static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
1650
1577
}
1651
1578
Const = ConstantStruct::get (ST, ConstVals);
1652
1579
} else {
1653
- const ValueLatticeElement & IV = Solver.getLatticeValueFor (V);
1580
+ LatticeVal IV = Solver.getLatticeValueFor (V);
1654
1581
if (IV.isOverdefined ())
1655
1582
return false ;
1656
-
1657
- if (IV.isConstantRange ()) {
1658
- if (IV.getConstantRange ().isSingleElement ())
1659
- Const =
1660
- ConstantInt::get (V->getType (), IV.asConstantInteger ().getValue ());
1661
- else
1662
- return false ;
1663
- } else
1664
- Const =
1665
- IV.isConstant () ? IV.getConstant () : UndefValue::get (V->getType ());
1583
+ Const = IV.isConstant () ? IV.getConstant () : UndefValue::get (V->getType ());
1666
1584
}
1667
1585
assert (Const && " Constant is nullptr here!" );
1668
1586
DEBUG (dbgs () << " Constant: " << *Const << " = " << *V << ' \n ' );
@@ -1863,14 +1781,10 @@ static bool runIPSCCP(Module &M, const DataLayout &DL,
1863
1781
1864
1782
if (Solver.isBlockExecutable (&F.front ()))
1865
1783
for (Function::arg_iterator AI = F.arg_begin (), E = F.arg_end (); AI != E;
1866
- ++AI) {
1784
+ ++AI)
1867
1785
if (!AI->use_empty () && tryToReplaceWithConstant (Solver, &*AI))
1868
1786
++IPNumArgsElimed;
1869
1787
1870
- if (!AI->use_empty () && tryToReplaceWithConstantRange (Solver, &*AI))
1871
- ++IPNumRangeInfoUsed;
1872
- }
1873
-
1874
1788
for (Function::iterator BB = F.begin (), E = F.end (); BB != E; ++BB) {
1875
1789
if (!Solver.isBlockExecutable (&*BB)) {
1876
1790
DEBUG (dbgs () << " BasicBlock Dead:" << *BB);
0 commit comments