15 #define DEBUG_TYPE "sparseprop"
34 else if (V == OverdefinedVal)
36 else if (V == UntrackedVal)
39 OS <<
"unknown lattice value";
54 if (I != ValueState.end())
return I->second;
59 else if (
Constant *
C = dyn_cast<Constant>(V))
61 else if (
Argument *
A = dyn_cast<Argument>(V))
63 else if (!isa<Instruction>(V))
73 return ValueState[V] = LV;
78 void SparseSolver::UpdateState(
Instruction &Inst, LatticeVal V) {
80 if (I != ValueState.end() && I->second == V)
84 ValueState[&Inst] = V;
85 InstWorkList.push_back(&Inst);
90 void SparseSolver::MarkBlockExecutable(
BasicBlock *BB) {
92 BBExecutable.insert(BB);
93 BBWorkList.push_back(BB);
99 if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)
103 <<
" -> " << Dest->
getName() <<
"\n");
105 if (BBExecutable.count(Dest)) {
110 visitPHINode(*cast<PHINode>(I));
113 MarkBlockExecutable(Dest);
122 bool AggressiveUndef) {
126 if (
BranchInst *BI = dyn_cast<BranchInst>(&TI)) {
127 if (BI->isUnconditional()) {
141 Succs[0] = Succs[1] =
true;
150 if (C == 0 || !isa<ConstantInt>(C)) {
152 Succs[0] = Succs[1] =
true;
161 if (isa<InvokeInst>(TI)) {
164 Succs[0] = Succs[1] =
true;
168 if (isa<IndirectBrInst>(TI)) {
192 if (C == 0 || !isa<ConstantInt>(C)) {
205 bool AggressiveUndef) {
208 getFeasibleSuccessors(*TI, SuccFeasible, AggressiveUndef);
219 getFeasibleSuccessors(TI, SuccFeasible,
true);
224 for (
unsigned i = 0, e = SuccFeasible.
size(); i != e; ++i)
229 void SparseSolver::visitPHINode(
PHINode &PN) {
250 UpdateState(PN, Overdefined);
267 if (PNIV == Overdefined)
272 UpdateState(PN, PNIV);
279 if (
PHINode *PN = dyn_cast<PHINode>(&I))
280 return visitPHINode(*PN);
289 visitTerminatorInst(*TI);
296 while (!BBWorkList.empty() || !InstWorkList.empty()) {
298 while (!InstWorkList.empty()) {
300 InstWorkList.pop_back();
302 DEBUG(
dbgs() <<
"\nPopped off I-WL: " << *I <<
"\n");
315 while (!BBWorkList.empty()) {
317 BBWorkList.pop_back();
319 DEBUG(
dbgs() <<
"\nPopped off BBWL: " << *BB);
330 OS <<
"\nFUNCTION: " << F.
getName() <<
"\n";
332 if (!BBExecutable.count(BB))
333 OS <<
"INFEASIBLE: ";
LatticeVal getOrInitValueState(Value *V)
LLVM Argument representation.
LatticeVal getUndefVal() const
virtual LatticeVal ComputeInstructionState(Instruction &I, SparseSolver &SS)
bool isEdgeFeasible(BasicBlock *From, BasicBlock *To, bool AggressiveUndef=false)
unsigned getSuccessorIndex() const
Returns TerminatorInst's successor index for current case successor.
StringRef getName() const
virtual bool IsSpecialCasedPHI(PHINode *PN)
virtual bool IsUntrackedValue(Value *V)
void assign(unsigned NumElts, const T &Elt)
virtual LatticeVal ComputeConstant(Constant *C)
virtual ~AbstractLatticeFunction()
unsigned getNumIncomingValues() const
unsigned getNumSuccessors() const
LatticeVal getUntrackedVal() const
* if(!EatIfPresent(lltok::kw_thread_local)) return false
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
LLVM Constant Representation.
LatticeVal getLatticeState(Value *V) const
virtual Constant * GetConstant(LatticeVal LV, Value *Val, SparseSolver &SS)
BasicBlock * getIncomingBlock(unsigned i) const
virtual LatticeVal ComputeArgument(Argument *I)
void Print(Function &F, raw_ostream &OS) const
Value * getIncomingValue(unsigned i) const
const BasicBlock & getEntryBlock() const
CaseIt findCaseValue(const ConstantInt *C)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
virtual void PrintValue(LatticeVal V, raw_ostream &OS)
PrintValue - Render the specified lattice value to the specified stream.
Value * getCondition() const
virtual LatticeVal MergeValues(LatticeVal X, LatticeVal Y)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
LLVM Value Representation.
LatticeVal getOverdefinedVal() const
const BasicBlock * getParent() const