mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-03 17:31:50 +00:00
Lowerpacked and SCCP support for the insertelement operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25406 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4eb2e3a6f4
commit
8fcf01ead0
@ -61,7 +61,11 @@ public:
|
||||
|
||||
/// @brief Lowers packed extractelement instructions.
|
||||
/// @param EI the extractelement operator to convert
|
||||
void visitExtractElementInst(ExtractElementInst& EI);
|
||||
void visitExtractElementInst(ExtractElementInst& EE);
|
||||
|
||||
/// @brief Lowers packed insertelement instructions.
|
||||
/// @param EI the insertelement operator to convert
|
||||
void visitInsertElementInst(InsertElementInst& IE);
|
||||
|
||||
/// This function asserts if the instruction is a PackedType but
|
||||
/// is handled by another function.
|
||||
@ -345,16 +349,19 @@ void LowerPacked::visitExtractElementInst(ExtractElementInst& EI)
|
||||
if (ConstantUInt *C = dyn_cast<ConstantUInt>(op1)) {
|
||||
EI.replaceAllUsesWith(op0Vals[C->getValue()]);
|
||||
} else {
|
||||
AllocaInst *alloca = new AllocaInst(PTy->getElementType(),
|
||||
ConstantUInt::get(Type::UIntTy, PTy->getNumElements()),
|
||||
EI.getName() + ".alloca", &(EI.getParent()->getParent()->getEntryBlock().front()));
|
||||
AllocaInst *alloca =
|
||||
new AllocaInst(PTy->getElementType(),
|
||||
ConstantUInt::get(Type::UIntTy, PTy->getNumElements()),
|
||||
EI.getName() + ".alloca",
|
||||
EI.getParent()->getParent()->getEntryBlock().begin());
|
||||
for (unsigned i = 0; i < PTy->getNumElements(); ++i) {
|
||||
GetElementPtrInst *GEP = new GetElementPtrInst(alloca, ConstantUInt::get(Type::UIntTy, i),
|
||||
"store.ge", &EI);
|
||||
GetElementPtrInst *GEP =
|
||||
new GetElementPtrInst(alloca, ConstantUInt::get(Type::UIntTy, i),
|
||||
"store.ge", &EI);
|
||||
new StoreInst(op0Vals[i], GEP, &EI);
|
||||
}
|
||||
GetElementPtrInst *GEP = new GetElementPtrInst(alloca, op1,
|
||||
EI.getName() + ".ge", &EI);
|
||||
GetElementPtrInst *GEP =
|
||||
new GetElementPtrInst(alloca, op1, EI.getName() + ".ge", &EI);
|
||||
LoadInst *load = new LoadInst(GEP, EI.getName() + ".load", &EI);
|
||||
EI.replaceAllUsesWith(load);
|
||||
}
|
||||
@ -363,6 +370,36 @@ void LowerPacked::visitExtractElementInst(ExtractElementInst& EI)
|
||||
instrsToRemove.push_back(&EI);
|
||||
}
|
||||
|
||||
void LowerPacked::visitInsertElementInst(InsertElementInst& IE)
|
||||
{
|
||||
std::vector<Value*>& Vals = getValues(IE.getOperand(0));
|
||||
Value *Elt = IE.getOperand(1);
|
||||
Value *Idx = IE.getOperand(2);
|
||||
std::vector<Value*> result;
|
||||
result.reserve(Vals.size());
|
||||
|
||||
if (ConstantUInt *C = dyn_cast<ConstantUInt>(Idx)) {
|
||||
unsigned idxVal = C->getValue();
|
||||
for (unsigned i = 0; i != Vals.size(); ++i) {
|
||||
result.push_back(i == idxVal ? Elt : Vals[i]);
|
||||
}
|
||||
} else {
|
||||
for (unsigned i = 0; i != Vals.size(); ++i) {
|
||||
SetCondInst *setcc =
|
||||
new SetCondInst(Instruction::SetEQ, Idx,
|
||||
ConstantUInt::get(Type::UIntTy, i),
|
||||
"setcc", &IE);
|
||||
SelectInst *select =
|
||||
new SelectInst(setcc, Elt, Vals[i], "select", &IE);
|
||||
result.push_back(select);
|
||||
}
|
||||
}
|
||||
|
||||
setValues(&IE, result);
|
||||
Changed = true;
|
||||
instrsToRemove.push_back(&IE);
|
||||
}
|
||||
|
||||
bool LowerPacked::runOnFunction(Function& F)
|
||||
{
|
||||
// initialize
|
||||
|
@ -323,6 +323,7 @@ private:
|
||||
void visitBinaryOperator(Instruction &I);
|
||||
void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
|
||||
void visitExtractElementInst(ExtractElementInst &I);
|
||||
void visitInsertElementInst(InsertElementInst &I);
|
||||
|
||||
// Instructions that cannot be folded away...
|
||||
void visitStoreInst (Instruction &I);
|
||||
@ -740,6 +741,26 @@ void SCCPSolver::visitExtractElementInst(ExtractElementInst &I) {
|
||||
IdxState.getConstant()));
|
||||
}
|
||||
|
||||
void SCCPSolver::visitInsertElementInst(InsertElementInst &I) {
|
||||
LatticeVal &ValState = getValueState(I.getOperand(0));
|
||||
LatticeVal &EltState = getValueState(I.getOperand(1));
|
||||
LatticeVal &IdxState = getValueState(I.getOperand(2));
|
||||
|
||||
if (ValState.isOverdefined() || EltState.isOverdefined() ||
|
||||
IdxState.isOverdefined())
|
||||
markOverdefined(&I);
|
||||
else if(ValState.isConstant() && EltState.isConstant() &&
|
||||
IdxState.isConstant())
|
||||
markConstant(&I, ConstantExpr::getInsertElement(ValState.getConstant(),
|
||||
EltState.getConstant(),
|
||||
IdxState.getConstant()));
|
||||
else if (ValState.isUndefined() && EltState.isConstant() &&
|
||||
IdxState.isConstant())
|
||||
markConstant(&I, ConstantExpr::getInsertElement(UndefValue::get(I.getType()),
|
||||
EltState.getConstant(),
|
||||
IdxState.getConstant()));
|
||||
}
|
||||
|
||||
// Handle getelementptr instructions... if all operands are constants then we
|
||||
// can turn this into a getelementptr ConstantExpr.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user