Skip to content

Commit e1e47ac

Browse files
authored
[DataLayout] Move '*AlignElem' structs and enum inside DataLayout (NFC) (#103723)
This makes `LayoutAlignElem` / `PointerAlignElem` and `AlignTypeEnum` inner types of `DataLayout`. The types are also renamed to match their meaning (LangRef refers to them as "specification" and "specifier"). Pull Request: #103723
1 parent cf2e101 commit e1e47ac

File tree

2 files changed

+152
-190
lines changed

2 files changed

+152
-190
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,11 @@ class StructLayout;
4949
class Triple;
5050
class Value;
5151

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-
6052
// FIXME: Currently the DataLayout string carries a "preferred alignment"
6153
// for types. As the DataLayout is module/global, this should likely be
6254
// sunk down to an FTTI element that is queried rather than a global
6355
// preference.
6456

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-
9757
/// A parsed version of the target data layout string in and methods for
9858
/// querying it.
9959
///
@@ -102,6 +62,26 @@ struct PointerAlignElem {
10262
/// target being codegen'd to.
10363
class DataLayout {
10464
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+
10585
enum class FunctionPtrAlignType {
10686
/// The function pointer alignment is independent of the function alignment.
10787
Independent,
@@ -135,20 +115,26 @@ class DataLayout {
135115
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
136116
SmallVector<unsigned char, 8> LegalIntWidths;
137117

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+
};
142125

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;
145133

146134
/// The string representation used to create this DataLayout
147135
std::string StringRepresentation;
148136

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".
152138
Align StructABIAlignment = Align::Constant<1>();
153139
Align StructPrefAlignment = Align::Constant<8>();
154140

@@ -159,16 +145,19 @@ class DataLayout {
159145
/// well-defined bitwise representation.
160146
SmallVector<unsigned, 8> NonIntegralAddressSpaces;
161147

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;
166156

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.
168158
/// 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);
172161

173162
/// Internal helper to get alignment for integer of given bitwidth.
174163
Align getIntegerAlignment(uint32_t BitWidth, bool abi_or_pref) const;
@@ -375,7 +364,7 @@ class DataLayout {
375364
/// FIXME: The defaults need to be removed once all of
376365
/// the backends/clients are updated.
377366
unsigned getPointerSizeInBits(unsigned AS = 0) const {
378-
return getPointerAlignElem(AS).TypeBitWidth;
367+
return getPointerSpec(AS).BitWidth;
379368
}
380369

381370
/// Returns the maximum index size over all address spaces.
@@ -385,7 +374,7 @@ class DataLayout {
385374

386375
/// Size in bits of index used for address calculation in getelementptr.
387376
unsigned getIndexSizeInBits(unsigned AS) const {
388-
return getPointerAlignElem(AS).IndexBitWidth;
377+
return getPointerSpec(AS).IndexBitWidth;
389378
}
390379

391380
/// Layout pointer size, in bits, based on the type. If this function is

0 commit comments

Comments
 (0)