Skip to content

Commit 8368c37

Browse files
committed
C++: Use shortestDistances HOP for IR BB indexes
This doesn't make it much faster, but it reduces the debug output volume. It also simplifies the code. I've found this change necessary when I compute the full IR on a Wireshark snapshot in QL4E. Without it, Eclipse runs out of memory because the console log is too large.
1 parent 6243c72 commit 8368c37

File tree

3 files changed

+12
-45
lines changed

3 files changed

+12
-45
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRBlock.qll

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,13 @@ private cached module Cached {
159159
not startsBasicBlock(i2)
160160
}
161161

162-
/** Gets the index of `i` in its `IRBlock`. */
163-
private int getMemberIndex(Instruction i) {
164-
startsBasicBlock(i) and
165-
result = 0
166-
or
167-
exists(Instruction iPrev |
168-
adjacentInBlock(iPrev, i) and
169-
result = getMemberIndex(iPrev) + 1
170-
)
171-
}
162+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
163+
private Instruction getInstructionFromFirst(Instruction first, int index) =
164+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
172165

173166
/** Holds if `i` is the `index`th instruction in `block`. */
174167
cached Instruction getInstruction(TIRBlock block, int index) {
175-
exists(Instruction first |
176-
block = MkIRBlock(first) and
177-
index = getMemberIndex(result) and
178-
adjacentInBlock*(first, result)
179-
)
168+
result = getInstructionFromFirst(getFirstInstruction(block), index)
180169
}
181170

182171
cached int getInstructionCount(TIRBlock block) {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRBlock.qll

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,13 @@ private cached module Cached {
159159
not startsBasicBlock(i2)
160160
}
161161

162-
/** Gets the index of `i` in its `IRBlock`. */
163-
private int getMemberIndex(Instruction i) {
164-
startsBasicBlock(i) and
165-
result = 0
166-
or
167-
exists(Instruction iPrev |
168-
adjacentInBlock(iPrev, i) and
169-
result = getMemberIndex(iPrev) + 1
170-
)
171-
}
162+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
163+
private Instruction getInstructionFromFirst(Instruction first, int index) =
164+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
172165

173166
/** Holds if `i` is the `index`th instruction in `block`. */
174167
cached Instruction getInstruction(TIRBlock block, int index) {
175-
exists(Instruction first |
176-
block = MkIRBlock(first) and
177-
index = getMemberIndex(result) and
178-
adjacentInBlock*(first, result)
179-
)
168+
result = getInstructionFromFirst(getFirstInstruction(block), index)
180169
}
181170

182171
cached int getInstructionCount(TIRBlock block) {

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRBlock.qll

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,13 @@ private cached module Cached {
159159
not startsBasicBlock(i2)
160160
}
161161

162-
/** Gets the index of `i` in its `IRBlock`. */
163-
private int getMemberIndex(Instruction i) {
164-
startsBasicBlock(i) and
165-
result = 0
166-
or
167-
exists(Instruction iPrev |
168-
adjacentInBlock(iPrev, i) and
169-
result = getMemberIndex(iPrev) + 1
170-
)
171-
}
162+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
163+
private Instruction getInstructionFromFirst(Instruction first, int index) =
164+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
172165

173166
/** Holds if `i` is the `index`th instruction in `block`. */
174167
cached Instruction getInstruction(TIRBlock block, int index) {
175-
exists(Instruction first |
176-
block = MkIRBlock(first) and
177-
index = getMemberIndex(result) and
178-
adjacentInBlock*(first, result)
179-
)
168+
result = getInstructionFromFirst(getFirstInstruction(block), index)
180169
}
181170

182171
cached int getInstructionCount(TIRBlock block) {

0 commit comments

Comments
 (0)