Add source location support to FuncCursor and EncCursor.

A cursor now also remembers a current source location which will be
assigned to all new instructions created with the cursor.

The old layout::Cursor can't support source locations because it doesn't
have a reference to the full ir::Function.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-21 10:38:11 -07:00
parent b2a314a229
commit 4d4da2dc60
9 changed files with 143 additions and 38 deletions

View File

@@ -62,7 +62,7 @@ fn legalize_entry_arguments(func: &mut Function, entry: Ebb) {
// Insert position for argument conversion code.
// We want to insert instructions before the first instruction in the entry block.
// If the entry block is empty, append instructions to it instead.
let mut pos = Cursor::new(&mut func.layout).at_first_inst(entry);
let mut pos = Cursor::new(&mut func.layout, &mut func.srclocs).at_first_inst(entry);
// Keep track of the argument types in the ABI-legalized signature.
let abi_types = &func.signature.argument_types;
@@ -488,7 +488,8 @@ fn legalize_inst_arguments<ArgType>(
/// Returns `true` if any instructions were inserted.
pub fn handle_call_abi(mut inst: Inst, func: &mut Function, cfg: &ControlFlowGraph) -> bool {
let dfg = &mut func.dfg;
let pos = &mut Cursor::new(&mut func.layout).at_inst(inst);
let pos = &mut Cursor::new(&mut func.layout, &mut func.srclocs).at_inst(inst);
pos.use_srcloc(inst);
// Start by checking if the argument types already match the signature.
let sig_ref = match check_call_signature(dfg, inst) {
@@ -530,7 +531,8 @@ pub fn handle_call_abi(mut inst: Inst, func: &mut Function, cfg: &ControlFlowGra
pub fn handle_return_abi(inst: Inst, func: &mut Function, cfg: &ControlFlowGraph) -> bool {
let dfg = &mut func.dfg;
let sig = &mut func.signature;
let pos = &mut Cursor::new(&mut func.layout).at_inst(inst);
let pos = &mut Cursor::new(&mut func.layout, &mut func.srclocs).at_inst(inst);
pos.use_srcloc(inst);
// Check if the returned types already match the signature.
if check_return_signature(dfg, inst, sig) {

View File

@@ -51,6 +51,7 @@ fn deref_addr(inst: ir::Inst, func: &mut ir::Function, base: ir::GlobalVar, offs
// detects any cycles in the `deref` globals.
let ptr_ty = func.dfg.value_type(func.dfg.first_result(inst));
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
let base_addr = pos.ins().global_addr(ptr_ty, base);
// TODO: We could probably set both `notrap` and `aligned` on this load instruction.

View File

@@ -48,6 +48,7 @@ fn dynamic_addr(
let addr_ty = func.dfg.value_type(func.dfg.first_result(inst));
let min_size = func.heaps[heap].min_size.into();
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Start with the bounds check. Trap if `offset + size > bound`.
let bound_addr = pos.ins().global_addr(addr_ty, bound_gv);
@@ -99,6 +100,7 @@ fn static_addr(
let offset_ty = func.dfg.value_type(offset);
let addr_ty = func.dfg.value_type(func.dfg.first_result(inst));
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Start with the bounds check. Trap if `offset + size > bound`.
if size > bound {
@@ -147,6 +149,7 @@ fn offset_addr(
func: &mut ir::Function,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `offset` to `addr_ty`.
if offset_ty != addr_ty {

View File

@@ -138,6 +138,7 @@ fn expand_cond_trap(inst: ir::Inst, func: &mut ir::Function, cfg: &mut ControlFl
}
let mut pos = FuncCursor::new(func).after_inst(inst);
pos.use_srcloc(inst);
pos.ins().trap(code);
pos.insert_ebb(new_ebb);
@@ -154,6 +155,7 @@ fn expand_fconst(inst: ir::Inst, func: &mut ir::Function, _cfg: &mut ControlFlow
// In the future, we may want to generate constant pool entries for these constants, but for
// now use an `iconst` and a bit cast.
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
let ival = match pos.func.dfg[inst] {
ir::InstructionData::UnaryIeee32 {
opcode: ir::Opcode::F32const,

View File

@@ -120,7 +120,7 @@ fn split_any(
concat: Opcode,
) -> (Value, Value) {
let mut repairs = Vec::new();
let mut pos = ir::Cursor::new(layout).at_position(pos);
let mut pos = ir::Cursor::new(layout, None).at_position(pos);
let result = split_value(dfg, &mut pos, value, concat, &mut repairs);
// We have split the value requested, and now we may need to fix some EBB predecessors.