[llvm] 32a067c - [GlobalISel] Introduce LLT:token() as a special scalar type (#85189)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 14 21:47:53 PDT 2024
Author: Sameer Sahasrabuddhe
Date: 2024-03-15T10:17:50+05:30
New Revision: 32a067c068f9ac285cf98be3154c8f1909fa2b21
URL: https://github.com/llvm/llvm-project/commit/32a067c068f9ac285cf98be3154c8f1909fa2b21
DIFF: https://github.com/llvm/llvm-project/commit/32a067c068f9ac285cf98be3154c8f1909fa2b21.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/CodeGenTypes/LowLevelType.h
llvm/lib/CodeGen/LowLevelTypeUtils.cpp
llvm/unittests/CodeGen/LowLevelTypeTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGenTypes/LowLevelType.h b/llvm/include/llvm/CodeGenTypes/LowLevelType.h
index 5a16cffb80b32b..62ee28cfac99c5 100644
--- a/llvm/include/llvm/CodeGenTypes/LowLevelType.h
+++ b/llvm/include/llvm/CodeGenTypes/LowLevelType.h
@@ -45,6 +45,14 @@ class LLT {
/*AddressSpace=*/0};
}
+ /// Get a low-level token; just a scalar with zero bits (or no size).
+ static constexpr LLT token() {
+ return LLT{/*isPointer=*/false, /*isVector=*/false,
+ /*isScalar=*/true, ElementCount::getFixed(0),
+ /*SizeInBits=*/0,
+ /*AddressSpace=*/0};
+ }
+
/// Get a low-level pointer in the given address space.
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits) {
assert(SizeInBits > 0 && "invalid pointer size");
@@ -134,17 +142,17 @@ class LLT {
explicit LLT(MVT VT);
- constexpr bool isValid() const { return IsScalar || IsPointer || IsVector; }
-
+ constexpr bool isValid() const { return IsScalar || RawData != 0; }
constexpr bool isScalar() const { return IsScalar; }
-
- constexpr bool isPointer() const { return IsPointer && !IsVector; }
-
- constexpr bool isPointerVector() const { return IsPointer && IsVector; }
-
- constexpr bool isPointerOrPointerVector() const { return IsPointer; }
-
- constexpr bool isVector() const { return IsVector; }
+ constexpr bool isToken() const { return IsScalar && RawData == 0; };
+ constexpr bool isVector() const { return isValid() && IsVector; }
+ constexpr bool isPointer() const {
+ return isValid() && IsPointer && !IsVector;
+ }
+ constexpr bool isPointerVector() const { return IsPointer && isVector(); }
+ constexpr bool isPointerOrPointerVector() const {
+ return IsPointer && isValid();
+ }
/// Returns the number of elements in a vector LLT. Must only be called on
/// vector types.
@@ -314,6 +322,28 @@ class LLT {
/// described in static const *Field variables. Each of these variables
/// is a 2-element array, with the first element describing the bitfield size
/// and the second element describing the bitfield offset.
+ ///
+ /// +--------+---------+--------+----------+----------------------+
+ /// |isScalar|isPointer|isVector| RawData |Notes |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 0 | 0 | 0 | 0 |Invalid |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 0 | 0 | 1 | 0 |Tombstone Key |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 0 | 1 | 0 | 0 |Empty Key |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 1 | 0 | 0 | 0 |Token |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 1 | 0 | 0 | non-zero |Scalar |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 0 | 1 | 0 | non-zero |Pointer |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 0 | 0 | 1 | non-zero |Vector of non-pointer |
+ /// +--------+---------+--------+----------+----------------------+
+ /// | 0 | 1 | 1 | non-zero |Vector of pointer |
+ /// +--------+---------+--------+----------+----------------------+
+ ///
+ /// Everything else is reserved.
typedef int BitFieldInfo[2];
///
/// This is how the bitfields are packed per Kind:
diff --git a/llvm/lib/CodeGen/LowLevelTypeUtils.cpp b/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
index bc2ea3f05b6da6..5caf20add2a11e 100644
--- a/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
+++ b/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
@@ -39,6 +39,9 @@ LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
return LLT::scalar(SizeInBits);
}
+ if (Ty.isTokenTy())
+ return LLT::token();
+
return LLT();
}
diff --git a/llvm/unittests/CodeGen/LowLevelTypeTest.cpp b/llvm/unittests/CodeGen/LowLevelTypeTest.cpp
index cb34802a5de271..b60d82b529fa3f 100644
--- a/llvm/unittests/CodeGen/LowLevelTypeTest.cpp
+++ b/llvm/unittests/CodeGen/LowLevelTypeTest.cpp
@@ -18,6 +18,24 @@ using namespace llvm;
namespace {
+TEST(LowLevelTypeTest, Token) {
+ LLVMContext C;
+ DataLayout DL("");
+
+ const LLT TTy = LLT::token();
+
+ // Test kind.
+ EXPECT_TRUE(TTy.isValid());
+ EXPECT_TRUE(TTy.isScalar());
+ EXPECT_TRUE(TTy.isToken());
+
+ EXPECT_FALSE(TTy.isPointer());
+ EXPECT_FALSE(TTy.isVector());
+
+ const LLT STy = LLT::scalar(0);
+ EXPECT_EQ(STy, TTy);
+}
+
TEST(LowLevelTypeTest, Scalar) {
LLVMContext C;
DataLayout DL("");
@@ -32,6 +50,8 @@ TEST(LowLevelTypeTest, Scalar) {
ASSERT_FALSE(Ty.isPointer());
ASSERT_FALSE(Ty.isVector());
+ EXPECT_TRUE(S != 0 || Ty.isToken());
+
// Test sizes.
EXPECT_EQ(S, Ty.getSizeInBits());
EXPECT_EQ(S, Ty.getScalarSizeInBits());
@@ -77,6 +97,7 @@ TEST(LowLevelTypeTest, Vector) {
ASSERT_FALSE(VTy.isScalar());
ASSERT_FALSE(VTy.isPointer());
+ ASSERT_FALSE(VTy.isToken());
// Test sizes.
EXPECT_EQ(S, VTy.getScalarSizeInBits());
@@ -300,6 +321,7 @@ TEST(LowLevelTypeTest, Invalid) {
ASSERT_FALSE(Ty.isScalar());
ASSERT_FALSE(Ty.isPointer());
ASSERT_FALSE(Ty.isVector());
+ ASSERT_FALSE(Ty.isToken());
}
TEST(LowLevelTypeTest, Divide) {
More information about the llvm-commits
mailing list