[meta] Introduce the Immediates structure instead of using dynamic lookup;

This commit is contained in:
Benjamin Bouvier
2019-09-04 16:26:55 +02:00
parent bafd79330d
commit 29e3ec51c1
10 changed files with 369 additions and 363 deletions

View File

@@ -8,12 +8,13 @@ use crate::cdsl::operands::{create_operand as operand, create_operand_doc as ope
use crate::cdsl::type_inference::Constraint::WiderOrEq;
use crate::cdsl::types::{LaneType, ValueType};
use crate::cdsl::typevar::{Interval, TypeSetBuilder, TypeVar};
use crate::shared::immediates::Immediates;
use crate::shared::{types, OperandKinds};
pub fn define(
all_instructions: &mut AllInstructions,
format_registry: &FormatRegistry,
immediates: &OperandKinds,
imm: &Immediates,
entities: &OperandKinds,
) -> InstructionGroup {
let mut ig = InstructionGroupBuilder::new(
@@ -24,20 +25,6 @@ pub fn define(
);
// Operand kind shorthands.
let intcc = immediates.by_name("intcc");
let floatcc = immediates.by_name("floatcc");
let trapcode = immediates.by_name("trapcode");
let uimm8 = immediates.by_name("uimm8");
let uimm32 = immediates.by_name("uimm32");
let imm64 = immediates.by_name("imm64");
let uimm128 = immediates.by_name("uimm128");
let offset32 = immediates.by_name("offset32");
let memflags = immediates.by_name("memflags");
let ieee32 = immediates.by_name("ieee32");
let ieee64 = immediates.by_name("ieee64");
let boolean = immediates.by_name("boolean");
let regunit = immediates.by_name("regunit");
let ebb = entities.by_name("ebb");
let jump_table = entities.by_name("jump_table");
let variable_args = entities.by_name("variable_args");
@@ -142,7 +129,7 @@ pub fn define(
let addr = &operand("addr", iAddr);
let c = &operand_doc("c", Testable, "Controlling value to test");
let Cond = &operand("Cond", intcc);
let Cond = &operand("Cond", &imm.intcc);
let x = &operand("x", iB);
let y = &operand("y", iB);
let EBB = &operand_doc("EBB", ebb, "Destination extended basic block");
@@ -253,7 +240,7 @@ pub fn define(
.is_branch(true),
);
let Cond = &operand("Cond", floatcc);
let Cond = &operand("Cond", &imm.floatcc);
let f = &operand("f", fflags);
ig.push(
@@ -300,7 +287,7 @@ pub fn define(
// These are the instructions which br_table legalizes to: they perform address computations,
// using pointer-sized integers, so their type variables are more constrained.
let x = &operand_doc("x", iAddr, "index into jump table");
let Size = &operand_doc("Size", uimm8, "Size in bytes");
let Size = &operand_doc("Size", &imm.uimm8, "Size in bytes");
ig.push(
Inst::new(
@@ -365,7 +352,7 @@ pub fn define(
.can_store(true),
);
let code = &operand("code", trapcode);
let code = &operand("code", &imm.trapcode);
ig.push(
Inst::new(
@@ -418,7 +405,7 @@ pub fn define(
.can_trap(true),
);
let Cond = &operand("Cond", intcc);
let Cond = &operand("Cond", &imm.intcc);
let f = &operand("f", iflags);
ig.push(
@@ -432,7 +419,7 @@ pub fn define(
.can_trap(true),
);
let Cond = &operand("Cond", floatcc);
let Cond = &operand("Cond", &imm.floatcc);
let f = &operand("f", fflags);
ig.push(
@@ -539,11 +526,11 @@ pub fn define(
);
let SS = &operand("SS", stack_slot);
let Offset = &operand_doc("Offset", offset32, "Byte offset from base address");
let Offset = &operand_doc("Offset", &imm.offset32, "Byte offset from base address");
let x = &operand_doc("x", Mem, "Value to be stored");
let a = &operand_doc("a", Mem, "Value loaded");
let p = &operand("p", iAddr);
let MemFlags = &operand("MemFlags", memflags);
let MemFlags = &operand("MemFlags", &imm.memflags);
let args = &operand_doc("args", variable_args, "Address arguments");
ig.push(
@@ -876,7 +863,7 @@ pub fn define(
let x = &operand_doc("x", Mem, "Value to be stored");
let a = &operand_doc("a", Mem, "Value loaded");
let Offset = &operand_doc("Offset", offset32, "In-bounds offset into stack slot");
let Offset = &operand_doc("Offset", &imm.offset32, "In-bounds offset into stack slot");
ig.push(
Inst::new(
@@ -962,7 +949,7 @@ pub fn define(
let H = &operand("H", heap);
let p = &operand("p", HeapOffset);
let Size = &operand_doc("Size", uimm32, "Size in bytes");
let Size = &operand_doc("Size", &imm.uimm32, "Size in bytes");
ig.push(
Inst::new(
@@ -990,7 +977,7 @@ pub fn define(
);
let T = &operand("T", table);
let p = &operand("p", TableOffset);
let Offset = &operand_doc("Offset", offset32, "Byte offset from element address");
let Offset = &operand_doc("Offset", &imm.offset32, "Byte offset from element address");
ig.push(
Inst::new(
@@ -1013,7 +1000,7 @@ pub fn define(
.operands_out(vec![addr]),
);
let N = &operand("N", imm64);
let N = &operand("N", &imm.imm64);
let a = &operand_doc("a", Int, "A constant integer scalar or vector value");
ig.push(
@@ -1030,7 +1017,7 @@ pub fn define(
.operands_out(vec![a]),
);
let N = &operand("N", ieee32);
let N = &operand("N", &imm.ieee32);
let a = &operand_doc("a", f32_, "A constant f32 scalar value");
ig.push(
@@ -1046,7 +1033,7 @@ pub fn define(
.operands_out(vec![a]),
);
let N = &operand("N", ieee64);
let N = &operand("N", &imm.ieee64);
let a = &operand_doc("a", f64_, "A constant f64 scalar value");
ig.push(
@@ -1062,7 +1049,7 @@ pub fn define(
.operands_out(vec![a]),
);
let N = &operand("N", boolean);
let N = &operand("N", &imm.boolean);
let a = &operand_doc("a", Bool, "A constant boolean scalar or vector value");
ig.push(
@@ -1079,7 +1066,11 @@ pub fn define(
.operands_out(vec![a]),
);
let N = &operand_doc("N", uimm128, "The 16 immediate bytes of a 128-bit vector");
let N = &operand_doc(
"N",
&imm.uimm128,
"The 16 immediate bytes of a 128-bit vector",
);
let a = &operand_doc("a", TxN, "A constant vector value");
ig.push(
@@ -1137,7 +1128,7 @@ pub fn define(
.operands_out(vec![a]),
);
let cc = &operand_doc("cc", intcc, "Controlling condition code");
let cc = &operand_doc("cc", &imm.intcc, "Controlling condition code");
let flags = &operand_doc("flags", iflags, "The machine's flag register");
ig.push(
@@ -1217,8 +1208,8 @@ pub fn define(
.can_load(true),
);
let src = &operand("src", regunit);
let dst = &operand("dst", regunit);
let src = &operand("src", &imm.regunit);
let dst = &operand("dst", &imm.regunit);
ig.push(
Inst::new(
@@ -1302,7 +1293,7 @@ pub fn define(
.other_side_effects(true),
);
let Offset = &operand_doc("Offset", imm64, "Offset from current stack pointer");
let Offset = &operand_doc("Offset", &imm.imm64, "Offset from current stack pointer");
ig.push(
Inst::new(
@@ -1319,7 +1310,7 @@ pub fn define(
.other_side_effects(true),
);
let Offset = &operand_doc("Offset", imm64, "Offset from current stack pointer");
let Offset = &operand_doc("Offset", &imm.imm64, "Offset from current stack pointer");
ig.push(
Inst::new(
@@ -1498,7 +1489,7 @@ pub fn define(
let x = &operand_doc("x", TxN, "SIMD vector to modify");
let y = &operand_doc("y", &TxN.lane_of(), "New lane value");
let Idx = &operand_doc("Idx", uimm8, "Lane index");
let Idx = &operand_doc("Idx", &imm.uimm8, "Lane index");
ig.push(
Inst::new(
@@ -1532,7 +1523,7 @@ pub fn define(
);
let a = &operand("a", &Int.as_bool());
let Cond = &operand("Cond", intcc);
let Cond = &operand("Cond", &imm.intcc);
let x = &operand("x", Int);
let y = &operand("y", Int);
@@ -1566,7 +1557,7 @@ pub fn define(
let a = &operand("a", b1);
let x = &operand("x", iB);
let Y = &operand("Y", imm64);
let Y = &operand("Y", &imm.imm64);
ig.push(
Inst::new(
@@ -1757,7 +1748,7 @@ pub fn define(
let a = &operand("a", iB);
let x = &operand("x", iB);
let Y = &operand("Y", imm64);
let Y = &operand("Y", &imm.imm64);
ig.push(
Inst::new(
@@ -2092,7 +2083,7 @@ pub fn define(
);
let x = &operand("x", iB);
let Y = &operand("Y", imm64);
let Y = &operand("Y", &imm.imm64);
let a = &operand("a", iB);
ig.push(
@@ -2145,7 +2136,7 @@ pub fn define(
let x = &operand_doc("x", Int, "Scalar or vector value to shift");
let y = &operand_doc("y", iB, "Number of bits to shift");
let Y = &operand("Y", imm64);
let Y = &operand("Y", &imm.imm64);
let a = &operand("a", Int);
ig.push(
@@ -2375,7 +2366,7 @@ pub fn define(
.simd_lanes(Interval::All)
.build(),
);
let Cond = &operand("Cond", floatcc);
let Cond = &operand("Cond", &imm.floatcc);
let x = &operand("x", Float);
let y = &operand("y", Float);
let a = &operand("a", &Float.as_bool());
@@ -2687,7 +2678,7 @@ pub fn define(
.operands_out(vec![a]),
);
let Cond = &operand("Cond", intcc);
let Cond = &operand("Cond", &imm.intcc);
let f = &operand("f", iflags);
let a = &operand("a", b1);
@@ -2705,7 +2696,7 @@ pub fn define(
.operands_out(vec![a]),
);
let Cond = &operand("Cond", floatcc);
let Cond = &operand("Cond", &imm.floatcc);
let f = &operand("f", fflags);
ig.push(