SSA: Add BasicBlock.{getNode/1,length/0} to the input signature

This commit is contained in:
Tom Hvitved
2024-07-03 11:09:56 +02:00
parent 8e8100fd34
commit 4ae8720930
19 changed files with 117 additions and 33 deletions

View File

@@ -17,6 +17,12 @@ signature module InputSig<LocationSig Location> {
/** Gets a textual representation of this basic block. */
string toString();
/** Gets the `i`th node in this basic block. */
ControlFlowNode getNode(int i);
/** Gets the length of this basic block. */
int length();
/** Gets the enclosing callable. */
Callable getEnclosingCallable();
@@ -24,6 +30,15 @@ signature module InputSig<LocationSig Location> {
Location getLocation();
}
/** A control flow node. */
class ControlFlowNode {
/** Gets a textual representation of this control flow node. */
string toString();
/** Gets the location of this control flow node. */
Location getLocation();
}
/**
* Gets the basic block that immediately dominates basic block `bb`, if any.
*
@@ -672,6 +687,8 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
private module CaptureSsaInput implements Ssa::InputSig<Location> {
final class BasicBlock = Input::BasicBlock;
final class ControlFlowNode = Input::ControlFlowNode;
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) {
result = Input::getImmediateBasicBlockDominator(bb)
}
@@ -717,10 +734,10 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
TSynthPhi(CaptureSsa::DefinitionExt phi) {
phi instanceof CaptureSsa::PhiNode or phi instanceof CaptureSsa::PhiReadNode
} or
TExprNode(Expr expr, boolean isPost) {
expr instanceof VariableRead and isPost = [false, true]
TExprNode(Expr expr, Boolean isPost) {
expr instanceof VariableRead
or
synthRead(_, _, _, _, expr) and isPost = [false, true]
synthRead(_, _, _, _, expr)
} or
TParamNode(CapturedParameter p) or
TThisParamNode(Callable c) { captureAccess(_, c) } or

View File

@@ -15,10 +15,25 @@ signature module InputSig<LocationSig Location> {
/** Gets a textual representation of this basic block. */
string toString();
/** Gets the `i`th node in this basic block. */
ControlFlowNode getNode(int i);
/** Gets the length of this basic block. */
int length();
/** Gets the location of this basic block. */
Location getLocation();
}
/** A control flow node. */
class ControlFlowNode {
/** Gets a textual representation of this control flow node. */
string toString();
/** Gets the location of this control flow node. */
Location getLocation();
}
/**
* Gets the basic block that immediately dominates basic block `bb`, if any.
*
@@ -905,6 +920,13 @@ module Make<LocationSig Location, InputSig<Location> Input> {
/** Gets a textual representation of this SSA definition. */
string toString() { result = "SSA def(" + this.getSourceVariable() + ")" }
/** Gets the location of this SSA definition. */
Location getLocation() {
exists(BasicBlock bb, int i | this.definesAt(_, bb, i) |
if i = -1 then result = bb.getLocation() else result = bb.getNode(i).getLocation()
)
}
}
/** An SSA definition that corresponds to a write. */
@@ -961,6 +983,13 @@ module Make<LocationSig Location, InputSig<Location> Input> {
/** Gets a textual representation of this SSA definition. */
string toString() { result = this.(Definition).toString() }
/** Gets the location of this SSA definition. */
Location getLocation() {
exists(BasicBlock bb, int i | this.definesAt(_, bb, i, _) |
if i = -1 then result = bb.getLocation() else result = bb.getNode(i).getLocation()
)
}
}
/**