blob: 80a59e05bc54488faa6fe9728b8da88c188b3a30 [file] [log] [blame]
Micah Villmowb4faa152012-10-04 23:01:22 +00001//===-- DataLayout.cpp - Data size & alignment routines --------------------==//
Micah Villmowac34b5c2012-10-04 22:08:14 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Micah Villmowb4faa152012-10-04 23:01:22 +000010// This file defines layout properties related to datatype size/offset/alignment
Micah Villmowac34b5c2012-10-04 22:08:14 +000011// information.
12//
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
Chandler Carruth9fb823b2013-01-02 11:36:10 +000019#include "llvm/IR/DataLayout.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/ADT/DenseMap.h"
Rafael Espindola458a4852013-12-19 23:03:03 +000021#include "llvm/ADT/STLExtras.h"
Rafael Espindola58873562014-01-03 19:21:54 +000022#include "llvm/ADT/Triple.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000023#include "llvm/IR/Constants.h"
24#include "llvm/IR/DerivedTypes.h"
Chandler Carruth03eb0de2014-03-04 10:40:04 +000025#include "llvm/IR/GetElementPtrTypeIterator.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000026#include "llvm/IR/Module.h"
Micah Villmowac34b5c2012-10-04 22:08:14 +000027#include "llvm/Support/ErrorHandling.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/Support/ManagedStatic.h"
29#include "llvm/Support/MathExtras.h"
Micah Villmowac34b5c2012-10-04 22:08:14 +000030#include "llvm/Support/Mutex.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/Support/raw_ostream.h"
Micah Villmowac34b5c2012-10-04 22:08:14 +000032#include <algorithm>
33#include <cstdlib>
34using namespace llvm;
35
Micah Villmowac34b5c2012-10-04 22:08:14 +000036//===----------------------------------------------------------------------===//
37// Support for StructLayout
38//===----------------------------------------------------------------------===//
39
Eli Bendersky41913c72013-04-16 15:41:18 +000040StructLayout::StructLayout(StructType *ST, const DataLayout &DL) {
Micah Villmowac34b5c2012-10-04 22:08:14 +000041 assert(!ST->isOpaque() && "Cannot get layout of opaque structs");
42 StructAlignment = 0;
43 StructSize = 0;
44 NumElements = ST->getNumElements();
45
46 // Loop over each of the elements, placing them in memory.
47 for (unsigned i = 0, e = NumElements; i != e; ++i) {
48 Type *Ty = ST->getElementType(i);
Eli Bendersky41913c72013-04-16 15:41:18 +000049 unsigned TyAlign = ST->isPacked() ? 1 : DL.getABITypeAlignment(Ty);
Micah Villmowac34b5c2012-10-04 22:08:14 +000050
51 // Add padding if necessary to align the data element properly.
52 if ((StructSize & (TyAlign-1)) != 0)
David Majnemerf3cadce2014-10-20 06:13:33 +000053 StructSize = RoundUpToAlignment(StructSize, TyAlign);
Micah Villmowac34b5c2012-10-04 22:08:14 +000054
55 // Keep track of maximum alignment constraint.
56 StructAlignment = std::max(TyAlign, StructAlignment);
57
58 MemberOffsets[i] = StructSize;
Eli Bendersky41913c72013-04-16 15:41:18 +000059 StructSize += DL.getTypeAllocSize(Ty); // Consume space for this data item
Micah Villmowac34b5c2012-10-04 22:08:14 +000060 }
61
62 // Empty structures have alignment of 1 byte.
63 if (StructAlignment == 0) StructAlignment = 1;
64
65 // Add padding to the end of the struct so that it could be put in an array
66 // and all array elements would be aligned correctly.
67 if ((StructSize & (StructAlignment-1)) != 0)
David Majnemerf3cadce2014-10-20 06:13:33 +000068 StructSize = RoundUpToAlignment(StructSize, StructAlignment);
Micah Villmowac34b5c2012-10-04 22:08:14 +000069}
70
71
72/// getElementContainingOffset - Given a valid offset into the structure,
73/// return the structure index that contains it.
74unsigned StructLayout::getElementContainingOffset(uint64_t Offset) const {
75 const uint64_t *SI =
76 std::upper_bound(&MemberOffsets[0], &MemberOffsets[NumElements], Offset);
77 assert(SI != &MemberOffsets[0] && "Offset not in structure type!");
78 --SI;
79 assert(*SI <= Offset && "upper_bound didn't work");
80 assert((SI == &MemberOffsets[0] || *(SI-1) <= Offset) &&
81 (SI+1 == &MemberOffsets[NumElements] || *(SI+1) > Offset) &&
82 "Upper bound didn't work!");
83
84 // Multiple fields can have the same offset if any of them are zero sized.
85 // For example, in { i32, [0 x i32], i32 }, searching for offset 4 will stop
86 // at the i32 element, because it is the last element at that offset. This is
87 // the right one to return, because anything after it will have a higher
88 // offset, implying that this element is non-empty.
89 return SI-&MemberOffsets[0];
90}
91
92//===----------------------------------------------------------------------===//
Micah Villmowb4faa152012-10-04 23:01:22 +000093// LayoutAlignElem, LayoutAlign support
Micah Villmowac34b5c2012-10-04 22:08:14 +000094//===----------------------------------------------------------------------===//
95
Micah Villmowb4faa152012-10-04 23:01:22 +000096LayoutAlignElem
97LayoutAlignElem::get(AlignTypeEnum align_type, unsigned abi_align,
Micah Villmowac34b5c2012-10-04 22:08:14 +000098 unsigned pref_align, uint32_t bit_width) {
99 assert(abi_align <= pref_align && "Preferred alignment worse than ABI!");
Micah Villmowb4faa152012-10-04 23:01:22 +0000100 LayoutAlignElem retval;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000101 retval.AlignType = align_type;
102 retval.ABIAlign = abi_align;
103 retval.PrefAlign = pref_align;
104 retval.TypeBitWidth = bit_width;
105 return retval;
106}
107
108bool
Micah Villmowb4faa152012-10-04 23:01:22 +0000109LayoutAlignElem::operator==(const LayoutAlignElem &rhs) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000110 return (AlignType == rhs.AlignType
111 && ABIAlign == rhs.ABIAlign
112 && PrefAlign == rhs.PrefAlign
113 && TypeBitWidth == rhs.TypeBitWidth);
114}
115
Micah Villmowb4faa152012-10-04 23:01:22 +0000116const LayoutAlignElem
Benjamin Kramer058f5b32013-11-19 20:28:04 +0000117DataLayout::InvalidAlignmentElem = { INVALID_ALIGN, 0, 0, 0 };
Micah Villmow89021e42012-10-09 16:06:12 +0000118
119//===----------------------------------------------------------------------===//
120// PointerAlignElem, PointerAlign support
121//===----------------------------------------------------------------------===//
122
123PointerAlignElem
Rafael Espindolaf39136c2013-12-13 23:15:20 +0000124PointerAlignElem::get(uint32_t AddressSpace, unsigned ABIAlign,
125 unsigned PrefAlign, uint32_t TypeByteWidth) {
126 assert(ABIAlign <= PrefAlign && "Preferred alignment worse than ABI!");
Micah Villmow89021e42012-10-09 16:06:12 +0000127 PointerAlignElem retval;
Rafael Espindolaf39136c2013-12-13 23:15:20 +0000128 retval.AddressSpace = AddressSpace;
129 retval.ABIAlign = ABIAlign;
130 retval.PrefAlign = PrefAlign;
131 retval.TypeByteWidth = TypeByteWidth;
Micah Villmow89021e42012-10-09 16:06:12 +0000132 return retval;
133}
134
135bool
136PointerAlignElem::operator==(const PointerAlignElem &rhs) const {
137 return (ABIAlign == rhs.ABIAlign
138 && AddressSpace == rhs.AddressSpace
139 && PrefAlign == rhs.PrefAlign
Rafael Espindolaf39136c2013-12-13 23:15:20 +0000140 && TypeByteWidth == rhs.TypeByteWidth);
Micah Villmow89021e42012-10-09 16:06:12 +0000141}
142
143const PointerAlignElem
Benjamin Kramer058f5b32013-11-19 20:28:04 +0000144DataLayout::InvalidPointerElem = { 0U, 0U, 0U, ~0U };
Micah Villmowac34b5c2012-10-04 22:08:14 +0000145
146//===----------------------------------------------------------------------===//
Micah Villmowb4faa152012-10-04 23:01:22 +0000147// DataLayout Class Implementation
Micah Villmowac34b5c2012-10-04 22:08:14 +0000148//===----------------------------------------------------------------------===//
149
Rafael Espindola58873562014-01-03 19:21:54 +0000150const char *DataLayout::getManglingComponent(const Triple &T) {
151 if (T.isOSBinFormatMachO())
152 return "-m:o";
David Majnemer7db449a2015-03-17 23:54:51 +0000153 if (T.isOSWindows() && T.isOSBinFormatCOFF())
154 return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
Saleem Abdulrasoolcd130822014-04-02 20:32:05 +0000155 return "-m:e";
Rafael Espindola58873562014-01-03 19:21:54 +0000156}
157
Rafael Espindolae23b8772013-12-20 15:21:32 +0000158static const LayoutAlignElem DefaultAlignments[] = {
Rafael Espindola458a4852013-12-19 23:03:03 +0000159 { INTEGER_ALIGN, 1, 1, 1 }, // i1
160 { INTEGER_ALIGN, 8, 1, 1 }, // i8
161 { INTEGER_ALIGN, 16, 2, 2 }, // i16
162 { INTEGER_ALIGN, 32, 4, 4 }, // i32
163 { INTEGER_ALIGN, 64, 4, 8 }, // i64
164 { FLOAT_ALIGN, 16, 2, 2 }, // half
165 { FLOAT_ALIGN, 32, 4, 4 }, // float
166 { FLOAT_ALIGN, 64, 8, 8 }, // double
167 { FLOAT_ALIGN, 128, 16, 16 }, // ppcf128, quad, ...
168 { VECTOR_ALIGN, 64, 8, 8 }, // v2i32, v1i64, ...
169 { VECTOR_ALIGN, 128, 16, 16 }, // v16i8, v8i16, v4i32, ...
170 { AGGREGATE_ALIGN, 0, 0, 8 } // struct
171};
172
Rafael Espindola248ac132014-02-25 22:23:04 +0000173void DataLayout::reset(StringRef Desc) {
174 clear();
175
Craig Topperc6207612014-04-09 06:08:46 +0000176 LayoutMap = nullptr;
Chandler Carruthf67321c2014-10-20 10:41:29 +0000177 BigEndian = false;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000178 StackNaturalAlign = 0;
Rafael Espindola58873562014-01-03 19:21:54 +0000179 ManglingMode = MM_None;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000180
181 // Default alignments
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000182 for (const LayoutAlignElem &E : DefaultAlignments) {
Rafael Espindola458a4852013-12-19 23:03:03 +0000183 setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign, E.PrefAlign,
184 E.TypeBitWidth);
185 }
Micah Villmow89021e42012-10-09 16:06:12 +0000186 setPointerAlignment(0, 8, 8, 8);
Patrik Hägglund01860a62012-11-14 09:04:56 +0000187
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000188 parseSpecifier(Desc);
189}
190
191/// Checked version of split, to ensure mandatory subparts.
192static std::pair<StringRef, StringRef> split(StringRef Str, char Separator) {
193 assert(!Str.empty() && "parse error, string can't be empty here");
194 std::pair<StringRef, StringRef> Split = Str.split(Separator);
David Majnemer2dc1b0f2014-12-10 01:38:28 +0000195 if (Split.second.empty() && Split.first != Str)
196 report_fatal_error("Trailing separator in datalayout string");
David Majnemer612f3122014-12-10 02:36:41 +0000197 if (!Split.second.empty() && Split.first.empty())
198 report_fatal_error("Expected token before separator in datalayout string");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000199 return Split;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000200}
201
Cameron McInally8af9eac2014-01-07 19:51:38 +0000202/// Get an unsigned integer, including error checks.
Patrik Hägglund3eb16c52012-11-28 12:13:12 +0000203static unsigned getInt(StringRef R) {
Cameron McInallyf0379fa2014-01-13 22:04:55 +0000204 unsigned Result;
Patrik Hägglund504f4782012-11-28 14:32:52 +0000205 bool error = R.getAsInteger(10, Result); (void)error;
Cameron McInallyf0379fa2014-01-13 22:04:55 +0000206 if (error)
207 report_fatal_error("not a number, or does not fit in an unsigned int");
Patrik Hägglund3eb16c52012-11-28 12:13:12 +0000208 return Result;
209}
210
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000211/// Convert bits into bytes. Assert if not a byte width multiple.
212static unsigned inBytes(unsigned Bits) {
David Majnemer2dc1b0f2014-12-10 01:38:28 +0000213 if (Bits % 8)
214 report_fatal_error("number of bits must be a byte width multiple");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000215 return Bits / 8;
216}
217
218void DataLayout::parseSpecifier(StringRef Desc) {
Mehdi Amini46a43552015-03-04 18:43:29 +0000219 StringRepresentation = Desc;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000220 while (!Desc.empty()) {
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000221 // Split at '-'.
222 std::pair<StringRef, StringRef> Split = split(Desc, '-');
Micah Villmowac34b5c2012-10-04 22:08:14 +0000223 Desc = Split.second;
224
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000225 // Split at ':'.
226 Split = split(Split.first, ':');
Micah Villmowac34b5c2012-10-04 22:08:14 +0000227
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000228 // Aliases used below.
229 StringRef &Tok = Split.first; // Current token.
230 StringRef &Rest = Split.second; // The rest of the string.
Micah Villmowac34b5c2012-10-04 22:08:14 +0000231
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000232 char Specifier = Tok.front();
233 Tok = Tok.substr(1);
234
235 switch (Specifier) {
Rafael Espindola6994fdf2014-01-01 22:29:43 +0000236 case 's':
237 // Ignored for backward compatibility.
238 // FIXME: remove this on LLVM 4.0.
239 break;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000240 case 'E':
Chandler Carruthf67321c2014-10-20 10:41:29 +0000241 BigEndian = true;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000242 break;
243 case 'e':
Chandler Carruthf67321c2014-10-20 10:41:29 +0000244 BigEndian = false;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000245 break;
246 case 'p': {
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000247 // Address space.
248 unsigned AddrSpace = Tok.empty() ? 0 : getInt(Tok);
David Majnemer5330c692014-12-10 01:17:08 +0000249 if (!isUInt<24>(AddrSpace))
250 report_fatal_error("Invalid address space, must be a 24bit integer");
Micah Villmowac34b5c2012-10-04 22:08:14 +0000251
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000252 // Size.
David Majnemer2dc1b0f2014-12-10 01:38:28 +0000253 if (Rest.empty())
254 report_fatal_error(
255 "Missing size specification for pointer in datalayout string");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000256 Split = split(Rest, ':');
257 unsigned PointerMemSize = inBytes(getInt(Tok));
Owen Anderson5bc2bbe2015-03-02 06:00:02 +0000258 if (!PointerMemSize)
259 report_fatal_error("Invalid pointer size of 0 bytes");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000260
261 // ABI alignment.
David Majnemer2dc1b0f2014-12-10 01:38:28 +0000262 if (Rest.empty())
263 report_fatal_error(
264 "Missing alignment specification for pointer in datalayout string");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000265 Split = split(Rest, ':');
266 unsigned PointerABIAlign = inBytes(getInt(Tok));
Owen Anderson040f2f82015-03-02 06:33:51 +0000267 if (!isPowerOf2_64(PointerABIAlign))
268 report_fatal_error(
269 "Pointer ABI alignment must be a power of 2");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000270
271 // Preferred alignment.
272 unsigned PointerPrefAlign = PointerABIAlign;
273 if (!Rest.empty()) {
274 Split = split(Rest, ':');
275 PointerPrefAlign = inBytes(getInt(Tok));
Owen Anderson040f2f82015-03-02 06:33:51 +0000276 if (!isPowerOf2_64(PointerPrefAlign))
277 report_fatal_error(
278 "Pointer preferred alignment must be a power of 2");
Micah Villmowac34b5c2012-10-04 22:08:14 +0000279 }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000280
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000281 setPointerAlignment(AddrSpace, PointerABIAlign, PointerPrefAlign,
282 PointerMemSize);
Micah Villmowac34b5c2012-10-04 22:08:14 +0000283 break;
284 }
285 case 'i':
286 case 'v':
287 case 'f':
Rafael Espindola6994fdf2014-01-01 22:29:43 +0000288 case 'a': {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000289 AlignTypeEnum AlignType;
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000290 switch (Specifier) {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000291 default:
292 case 'i': AlignType = INTEGER_ALIGN; break;
293 case 'v': AlignType = VECTOR_ALIGN; break;
294 case 'f': AlignType = FLOAT_ALIGN; break;
295 case 'a': AlignType = AGGREGATE_ALIGN; break;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000296 }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000297
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000298 // Bit size.
299 unsigned Size = Tok.empty() ? 0 : getInt(Tok);
300
David Majnemer5330c692014-12-10 01:17:08 +0000301 if (AlignType == AGGREGATE_ALIGN && Size != 0)
302 report_fatal_error(
303 "Sized aggregate specification in datalayout string");
Rafael Espindolaabdd7262014-01-06 21:40:24 +0000304
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000305 // ABI alignment.
David Majnemer612f3122014-12-10 02:36:41 +0000306 if (Rest.empty())
307 report_fatal_error(
308 "Missing alignment specification in datalayout string");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000309 Split = split(Rest, ':');
310 unsigned ABIAlign = inBytes(getInt(Tok));
Owen Andersonab1c7a72015-03-02 09:34:59 +0000311 if (AlignType != AGGREGATE_ALIGN && !ABIAlign)
312 report_fatal_error(
313 "ABI alignment specification must be >0 for non-aggregate types");
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000314
315 // Preferred alignment.
316 unsigned PrefAlign = ABIAlign;
317 if (!Rest.empty()) {
318 Split = split(Rest, ':');
319 PrefAlign = inBytes(getInt(Tok));
Micah Villmowac34b5c2012-10-04 22:08:14 +0000320 }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000321
Patrik Hägglund01860a62012-11-14 09:04:56 +0000322 setAlignment(AlignType, ABIAlign, PrefAlign, Size);
Micah Villmowb4faa152012-10-04 23:01:22 +0000323
Micah Villmowac34b5c2012-10-04 22:08:14 +0000324 break;
325 }
326 case 'n': // Native integer types.
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000327 for (;;) {
328 unsigned Width = getInt(Tok);
David Majnemer5330c692014-12-10 01:17:08 +0000329 if (Width == 0)
330 report_fatal_error(
331 "Zero width native integer type in datalayout string");
Patrik Hägglund3eb16c52012-11-28 12:13:12 +0000332 LegalIntWidths.push_back(Width);
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000333 if (Rest.empty())
334 break;
335 Split = split(Rest, ':');
336 }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000337 break;
338 case 'S': { // Stack natural alignment.
Patrik Hagglund086ee1e2012-11-30 10:06:59 +0000339 StackNaturalAlign = inBytes(getInt(Tok));
Micah Villmowac34b5c2012-10-04 22:08:14 +0000340 break;
341 }
Rafael Espindola58873562014-01-03 19:21:54 +0000342 case 'm':
David Majnemer612f3122014-12-10 02:36:41 +0000343 if (!Tok.empty())
344 report_fatal_error("Unexpected trailing characters after mangling specifier in datalayout string");
345 if (Rest.empty())
346 report_fatal_error("Expected mangling specifier in datalayout string");
347 if (Rest.size() > 1)
348 report_fatal_error("Unknown mangling specifier in datalayout string");
Rafael Espindola58873562014-01-03 19:21:54 +0000349 switch(Rest[0]) {
350 default:
David Majnemer5330c692014-12-10 01:17:08 +0000351 report_fatal_error("Unknown mangling in datalayout string");
Rafael Espindola58873562014-01-03 19:21:54 +0000352 case 'e':
353 ManglingMode = MM_ELF;
354 break;
355 case 'o':
356 ManglingMode = MM_MachO;
357 break;
358 case 'm':
359 ManglingMode = MM_Mips;
360 break;
Rafael Espindolaaf77e122014-01-10 13:42:12 +0000361 case 'w':
David Majnemer7db449a2015-03-17 23:54:51 +0000362 ManglingMode = MM_WinCOFF;
363 break;
364 case 'x':
365 ManglingMode = MM_WinCOFFX86;
Rafael Espindola58873562014-01-03 19:21:54 +0000366 break;
367 }
368 break;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000369 default:
David Majnemer5330c692014-12-10 01:17:08 +0000370 report_fatal_error("Unknown specifier in datalayout string");
Micah Villmowac34b5c2012-10-04 22:08:14 +0000371 break;
372 }
373 }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000374}
375
Craig Topperc6207612014-04-09 06:08:46 +0000376DataLayout::DataLayout(const Module *M) : LayoutMap(nullptr) {
Rafael Espindolac435adc2014-09-10 21:27:43 +0000377 init(M);
378}
379
Mehdi Amini46a43552015-03-04 18:43:29 +0000380void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000381
Rafael Espindolaae593f12014-02-26 17:02:08 +0000382bool DataLayout::operator==(const DataLayout &Other) const {
Chandler Carruthf67321c2014-10-20 10:41:29 +0000383 bool Ret = BigEndian == Other.BigEndian &&
Rafael Espindolaae593f12014-02-26 17:02:08 +0000384 StackNaturalAlign == Other.StackNaturalAlign &&
385 ManglingMode == Other.ManglingMode &&
386 LegalIntWidths == Other.LegalIntWidths &&
Rafael Espindola89992b02014-04-22 17:47:03 +0000387 Alignments == Other.Alignments && Pointers == Other.Pointers;
Mehdi Amini46a43552015-03-04 18:43:29 +0000388 // Note: getStringRepresentation() might differs, it is not canonicalized
Rafael Espindolaae593f12014-02-26 17:02:08 +0000389 return Ret;
390}
391
Micah Villmowac34b5c2012-10-04 22:08:14 +0000392void
Micah Villmowb4faa152012-10-04 23:01:22 +0000393DataLayout::setAlignment(AlignTypeEnum align_type, unsigned abi_align,
Micah Villmowac34b5c2012-10-04 22:08:14 +0000394 unsigned pref_align, uint32_t bit_width) {
David Majnemer1b9fc3a2015-02-16 05:41:53 +0000395 if (!isUInt<24>(bit_width))
396 report_fatal_error("Invalid bit width, must be a 24bit integer");
397 if (!isUInt<16>(abi_align))
398 report_fatal_error("Invalid ABI alignment, must be a 16bit integer");
399 if (!isUInt<16>(pref_align))
400 report_fatal_error("Invalid preferred alignment, must be a 16bit integer");
Owen Anderson5af4b212015-03-02 09:35:03 +0000401 if (abi_align != 0 && !isPowerOf2_64(abi_align))
402 report_fatal_error("Invalid ABI alignment, must be a power of 2");
403 if (pref_align != 0 && !isPowerOf2_64(pref_align))
404 report_fatal_error("Invalid preferred alignment, must be a power of 2");
David Majnemer1b9fc3a2015-02-16 05:41:53 +0000405
406 if (pref_align < abi_align)
407 report_fatal_error(
408 "Preferred alignment cannot be less than the ABI alignment");
409
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000410 for (LayoutAlignElem &Elem : Alignments) {
411 if (Elem.AlignType == (unsigned)align_type &&
412 Elem.TypeBitWidth == bit_width) {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000413 // Update the abi, preferred alignments.
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000414 Elem.ABIAlign = abi_align;
415 Elem.PrefAlign = pref_align;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000416 return;
417 }
418 }
419
Micah Villmowb4faa152012-10-04 23:01:22 +0000420 Alignments.push_back(LayoutAlignElem::get(align_type, abi_align,
Micah Villmowac34b5c2012-10-04 22:08:14 +0000421 pref_align, bit_width));
422}
423
Rafael Espindola667fcb82014-02-26 16:58:35 +0000424DataLayout::PointersTy::iterator
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000425DataLayout::findPointerLowerBound(uint32_t AddressSpace) {
Rafael Espindola667fcb82014-02-26 16:58:35 +0000426 return std::lower_bound(Pointers.begin(), Pointers.end(), AddressSpace,
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000427 [](const PointerAlignElem &A, uint32_t AddressSpace) {
428 return A.AddressSpace < AddressSpace;
429 });
Rafael Espindola667fcb82014-02-26 16:58:35 +0000430}
431
Rafael Espindolaf39136c2013-12-13 23:15:20 +0000432void DataLayout::setPointerAlignment(uint32_t AddrSpace, unsigned ABIAlign,
433 unsigned PrefAlign,
434 uint32_t TypeByteWidth) {
David Majnemer4b042922015-02-16 05:41:55 +0000435 if (PrefAlign < ABIAlign)
436 report_fatal_error(
437 "Preferred alignment cannot be less than the ABI alignment");
438
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000439 PointersTy::iterator I = findPointerLowerBound(AddrSpace);
Rafael Espindola667fcb82014-02-26 16:58:35 +0000440 if (I == Pointers.end() || I->AddressSpace != AddrSpace) {
441 Pointers.insert(I, PointerAlignElem::get(AddrSpace, ABIAlign, PrefAlign,
442 TypeByteWidth));
Micah Villmow89021e42012-10-09 16:06:12 +0000443 } else {
Rafael Espindola667fcb82014-02-26 16:58:35 +0000444 I->ABIAlign = ABIAlign;
445 I->PrefAlign = PrefAlign;
446 I->TypeByteWidth = TypeByteWidth;
Micah Villmow89021e42012-10-09 16:06:12 +0000447 }
448}
449
Micah Villmowac34b5c2012-10-04 22:08:14 +0000450/// getAlignmentInfo - Return the alignment (either ABI if ABIInfo = true or
Micah Villmowb4faa152012-10-04 23:01:22 +0000451/// preferred if ABIInfo = false) the layout wants for the specified datatype.
452unsigned DataLayout::getAlignmentInfo(AlignTypeEnum AlignType,
Micah Villmowac34b5c2012-10-04 22:08:14 +0000453 uint32_t BitWidth, bool ABIInfo,
454 Type *Ty) const {
455 // Check to see if we have an exact match and remember the best match we see.
456 int BestMatchIdx = -1;
457 int LargestInt = -1;
458 for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
Micah Villmow6d05e692012-10-05 17:02:14 +0000459 if (Alignments[i].AlignType == (unsigned)AlignType &&
Micah Villmowac34b5c2012-10-04 22:08:14 +0000460 Alignments[i].TypeBitWidth == BitWidth)
461 return ABIInfo ? Alignments[i].ABIAlign : Alignments[i].PrefAlign;
462
463 // The best match so far depends on what we're looking for.
Sanjay Patel42af5c62015-07-21 16:09:58 +0000464 if (AlignType == INTEGER_ALIGN &&
465 Alignments[i].AlignType == INTEGER_ALIGN) {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000466 // The "best match" for integers is the smallest size that is larger than
467 // the BitWidth requested.
468 if (Alignments[i].TypeBitWidth > BitWidth && (BestMatchIdx == -1 ||
Eli Benderskyfaf5e3e2013-01-30 19:24:23 +0000469 Alignments[i].TypeBitWidth < Alignments[BestMatchIdx].TypeBitWidth))
Micah Villmowac34b5c2012-10-04 22:08:14 +0000470 BestMatchIdx = i;
471 // However, if there isn't one that's larger, then we must use the
472 // largest one we have (see below)
473 if (LargestInt == -1 ||
474 Alignments[i].TypeBitWidth > Alignments[LargestInt].TypeBitWidth)
475 LargestInt = i;
476 }
477 }
478
479 // Okay, we didn't find an exact solution. Fall back here depending on what
480 // is being looked for.
481 if (BestMatchIdx == -1) {
482 // If we didn't find an integer alignment, fall back on most conservative.
483 if (AlignType == INTEGER_ALIGN) {
484 BestMatchIdx = LargestInt;
Owen Anderson7e621e92015-03-08 21:53:59 +0000485 } else if (AlignType == VECTOR_ALIGN) {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000486 // By default, use natural alignment for vector types. This is consistent
487 // with what clang and llvm-gcc do.
488 unsigned Align = getTypeAllocSize(cast<VectorType>(Ty)->getElementType());
489 Align *= cast<VectorType>(Ty)->getNumElements();
490 // If the alignment is not a power of 2, round up to the next power of 2.
491 // This happens for non-power-of-2 length vectors.
492 if (Align & (Align-1))
493 Align = NextPowerOf2(Align);
494 return Align;
495 }
496 }
497
Owen Anderson7e621e92015-03-08 21:53:59 +0000498 // If we still couldn't find a reasonable default alignment, fall back
499 // to a simple heuristic that the alignment is the first power of two
500 // greater-or-equal to the store size of the type. This is a reasonable
501 // approximation of reality, and if the user wanted something less
502 // less conservative, they should have specified it explicitly in the data
503 // layout.
504 if (BestMatchIdx == -1) {
505 unsigned Align = getTypeStoreSize(Ty);
506 if (Align & (Align-1))
507 Align = NextPowerOf2(Align);
508 return Align;
509 }
510
Micah Villmowac34b5c2012-10-04 22:08:14 +0000511 // Since we got a "best match" index, just return it.
512 return ABIInfo ? Alignments[BestMatchIdx].ABIAlign
513 : Alignments[BestMatchIdx].PrefAlign;
514}
515
516namespace {
517
518class StructLayoutMap {
519 typedef DenseMap<StructType*, StructLayout*> LayoutInfoTy;
520 LayoutInfoTy LayoutInfo;
521
522public:
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000523 ~StructLayoutMap() {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000524 // Remove any layouts.
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000525 for (const auto &I : LayoutInfo) {
526 StructLayout *Value = I.second;
Micah Villmowac34b5c2012-10-04 22:08:14 +0000527 Value->~StructLayout();
528 free(Value);
529 }
530 }
531
532 StructLayout *&operator[](StructType *STy) {
533 return LayoutInfo[STy];
534 }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000535};
536
537} // end anonymous namespace
538
Rafael Espindola248ac132014-02-25 22:23:04 +0000539void DataLayout::clear() {
540 LegalIntWidths.clear();
541 Alignments.clear();
542 Pointers.clear();
543 delete static_cast<StructLayoutMap *>(LayoutMap);
Craig Topperc6207612014-04-09 06:08:46 +0000544 LayoutMap = nullptr;
Rafael Espindola248ac132014-02-25 22:23:04 +0000545}
546
Micah Villmowb4faa152012-10-04 23:01:22 +0000547DataLayout::~DataLayout() {
Rafael Espindola248ac132014-02-25 22:23:04 +0000548 clear();
Micah Villmowac34b5c2012-10-04 22:08:14 +0000549}
550
Micah Villmowb4faa152012-10-04 23:01:22 +0000551const StructLayout *DataLayout::getStructLayout(StructType *Ty) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000552 if (!LayoutMap)
553 LayoutMap = new StructLayoutMap();
554
555 StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
556 StructLayout *&SL = (*STM)[Ty];
557 if (SL) return SL;
558
559 // Otherwise, create the struct layout. Because it is variable length, we
560 // malloc it, then use placement new.
561 int NumElts = Ty->getNumElements();
562 StructLayout *L =
563 (StructLayout *)malloc(sizeof(StructLayout)+(NumElts-1) * sizeof(uint64_t));
564
565 // Set SL before calling StructLayout's ctor. The ctor could cause other
566 // entries to be added to TheMap, invalidating our reference.
567 SL = L;
568
569 new (L) StructLayout(Ty, *this);
570
571 return L;
572}
573
Micah Villmowac34b5c2012-10-04 22:08:14 +0000574
Rafael Espindola5109fcc2014-02-26 16:49:40 +0000575unsigned DataLayout::getPointerABIAlignment(unsigned AS) const {
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000576 PointersTy::const_iterator I = findPointerLowerBound(AS);
Rafael Espindola667fcb82014-02-26 16:58:35 +0000577 if (I == Pointers.end() || I->AddressSpace != AS) {
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000578 I = findPointerLowerBound(0);
Rafael Espindola667fcb82014-02-26 16:58:35 +0000579 assert(I->AddressSpace == 0);
Rafael Espindola5109fcc2014-02-26 16:49:40 +0000580 }
Rafael Espindola667fcb82014-02-26 16:58:35 +0000581 return I->ABIAlign;
Rafael Espindola5109fcc2014-02-26 16:49:40 +0000582}
583
584unsigned DataLayout::getPointerPrefAlignment(unsigned AS) const {
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000585 PointersTy::const_iterator I = findPointerLowerBound(AS);
Rafael Espindola667fcb82014-02-26 16:58:35 +0000586 if (I == Pointers.end() || I->AddressSpace != AS) {
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000587 I = findPointerLowerBound(0);
Rafael Espindola667fcb82014-02-26 16:58:35 +0000588 assert(I->AddressSpace == 0);
Rafael Espindola5109fcc2014-02-26 16:49:40 +0000589 }
Rafael Espindola667fcb82014-02-26 16:58:35 +0000590 return I->PrefAlign;
Rafael Espindola5109fcc2014-02-26 16:49:40 +0000591}
592
593unsigned DataLayout::getPointerSize(unsigned AS) const {
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000594 PointersTy::const_iterator I = findPointerLowerBound(AS);
Rafael Espindola667fcb82014-02-26 16:58:35 +0000595 if (I == Pointers.end() || I->AddressSpace != AS) {
Rafael Espindolae8ae0db2014-02-26 17:05:38 +0000596 I = findPointerLowerBound(0);
Rafael Espindola667fcb82014-02-26 16:58:35 +0000597 assert(I->AddressSpace == 0);
Rafael Espindola5109fcc2014-02-26 16:49:40 +0000598 }
Rafael Espindola667fcb82014-02-26 16:58:35 +0000599 return I->TypeByteWidth;
Rafael Espindola5109fcc2014-02-26 16:49:40 +0000600}
601
Matt Arsenault6f4be902013-07-26 17:37:20 +0000602unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const {
603 assert(Ty->isPtrOrPtrVectorTy() &&
604 "This should only be called with a pointer or pointer vector type");
605
606 if (Ty->isPointerTy())
607 return getTypeSizeInBits(Ty);
608
Matt Arsenault517cf482013-07-27 19:22:28 +0000609 return getTypeSizeInBits(Ty->getScalarType());
Matt Arsenault6f4be902013-07-26 17:37:20 +0000610}
Micah Villmowac34b5c2012-10-04 22:08:14 +0000611
Micah Villmowac34b5c2012-10-04 22:08:14 +0000612/*!
613 \param abi_or_pref Flag that determines which alignment is returned. true
614 returns the ABI alignment, false returns the preferred alignment.
615 \param Ty The underlying type for which alignment is determined.
616
617 Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
618 == false) for the requested type \a Ty.
619 */
Micah Villmowb4faa152012-10-04 23:01:22 +0000620unsigned DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000621 int AlignType = -1;
622
623 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
624 switch (Ty->getTypeID()) {
625 // Early escape for the non-numeric types.
626 case Type::LabelTyID:
Micah Villmowac34b5c2012-10-04 22:08:14 +0000627 return (abi_or_pref
Micah Villmow89021e42012-10-09 16:06:12 +0000628 ? getPointerABIAlignment(0)
629 : getPointerPrefAlignment(0));
630 case Type::PointerTyID: {
Matt Arsenaultc1728972014-09-18 22:28:56 +0000631 unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
Micah Villmow89021e42012-10-09 16:06:12 +0000632 return (abi_or_pref
633 ? getPointerABIAlignment(AS)
634 : getPointerPrefAlignment(AS));
635 }
Micah Villmowac34b5c2012-10-04 22:08:14 +0000636 case Type::ArrayTyID:
637 return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
638
639 case Type::StructTyID: {
640 // Packed structure types always have an ABI alignment of one.
641 if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
642 return 1;
643
644 // Get the layout annotation... which is lazily created on demand.
645 const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
646 unsigned Align = getAlignmentInfo(AGGREGATE_ALIGN, 0, abi_or_pref, Ty);
647 return std::max(Align, Layout->getAlignment());
648 }
649 case Type::IntegerTyID:
Micah Villmowac34b5c2012-10-04 22:08:14 +0000650 AlignType = INTEGER_ALIGN;
651 break;
652 case Type::HalfTyID:
653 case Type::FloatTyID:
654 case Type::DoubleTyID:
655 // PPC_FP128TyID and FP128TyID have different data contents, but the
656 // same size and alignment, so they look the same here.
657 case Type::PPC_FP128TyID:
658 case Type::FP128TyID:
659 case Type::X86_FP80TyID:
660 AlignType = FLOAT_ALIGN;
661 break;
662 case Type::X86_MMXTyID:
663 case Type::VectorTyID:
664 AlignType = VECTOR_ALIGN;
665 break;
666 default:
667 llvm_unreachable("Bad type for getAlignment!!!");
668 }
669
670 return getAlignmentInfo((AlignTypeEnum)AlignType, getTypeSizeInBits(Ty),
671 abi_or_pref, Ty);
672}
673
Micah Villmowb4faa152012-10-04 23:01:22 +0000674unsigned DataLayout::getABITypeAlignment(Type *Ty) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000675 return getAlignment(Ty, true);
676}
677
678/// getABIIntegerTypeAlignment - Return the minimum ABI-required alignment for
679/// an integer type of the specified bitwidth.
Micah Villmowb4faa152012-10-04 23:01:22 +0000680unsigned DataLayout::getABIIntegerTypeAlignment(unsigned BitWidth) const {
Craig Topperc6207612014-04-09 06:08:46 +0000681 return getAlignmentInfo(INTEGER_ALIGN, BitWidth, true, nullptr);
Micah Villmowac34b5c2012-10-04 22:08:14 +0000682}
683
Micah Villmowb4faa152012-10-04 23:01:22 +0000684unsigned DataLayout::getPrefTypeAlignment(Type *Ty) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000685 return getAlignment(Ty, false);
686}
687
Micah Villmowb4faa152012-10-04 23:01:22 +0000688unsigned DataLayout::getPreferredTypeAlignmentShift(Type *Ty) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000689 unsigned Align = getPrefTypeAlignment(Ty);
690 assert(!(Align & (Align-1)) && "Alignment is not a power of two!");
691 return Log2_32(Align);
692}
693
Micah Villmow89021e42012-10-09 16:06:12 +0000694IntegerType *DataLayout::getIntPtrType(LLVMContext &C,
695 unsigned AddressSpace) const {
696 return IntegerType::get(C, getPointerSizeInBits(AddressSpace));
Micah Villmowac34b5c2012-10-04 22:08:14 +0000697}
698
Duncan Sands5bdd9dd2012-10-29 17:31:46 +0000699Type *DataLayout::getIntPtrType(Type *Ty) const {
Chandler Carruth7ec50852012-11-01 08:07:29 +0000700 assert(Ty->isPtrOrPtrVectorTy() &&
701 "Expected a pointer or pointer vector type.");
Matt Arsenault4dbd4892014-04-23 21:10:15 +0000702 unsigned NumBits = getPointerTypeSizeInBits(Ty);
Duncan Sands5bdd9dd2012-10-29 17:31:46 +0000703 IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
704 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
705 return VectorType::get(IntTy, VecTy->getNumElements());
706 return IntTy;
Micah Villmow12d91272012-10-24 15:52:52 +0000707}
708
Arnaud A. de Grandmaisonf364bc62013-03-22 08:25:01 +0000709Type *DataLayout::getSmallestLegalIntType(LLVMContext &C, unsigned Width) const {
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000710 for (unsigned LegalIntWidth : LegalIntWidths)
711 if (Width <= LegalIntWidth)
712 return Type::getIntNTy(C, LegalIntWidth);
Craig Topperc6207612014-04-09 06:08:46 +0000713 return nullptr;
Arnaud A. de Grandmaisonf364bc62013-03-22 08:25:01 +0000714}
715
Matt Arsenault899f7d22013-09-16 22:43:16 +0000716unsigned DataLayout::getLargestLegalIntTypeSize() const {
Benjamin Kramer3ad5c962014-03-10 15:03:06 +0000717 auto Max = std::max_element(LegalIntWidths.begin(), LegalIntWidths.end());
718 return Max != LegalIntWidths.end() ? *Max : 0;
Matt Arsenault899f7d22013-09-16 22:43:16 +0000719}
720
Micah Villmowb4faa152012-10-04 23:01:22 +0000721uint64_t DataLayout::getIndexedOffset(Type *ptrTy,
Micah Villmowac34b5c2012-10-04 22:08:14 +0000722 ArrayRef<Value *> Indices) const {
723 Type *Ty = ptrTy;
724 assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()");
725 uint64_t Result = 0;
726
727 generic_gep_type_iterator<Value* const*>
728 TI = gep_type_begin(ptrTy, Indices);
729 for (unsigned CurIDX = 0, EndIDX = Indices.size(); CurIDX != EndIDX;
730 ++CurIDX, ++TI) {
731 if (StructType *STy = dyn_cast<StructType>(*TI)) {
732 assert(Indices[CurIDX]->getType() ==
733 Type::getInt32Ty(ptrTy->getContext()) &&
734 "Illegal struct idx");
735 unsigned FieldNo = cast<ConstantInt>(Indices[CurIDX])->getZExtValue();
736
737 // Get structure layout information...
738 const StructLayout *Layout = getStructLayout(STy);
739
740 // Add in the offset, as calculated by the structure layout info...
741 Result += Layout->getElementOffset(FieldNo);
742
743 // Update Ty to refer to current element
744 Ty = STy->getElementType(FieldNo);
745 } else {
746 // Update Ty to refer to current element
747 Ty = cast<SequentialType>(Ty)->getElementType();
748
749 // Get the array index and the size of each array element.
750 if (int64_t arrayIdx = cast<ConstantInt>(Indices[CurIDX])->getSExtValue())
751 Result += (uint64_t)arrayIdx * getTypeAllocSize(Ty);
752 }
753 }
754
755 return Result;
756}
757
758/// getPreferredAlignment - Return the preferred alignment of the specified
759/// global. This includes an explicitly requested alignment (if the global
760/// has one).
Micah Villmowb4faa152012-10-04 23:01:22 +0000761unsigned DataLayout::getPreferredAlignment(const GlobalVariable *GV) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000762 Type *ElemType = GV->getType()->getElementType();
763 unsigned Alignment = getPrefTypeAlignment(ElemType);
764 unsigned GVAlignment = GV->getAlignment();
765 if (GVAlignment >= Alignment) {
766 Alignment = GVAlignment;
767 } else if (GVAlignment != 0) {
768 Alignment = std::max(GVAlignment, getABITypeAlignment(ElemType));
769 }
770
771 if (GV->hasInitializer() && GVAlignment == 0) {
772 if (Alignment < 16) {
773 // If the global is not external, see if it is large. If so, give it a
774 // larger alignment.
775 if (getTypeSizeInBits(ElemType) > 128)
776 Alignment = 16; // 16-byte alignment.
777 }
778 }
779 return Alignment;
780}
781
782/// getPreferredAlignmentLog - Return the preferred alignment of the
783/// specified global, returned in log form. This includes an explicitly
784/// requested alignment (if the global has one).
Micah Villmowb4faa152012-10-04 23:01:22 +0000785unsigned DataLayout::getPreferredAlignmentLog(const GlobalVariable *GV) const {
Micah Villmowac34b5c2012-10-04 22:08:14 +0000786 return Log2_32(getPreferredAlignment(GV));
787}
Rafael Espindola93512512014-02-25 17:30:31 +0000788