//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the Owen Anderson and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// ValueTable Class
//===----------------------------------------------------------------------===//
+namespace {
+
/// This class holds the mapping between values and value numbers. It is used
/// as an efficient mechanism to determine the expression-wise equivalence of
/// two values.
SmallVector<uint32_t, 4> varargs;
Expression() { }
- Expression(ExpressionOpcode o) : opcode(o) { }
+ explicit Expression(ExpressionOpcode o) : opcode(o) { }
bool operator==(const Expression &other) const {
if (opcode != other.opcode)
}
};
+}
namespace {
class VISIBILITY_HIDDEN ValueTable {
}
namespace llvm {
-template <> struct DenseMapKeyInfo<Expression> {
+template <> struct DenseMapInfo<Expression> {
static inline Expression getEmptyKey() {
return Expression(Expression::EMPTY);
}
hash = e.secondVN + hash * 37;
hash = e.thirdVN + hash * 37;
- hash = (unsigned)((uintptr_t)e.type >> 4) ^
- (unsigned)((uintptr_t)e.type >> 9) +
- hash * 37;
+ hash = ((unsigned)((uintptr_t)e.type >> 4) ^
+ (unsigned)((uintptr_t)e.type >> 9)) +
+ hash * 37;
for (SmallVector<uint32_t, 4>::const_iterator I = e.varargs.begin(),
E = e.varargs.end(); I != E; ++I)
return hash;
}
+ static bool isEqual(const Expression &LHS, const Expression &RHS) {
+ return LHS == RHS;
+ }
static bool isPod() { return true; }
};
}
return nextValueNumber;
}
+namespace {
+
//===----------------------------------------------------------------------===//
// ValueNumberedSet Class
//===----------------------------------------------------------------------===//
}
};
+}
+
//===----------------------------------------------------------------------===//
// GVNPRE Pass
//===----------------------------------------------------------------------===//
newVal = new ShuffleVectorInst(newOp1, newOp2, newOp3,
S->getName()+".expr");
else if (InsertElementInst* I = dyn_cast<InsertElementInst>(U))
- newVal = new InsertElementInst(newOp1, newOp2, newOp3,
- I->getName()+".expr");
+ newVal = InsertElementInst::Create(newOp1, newOp2, newOp3,
+ I->getName()+".expr");
else if (SelectInst* I = dyn_cast<SelectInst>(U))
- newVal = new SelectInst(newOp1, newOp2, newOp3, I->getName()+".expr");
+ newVal = SelectInst::Create(newOp1, newOp2, newOp3, I->getName()+".expr");
uint32_t v = VN.lookup_or_add(newVal);
}
if (newOp1 != U->getPointerOperand() || changed_idx) {
- Instruction* newVal = new GetElementPtrInst(newOp1,
- newIdx.begin(), newIdx.end(),
- U->getName()+".expr");
+ Instruction* newVal =
+ GetElementPtrInst::Create(newOp1,
+ newIdx.begin(), newIdx.end(),
+ U->getName()+".expr");
uint32_t v = VN.lookup_or_add(newVal);
isa<ShuffleVectorInst>(U) ||
isa<ExtractElementInst>(U) ||
isa<InsertElementInst>(U) ||
- isa<SelectInst>(U))
+ isa<SelectInst>(U)) {
if (isa<BinaryOperator>(U->getOperand(1)) ||
isa<CmpInst>(U->getOperand(1)) ||
isa<ShuffleVectorInst>(U->getOperand(1)) ||
} else {
s2 = U->getOperand(1);
}
+ }
// Ternary Operators
Value* s3 = 0;
if (isa<ShuffleVectorInst>(U) ||
isa<InsertElementInst>(U) ||
- isa<SelectInst>(U))
+ isa<SelectInst>(U)) {
if (isa<BinaryOperator>(U->getOperand(2)) ||
isa<CmpInst>(U->getOperand(2)) ||
isa<ShuffleVectorInst>(U->getOperand(2)) ||
} else {
s3 = U->getOperand(2);
}
+ }
// Vararg operators
SmallVector<Value*, 4> sVarargs;
newVal = new ShuffleVectorInst(s1, s2, s3, S->getName()+".gvnpre",
(*PI)->getTerminator());
else if (InsertElementInst* S = dyn_cast<InsertElementInst>(U))
- newVal = new InsertElementInst(s1, s2, s3, S->getName()+".gvnpre",
- (*PI)->getTerminator());
+ newVal = InsertElementInst::Create(s1, s2, s3, S->getName()+".gvnpre",
+ (*PI)->getTerminator());
else if (ExtractElementInst* S = dyn_cast<ExtractElementInst>(U))
newVal = new ExtractElementInst(s1, s2, S->getName()+".gvnpre",
(*PI)->getTerminator());
else if (SelectInst* S = dyn_cast<SelectInst>(U))
- newVal = new SelectInst(s1, s2, s3, S->getName()+".gvnpre",
- (*PI)->getTerminator());
+ newVal = SelectInst::Create(s1, s2, s3, S->getName()+".gvnpre",
+ (*PI)->getTerminator());
else if (CastInst* C = dyn_cast<CastInst>(U))
newVal = CastInst::create(C->getOpcode(), s1, C->getType(),
C->getName()+".gvnpre",
(*PI)->getTerminator());
else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(U))
- newVal = new GetElementPtrInst(s1, sVarargs.begin(), sVarargs.end(),
- G->getName()+".gvnpre",
- (*PI)->getTerminator());
-
-
+ newVal = GetElementPtrInst::Create(s1, sVarargs.begin(), sVarargs.end(),
+ G->getName()+".gvnpre",
+ (*PI)->getTerminator());
+
VN.add(newVal, VN.lookup(U));
ValueNumberedSet& predAvail = availableOut[*PI];
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
if (p == 0)
- p = new PHINode(avail[*PI]->getType(), "gvnpre-join", BB->begin());
+ p = PHINode::Create(avail[*PI]->getType(), "gvnpre-join", BB->begin());
p->addIncoming(avail[*PI], *PI);
}