mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-23 02:32:11 +00:00
Add support for extractvalue and insertvalue instructions in GVN.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52472 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b230372437
commit
d34ac6e782
@ -59,7 +59,7 @@ namespace {
|
||||
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 @@ namespace {
|
||||
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::ExpressionOpcode ValueTable::getOpcode(CastInst* C) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -539,6 +575,32 @@ uint32_t ValueTable::lookup_or_add(Value* V) {
|
||||
|
||||
} else {
|
||||
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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user