Skip to content

Commit

Permalink
Revert "keep pointer cells separate in overlapping accesses"
Browse files Browse the repository at this point in the history
This reverts commit 14af03a.
  • Loading branch information
sadrabt committed Dec 2, 2024
1 parent 14af03a commit 957ba7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Graph(val proc: Procedure,
val node = Node(Some(this), byteSize)
node.allocationRegions.add(StackLocation(s"Stack_${proc}_$offset", proc, byteSize))
node.flags.stack = true
node.addCell(0, 0)
node.addCell(0, byteSize)
stackMapping.update(offset, node)
lastOffset = offset
else
Expand Down
35 changes: 16 additions & 19 deletions src/main/scala/analysis/data_structure_analysis/LocalPhase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,23 @@ class LocalPhase(proc: Procedure,
val diff = pointer.offset - lhsOrValue.offset
val startPointerOffset = pointer.offset // starting offset for the dereference
val lhsNode = lhsOrValue.node.get

//
//
// collect all cells that are being dereferenced
val pointers = pointer.node.get.cells.filter((offset, _) => offset >= startPointerOffset && offset < startPointerOffset + size).toSeq.sortBy((offset, cell) => offset)
if pointers.size > 1 then
graph.collapseNode(lhsNode)
for (((offset, cell), i) <- pointers.zipWithIndex) { // iterate and merge each pointee at correct offset it lhs/value cell
val lhs = lhsNode.addCell(offset - diff, 0) // todo check if 0 is the right size
// update the access size of the pointer
graph.find(cell).growSize(if i < pointers.size - 1 then (pointers(i + 1)._1 - offset - diff).toInt else (size - (offset - diff)).toInt)
val res = graph.mergeCells(lhs, graph.adjust(graph.find(cell).getPointee))
graph.handleOverlapping(res)
}

// val collapse = pointer.node.get.cells.filter((offset, _) => offset >= startPointerOffset && offset < startPointerOffset + size).toSeq.sortBy((offset, cell) => offset).size != 1
// pointer.growSize(size)
// graph.selfCollapse(pointer.node.get)
// if collapse then graph.collapseNode(graph.find(graph.find(pointer).getPointee.node).node)
// graph.mergeCells(lhsOrValue, graph.adjust(graph.find(pointer).getPointee))
//
// // collect all cells that are being dereferenced
// val pointers = pointer.node.get.cells.filter((offset, _) => offset >= startPointerOffset && offset < startPointerOffset + size).toSeq.sortBy((offset, cell) => offset)
// for (((offset, cell), i) <- pointers.zipWithIndex) { // iterate and merge each pointee at correct offset it lhs/value cell
// val lhs = lhsNode.addCell(offset - diff, 0) // todo check if 0 is the right size
// // update the access size of the pointer
// graph.find(cell).growSize(if i < pointers.size - 1 then (pointers(i + 1)._1 - offset - diff).toInt else (size - (offset - diff)).toInt)
// val res = graph.mergeCells(lhs, graph.adjust(graph.find(cell).getPointee))
// graph.handleOverlapping(res)
// }

val collapse = pointer.node.get.cells.filter((offset, _) => offset >= startPointerOffset && offset < startPointerOffset + size).toSeq.sortBy((offset, cell) => offset).size != 1
pointer.growSize(size)
graph.selfCollapse(pointer.node.get)
if collapse then graph.collapseNode(graph.find(graph.find(pointer).getPointee.node).node)
graph.mergeCells(lhsOrValue, graph.adjust(graph.find(pointer).getPointee))
}


Expand Down
5 changes: 3 additions & 2 deletions src/test/scala/DataStructureAnalysisTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ class DataStructureAnalysisTest extends AnyFunSuite {
val stack72 = dsg.get(dsg.stackMapping(72).cells(0)) // R31 + 0x40 + 8
val stack16 = dsg.get(dsg.stackMapping(16).cells(0)) // R31 + 40
val stack32 = dsg.get(dsg.stackMapping(32).cells(0)) // R31 + 32
val stack24 = dsg.get(dsg.stackMapping(16).cells(8)) // R31 + 24 and Malloc merged together with R31 + 16
val stack24 = dsg.get(dsg.stackMapping(16).addCell(8, 0)) // R31 + 24 and Malloc merged together with R31 + 16

assert(dsg.adjust(stack64.getPointee).equals(R29formal)) // R31 points to the frame pointer
assert(dsg.adjust(stack72.getPointee).equals(dsg.adjust(dsg.formals(R30)))) // R31 + 8 points to the link register
assert(stack24 != stack16)

// overlapping access
assert(dsg.adjust(stack16.getPointee).equals(dsg.get(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0))))
assert(dsg.adjust(stack24.getPointee).equals(dsg.get(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0))))
assert(stack24 == stack16)

// assert(!dsg.get(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0)).equals(dsg.get(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0))))
assert(dsg.get(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0)).equals(dsg.get(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0))))
Expand Down

0 comments on commit 957ba7e

Please sign in to comment.