[llvm] [GlobalISel] Introduce LLT:token() as a special scalar type (PR #85189)
Sameer Sahasrabuddhe via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 23:55:59 PDT 2024
https://github.com/ssahasra created https://github.com/llvm/llvm-project/pull/85189
The new token type is used in #67006 for implementing convergence control tokens in GMIR.
>From 788944cd47533580cc3df6535725a0982027922d Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
Date: Thu, 14 Mar 2024 12:12:50 +0530
Subject: [PATCH] [GlobalISel] Introduce LLT:token() as a special scalar type
The new token type is used in #67006 for implementing convergence control tokens
in GMIR.
---
llvm/include/llvm/CodeGenTypes/LowLevelType.h | 50 +++++++++++++++----
llvm/lib/CodeGen/LowLevelTypeUtils.cpp | 4 ++
llvm/unittests/CodeGen/LowLevelTypeTest.cpp | 26 ++++++++++
3 files changed, 70 insertions(+), 10 deletions(-)
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..3499fe1ee75776 100644
--- a/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
+++ b/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
@@ -39,6 +39,10 @@ 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..3a6ee6120c4d22 100644
--- a/llvm/unittests/CodeGen/LowLevelTypeTest.cpp
+++ b/llvm/unittests/CodeGen/LowLevelTypeTest.cpp
@@ -18,6 +18,28 @@ using namespace llvm;
namespace {
+TEST(LowLevelTypeTest, Token) {
+ LLVMContext C;
+ DataLayout DL("");
+
+ const LLT TTy = LLT::token();
+
+ // Test kind.
+ ASSERT_TRUE(TTy.isValid());
+ ASSERT_TRUE(TTy.isScalar());
+ ASSERT_TRUE(TTy.isToken());
+
+ ASSERT_FALSE(TTy.isPointer());
+ ASSERT_FALSE(TTy.isVector());
+
+ const LLT STy = LLT::scalar(0);
+ ASSERT_TRUE(STy == TTy);
+
+ // Test equality operators.
+ EXPECT_TRUE(TTy == TTy);
+ EXPECT_FALSE(TTy != TTy);
+}
+
TEST(LowLevelTypeTest, Scalar) {
LLVMContext C;
DataLayout DL("");
@@ -32,6 +54,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 +101,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 +325,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