Skip to content
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
1 change: 1 addition & 0 deletions clang/include/clang/Basic/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,7 @@ BUILTIN(__builtin_cheri_address_set, "v*mvC*mz", "nct")
BUILTIN(__builtin_cheri_base_get, "zvC*m", "nct")
BUILTIN(__builtin_cheri_bounds_set, "v*mvC*mz", "nct")
BUILTIN(__builtin_cheri_bounds_set_exact, "v*mvC*mz", "nct")
BUILTIN(__builtin_cheri_bounds_set_round_down, "v*mvC*mz", "nct")
BUILTIN(__builtin_cheri_equal_exact, "bvC*mvC*m", "nct")
BUILTIN(__builtin_cheri_flags_set, "v*mvC*mz", "nct")
BUILTIN(__builtin_cheri_flags_get, "zvC*m", "nct")
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5032,6 +5032,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
{SizeTy}, {Cap, Length}),
Cap->getType()));
}
case Builtin::BI__builtin_cheri_bounds_set_round_down: {
Value *Cap = EmitScalarExpr(E->getArg(0));
Value *Length = EmitScalarExpr(E->getArg(1));
return RValue::get(Builder.CreateBitCast(
Builder.CreateIntrinsic(
llvm::Intrinsic::cheri_cap_bounds_set_round_down, {SizeTy},
{Cap, Length}),
Cap->getType()));
}
case Builtin::BI__builtin_cheri_flags_get:
return RValue::get(
Builder.CreateIntrinsic(llvm::Intrinsic::cheri_cap_flags_get, {SizeTy},
Expand Down
12 changes: 12 additions & 0 deletions clang/test/CodeGen/cheri/cheriot-csetboundsrounddown.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
// RUN: %clang_cc1 %s -o - "-triple" "riscv32cheriot-unknown-cheriotrtos" "-emit-llvm" "-mframe-pointer=none" "-mcmodel=small" "-target-abi" "cheriot" "-Oz" "-Werror" -std=c2x | FileCheck %s

// CHECK-LABEL: define dso_local ptr addrspace(200) @foo
// CHECK-SAME: (ptr addrspace(200) noundef readnone [[CAP:%.*]], i32 noundef [[B:%.*]]) local_unnamed_addr addrspace(200) #[[ATTR0:[0-9]+]] {
// CHECK-NEXT: entry:
// CHECK-NEXT: [[TMP0:%.*]] = tail call ptr addrspace(200) @llvm.cheri.cap.bounds.set.round.down.i32(ptr addrspace(200) [[CAP]], i32 [[B]])
// CHECK-NEXT: ret ptr addrspace(200) [[TMP0]]
//
void *foo(void* cap, int b) {
return __builtin_cheri_bounds_set_round_down(cap, b);
}
4 changes: 4 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsCHERICap.td
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def int_cheri_cap_bounds_set_exact :
Intrinsic<[llvm_cap_ty],
[llvm_cap_ty, llvm_anyint_ty],
[IntrNoMem, IntrWillReturn]>;
def int_cheri_cap_bounds_set_round_down :
Intrinsic<[llvm_cap_ty],
[llvm_cap_ty, llvm_anyint_ty],
[IntrNoMem, IntrWillReturn]>;
def int_cheri_cap_type_get :
Intrinsic<[llvm_anyint_ty],
[llvm_cap_ty],
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,7 @@ bool RISCVInstrInfo::isSetBoundsInstr(const MachineInstr &I,
case RISCV::CSetBounds:
case RISCV::CSetBoundsExact:
case RISCV::CSetBoundsImm:
case RISCV::CSetBoundsRoundDown:
Base = &I.getOperand(1);
Size = &I.getOperand(2);
return true;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ let mayTrap = 1 in {
def CSetBounds : Cheri_rr<0x8, "csetbounds">;
def CSetBoundsExact : Cheri_rr<0x9, "csetboundsexact">;
def CSetBoundsImm : Cheri_ri<0x2, "csetbounds", 0>;
def CSetBoundsRoundDown : Cheri_rr<0xA, "csetboundsrounddown">;
} // mayTrap = 1
} // let Constraints = "@traps_if_sealed $rs1"
def CClearTag : Cheri_r<0xb, "ccleartag", GPCR>;
Expand Down Expand Up @@ -1306,6 +1307,7 @@ def : PatGpcrGpr<cptradd, CIncOffset>;
def : PatGpcrSimm12<cptradd, CIncOffsetImm>;
def : PatGpcrGpr<int_cheri_cap_bounds_set, CSetBounds>;
def : PatGpcrGpr<int_cheri_cap_bounds_set_exact, CSetBoundsExact>;
def : PatGpcrGpr<int_cheri_cap_bounds_set_round_down, CSetBoundsRoundDown>;
def : PatGpcrGpr<riscv_cap_bounds_set, CSetBounds>;
def : PatGpcrUimm12<riscv_cap_bounds_set, CSetBoundsImm>;
def : PatGpcrUimm12<int_cheri_cap_bounds_set, CSetBoundsImm>;
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/CodeGen/RISCV/cheri/cheriot-csetboundsrounddown.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
; RUN: llc --filetype=asm --mcpu=cheriot --mtriple=riscv32cheriot-unknown-cheriotrtos -target-abi cheriot %s -mattr=+xcheri,+cap-mode -o - | FileCheck %s
target datalayout = "e-m:e-pf200:64:64:64:32-p:32:32-i64:64-n32-S128-A200-P200-G200"
target triple = "riscv32cheriot-unknown-cheriotrtos"

define ptr addrspace(200) @foo(ptr addrspace(200) %cap, i32 noundef %b) addrspace(200) {
; CHECK-LABEL: foo:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: csetboundsrounddown ca0, ca0, a1
; CHECK-NEXT: cret
entry:
%0 = tail call ptr addrspace(200) @llvm.cheri.cap.bounds.set.round.down.i32(ptr addrspace(200) %cap, i32 %b)
ret ptr addrspace(200) %0
}

declare ptr addrspace(200) @llvm.cheri.cap.bounds.set.round.down.i32(ptr addrspace(200), i32) addrspace(200)
19 changes: 19 additions & 0 deletions llvm/test/MC/RISCV/cheri/cheriot.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# RUN: llvm-mc %s -triple=riscv32cheriot -mcpu=cheriot -mattr=+xcheri -riscv-no-aliases -show-encoding \
# RUN: | FileCheck %s

csetboundsrounddown cra, cra, zero
# CHECK: encoding: [0xdb,0x80,0x00,0x14]
csetboundsrounddown cra, ca5, zero
# CHECK: encoding: [0xdb,0x80,0x07,0x14]
csetboundsrounddown cra, cra, a5
# CHECK: encoding: [0xdb,0x80,0xf0,0x14]
csetboundsrounddown cra, ca5, a5
# CHECK: encoding: [0xdb,0x80,0xf7,0x14]
csetboundsrounddown ca5, cra, zero
# CHECK: [0xdb,0x87,0x00,0x14]
csetboundsrounddown ca5, ca5, zero
# CHECK: [0xdb,0x87,0x07,0x14]
csetboundsrounddown ca5, cra, a5
# CHECK: [0xdb,0x87,0xf0,0x14]
csetboundsrounddown ca5, ca5, a5
# CHECK: [0xdb,0x87,0xf7,0x14]