Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/codegen/meta/src/shared/entities.rs
1693 views
1
use crate::cdsl::operands::{OperandKind, OperandKindFields};
2
3
/// Small helper to initialize an OperandBuilder with the right kind, for a given name and doc.
4
fn 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
13
pub(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 basic block in the same function, without any arguments.
27
/// This is primarily used to refer to block `try_call` terminators to get
28
/// exception metadata (e.g., resume PCs) as first-class values.
29
pub(crate) raw_block: OperandKind,
30
31
/// A reference to a stack slot declared in the function preamble.
32
pub(crate) stack_slot: OperandKind,
33
34
/// A reference to a dynamic_stack slot declared in the function preamble.
35
pub(crate) dynamic_stack_slot: OperandKind,
36
37
/// A reference to a global value.
38
pub(crate) global_value: OperandKind,
39
40
/// A reference to a function signature declared in the function preamble.
41
/// This is used to provide the call signature in a call_indirect instruction.
42
pub(crate) sig_ref: OperandKind,
43
44
/// A reference to an external function declared in the function preamble.
45
/// This is used to provide the callee and signature in a call instruction.
46
pub(crate) func_ref: OperandKind,
47
48
/// A reference to a jump table declared in the function preamble.
49
pub(crate) jump_table: OperandKind,
50
51
/// A reference to an exception table declared in the function preamble.
52
pub(crate) exception_table: OperandKind,
53
54
/// A variable-sized list of value operands. Use for Block and function call arguments.
55
pub(crate) varargs: OperandKind,
56
57
/// A constant stored in the constant pool.
58
///
59
/// This operand is used to pass constants to instructions like `vconst`
60
/// while storing the actual bytes in the constant pool.
61
pub(crate) pool_constant: OperandKind,
62
63
/// An unsigned 128-bit immediate integer operand, stored out-of-line in the
64
/// `DataFlowGraph::immediates` pool.
65
///
66
/// This operand is used to pass entire 128-bit vectors as immediates to instructions like
67
/// `shuffle` and `mask`.
68
pub(crate) uimm128: OperandKind,
69
}
70
71
impl EntityRefs {
72
pub fn new() -> Self {
73
Self {
74
block_call: new(
75
"destination",
76
"ir::BlockCall",
77
"a basic block in the same function, with its arguments provided.",
78
),
79
80
block_then: new(
81
"block_then",
82
"ir::BlockCall",
83
"a basic block in the same function, with its arguments provided.",
84
),
85
86
block_else: new(
87
"block_else",
88
"ir::BlockCall",
89
"a basic block in the same function, with its arguments provided.",
90
),
91
92
raw_block: new(
93
"raw_block",
94
"ir::Block",
95
"a basic block in the same function, with no arguments provided.",
96
),
97
98
stack_slot: new("stack_slot", "ir::StackSlot", "A stack slot"),
99
100
dynamic_stack_slot: new(
101
"dynamic_stack_slot",
102
"ir::DynamicStackSlot",
103
"A dynamic stack slot",
104
),
105
106
global_value: new("global_value", "ir::GlobalValue", "A global value."),
107
108
sig_ref: new("sig_ref", "ir::SigRef", "A function signature."),
109
110
func_ref: new("func_ref", "ir::FuncRef", "An external function."),
111
112
jump_table: new("table", "ir::JumpTable", "A jump table."),
113
114
exception_table: new("exception", "ir::ExceptionTable", "An exception table."),
115
116
varargs: OperandKind::new(
117
"",
118
"&[Value]",
119
OperandKindFields::VariableArgs,
120
r#"
121
A variable size list of `value` operands.
122
123
Use this to represent arguments passed to a function call, arguments
124
passed to a basic block, or a variable number of results
125
returned from an instruction.
126
"#,
127
),
128
129
pool_constant: new(
130
"constant_handle",
131
"ir::Constant",
132
"A constant stored in the constant pool.",
133
),
134
135
uimm128: new(
136
"imm",
137
"ir::Immediate",
138
"A 128-bit immediate unsigned integer.",
139
),
140
}
141
}
142
}
143
144