Convert TargetData::getIndexedOffset to use ArrayRef.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135478 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jay Foad
2011-07-19 14:01:37 +00:00
parent 1d2f569c34
commit 8fbbb39807
11 changed files with 25 additions and 30 deletions

View File

@ -646,6 +646,7 @@ from the previous release.</p>
<li><code>MDNode::getIfExists</code></li> <li><code>MDNode::getIfExists</code></li>
<li><code>MDNode::getTemporary</code></li> <li><code>MDNode::getTemporary</code></li>
<li><code>MDNode::getWhenValsUnresolved</code></li> <li><code>MDNode::getWhenValsUnresolved</code></li>
<li><code>TargetData::getIndexedOffset</code></li>
</ul></li> </ul></li>
<li>All forms of <code>StringMap::getOrCreateValue</code> have been remove <li>All forms of <code>StringMap::getOrCreateValue</code> have been remove

View File

@ -33,6 +33,8 @@ class StructType;
class StructLayout; class StructLayout;
class GlobalVariable; class GlobalVariable;
class LLVMContext; class LLVMContext;
template<typename T>
class ArrayRef;
/// Enum used to categorize the alignment types stored by TargetAlignElem /// Enum used to categorize the alignment types stored by TargetAlignElem
enum AlignTypeEnum { enum AlignTypeEnum {
@ -264,8 +266,7 @@ public:
/// getIndexedOffset - return the offset from the beginning of the type for /// getIndexedOffset - return the offset from the beginning of the type for
/// the specified indices. This is used to implement getelementptr. /// the specified indices. This is used to implement getelementptr.
/// ///
uint64_t getIndexedOffset(Type *Ty, uint64_t getIndexedOffset(Type *Ty, ArrayRef<Value *> Indices) const;
Value* const* Indices, unsigned NumIndices) const;
/// getStructLayout - Return a StructLayout object, indicating the alignment /// getStructLayout - Return a StructLayout object, indicating the alignment
/// of the struct, its size, and the offsets of its fields. Note that this /// of the struct, its size, and the offsets of its fields. Note that this

View File

@ -606,10 +606,10 @@ static Constant *SymbolicallyEvaluateGEP(ArrayRef<Constant *> Ops,
} }
unsigned BitWidth = TD->getTypeSizeInBits(IntPtrTy); unsigned BitWidth = TD->getTypeSizeInBits(IntPtrTy);
APInt Offset = APInt(BitWidth, APInt Offset =
TD->getIndexedOffset(Ptr->getType(), APInt(BitWidth, TD->getIndexedOffset(Ptr->getType(),
(Value**)Ops.data() + 1, makeArrayRef((Value **)Ops.data() + 1,
Ops.size() - 1)); Ops.size() - 1)));
Ptr = cast<Constant>(Ptr->stripPointerCasts()); Ptr = cast<Constant>(Ptr->stripPointerCasts());
// If this is a GEP of a GEP, fold it all into a single GEP. // If this is a GEP of a GEP, fold it all into a single GEP.
@ -628,9 +628,7 @@ static Constant *SymbolicallyEvaluateGEP(ArrayRef<Constant *> Ops,
Ptr = cast<Constant>(GEP->getOperand(0)); Ptr = cast<Constant>(GEP->getOperand(0));
Offset += APInt(BitWidth, Offset += APInt(BitWidth,
TD->getIndexedOffset(Ptr->getType(), TD->getIndexedOffset(Ptr->getType(), NestedOps));
(Value**)NestedOps.data(),
NestedOps.size()));
Ptr = cast<Constant>(Ptr->stripPointerCasts()); Ptr = cast<Constant>(Ptr->stripPointerCasts());
} }

View File

@ -63,7 +63,7 @@ static Value *getUnderlyingObjectWithOffset(Value *V, const TargetData *TD,
return V; return V;
SmallVector<Value*, 8> Indices(GEP->op_begin() + 1, GEP->op_end()); SmallVector<Value*, 8> Indices(GEP->op_begin() + 1, GEP->op_end());
ByteOffset += TD->getIndexedOffset(GEP->getPointerOperandType(), ByteOffset += TD->getIndexedOffset(GEP->getPointerOperandType(),
&Indices[0], Indices.size()); Indices);
V = GEP->getPointerOperand(); V = GEP->getPointerOperand();
} else if (Operator::getOpcode(V) == Instruction::BitCast) { } else if (Operator::getOpcode(V) == Instruction::BitCast) {
V = cast<Operator>(V)->getOperand(0); V = cast<Operator>(V)->getOperand(0);

View File

@ -1409,8 +1409,7 @@ static const MCExpr *LowerConstant(const Constant *CV, AsmPrinter &AP) {
// Generate a symbolic expression for the byte address // Generate a symbolic expression for the byte address
const Constant *PtrVal = CE->getOperand(0); const Constant *PtrVal = CE->getOperand(0);
SmallVector<Value*, 8> IdxVec(CE->op_begin()+1, CE->op_end()); SmallVector<Value*, 8> IdxVec(CE->op_begin()+1, CE->op_end());
int64_t Offset = TD.getIndexedOffset(PtrVal->getType(), &IdxVec[0], int64_t Offset = TD.getIndexedOffset(PtrVal->getType(), IdxVec);
IdxVec.size());
const MCExpr *Base = LowerConstant(CE->getOperand(0), AP); const MCExpr *Base = LowerConstant(CE->getOperand(0), AP);
if (Offset == 0) if (Offset == 0)

View File

@ -542,8 +542,7 @@ CstExprResTy ELFWriter::ResolveConstantExpr(const Constant *CV) {
case Instruction::GetElementPtr: { case Instruction::GetElementPtr: {
const Constant *ptrVal = CE->getOperand(0); const Constant *ptrVal = CE->getOperand(0);
SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end()); SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0], int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), idxVec);
idxVec.size());
return std::make_pair(ptrVal, Offset); return std::make_pair(ptrVal, Offset);
} }
case Instruction::IntToPtr: { case Instruction::IntToPtr: {

View File

@ -549,8 +549,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
// Compute the index // Compute the index
GenericValue Result = getConstantValue(Op0); GenericValue Result = getConstantValue(Op0);
SmallVector<Value*, 8> Indices(CE->op_begin()+1, CE->op_end()); SmallVector<Value*, 8> Indices(CE->op_begin()+1, CE->op_end());
uint64_t Offset = uint64_t Offset = TD->getIndexedOffset(Op0->getType(), Indices);
TD->getIndexedOffset(Op0->getType(), &Indices[0], Indices.size());
char* tmp = (char*) Result.PointerVal; char* tmp = (char*) Result.PointerVal;
Result = PTOGV(tmp + Offset); Result = PTOGV(tmp + Offset);

View File

@ -521,15 +521,16 @@ IntegerType *TargetData::getIntPtrType(LLVMContext &C) const {
} }
uint64_t TargetData::getIndexedOffset(Type *ptrTy, Value* const* Indices, uint64_t TargetData::getIndexedOffset(Type *ptrTy,
unsigned NumIndices) const { ArrayRef<Value *> Indices) const {
Type *Ty = ptrTy; Type *Ty = ptrTy;
assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()"); assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()");
uint64_t Result = 0; uint64_t Result = 0;
generic_gep_type_iterator<Value* const*> generic_gep_type_iterator<Value* const*>
TI = gep_type_begin(ptrTy, Indices, Indices+NumIndices); TI = gep_type_begin(ptrTy, Indices.begin(), Indices.end());
for (unsigned CurIDX = 0; CurIDX != NumIndices; ++CurIDX, ++TI) { for (unsigned CurIDX = 0, EndIDX = Indices.size(); CurIDX != EndIDX;
++CurIDX, ++TI) {
if (StructType *STy = dyn_cast<StructType>(*TI)) { if (StructType *STy = dyn_cast<StructType>(*TI)) {
assert(Indices[CurIDX]->getType() == assert(Indices[CurIDX]->getType() ==
Type::getInt32Ty(ptrTy->getContext()) && Type::getInt32Ty(ptrTy->getContext()) &&

View File

@ -346,9 +346,9 @@ bool FunctionComparator::isEquivalentGEP(const GEPOperator *GEP1,
SmallVector<Value *, 8> Indices1(GEP1->idx_begin(), GEP1->idx_end()); SmallVector<Value *, 8> Indices1(GEP1->idx_begin(), GEP1->idx_end());
SmallVector<Value *, 8> Indices2(GEP2->idx_begin(), GEP2->idx_end()); SmallVector<Value *, 8> Indices2(GEP2->idx_begin(), GEP2->idx_end());
uint64_t Offset1 = TD->getIndexedOffset(GEP1->getPointerOperandType(), uint64_t Offset1 = TD->getIndexedOffset(GEP1->getPointerOperandType(),
Indices1.data(), Indices1.size()); Indices1);
uint64_t Offset2 = TD->getIndexedOffset(GEP2->getPointerOperandType(), uint64_t Offset2 = TD->getIndexedOffset(GEP2->getPointerOperandType(),
Indices2.data(), Indices2.size()); Indices2);
return Offset1 == Offset2; return Offset1 == Offset2;
} }

View File

@ -266,8 +266,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// Get the current byte offset into the thing. Use the original // Get the current byte offset into the thing. Use the original
// operand in case we're looking through a bitcast. // operand in case we're looking through a bitcast.
SmallVector<Value*, 8> Ops(GEP->idx_begin(), GEP->idx_end()); SmallVector<Value*, 8> Ops(GEP->idx_begin(), GEP->idx_end());
Offset = TD->getIndexedOffset(GEP->getPointerOperandType(), Offset = TD->getIndexedOffset(GEP->getPointerOperandType(), Ops);
Ops.data(), Ops.size());
Op1 = GEP->getPointerOperand()->stripPointerCasts(); Op1 = GEP->getPointerOperand()->stripPointerCasts();

View File

@ -516,7 +516,7 @@ bool ConvertToScalarInfo::CanConvertToScalar(Value *V, uint64_t Offset) {
// Compute the offset that this GEP adds to the pointer. // Compute the offset that this GEP adds to the pointer.
SmallVector<Value*, 8> Indices(GEP->op_begin()+1, GEP->op_end()); SmallVector<Value*, 8> Indices(GEP->op_begin()+1, GEP->op_end());
uint64_t GEPOffset = TD.getIndexedOffset(GEP->getPointerOperandType(), uint64_t GEPOffset = TD.getIndexedOffset(GEP->getPointerOperandType(),
&Indices[0], Indices.size()); Indices);
// See if all uses can be converted. // See if all uses can be converted.
if (!CanConvertToScalar(GEP, Offset+GEPOffset)) if (!CanConvertToScalar(GEP, Offset+GEPOffset))
return false; return false;
@ -589,7 +589,7 @@ void ConvertToScalarInfo::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI,
// Compute the offset that this GEP adds to the pointer. // Compute the offset that this GEP adds to the pointer.
SmallVector<Value*, 8> Indices(GEP->op_begin()+1, GEP->op_end()); SmallVector<Value*, 8> Indices(GEP->op_begin()+1, GEP->op_end());
uint64_t GEPOffset = TD.getIndexedOffset(GEP->getPointerOperandType(), uint64_t GEPOffset = TD.getIndexedOffset(GEP->getPointerOperandType(),
&Indices[0], Indices.size()); Indices);
ConvertUsesToScalar(GEP, NewAI, Offset+GEPOffset*8); ConvertUsesToScalar(GEP, NewAI, Offset+GEPOffset*8);
GEP->eraseFromParent(); GEP->eraseFromParent();
continue; continue;
@ -1776,8 +1776,7 @@ void SROA::isSafeGEP(GetElementPtrInst *GEPI,
// Compute the offset due to this GEP and check if the alloca has a // Compute the offset due to this GEP and check if the alloca has a
// component element at that offset. // component element at that offset.
SmallVector<Value*, 8> Indices(GEPI->op_begin() + 1, GEPI->op_end()); SmallVector<Value*, 8> Indices(GEPI->op_begin() + 1, GEPI->op_end());
Offset += TD->getIndexedOffset(GEPI->getPointerOperandType(), Offset += TD->getIndexedOffset(GEPI->getPointerOperandType(), Indices);
&Indices[0], Indices.size());
if (!TypeHasComponent(Info.AI->getAllocatedType(), Offset, 0)) if (!TypeHasComponent(Info.AI->getAllocatedType(), Offset, 0))
MarkUnsafe(Info, GEPI); MarkUnsafe(Info, GEPI);
} }
@ -2053,8 +2052,7 @@ void SROA::RewriteGEP(GetElementPtrInst *GEPI, AllocaInst *AI, uint64_t Offset,
SmallVector<AllocaInst*, 32> &NewElts) { SmallVector<AllocaInst*, 32> &NewElts) {
uint64_t OldOffset = Offset; uint64_t OldOffset = Offset;
SmallVector<Value*, 8> Indices(GEPI->op_begin() + 1, GEPI->op_end()); SmallVector<Value*, 8> Indices(GEPI->op_begin() + 1, GEPI->op_end());
Offset += TD->getIndexedOffset(GEPI->getPointerOperandType(), Offset += TD->getIndexedOffset(GEPI->getPointerOperandType(), Indices);
&Indices[0], Indices.size());
RewriteForScalarRepl(GEPI, AI, Offset, NewElts); RewriteForScalarRepl(GEPI, AI, Offset, NewElts);