Skip to content

Commit 650a4cc

Browse files
committed
Cranelift: ISLE: add type parameters to most clif terms in lower
Right now in ISLE, most clif instructions have a type parameter in opt for the midend, but not in lowering. From our previous discussions, this is mostly due to the order of implementation rather than a design deciscion. For our verification work, it's useful to also have the type parameters in the lowering terms, as well, if they produce values (e.g., excluding things like `store`). This is based on an earlier commit from @mmcloughlin, with changes to merge into upstream after bytecodealliance#10524.
1 parent 8adf03d commit 650a4cc

File tree

14 files changed

+2397
-2390
lines changed

14 files changed

+2397
-2390
lines changed

cranelift/codegen/build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ fn run_compilation(compilation: &IsleCompilation) -> Result<(), Errors> {
224224
}));
225225
}
226226

227-
if let Ok(out_dir) = std::env::var("OUT_DIR") {
228-
options.prefixes.push(isle::codegen::Prefix {
229-
prefix: out_dir,
230-
name: "<OUT_DIR>".to_string(),
231-
})
232-
};
227+
// if let Ok(out_dir) = std::env::var("OUT_DIR") {
228+
// options.prefixes.push(isle::codegen::Prefix {
229+
// prefix: out_dir,
230+
// name: "<OUT_DIR>".to_string(),
231+
// })
232+
// };
233233

234234
isle::compile::from_files(file_paths, &options)?
235235
};

cranelift/codegen/meta/src/gen_isle.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ fn gen_common_isle(
230230

231231
(IsleTarget::Opt, _, 1, false) => ("Value", true, "make_inst", "inst_data_value"),
232232
(IsleTarget::Opt, _, _, _) => ("Inst", false, "make_skeleton_inst", "inst_data"),
233+
(IsleTarget::Lower, false, r, _) if r >= 1
234+
=> ("Inst", true, "make_inst", "inst_data_value"),
233235
(IsleTarget::Lower, _, _, _) => ("Inst", false, "make_inst", "inst_data_value"),
234236
};
235237

@@ -268,7 +270,7 @@ fn gen_common_isle(
268270

269271
let mut s = format!(
270272
"({inst_data_etor} {}(InstructionData.{} (Opcode.{})",
271-
if ty_in_decl { "ty " } else { "" },
273+
if ty_in_decl { "ty " } else if isle_target == IsleTarget::Lower { "_" } else { "" },
272274
inst.format.name,
273275
inst.camel_name
274276
);

cranelift/codegen/src/isa/aarch64/inst.isle

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@
19561956
(decl imm12_from_value (Imm12) Value)
19571957
(extractor
19581958
(imm12_from_value n)
1959-
(iconst (u64_from_imm64 (imm12_from_u64 n))))
1959+
(iconst _ (u64_from_imm64 (imm12_from_u64 n))))
19601960
;; Conceptually the same as `imm12_from_value`, but tries negating the constant
19611961
;; value (first sign-extending to handle narrow widths).
19621962
(spec (imm12_from_negated_value arg)
@@ -1980,7 +1980,7 @@
19801980
)
19811981
(decl pure partial imm12_from_negated_value (Value) Imm12)
19821982
(rule imm12_from_negated_value
1983-
(imm12_from_negated_value (has_type ty (iconst n)))
1983+
(imm12_from_negated_value (has_type ty (iconst _ n)))
19841984
(if-let (imm12_from_u64 imm) (i64_cast_unsigned (i64_checked_neg (i64_sextend_imm64 ty n))))
19851985
imm)
19861986

@@ -3755,7 +3755,7 @@
37553755
(MInst.TrapIf (cond_br_cond (Cond.Hs)) tc))))
37563756

37573757
(decl sink_atomic_load (Inst) Reg)
3758-
(rule (sink_atomic_load x @ (atomic_load _ addr))
3758+
(rule (sink_atomic_load x @ (atomic_load _ _ addr))
37593759
(let ((_ Unit (sink_inst x)))
37603760
(put_in_reg addr)))
37613761

@@ -3777,18 +3777,18 @@
37773777
(alu_rrr op ty x y))
37783778

37793779
;; Special cases for when one operand is a constant.
3780-
(rule (alu_rs_imm_logic_commutative op ty x (iconst k))
3780+
(rule (alu_rs_imm_logic_commutative op ty x (iconst _ k))
37813781
(if-let imm (imm_logic_from_imm64 ty k))
37823782
(alu_rr_imm_logic op ty x imm))
3783-
(rule 1 (alu_rs_imm_logic_commutative op ty (iconst k) x)
3783+
(rule 1 (alu_rs_imm_logic_commutative op ty (iconst _ k) x)
37843784
(if-let imm (imm_logic_from_imm64 ty k))
37853785
(alu_rr_imm_logic op ty x imm))
37863786

37873787
;; Special cases for when one operand is shifted left by a constant.
3788-
(rule (alu_rs_imm_logic_commutative op ty x (ishl y (iconst k)))
3788+
(rule (alu_rs_imm_logic_commutative op ty x (ishl _ y (iconst _ k)))
37893789
(if-let amt (lshl_from_imm64 ty k))
37903790
(alu_rrr_shift op ty x y amt))
3791-
(rule 1 (alu_rs_imm_logic_commutative op ty (ishl x (iconst k)) y)
3791+
(rule 1 (alu_rs_imm_logic_commutative op ty (ishl _ x (iconst _ k)) y)
37923792
(if-let amt (lshl_from_imm64 ty k))
37933793
(alu_rrr_shift op ty y x amt))
37943794

@@ -3805,10 +3805,10 @@
38053805
(decl alu_rs_imm_logic (ALUOp Type Value Value) Reg)
38063806
(rule -1 (alu_rs_imm_logic op ty x y)
38073807
(alu_rrr op ty x y))
3808-
(rule (alu_rs_imm_logic op ty x (iconst k))
3808+
(rule (alu_rs_imm_logic op ty x (iconst _ k))
38093809
(if-let imm (imm_logic_from_imm64 ty k))
38103810
(alu_rr_imm_logic op ty x imm))
3811-
(rule (alu_rs_imm_logic op ty x (ishl y (iconst k)))
3811+
(rule (alu_rs_imm_logic op ty x (ishl _ y (iconst _ k)))
38123812
(if-let amt (lshl_from_imm64 ty k))
38133813
(alu_rrr_shift op ty x y amt))
38143814

@@ -3905,15 +3905,15 @@
39053905

39063906
(rule 0 (amode ty val offset)
39073907
(amode_no_more_iconst ty val offset))
3908-
(rule 1 (amode ty (iadd x (i32_from_iconst y)) offset)
3908+
(rule 1 (amode ty (iadd _ x (i32_from_iconst y)) offset)
39093909
(if-let new_offset (i32_checked_add y offset))
39103910
(amode_no_more_iconst ty x new_offset))
3911-
(rule 2 (amode ty (iadd (i32_from_iconst x) y) offset)
3911+
(rule 2 (amode ty (iadd _ (i32_from_iconst x) y) offset)
39123912
(if-let new_offset (i32_checked_add x offset))
39133913
(amode_no_more_iconst ty y new_offset))
39143914

39153915
(rule 3
3916-
(amode ty (stack_addr slot offset1) offset2)
3916+
(amode ty (stack_addr _ slot offset1) offset2)
39173917
(AMode.SlotOffset
39183918
(abi_stackslot_offset_into_slot_region slot offset1 offset2)))
39193919

@@ -3939,15 +3939,15 @@
39393939
;; instructions. Constants on the other hand added to the amode represent only
39403940
;; a single instruction folded in, so fewer instructions should be generated
39413941
;; with these higher priority than the rules above.
3942-
(rule 3 (amode_no_more_iconst ty (iadd x y) offset)
3942+
(rule 3 (amode_no_more_iconst ty (iadd _ x y) offset)
39433943
(AMode.RegReg (amode_add x offset) y))
3944-
(rule 4 (amode_no_more_iconst ty (iadd x (uextend y @ (value_type $I32))) offset)
3944+
(rule 4 (amode_no_more_iconst ty (iadd _ x (uextend _ y @ (value_type $I32))) offset)
39453945
(AMode.RegExtended (amode_add x offset) y (ExtendOp.UXTW)))
3946-
(rule 4 (amode_no_more_iconst ty (iadd x (sextend y @ (value_type $I32))) offset)
3946+
(rule 4 (amode_no_more_iconst ty (iadd _ x (sextend _ y @ (value_type $I32))) offset)
39473947
(AMode.RegExtended (amode_add x offset) y (ExtendOp.SXTW)))
3948-
(rule 5 (amode_no_more_iconst ty (iadd (uextend x @ (value_type $I32)) y) offset)
3948+
(rule 5 (amode_no_more_iconst ty (iadd _ (uextend _ x @ (value_type $I32)) y) offset)
39493949
(AMode.RegExtended (amode_add y offset) x (ExtendOp.UXTW)))
3950-
(rule 5 (amode_no_more_iconst ty (iadd (sextend x @ (value_type $I32)) y) offset)
3950+
(rule 5 (amode_no_more_iconst ty (iadd _ (sextend _ x @ (value_type $I32)) y) offset)
39513951
(AMode.RegExtended (amode_add y offset) x (ExtendOp.SXTW)))
39523952

39533953
;; `RegScaled*` rules where this matches an addition of an "index register" to a
@@ -3957,19 +3957,19 @@
39573957
;; Note that this can additionally bundle an extending operation but the
39583958
;; extension must happen before the shift. This will pattern-match the shift
39593959
;; first and then if that succeeds afterwards try to find an extend.
3960-
(rule 6 (amode_no_more_iconst ty (iadd x (ishl y (iconst (u64_from_imm64 n)))) offset)
3960+
(rule 6 (amode_no_more_iconst ty (iadd _ x (ishl _ y (iconst _ (u64_from_imm64 n)))) offset)
39613961
(if-let true (u64_eq (ty_bytes ty) (u64_wrapping_shl 1 (shift_masked_imm ty n))))
39623962
(amode_reg_scaled (amode_add x offset) y))
3963-
(rule 7 (amode_no_more_iconst ty (iadd (ishl y (iconst (u64_from_imm64 n))) x) offset)
3963+
(rule 7 (amode_no_more_iconst ty (iadd _ (ishl _ y (iconst _ (u64_from_imm64 n))) x) offset)
39643964
(if-let true (u64_eq (ty_bytes ty) (u64_wrapping_shl 1 (shift_masked_imm ty n))))
39653965
(amode_reg_scaled (amode_add x offset) y))
39663966

39673967
(decl amode_reg_scaled (Reg Value) AMode)
39683968
(rule 0 (amode_reg_scaled base index)
39693969
(AMode.RegScaled base index))
3970-
(rule 1 (amode_reg_scaled base (uextend index @ (value_type $I32)))
3970+
(rule 1 (amode_reg_scaled base (uextend _ index @ (value_type $I32)))
39713971
(AMode.RegScaledExtended base index (ExtendOp.UXTW)))
3972-
(rule 1 (amode_reg_scaled base (sextend index @ (value_type $I32)))
3972+
(rule 1 (amode_reg_scaled base (sextend _ index @ (value_type $I32)))
39733973
(AMode.RegScaledExtended base index (ExtendOp.SXTW)))
39743974

39753975
;; Helper to add a 32-bit signed immediate to the register provided. This will
@@ -4007,7 +4007,7 @@
40074007

40084008

40094009
(decl sink_load_into_addr (Type Inst) Reg)
4010-
(rule (sink_load_into_addr ty x @ (load _ addr (offset32 offset)))
4010+
(rule (sink_load_into_addr ty x @ (load _ _ addr (offset32 offset)))
40114011
(let ((_ Unit (sink_inst x)))
40124012
(add_imm_to_addr addr (i64_cast_unsigned offset))))
40134013

0 commit comments

Comments
 (0)