Skip to content

Commit

Permalink
Build PDG exclusively on provenance
Browse files Browse the repository at this point in the history
The event source- and assignment-based PDG
construction steps were giving incorrect results
for indirect accesses, so remove them completely.

Update the PDG snapshots to match this change.
  • Loading branch information
ahomescu committed Jul 24, 2024
1 parent c8b172a commit 131d77a
Show file tree
Hide file tree
Showing 3 changed files with 1,432 additions and 1,504 deletions.
74 changes: 6 additions & 68 deletions pdg/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn update_provenance(
Realloc { new_ptr, .. } => {
provenances.insert(new_ptr, mapping);
}
Offset(_, _, new_ptr) => {
Offset(_, _, new_ptr) | Project(_, new_ptr, _) => {
provenances.insert(new_ptr, mapping);
}
CopyRef => {
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn add_node(

let node_kind = event.kind.to_node_kind(func.id, address_taken)?;
let this_id = func.id;
let (src_fn, dest_fn) = match event_metadata.transfer_kind {
let (_src_fn, dest_fn) = match event_metadata.transfer_kind {
TransferKind::None => (this_id, this_id),
TransferKind::Arg(id) => (this_id, id),
TransferKind::Ret(id) => (id, this_id),
Expand All @@ -163,48 +163,8 @@ pub fn add_node(
statement_idx = 0;
}

let provenance = event
.kind
.ptr(event_metadata)
.and_then(|ptr| provenances.get(&ptr).cloned());
let direct_source = provenance.and_then(|(gid, _last_nid_ref)| {
graphs.graphs[gid]
.nodes
.iter()
.rposition(|n| {
if let (Some(d), Some(s)) = (&n.dest, &event_metadata.source) {
d == s
} else {
false
}
})
.map(|nid| (gid, NodeId::from(nid)))
});

let source = direct_source.or_else(|| {
event_metadata.source.as_ref().and_then(|src| {
let latest_assignment = graphs.latest_assignment.get(&(src_fn, src.local)).cloned();
if !src.projection.is_empty() {
if let Some((gid, _)) = latest_assignment {
if let Some((nid, n)) = graphs.graphs[gid].nodes.iter_enumerated().rev().next()
{
if let NodeKind::Project(..) = n.kind {
return Some((gid, nid));
}
}
}
}

if !matches!(event.kind, EventKind::AddrOfLocal(..)) && src.projection.is_empty() {
latest_assignment
} else if let EventKind::Project(..) = event.kind {
latest_assignment
} else {
provenance
}
})
});

let ptr = event.kind.ptr(event_metadata);
let provenance = ptr.and_then(|ptr| provenances.get(&ptr).cloned());
let function = Func {
id: dest_fn,
name: metadata.functions[&dest_fn].clone(),
Expand All @@ -215,17 +175,15 @@ pub fn add_node(
block: basic_block_idx.into(),
statement_idx,
kind: node_kind,
source: source
source: provenance
.and_then(|p| parent(&node_kind, p))
.map(|(_, nid)| nid),
dest: event_metadata.destination.clone(),
debug_info: event_metadata.debug_info.clone(),
info: None,
};

let graph_id = source
.or(direct_source)
.or(provenance)
let graph_id = provenance
.and_then(|p| parent(&node_kind, p))
.map(|(gid, _)| gid)
.unwrap_or_else(|| graphs.graphs.push(Graph::new()));
Expand All @@ -238,26 +196,6 @@ pub fn add_node(
(graph_id, node_id),
);

if let Some(dest) = &event_metadata.destination {
let unique_place = (dest_fn, dest.local);
let last_setting = (graph_id, node_id);

if let Some(last @ (last_gid, last_nid)) =
graphs.latest_assignment.insert(unique_place, last_setting)
{
if !dest.projection.is_empty()
&& graphs.graphs[last_gid].nodes[last_nid]
.dest
.as_ref()
.unwrap()
.projection
.is_empty()
{
graphs.latest_assignment.insert(unique_place, last);
}
}
}

Some(node_id)
}

Expand Down
Loading

0 comments on commit 131d77a

Please sign in to comment.