[llvm] [CodeGen, CHERI] Add capability types to MVT. (PR #156616)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 08:03:06 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Owen Anderson (resistor)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/156616.diff
3 Files Affected:
- (modified) llvm/include/llvm/CodeGen/ValueTypes.td (+8)
- (modified) llvm/include/llvm/CodeGenTypes/MachineValueType.h (+6)
- (modified) llvm/utils/TableGen/Basic/VTEmitter.cpp (+2)
``````````diff
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.td b/llvm/include/llvm/CodeGen/ValueTypes.td
index b06158d85f510..0d6875dd1b36b 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,9 @@ 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
+
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("
``````````
</details>
https://github.com/llvm/llvm-project/pull/156616
More information about the llvm-commits
mailing list