Skip to content

Commit 32a067c

Browse files
authored
[GlobalISel] Introduce LLT:token() as a special scalar type (#85189)
The new token type is used in #67006 for implementing convergence control tokens in GMIR.
1 parent e8e8df4 commit 32a067c

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

llvm/include/llvm/CodeGenTypes/LowLevelType.h

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class LLT {
4545
/*AddressSpace=*/0};
4646
}
4747

48+
/// Get a low-level token; just a scalar with zero bits (or no size).
49+
static constexpr LLT token() {
50+
return LLT{/*isPointer=*/false, /*isVector=*/false,
51+
/*isScalar=*/true, ElementCount::getFixed(0),
52+
/*SizeInBits=*/0,
53+
/*AddressSpace=*/0};
54+
}
55+
4856
/// Get a low-level pointer in the given address space.
4957
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits) {
5058
assert(SizeInBits > 0 && "invalid pointer size");
@@ -134,17 +142,17 @@ class LLT {
134142

135143
explicit LLT(MVT VT);
136144

137-
constexpr bool isValid() const { return IsScalar || IsPointer || IsVector; }
138-
145+
constexpr bool isValid() const { return IsScalar || RawData != 0; }
139146
constexpr bool isScalar() const { return IsScalar; }
140-
141-
constexpr bool isPointer() const { return IsPointer && !IsVector; }
142-
143-
constexpr bool isPointerVector() const { return IsPointer && IsVector; }
144-
145-
constexpr bool isPointerOrPointerVector() const { return IsPointer; }
146-
147-
constexpr bool isVector() const { return IsVector; }
147+
constexpr bool isToken() const { return IsScalar && RawData == 0; };
148+
constexpr bool isVector() const { return isValid() && IsVector; }
149+
constexpr bool isPointer() const {
150+
return isValid() && IsPointer && !IsVector;
151+
}
152+
constexpr bool isPointerVector() const { return IsPointer && isVector(); }
153+
constexpr bool isPointerOrPointerVector() const {
154+
return IsPointer && isValid();
155+
}
148156

149157
/// Returns the number of elements in a vector LLT. Must only be called on
150158
/// vector types.
@@ -314,6 +322,28 @@ class LLT {
314322
/// described in static const *Field variables. Each of these variables
315323
/// is a 2-element array, with the first element describing the bitfield size
316324
/// and the second element describing the bitfield offset.
325+
///
326+
/// +--------+---------+--------+----------+----------------------+
327+
/// |isScalar|isPointer|isVector| RawData |Notes |
328+
/// +--------+---------+--------+----------+----------------------+
329+
/// | 0 | 0 | 0 | 0 |Invalid |
330+
/// +--------+---------+--------+----------+----------------------+
331+
/// | 0 | 0 | 1 | 0 |Tombstone Key |
332+
/// +--------+---------+--------+----------+----------------------+
333+
/// | 0 | 1 | 0 | 0 |Empty Key |
334+
/// +--------+---------+--------+----------+----------------------+
335+
/// | 1 | 0 | 0 | 0 |Token |
336+
/// +--------+---------+--------+----------+----------------------+
337+
/// | 1 | 0 | 0 | non-zero |Scalar |
338+
/// +--------+---------+--------+----------+----------------------+
339+
/// | 0 | 1 | 0 | non-zero |Pointer |
340+
/// +--------+---------+--------+----------+----------------------+
341+
/// | 0 | 0 | 1 | non-zero |Vector of non-pointer |
342+
/// +--------+---------+--------+----------+----------------------+
343+
/// | 0 | 1 | 1 | non-zero |Vector of pointer |
344+
/// +--------+---------+--------+----------+----------------------+
345+
///
346+
/// Everything else is reserved.
317347
typedef int BitFieldInfo[2];
318348
///
319349
/// This is how the bitfields are packed per Kind:

llvm/lib/CodeGen/LowLevelTypeUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
3939
return LLT::scalar(SizeInBits);
4040
}
4141

42+
if (Ty.isTokenTy())
43+
return LLT::token();
44+
4245
return LLT();
4346
}
4447

llvm/unittests/CodeGen/LowLevelTypeTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ using namespace llvm;
1818

1919
namespace {
2020

21+
TEST(LowLevelTypeTest, Token) {
22+
LLVMContext C;
23+
DataLayout DL("");
24+
25+
const LLT TTy = LLT::token();
26+
27+
// Test kind.
28+
EXPECT_TRUE(TTy.isValid());
29+
EXPECT_TRUE(TTy.isScalar());
30+
EXPECT_TRUE(TTy.isToken());
31+
32+
EXPECT_FALSE(TTy.isPointer());
33+
EXPECT_FALSE(TTy.isVector());
34+
35+
const LLT STy = LLT::scalar(0);
36+
EXPECT_EQ(STy, TTy);
37+
}
38+
2139
TEST(LowLevelTypeTest, Scalar) {
2240
LLVMContext C;
2341
DataLayout DL("");
@@ -32,6 +50,8 @@ TEST(LowLevelTypeTest, Scalar) {
3250
ASSERT_FALSE(Ty.isPointer());
3351
ASSERT_FALSE(Ty.isVector());
3452

53+
EXPECT_TRUE(S != 0 || Ty.isToken());
54+
3555
// Test sizes.
3656
EXPECT_EQ(S, Ty.getSizeInBits());
3757
EXPECT_EQ(S, Ty.getScalarSizeInBits());
@@ -77,6 +97,7 @@ TEST(LowLevelTypeTest, Vector) {
7797

7898
ASSERT_FALSE(VTy.isScalar());
7999
ASSERT_FALSE(VTy.isPointer());
100+
ASSERT_FALSE(VTy.isToken());
80101

81102
// Test sizes.
82103
EXPECT_EQ(S, VTy.getScalarSizeInBits());
@@ -300,6 +321,7 @@ TEST(LowLevelTypeTest, Invalid) {
300321
ASSERT_FALSE(Ty.isScalar());
301322
ASSERT_FALSE(Ty.isPointer());
302323
ASSERT_FALSE(Ty.isVector());
324+
ASSERT_FALSE(Ty.isToken());
303325
}
304326

305327
TEST(LowLevelTypeTest, Divide) {

0 commit comments

Comments
 (0)