@@ -49,43 +49,11 @@ class StructLayout;
49
49
class Triple ;
50
50
class Value ;
51
51
52
- // / Enum used to categorize the alignment types stored by LayoutAlignElem
53
- enum AlignTypeEnum {
54
- INTEGER_ALIGN = ' i' ,
55
- VECTOR_ALIGN = ' v' ,
56
- FLOAT_ALIGN = ' f' ,
57
- AGGREGATE_ALIGN = ' a'
58
- };
59
-
60
52
// FIXME: Currently the DataLayout string carries a "preferred alignment"
61
53
// for types. As the DataLayout is module/global, this should likely be
62
54
// sunk down to an FTTI element that is queried rather than a global
63
55
// preference.
64
56
65
- // / Layout alignment element.
66
- // /
67
- // / Stores the alignment data associated with a given type bit width.
68
- struct LayoutAlignElem {
69
- uint32_t TypeBitWidth;
70
- Align ABIAlign;
71
- Align PrefAlign;
72
-
73
- bool operator ==(const LayoutAlignElem &rhs) const ;
74
- };
75
-
76
- // / Layout pointer alignment element.
77
- // /
78
- // / Stores the alignment data associated with a given pointer and address space.
79
- struct PointerAlignElem {
80
- uint32_t AddressSpace;
81
- uint32_t TypeBitWidth;
82
- Align ABIAlign;
83
- Align PrefAlign;
84
- uint32_t IndexBitWidth;
85
-
86
- bool operator ==(const PointerAlignElem &rhs) const ;
87
- };
88
-
89
57
// / A parsed version of the target data layout string in and methods for
90
58
// / querying it.
91
59
// /
@@ -127,27 +95,54 @@ class DataLayout {
127
95
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
128
96
SmallVector<unsigned char , 8 > LegalIntWidths;
129
97
98
+ // Primitive type specifier.
99
+ enum class PrimitiveSpecifier {
100
+ Integer = ' i' ,
101
+ Float = ' f' ,
102
+ Vector = ' v' ,
103
+ // TODO: Aggregates are not primitives. This should be separated.
104
+ Aggregate = ' a'
105
+ };
106
+
107
+ // Primitive type specification.
108
+ struct PrimitiveSpec {
109
+ uint32_t TypeBitWidth;
110
+ Align ABIAlign;
111
+ Align PrefAlign;
112
+
113
+ bool operator ==(const PrimitiveSpec &Other) const ;
114
+ };
115
+
116
+ // Pointer type specification.
117
+ struct PointerSpec {
118
+ uint32_t AddressSpace;
119
+ uint32_t TypeBitWidth;
120
+ Align ABIAlign;
121
+ Align PrefAlign;
122
+ uint32_t IndexBitWidth;
123
+
124
+ bool operator ==(const PointerSpec &Other) const ;
125
+ };
126
+
130
127
// Default primitive type specifications.
131
- static const LayoutAlignElem DefaultIntSpecs[];
132
- static const LayoutAlignElem DefaultFloatSpecs[];
133
- static const LayoutAlignElem DefaultVectorSpecs[];
128
+ static const PrimitiveSpec DefaultIntSpecs[];
129
+ static const PrimitiveSpec DefaultFloatSpecs[];
130
+ static const PrimitiveSpec DefaultVectorSpecs[];
134
131
135
132
// Default pointer type specifications.
136
- static const PointerAlignElem DefaultPointerSpecs[];
133
+ static const PointerSpec DefaultPointerSpecs[];
137
134
138
135
// Primitive type specifications. Sorted and uniqued by type bit width.
139
- SmallVector<LayoutAlignElem , 6 > IntAlignments ;
140
- SmallVector<LayoutAlignElem , 4 > FloatAlignments ;
141
- SmallVector<LayoutAlignElem , 10 > VectorAlignments ;
136
+ SmallVector<PrimitiveSpec , 6 > IntSpecs ;
137
+ SmallVector<PrimitiveSpec , 4 > FloatSpecs ;
138
+ SmallVector<PrimitiveSpec , 10 > VectorSpecs ;
142
139
143
140
// Pointer type specifications. Sorted and uniqued by address space number.
144
- SmallVector<PointerAlignElem , 8 > Pointers ;
141
+ SmallVector<PointerSpec , 8 > PointerSpecs ;
145
142
146
143
// / The string representation used to create this DataLayout
147
144
std::string StringRepresentation;
148
145
149
- const PointerAlignElem &getPointerAlignElem (uint32_t AddressSpace) const ;
150
-
151
146
// Struct type ABI and preferred alignments. The default spec is "a:8:64".
152
147
Align StructABIAlignment = Align::Constant<1 >();
153
148
Align StructPrefAlignment = Align::Constant<8 >();
@@ -159,16 +154,25 @@ class DataLayout {
159
154
// / well-defined bitwise representation.
160
155
SmallVector<unsigned , 8 > NonIntegralAddressSpaces;
161
156
162
- // / Attempts to set the alignment of the given type. Returns an error
163
- // / description on failure.
164
- Error setAlignment (AlignTypeEnum AlignType, Align ABIAlign, Align PrefAlign,
165
- uint32_t BitWidth);
157
+ // Searches for a primitive specification that matches the given bit width.
158
+ // Returns the end iterator if the specification is not found.
159
+ SmallVectorImpl<PrimitiveSpec>::const_iterator
160
+ getPrimitiveSpec (const SmallVectorImpl<PrimitiveSpec> &Specs,
161
+ uint32_t BitWidth) const ;
162
+
163
+ // Attempts to set the specification for the given type.
164
+ // Returns an error description on failure.
165
+ Error setPrimitiveSpec (PrimitiveSpecifier Specifier, uint32_t BitWidth,
166
+ Align ABIAlign, Align PrefAlign);
167
+
168
+ // Searches for a pointer specification that matches the given address space.
169
+ // Returns the default address space specification if not found.
170
+ const PointerSpec &getPointerSpec (uint32_t AddressSpace) const ;
166
171
167
- // / Attempts to set the alignment of a pointer in the given address space.
168
- // / Returns an error description on failure.
169
- Error setPointerAlignmentInBits (uint32_t AddrSpace, Align ABIAlign,
170
- Align PrefAlign, uint32_t TypeBitWidth,
171
- uint32_t IndexBitWidth);
172
+ // Attempts to set the specification for pointer in the given address space.
173
+ // Returns an error description on failure.
174
+ Error setPointerSpec (uint32_t AddrSpace, uint32_t TypeBitWidth,
175
+ Align ABIAlign, Align PrefAlign, uint32_t IndexBitWidth);
172
176
173
177
// / Internal helper to get alignment for integer of given bitwidth.
174
178
Align getIntegerAlignment (uint32_t BitWidth, bool abi_or_pref) const ;
@@ -375,7 +379,7 @@ class DataLayout {
375
379
// / FIXME: The defaults need to be removed once all of
376
380
// / the backends/clients are updated.
377
381
unsigned getPointerSizeInBits (unsigned AS = 0 ) const {
378
- return getPointerAlignElem (AS).TypeBitWidth ;
382
+ return getPointerSpec (AS).TypeBitWidth ;
379
383
}
380
384
381
385
// / Returns the maximum index size over all address spaces.
@@ -385,7 +389,7 @@ class DataLayout {
385
389
386
390
// / Size in bits of index used for address calculation in getelementptr.
387
391
unsigned getIndexSizeInBits (unsigned AS) const {
388
- return getPointerAlignElem (AS).IndexBitWidth ;
392
+ return getPointerSpec (AS).IndexBitWidth ;
389
393
}
390
394
391
395
// / Layout pointer size, in bits, based on the type. If this function is
0 commit comments