diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td index d40e43f4534c..8225650cda2d 100644 --- a/llvm/lib/Target/RISCV/RISCV.td +++ b/llvm/lib/Target/RISCV/RISCV.td @@ -180,6 +180,14 @@ def HasCheri : Predicate<"Subtarget->hasCheri()">, AssemblerPredicate<(all_of FeatureCheri), "CHERI Extension">; +def FeatureCheriMemVersion + : SubtargetFeature<"xcherimemversion", "HasCheriMemVersion", "true", + "Implements the CHERI extension with support for memory versioning">; +def HasCheriMemVersion + : Predicate<"Subtarget->hasCheriMemVersion()">, + AssemblerPredicate<(all_of FeatureCheriMemVersion), + "CHERI Extension with memory versioning">; + def FeatureCapMode : SubtargetFeature<"cap-mode", "IsCapMode", "true", "Capability mode">; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td index 513d22bd2515..3f5485576227 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td @@ -1554,3 +1554,26 @@ let Predicates = [HasCheri, IsRV64, IsCapMode] in { defm : CheriLdPat; defm : CheriStPat; } // Predicates = [HasCheri, IsRV64, IsCapMode] + + +/// CHERI memory colouring extensions +let Predicates = [HasCheri, HasCheriMemVersion] in { +def CGetVersion : Cheri_r<0x13, "cgetversion">; +def CSetVersion : Cheri_rr<0x2, "csetversion">; +let mayLoad = 1, mayStore = 0, hasSideEffects = 0 in { +def CLoadVersion : RVInstCheriSrcDst<0x7f, 0x16, 0, OPC_CHERI, (outs GPR:$rd), + (ins GPCRMemAtomic:$rs1), + "cloadversion", "$rd, $rs1">; +def CLoadVersions : RVInstCheriSrcDst<0x7f, 0x15, 0, OPC_CHERI, (outs GPR:$rd), + (ins GPCRMemAtomic:$rs1), + "cloadversions", "$rd, $rs1">; +} +let mayStore = 1, mayLoad = 0, hasSideEffects = 0 in +def CStoreVersion : RVInstCheriTwoSrc<0x7e, 0x2, 0, OPC_CHERI, (outs), + (ins GPCRMemAtomic:$rs1, GPR:$rs2), + "cstoreversion", "$rs2, $rs1">; +let mayLoad = 1, mayStore = 1, hasSideEffects = 0 in +def CAmoCDecVersion : RVInstR<0x3, 0, OPC_CHERI, (outs GPR:$rd), + (ins GPCRMemAtomic:$rs1, GPCR:$rs2), + "camocdecversion", "$rd, $rs1, $rs2">; +} diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h index 7b952bfbbeac..c5cea3165b9b 100644 --- a/llvm/lib/Target/RISCV/RISCVSubtarget.h +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h @@ -55,6 +55,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo { bool HasRV64 = false; bool IsRV32E = false; bool HasCheri = false; + bool HasCheriMemVersion = false; bool IsCapMode = false; bool EnableLinkerRelax = false; bool EnableRVCHintInstrs = true; @@ -118,6 +119,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo { bool is64Bit() const { return HasRV64; } bool isRV32E() const { return IsRV32E; } bool hasCheri() const { return HasCheri; } + bool hasCheriMemVersion() const { return HasCheriMemVersion; } bool isCapMode() const { return IsCapMode; } bool enableLinkerRelax() const { return EnableLinkerRelax; } bool enableRVCHintInstrs() const { return EnableRVCHintInstrs; } diff --git a/llvm/test/MC/RISCV/cheri/rv64xcheri-version.s b/llvm/test/MC/RISCV/cheri/rv64xcheri-version.s new file mode 100644 index 000000000000..ffdd14132dbb --- /dev/null +++ b/llvm/test/MC/RISCV/cheri/rv64xcheri-version.s @@ -0,0 +1,31 @@ +# RUN: llvm-mc %s -triple=riscv64 -mattr=+xcheri,+xcherimemversion -show-encoding \ +# RUN: | FileCheck %s +# RUN: not llvm-mc %s -triple=riscv64 -mattr=+xcheri -show-encoding \ +# RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-DISABLED + +# CHECK: cgetversion gp, csp +# CHECK: encoding: [0xdb,0x01,0x31,0xff] +# CHECK-DISABLED: error: instruction requires the following: CHERI Extension with memory versioning +cgetversion x3, c2 +# CHECK: csetversion cra, csp, gp +# CHECK: encoding: [0xdb,0x00,0x31,0x04] +# CHECK-DISABLED: error: instruction requires the following: CHERI Extension with memory versioning +csetversion c1, c2, x3 +# CHECK: cloadversion sp, (cra) +# CHECK: encoding: [0x5b,0x81,0x60,0xff] +# CHECK-DISABLED: error: instruction requires the following: CHERI Extension with memory versioning +cloadversion x2, (c1) +# CHECK: cloadversions sp, (cra) +# CHECK: encoding: [0x5b,0x81,0x50,0xff] +# CHECK-DISABLED: error: instruction requires the following: CHERI Extension with memory versioning +cloadversions x2, (c1) +# CHECK: cstoreversion ra, (ctp) +# CHECK: encoding: [0x5b,0x01,0x12,0xfc] +# CHECK-DISABLED: error: instruction requires the following: CHERI Extension with memory versioning +cstoreversion x1, (c4) +# CHECK: camocdecversion ra, (csp), cgp +# CHECK: encoding: [0xdb,0x00,0x31,0x06] +# CHECK-DISABLED: error: instruction requires the following: CHERI Extension with memory versioning +camocdecversion x1, (c2), c3 + +