Skip to content

[GlobalISel] Introduce LLT:token() as a special scalar type #85189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions llvm/include/llvm/CodeGenTypes/LowLevelType.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/CodeGen/LowLevelTypeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
return LLT::scalar(SizeInBits);
}

if (Ty.isTokenTy())
return LLT::token();

return LLT();
}

Expand Down
22 changes: 22 additions & 0 deletions llvm/unittests/CodeGen/LowLevelTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down