@@ -389,6 +389,25 @@ def PseudoCGetAddr : Pseudo<(outs GPR:$rd), (ins GPCR:$cs1), [],
389389 "cgetaddr", "$rd, $cs1">;
390390}
391391
392+ let Predicates = [HasCheriot] in {
393+ def : InstAlias<"ct.cgetperm $rd, $rs1",
394+ (CGetPerm GPR:$rd, GPCR:$rs1)>;
395+ def : InstAlias<"ct.cgettype $rd, $rs1",
396+ (CGetType GPR:$rd, GPCR:$rs1)>;
397+ def : InstAlias<"ct.cgetbase $rd, $rs1",
398+ (CGetBase GPR:$rd, GPCR:$rs1)>;
399+ def : InstAlias<"ct.cgetlen $rd, $rs1",
400+ (CGetLen GPR:$rd, GPCR:$rs1)>;
401+ def : InstAlias<"ct.cgettag $rd, $rs1",
402+ (CGetTag GPR:$rd, GPCR:$rs1)>;
403+ def : InstAlias<"ct.cgethigh $rd, $rs1",
404+ (CGetHigh GPR:$rd, GPCR:$rs1)>;
405+ def : InstAlias<"ct.cgettop $rd, $rs1",
406+ (CGetTop GPR:$rd, GPCR:$rs1)>;
407+ def : InstAlias<"ct.cgetaddr $rd, $rs1",
408+ (PseudoCGetAddr GPR:$rd, GPCR:$rs1)>;
409+ }
410+
392411//===----------------------------------------------------------------------===//
393412// Capability-Modification Instructions
394413//===----------------------------------------------------------------------===//
@@ -434,6 +453,44 @@ def : InstAlias<"csetboundsimm $cd, $cs1, $imm",
434453 (CSetBoundsImm GPCR:$cd, GPCR:$cs1, uimm12:$imm), 0>;
435454}
436455
456+ let Predicates = [HasCheriot] in {
457+ def : InstAlias<"ct.cseal $rd, $rs1, $rs2",
458+ (CSeal GPCR:$rd, GPCR:$rs1, GPCR:$rs2)>;
459+ def : InstAlias<"ct.cunseal $rd, $rs1, $rs2",
460+ (CUnseal GPCR:$rd, GPCR:$rs1, GPCR:$rs2)>;
461+ def : InstAlias<"ct.candperm $rd, $rs1, $rs2",
462+ (CAndPerm GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
463+ def : InstAlias<"ct.csetaddr $rd, $rs1, $rs2",
464+ (CSetAddr GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
465+ def : InstAlias<"ct.csethigh $rd, $rs1, $rs2",
466+ (CSetHigh GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
467+ def : InstAlias<"ct.cincaddr $rd, $rs1, $rs2",
468+ (CIncOffset GPCR:$rd, GPCR:$rs1, GPR:$rs2), 0>;
469+ def : InstAlias<"ct.cincoffset $rd, $rs1, $rs2",
470+ (CIncOffset GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
471+ def : InstAlias<"ct.cincaddr $rd, $rs1, $rs2",
472+ (CIncOffsetImm GPCR:$rd, GPCR:$rs1, simm12:$rs2), 0>;
473+ def : InstAlias<"ct.cincoffset $rd, $rs1, $rs2",
474+ (CIncOffsetImm GPCR:$rd, GPCR:$rs1, simm12:$rs2)>;
475+ def : InstAlias<"ct.csetbounds $rd, $rs1, $rs2",
476+ (CSetBounds GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
477+ def : InstAlias<"ct.csetboundsexact $rd, $rs1, $rs2",
478+ (CSetBoundsExact GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
479+ def : InstAlias<"ct.csetbounds $rd, $rs1, $rs2",
480+ (CSetBoundsImm GPCR:$rd, GPCR:$rs1, uimm12:$rs2)>;
481+ def : InstAlias<"ct.csetboundsrounddown $rd, $rs1, $rs2",
482+ (CSetBoundsRoundDown GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
483+ def : InstAlias<"ct.ccleartag $rd, $rs1",
484+ (CClearTag GPCR:$rd, GPCR:$rs1)>;
485+
486+ def : InstAlias<"ct.cincaddrimm $cd, $cs1, $imm",
487+ (CIncOffsetImm GPCR:$cd, GPCR:$cs1, simm12:$imm), 0>;
488+ def : InstAlias<"ct.cincoffsetimm $cd, $cs1, $imm",
489+ (CIncOffsetImm GPCR:$cd, GPCR:$cs1, simm12:$imm), 0>;
490+ def : InstAlias<"ct.csetboundsimm $cd, $cs1, $imm",
491+ (CSetBoundsImm GPCR:$cd, GPCR:$cs1, uimm12:$imm), 0>;
492+ }
493+
437494//===----------------------------------------------------------------------===//
438495// Pointer-Arithmetic Instructions
439496//===----------------------------------------------------------------------===//
@@ -452,6 +509,13 @@ let isMoveReg = 1, isReMaterializable = 1, isAsCheapAsAMove = 1,
452509def CMove : Cheri_r<0xa, "cmove", GPCR>;
453510}
454511
512+ let Predicates = [HasCheriot] in {
513+ def : InstAlias<"ct.cmove $rd, $rs1",
514+ (CMove GPCR:$rd, GPCR:$rs1)>;
515+ def : InstAlias<"ct.csub $rd, $rs1, $rs2",
516+ (PseudoCSub GPR:$rd, GPCR:$rs1, GPCR:$rs2)>;
517+ }
518+
455519//===----------------------------------------------------------------------===//
456520// Control-Flow Instructions
457521//===----------------------------------------------------------------------===//
@@ -490,6 +554,15 @@ def CSEQX : Cheri_rr<0x21, "csetequalexact", GPR, GPCR, GPCR>;
490554def : InstAlias<"cseqx $rd, $cs1, $cs2", (CSEQX GPR:$rd, GPCR:$cs1, GPCR:$cs2)>;
491555}
492556
557+ let Predicates = [HasCheriot] in {
558+ def : InstAlias<"ct.ctestsubset $rd, $rs1, $rs2",
559+ (CTestSubset GPR:$rd, GPCRC0IsDDC:$rs1, GPCR:$rs2)>;
560+ def : InstAlias<"ct.csetequalexact $rd, $rs1, $rs2",
561+ (CSEQX GPR:$rd, GPCR:$rs1, GPCR:$rs2), 0>;
562+ def : InstAlias<"ct.cseqx $rd, $cs1, $cs2",
563+ (CSEQX GPR:$rd, GPCR:$cs1, GPCR:$cs2), 2>;
564+ }
565+
493566//===----------------------------------------------------------------------===//
494567// Special Capabilty Register Access Instructions
495568//===----------------------------------------------------------------------===//
@@ -506,6 +579,15 @@ def : InstAlias<"cspecialw $scr, $cs",
506579 (CSpecialRW C0, special_capreg:$scr, GPCRNoC0:$cs)>;
507580}
508581
582+ let Predicates = [HasCheriot] in {
583+ def : InstAlias<"ct.cspecialrw $rd, $imm5, $rs1",
584+ (CSpecialRW GPCR:$rd, special_capreg:$imm5, GPCR:$rs1)>;
585+ def : InstAlias<"ct.cspecialr $cd, $scr",
586+ (CSpecialRW GPCR:$cd, special_capreg:$scr, C0), 2>;
587+ def : InstAlias<"ct.cspecialw $scr, $cs",
588+ (CSpecialRW C0, special_capreg:$scr, GPCRNoC0:$cs), 2>;
589+ }
590+
509591//===----------------------------------------------------------------------===//
510592// Fast Register-Clearing Instructions
511593//===----------------------------------------------------------------------===//
@@ -527,6 +609,16 @@ def : InstAlias<"crrl $rd, $rs1", (CRRL GPR:$rd, GPR:$rs1)>;
527609def : InstAlias<"cram $rd, $rs1", (CRAM GPR:$rd, GPR:$rs1)>;
528610}
529611
612+ let Predicates = [HasCheriot] in {
613+ def : InstAlias<"ct.croundrepresentablelength $rd, $rs1",
614+ (CRRL GPR:$rd, GPR:$rs1)>;
615+ def : InstAlias<"ct.crepresentablealignmentmask $rd, $rs1",
616+ (CRAM GPR:$rd, GPR:$rs1)>;
617+
618+ def : InstAlias<"ct.crrl $rd, $rs1", (CRRL GPR:$rd, GPR:$rs1), 2>;
619+ def : InstAlias<"ct.cram $rd, $rs1", (CRAM GPR:$rd, GPR:$rs1), 2>;
620+ }
621+
530622//===----------------------------------------------------------------------===//
531623// Tag-Memory Access Instructions
532624//===----------------------------------------------------------------------===//
@@ -786,6 +878,31 @@ def : InstAlias<"cjalr $rs, $offset", (CJALR C1, GPCR:$rs, simm12:$of
786878def : InstAlias<"cjalr $rd, $rs, $offset", (CJALR GPCR:$rd, GPCR:$rs, simm12:$offset), 0>;
787879} // Predicates = [HasCheri, IsCapMode]
788880
881+ let Predicates = [HasCheriot] in {
882+ def : InstAlias<"ct.auipcc $rd, $imm20",
883+ (AUIPCC GPCR:$rd, uimm20_auipc:$imm20)>;
884+ def : InstAlias<"ct.auicgp $rd, $imm20",
885+ (AUICGP GPCR:$rd, uimm20_auigp:$imm20)>;
886+ def : InstAlias<"ct.cjal $rd, $imm20",
887+ (CJAL GPCR:$rd, simm21_lsb0_jal:$imm20)>;
888+ def : InstAlias<"ct.cjalr $rd, ${imm12}(${rs1})",
889+ (CJALR GPCR:$rd, GPCR:$rs1, simm12:$imm12)>;
890+
891+ def : InstAlias<"ct.cjal $offset", (CJAL C1, simm21_lsb0_jal:$offset), 2>;
892+ def : InstAlias<"ct.cj $offset", (CJAL C0, simm21_lsb0_jal:$offset), 0>;
893+
894+ def : InstAlias<"ct.cjr $rs", (CJALR C0, GPCR:$rs, 0), 8>;
895+ def : InstAlias<"ct.cjr ${offset}(${rs})", (CJALR C0, GPCR:$rs, simm12:$offset), 5>;
896+ def : InstAlias<"ct.cjalr $rs", (CJALR C1, GPCR:$rs, 0), 8>;
897+ def : InstAlias<"ct.cjalr ${offset}(${rs})", (CJALR C1, GPCR:$rs, simm12:$offset), 5>;
898+ def : InstAlias<"ct.cjalr $rd, $rs", (CJALR GPCR:$rd, GPCR:$rs, 0), 7>;
899+ def : InstAlias<"ct.cret", (CJALR C0, C1, 0), 9>;
900+
901+ def : InstAlias<"ct.cjr $rs, $offset", (CJALR C0, GPCR:$rs, simm12:$offset), 0>;
902+ def : InstAlias<"ct.cjalr $rs, $offset", (CJALR C1, GPCR:$rs, simm12:$offset), 0>;
903+ def : InstAlias<"ct.cjalr $rd, $rs, $offset", (CJALR GPCR:$rd, GPCR:$rs, simm12:$offset), 0>;
904+ }
905+
789906// Expands to an instruction alias with and without a c prefix for loads/stores
790907multiclass CPrefixedInstAlias<string Asm, dag Result> {
791908 def : InstAlias<"c" # Asm, Result, 0>;
@@ -834,6 +951,13 @@ defm : CPrefixedInstAlias<"sc $rs2, (${rs1})",
834951 (CSC_64 GPCR:$rs2, GPCR:$rs1, 0)>;
835952}
836953
954+ let Predicates = [HasCheriot] in {
955+ def : InstAlias<"ct.clc $rd, ${imm12}(${rs1})",
956+ (CLC_64 GPCR:$rd, GPCR:$rs1, simm12:$imm12)>;
957+ def : InstAlias<"ct.csc $rd, ${imm12}(${rs1})",
958+ (CSC_64 GPCR:$rd, GPCR:$rs1, simm12:$imm12)>;
959+ }
960+
837961let Predicates = [HasCheri, IsRV64, IsCapMode] in {
838962let DecoderNamespace = "CapModeOnly_",
839963 hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
@@ -1884,6 +2008,13 @@ def PseudoCCALL : Pseudo<(outs), (ins cap_call_symbol:$func), []> {
18842008 let AsmString = "ccall\t$func";
18852009}
18862010
2011+ let Predicates = [HasCheriot] in {
2012+ def : InstAlias<"ct.ccall $rd, $func",
2013+ (PseudoCCALLReg GPCR:$rd, cap_call_symbol:$func)>;
2014+ def : InstAlias<"ct.ccall $func",
2015+ (PseudoCCALL cap_call_symbol:$func)>;
2016+ }
2017+
18872018// The PseudoCompartmentCall of expands to AUIPCC, CLC_64, C_CJALR (10 bytes),
18882019// but the setup to obtain the callee capability from an import table can
18892020// require up to 8 additional bytes.
@@ -1932,6 +2063,10 @@ def PseudoCTAIL : Pseudo<(outs), (ins cap_call_symbol:$dst), []> {
19322063 let AsmString = "ctail\t$dst";
19332064}
19342065
2066+ let Predicates = [HasCheriot] in
2067+ def : InstAlias<"ct.ctail $dst",
2068+ (PseudoCTAIL cap_call_symbol:$dst)>;
2069+
19352070let Predicates = [HasCheri, IsCapMode, IsPureCapABI],
19362071 isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [C2] in
19372072def PseudoCTAILIndirect : Pseudo<(outs), (ins GPCRNoC0C1:$rs1),
@@ -1953,6 +2088,10 @@ def PseudoCJump : Pseudo<(outs GPCR:$rd),
19532088 let AsmString = "cjump\t$target, $rd";
19542089}
19552090
2091+ let Predicates = [HasCheriot] in
2092+ def : InstAlias<"ct.cjump $target, $rd",
2093+ (PseudoCJump GPCR:$rd, pseudo_cap_jump_symbol:$target)>;
2094+
19562095defm : CheriLdPat<sextloadi8, CLB>, Requires<[HasCheri, IsCapMode]>;
19572096defm : CheriLdPat<extloadi8, CLB>, Requires<[HasCheri, IsCapMode]>;
19582097defm : CheriLdPat<sextloadi16, CLH>, Requires<[HasCheri, IsCapMode]>;
0 commit comments