Files
wasmtime/cranelift/isle/isle/isle_examples/link/iflets.isle
Chris Fallin 5b7d56f6f7 ISLE: add support for extended left-hand sides with if-let clauses. (#4072)
This PR adds support for `if-let` clauses, as proposed in
bytecodealliance/rfcs#21. These clauses augment the left-hand side
(pattern-matching phase) of rules in the ISLE instruction-selection DSL
with sub-patterns matching on sub-expressions. The ability to list
additional match operations to perform, out-of-line from the original
toplevel pattern, greatly simplifies some idioms. See the RFC for more
details and examples of use.
2022-04-28 16:37:11 -07:00

30 lines
469 B
Common Lisp

(type u32 (primitive u32))
(decl pure A (u32 u32) u32)
(extern constructor A A)
(decl B (u32 u32) u32)
(extern extractor B B)
(decl C (u32 u32 u32 u32) u32)
(decl pure predicate () u32)
(rule (predicate) 1)
(rule (C a b c (B d e))
(if-let (B f g) d)
(if-let h (A a b))
(A h a))
(rule (C a b c d)
(if (predicate))
42)
(rule (C a b a b)
(if-let x (D a b))
x)
(decl pure D (u32 u32) u32)
(rule (D x 0) x)
(rule (D 0 x) x)