mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
Apply some cleanups. No functionality changes.
llvm-svn: 85498
This commit is contained in:
parent
57a8d8d4e0
commit
5207d16c05
@ -14,7 +14,7 @@
|
||||
// languages. This implementation expands the idea and removes any conditional
|
||||
// branches that can be proved redundant, not only those used in array bound
|
||||
// checks. With the SSI representation, each variable has a
|
||||
// constraint. By analyzing these constraints we can proof that a branch is
|
||||
// constraint. By analyzing these constraints we can prove that a branch is
|
||||
// redundant. When a branch is proved redundant it means that
|
||||
// one direction will always be taken; thus, we can change this branch into an
|
||||
// unconditional jump.
|
||||
@ -43,7 +43,7 @@ using namespace llvm;
|
||||
STATISTIC(NumBranchTested, "Number of conditional branches analyzed");
|
||||
STATISTIC(NumBranchRemoved, "Number of conditional branches removed");
|
||||
|
||||
//namespace {
|
||||
namespace {
|
||||
|
||||
class ABCD : public FunctionPass {
|
||||
public:
|
||||
@ -57,6 +57,7 @@ class ABCD : public FunctionPass {
|
||||
bool runOnFunction(Function &F);
|
||||
|
||||
private:
|
||||
/// Keep track of whether we've modified the program yet.
|
||||
bool modified;
|
||||
|
||||
enum ProveResult {
|
||||
@ -151,8 +152,8 @@ class ABCD : public FunctionPass {
|
||||
/// minimum true and minimum reduced results are stored
|
||||
class MemoizedResultChart {
|
||||
public:
|
||||
MemoizedResultChart() : max_false(NULL), min_true(NULL),
|
||||
min_reduced(NULL) {}
|
||||
MemoizedResultChart()
|
||||
: max_false(NULL), min_true(NULL), min_reduced(NULL) {}
|
||||
|
||||
/// Returns the max false
|
||||
Bound *getFalse() const { return max_false; }
|
||||
@ -192,7 +193,7 @@ class ABCD : public FunctionPass {
|
||||
};
|
||||
|
||||
/// This class stores the result found for a node of the graph,
|
||||
/// so these results do not need to be recalculate and only searched for.
|
||||
/// so these results do not need to be recalculated, only searched for.
|
||||
class MemoizedResult {
|
||||
public:
|
||||
/// Test if there is true result stored from b to a
|
||||
@ -244,9 +245,8 @@ class ABCD : public FunctionPass {
|
||||
/// we could infer a constraint v <= u + c in the source program.
|
||||
class Edge {
|
||||
public:
|
||||
Edge(Value *V, APInt val, bool upper) : vertex(V), value(val),
|
||||
upper_bound(upper)
|
||||
{}
|
||||
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; }
|
||||
@ -439,7 +439,7 @@ class ABCD : public FunctionPass {
|
||||
SmallVector<PHINode *, 16> phis_to_remove;
|
||||
};
|
||||
|
||||
//} // end anonymous namespace.
|
||||
} // end anonymous namespace.
|
||||
|
||||
char ABCD::ID = 0;
|
||||
static RegisterPass<ABCD> X("abcd", "ABCD: Eliminating Array Bounds Checks on Demand");
|
||||
@ -600,7 +600,7 @@ void ABCD::fixPhi(BasicBlock *BB, BasicBlock *Succ) {
|
||||
|
||||
/// Removes phis that have no predecessor
|
||||
void ABCD::removePhis() {
|
||||
for (unsigned i = 0, end = phis_to_remove.size(); i < end; ++i) {
|
||||
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();
|
||||
@ -666,9 +666,8 @@ void ABCD::createConstraintBinaryOperator(BinaryOperator *BO) {
|
||||
return;
|
||||
}
|
||||
|
||||
APInt MinusOne = APInt::getAllOnesValue(value.getBitWidth());
|
||||
inequality_graph.addEdge(I, BO, value, true);
|
||||
inequality_graph.addEdge(BO, I, value * MinusOne, false);
|
||||
inequality_graph.addEdge(BO, I, -value, false);
|
||||
createConstraintInstruction(I);
|
||||
}
|
||||
|
||||
@ -728,10 +727,8 @@ void ABCD::createConstraintCmpInst(ICmpInst *ICI, TerminatorInst *TI) {
|
||||
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);
|
||||
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);
|
||||
@ -776,7 +773,7 @@ void ABCD::createConstraintCmpInst(ICmpInst *ICI, TerminatorInst *TI) {
|
||||
/// a->b and a->c with weight 0 in the upper bound graph.
|
||||
void ABCD::createConstraintPHINode(PHINode *PN) {
|
||||
int32_t width = cast<IntegerType>(PN->getType())->getBitWidth();
|
||||
for (unsigned i = 0, end = PN->getNumIncomingValues(); i < end; ++i) {
|
||||
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
|
||||
Value *V = PN->getIncomingValue(i);
|
||||
if (Instruction *I = dyn_cast<Instruction>(V)) {
|
||||
createConstraintInstruction(I);
|
||||
@ -815,9 +812,8 @@ void ABCD::createConstraintSigInst(Instruction *I_op, BasicBlock *BB_succ_t,
|
||||
void ABCD::createConstraintSigSig(PHINode *SIG_op1, PHINode *SIG_op2,
|
||||
APInt value) {
|
||||
if (SIG_op1 && SIG_op2) {
|
||||
APInt MinusOne = APInt::getAllOnesValue(value.getBitWidth());
|
||||
inequality_graph.addEdge(SIG_op2, SIG_op1, value, true);
|
||||
inequality_graph.addEdge(SIG_op1, SIG_op2, value * MinusOne, false);
|
||||
inequality_graph.addEdge(SIG_op1, SIG_op2, -value, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1093,9 +1089,9 @@ void ABCD::InequalityGraph::printEdge(raw_ostream &OS, Value *source,
|
||||
|
||||
void ABCD::InequalityGraph::printName(raw_ostream &OS, Value *info) const {
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(info)) {
|
||||
OS << *CI->getValue().getRawData();
|
||||
OS << *CI;
|
||||
} else {
|
||||
if (info->getName() == "") {
|
||||
if (!info->hasName()) {
|
||||
info->setName("V");
|
||||
}
|
||||
OS << info->getNameStr();
|
||||
|
Loading…
Reference in New Issue
Block a user