#define DEBUG_TYPE "abcd"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Constants.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/SSI.h"
using namespace llvm;
STATISTIC(NumBranchTested, "Number of conditional branches analyzed");
STATISTIC(NumBranchRemoved, "Number of conditional branches removed");
namespace {
class ABCD : public FunctionPass {
public:
static char ID; ABCD() : FunctionPass(&ID) {}
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<SSI>();
}
bool runOnFunction(Function &F);
private:
bool modified;
enum ProveResult {
False = 0,
Reduced = 1,
True = 2
};
typedef ProveResult (*meet_function)(ProveResult, ProveResult);
static ProveResult max(ProveResult res1, ProveResult res2) {
return (ProveResult) std::max(res1, res2);
}
static ProveResult min(ProveResult res1, ProveResult res2) {
return (ProveResult) std::min(res1, res2);
}
class Bound {
public:
Bound(APInt v, bool upper) : value(v), upper_bound(upper) {}
Bound(const Bound *b, int cnst)
: value(b->value - cnst), upper_bound(b->upper_bound) {}
Bound(const Bound *b, const APInt &cnst)
: value(b->value - cnst), upper_bound(b->upper_bound) {}
bool isUpperBound() const { return upper_bound; }
int32_t getBitWidth() const { return value.getBitWidth(); }
static Bound *createIncrement(const Bound *b) {
return new Bound(b->isUpperBound() ? b->value+1 : b->value-1,
b->upper_bound);
}
static Bound *createDecrement(const Bound *b) {
return new Bound(b->isUpperBound() ? b->value-1 : b->value+1,
b->upper_bound);
}
static bool eq(const Bound *a, const Bound *b) {
if (!a || !b) return false;
assert(a->isUpperBound() == b->isUpperBound());
return a->value == b->value;
}
static bool leq(APInt val, const Bound *b) {
if (!b) return false;
return b->isUpperBound() ? val.sle(b->value) : val.sge(b->value);
}
static bool leq(const Bound *a, const Bound *b) {
if (!a || !b) return false;
assert(a->isUpperBound() == b->isUpperBound());
return a->isUpperBound() ? a->value.sle(b->value) :
a->value.sge(b->value);
}
static bool lt(const Bound *a, const Bound *b) {
if (!a || !b) return false;
assert(a->isUpperBound() == b->isUpperBound());
return a->isUpperBound() ? a->value.slt(b->value) :
a->value.sgt(b->value);
}
static bool geq(const Bound *b, APInt val) {
return leq(val, b);
}
static bool geq(const Bound *a, const Bound *b) {
return leq(b, a);
}
private:
APInt value;
bool upper_bound;
};
class MemoizedResultChart {
public:
MemoizedResultChart()
: max_false(NULL), min_true(NULL), min_reduced(NULL) {}
Bound *getFalse() const { return max_false; }
Bound *getTrue() const { return min_true; }
Bound *getReduced() const { return min_reduced; }
ProveResult getResult(const Bound *bound) const;
void addFalse(Bound *bound);
void addTrue(Bound *bound);
void addReduced(Bound *bound);
void clearRedundantReduced();
void clear() {
delete max_false;
delete min_true;
delete min_reduced;
}
private:
Bound *max_false, *min_true, *min_reduced;
};
class MemoizedResult {
public:
bool hasTrue(Value *b, const Bound *bound) const {
Bound *trueBound = map.lookup(b).getTrue();
return trueBound && Bound::leq(trueBound, bound);
}
bool hasFalse(Value *b, const Bound *bound) const {
Bound *falseBound = map.lookup(b).getFalse();
return falseBound && Bound::leq(falseBound, bound);
}
bool hasReduced(Value *b, const Bound *bound) const {
Bound *reducedBound = map.lookup(b).getReduced();
return reducedBound && Bound::leq(reducedBound, bound);
}
ProveResult getBoundResult(Value *b, Bound *bound) {
return map[b].getResult(bound);
}
void clear() {
DenseMapIterator<Value*, MemoizedResultChart> begin = map.begin();
DenseMapIterator<Value*, MemoizedResultChart> end = map.end();
for (; begin != end; ++begin) {
begin->second.clear();
}
map.clear();
}
void updateBound(Value *b, Bound *bound, const ProveResult res);
private:
DenseMap<Value*, MemoizedResultChart> map;
};
class Edge {
public:
Edge(Value *V, APInt val, bool upper)
: vertex(V), value(val), upper_bound(upper) {}
Value *getVertex() const { return vertex; }
const APInt &getValue() const { return value; }
bool isUpperBound() const { return upper_bound; }
private:
Value *vertex;
APInt value;
bool upper_bound;
};
class InequalityGraph {
public:
void addEdge(Value *V_from, Value *V_to, APInt value, bool upper);
bool hasNode(Value *V) const { return graph.count(V); }
bool hasEdge(Value *V, bool upper) const;
SmallPtrSet<Edge *, 16> getEdges(Value *V) const {
return graph.lookup(V);
}
void printGraph(raw_ostream &OS, Function &F) const {
printHeader(OS, F);
printBody(OS);
printFooter(OS);
}
void clear() {
graph.clear();
}
private:
DenseMap<Value *, SmallPtrSet<Edge *, 16> > graph;
DenseMap<Value *, SmallPtrSet<Edge *, 16> >::iterator addNode(Value *V) {
SmallPtrSet<Edge *, 16> p;
return graph.insert(std::make_pair(V, p)).first;
}
void printHeader(raw_ostream &OS, Function &F) const;
void printFooter(raw_ostream &OS) const {
OS << "}\n";
}
void printBody(raw_ostream &OS) const;
void printVertex(raw_ostream &OS, Value *source) const;
void printEdge(raw_ostream &OS, Value *source, Edge *edge) const;
void printName(raw_ostream &OS, Value *info) const;
};
void createSSI(Function &F);
void executeABCD(Function &F);
void seekRedundancy(ICmpInst *ICI, TerminatorInst *TI);
void removeRedundancy(TerminatorInst *TI, bool Succ_edge);
void fixPhi(BasicBlock *BB, BasicBlock *Succ);
void removePhis();
void createConstraintInstruction(Instruction *I);
void createConstraintBinaryOperator(BinaryOperator *BO);
void createConstraintCmpInst(ICmpInst *ICI, TerminatorInst *TI);
void createConstraintPHINode(PHINode *PN);
bool createBinaryOperatorInfo(BinaryOperator *BO, Instruction **I1,
Instruction **I2, ConstantInt **C1,
ConstantInt **C2);
void createConstraintSigInst(Instruction *I_op, BasicBlock *BB_succ_t,
BasicBlock *BB_succ_f, PHINode **SIG_op_t,
PHINode **SIG_op_f);
void createConstraintSigSig(PHINode *SIG_op1, PHINode *SIG_op2,
ConstantInt *V_op1, ConstantInt *V_op2,
APInt value);
PHINode *findSigma(BasicBlock *BB, Instruction *I);
bool demandProve(Value *a, Value *b, int c, bool upper_bound);
ProveResult prove(Value *a, Value *b, Bound *bound, unsigned level);
void updateMemDistance(Value *a, Value *b, Bound *bound, unsigned level,
meet_function meet);
InequalityGraph inequality_graph;
MemoizedResult mem_result;
DenseMap<Value*, Bound*> active;
SmallPtrSet<Value*, 16> created;
SmallVector<PHINode *, 16> phis_to_remove;
};
}
char ABCD::ID = 0;
static RegisterPass<ABCD> X("abcd", "ABCD: Eliminating Array Bounds Checks on Demand");
bool ABCD::runOnFunction(Function &F) {
modified = false;
createSSI(F);
executeABCD(F);
DEBUG(inequality_graph.printGraph(dbgs(), F));
removePhis();
inequality_graph.clear();
mem_result.clear();
active.clear();
created.clear();
phis_to_remove.clear();
return modified;
}
void ABCD::createSSI(Function &F) {
SSI *ssi = &getAnalysis<SSI>();
SmallVector<Instruction *, 16> Insts;
for (Function::iterator begin = F.begin(), end = F.end();
begin != end; ++begin) {
BasicBlock *BB = begin;
TerminatorInst *TI = BB->getTerminator();
if (TI->getNumOperands() == 0)
continue;
if (ICmpInst *ICI = dyn_cast<ICmpInst>(TI->getOperand(0))) {
if (Instruction *I = dyn_cast<Instruction>(ICI->getOperand(0))) {
modified = true; Insts.push_back(I);
}
if (Instruction *I = dyn_cast<Instruction>(ICI->getOperand(1))) {
modified = true;
Insts.push_back(I);
}
}
}
ssi->createSSI(Insts);
}
void ABCD::executeABCD(Function &F) {
for (Function::iterator begin = F.begin(), end = F.end();
begin != end; ++begin) {
BasicBlock *BB = begin;
TerminatorInst *TI = BB->getTerminator();
if (TI->getNumOperands() == 0)
continue;
ICmpInst *ICI = dyn_cast<ICmpInst>(TI->getOperand(0));
if (!ICI || !ICI->getOperand(0)->getType()->isIntegerTy())
continue;
createConstraintCmpInst(ICI, TI);
seekRedundancy(ICI, TI);
}
}
void ABCD::seekRedundancy(ICmpInst *ICI, TerminatorInst *TI) {
CmpInst::Predicate Pred = ICI->getPredicate();
Value *source, *dest;
int distance1, distance2;
bool upper;
switch(Pred) {
case CmpInst::ICMP_SGT: upper = false;
distance1 = 1;
distance2 = 0;
break;
case CmpInst::ICMP_SGE: upper = false;
distance1 = 0;
distance2 = -1;
break;
case CmpInst::ICMP_SLT: upper = true;
distance1 = -1;
distance2 = 0;
break;
case CmpInst::ICMP_SLE: upper = true;
distance1 = 0;
distance2 = 1;
break;
default:
return;
}
++NumBranchTested;
source = ICI->getOperand(0);
dest = ICI->getOperand(1);
if (demandProve(dest, source, distance1, upper)) {
removeRedundancy(TI, true);
} else if (demandProve(dest, source, distance2, !upper)) {
removeRedundancy(TI, false);
}
}
void ABCD::removeRedundancy(TerminatorInst *TI, bool Succ_edge) {
BasicBlock *Succ;
if (Succ_edge) {
Succ = TI->getSuccessor(0);
fixPhi(TI->getParent(), TI->getSuccessor(1));
} else {
Succ = TI->getSuccessor(1);
fixPhi(TI->getParent(), TI->getSuccessor(0));
}
BranchInst::Create(Succ, TI);
TI->eraseFromParent(); ++NumBranchRemoved;
modified = true;
}
void ABCD::fixPhi(BasicBlock *BB, BasicBlock *Succ) {
BasicBlock::iterator begin = Succ->begin();
while (PHINode *PN = dyn_cast<PHINode>(begin++)) {
PN->removeIncomingValue(BB, false);
if (PN->getNumIncomingValues() == 0)
phis_to_remove.push_back(PN);
}
}
void ABCD::removePhis() {
for (unsigned i = 0, e = phis_to_remove.size(); i != e; ++i) {
PHINode *PN = phis_to_remove[i];
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
PN->eraseFromParent();
}
}
void ABCD::createConstraintInstruction(Instruction *I) {
if (created.insert(I)) {
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I)) {
createConstraintBinaryOperator(BO);
} else if (PHINode *PN = dyn_cast<PHINode>(I)) {
createConstraintPHINode(PN);
}
}
}
void ABCD::createConstraintBinaryOperator(BinaryOperator *BO) {
Instruction *I1 = NULL, *I2 = NULL;
ConstantInt *CI1 = NULL, *CI2 = NULL;
if (!createBinaryOperatorInfo(BO, &I1, &I2, &CI1, &CI2))
return;
Instruction *I = 0;
APInt value;
switch (BO->getOpcode()) {
case Instruction::Add:
if (I1) {
I = I1;
value = CI2->getValue();
} else if (I2) {
I = I2;
value = CI1->getValue();
}
break;
case Instruction::Sub:
if (!I1)
return;
I = I1;
value = -CI2->getValue();
break;
default:
return;
}
inequality_graph.addEdge(I, BO, value, true);
inequality_graph.addEdge(BO, I, -value, false);
createConstraintInstruction(I);
}
bool ABCD::createBinaryOperatorInfo(BinaryOperator *BO, Instruction **I1,
Instruction **I2, ConstantInt **C1,
ConstantInt **C2) {
Value *op1 = BO->getOperand(0);
Value *op2 = BO->getOperand(1);
if ((*I1 = dyn_cast<Instruction>(op1))) {
if ((*C2 = dyn_cast<ConstantInt>(op2)))
return true;
return false; } else {
if ((*C1 = dyn_cast<ConstantInt>(op1)) &&
(*I2 = dyn_cast<Instruction>(op2)))
return true;
return false; }
}
void ABCD::createConstraintCmpInst(ICmpInst *ICI, TerminatorInst *TI) {
Value *V_op1 = ICI->getOperand(0);
Value *V_op2 = ICI->getOperand(1);
if (!V_op1->getType()->isIntegerTy())
return;
Instruction *I_op1 = dyn_cast<Instruction>(V_op1);
Instruction *I_op2 = dyn_cast<Instruction>(V_op2);
if (!I_op1 && !I_op2)
return;
BasicBlock *BB_succ_t = TI->getSuccessor(0);
BasicBlock *BB_succ_f = TI->getSuccessor(1);
PHINode *SIG_op1_t = NULL, *SIG_op1_f = NULL,
*SIG_op2_t = NULL, *SIG_op2_f = NULL;
createConstraintSigInst(I_op1, BB_succ_t, BB_succ_f, &SIG_op1_t, &SIG_op1_f);
createConstraintSigInst(I_op2, BB_succ_t, BB_succ_f, &SIG_op2_t, &SIG_op2_f);
int32_t width = cast<IntegerType>(V_op1->getType())->getBitWidth();
APInt MinusOne = APInt::getAllOnesValue(width);
APInt Zero = APInt::getNullValue(width);
CmpInst::Predicate Pred = ICI->getPredicate();
ConstantInt *CI1 = dyn_cast<ConstantInt>(V_op1);
ConstantInt *CI2 = dyn_cast<ConstantInt>(V_op2);
switch (Pred) {
case CmpInst::ICMP_SGT: createConstraintSigSig(SIG_op2_t, SIG_op1_t, CI2, CI1, MinusOne);
createConstraintSigSig(SIG_op1_f, SIG_op2_f, CI1, CI2, Zero);
break;
case CmpInst::ICMP_SGE: createConstraintSigSig(SIG_op2_t, SIG_op1_t, CI2, CI1, Zero);
createConstraintSigSig(SIG_op1_f, SIG_op2_f, CI1, CI2, MinusOne);
break;
case CmpInst::ICMP_SLT: createConstraintSigSig(SIG_op1_t, SIG_op2_t, CI1, CI2, MinusOne);
createConstraintSigSig(SIG_op2_f, SIG_op1_f, CI2, CI1, Zero);
break;
case CmpInst::ICMP_SLE: createConstraintSigSig(SIG_op1_t, SIG_op2_t, CI1, CI2, Zero);
createConstraintSigSig(SIG_op2_f, SIG_op1_f, CI2, CI1, MinusOne);
break;
default:
break;
}
if (I_op1)
createConstraintInstruction(I_op1);
if (I_op2)
createConstraintInstruction(I_op2);
}
void ABCD::createConstraintPHINode(PHINode *PN) {
if (PN->getNumOperands() == 2) return;
int32_t width = cast<IntegerType>(PN->getType())->getBitWidth();
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
Value *V = PN->getIncomingValue(i);
if (Instruction *I = dyn_cast<Instruction>(V)) {
createConstraintInstruction(I);
}
inequality_graph.addEdge(V, PN, APInt(width, 0), true);
inequality_graph.addEdge(V, PN, APInt(width, 0), false);
}
}
void ABCD::createConstraintSigInst(Instruction *I_op, BasicBlock *BB_succ_t,
BasicBlock *BB_succ_f, PHINode **SIG_op_t,
PHINode **SIG_op_f) {
*SIG_op_t = findSigma(BB_succ_t, I_op);
*SIG_op_f = findSigma(BB_succ_f, I_op);
if (*SIG_op_t) {
int32_t width = cast<IntegerType>((*SIG_op_t)->getType())->getBitWidth();
inequality_graph.addEdge(I_op, *SIG_op_t, APInt(width, 0), true);
inequality_graph.addEdge(*SIG_op_t, I_op, APInt(width, 0), false);
}
if (*SIG_op_f) {
int32_t width = cast<IntegerType>((*SIG_op_f)->getType())->getBitWidth();
inequality_graph.addEdge(I_op, *SIG_op_f, APInt(width, 0), true);
inequality_graph.addEdge(*SIG_op_f, I_op, APInt(width, 0), false);
}
}
void ABCD::createConstraintSigSig(PHINode *SIG_op1, PHINode *SIG_op2,
ConstantInt *V_op1, ConstantInt *V_op2,
APInt value) {
if (SIG_op1 && SIG_op2) {
inequality_graph.addEdge(SIG_op2, SIG_op1, value, true);
inequality_graph.addEdge(SIG_op1, SIG_op2, -value, false);
} else if (SIG_op1 && V_op2) {
inequality_graph.addEdge(V_op2, SIG_op1, value, true);
inequality_graph.addEdge(SIG_op1, V_op2, -value, false);
} else if (SIG_op2 && V_op1) {
inequality_graph.addEdge(SIG_op2, V_op1, value, true);
inequality_graph.addEdge(V_op1, SIG_op2, -value, false);
}
}
PHINode *ABCD::findSigma(BasicBlock *BB, Instruction *I) {
if (I == NULL || BB->getSinglePredecessor() == NULL)
return NULL;
BasicBlock::iterator begin = BB->begin();
BasicBlock::iterator end = BB->end();
for (unsigned i = 0; i < 2 && begin != end; ++i, ++begin) {
Instruction *I_succ = begin;
if (PHINode *PN = dyn_cast<PHINode>(I_succ))
if (PN->getIncomingValue(0) == I)
return PN;
}
return NULL;
}
bool ABCD::demandProve(Value *a, Value *b, int c, bool upper_bound) {
int32_t width = cast<IntegerType>(a->getType())->getBitWidth();
Bound *bound = new Bound(APInt(width, c), upper_bound);
mem_result.clear();
active.clear();
ProveResult res = prove(a, b, bound, 0);
return res != False;
}
ABCD::ProveResult ABCD::prove(Value *a, Value *b, Bound *bound,
unsigned level) {
if (mem_result.hasTrue(b, bound))
return True;
if (mem_result.hasFalse(b, bound))
return False;
if (mem_result.hasReduced(b, bound))
return Reduced;
if (a == b && Bound::geq(bound, APInt(bound->getBitWidth(), 0, true)))
return True;
if (!inequality_graph.hasEdge(b, bound->isUpperBound()))
return False;
if (active.count(b)) {
if (Bound::leq(active.lookup(b), bound))
return Reduced;
return False; }
active[b] = bound;
PHINode *PN = dyn_cast<PHINode>(b);
if (PN && PN->getNumIncomingValues() > 1)
updateMemDistance(a, b, bound, level, min);
else
updateMemDistance(a, b, bound, level, max);
active.erase(b);
ABCD::ProveResult res = mem_result.getBoundResult(b, bound);
return res;
}
void ABCD::updateMemDistance(Value *a, Value *b, Bound *bound, unsigned level,
meet_function meet) {
ABCD::ProveResult res = (meet == max) ? False : True;
SmallPtrSet<Edge *, 16> Edges = inequality_graph.getEdges(b);
SmallPtrSet<Edge *, 16>::iterator begin = Edges.begin(), end = Edges.end();
for (; begin != end ; ++begin) {
if (((res >= Reduced) && (meet == max)) ||
((res == False) && (meet == min))) {
break;
}
Edge *in = *begin;
if (in->isUpperBound() == bound->isUpperBound()) {
Value *succ = in->getVertex();
res = meet(res, prove(a, succ, new Bound(bound, in->getValue()),
level+1));
}
}
mem_result.updateBound(b, bound, res);
}
ABCD::ProveResult ABCD::MemoizedResultChart::getResult(const Bound *bound)const{
if (max_false && Bound::leq(bound, max_false))
return False;
if (min_true && Bound::leq(min_true, bound))
return True;
if (min_reduced && Bound::leq(min_reduced, bound))
return Reduced;
return False;
}
void ABCD::MemoizedResultChart::addFalse(Bound *bound) {
if (!max_false || Bound::leq(max_false, bound))
max_false = bound;
if (Bound::eq(max_false, min_reduced))
min_reduced = Bound::createIncrement(min_reduced);
if (Bound::eq(max_false, min_true))
min_true = Bound::createIncrement(min_true);
if (Bound::eq(min_reduced, min_true))
min_reduced = NULL;
clearRedundantReduced();
}
void ABCD::MemoizedResultChart::addTrue(Bound *bound) {
if (!min_true || Bound::leq(bound, min_true))
min_true = bound;
if (Bound::eq(min_true, min_reduced))
min_reduced = Bound::createDecrement(min_reduced);
if (Bound::eq(min_true, max_false))
max_false = Bound::createDecrement(max_false);
if (Bound::eq(max_false, min_reduced))
min_reduced = NULL;
clearRedundantReduced();
}
void ABCD::MemoizedResultChart::addReduced(Bound *bound) {
if (!min_reduced || Bound::leq(bound, min_reduced))
min_reduced = bound;
if (Bound::eq(min_reduced, min_true))
min_true = Bound::createIncrement(min_true);
if (Bound::eq(min_reduced, max_false))
max_false = Bound::createDecrement(max_false);
}
void ABCD::MemoizedResultChart::clearRedundantReduced() {
if (min_true && min_reduced && Bound::lt(min_true, min_reduced))
min_reduced = NULL;
if (max_false && min_reduced && Bound::lt(min_reduced, max_false))
min_reduced = NULL;
}
void ABCD::MemoizedResult::updateBound(Value *b, Bound *bound,
const ProveResult res) {
if (res == False) {
map[b].addFalse(bound);
} else if (res == True) {
map[b].addTrue(bound);
} else {
map[b].addReduced(bound);
}
}
void ABCD::InequalityGraph::addEdge(Value *V_to, Value *V_from,
APInt value, bool upper) {
assert(V_from->getType() == V_to->getType());
assert(cast<IntegerType>(V_from->getType())->getBitWidth() ==
value.getBitWidth());
DenseMap<Value *, SmallPtrSet<Edge *, 16> >::iterator from;
from = addNode(V_from);
from->second.insert(new Edge(V_to, value, upper));
}
bool ABCD::InequalityGraph::hasEdge(Value *V, bool upper) const {
SmallPtrSet<Edge *, 16> it = graph.lookup(V);
SmallPtrSet<Edge *, 16>::iterator begin = it.begin();
SmallPtrSet<Edge *, 16>::iterator end = it.end();
for (; begin != end; ++begin) {
if ((*begin)->isUpperBound() == upper) {
return true;
}
}
return false;
}
void ABCD::InequalityGraph::printHeader(raw_ostream &OS, Function &F) const {
OS << "digraph dotgraph {\n";
OS << "label=\"Inequality Graph for \'";
OS << F.getNameStr() << "\' function\";\n";
OS << "node [shape=record,fontname=\"Times-Roman\",fontsize=14];\n";
}
void ABCD::InequalityGraph::printBody(raw_ostream &OS) const {
DenseMap<Value *, SmallPtrSet<Edge *, 16> >::const_iterator begin =
graph.begin(), end = graph.end();
for (; begin != end ; ++begin) {
SmallPtrSet<Edge *, 16>::iterator begin_par =
begin->second.begin(), end_par = begin->second.end();
Value *source = begin->first;
printVertex(OS, source);
for (; begin_par != end_par ; ++begin_par) {
Edge *edge = *begin_par;
printEdge(OS, source, edge);
}
}
}
void ABCD::InequalityGraph::printVertex(raw_ostream &OS, Value *source) const {
OS << "\"";
printName(OS, source);
OS << "\"";
OS << " [label=\"{";
printName(OS, source);
OS << "}\"];\n";
}
void ABCD::InequalityGraph::printEdge(raw_ostream &OS, Value *source,
Edge *edge) const {
Value *dest = edge->getVertex();
APInt value = edge->getValue();
bool upper = edge->isUpperBound();
OS << "\"";
printName(OS, source);
OS << "\"";
OS << " -> ";
OS << "\"";
printName(OS, dest);
OS << "\"";
OS << " [label=\"" << value << "\"";
if (upper) {
OS << "color=\"blue\"";
} else {
OS << "color=\"red\"";
}
OS << "];\n";
}
void ABCD::InequalityGraph::printName(raw_ostream &OS, Value *info) const {
if (ConstantInt *CI = dyn_cast<ConstantInt>(info)) {
OS << *CI;
} else {
if (!info->hasName()) {
info->setName("V");
}
OS << info->getNameStr();
}
}
FunctionPass *llvm::createABCDPass() {
return new ABCD();
}