Skip to content
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

Add MC support for CHERI memory colouring instructions. #508

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions llvm/lib/Target/RISCV/RISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down
23 changes: 23 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td
Original file line number Diff line number Diff line change
Expand Up @@ -1554,3 +1554,26 @@ let Predicates = [HasCheri, IsRV64, IsCapMode] in {
defm : CheriLdPat<load, CLC_128>;
defm : CheriStPat<store, CSC_128, GPCR>;
} // Predicates = [HasCheri, IsRV64, IsCapMode]


/// CHERI memory colouring extensions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instructions go in the first half of the file to keep MC and CodeGen cleanly separated*

(* pseudos are more complicated, but placed based on whether they're used for assembly or just CodeGen)

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">;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"camocdecversion", "$rd, $rs1, $rs2">;
"camocdecversion", "$rd, $rs2, $rs1">;

to match stores and atomics

}
2 changes: 2 additions & 0 deletions llvm/lib/Target/RISCV/RISCVSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down
31 changes: 31 additions & 0 deletions llvm/test/MC/RISCV/cheri/rv64xcheri-version.s
Original file line number Diff line number Diff line change
@@ -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