refactor: change LowerCtx::get_immediate to return a DataValue
This change abstracts away (from the perspective of the new backend) how immediate values are stored in InstructionData. It gathers large immediates from necessary places (e.g. constant pool) and delegates to `InstructionData::imm_value` for the rest. This refactor only touches original users of `LowerCtx::get_immediate` but a future change could do the same for any place the new backend is accessing InstructionData directly to retrieve immediates.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
use crate::ir::condcodes::{FloatCC, IntCC};
|
||||
use crate::ir::types::*;
|
||||
use crate::ir::Inst as IRInst;
|
||||
use crate::ir::{InstructionData, Opcode, Type};
|
||||
use crate::ir::{Opcode, Type};
|
||||
use crate::machinst::lower::*;
|
||||
use crate::machinst::*;
|
||||
use crate::CodegenResult;
|
||||
@@ -20,6 +20,7 @@ use crate::isa::aarch64::AArch64Backend;
|
||||
|
||||
use super::lower_inst;
|
||||
|
||||
use crate::data_value::DataValue;
|
||||
use log::{debug, trace};
|
||||
use regalloc::{Reg, RegClass, Writable};
|
||||
use smallvec::SmallVec;
|
||||
@@ -126,22 +127,9 @@ pub(crate) fn const_param_to_u128<C: LowerCtx<I = Inst>>(
|
||||
ctx: &mut C,
|
||||
inst: IRInst,
|
||||
) -> Option<u128> {
|
||||
let data = match ctx.data(inst) {
|
||||
&InstructionData::Shuffle { mask, .. } => ctx.get_immediate(mask),
|
||||
&InstructionData::UnaryConst {
|
||||
constant_handle, ..
|
||||
} => ctx.get_constant_data(constant_handle),
|
||||
_ => return None,
|
||||
};
|
||||
let data = data.clone().into_vec();
|
||||
|
||||
if data.len() == 16 {
|
||||
let mut bytes = [0u8; 16];
|
||||
|
||||
bytes.copy_from_slice(&data);
|
||||
Some(u128::from_le_bytes(bytes))
|
||||
} else {
|
||||
None
|
||||
match ctx.get_immediate(inst) {
|
||||
Some(DataValue::V128(bytes)) => Some(u128::from_le_bytes(bytes)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Lowering rules for X64.
|
||||
|
||||
use crate::data_value::DataValue;
|
||||
use crate::ir::{
|
||||
condcodes::FloatCC, condcodes::IntCC, types, AbiParam, ArgumentPurpose, ExternalName,
|
||||
Inst as IRInst, InstructionData, LibCall, Opcode, Signature, Type,
|
||||
@@ -2985,10 +2986,9 @@ fn lower_insn_to_regs<C: LowerCtx<I = Inst>>(
|
||||
let lhs_ty = ctx.input_ty(insn, 0);
|
||||
let lhs = put_input_in_reg(ctx, inputs[0]);
|
||||
let rhs = put_input_in_reg(ctx, inputs[1]);
|
||||
let mask = if let &InstructionData::Shuffle { mask, .. } = ctx.data(insn) {
|
||||
ctx.get_immediate(mask).clone()
|
||||
} else {
|
||||
unreachable!("shuffle should always have the shuffle format")
|
||||
let mask = match ctx.get_immediate(insn) {
|
||||
Some(DataValue::V128(bytes)) => bytes.to_vec(),
|
||||
_ => unreachable!("shuffle should always have a 16-byte immediate"),
|
||||
};
|
||||
|
||||
// A mask-building helper: in 128-bit SIMD, 0-15 indicate which lane to read from and a
|
||||
|
||||
Reference in New Issue
Block a user