[llvm] [CodeGen, CHERI] Add capability types to MVT. (PR #156616)
Owen Anderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 08:02:28 PDT 2025
https://github.com/resistor updated https://github.com/llvm/llvm-project/pull/156616
>From 23c082cf6a39166d2890a58ee9a7d2a3ef679856 Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Wed, 3 Sep 2025 16:13:47 +0800
Subject: [PATCH 1/2] [CodeGen, CHERI] Add capability types to MVT.
This adds value types for representing capability types, enabling their use in instruction selection and other parts of the backend.
These types are distinguished from each other only by size. This is sufficient, at least today, because no existing CHERI configuration supports multiple capability sizes simultaneously. Hybrid configurations supporting intermixed integral pointers and capabilities do exist, and are one of the reasons why these value types are needed beyond existing integral types.
Co-authored-by: David Chisnall <theraven at theravensnest.org>
Co-authored-by: Jessica Clarke <jrtc27 at jrtc27.com>
---
llvm/include/llvm/CodeGen/ValueTypes.td | 9 +++++++++
llvm/include/llvm/CodeGenTypes/MachineValueType.h | 6 ++++++
llvm/utils/TableGen/Basic/VTEmitter.cpp | 2 ++
3 files changed, 17 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.td b/llvm/include/llvm/CodeGen/ValueTypes.td
index b06158d85f510..adefa08be9c11 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.td
+++ b/llvm/include/llvm/CodeGen/ValueTypes.td
@@ -28,6 +28,7 @@ class ValueType<int size, int value> {
// Indicates this VT should be included in the
// [FIRST_VALUETYPE,LAST_VALUETYPE] range.
bit isNormalValueType = true;
+ bit isCapability = false;
}
class VTAny<int value> : ValueType<0, value> {
@@ -65,6 +66,10 @@ class VTVecTup<int size, int nf, ValueType dummy_elt, int value>
let isRISCVVecTuple = true;
}
+class VTCapability<int size, int value> : ValueType<size, value> {
+ let isCapability = true;
+}
+
defset list<ValueType> ValueTypes = {
def OtherVT : ValueType<0, 1> { // "Other" value
@@ -357,6 +362,10 @@ def amdgpuBufferStridedPointer : ValueType<192, 252>;
def aarch64mfp8 : ValueType<8, 253>; // 8-bit value in FPR (AArch64)
+def c64 : VTCapability<64, 254>; // 64-bit capability value
+def c128 : VTCapability<128, 255>; // 128-bit capability value
+def c256 : VTCapability<256, 256>; // 256-bit capability value
+
let isNormalValueType = false in {
def token : ValueType<0, 504>; // TokenTy
def MetadataVT : ValueType<0, 505> { // Metadata
diff --git a/llvm/include/llvm/CodeGenTypes/MachineValueType.h b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
index b8e91a022ec5e..b3ba1d7c3a568 100644
--- a/llvm/include/llvm/CodeGenTypes/MachineValueType.h
+++ b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
@@ -178,6 +178,12 @@ namespace llvm {
return (isFixedLengthVector() && getFixedSizeInBits() == 2048);
}
+ /// Return true if this is a capability type.
+ bool isCapability() const {
+ return (SimpleTy >= MVT::FIRST_CAPABILITY_VALUETYPE) &&
+ (SimpleTy <= MVT::LAST_CAPABILITY_VALUETYPE);
+ }
+
/// Return true if this is an overloaded type for TableGen.
bool isOverloaded() const {
switch (SimpleTy) {
diff --git a/llvm/utils/TableGen/Basic/VTEmitter.cpp b/llvm/utils/TableGen/Basic/VTEmitter.cpp
index 040f37c3a5e1e..53cb53296e7c2 100644
--- a/llvm/utils/TableGen/Basic/VTEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/VTEmitter.cpp
@@ -132,6 +132,7 @@ void VTEmitter::run(raw_ostream &OS) {
bool IsVector = VT->getValueAsBit("isVector");
bool IsScalable = VT->getValueAsBit("isScalable");
bool IsRISCVVecTuple = VT->getValueAsBit("isRISCVVecTuple");
+ bool IsCapability = VT->getValueAsBit("isCapability");
int64_t NF = VT->getValueAsInt("NF");
bool IsNormalValueType = VT->getValueAsBit("isNormalValueType");
int64_t NElem = IsVector ? VT->getValueAsInt("nElem") : 0;
@@ -152,6 +153,7 @@ void VTEmitter::run(raw_ostream &OS) {
UpdateVTRange("INTEGER_VALUETYPE", Name, IsInteger && !IsVector);
UpdateVTRange("FP_VALUETYPE", Name, IsFP && !IsVector);
UpdateVTRange("VALUETYPE", Name, IsNormalValueType);
+ UpdateVTRange("CAPABILITY_VALUETYPE", Name, IsCapability);
// clang-format off
OS << " GET_VT_ATTR("
>From 5304f54248b80c87d573f3be49bcd38525d3f17c Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Wed, 3 Sep 2025 23:01:52 +0800
Subject: [PATCH 2/2] Remove c256 per review consensus.
---
llvm/include/llvm/CodeGen/ValueTypes.td | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.td b/llvm/include/llvm/CodeGen/ValueTypes.td
index adefa08be9c11..0d6875dd1b36b 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.td
+++ b/llvm/include/llvm/CodeGen/ValueTypes.td
@@ -364,7 +364,6 @@ def aarch64mfp8 : ValueType<8, 253>; // 8-bit value in FPR (AArch64)
def c64 : VTCapability<64, 254>; // 64-bit capability value
def c128 : VTCapability<128, 255>; // 128-bit capability value
-def c256 : VTCapability<256, 256>; // 256-bit capability value
let isNormalValueType = false in {
def token : ValueType<0, 504>; // TokenTy
More information about the llvm-commits
mailing list