Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CLIF legalization into ISLE #7321

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2d8b8b5
riscv64: Optimize shift-by-i128 a bit more
alexcrichton Nov 13, 2023
763b571
Scaffold a way of legalizing through ISLE
alexcrichton Oct 10, 2023
10a5ada
Legalize `stack_store` in ISLE
alexcrichton Oct 12, 2023
4af131f
Start a `legalize_shared.isle`
alexcrichton Oct 12, 2023
52938c1
Add legalizer for all backends
alexcrichton Oct 12, 2023
f034387
Delete prior legalization of `StackStore`
alexcrichton Oct 12, 2023
8821900
Move `StackLoad` legalizing to ISLE
alexcrichton Oct 12, 2023
4b60f31
Move trapnz-style legalization to ISLE
alexcrichton Oct 21, 2023
24a7877
Move `*_imm` and `*_not` legalization into ISLE
alexcrichton Oct 21, 2023
0f9ff0b
Move global value legalization into ISLE
alexcrichton Oct 21, 2023
76cd417
Move table_addr legalization into ISLE
alexcrichton Oct 21, 2023
54cba63
Add a simple test for two-legalizations
alexcrichton Oct 21, 2023
e0e2191
Add a test for nan canonicalization legalizations
alexcrichton Oct 21, 2023
8d09a90
Move NaN canonicalization into ISLE
alexcrichton Oct 21, 2023
0099414
x64: Replace `CvtUint64ToFloatSeq` with legalization
alexcrichton Oct 21, 2023
799747c
Delete unused function
alexcrichton Oct 21, 2023
42f91d5
Add back in method for tests
alexcrichton Oct 21, 2023
cb2d4b0
Fix x64 test issue arising
alexcrichton Oct 21, 2023
96cb6f0
Fix issues with rebase
alexcrichton Nov 13, 2023
c619784
Only build necessary ISLE compilations
alexcrichton Nov 13, 2023
c8ed85e
Unify `ins_*` and `replace_*` constructors
alexcrichton Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Legalize stack_store in ISLE
alexcrichton committed Nov 13, 2023
commit 10a5ada057441a529fed2762679275eb5e62ec4a
5 changes: 4 additions & 1 deletion cranelift/codegen/meta/src/gen_inst.rs
Original file line number Diff line number Diff line change
@@ -1229,7 +1229,7 @@ impl IsleTarget {
}
}
fn ignore_value_lists(&self) -> bool {
matches!(self, IsleTarget::Opt | IsleTarget::Legalize)
matches!(self, IsleTarget::Opt)
}
fn match_type(&self) -> bool {
matches!(self, IsleTarget::Opt)
@@ -1627,6 +1627,9 @@ fn gen_insn_constructor(
common_ctor: &str,
ret_ty: &str,
) {
if inst.format.has_value_list {
return;
}
// Generate a constructor if this is the mid-end prelude.
let input_tys = inst
.operands_in
2 changes: 1 addition & 1 deletion cranelift/codegen/src/context.rs
Original file line number Diff line number Diff line change
@@ -290,8 +290,8 @@ impl Context {
self.loop_analysis.clear();

// Run some specific legalizations only.
simple_legalize(&mut self.func, &mut self.cfg, isa);
isa.legalize_function(&mut self.func, &mut self.cfg);
simple_legalize(&mut self.func, &mut self.cfg, isa);
self.verify_if(isa)
}

16 changes: 16 additions & 0 deletions cranelift/codegen/src/isa/riscv64/legalize.isle
Original file line number Diff line number Diff line change
@@ -26,6 +26,13 @@
(extern constructor value_array_2_ctor value_array_2_ctor)
(decl value_array_3_ctor (Value Value Value) ValueArray3)
(extern constructor value_array_3_ctor value_array_3_ctor)
(decl value_list_slice (ValueSlice) ValueList)
(extern extractor infallible value_list_slice value_list_slice)
(decl value_slice_unwrap (Value ValueSlice) ValueSlice)
(extern extractor value_slice_unwrap value_slice_unwrap)
(decl unwrap_head_value_list_1 (Value ValueSlice) ValueList)
(extractor (unwrap_head_value_list_1 head tail)
(value_list_slice (value_slice_unwrap head tail)))

(decl pure first_result (Inst) Value)
(extern constructor first_result first_result)
@@ -48,6 +55,8 @@
;; all backends in addition to backend-specific legalization.
(decl partial legalize (Inst) Inst)

;; ========= `{u,s}extend` ====================================================

;; Transform extend-to-i128 to an `iconcat` instruction
(rule 0 (legalize (has_type $I128 (uextend x @ (value_type (fits_in_32 _)))))
(replace_iconcat $I64 (ins_uextend $I64 x) (ins_i64 0)))
@@ -58,3 +67,10 @@
(replace_iconcat $I64 val64 (ins_sshr $I64 val64 (ins_i64 63)))))
(rule 1 (legalize (has_type $I128 (sextend x @ (value_type $I64))))
(replace_iconcat $I64 x (ins_sshr $I64 x (ins_i64 63))))

;; ========= `stack_store` ====================================================

;; stack_store(val, slot, offset) => store(val, stack_addr(slot, offset), 0)
(rule (legalize (stack_store val @ (value_type ty) slot offset))
(let ((addr Value (ins_stack_addr $I64 slot offset)))
(replace_store ty (mem_flags_notrap) val addr (i32_to_offset32 0))))
13 changes: 13 additions & 0 deletions cranelift/codegen/src/isa/riscv64/legalize.rs
Original file line number Diff line number Diff line change
@@ -77,6 +77,19 @@ impl generated::Context for Legalize<'_> {
}
}

fn value_list_slice(&mut self, list: ValueList) -> ValueSlice {
(list, 0)
}

fn value_slice_unwrap(&mut self, slice: ValueSlice) -> Option<(Value, ValueSlice)> {
let (list, off) = slice;
if let Some(val) = list.get(off, &self.pos.func.dfg.value_lists) {
Some((val, (list, off + 1)))
} else {
None
}
}

fn value_array_2_ctor(&mut self, arg0: Value, arg1: Value) -> ValueArray2 {
[arg0, arg1]
}
6 changes: 6 additions & 0 deletions cranelift/codegen/src/isle_prelude.rs
Original file line number Diff line number Diff line change
@@ -828,6 +828,12 @@ macro_rules! isle_common_prelude_methods {
MemFlags::trusted()
}

fn mem_flags_notrap(&mut self) -> MemFlags {
let mut mflags = MemFlags::new();
mflags.set_notrap();
mflags
}

#[inline]
fn intcc_unsigned(&mut self, x: &IntCC) -> IntCC {
x.unsigned()
4 changes: 4 additions & 0 deletions cranelift/codegen/src/prelude.isle
Original file line number Diff line number Diff line change
@@ -337,6 +337,10 @@
(decl pure mem_flags_trusted () MemFlags)
(extern constructor mem_flags_trusted mem_flags_trusted)

;; `MemFlags::notrap`
(decl pure mem_flags_notrap () MemFlags)
(extern constructor mem_flags_notrap mem_flags_notrap)

;;;; Helpers for Working with Flags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Swap args of an IntCC flag.