@@ -389,6 +389,17 @@ 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", (CGetPerm GPR:$rd, GPCR:$rs1)>;
394+ def : InstAlias<"ct.cgettype $rd, $rs1", (CGetType GPR:$rd, GPCR:$rs1)>;
395+ def : InstAlias<"ct.cgetbase $rd, $rs1", (CGetBase GPR:$rd, GPCR:$rs1)>;
396+ def : InstAlias<"ct.cgetlen $rd, $rs1", (CGetLen GPR:$rd, GPCR:$rs1)>;
397+ def : InstAlias<"ct.cgettag $rd, $rs1", (CGetTag GPR:$rd, GPCR:$rs1)>;
398+ def : InstAlias<"ct.cgethigh $rd, $rs1", (CGetHigh GPR:$rd, GPCR:$rs1)>;
399+ def : InstAlias<"ct.cgettop $rd, $rs1", (CGetTop GPR:$rd, GPCR:$rs1)>;
400+ def : InstAlias<"ct.cgetaddr $rd, $rs1", (PseudoCGetAddr GPR:$rd, GPCR:$rs1)>;
401+ }
402+
392403//===----------------------------------------------------------------------===//
393404// Capability-Modification Instructions
394405//===----------------------------------------------------------------------===//
@@ -434,6 +445,43 @@ def : InstAlias<"csetboundsimm $cd, $cs1, $imm",
434445 (CSetBoundsImm GPCR:$cd, GPCR:$cs1, uimm12:$imm), 0>;
435446}
436447
448+ let Predicates = [HasCheriot] in {
449+ def : InstAlias<"ct.cseal $rd, $rs1, $rs2", (CSeal GPCR:$rd, GPCR:$rs1,
450+ GPCR:$rs2)>;
451+ def : InstAlias<"ct.cunseal $rd, $rs1, $rs2", (CUnseal GPCR:$rd, GPCR:$rs1,
452+ GPCR:$rs2)>;
453+ def : InstAlias<"ct.candperm $rd, $rs1, $rs2", (CAndPerm GPCR:$rd, GPCR:$rs1,
454+ GPR:$rs2)>;
455+ def : InstAlias<"ct.csetaddr $rd, $rs1, $rs2", (CSetAddr GPCR:$rd, GPCR:$rs1,
456+ GPR:$rs2)>;
457+ def : InstAlias<"ct.csethigh $rd, $rs1, $rs2", (CSetHigh GPCR:$rd, GPCR:$rs1,
458+ GPR:$rs2)>;
459+ def : InstAlias<"ct.cincaddr $rd, $rs1, $rs2",
460+ (CIncOffset GPCR:$rd, GPCR:$rs1, GPR:$rs2), 0>;
461+ def : InstAlias<"ct.cincoffset $rd, $rs1, $rs2", (CIncOffset GPCR:$rd,
462+ GPCR:$rs1, GPR:$rs2)>;
463+ def : InstAlias<"ct.cincaddr $rd, $rs1, $rs2",
464+ (CIncOffsetImm GPCR:$rd, GPCR:$rs1, simm12:$rs2), 0>;
465+ def : InstAlias<"ct.cincoffset $rd, $rs1, $rs2", (CIncOffsetImm GPCR:$rd,
466+ GPCR:$rs1, simm12:$rs2)>;
467+ def : InstAlias<"ct.csetbounds $rd, $rs1, $rs2", (CSetBounds GPCR:$rd,
468+ GPCR:$rs1, GPR:$rs2)>;
469+ def : InstAlias<"ct.csetboundsexact $rd, $rs1, $rs2",
470+ (CSetBoundsExact GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
471+ def : InstAlias<"ct.csetbounds $rd, $rs1, $rs2", (CSetBoundsImm GPCR:$rd,
472+ GPCR:$rs1, uimm12:$rs2)>;
473+ def : InstAlias<"ct.csetboundsrounddown $rd, $rs1, $rs2",
474+ (CSetBoundsRoundDown GPCR:$rd, GPCR:$rs1, GPR:$rs2)>;
475+ def : InstAlias<"ct.ccleartag $rd, $rs1", (CClearTag GPCR:$rd, GPCR:$rs1)>;
476+
477+ def : InstAlias<"ct.cincaddrimm $cd, $cs1, $imm",
478+ (CIncOffsetImm GPCR:$cd, GPCR:$cs1, simm12:$imm), 0>;
479+ def : InstAlias<"ct.cincoffsetimm $cd, $cs1, $imm",
480+ (CIncOffsetImm GPCR:$cd, GPCR:$cs1, simm12:$imm), 0>;
481+ def : InstAlias<"ct.csetboundsimm $cd, $cs1, $imm",
482+ (CSetBoundsImm GPCR:$cd, GPCR:$cs1, uimm12:$imm), 0>;
483+ }
484+
437485//===----------------------------------------------------------------------===//
438486// Pointer-Arithmetic Instructions
439487//===----------------------------------------------------------------------===//
@@ -452,6 +500,12 @@ let isMoveReg = 1, isReMaterializable = 1, isAsCheapAsAMove = 1,
452500def CMove : Cheri_r<0xa, "cmove", GPCR>;
453501}
454502
503+ let Predicates = [HasCheriot] in {
504+ def : InstAlias<"ct.cmove $rd, $rs1", (CMove GPCR:$rd, GPCR:$rs1)>;
505+ def : InstAlias<"ct.csub $rd, $rs1, $rs2", (PseudoCSub GPR:$rd, GPCR:$rs1,
506+ GPCR:$rs2)>;
507+ }
508+
455509//===----------------------------------------------------------------------===//
456510// Control-Flow Instructions
457511//===----------------------------------------------------------------------===//
@@ -490,6 +544,15 @@ def CSEQX : Cheri_rr<0x21, "csetequalexact", GPR, GPCR, GPCR>;
490544def : InstAlias<"cseqx $rd, $cs1, $cs2", (CSEQX GPR:$rd, GPCR:$cs1, GPCR:$cs2)>;
491545}
492546
547+ let Predicates = [HasCheriot] in {
548+ def : InstAlias<"ct.ctestsubset $rd, $rs1, $rs2",
549+ (CTestSubset GPR:$rd, GPCRC0IsDDC:$rs1, GPCR:$rs2)>;
550+ def : InstAlias<"ct.csetequalexact $rd, $rs1, $rs2",
551+ (CSEQX GPR:$rd, GPCR:$rs1, GPCR:$rs2), 0>;
552+ def : InstAlias<"ct.cseqx $rd, $cs1, $cs2",
553+ (CSEQX GPR:$rd, GPCR:$cs1, GPCR:$cs2), 2>;
554+ }
555+
493556//===----------------------------------------------------------------------===//
494557// Special Capabilty Register Access Instructions
495558//===----------------------------------------------------------------------===//
@@ -506,6 +569,15 @@ def : InstAlias<"cspecialw $scr, $cs",
506569 (CSpecialRW C0, special_capreg:$scr, GPCRNoC0:$cs)>;
507570}
508571
572+ let Predicates = [HasCheriot] in {
573+ def : InstAlias<"ct.cspecialrw $rd, $imm5, $rs1",
574+ (CSpecialRW GPCR:$rd, special_capreg:$imm5, GPCR:$rs1)>;
575+ def : InstAlias<"ct.cspecialr $cd, $scr",
576+ (CSpecialRW GPCR:$cd, special_capreg:$scr, C0), 2>;
577+ def : InstAlias<"ct.cspecialw $scr, $cs",
578+ (CSpecialRW C0, special_capreg:$scr, GPCRNoC0:$cs), 2>;
579+ }
580+
509581//===----------------------------------------------------------------------===//
510582// Fast Register-Clearing Instructions
511583//===----------------------------------------------------------------------===//
@@ -527,6 +599,16 @@ def : InstAlias<"crrl $rd, $rs1", (CRRL GPR:$rd, GPR:$rs1)>;
527599def : InstAlias<"cram $rd, $rs1", (CRAM GPR:$rd, GPR:$rs1)>;
528600}
529601
602+ let Predicates = [HasCheriot] in {
603+ def : InstAlias<"ct.croundrepresentablelength $rd, $rs1", (CRRL GPR:$rd,
604+ GPR:$rs1)>;
605+ def : InstAlias<"ct.crepresentablealignmentmask $rd, $rs1", (CRAM GPR:$rd,
606+ GPR:$rs1)>;
607+
608+ def : InstAlias<"ct.crrl $rd, $rs1", (CRRL GPR:$rd, GPR:$rs1), 2>;
609+ def : InstAlias<"ct.cram $rd, $rs1", (CRAM GPR:$rd, GPR:$rs1), 2>;
610+ }
611+
530612//===----------------------------------------------------------------------===//
531613// Tag-Memory Access Instructions
532614//===----------------------------------------------------------------------===//
@@ -786,6 +868,36 @@ def : InstAlias<"cjalr $rs, $offset", (CJALR C1, GPCR:$rs, simm12:$of
786868def : InstAlias<"cjalr $rd, $rs, $offset", (CJALR GPCR:$rd, GPCR:$rs, simm12:$offset), 0>;
787869} // Predicates = [HasCheri, IsCapMode]
788870
871+ let Predicates = [HasCheriot] in {
872+ def : InstAlias<"ct.auipcc $rd, $imm20", (AUIPCC GPCR:$rd,
873+ uimm20_auipc:$imm20)>;
874+ def : InstAlias<"ct.auicgp $rd, $imm20", (AUICGP GPCR:$rd,
875+ uimm20_auigp:$imm20)>;
876+ def : InstAlias<"ct.cjal $rd, $imm20", (CJAL GPCR:$rd,
877+ simm21_lsb0_jal:$imm20)>;
878+ def : InstAlias<"ct.cjalr $rd, ${imm12}(${rs1})", (CJALR GPCR:$rd, GPCR:$rs1,
879+ simm12:$imm12)>;
880+
881+ def : InstAlias<"ct.cjal $offset", (CJAL C1, simm21_lsb0_jal:$offset), 2>;
882+ def : InstAlias<"ct.cj $offset", (CJAL C0, simm21_lsb0_jal:$offset), 0>;
883+
884+ def : InstAlias<"ct.cjr $rs", (CJALR C0, GPCR:$rs, 0), 8>;
885+ def : InstAlias<"ct.cjr ${offset}(${rs})",
886+ (CJALR C0, GPCR:$rs, simm12:$offset), 5>;
887+ def : InstAlias<"ct.cjalr $rs", (CJALR C1, GPCR:$rs, 0), 8>;
888+ def : InstAlias<"ct.cjalr ${offset}(${rs})",
889+ (CJALR C1, GPCR:$rs, simm12:$offset), 5>;
890+ def : InstAlias<"ct.cjalr $rd, $rs", (CJALR GPCR:$rd, GPCR:$rs, 0), 7>;
891+ def : InstAlias<"ct.cret", (CJALR C0, C1, 0), 9>;
892+
893+ def : InstAlias<"ct.cjr $rs, $offset", (CJALR C0, GPCR:$rs, simm12:$offset),
894+ 0>;
895+ def : InstAlias<"ct.cjalr $rs, $offset", (CJALR C1, GPCR:$rs, simm12:$offset),
896+ 0>;
897+ def : InstAlias<"ct.cjalr $rd, $rs, $offset",
898+ (CJALR GPCR:$rd, GPCR:$rs, simm12:$offset), 0>;
899+ }
900+
789901// Expands to an instruction alias with and without a c prefix for loads/stores
790902multiclass CPrefixedInstAlias<string Asm, dag Result> {
791903 def : InstAlias<"c" # Asm, Result, 0>;
@@ -834,6 +946,13 @@ defm : CPrefixedInstAlias<"sc $rs2, (${rs1})",
834946 (CSC_64 GPCR:$rs2, GPCR:$rs1, 0)>;
835947}
836948
949+ let Predicates = [HasCheriot] in {
950+ def : InstAlias<"ct.clc $rd, ${imm12}(${rs1})", (CLC_64 GPCR:$rd, GPCR:$rs1,
951+ simm12:$imm12)>;
952+ def : InstAlias<"ct.csc $rd, ${imm12}(${rs1})", (CSC_64 GPCR:$rd, GPCR:$rs1,
953+ simm12:$imm12)>;
954+ }
955+
837956let Predicates = [HasCheri, IsRV64, IsCapMode] in {
838957let DecoderNamespace = "CapModeOnly_",
839958 hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
@@ -1884,6 +2003,12 @@ def PseudoCCALL : Pseudo<(outs), (ins cap_call_symbol:$func), []> {
18842003 let AsmString = "ccall\t$func";
18852004}
18862005
2006+ let Predicates = [HasCheriot] in {
2007+ def : InstAlias<"ct.ccall $rd, $func", (PseudoCCALLReg GPCR:$rd,
2008+ cap_call_symbol:$func)>;
2009+ def : InstAlias<"ct.ccall $func", (PseudoCCALL cap_call_symbol:$func)>;
2010+ }
2011+
18872012// The PseudoCompartmentCall of expands to AUIPCC, CLC_64, C_CJALR (10 bytes),
18882013// but the setup to obtain the callee capability from an import table can
18892014// require up to 8 additional bytes.
@@ -1932,6 +2057,10 @@ def PseudoCTAIL : Pseudo<(outs), (ins cap_call_symbol:$dst), []> {
19322057 let AsmString = "ctail\t$dst";
19332058}
19342059
2060+ let Predicates = [HasCheriot] in def : InstAlias<
2061+ "ct.ctail $dst",
2062+ (PseudoCTAIL cap_call_symbol:$dst)>;
2063+
19352064let Predicates = [HasCheri, IsCapMode, IsPureCapABI],
19362065 isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [C2] in
19372066def PseudoCTAILIndirect : Pseudo<(outs), (ins GPCRNoC0C1:$rs1),
@@ -1953,6 +2082,11 @@ def PseudoCJump : Pseudo<(outs GPCR:$rd),
19532082 let AsmString = "cjump\t$target, $rd";
19542083}
19552084
2085+ let Predicates = [HasCheriot] in def : InstAlias<
2086+ "ct.cjump $target, $rd",
2087+ (PseudoCJump GPCR:$rd,
2088+ pseudo_cap_jump_symbol:$target)>;
2089+
19562090defm : CheriLdPat<sextloadi8, CLB>, Requires<[HasCheri, IsCapMode]>;
19572091defm : CheriLdPat<extloadi8, CLB>, Requires<[HasCheri, IsCapMode]>;
19582092defm : CheriLdPat<sextloadi16, CLH>, Requires<[HasCheri, IsCapMode]>;
0 commit comments