Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c32e4c

Browse files
author
Dave Bartolomeo
committed
C++/C#: Do filtering of instructions in cached predicates
The four cached predicates used to access common properties of instructions took a `TStageInstruction` as a parameter. This requires the calling code, in `Instruction.qll`, to then join the results with `hasInstruction()` to filter out results for `TRawInstruction`s that were discarded as unreachable. By simply switching the parameter types to `Instruction`, we can force that join to happen in the cached predicate itself. This makes the various accessor predicates on `Instruction` trivially inlinable to the cached predicate, instead of being joins of two huge relations that might have to be recomputed in later stages.
1 parent e62b884 commit 1c32e4c

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private module Cached {
263263
}
264264

265265
cached
266-
Language::AST getInstructionAST(TStageInstruction instr) {
266+
Language::AST getInstructionAST(Instruction instr) {
267267
instr = rawInstruction(_, _, result)
268268
or
269269
exists(RawIR::Instruction blockStartInstr |
@@ -282,7 +282,7 @@ private module Cached {
282282
}
283283

284284
cached
285-
Language::LanguageType getInstructionResultType(TStageInstruction instr) {
285+
Language::LanguageType getInstructionResultType(Instruction instr) {
286286
result = instr.(RawIR::Instruction).getResultLanguageType()
287287
or
288288
exists(Alias::MemoryLocation defLocation |
@@ -300,7 +300,7 @@ private module Cached {
300300
}
301301

302302
cached
303-
Opcode getInstructionOpcode(TStageInstruction instr) {
303+
Opcode getInstructionOpcode(Instruction instr) {
304304
instr = rawInstruction(_, result, _)
305305
or
306306
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
@@ -311,7 +311,7 @@ private module Cached {
311311
}
312312

313313
cached
314-
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
314+
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
315315
instr = rawInstruction(result, _, _)
316316
or
317317
instr = phiInstruction(result, _, _)

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private module Cached {
263263
}
264264

265265
cached
266-
Language::AST getInstructionAST(TStageInstruction instr) {
266+
Language::AST getInstructionAST(Instruction instr) {
267267
instr = rawInstruction(_, _, result)
268268
or
269269
exists(RawIR::Instruction blockStartInstr |
@@ -282,7 +282,7 @@ private module Cached {
282282
}
283283

284284
cached
285-
Language::LanguageType getInstructionResultType(TStageInstruction instr) {
285+
Language::LanguageType getInstructionResultType(Instruction instr) {
286286
result = instr.(RawIR::Instruction).getResultLanguageType()
287287
or
288288
exists(Alias::MemoryLocation defLocation |
@@ -300,7 +300,7 @@ private module Cached {
300300
}
301301

302302
cached
303-
Opcode getInstructionOpcode(TStageInstruction instr) {
303+
Opcode getInstructionOpcode(Instruction instr) {
304304
instr = rawInstruction(_, result, _)
305305
or
306306
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
@@ -311,7 +311,7 @@ private module Cached {
311311
}
312312

313313
cached
314-
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
314+
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
315315
instr = rawInstruction(result, _, _)
316316
or
317317
instr = phiInstruction(result, _, _)

csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private module Cached {
263263
}
264264

265265
cached
266-
Language::AST getInstructionAST(TStageInstruction instr) {
266+
Language::AST getInstructionAST(Instruction instr) {
267267
instr = rawInstruction(_, _, result)
268268
or
269269
exists(RawIR::Instruction blockStartInstr |
@@ -282,7 +282,7 @@ private module Cached {
282282
}
283283

284284
cached
285-
Language::LanguageType getInstructionResultType(TStageInstruction instr) {
285+
Language::LanguageType getInstructionResultType(Instruction instr) {
286286
result = instr.(RawIR::Instruction).getResultLanguageType()
287287
or
288288
exists(Alias::MemoryLocation defLocation |
@@ -300,7 +300,7 @@ private module Cached {
300300
}
301301

302302
cached
303-
Opcode getInstructionOpcode(TStageInstruction instr) {
303+
Opcode getInstructionOpcode(Instruction instr) {
304304
instr = rawInstruction(_, result, _)
305305
or
306306
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
@@ -311,7 +311,7 @@ private module Cached {
311311
}
312312

313313
cached
314-
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
314+
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
315315
instr = rawInstruction(result, _, _)
316316
or
317317
instr = phiInstruction(result, _, _)

0 commit comments

Comments
 (0)