Skip to content

cranelift: ISLE wrapper for constructing constants #10528

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions cranelift/codegen/src/isle_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,15 @@ macro_rules! isle_common_prelude_methods {
}
}

#[inline]
fn ty_vec(&mut self, ty: Type) -> Option<Type> {
if ty.is_vector() {
Some(ty)
} else {
None
}
}

#[inline]
fn ty_vec64_int(&mut self, ty: Type) -> Option<Type> {
if ty.is_vector() && ty.bits() == 64 && ty.lane_type().is_int() {
Expand Down
4 changes: 4 additions & 0 deletions cranelift/codegen/src/prelude.isle
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@
(decl ty_dyn_vec128 (Type) Type)
(extern extractor ty_dyn_vec128 ty_dyn_vec128)

;; An extractor that only matches vector.
(decl ty_vec (Type) Type)
(extern extractor ty_vec ty_vec)

;; An extractor that only matches 64-bit vector types with integer
;; lanes (I8X8, I16X4, I32X2)
(decl ty_vec64_int (Type) Type)
Expand Down
9 changes: 9 additions & 0 deletions cranelift/codegen/src/prelude_opt.isle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@
(iconst ty (imm64 c)))
(rule 1 (iconst_u $I128 c) (uextend $I128 (iconst_u $I64 c)))

;; Constructs a constant value node from a 64-bit immediate, adapting it
;; to the specified type. For 128-bit integers, the immediate is zero-extended;
;; for other integer types, a direct iconst is generated; and for vector types,
;; the constant is splatted across all lanes.
(decl const (Type Imm64) Value)
(rule 2 (const $I128 n) (uextend $I128 (iconst $I64 n)))
(rule 1 (const (ty_int ty) n) (iconst ty n))
(rule 0 (const (ty_vec ty) n) (splat ty (const (lane_type ty) n)))

;; These take `Value`, rather than going through `inst_data_tupled`, because
;; most of the time they want to return the original `Value`, and it would be
;; a waste to need to re-GVN the instruction data in those cases.
Expand Down