blob: 7bb77636c815d87a7484b76fa9efbb9fea1b9e64 [file] [log] [blame]
Chris Lattnere7fb3602001-08-27 16:00:15 +00001//===-- TargetData.cpp - Data size & alignment routines --------------------==//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnere7fb3602001-08-27 16:00:15 +00009//
10// This file defines target properties related to datatype size/offset/alignment
Chris Lattner0e7ac162004-02-26 08:02:17 +000011// information.
Chris Lattnere7fb3602001-08-27 16:00:15 +000012//
13// This structure should be created once, filled in if the defaults are not
14// correct and then passed around by const&. None of the members functions
15// require modification to the object.
16//
17//===----------------------------------------------------------------------===//
18
Vikram S. Adve0799fc42001-09-18 12:58:33 +000019#include "llvm/Target/TargetData.h"
Chris Lattner53a0c382003-04-24 19:09:05 +000020#include "llvm/Module.h"
Chris Lattnere7fb3602001-08-27 16:00:15 +000021#include "llvm/DerivedTypes.h"
Chris Lattner31bcdb82002-04-28 19:55:58 +000022#include "llvm/Constants.h"
Chris Lattner28977af2004-04-05 01:30:19 +000023#include "llvm/Support/GetElementPtrTypeIterator.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000024#include "llvm/Support/MathExtras.h"
Owen Anderson8f60c562006-05-12 05:49:47 +000025#include "llvm/ADT/StringExtras.h"
Chris Lattnere7ea48c2005-03-13 19:04:41 +000026#include <algorithm>
Owen Anderson8f60c562006-05-12 05:49:47 +000027#include <cstdlib>
Owen Anderson2577c222006-05-12 07:01:44 +000028#include <sstream>
Chris Lattnerf0453282003-12-22 05:01:15 +000029using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000030
Misha Brukman5560c9d2003-08-18 14:43:39 +000031// Handle the Pass registration stuff necessary to use TargetData's.
Chris Lattneraa31ad02002-09-25 23:46:55 +000032namespace {
33 // Register the default SparcV9 implementation...
34 RegisterPass<TargetData> X("targetdata", "Target Data Layout");
35}
36
Chris Lattnere7fb3602001-08-27 16:00:15 +000037static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
Misha Brukmanc8e87642004-07-23 01:09:52 +000038 uint64_t &Size, unsigned char &Alignment);
Chris Lattnere7fb3602001-08-27 16:00:15 +000039
40//===----------------------------------------------------------------------===//
Chris Lattner0e7ac162004-02-26 08:02:17 +000041// Support for StructLayout
Chris Lattnere7fb3602001-08-27 16:00:15 +000042//===----------------------------------------------------------------------===//
43
Chris Lattner0e7ac162004-02-26 08:02:17 +000044StructLayout::StructLayout(const StructType *ST, const TargetData &TD) {
Chris Lattnere7fb3602001-08-27 16:00:15 +000045 StructAlignment = 0;
46 StructSize = 0;
47
48 // Loop over each of the elements, placing them in memory...
Misha Brukmanf976c852005-04-21 22:55:34 +000049 for (StructType::element_iterator TI = ST->element_begin(),
Misha Brukmanc8e87642004-07-23 01:09:52 +000050 TE = ST->element_end(); TI != TE; ++TI) {
Chris Lattnere7fb3602001-08-27 16:00:15 +000051 const Type *Ty = *TI;
52 unsigned char A;
Vikram S. Advef66723f2002-05-19 15:28:02 +000053 unsigned TyAlign;
54 uint64_t TySize;
55 getTypeInfo(Ty, &TD, TySize, A);
56 TyAlign = A;
Chris Lattnere7fb3602001-08-27 16:00:15 +000057
Misha Brukman5560c9d2003-08-18 14:43:39 +000058 // Add padding if necessary to make the data element aligned properly...
Chris Lattnere7fb3602001-08-27 16:00:15 +000059 if (StructSize % TyAlign != 0)
60 StructSize = (StructSize/TyAlign + 1) * TyAlign; // Add padding...
61
62 // Keep track of maximum alignment constraint
Chris Lattner697954c2002-01-20 22:54:45 +000063 StructAlignment = std::max(TyAlign, StructAlignment);
Chris Lattnere7fb3602001-08-27 16:00:15 +000064
65 MemberOffsets.push_back(StructSize);
Vikram S. Advef66723f2002-05-19 15:28:02 +000066 StructSize += TySize; // Consume space for this data item
Chris Lattnere7fb3602001-08-27 16:00:15 +000067 }
68
Chris Lattner4e840d42003-05-21 18:08:44 +000069 // Empty structures have alignment of 1 byte.
70 if (StructAlignment == 0) StructAlignment = 1;
71
Chris Lattnere7fb3602001-08-27 16:00:15 +000072 // Add padding to the end of the struct so that it could be put in an array
73 // and all array elements would be aligned correctly.
74 if (StructSize % StructAlignment != 0)
75 StructSize = (StructSize/StructAlignment + 1) * StructAlignment;
Chris Lattnere7fb3602001-08-27 16:00:15 +000076}
77
Chris Lattnere7ea48c2005-03-13 19:04:41 +000078
79/// getElementContainingOffset - Given a valid offset into the structure,
80/// return the structure index that contains it.
81unsigned StructLayout::getElementContainingOffset(uint64_t Offset) const {
82 std::vector<uint64_t>::const_iterator SI =
83 std::upper_bound(MemberOffsets.begin(), MemberOffsets.end(),
84 Offset);
85 assert(SI != MemberOffsets.begin() && "Offset not in structure type!");
86 --SI;
87 assert(*SI <= Offset && "upper_bound didn't work");
88 assert((SI == MemberOffsets.begin() || *(SI-1) < Offset) &&
89 (SI+1 == MemberOffsets.end() || *(SI+1) > Offset) &&
90 "Upper bound didn't work!");
91 return SI-MemberOffsets.begin();
92}
93
Chris Lattnere7fb3602001-08-27 16:00:15 +000094//===----------------------------------------------------------------------===//
95// TargetData Class Implementation
96//===----------------------------------------------------------------------===//
97
Vikram S. Advef66723f2002-05-19 15:28:02 +000098TargetData::TargetData(const std::string &TargetName,
Chris Lattner10daaa12003-04-26 20:11:09 +000099 bool isLittleEndian, unsigned char PtrSize,
Chris Lattner85131c82002-10-14 22:41:13 +0000100 unsigned char PtrAl, unsigned char DoubleAl,
Misha Brukmanf976c852005-04-21 22:55:34 +0000101 unsigned char FloatAl, unsigned char LongAl,
Chris Lattner85131c82002-10-14 22:41:13 +0000102 unsigned char IntAl, unsigned char ShortAl,
Misha Brukmanc8e87642004-07-23 01:09:52 +0000103 unsigned char ByteAl, unsigned char BoolAl) {
Chris Lattnere7fb3602001-08-27 16:00:15 +0000104
Chris Lattner46326d92003-04-25 02:50:45 +0000105 // If this assert triggers, a pass "required" TargetData information, but the
Brian Gaeke8121fcd2004-04-14 21:21:56 +0000106 // top level tool did not provide one for it. We do not want to default
Chris Lattner46326d92003-04-25 02:50:45 +0000107 // construct, or else we might end up using a bad endianness or pointer size!
108 //
109 assert(!TargetName.empty() &&
110 "ERROR: Tool did not specify a target data to use!");
111
Chris Lattner85131c82002-10-14 22:41:13 +0000112 LittleEndian = isLittleEndian;
Chris Lattnere7fb3602001-08-27 16:00:15 +0000113 PointerSize = PtrSize;
114 PointerAlignment = PtrAl;
115 DoubleAlignment = DoubleAl;
116 FloatAlignment = FloatAl;
117 LongAlignment = LongAl;
118 IntAlignment = IntAl;
119 ShortAlignment = ShortAl;
120 ByteAlignment = ByteAl;
Misha Brukmanc8e87642004-07-23 01:09:52 +0000121 BoolAlignment = BoolAl;
Chris Lattnere7fb3602001-08-27 16:00:15 +0000122}
123
Owen Anderson8f60c562006-05-12 05:49:47 +0000124TargetData::TargetData(const std::string &TargetName,
125 const std::string &TargetDescription) {
Owen Andersond988b322006-05-20 00:24:56 +0000126 assert(!TargetName.empty() &&
127 "ERROR: Tool did not specify a target data to use!");
128
129
Owen Anderson8f60c562006-05-12 05:49:47 +0000130 std::string temp = TargetDescription;
131
132 LittleEndian = false;
133 PointerSize = 8;
134 PointerAlignment = 8;
135 DoubleAlignment = 8;
136 FloatAlignment = 4;
137 LongAlignment = 8;
138 IntAlignment = 4;
139 ShortAlignment = 2;
140 ByteAlignment = 1;
141 BoolAlignment = 1;
142
Owen Andersond988b322006-05-20 00:24:56 +0000143 while (!temp.empty()) {
Owen Anderson8f60c562006-05-12 05:49:47 +0000144 std::string token = getToken(temp, "-");
145
Owen Anderson84cc6db2006-05-17 21:56:02 +0000146 char signal = getToken(token, ":")[0];
147
148 switch(signal) {
Owen Anderson8f60c562006-05-12 05:49:47 +0000149 case 'E':
Owen Anderson571a13f2006-05-12 06:06:55 +0000150 LittleEndian = false;
151 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000152 case 'e':
Owen Anderson571a13f2006-05-12 06:06:55 +0000153 LittleEndian = true;
154 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000155 case 'p':
Owen Anderson571a13f2006-05-12 06:06:55 +0000156 PointerSize = atoi(getToken(token,":").c_str()) / 8;
157 PointerAlignment = atoi(getToken(token,":").c_str()) / 8;
158 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000159 case 'd':
Owen Anderson571a13f2006-05-12 06:06:55 +0000160 token = getToken(token,":"); //Ignore the size
161 DoubleAlignment = atoi(getToken(token,":").c_str()) / 8;
162 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000163 case 'f':
Owen Anderson571a13f2006-05-12 06:06:55 +0000164 token = getToken(token, ":"); //Ignore the size
165 FloatAlignment = atoi(getToken(token, ":").c_str()) / 8;
166 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000167 case 'l':
Owen Anderson571a13f2006-05-12 06:06:55 +0000168 token = getToken(token, ":"); //Ignore the size
169 LongAlignment = atoi(getToken(token, ":").c_str()) / 8;
170 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000171 case 'i':
Owen Anderson571a13f2006-05-12 06:06:55 +0000172 token = getToken(token, ":"); //Ignore the size
173 IntAlignment = atoi(getToken(token, ":").c_str()) / 8;
174 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000175 case 's':
Owen Anderson571a13f2006-05-12 06:06:55 +0000176 token = getToken(token, ":"); //Ignore the size
177 ShortAlignment = atoi(getToken(token, ":").c_str()) / 8;
178 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000179 case 'b':
Owen Anderson571a13f2006-05-12 06:06:55 +0000180 token = getToken(token, ":"); //Ignore the size
181 ByteAlignment = atoi(getToken(token, ":").c_str()) / 8;
182 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000183 case 'B':
Owen Anderson571a13f2006-05-12 06:06:55 +0000184 token = getToken(token, ":"); //Ignore the size
185 BoolAlignment = atoi(getToken(token, ":").c_str()) / 8;
186 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000187 default:
Owen Anderson571a13f2006-05-12 06:06:55 +0000188 break;
Owen Anderson8f60c562006-05-12 05:49:47 +0000189 }
190 }
191}
192
Chris Lattner0e7ac162004-02-26 08:02:17 +0000193TargetData::TargetData(const std::string &ToolName, const Module *M) {
Chris Lattner030574f2003-08-24 13:49:22 +0000194 LittleEndian = M->getEndianness() != Module::BigEndian;
195 PointerSize = M->getPointerSize() != Module::Pointer64 ? 4 : 8;
Chris Lattner53a0c382003-04-24 19:09:05 +0000196 PointerAlignment = PointerSize;
Chris Lattnerdd7253c2003-04-25 06:06:43 +0000197 DoubleAlignment = PointerSize;
Chris Lattner53a0c382003-04-24 19:09:05 +0000198 FloatAlignment = 4;
Chris Lattnerda6122f2004-11-02 22:18:18 +0000199 LongAlignment = PointerSize;
Chris Lattner53a0c382003-04-24 19:09:05 +0000200 IntAlignment = 4;
201 ShortAlignment = 2;
202 ByteAlignment = 1;
Misha Brukmanc8e87642004-07-23 01:09:52 +0000203 BoolAlignment = 1;
Chris Lattner53a0c382003-04-24 19:09:05 +0000204}
205
Chris Lattner8dff24f2006-01-14 00:07:34 +0000206/// Layouts - The lazy cache of structure layout information maintained by
207/// TargetData.
208///
Chris Lattner0e7ac162004-02-26 08:02:17 +0000209static std::map<std::pair<const TargetData*,const StructType*>,
210 StructLayout> *Layouts = 0;
211
212
Chris Lattnere7fb3602001-08-27 16:00:15 +0000213TargetData::~TargetData() {
Chris Lattner0e7ac162004-02-26 08:02:17 +0000214 if (Layouts) {
215 // Remove any layouts for this TD.
216 std::map<std::pair<const TargetData*,
217 const StructType*>, StructLayout>::iterator
218 I = Layouts->lower_bound(std::make_pair(this, (const StructType*)0));
219 while (I != Layouts->end() && I->first.first == this)
220 Layouts->erase(I++);
221 if (Layouts->empty()) {
222 delete Layouts;
223 Layouts = 0;
224 }
225 }
226}
227
Owen Anderson2577c222006-05-12 07:01:44 +0000228std::string TargetData::getStringRepresentation() const {
229 std::stringstream repr;
230
231 if (LittleEndian)
232 repr << "e";
233 else
234 repr << "E";
235
236 repr << "-p:" << (PointerSize * 8) << ":" << (PointerAlignment * 8);
237 repr << "-d:64:" << (DoubleAlignment * 8);
238 repr << "-f:32:" << (FloatAlignment * 8);
239 repr << "-l:64:" << (LongAlignment * 8);
240 repr << "-i:32:" << (IntAlignment * 8);
241 repr << "-s:16:" << (ShortAlignment * 8);
242 repr << "-b:8:" << (ByteAlignment * 8);
243 repr << "-B:8:" << (BoolAlignment * 8);
244
245 return repr.str();
246}
247
Chris Lattner0e7ac162004-02-26 08:02:17 +0000248const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
249 if (Layouts == 0)
250 Layouts = new std::map<std::pair<const TargetData*,const StructType*>,
251 StructLayout>();
252 std::map<std::pair<const TargetData*,const StructType*>,
253 StructLayout>::iterator
254 I = Layouts->lower_bound(std::make_pair(this, Ty));
255 if (I != Layouts->end() && I->first.first == this && I->first.second == Ty)
256 return &I->second;
257 else {
258 return &Layouts->insert(I, std::make_pair(std::make_pair(this, Ty),
259 StructLayout(Ty, *this)))->second;
260 }
Chris Lattnere7fb3602001-08-27 16:00:15 +0000261}
262
Chris Lattner8dff24f2006-01-14 00:07:34 +0000263/// InvalidateStructLayoutInfo - TargetData speculatively caches StructLayout
264/// objects. If a TargetData object is alive when types are being refined and
265/// removed, this method must be called whenever a StructType is removed to
266/// avoid a dangling pointer in this cache.
267void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
268 if (!Layouts) return; // No cache.
269
270 std::map<std::pair<const TargetData*,const StructType*>,
271 StructLayout>::iterator I = Layouts->find(std::make_pair(this, Ty));
272 if (I != Layouts->end())
273 Layouts->erase(I);
274}
275
276
277
Chris Lattnere7fb3602001-08-27 16:00:15 +0000278static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
Misha Brukmanc8e87642004-07-23 01:09:52 +0000279 uint64_t &Size, unsigned char &Alignment) {
Chris Lattnerf59ce922001-12-13 00:46:11 +0000280 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000281 switch (Ty->getTypeID()) {
Misha Brukmanc8e87642004-07-23 01:09:52 +0000282 case Type::BoolTyID: Size = 1; Alignment = TD->getBoolAlignment(); return;
Chris Lattnere7fb3602001-08-27 16:00:15 +0000283 case Type::VoidTyID:
Chris Lattnere7fb3602001-08-27 16:00:15 +0000284 case Type::UByteTyID:
285 case Type::SByteTyID: Size = 1; Alignment = TD->getByteAlignment(); return;
286 case Type::UShortTyID:
287 case Type::ShortTyID: Size = 2; Alignment = TD->getShortAlignment(); return;
288 case Type::UIntTyID:
289 case Type::IntTyID: Size = 4; Alignment = TD->getIntAlignment(); return;
290 case Type::ULongTyID:
291 case Type::LongTyID: Size = 8; Alignment = TD->getLongAlignment(); return;
292 case Type::FloatTyID: Size = 4; Alignment = TD->getFloatAlignment(); return;
293 case Type::DoubleTyID: Size = 8; Alignment = TD->getDoubleAlignment(); return;
294 case Type::LabelTyID:
295 case Type::PointerTyID:
296 Size = TD->getPointerSize(); Alignment = TD->getPointerAlignment();
297 return;
298 case Type::ArrayTyID: {
Chris Lattner59b00672004-07-01 17:32:59 +0000299 const ArrayType *ATy = cast<ArrayType>(Ty);
Chris Lattnere7fb3602001-08-27 16:00:15 +0000300 getTypeInfo(ATy->getElementType(), TD, Size, Alignment);
Brian Gaekee0e35892004-07-02 07:01:31 +0000301 unsigned AlignedSize = (Size + Alignment - 1)/Alignment*Alignment;
Chris Lattner59b00672004-07-01 17:32:59 +0000302 Size = AlignedSize*ATy->getNumElements();
Chris Lattnere7fb3602001-08-27 16:00:15 +0000303 return;
304 }
Chris Lattner527efc62004-12-01 17:14:28 +0000305 case Type::PackedTyID: {
306 const PackedType *PTy = cast<PackedType>(Ty);
307 getTypeInfo(PTy->getElementType(), TD, Size, Alignment);
308 unsigned AlignedSize = (Size + Alignment - 1)/Alignment*Alignment;
309 Size = AlignedSize*PTy->getNumElements();
Evan Chenge668bda2006-03-31 22:33:42 +0000310 // FIXME: The alignments of specific packed types are target dependent.
311 // For now, just set it to be equal to Size.
Chris Lattner0aab36f2006-04-03 23:14:49 +0000312 Alignment = Size;
Chris Lattner527efc62004-12-01 17:14:28 +0000313 return;
314 }
Chris Lattnere7fb3602001-08-27 16:00:15 +0000315 case Type::StructTyID: {
316 // Get the layout annotation... which is lazily created on demand.
Chris Lattner59b00672004-07-01 17:32:59 +0000317 const StructLayout *Layout = TD->getStructLayout(cast<StructType>(Ty));
Chris Lattnere7fb3602001-08-27 16:00:15 +0000318 Size = Layout->StructSize; Alignment = Layout->StructAlignment;
319 return;
320 }
Misha Brukmanf976c852005-04-21 22:55:34 +0000321
Chris Lattnere7fb3602001-08-27 16:00:15 +0000322 default:
323 assert(0 && "Bad type for getTypeInfo!!!");
324 return;
325 }
326}
327
Vikram S. Advef66723f2002-05-19 15:28:02 +0000328uint64_t TargetData::getTypeSize(const Type *Ty) const {
329 uint64_t Size;
330 unsigned char Align;
Chris Lattnere7fb3602001-08-27 16:00:15 +0000331 getTypeInfo(Ty, this, Size, Align);
332 return Size;
333}
334
335unsigned char TargetData::getTypeAlignment(const Type *Ty) const {
Vikram S. Advef66723f2002-05-19 15:28:02 +0000336 uint64_t Size;
337 unsigned char Align;
Chris Lattnere7fb3602001-08-27 16:00:15 +0000338 getTypeInfo(Ty, this, Size, Align);
339 return Align;
340}
341
Chris Lattnerd2b0bb42004-08-17 19:13:00 +0000342unsigned char TargetData::getTypeAlignmentShift(const Type *Ty) const {
343 unsigned Align = getTypeAlignment(Ty);
344 assert(!(Align & (Align-1)) && "Alignment is not a power of two!");
Chris Lattner0561b3f2005-08-02 19:26:06 +0000345 return Log2_32(Align);
Chris Lattnerd2b0bb42004-08-17 19:13:00 +0000346}
347
Chris Lattnerf0453282003-12-22 05:01:15 +0000348/// getIntPtrType - Return an unsigned integer type that is the same size or
349/// greater to the host pointer size.
350const Type *TargetData::getIntPtrType() const {
351 switch (getPointerSize()) {
352 default: assert(0 && "Unknown pointer size!");
353 case 2: return Type::UShortTy;
354 case 4: return Type::UIntTy;
355 case 8: return Type::ULongTy;
356 }
357}
358
359
Vikram S. Advef66723f2002-05-19 15:28:02 +0000360uint64_t TargetData::getIndexedOffset(const Type *ptrTy,
Misha Brukmanc8e87642004-07-23 01:09:52 +0000361 const std::vector<Value*> &Idx) const {
Vikram S. Adveed0030e2002-08-04 20:52:39 +0000362 const Type *Ty = ptrTy;
363 assert(isa<PointerType>(Ty) && "Illegal argument for getIndexedOffset()");
Vikram S. Advef66723f2002-05-19 15:28:02 +0000364 uint64_t Result = 0;
Chris Lattnere7fb3602001-08-27 16:00:15 +0000365
Chris Lattner28977af2004-04-05 01:30:19 +0000366 generic_gep_type_iterator<std::vector<Value*>::const_iterator>
367 TI = gep_type_begin(ptrTy, Idx.begin(), Idx.end());
368 for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX, ++TI) {
369 if (const StructType *STy = dyn_cast<StructType>(*TI)) {
370 assert(Idx[CurIDX]->getType() == Type::UIntTy && "Illegal struct idx");
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000371 unsigned FieldNo = cast<ConstantUInt>(Idx[CurIDX])->getValue();
Chris Lattnere7fb3602001-08-27 16:00:15 +0000372
373 // Get structure layout information...
374 const StructLayout *Layout = getStructLayout(STy);
375
376 // Add in the offset, as calculated by the structure layout info...
Vikram S. Advef66723f2002-05-19 15:28:02 +0000377 assert(FieldNo < Layout->MemberOffsets.size() &&"FieldNo out of range!");
Chris Lattnere7fb3602001-08-27 16:00:15 +0000378 Result += Layout->MemberOffsets[FieldNo];
Vikram S. Adveed0030e2002-08-04 20:52:39 +0000379
Chris Lattnere7fb3602001-08-27 16:00:15 +0000380 // Update Ty to refer to current element
Chris Lattnerd21cd802004-02-09 04:37:31 +0000381 Ty = STy->getElementType(FieldNo);
Chris Lattner28977af2004-04-05 01:30:19 +0000382 } else {
383 // Update Ty to refer to current element
384 Ty = cast<SequentialType>(Ty)->getElementType();
385
386 // Get the array index and the size of each array element.
387 int64_t arrayIdx = cast<ConstantInt>(Idx[CurIDX])->getRawValue();
388 Result += arrayIdx * (int64_t)getTypeSize(Ty);
Chris Lattnere7fb3602001-08-27 16:00:15 +0000389 }
390 }
391
392 return Result;
393}
Brian Gaeked0fde302003-11-11 22:41:34 +0000394