Skip to content

Commit 52eb7ae

Browse files
committed
Revert "Merge pull request github#13207 from MathiasVP/use-equiv-class-in-getInstruction"
This reverts commit 5bc844c, reversing changes made to b2fb2aa.
1 parent a646749 commit 52eb7ae

File tree

5 files changed

+20
-90
lines changed

5 files changed

+20
-90
lines changed

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,14 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Gets the index of `i` in its `IRBlock`. */
259-
private int getMemberIndex(Instruction i) {
260-
startsBasicBlock(i) and
261-
result = 0
262-
or
263-
exists(Instruction iPrev |
264-
adjacentInBlock(iPrev, i) and
265-
result = getMemberIndex(iPrev) + 1
266-
)
267-
}
268-
269-
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
258+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+
private Instruction getInstructionFromFirst(Instruction first, int index) =
260+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
270261

271262
/** Holds if `i` is the `index`th instruction in `block`. */
272263
cached
273264
Instruction getInstruction(TIRBlock block, int index) {
274-
exists(Instruction first | block = MkIRBlock(first) |
275-
first = result and index = 0
276-
or
277-
index = getMemberIndex(result) and
278-
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
279-
)
265+
result = getInstructionFromFirst(getFirstInstruction(block), index)
280266
}
281267

282268
cached

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,14 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Gets the index of `i` in its `IRBlock`. */
259-
private int getMemberIndex(Instruction i) {
260-
startsBasicBlock(i) and
261-
result = 0
262-
or
263-
exists(Instruction iPrev |
264-
adjacentInBlock(iPrev, i) and
265-
result = getMemberIndex(iPrev) + 1
266-
)
267-
}
268-
269-
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
258+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+
private Instruction getInstructionFromFirst(Instruction first, int index) =
260+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
270261

271262
/** Holds if `i` is the `index`th instruction in `block`. */
272263
cached
273264
Instruction getInstruction(TIRBlock block, int index) {
274-
exists(Instruction first | block = MkIRBlock(first) |
275-
first = result and index = 0
276-
or
277-
index = getMemberIndex(result) and
278-
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
279-
)
265+
result = getInstructionFromFirst(getFirstInstruction(block), index)
280266
}
281267

282268
cached

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,14 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Gets the index of `i` in its `IRBlock`. */
259-
private int getMemberIndex(Instruction i) {
260-
startsBasicBlock(i) and
261-
result = 0
262-
or
263-
exists(Instruction iPrev |
264-
adjacentInBlock(iPrev, i) and
265-
result = getMemberIndex(iPrev) + 1
266-
)
267-
}
268-
269-
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
258+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+
private Instruction getInstructionFromFirst(Instruction first, int index) =
260+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
270261

271262
/** Holds if `i` is the `index`th instruction in `block`. */
272263
cached
273264
Instruction getInstruction(TIRBlock block, int index) {
274-
exists(Instruction first | block = MkIRBlock(first) |
275-
first = result and index = 0
276-
or
277-
index = getMemberIndex(result) and
278-
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
279-
)
265+
result = getInstructionFromFirst(getFirstInstruction(block), index)
280266
}
281267

282268
cached

csharp/ql/src/experimental/ir/implementation/raw/IRBlock.qll

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,14 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Gets the index of `i` in its `IRBlock`. */
259-
private int getMemberIndex(Instruction i) {
260-
startsBasicBlock(i) and
261-
result = 0
262-
or
263-
exists(Instruction iPrev |
264-
adjacentInBlock(iPrev, i) and
265-
result = getMemberIndex(iPrev) + 1
266-
)
267-
}
268-
269-
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
258+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+
private Instruction getInstructionFromFirst(Instruction first, int index) =
260+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
270261

271262
/** Holds if `i` is the `index`th instruction in `block`. */
272263
cached
273264
Instruction getInstruction(TIRBlock block, int index) {
274-
exists(Instruction first | block = MkIRBlock(first) |
275-
first = result and index = 0
276-
or
277-
index = getMemberIndex(result) and
278-
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
279-
)
265+
result = getInstructionFromFirst(getFirstInstruction(block), index)
280266
}
281267

282268
cached

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/IRBlock.qll

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,14 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Gets the index of `i` in its `IRBlock`. */
259-
private int getMemberIndex(Instruction i) {
260-
startsBasicBlock(i) and
261-
result = 0
262-
or
263-
exists(Instruction iPrev |
264-
adjacentInBlock(iPrev, i) and
265-
result = getMemberIndex(iPrev) + 1
266-
)
267-
}
268-
269-
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
258+
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259+
private Instruction getInstructionFromFirst(Instruction first, int index) =
260+
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
270261

271262
/** Holds if `i` is the `index`th instruction in `block`. */
272263
cached
273264
Instruction getInstruction(TIRBlock block, int index) {
274-
exists(Instruction first | block = MkIRBlock(first) |
275-
first = result and index = 0
276-
or
277-
index = getMemberIndex(result) and
278-
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
279-
)
265+
result = getInstructionFromFirst(getFirstInstruction(block), index)
280266
}
281267

282268
cached

0 commit comments

Comments
 (0)