;; Prelude definitions specific to the mid-end. ;;;;; eclass and enode access ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Extract any node(s) for the given eclass ID. (decl multi inst_data (Type InstructionData) Value) (extern extractor inst_data inst_data_etor) ;; Construct a pure node, returning a new (or deduplicated ;; already-existing) eclass ID. (decl make_inst (Type InstructionData) Value) (extern constructor make_inst make_inst_ctor) ;; Constructors for value arrays. (decl value_array_2_ctor (Value Value) ValueArray2) (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) (rule (eq ty x y) (icmp ty (IntCC.Equal) x y)) (rule (ne ty x y) (icmp ty (IntCC.NotEqual) x y)) (rule (ult ty x y) (icmp ty (IntCC.UnsignedLessThan) x y)) (rule (ule ty x y) (icmp ty (IntCC.UnsignedLessThanOrEqual) x y)) (rule (ugt ty x y) (icmp ty (IntCC.UnsignedGreaterThan) x y)) (rule (uge ty x y) (icmp ty (IntCC.UnsignedGreaterThanOrEqual) x y)) (rule (slt ty x y) (icmp ty (IntCC.SignedLessThan) x y)) (rule (sle ty x y) (icmp ty (IntCC.SignedLessThanOrEqual) x y)) (rule (sgt ty x y) (icmp ty (IntCC.SignedGreaterThan) x y)) (rule (sge ty x y) (icmp ty (IntCC.SignedGreaterThanOrEqual) x y)) ;;;;; optimization toplevel ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The main matcher rule invoked by the toplevel driver. (decl multi simplify (Value) Value) ;; Mark a node as requiring remat when used in a different block. (decl remat (Value) Value) (extern constructor remat remat) ;; Mark a node as subsuming whatever else it's rewritten from -- this ;; is definitely preferable, not just a possible option. Useful for, ;; e.g., constant propagation where we arrive at a definite "final ;; answer". (decl subsume (Value) Value) (extern constructor subsume subsume) ;;;;; constructors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (decl iconst_u64 (Type u64) Value) ;; Use a single iconst for types that fit in 64 bits. (rule 0 (iconst_u64 (ty_int_ref_scalar_64 ty) val) (if-let $true (u64_le val (ty_umax ty))) (iconst ty (imm64_masked ty val))) ;; For i128 types use a iconst, but zero extend it to i128. (rule 1 (iconst_u64 $I128 val) (uextend $I128 (iconst $I64 (imm64_masked $I64 val))))