aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/ExprTypeConvert.cpp26
-rw-r--r--lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp29
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp3
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp20
4 files changed, 23 insertions, 55 deletions
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp
index a84f1d0f5e..33aa3cb475 100644
--- a/lib/Transforms/ExprTypeConvert.cpp
+++ b/lib/Transforms/ExprTypeConvert.cpp
@@ -24,19 +24,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
ValueMapCache &VMC);
-// AllIndicesZero - Return true if all of the indices of the specified memory
-// access instruction are zero, indicating an effectively nil offset to the
-// pointer value.
-//
-static bool AllIndicesZero(const MemAccessInst *MAI) {
- for (User::const_op_iterator S = MAI->idx_begin(), E = MAI->idx_end();
- S != E; ++S)
- if (!isa<Constant>(S->get()) || !cast<Constant>(S->get())->isNullValue())
- return false;
- return true;
-}
-
-
// Peephole Malloc instructions: we take a look at the use chain of the
// malloc instruction, and try to find out if the following conditions hold:
// 1. The malloc is of the form: 'malloc [sbyte], uint <constant>'
@@ -253,7 +240,7 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
// index array. If there are, check to see if removing them causes us to
// get to the right type...
//
- std::vector<Value*> Indices = GEP->copyIndices();
+ std::vector<Value*> Indices(GEP->idx_begin(), GEP->idx_end());
const Type *BaseType = GEP->getPointerOperand()->getType();
const Type *ElTy = 0;
@@ -446,7 +433,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
// index array. If there are, check to see if removing them causes us to
// get to the right type...
//
- std::vector<Value*> Indices = GEP->copyIndices();
+ std::vector<Value*> Indices(GEP->idx_begin(), GEP->idx_end());
const Type *BaseType = GEP->getPointerOperand()->getType();
const Type *PVTy = cast<PointerType>(Ty)->getElementType();
Res = 0;
@@ -497,8 +484,9 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
//
if (Res == 0) {
const PointerType *NewSrcTy = PointerType::get(PVTy);
+ std::vector<Value*> Indices(GEP->idx_begin(), GEP->idx_end());
Res = new GetElementPtrInst(Constant::getNullValue(NewSrcTy),
- GEP->copyIndices(), Name);
+ Indices, Name);
VMC.ExprMap[I] = Res;
Res->setOperand(0, ConvertExpressionToType(I->getOperand(0),
NewSrcTy, VMC));
@@ -1108,9 +1096,9 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// to getelementptr long * %reg123, uint %N
// ... where the type must simply stay the same size...
//
- Res = new GetElementPtrInst(NewVal,
- cast<GetElementPtrInst>(I)->copyIndices(),
- Name);
+ GetElementPtrInst *GEP = cast<GetElementPtrInst>(I);
+ std::vector<Value*> Indices(GEP->idx_begin(), GEP->idx_end());
+ Res = new GetElementPtrInst(NewVal, Indices, Name);
}
#endif
break;
diff --git a/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp b/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
index 4e6cbcf5f4..b50c4fb5bf 100644
--- a/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
+++ b/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
@@ -47,8 +47,8 @@ DecomposePass::runOnBasicBlock(BasicBlock &BB)
{
bool Changed = false;
for (BasicBlock::iterator II = BB.begin(); II != BB.end(); ) {
- if (MemAccessInst *MAI = dyn_cast<MemAccessInst>(&*II))
- if (MAI->getNumIndices() >= 2) {
+ if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&*II))
+ if (GEP->getNumIndices() >= 2) {
Changed |= decomposeArrayRef(II); // always modifies II
continue;
}
@@ -64,7 +64,7 @@ IsZero(Value* idx)
return (isa<ConstantInt>(idx) && cast<ConstantInt>(idx)->isNullValue());
}
-// For any MemAccessInst with 2 or more array and structure indices:
+// For any GetElementPtrInst with 2 or more array and structure indices:
//
// opCode CompositeType* P, [uint|ubyte] idx1, ..., [uint|ubyte] idxN
//
@@ -88,9 +88,9 @@ IsZero(Value* idx)
bool
DecomposePass::decomposeArrayRef(BasicBlock::iterator &BBI)
{
- MemAccessInst &MAI = cast<MemAccessInst>(*BBI);
- BasicBlock *BB = MAI.getParent();
- Value *LastPtr = MAI.getPointerOperand();
+ GetElementPtrInst &GEP = cast<GetElementPtrInst>(*BBI);
+ BasicBlock *BB = GEP.getParent();
+ Value *LastPtr = GEP.getPointerOperand();
// Remove the instruction from the stream
BB->getInstList().remove(BBI);
@@ -99,12 +99,12 @@ DecomposePass::decomposeArrayRef(BasicBlock::iterator &BBI)
std::vector<Instruction*> NewInsts;
// Process each index except the last one.
- User::const_op_iterator OI = MAI.idx_begin(), OE = MAI.idx_end();
+ User::const_op_iterator OI = GEP.idx_begin(), OE = GEP.idx_end();
for (; OI+1 != OE; ++OI) {
std::vector<Value*> Indices;
// If this is the first index and is 0, skip it and move on!
- if (OI == MAI.idx_begin()) {
+ if (OI == GEP.idx_begin()) {
if (IsZero(*OI)) continue;
} else
// Not the first index: include initial [0] to deref the last ptr
@@ -127,21 +127,14 @@ DecomposePass::decomposeArrayRef(BasicBlock::iterator &BBI)
Indices.push_back(Constant::getNullValue(Type::UIntTy));
Indices.push_back(*OI);
- Instruction *NewI = 0;
- switch(MAI.getOpcode()) {
- case Instruction::GetElementPtr:
- NewI = new GetElementPtrInst(LastPtr, Indices, MAI.getName());
- break;
- default:
- assert(0 && "Unrecognized memory access instruction");
- }
+ Instruction *NewI = new GetElementPtrInst(LastPtr, Indices, GEP.getName());
NewInsts.push_back(NewI);
// Replace all uses of the old instruction with the new
- MAI.replaceAllUsesWith(NewI);
+ GEP.replaceAllUsesWith(NewI);
// Now delete the old instruction...
- delete &MAI;
+ delete &GEP;
// Insert all of the new instructions...
BB->getInstList().insert(BBI, NewInsts.begin(), NewInsts.end());
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 61f41e140b..899bc5c881 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -183,7 +183,8 @@ private:
// Instructions that cannot be folded away...
void visitStoreInst (Instruction &I) { /*returns void*/ }
- void visitMemAccessInst (Instruction &I) { markOverdefined(&I); }
+ void visitLoadInst (Instruction &I) { markOverdefined(&I); }
+ void visitGetElementPtrInst(Instruction &I) { markOverdefined(&I); } // FIXME
void visitCallInst (Instruction &I) { markOverdefined(&I); }
void visitInvokeInst (Instruction &I) { markOverdefined(&I); }
void visitAllocationInst(Instruction &I) { markOverdefined(&I); }
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index d3aca318b0..5fcab97035 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -76,25 +76,11 @@ namespace {
static inline bool isSafeAlloca(const AllocaInst *AI) {
if (AI->isArrayAllocation()) return false;
+ // Only allow direct loads and stores...
for (Value::use_const_iterator UI = AI->use_begin(), UE = AI->use_end();
- UI != UE; ++UI) { // Loop over all of the uses of the alloca
-
- // Only allow nonindexed memory access instructions...
- if (MemAccessInst *MAI = dyn_cast<MemAccessInst>(*UI)) {
- if (MAI->getPointerOperand() != (Value*)AI)
- return false; // Reject stores of alloca pointer into some other loc.
-
- if (MAI->hasIndices()) { // indexed?
- // Allow the access if there is only one index and the index is
- // zero.
- if (*MAI->idx_begin() != Constant::getNullValue(Type::UIntTy) ||
- MAI->idx_begin()+1 != MAI->idx_end())
- return false;
- }
- } else {
+ UI != UE; ++UI) // Loop over all of the uses of the alloca
+ if (!isa<LoadInst>(*UI) && !isa<StoreInst>(*UI))
return false; // Not a load or store?
- }
- }
return true;
}