Skip to content

Commit 66818ea

Browse files
committed
Address review comments
1 parent 61bc6b7 commit 66818ea

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,26 @@ class DataLayout {
115115
// FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
116116
SmallVector<unsigned char, 8> LegalIntWidths;
117117

118-
// Primitive type specifier.
119-
enum class PrimitiveSpecifier {
118+
/// Type specifier used by some internal functions.
119+
enum class TypeSpecifier {
120120
Integer = 'i',
121121
Float = 'f',
122122
Vector = 'v',
123-
// TODO: Aggregates are not primitives. This should be separated.
124123
Aggregate = 'a'
125124
};
126125

127-
// Primitive type specifications. Sorted and uniqued by type bit width.
126+
/// Primitive type specifications. Sorted and uniqued by type bit width.
128127
SmallVector<PrimitiveSpec, 6> IntSpecs;
129128
SmallVector<PrimitiveSpec, 4> FloatSpecs;
130129
SmallVector<PrimitiveSpec, 10> VectorSpecs;
131130

132-
// Pointer type specifications. Sorted and uniqued by address space number.
131+
/// Pointer type specifications. Sorted and uniqued by address space number.
133132
SmallVector<PointerSpec, 8> PointerSpecs;
134133

135134
/// The string representation used to create this DataLayout
136135
std::string StringRepresentation;
137136

138-
// 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".
139138
Align StructABIAlignment = Align::Constant<1>();
140139
Align StructPrefAlignment = Align::Constant<8>();
141140

@@ -146,17 +145,17 @@ class DataLayout {
146145
/// well-defined bitwise representation.
147146
SmallVector<unsigned, 8> NonIntegralAddressSpaces;
148147

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,
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,
152151
Align ABIAlign, Align PrefAlign);
153152

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

158-
// Attempts to set the specification for pointer in the given address space.
159-
// Returns an error description on failure.
157+
/// Attempts to set the specification for pointer in the given address space.
158+
/// Returns an error description on failure.
160159
Error setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth, Align ABIAlign,
161160
Align PrefAlign, uint32_t IndexBitWidth);
162161

llvm/lib/IR/DataLayout.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
326326
continue;
327327
}
328328

329-
char Specifier = Tok.front();
329+
char SpecifierChar = Tok.front();
330330
Tok = Tok.substr(1);
331331

332-
switch (Specifier) {
332+
switch (SpecifierChar) {
333333
case 's':
334334
// Deprecated, but ignoring here to preserve loading older textual llvm
335335
// ASM file
@@ -408,21 +408,21 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
408408
case 'v':
409409
case 'f':
410410
case 'a': {
411-
PrimitiveSpecifier PrimSpecifier;
412-
switch (Specifier) {
411+
TypeSpecifier Specifier;
412+
switch (SpecifierChar) {
413413
default:
414414
llvm_unreachable("Unexpected specifier!");
415415
case 'i':
416-
PrimSpecifier = PrimitiveSpecifier::Integer;
416+
Specifier = TypeSpecifier::Integer;
417417
break;
418418
case 'v':
419-
PrimSpecifier = PrimitiveSpecifier::Vector;
419+
Specifier = TypeSpecifier::Vector;
420420
break;
421421
case 'f':
422-
PrimSpecifier = PrimitiveSpecifier::Float;
422+
Specifier = TypeSpecifier::Float;
423423
break;
424424
case 'a':
425-
PrimSpecifier = PrimitiveSpecifier::Aggregate;
425+
Specifier = TypeSpecifier::Aggregate;
426426
break;
427427
}
428428

@@ -432,7 +432,7 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
432432
if (Error Err = getInt(Tok, Size))
433433
return Err;
434434

435-
if (PrimSpecifier == PrimitiveSpecifier::Aggregate && Size != 0)
435+
if (Specifier == TypeSpecifier::Aggregate && Size != 0)
436436
return reportError(
437437
"Sized aggregate specification in datalayout string");
438438

@@ -445,16 +445,15 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
445445
unsigned ABIAlign;
446446
if (Error Err = getIntInBytes(Tok, ABIAlign))
447447
return Err;
448-
if (PrimSpecifier != PrimitiveSpecifier::Aggregate && !ABIAlign)
448+
if (Specifier != TypeSpecifier::Aggregate && !ABIAlign)
449449
return reportError(
450450
"ABI alignment specification must be >0 for non-aggregate types");
451451

452452
if (!isUInt<16>(ABIAlign))
453453
return reportError("Invalid ABI alignment, must be a 16bit integer");
454454
if (ABIAlign != 0 && !isPowerOf2_64(ABIAlign))
455455
return reportError("Invalid ABI alignment, must be a power of 2");
456-
if (PrimSpecifier == PrimitiveSpecifier::Integer && Size == 8 &&
457-
ABIAlign != 1)
456+
if (Specifier == TypeSpecifier::Integer && Size == 8 && ABIAlign != 1)
458457
return reportError(
459458
"Invalid ABI alignment, i8 must be naturally aligned");
460459

@@ -473,9 +472,8 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
473472
if (PrefAlign != 0 && !isPowerOf2_64(PrefAlign))
474473
return reportError("Invalid preferred alignment, must be a power of 2");
475474

476-
if (Error Err =
477-
setPrimitiveSpec(PrimSpecifier, Size, assumeAligned(ABIAlign),
478-
assumeAligned(PrefAlign)))
475+
if (Error Err = setPrimitiveSpec(Specifier, Size, assumeAligned(ABIAlign),
476+
assumeAligned(PrefAlign)))
479477
return Err;
480478

481479
break;
@@ -592,9 +590,8 @@ findPrimitiveSpecLowerBound(
592590
});
593591
}
594592

595-
Error DataLayout::setPrimitiveSpec(PrimitiveSpecifier Specifier,
596-
uint32_t BitWidth, Align ABIAlign,
597-
Align PrefAlign) {
593+
Error DataLayout::setPrimitiveSpec(TypeSpecifier Specifier, uint32_t BitWidth,
594+
Align ABIAlign, Align PrefAlign) {
598595
// AlignmentsTy::ABIAlign and AlignmentsTy::PrefAlign were once stored as
599596
// uint16_t, it is unclear if there are requirements for alignment to be less
600597
// than 2^16 other than storage. In the meantime we leave the restriction as
@@ -608,17 +605,17 @@ Error DataLayout::setPrimitiveSpec(PrimitiveSpecifier Specifier,
608605

609606
SmallVectorImpl<PrimitiveSpec> *Specs;
610607
switch (Specifier) {
611-
case PrimitiveSpecifier::Aggregate:
608+
case TypeSpecifier::Aggregate:
612609
StructABIAlignment = ABIAlign;
613610
StructPrefAlignment = PrefAlign;
614611
return Error::success();
615-
case PrimitiveSpecifier::Integer:
612+
case TypeSpecifier::Integer:
616613
Specs = &IntSpecs;
617614
break;
618-
case PrimitiveSpecifier::Float:
615+
case TypeSpecifier::Float:
619616
Specs = &FloatSpecs;
620617
break;
621-
case PrimitiveSpecifier::Vector:
618+
case TypeSpecifier::Vector:
622619
Specs = &VectorSpecs;
623620
break;
624621
}

0 commit comments

Comments
 (0)