Skip to content

Commit

Permalink
[cheriot] CSetBoundsRoundDown instruction and intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
nwf committed Dec 12, 2024
1 parent d65c708 commit eb05e95
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Basic/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,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
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 @@ -408,6 +408,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 @@ -1301,6 +1302,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

0 comments on commit eb05e95

Please sign in to comment.