Skip to content

Commit c0054e3

Browse files
committed
[DataLayout] Privatize and rename '*AlignElem' structs and enum (NFC)
1 parent d4640df commit c0054e3

File tree

2 files changed

+155
-151
lines changed

2 files changed

+155
-151
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 57 additions & 53 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
///
@@ -127,27 +95,54 @@ class DataLayout {
12795
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
12896
SmallVector<unsigned char, 8> LegalIntWidths;
12997

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

135132
// Default pointer type specifications.
136-
static const PointerAlignElem DefaultPointerSpecs[];
133+
static const PointerSpec DefaultPointerSpecs[];
137134

138135
// 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;
142139

143140
// Pointer type specifications. Sorted and uniqued by address space number.
144-
SmallVector<PointerAlignElem, 8> Pointers;
141+
SmallVector<PointerSpec, 8> PointerSpecs;
145142

146143
/// The string representation used to create this DataLayout
147144
std::string StringRepresentation;
148145

149-
const PointerAlignElem &getPointerAlignElem(uint32_t AddressSpace) const;
150-
151146
// Struct type ABI and preferred alignments. The default spec is "a:8:64".
152147
Align StructABIAlignment = Align::Constant<1>();
153148
Align StructPrefAlignment = Align::Constant<8>();
@@ -159,16 +154,25 @@ class DataLayout {
159154
/// well-defined bitwise representation.
160155
SmallVector<unsigned, 8> NonIntegralAddressSpaces;
161156

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

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

173177
/// Internal helper to get alignment for integer of given bitwidth.
174178
Align getIntegerAlignment(uint32_t BitWidth, bool abi_or_pref) const;
@@ -375,7 +379,7 @@ class DataLayout {
375379
/// FIXME: The defaults need to be removed once all of
376380
/// the backends/clients are updated.
377381
unsigned getPointerSizeInBits(unsigned AS = 0) const {
378-
return getPointerAlignElem(AS).TypeBitWidth;
382+
return getPointerSpec(AS).TypeBitWidth;
379383
}
380384

381385
/// Returns the maximum index size over all address spaces.
@@ -385,7 +389,7 @@ class DataLayout {
385389

386390
/// Size in bits of index used for address calculation in getelementptr.
387391
unsigned getIndexSizeInBits(unsigned AS) const {
388-
return getPointerAlignElem(AS).IndexBitWidth;
392+
return getPointerSpec(AS).IndexBitWidth;
389393
}
390394

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

0 commit comments

Comments
 (0)