cranelift_codegen_meta/shared/entities.rs
1use crate::cdsl::operands::{OperandKind, OperandKindFields};
2
3/// Small helper to initialize an OperandBuilder with the right kind, for a given name and doc.
4fn new(format_field_name: &'static str, rust_type: &'static str, doc: &'static str) -> OperandKind {
5 OperandKind::new(
6 format_field_name,
7 rust_type,
8 OperandKindFields::EntityRef,
9 doc,
10 )
11}
12
13pub(crate) struct EntityRefs {
14 /// A reference to a basic block in the same function, with its arguments provided.
15 /// This is primarily used in control flow instructions.
16 pub(crate) block_call: OperandKind,
17
18 /// A reference to a basic block in the same function, with its arguments provided.
19 /// This is primarily used in control flow instructions.
20 pub(crate) block_then: OperandKind,
21
22 /// A reference to a basic block in the same function, with its arguments provided.
23 /// This is primarily used in control flow instructions.
24 pub(crate) block_else: OperandKind,
25
26 /// A reference to a stack slot declared in the function preamble.
27 pub(crate) stack_slot: OperandKind,
28
29 /// A reference to a dynamic_stack slot declared in the function preamble.
30 pub(crate) dynamic_stack_slot: OperandKind,
31
32 /// A reference to a global value.
33 pub(crate) global_value: OperandKind,
34
35 /// A reference to a function signature declared in the function preamble.
36 /// This is used to provide the call signature in a call_indirect instruction.
37 pub(crate) sig_ref: OperandKind,
38
39 /// A reference to an external function declared in the function preamble.
40 /// This is used to provide the callee and signature in a call instruction.
41 pub(crate) func_ref: OperandKind,
42
43 /// A reference to a jump table declared in the function preamble.
44 pub(crate) jump_table: OperandKind,
45
46 /// A reference to an exception table declared in the function preamble.
47 pub(crate) exception_table: OperandKind,
48
49 /// A variable-sized list of value operands. Use for Block and function call arguments.
50 pub(crate) varargs: OperandKind,
51
52 /// A constant stored in the constant pool.
53 ///
54 /// This operand is used to pass constants to instructions like `vconst`
55 /// while storing the actual bytes in the constant pool.
56 pub(crate) pool_constant: OperandKind,
57
58 /// An unsigned 128-bit immediate integer operand, stored out-of-line in the
59 /// `DataFlowGraph::immediates` pool.
60 ///
61 /// This operand is used to pass entire 128-bit vectors as immediates to instructions like
62 /// `shuffle` and `mask`.
63 pub(crate) uimm128: OperandKind,
64}
65
66impl EntityRefs {
67 pub fn new() -> Self {
68 Self {
69 block_call: new(
70 "destination",
71 "ir::BlockCall",
72 "a basic block in the same function, with its arguments provided.",
73 ),
74
75 block_then: new(
76 "block_then",
77 "ir::BlockCall",
78 "a basic block in the same function, with its arguments provided.",
79 ),
80
81 block_else: new(
82 "block_else",
83 "ir::BlockCall",
84 "a basic block in the same function, with its arguments provided.",
85 ),
86
87 stack_slot: new("stack_slot", "ir::StackSlot", "A stack slot"),
88
89 dynamic_stack_slot: new(
90 "dynamic_stack_slot",
91 "ir::DynamicStackSlot",
92 "A dynamic stack slot",
93 ),
94
95 global_value: new("global_value", "ir::GlobalValue", "A global value."),
96
97 sig_ref: new("sig_ref", "ir::SigRef", "A function signature."),
98
99 func_ref: new("func_ref", "ir::FuncRef", "An external function."),
100
101 jump_table: new("table", "ir::JumpTable", "A jump table."),
102
103 exception_table: new("exception", "ir::ExceptionTable", "An exception table."),
104
105 varargs: OperandKind::new(
106 "",
107 "&[Value]",
108 OperandKindFields::VariableArgs,
109 r#"
110 A variable size list of `value` operands.
111
112 Use this to represent arguments passed to a function call, arguments
113 passed to a basic block, or a variable number of results
114 returned from an instruction.
115 "#,
116 ),
117
118 pool_constant: new(
119 "constant_handle",
120 "ir::Constant",
121 "A constant stored in the constant pool.",
122 ),
123
124 uimm128: new(
125 "imm",
126 "ir::Immediate",
127 "A 128-bit immediate unsigned integer.",
128 ),
129 }
130 }
131}