Reconstruct locations of the original source variable
This commit is contained in:
committed by
Dan Gohman
parent
d6059d4605
commit
8f95c51730
@@ -6,7 +6,10 @@ use crate::ir::builder::ReplaceBuilder;
|
||||
use crate::ir::extfunc::ExtFuncData;
|
||||
use crate::ir::instructions::{BranchInfo, CallInfo, InstructionData};
|
||||
use crate::ir::types;
|
||||
use crate::ir::{Ebb, FuncRef, Inst, SigRef, Signature, Type, Value, ValueList, ValueListPool};
|
||||
use crate::ir::{
|
||||
Ebb, FuncRef, Inst, SigRef, Signature, Type, Value, ValueLabelAssignments, ValueList,
|
||||
ValueListPool,
|
||||
};
|
||||
use crate::isa::TargetIsa;
|
||||
use crate::packed_option::ReservedValue;
|
||||
use crate::write::write_operands;
|
||||
@@ -15,6 +18,7 @@ use core::iter;
|
||||
use core::mem;
|
||||
use core::ops::{Index, IndexMut};
|
||||
use core::u16;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// A data flow graph defines all instructions and extended basic blocks in a function as well as
|
||||
/// the data flow dependencies between them. The DFG also tracks values which can be either
|
||||
@@ -60,6 +64,9 @@ pub struct DataFlowGraph {
|
||||
|
||||
/// External function references. These are functions that can be called directly.
|
||||
pub ext_funcs: PrimaryMap<FuncRef, ExtFuncData>,
|
||||
|
||||
/// Saves Value labels.
|
||||
pub values_labels: Option<HashMap<Value, ValueLabelAssignments>>,
|
||||
}
|
||||
|
||||
impl DataFlowGraph {
|
||||
@@ -73,6 +80,7 @@ impl DataFlowGraph {
|
||||
values: PrimaryMap::new(),
|
||||
signatures: PrimaryMap::new(),
|
||||
ext_funcs: PrimaryMap::new(),
|
||||
values_labels: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +93,7 @@ impl DataFlowGraph {
|
||||
self.values.clear();
|
||||
self.signatures.clear();
|
||||
self.ext_funcs.clear();
|
||||
self.values_labels = None;
|
||||
}
|
||||
|
||||
/// Get the total number of instructions created in this function, whether they are currently
|
||||
@@ -117,6 +126,13 @@ impl DataFlowGraph {
|
||||
pub fn num_values(&self) -> usize {
|
||||
self.values.len()
|
||||
}
|
||||
|
||||
/// Starts collection of debug information.
|
||||
pub fn collect_debug_info(&mut self) {
|
||||
if self.values_labels.is_none() {
|
||||
self.values_labels = Some(HashMap::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve value aliases.
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::ir::{EbbOffsets, InstEncodings, SourceLocs, StackSlots, ValueLocation
|
||||
use crate::ir::{JumpTableOffsets, JumpTables};
|
||||
use crate::isa::{CallConv, EncInfo, Encoding, Legalize, TargetIsa};
|
||||
use crate::regalloc::RegDiversions;
|
||||
use crate::value_label::ValueLabelsRanges;
|
||||
use crate::write::write_function;
|
||||
use core::fmt;
|
||||
|
||||
@@ -155,7 +156,15 @@ impl Function {
|
||||
|
||||
/// Return an object that can display this function with correct ISA-specific annotations.
|
||||
pub fn display<'a, I: Into<Option<&'a TargetIsa>>>(&'a self, isa: I) -> DisplayFunction<'a> {
|
||||
DisplayFunction(self, isa.into())
|
||||
DisplayFunction(self, isa.into().into())
|
||||
}
|
||||
|
||||
/// Return an object that can display this function with correct ISA-specific annotations.
|
||||
pub fn display_with<'a>(
|
||||
&'a self,
|
||||
annotations: DisplayFunctionAnnotations<'a>,
|
||||
) -> DisplayFunction<'a> {
|
||||
DisplayFunction(self, annotations)
|
||||
}
|
||||
|
||||
/// Find a presumed unique special-purpose function parameter value.
|
||||
@@ -202,26 +211,58 @@ impl Function {
|
||||
pub fn encode(&self, inst: ir::Inst, isa: &TargetIsa) -> Result<Encoding, Legalize> {
|
||||
isa.encode(&self, &self.dfg[inst], self.dfg.ctrl_typevar(inst))
|
||||
}
|
||||
|
||||
/// Starts collection of debug information.
|
||||
pub fn collect_debug_info(&mut self) {
|
||||
self.dfg.collect_debug_info();
|
||||
}
|
||||
}
|
||||
|
||||
/// Additional annotations for function display.
|
||||
pub struct DisplayFunctionAnnotations<'a> {
|
||||
/// Enable ISA annotations.
|
||||
pub isa: Option<&'a TargetIsa>,
|
||||
|
||||
/// Enable value labels annotations.
|
||||
pub value_ranges: Option<&'a ValueLabelsRanges>,
|
||||
}
|
||||
|
||||
impl<'a> DisplayFunctionAnnotations<'a> {
|
||||
fn default() -> Self {
|
||||
DisplayFunctionAnnotations {
|
||||
isa: None,
|
||||
value_ranges: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Option<&'a TargetIsa>> for DisplayFunctionAnnotations<'a> {
|
||||
fn from(isa: Option<&'a TargetIsa>) -> DisplayFunctionAnnotations {
|
||||
DisplayFunctionAnnotations {
|
||||
isa,
|
||||
value_ranges: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type capable of displaying a `Function` with correct ISA annotations.
|
||||
pub struct DisplayFunction<'a>(&'a Function, Option<&'a TargetIsa>);
|
||||
pub struct DisplayFunction<'a>(&'a Function, DisplayFunctionAnnotations<'a>);
|
||||
|
||||
impl<'a> fmt::Display for DisplayFunction<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write_function(fmt, self.0, self.1)
|
||||
write_function(fmt, self.0, &self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Function {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write_function(fmt, self, None)
|
||||
write_function(fmt, self, &DisplayFunctionAnnotations::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Function {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write_function(fmt, self, None)
|
||||
write_function(fmt, self, &DisplayFunctionAnnotations::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub use crate::ir::extfunc::{
|
||||
AbiParam, ArgumentExtension, ArgumentPurpose, ExtFuncData, Signature,
|
||||
};
|
||||
pub use crate::ir::extname::ExternalName;
|
||||
pub use crate::ir::function::Function;
|
||||
pub use crate::ir::function::{DisplayFunctionAnnotations, Function};
|
||||
pub use crate::ir::globalvalue::GlobalValueData;
|
||||
pub use crate::ir::heap::{HeapData, HeapStyle};
|
||||
pub use crate::ir::instructions::{
|
||||
@@ -51,7 +51,7 @@ pub use crate::ir::types::Type;
|
||||
pub use crate::ir::valueloc::{ArgumentLoc, ValueLoc};
|
||||
|
||||
use crate::binemit;
|
||||
use crate::entity::{PrimaryMap, SecondaryMap};
|
||||
use crate::entity::{entity_impl, PrimaryMap, SecondaryMap};
|
||||
use crate::isa;
|
||||
|
||||
/// Map of value locations.
|
||||
@@ -71,3 +71,34 @@ pub type JumpTableOffsets = SecondaryMap<JumpTable, binemit::CodeOffset>;
|
||||
|
||||
/// Source locations for instructions.
|
||||
pub type SourceLocs = SecondaryMap<Inst, SourceLoc>;
|
||||
|
||||
/// Marked with a label value.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ValueLabel(u32);
|
||||
entity_impl!(ValueLabel, "val");
|
||||
|
||||
/// A label of a Value.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ValueLabelStart {
|
||||
/// Source location when it is in effect
|
||||
pub from: SourceLoc,
|
||||
|
||||
/// The label index.
|
||||
pub label: ValueLabel,
|
||||
}
|
||||
|
||||
/// Value label assignements: label starts or value aliases.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ValueLabelAssignments {
|
||||
/// Original value labels assigned at transform.
|
||||
Starts(std::vec::Vec<ValueLabelStart>),
|
||||
|
||||
/// A value alias to original value.
|
||||
Alias {
|
||||
/// Source location when it is in effect
|
||||
from: SourceLoc,
|
||||
|
||||
/// The label index.
|
||||
value: Value,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user