@@ -49,51 +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
- static LayoutAlignElem get (Align ABIAlign, Align PrefAlign,
74
- uint32_t BitWidth);
75
-
76
- bool operator ==(const LayoutAlignElem &rhs) const ;
77
- };
78
-
79
- // / Layout pointer alignment element.
80
- // /
81
- // / Stores the alignment data associated with a given pointer and address space.
82
- struct PointerAlignElem {
83
- uint32_t AddressSpace;
84
- uint32_t TypeBitWidth;
85
- Align ABIAlign;
86
- Align PrefAlign;
87
- uint32_t IndexBitWidth;
88
-
89
- // / Initializer
90
- static PointerAlignElem getInBits (uint32_t AddressSpace, Align ABIAlign,
91
- Align PrefAlign, uint32_t TypeBitWidth,
92
- uint32_t IndexBitWidth);
93
-
94
- bool operator ==(const PointerAlignElem &rhs) const ;
95
- };
96
-
97
57
// / A parsed version of the target data layout string in and methods for
98
58
// / querying it.
99
59
// /
@@ -102,6 +62,26 @@ struct PointerAlignElem {
102
62
// / target being codegen'd to.
103
63
class DataLayout {
104
64
public:
65
+ // / Primitive type specification.
66
+ struct PrimitiveSpec {
67
+ uint32_t BitWidth;
68
+ Align ABIAlign;
69
+ Align PrefAlign;
70
+
71
+ bool operator ==(const PrimitiveSpec &Other) const ;
72
+ };
73
+
74
+ // / Pointer type specification.
75
+ struct PointerSpec {
76
+ uint32_t AddrSpace;
77
+ uint32_t BitWidth;
78
+ Align ABIAlign;
79
+ Align PrefAlign;
80
+ uint32_t IndexBitWidth;
81
+
82
+ bool operator ==(const PointerSpec &Other) const ;
83
+ };
84
+
105
85
enum class FunctionPtrAlignType {
106
86
// / The function pointer alignment is independent of the function alignment.
107
87
Independent,
@@ -135,20 +115,26 @@ class DataLayout {
135
115
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
136
116
SmallVector<unsigned char , 8 > LegalIntWidths;
137
117
138
- // 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;
118
+ // / Type specifier used by some internal functions.
119
+ enum class TypeSpecifier {
120
+ Integer = ' i' ,
121
+ Float = ' f' ,
122
+ Vector = ' v' ,
123
+ Aggregate = ' a'
124
+ };
142
125
143
- // Pointer type specifications. Sorted and uniqued by address space number.
144
- SmallVector<PointerAlignElem, 8 > Pointers;
126
+ // / Primitive type specifications. Sorted and uniqued by type bit width.
127
+ SmallVector<PrimitiveSpec, 6 > IntSpecs;
128
+ SmallVector<PrimitiveSpec, 4 > FloatSpecs;
129
+ SmallVector<PrimitiveSpec, 10 > VectorSpecs;
130
+
131
+ // / Pointer type specifications. Sorted and uniqued by address space number.
132
+ SmallVector<PointerSpec, 8 > PointerSpecs;
145
133
146
134
// / The string representation used to create this DataLayout
147
135
std::string StringRepresentation;
148
136
149
- const PointerAlignElem &getPointerAlignElem (uint32_t AddressSpace) const ;
150
-
151
- // Struct type ABI and preferred alignments. The default spec is "a:8:64".
137
+ // / Struct type ABI and preferred alignments. The default spec is "a:8:64".
152
138
Align StructABIAlignment = Align::Constant<1 >();
153
139
Align StructPrefAlignment = Align::Constant<8 >();
154
140
@@ -159,16 +145,19 @@ class DataLayout {
159
145
// / well-defined bitwise representation.
160
146
SmallVector<unsigned , 8 > NonIntegralAddressSpaces;
161
147
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);
148
+ // / Attempts to set the specification for the given type.
149
+ // / Returns an error description on failure.
150
+ Error setPrimitiveSpec (TypeSpecifier Specifier, uint32_t BitWidth,
151
+ Align ABIAlign, Align PrefAlign);
152
+
153
+ // / Searches for a pointer specification that matches the given address space.
154
+ // / Returns the default address space specification if not found.
155
+ const PointerSpec &getPointerSpec (uint32_t AddrSpace) const ;
166
156
167
- // / Attempts to set the alignment of a pointer in the given address space.
157
+ // / Attempts to set the specification for pointer in the given address space.
168
158
// / Returns an error description on failure.
169
- Error setPointerAlignmentInBits (uint32_t AddrSpace, Align ABIAlign,
170
- Align PrefAlign, uint32_t TypeBitWidth,
171
- uint32_t IndexBitWidth);
159
+ Error setPointerSpec (uint32_t AddrSpace, uint32_t BitWidth, Align ABIAlign,
160
+ Align PrefAlign, uint32_t IndexBitWidth);
172
161
173
162
// / Internal helper to get alignment for integer of given bitwidth.
174
163
Align getIntegerAlignment (uint32_t BitWidth, bool abi_or_pref) const ;
@@ -375,7 +364,7 @@ class DataLayout {
375
364
// / FIXME: The defaults need to be removed once all of
376
365
// / the backends/clients are updated.
377
366
unsigned getPointerSizeInBits (unsigned AS = 0 ) const {
378
- return getPointerAlignElem (AS).TypeBitWidth ;
367
+ return getPointerSpec (AS).BitWidth ;
379
368
}
380
369
381
370
// / Returns the maximum index size over all address spaces.
@@ -385,7 +374,7 @@ class DataLayout {
385
374
386
375
// / Size in bits of index used for address calculation in getelementptr.
387
376
unsigned getIndexSizeInBits (unsigned AS) const {
388
- return getPointerAlignElem (AS).IndexBitWidth ;
377
+ return getPointerSpec (AS).IndexBitWidth ;
389
378
}
390
379
391
380
// / Layout pointer size, in bits, based on the type. If this function is
0 commit comments