Expand a `global_value` instruction for a load global.
(
inst: ir::Inst,
func: &mut ir::Function,
base: ir::GlobalValue,
offset: ir::immediates::Offset32,
global_type: ir::Type,
flags: ir::MemFlagsData,
isa: &dyn TargetIsa,
)
| 118 | |
| 119 | /// Expand a `global_value` instruction for a load global. |
| 120 | fn load_addr( |
| 121 | inst: ir::Inst, |
| 122 | func: &mut ir::Function, |
| 123 | base: ir::GlobalValue, |
| 124 | offset: ir::immediates::Offset32, |
| 125 | global_type: ir::Type, |
| 126 | flags: ir::MemFlagsData, |
| 127 | isa: &dyn TargetIsa, |
| 128 | ) -> WalkCommand { |
| 129 | // We need to load a pointer from the `base` global value, so insert a new `global_value` |
| 130 | // instruction. This depends on the iterative legalization loop. Note that the IR verifier |
| 131 | // detects any cycles in the `load` globals. |
| 132 | let ptr_ty = isa.pointer_type(); |
| 133 | |
| 134 | let mut pos = FuncCursor::new(func).at_inst(inst); |
| 135 | pos.use_srcloc(inst); |
| 136 | |
| 137 | // Get the value for the base. |
| 138 | let base_addr = pos.ins().global_value(ptr_ty, base); |
| 139 | |
| 140 | // Perform the load. |
| 141 | pos.func |
| 142 | .replace(inst) |
| 143 | .load(global_type, flags, base_addr, offset); |
| 144 | |
| 145 | // Need to legalize the `global_value` for the base address. |
| 146 | WalkCommand::Revisit |
| 147 | } |
| 148 | |
| 149 | /// Expand a `global_value` instruction for a symbolic name global. |
| 150 | fn symbol( |
no test coverage detected