Skip to content

Commit

Permalink
SSA: Remove the need for ExitBasicBlock in SSA.
Browse files Browse the repository at this point in the history
  • Loading branch information
aschackmull committed Feb 10, 2025
1 parent 34edda6 commit 0b52709
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,4 @@ module InputSigCommon {
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock {
ExitBasicBlock() { this.getLastInstruction() instanceof ExitFunctionInstruction }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module PreSsa {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock {
private class ExitBasicBlock extends BasicBlock {
ExitBasicBlock() { scopeLast(_, this.getLastElement(), _) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ module BaseSsa {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock, ControlFlow::BasicBlocks::ExitBlock { }

class SourceVariable = PreSsa::SimpleLocalScopeVariable;

predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock, ControlFlow::BasicBlocks::ExitBlock { }

class SourceVariable = Ssa::SourceVariable;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ module VariableCaptureConfig implements InputSig<js::DbLocation> {
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }

predicate entryBlock(BasicBlock bb) { bb instanceof js::EntryBasicBlock }

predicate exitBlock(BasicBlock bb) { bb.getLastNode() instanceof js::ControlFlowExitNode }
}

module VariableCaptureOutput = Flow<js::DbLocation, VariableCaptureConfig>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ module SsaConfig implements InputSig<js::DbLocation> {

class BasicBlock = js::BasicBlock;

class ExitBasicBlock extends BasicBlock {
ExitBasicBlock() { this.isExitBlock() }
}

class SourceVariable extends LocalVariableOrThis {
SourceVariable() { not this.isCaptured() }
}
Expand Down
2 changes: 0 additions & 2 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module SsaInput implements SsaImplCommon::InputSig<Location> {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock, BasicBlocks::ExitBasicBlock { }

class SourceVariable = LocalVariable;

/**
Expand Down
2 changes: 0 additions & 2 deletions rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ module SsaInput implements SsaImplCommon::InputSig<Location> {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock = BasicBlocks::ExitBasicBlock;

/**
* A variable amenable to SSA construction.
*
Expand Down
7 changes: 0 additions & 7 deletions shared/dataflow/codeql/dataflow/VariableCapture.qll
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ signature module InputSig<LocationSig Location> {
/** Holds if `bb` is a control-flow entry point. */
default predicate entryBlock(BasicBlock bb) { not exists(getImmediateBasicBlockDominator(bb)) }

/** Holds if `bb` is a control-flow exit point. */
default predicate exitBlock(BasicBlock bb) { not exists(getABasicBlockSuccessor(bb)) }

/** A variable that is captured in a closure. */
class CapturedVariable {
/** Gets a textual representation of this variable. */
Expand Down Expand Up @@ -699,10 +696,6 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
result = Input::getABasicBlockSuccessor(bb)
}

class ExitBasicBlock extends BasicBlock {
ExitBasicBlock() { exitBlock(this) }
}

class SourceVariable = CaptureContainer;

predicate variableWrite(BasicBlock bb, int i, SourceVariable cc, boolean certain) {
Expand Down
13 changes: 5 additions & 8 deletions shared/ssa/codeql/ssa/Ssa.qll
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ signature module InputSig<LocationSig Location> {
/** Gets an immediate successor of basic block `bb`, if any. */
BasicBlock getABasicBlockSuccessor(BasicBlock bb);

/**
* An exit basic block, that is, a basic block whose last node is
* an exit node.
*/
class ExitBasicBlock extends BasicBlock;

/** A variable that can be SSA converted. */
class SourceVariable {
/** Gets a textual representation of this variable. */
Expand Down Expand Up @@ -855,6 +849,9 @@ module Make<LocationSig Location, InputSig<Location> Input> {
lastRefRedef(inp, _, _, def)
}

/** Holds if `bb` is a control-flow exit point. */
private predicate exitBlock(BasicBlock bb) { not exists(getABasicBlockSuccessor(bb)) }

/**
* NB: If this predicate is exposed, it should be cached.
*
Expand All @@ -873,7 +870,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
lastSsaRefExt(def, _, bb, i) and
(
// Can reach exit directly
bb instanceof ExitBasicBlock
exitBlock(bb)
or
// Can reach a block using one or more steps, where `def` is no longer live
varBlockReachesExitExt(def, bb)
Expand All @@ -893,7 +890,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
lastSsaRef(def, _, bb, i) and
(
// Can reach exit directly
bb instanceof ExitBasicBlock
exitBlock(bb)
or
// Can reach a block using one or more steps, where `def` is no longer live
varBlockReachesExit(def, bb)
Expand Down
2 changes: 0 additions & 2 deletions swift/ql/lib/codeql/swift/dataflow/Ssa.qll
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ module Ssa {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock = BasicBlocks::ExitBasicBlock;

private newtype TSourceVariable =
TNormalSourceVariable(VarDecl v) or
TKeyPathSourceVariable(EntryNode entry) { entry.getScope() instanceof KeyPathExpr }
Expand Down

0 comments on commit 0b52709

Please sign in to comment.