Skip to content

Commit e1f805c

Browse files
committed
Review fixes
1 parent f29a556 commit e1f805c

File tree

6 files changed

+87
-89
lines changed

6 files changed

+87
-89
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,12 @@ class LLVM_ABI TargetLoweringBase {
417417
/// amounts, returns MVT::i32.
418418
EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL) const;
419419

420-
virtual LLT getLLTForType(Type &Ty, const DataLayout &DL) const;
421-
virtual LLT getLLTForMVT(MVT Ty) const;
420+
/// Returns LLT for given Type, taking into account
421+
/// TargetOptions::EnableGlobalISelExtendedLLT.
422+
LLT getLLTForType(Type &Ty, const DataLayout &DL) const;
423+
/// Returns LLT for given MVT, taking into account
424+
/// TargetOptions::EnableGlobalISelExtendedLLT.
425+
LLT getLLTForMVT(MVT Ty) const;
422426

423427
/// Return the preferred type to use for a shift opcode, given the shifted
424428
/// amount type is \p ShiftValueTy.

llvm/include/llvm/CodeGenTypes/LowLevelType.h

Lines changed: 75 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@ class raw_ostream;
4040
class LLT {
4141
public:
4242
enum class FPVariant {
43-
IEEE_FLOAT = 0x0,
44-
BRAIN_FLOAT = 0x1, // BRAIN_FLOAT
45-
PPC128_FLOAT = 0x2, // PPC128_FLOAT
46-
EXTENDED_FP80 = 0x3, // FP80
47-
TENSOR_FLOAT32 = 0x4, // TENSOR_FLOAT32
48-
VARIANT_FLOAT_5 = 0x5, // UNASSIGNED
49-
VARIANT_FLOAT_6 = 0x6, // UNASSIGNED
50-
VARIANT_FLOAT_7 = 0x7, // UNASSIGNED
43+
IEEE_FLOAT,
44+
BF16, // BF16
45+
TENSOR_FLOAT32, // TENSOR_FLOAT32
46+
EXTENDED_FP80, // FP80
47+
PPC128_FLOAT, // PPC128_FLOAT
48+
VARIANT_FLOAT_5, // UNASSIGNED
49+
VARIANT_FLOAT_6, // UNASSIGNED
50+
VARIANT_FLOAT_7, // UNASSIGNED
5151
};
5252

53-
enum class Kind : uint64_t {
54-
INVALID = 0b0000,
55-
ANY_SCALAR = 0b0001,
56-
INTEGER = 0b0010,
57-
FLOAT = 0b0011,
58-
POINTER = 0b0100,
59-
VECTOR_ANY = 0b0101,
60-
VECTOR_INTEGER = 0b0110,
61-
VECTOR_FLOAT = 0b0111,
62-
VECTOR_POINTER = 0b1000,
53+
enum class Kind : uint8_t {
54+
INVALID,
55+
ANY_SCALAR,
56+
INTEGER,
57+
FLOAT,
58+
POINTER,
59+
VECTOR_ANY,
60+
VECTOR_INTEGER,
61+
VECTOR_FLOAT,
62+
VECTOR_POINTER,
6363
};
6464

6565
constexpr static Kind toVector(Kind Ty) {
@@ -136,15 +136,9 @@ class LLT {
136136
ScalarTy.isFloat() ? ScalarTy.getFPVariant()
137137
: static_cast<FPVariant>(0)};
138138
}
139-
// Get a 8-bit brain float value.
140-
static constexpr LLT bfloat8() {
141-
return floatingPoint(8, FPVariant::BRAIN_FLOAT);
142-
}
143139

144-
// Get a 16-bit brain float value.
145-
static constexpr LLT bfloat16() {
146-
return floatingPoint(16, FPVariant::BRAIN_FLOAT);
147-
}
140+
// Get a bfloat16 value.
141+
static constexpr LLT bfloat16() { return floatingPoint(16, FPVariant::BF16); }
148142

149143
/// Get a 16-bit IEEE half value.
150144
static constexpr LLT float16() {
@@ -231,7 +225,7 @@ class LLT {
231225
constexpr bool isScalar(unsigned Size) const {
232226
return isScalar() && getScalarSizeInBits() == Size;
233227
}
234-
constexpr bool isFloat() const { return isValid() && Info == Kind::FLOAT; }
228+
constexpr bool isFloat() const { return Info == Kind::FLOAT; }
235229
constexpr bool isFloat(unsigned Size) const {
236230
return isFloat() && getScalarSizeInBits() == Size;
237231
}
@@ -244,14 +238,12 @@ class LLT {
244238
constexpr bool isVariantFloat(unsigned Size, FPVariant Variant) const {
245239
return isVariantFloat(Variant) && getScalarSizeInBits() == Size;
246240
}
247-
constexpr bool isFloatVector() const {
248-
return isVector() && Info == Kind::VECTOR_FLOAT;
249-
}
241+
constexpr bool isFloatVector() const { return Info == Kind::VECTOR_FLOAT; }
250242
constexpr bool isIEEEFloat(unsigned Size) const {
251243
return isVariantFloat(Size, FPVariant::IEEE_FLOAT);
252244
}
253245
constexpr bool isBFloat(unsigned Size) const {
254-
return isVariantFloat(Size, FPVariant::BRAIN_FLOAT);
246+
return isVariantFloat(Size, FPVariant::BF16);
255247
}
256248
constexpr bool isX86FP80() const {
257249
return isVariantFloat(80, FPVariant::EXTENDED_FP80);
@@ -262,31 +254,22 @@ class LLT {
262254
constexpr bool isToken() const {
263255
return Info == Kind::ANY_SCALAR && RawData == 0;
264256
}
265-
constexpr bool isAnyScalar() const {
266-
return isValid() && Info == Kind::ANY_SCALAR;
267-
}
268-
constexpr bool isVectorAny() const {
269-
return isVector() && Info == Kind::VECTOR_ANY;
270-
}
271-
constexpr bool isInteger() const {
272-
return isValid() && Info == Kind::INTEGER;
273-
}
257+
constexpr bool isAnyScalar() const { return Info == Kind::ANY_SCALAR; }
258+
constexpr bool isVectorAny() const { return Info == Kind::VECTOR_ANY; }
259+
constexpr bool isInteger() const { return Info == Kind::INTEGER; }
274260
constexpr bool isInteger(unsigned Size) const {
275261
return isInteger() && getScalarSizeInBits() == Size;
276262
}
277263
constexpr bool isIntegerVector() const {
278-
return isVector() && Info == Kind::VECTOR_INTEGER;
264+
return Info == Kind::VECTOR_INTEGER;
279265
}
280266
constexpr bool isVector() const {
281-
return isValid() &&
282-
(Info == Kind::VECTOR_ANY || Info == Kind::VECTOR_INTEGER ||
283-
Info == Kind::VECTOR_FLOAT || Info == Kind::VECTOR_POINTER);
284-
}
285-
constexpr bool isPointer() const {
286-
return isValid() && Info == Kind::POINTER;
267+
return Info == Kind::VECTOR_ANY || Info == Kind::VECTOR_INTEGER ||
268+
Info == Kind::VECTOR_FLOAT || Info == Kind::VECTOR_POINTER;
287269
}
270+
constexpr bool isPointer() const { return Info == Kind::POINTER; }
288271
constexpr bool isPointerVector() const {
289-
return isVector() && Info == Kind::VECTOR_POINTER;
272+
return Info == Kind::VECTOR_POINTER;
290273
}
291274
constexpr bool isPointerOrPointerVector() const {
292275
return isPointer() || isPointerVector();
@@ -469,13 +452,13 @@ class LLT {
469452
#endif
470453

471454
constexpr bool operator==(const LLT &RHS) const {
472-
if (isAnyScalar() || RHS.isAnyScalar()) {
455+
if (isAnyScalar() || RHS.isAnyScalar())
473456
return isScalar() == RHS.isScalar() && RawData == RHS.RawData;
474-
}
475-
if (isVector() && RHS.isVector()) {
457+
458+
if (isVector() && RHS.isVector())
476459
return getElementType() == RHS.getElementType() &&
477460
getElementCount() == RHS.getElementCount();
478-
}
461+
479462
return Info == RHS.Info && RawData == RHS.RawData;
480463
}
481464

@@ -488,7 +471,7 @@ class LLT {
488471
/// LLT is packed into 64 bits as follows:
489472
/// Info : 4
490473
/// RawData : 60
491-
/// with 61 bits of RawData remaining for Kind-specific data, packed in
474+
/// with 60 bits of RawData remaining for Kind-specific data, packed in
492475
/// bitfields as described below. As there isn't a simple portable way to pack
493476
/// bits into bitfields, here the different fields in the packed structure is
494477
/// described in static const *Field variables. Each of these variables
@@ -509,38 +492,52 @@ class LLT {
509492
### (6)
510493
%%%% (7)
511494
512-
(1) ScalarSize (2) PointerSize (3) PointerAddressSpace
513-
(4) VectorElements (5) VectorScalable (6) FPVariant (7) Kind
495+
(1) ScalarSize: [63:32]
496+
(2) PointerSize: [63:48]
497+
(3) PointerAddressSpace: [47:24]
498+
(4) VectorElements: [23:8]
499+
(5) VectorScalable: [4:4]
500+
(6) FPVariant: [26:24]
501+
(7) Kind: [3:0]
514502
515503
*/
516-
typedef int BitFieldInfo[2];
517-
///
518-
/// This is how the bitfields are packed per Kind:
504+
505+
/// This is how the LLT are packed per Kind:
519506
/// * Invalid:
520-
/// gets encoded as RawData == 0, as that is an invalid encoding, since for
521-
/// valid encodings, SizeInBits/SizeOfElement must be larger than 0.
507+
/// Info: [3:0] = 0
508+
/// RawData: [63:4] = 0;
509+
///
522510
/// * Non-pointer scalar (isPointer == 0 && isVector == 0):
523-
/// SizeInBits: 32;
524-
/// FPInfoField: 3;
525-
static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 28};
526-
static const constexpr BitFieldInfo FPFieldInfo{3, 20};
511+
/// Info: [3:0];
512+
/// FPVariant: [26:24];
513+
/// SizeOfElement: [63:32];
514+
///
527515
/// * Pointer (isPointer == 1 && isVector == 0):
528-
/// SizeInBits: 16;
529-
/// AddressSpace: 24;
530-
static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 44};
531-
static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{24, 20};
516+
/// Info: [3:0];
517+
/// AddressSpace: [47:24];
518+
/// SizeInBits: [63:48];
519+
///
532520
/// * Vector-of-non-pointer (isPointer == 0 && isVector == 1):
533-
/// NumElements: 16;
534-
/// SizeOfElement: 32;
535-
/// FPInfoField: 3;
536-
/// Scalable: 1;
537-
static const constexpr BitFieldInfo VectorElementsFieldInfo{16, 4};
538-
static const constexpr BitFieldInfo VectorScalableFieldInfo{1, 0};
521+
/// Info: [3:0]
522+
/// Scalable: [4:4];
523+
/// VectorElements: [23:8];
524+
/// FPVariant: [26:24];
525+
/// SizeOfElement: [63:32];
526+
///
539527
/// * Vector-of-pointer (isPointer == 1 && isVector == 1):
540-
/// NumElements: 16;
541-
/// SizeOfElement: 16;
542-
/// AddressSpace: 24;
543-
/// Scalable: 1;
528+
/// Scalable: [4:4];
529+
/// VectorElements: [23:8];
530+
/// AddressSpace: [47:24];
531+
/// SizeInBits: [63:48];
532+
533+
/// BitFieldInfo: {Size, Offset}
534+
typedef int BitFieldInfo[2];
535+
static const constexpr BitFieldInfo VectorScalableFieldInfo{1, 0};
536+
static const constexpr BitFieldInfo VectorElementsFieldInfo{16, 4};
537+
static const constexpr BitFieldInfo FPFieldInfo{3, 20};
538+
static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{24, 20};
539+
static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 28};
540+
static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 44};
544541

545542
Kind Info : 4;
546543
uint64_t RawData : 60;

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,9 +3723,8 @@ bool IRTranslator::translate(const Constant &C, Register Reg) {
37233723
}
37243724

37253725
bool IRTranslator::mayTranslateUserTypes(const User &U) const {
3726-
if (TLI->getTargetMachine().Options.EnableGlobalISelExtendedLLT) {
3726+
if (TLI->getTargetMachine().Options.EnableGlobalISelExtendedLLT)
37273727
return true;
3728-
}
37293728

37303729
// BF16 cannot currently be represented by default LLT, to avoid miscompiles
37313730
// we prevent any instructions using them in targets with disabled

llvm/lib/CodeGen/LowLevelTypeUtils.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL, bool AllowExtendedLLT) {
6767
llvm_unreachable("Unhandled LLVM IR floating point type");
6868
}
6969

70-
if (Ty.isIntegerTy()) {
70+
if (Ty.isIntegerTy())
7171
return LLT::integer(SizeInBits);
72-
}
7372

7473
return LLT::scalar(SizeInBits);
7574
}
@@ -81,10 +80,9 @@ LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL, bool AllowExtendedLLT) {
8180
}
8281

8382
MVT llvm::getMVTForLLT(LLT Ty) {
84-
if (Ty.isVector()) {
83+
if (Ty.isVector())
8584
return MVT::getVectorVT(getMVTForLLT(Ty.getElementType()),
8685
Ty.getElementCount());
87-
}
8886

8987
if (Ty.isFloat()) {
9088
if (Ty == LLT::bfloat16())

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
19711971
if (Token.range().starts_with("f"))
19721972
FPVariant = LLT::FPVariant::IEEE_FLOAT;
19731973
else if (Token.range().starts_with("bf"))
1974-
FPVariant = LLT::FPVariant::BRAIN_FLOAT;
1974+
FPVariant = LLT::FPVariant::BF16;
19751975
else
19761976
return error("unknown floating point type identifier");
19771977

@@ -2053,7 +2053,7 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
20532053
auto ScalarSize = APSInt(VectorTyDigits).getZExtValue();
20542054
if (!verifyScalarSize(ScalarSize))
20552055
return error("invalid size for bfloat element in vector");
2056-
Ty = LLT::floatingPoint(ScalarSize, LLT::FPVariant::BRAIN_FLOAT);
2056+
Ty = LLT::floatingPoint(ScalarSize, LLT::FPVariant::BF16);
20572057
} else
20582058
return GetError();
20592059
lex();

llvm/lib/CodeGenTypes/LowLevelType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static std::optional<LLT::FPVariant> deriveFPInfo(MVT VT) {
2222

2323
switch (VT.getScalarType().SimpleTy) {
2424
case MVT::bf16:
25-
return LLT::FPVariant::BRAIN_FLOAT;
25+
return LLT::FPVariant::BF16;
2626
case MVT::f80:
2727
return LLT::FPVariant::EXTENDED_FP80;
2828
case MVT::ppcf128:

0 commit comments

Comments
 (0)