References:
References: Extending LLVM: Adding instructions, intrinsics, types, etc More
References: Extending LLVM: Adding instructions, intrinsics, types More
References: Extending LLVM: Adding instructions, intrinsics, types Mips::CSetBounds new instruction support in LLVM IR intrinsics td file llvm/include/IR/IntrinsicsCHERICap.td def int_cheri_cap_bounds_set : Intrinsic<[llvm_fatptr_ty], [llvm_fatptr_ty, llvm_anyint_ty], [IntrNoMem, IntrWillReturn]>; def int_cheri_cap_bounds_set_exact : Intrinsic<[llvm_fatptr_ty], [llvm_fatptr_ty, llvm_anyint_ty], [IntrNoMem, IntrWillReturn]>; target td file llvm/lib/Target/Mips/MipsInstrCheri.td // Accept CIncOffsetImm as an assembler mnemonic because ancient binutils is too stupid to have an opcode // with differing encoding depending on the parameters def : InstAlias<"csetboundsimm $dst, $src, $imm", (CSetBoundsImm CheriOpnd:$dst, CheriOpnd:$src, uimm11s0:$imm), 0>; def : InstAlias<"cincoffsetimm $dst, $src, $imm", (CIncOffsetImm CheriOpnd:$dst, CheriOpnd:$src, simm11s0:$imm), 0>; def : InstAlias<"csetboundsimm $dst, $imm", (CSetBoundsImm CheriOpnd:$dst, CheriOpnd:$dst, uimm11s0:$imm), 0>; def : InstAlias<"cincoffsetimm $dst, $imm", (CIncOffsetImm CheriOpnd:$dst, CheriOpnd:$dst, simm11s0:$imm), 0>; // CAssertInBounds pseudo def : InstAlias<"cassertinbounds $dst, $imm", (CSetBoundsImm CNULL, CheriOpnd:$dst, uimm11s0:$imm), 1>; def : InstAlias<"cassertinbounds $dst", (CSetBoundsImm CNULL, CheriOpnd:$dst, 1), 0>; // Property setters let isReMaterializable = 1, isAsCheapAsAMove = 1 in { def CAndPerms : CheriFmtCSet<0xd, "perm", "perms", "and">; def CSetFlags : CheriFmtCSet<0xe, "flags">; def CSetOffset : CheriFmtCSet<0xf, "offset">; def CSetBounds : CheriFmtCSet<0x8, "bounds">; def CSetBoundsExact : CheriFmtCSet<0x9, "boundsexact", "bounds", "set", "set_exact">; def CIncOffset : CheriFmt3Op<0x11, (outs CheriOpnd:$r1), (ins CheriOpnd:$r2, GPR64Opnd:$r3), "cincoffset\t$r1, $r2, $r3", [(set CheriOpnd:$r1, (ptradd CheriOpnd:$r2, GPR64Opnd:$r3))]>; def CClearTag : CheriFmt2Op<0xb, (outs CheriOpnd:$r1), (ins CheriOpnd:$r2), "ccleartag\t$r1, $r2", [(set CheriOpnd:$r1, (int_cheri_cap_tag_clear CheriOpnd:$r2))]>; def CSetAddr : CheriFmtCSet<0x22, "addr", "address">; // Add a pseudo instruction to pretend this is only one instruction to avoid register spills def CheriBoundedStackPseudoImm : CheriBoundedStackPseudo<(ins CheriOpnd:$fi, simm11s0:$frameoffs, uimm11s0:$size)>; // FIXME: duplicated to avoid machine verified errors def CheriBoundedStackPseudoReg : CheriBoundedStackPseudo<(ins CheriOpnd:$fi, simm11s0:$frameoffs, GPR64Opnd:$size)>; llvm/lib/Target/RISCV/RISCVInstrinfoXCheri.
Reference: Extending LLVM: Adding instructions, intrinsics, types, etc. “Adding a new intrinsic function to LLVM is much easier than adding a new instruction. Almost all extensions to LLVM should start as an intrinsic function and then be turned into an instruction if warranted.” llvm/docs/LangRef.html: Document the intrinsic. Decide whether it is code generator specific and what the restrictions are. Talk to other people about it so that you are sure it’s a good idea.
If you could revise
the fundmental principles of
computer system design
to improve security...
... what would you change?