Skip to content

Commit

Permalink
Merge pull request #3703 from uweigand/isle-prep-common
Browse files Browse the repository at this point in the history
ISLE standard prelude: Additional types and helpers
  • Loading branch information
fitzgen authored Jan 20, 2022
2 parents 9321a9d + be60a19 commit 0670d7b
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 29 deletions.
9 changes: 6 additions & 3 deletions cranelift/codegen/src/isa/aarch64/lower/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use super::{
Inst as MInst, JTSequenceInfo, MachLabel, MoveWideConst, NarrowValueMode, Opcode, OperandSize,
PairAMode, Reg, ScalarSize, ShiftOpAndAmt, UImm5, VectorSize, NZCV,
};
use crate::isa::aarch64::settings::Flags;
use crate::isa::aarch64::settings::Flags as IsaFlags;
use crate::machinst::isle::*;
use crate::settings::Flags;
use crate::{
binemit::CodeOffset,
ir::{
Expand All @@ -36,7 +37,8 @@ type BoxExternalName = Box<ExternalName>;
/// The main entry point for lowering with ISLE.
pub(crate) fn lower<C>(
lower_ctx: &mut C,
isa_flags: &Flags,
flags: &Flags,
isa_flags: &IsaFlags,
outputs: &[InsnOutput],
inst: Inst,
) -> Result<(), ()>
Expand All @@ -45,6 +47,7 @@ where
{
lower_common(
lower_ctx,
flags,
isa_flags,
outputs,
inst,
Expand All @@ -63,7 +66,7 @@ pub struct SinkableAtomicLoad {
atomic_addr: Value,
}

impl<C> generated_code::Context for IsleContext<'_, C, Flags, 6>
impl<C> generated_code::Context for IsleContext<'_, C, Flags, IsaFlags, 6>
where
C: LowerCtx<I = MInst>,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/clif.isle f176ef3bba99365
src/prelude.isle 22dd5ff133398960
src/prelude.isle 51d2aef2566c1c96
src/isa/aarch64/inst.isle f946561093de4ff5
src/isa/aarch64/lower.isle 2d2e1e076a0c8a23
16 changes: 9 additions & 7 deletions cranelift/codegen/src/isa/aarch64/lower/isle/generated_code.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/aarch64/lower_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) fn lower_insn_to_regs<C: LowerCtx<I = Inst>>(
None
};

if let Ok(()) = super::lower::isle::lower(ctx, isa_flags, &outputs, insn) {
if let Ok(()) = super::lower::isle::lower(ctx, flags, isa_flags, &outputs, insn) {
return Ok(());
}

Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/x64/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ fn lower_insn_to_regs<C: LowerCtx<I = Inst>>(
None
};

if let Ok(()) = isle::lower(ctx, isa_flags, &outputs, insn) {
if let Ok(()) = isle::lower(ctx, flags, isa_flags, &outputs, insn) {
return Ok(());
}

Expand Down
9 changes: 6 additions & 3 deletions cranelift/codegen/src/isa/x64/lower/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use crate::{
},
regs, x64_map_regs,
},
settings::Flags,
settings::Flags as IsaFlags,
},
machinst::{isle::*, InsnInput, InsnOutput, LowerCtx, VCodeConstantData},
settings::Flags,
};
use std::convert::TryFrom;

Expand All @@ -32,7 +33,8 @@ pub struct SinkableLoad {
/// The main entry point for lowering with ISLE.
pub(crate) fn lower<C>(
lower_ctx: &mut C,
isa_flags: &Flags,
flags: &Flags,
isa_flags: &IsaFlags,
outputs: &[InsnOutput],
inst: Inst,
) -> Result<(), ()>
Expand All @@ -41,6 +43,7 @@ where
{
lower_common(
lower_ctx,
flags,
isa_flags,
outputs,
inst,
Expand All @@ -49,7 +52,7 @@ where
)
}

impl<C> generated_code::Context for IsleContext<'_, C, Flags, 6>
impl<C> generated_code::Context for IsleContext<'_, C, Flags, IsaFlags, 6>
where
C: LowerCtx<I = MInst>,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/clif.isle f176ef3bba99365
src/prelude.isle 22dd5ff133398960
src/prelude.isle 51d2aef2566c1c96
src/isa/x64/inst.isle 61004acbb1289816
src/isa/x64/lower.isle 82db7f7d47ac7809
16 changes: 9 additions & 7 deletions cranelift/codegen/src/isa/x64/lower/isle/generated_code.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions cranelift/codegen/src/machinst/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ macro_rules! isle_prelude_methods {
TrapCode::IntegerOverflow
}

fn trap_code_bad_conversion_to_integer(&mut self) -> TrapCode {
TrapCode::BadConversionToInteger
}

fn avoid_div_traps(&mut self, _: Type) -> Option<()> {
if self.flags.avoid_div_traps() {
Some(())
} else {
None
}
}

fn nonzero_u64_from_imm64(&mut self, val: Imm64) -> Option<u64> {
match val.bits() {
0 => None,
Expand All @@ -285,12 +297,13 @@ macro_rules! isle_prelude_methods {

/// This structure is used to implement the ISLE-generated `Context` trait and
/// internally has a temporary reference to a machinst `LowerCtx`.
pub(crate) struct IsleContext<'a, C: LowerCtx, F, const N: usize>
pub(crate) struct IsleContext<'a, C: LowerCtx, F, I, const N: usize>
where
[C::I; N]: smallvec::Array,
{
pub lower_ctx: &'a mut C,
pub isa_flags: &'a F,
pub flags: &'a F,
pub isa_flags: &'a I,
pub emitted_insts: SmallVec<[C::I; N]>,
}

Expand All @@ -299,12 +312,13 @@ where
/// The `isle_lower` argument here is an ISLE-generated function for `lower` and
/// then this function otherwise handles register mapping and such around the
/// lowering.
pub(crate) fn lower_common<C, F, const N: usize>(
pub(crate) fn lower_common<C, F, I, const N: usize>(
lower_ctx: &mut C,
isa_flags: &F,
flags: &F,
isa_flags: &I,
outputs: &[InsnOutput],
inst: Inst,
isle_lower: fn(&mut IsleContext<'_, C, F, N>, Inst) -> Option<ValueRegs>,
isle_lower: fn(&mut IsleContext<'_, C, F, I, N>, Inst) -> Option<ValueRegs>,
map_regs: fn(&mut C::I, &RegRenamer),
) -> Result<(), ()>
where
Expand All @@ -315,6 +329,7 @@ where
// internal heap allocations.
let mut isle_ctx = IsleContext {
lower_ctx,
flags,
isa_flags,
emitted_insts: SmallVec::new(),
};
Expand Down
12 changes: 12 additions & 0 deletions cranelift/codegen/src/prelude.isle
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
(extern const $I64 Type)
(extern const $I128 Type)

(extern const $R32 Type)
(extern const $R64 Type)

(extern const $F32 Type)
(extern const $F64 Type)

Expand Down Expand Up @@ -338,3 +341,12 @@

(decl trap_code_integer_overflow () TrapCode)
(extern constructor trap_code_integer_overflow trap_code_integer_overflow)

(decl trap_code_bad_conversion_to_integer () TrapCode)
(extern constructor trap_code_bad_conversion_to_integer trap_code_bad_conversion_to_integer)

;;;; Helpers for accessing compilation flags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(decl avoid_div_traps () Type)
(extern extractor avoid_div_traps avoid_div_traps)

0 comments on commit 0670d7b

Please sign in to comment.