forked from OSchip/llvm-project
Extend TargetData::getIndexedOffset to support arrays and pointers!
llvm-svn: 2535
This commit is contained in:
parent
ac70e1cdd0
commit
8b1e4d63fe
|
|
@ -145,16 +145,12 @@ unsigned char TargetData::getTypeAlignment(const Type *Ty) const {
|
||||||
return Align;
|
return Align;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TargetData::getIndexedOffset(const Type *ptrTy,
|
unsigned TargetData::getIndexedOffset(const Type *Ty,
|
||||||
const std::vector<Value*> &Idx) const {
|
const std::vector<Value*> &Idx) const {
|
||||||
const PointerType *PtrTy = cast<const PointerType>(ptrTy);
|
|
||||||
unsigned Result = 0;
|
unsigned Result = 0;
|
||||||
|
|
||||||
// Get the type pointed to...
|
for (unsigned CurIDX = 0, E = Idx.size(); CurIDX != E; ++CurIDX) {
|
||||||
const Type *Ty = PtrTy->getElementType();
|
if (const StructType *STy = dyn_cast<StructType>(Ty)) {
|
||||||
|
|
||||||
for (unsigned CurIDX = 0; CurIDX < Idx.size(); ++CurIDX) {
|
|
||||||
if (const StructType *STy = dyn_cast<const StructType>(Ty)) {
|
|
||||||
assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
|
assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
|
||||||
unsigned FieldNo = cast<ConstantUInt>(Idx[CurIDX])->getValue();
|
unsigned FieldNo = cast<ConstantUInt>(Idx[CurIDX])->getValue();
|
||||||
|
|
||||||
|
|
@ -168,10 +164,17 @@ unsigned TargetData::getIndexedOffset(const Type *ptrTy,
|
||||||
// Update Ty to refer to current element
|
// Update Ty to refer to current element
|
||||||
Ty = STy->getElementTypes()[FieldNo];
|
Ty = STy->getElementTypes()[FieldNo];
|
||||||
|
|
||||||
} else if (isa<const ArrayType>(Ty)) {
|
} else if (const SequentialType *STy = dyn_cast<SequentialType>(Ty)) {
|
||||||
assert(0 && "Loading from arrays not implemented yet!");
|
assert(Idx[CurIDX]->getType() == Type::UIntTy &&"Illegal sequential idx");
|
||||||
|
assert(isa<ConstantUInt>(Idx[CurIDX]) &&
|
||||||
|
"getIndexedOffset cannot compute offset of non-constant index!");
|
||||||
|
|
||||||
|
unsigned IndexNo = cast<ConstantUInt>(Idx[CurIDX])->getValue();
|
||||||
|
Ty = STy->getElementType();
|
||||||
|
|
||||||
|
Result += IndexNo*getTypeSize(Ty);
|
||||||
} else {
|
} else {
|
||||||
assert(0 && "Indexing type that is not struct or array?");
|
assert(0 && "Indexing type that is not struct, array, or pointer?");
|
||||||
return 0; // Load directly through ptr
|
return 0; // Load directly through ptr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue