@@ -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
// /
@@ -94,6 +62,26 @@ struct PointerAlignElem {
94
62
// / target being codegen'd to.
95
63
class DataLayout {
96
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 AddressSpace;
77
+ uint32_t BitWidth;
78
+ Align ABIAlign;
79
+ Align PrefAlign;
80
+ uint32_t IndexBitWidth;
81
+
82
+ bool operator ==(const PointerSpec &Other) const ;
83
+ };
84
+
97
85
enum class FunctionPtrAlignType {
98
86
// / The function pointer alignment is independent of the function alignment.
99
87
Independent,
@@ -127,19 +115,26 @@ class DataLayout {
127
115
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
128
116
SmallVector<unsigned char , 8 > LegalIntWidths;
129
117
118
+ // Primitive type specifier.
119
+ enum class PrimitiveSpecifier {
120
+ Integer = ' i' ,
121
+ Float = ' f' ,
122
+ Vector = ' v' ,
123
+ // TODO: Aggregates are not primitives. This should be separated.
124
+ Aggregate = ' a'
125
+ };
126
+
130
127
// Primitive type specifications. Sorted and uniqued by type bit width.
131
- SmallVector<LayoutAlignElem , 6 > IntAlignments ;
132
- SmallVector<LayoutAlignElem , 4 > FloatAlignments ;
133
- SmallVector<LayoutAlignElem , 10 > VectorAlignments ;
128
+ SmallVector<PrimitiveSpec , 6 > IntSpecs ;
129
+ SmallVector<PrimitiveSpec , 4 > FloatSpecs ;
130
+ SmallVector<PrimitiveSpec , 10 > VectorSpecs ;
134
131
135
132
// Pointer type specifications. Sorted and uniqued by address space number.
136
- SmallVector<PointerAlignElem , 8 > Pointers ;
133
+ SmallVector<PointerSpec , 8 > PointerSpecs ;
137
134
138
135
// / The string representation used to create this DataLayout
139
136
std::string StringRepresentation;
140
137
141
- const PointerAlignElem &getPointerAlignElem (uint32_t AddressSpace) const ;
142
-
143
138
// Struct type ABI and preferred alignments. The default spec is "a:8:64".
144
139
Align StructABIAlignment = Align::Constant<1 >();
145
140
Align StructPrefAlignment = Align::Constant<8 >();
@@ -151,16 +146,19 @@ class DataLayout {
151
146
// / well-defined bitwise representation.
152
147
SmallVector<unsigned , 8 > NonIntegralAddressSpaces;
153
148
154
- // / Attempts to set the alignment of the given type. Returns an error
155
- // / description on failure.
156
- Error setAlignment (AlignTypeEnum AlignType, Align ABIAlign, Align PrefAlign,
157
- uint32_t BitWidth);
149
+ // Attempts to set the specification for the given type.
150
+ // Returns an error description on failure.
151
+ Error setPrimitiveSpec (PrimitiveSpecifier Specifier, uint32_t BitWidth,
152
+ Align ABIAlign, Align PrefAlign);
153
+
154
+ // Searches for a pointer specification that matches the given address space.
155
+ // Returns the default address space specification if not found.
156
+ const PointerSpec &getPointerSpec (uint32_t Spec) const ;
158
157
159
- // / Attempts to set the alignment of a pointer in the given address space.
160
- // / Returns an error description on failure.
161
- Error setPointerAlignmentInBits (uint32_t AddrSpace, Align ABIAlign,
162
- Align PrefAlign, uint32_t TypeBitWidth,
163
- uint32_t IndexBitWidth);
158
+ // Attempts to set the specification for pointer in the given address space.
159
+ // Returns an error description on failure.
160
+ Error setPointerSpec (uint32_t AddrSpace, uint32_t TypeBitWidth,
161
+ Align ABIAlign, Align PrefAlign, uint32_t IndexBitWidth);
164
162
165
163
// / Internal helper to get alignment for integer of given bitwidth.
166
164
Align getIntegerAlignment (uint32_t BitWidth, bool abi_or_pref) const ;
@@ -367,7 +365,7 @@ class DataLayout {
367
365
// / FIXME: The defaults need to be removed once all of
368
366
// / the backends/clients are updated.
369
367
unsigned getPointerSizeInBits (unsigned AS = 0 ) const {
370
- return getPointerAlignElem (AS).TypeBitWidth ;
368
+ return getPointerSpec (AS).BitWidth ;
371
369
}
372
370
373
371
// / Returns the maximum index size over all address spaces.
@@ -377,7 +375,7 @@ class DataLayout {
377
375
378
376
// / Size in bits of index used for address calculation in getelementptr.
379
377
unsigned getIndexSizeInBits (unsigned AS) const {
380
- return getPointerAlignElem (AS).IndexBitWidth ;
378
+ return getPointerSpec (AS).IndexBitWidth ;
381
379
}
382
380
383
381
// / Layout pointer size, in bits, based on the type. If this function is
0 commit comments