Skip to content

Commit 3093750

Browse files
committed
[DataLayout] Move '*AlignElem' structs and enum inside DataLayout (NFC)
1 parent 7df4e25 commit 3093750

File tree

2 files changed

+149
-150
lines changed

2 files changed

+149
-150
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -49,43 +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-
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-
8957
/// A parsed version of the target data layout string in and methods for
9058
/// querying it.
9159
///
@@ -94,6 +62,26 @@ struct PointerAlignElem {
9462
/// target being codegen'd to.
9563
class DataLayout {
9664
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+
9785
enum class FunctionPtrAlignType {
9886
/// The function pointer alignment is independent of the function alignment.
9987
Independent,
@@ -127,19 +115,26 @@ class DataLayout {
127115
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
128116
SmallVector<unsigned char, 8> LegalIntWidths;
129117

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+
130127
// 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;
134131

135132
// Pointer type specifications. Sorted and uniqued by address space number.
136-
SmallVector<PointerAlignElem, 8> Pointers;
133+
SmallVector<PointerSpec, 8> PointerSpecs;
137134

138135
/// The string representation used to create this DataLayout
139136
std::string StringRepresentation;
140137

141-
const PointerAlignElem &getPointerAlignElem(uint32_t AddressSpace) const;
142-
143138
// Struct type ABI and preferred alignments. The default spec is "a:8:64".
144139
Align StructABIAlignment = Align::Constant<1>();
145140
Align StructPrefAlignment = Align::Constant<8>();
@@ -151,16 +146,19 @@ class DataLayout {
151146
/// well-defined bitwise representation.
152147
SmallVector<unsigned, 8> NonIntegralAddressSpaces;
153148

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

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);
164162

165163
/// Internal helper to get alignment for integer of given bitwidth.
166164
Align getIntegerAlignment(uint32_t BitWidth, bool abi_or_pref) const;
@@ -367,7 +365,7 @@ class DataLayout {
367365
/// FIXME: The defaults need to be removed once all of
368366
/// the backends/clients are updated.
369367
unsigned getPointerSizeInBits(unsigned AS = 0) const {
370-
return getPointerAlignElem(AS).TypeBitWidth;
368+
return getPointerSpec(AS).BitWidth;
371369
}
372370

373371
/// Returns the maximum index size over all address spaces.
@@ -377,7 +375,7 @@ class DataLayout {
377375

378376
/// Size in bits of index used for address calculation in getelementptr.
379377
unsigned getIndexSizeInBits(unsigned AS) const {
380-
return getPointerAlignElem(AS).IndexBitWidth;
378+
return getPointerSpec(AS).IndexBitWidth;
381379
}
382380

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

0 commit comments

Comments
 (0)