[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Apr 4 20:30:01 PDT 2004
Changes in directory llvm/lib/Target:
TargetData.cpp updated: 1.43 -> 1.44
---
Log message:
Support getelementptr instructions which use uint's to index into structure
types and can have arbitrary 32- and 64-bit integer types indexing into
sequential types.
---
Diffs of the changes: (+13 -11)
Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.43 llvm/lib/Target/TargetData.cpp:1.44
--- llvm/lib/Target/TargetData.cpp:1.43 Thu Feb 26 02:02:17 2004
+++ llvm/lib/Target/TargetData.cpp Sun Apr 4 20:29:25 2004
@@ -20,6 +20,7 @@
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
+#include "llvm/Support/GetElementPtrTypeIterator.h"
using namespace llvm;
// Handle the Pass registration stuff necessary to use TargetData's.
@@ -218,17 +219,11 @@
assert(isa<PointerType>(Ty) && "Illegal argument for getIndexedOffset()");
uint64_t Result = 0;
- for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX) {
- if (Idx[CurIDX]->getType() == Type::LongTy) {
- // Update Ty to refer to current element
- Ty = cast<SequentialType>(Ty)->getElementType();
-
- // Get the array index and the size of each array element.
- int64_t arrayIdx = cast<ConstantSInt>(Idx[CurIDX])->getValue();
- Result += arrayIdx * (int64_t)getTypeSize(Ty);
- } else {
- const StructType *STy = cast<StructType>(Ty);
- assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
+ generic_gep_type_iterator<std::vector<Value*>::const_iterator>
+ TI = gep_type_begin(ptrTy, Idx.begin(), Idx.end());
+ for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX, ++TI) {
+ if (const StructType *STy = dyn_cast<StructType>(*TI)) {
+ assert(Idx[CurIDX]->getType() == Type::UIntTy && "Illegal struct idx");
unsigned FieldNo = cast<ConstantUInt>(Idx[CurIDX])->getValue();
// Get structure layout information...
@@ -240,6 +235,13 @@
// Update Ty to refer to current element
Ty = STy->getElementType(FieldNo);
+ } else {
+ // Update Ty to refer to current element
+ Ty = cast<SequentialType>(Ty)->getElementType();
+
+ // Get the array index and the size of each array element.
+ int64_t arrayIdx = cast<ConstantInt>(Idx[CurIDX])->getRawValue();
+ Result += arrayIdx * (int64_t)getTypeSize(Ty);
}
}
More information about the llvm-commits
mailing list