[llvm-commits] [llvm] r52472 - /llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Owen Anderson
resistor at mac.com
Wed Jun 18 14:59:01 PDT 2008
Author: resistor
Date: Wed Jun 18 16:59:00 2008
New Revision: 52472
URL: http://llvm.org/viewvc/llvm-project?rev=52472&view=rev
Log:
Add support for extractvalue and insertvalue instructions in GVN.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=52472&r1=52471&r2=52472&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Wed Jun 18 16:59:00 2008
@@ -59,7 +59,7 @@
SHUFFLE, SELECT, TRUNC, ZEXT, SEXT, FPTOUI,
FPTOSI, UITOFP, SITOFP, FPTRUNC, FPEXT,
PTRTOINT, INTTOPTR, BITCAST, GEP, CALL, CONSTANT,
- EMPTY, TOMBSTONE };
+ EXTRACTVALUE, INSERTVALUE, EMPTY, TOMBSTONE };
ExpressionOpcode opcode;
const Type* type;
@@ -150,6 +150,8 @@
Expression create_expression(GetElementPtrInst* G);
Expression create_expression(CallInst* C);
Expression create_expression(Constant* C);
+ Expression create_expression(InsertValueInst* I);
+ Expression create_expression(ExtractValueInst* I);
public:
ValueTable() : nextValueNumber(1) { }
uint32_t lookup_or_add(Value* V);
@@ -284,6 +286,40 @@
}
}
+Expression ValueTable::create_expression(InsertValueInst* I) {
+ Expression e;
+
+ e.type = I->getType();
+ e.firstVN = lookup_or_add(I->getOperand(0));
+ e.secondVN = lookup_or_add(I->getOperand(1));
+ e.thirdVN = 0;
+ e.function = 0;
+ e.opcode = Expression::INSERTVALUE;
+
+ for (InsertValueInst::op_iterator OI = I->op_begin()+2,
+ OE = I->op_end(); OI != OE; ++OI)
+ e.varargs.push_back(lookup_or_add(I));
+
+ return e;
+}
+
+Expression ValueTable::create_expression(ExtractValueInst* I) {
+ Expression e;
+
+ e.type = I->getType();
+ e.firstVN = lookup_or_add(I->getOperand(0));
+ e.secondVN = lookup_or_add(I->getOperand(1));
+ e.thirdVN = 0;
+ e.function = 0;
+ e.opcode = Expression::EXTRACTVALUE;
+
+ for (InsertValueInst::op_iterator OI = I->op_begin()+2,
+ OE = I->op_end(); OI != OE; ++OI)
+ e.varargs.push_back(lookup_or_add(I));
+
+ return e;
+}
+
Expression ValueTable::create_expression(CallInst* C) {
Expression e;
@@ -541,6 +577,32 @@
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
}
+ } else if (InsertValueInst* II = dyn_cast<InsertValueInst>(V)) {
+ Expression e = create_expression(II);
+
+ DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
+ if (EI != expressionNumbering.end()) {
+ valueNumbering.insert(std::make_pair(V, EI->second));
+ return EI->second;
+ } else {
+ expressionNumbering.insert(std::make_pair(e, nextValueNumber));
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+
+ return nextValueNumber++;
+ }
+ } else if (ExtractValueInst* E = dyn_cast<ExtractValueInst>(V)) {
+ Expression e = create_expression(E);
+
+ DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
+ if (EI != expressionNumbering.end()) {
+ valueNumbering.insert(std::make_pair(V, EI->second));
+ return EI->second;
+ } else {
+ expressionNumbering.insert(std::make_pair(e, nextValueNumber));
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+
+ return nextValueNumber++;
+ }
} else if (BinaryOperator* BO = dyn_cast<BinaryOperator>(V)) {
Expression e = create_expression(BO);
More information about the llvm-commits
mailing list