Skip to content

Commit c9ce642

Browse files
authored
Merge pull request github#16339 from MathiasVP/one-less-stage
C++: Remove a stage by properly caching `getResultIRType`
2 parents 6147a38 + 70e9c48 commit c9ce642

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ class Instruction extends Construction::TStageInstruction {
247247
* Gets the type of the result produced by this instruction. If the instruction does not produce
248248
* a result, its result type will be `IRVoidType`.
249249
*/
250-
cached
251-
final IRType getResultIRType() { result = this.getResultLanguageType().getIRType() }
250+
final IRType getResultIRType() { result = Construction::getInstructionResultIRType(this) }
252251

253252
/**
254253
* Gets the type of the result produced by this instruction. If the

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ private module Cached {
429429
instr = unreachedInstruction(_) and result = Language::getVoidType()
430430
}
431431

432+
cached
433+
IRType getInstructionResultIRType(Instruction instr) {
434+
result = instr.getResultLanguageType().getIRType()
435+
}
436+
432437
/**
433438
* Holds if `opcode` is the opcode that specifies the operation performed by `instr`.
434439
*

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ class Instruction extends Construction::TStageInstruction {
247247
* Gets the type of the result produced by this instruction. If the instruction does not produce
248248
* a result, its result type will be `IRVoidType`.
249249
*/
250-
cached
251-
final IRType getResultIRType() { result = this.getResultLanguageType().getIRType() }
250+
final IRType getResultIRType() { result = Construction::getInstructionResultIRType(this) }
252251

253252
/**
254253
* Gets the type of the result produced by this instruction. If the

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ CppType getInstructionResultType(TStageInstruction instr) {
377377
result = getVoidType()
378378
}
379379

380+
IRType getInstructionResultIRType(Instruction instr) {
381+
result = instr.getResultLanguageType().getIRType()
382+
}
383+
380384
predicate getInstructionOpcode(Opcode opcode, TStageInstruction instr) {
381385
getInstructionTranslatedElement(instr).hasInstruction(opcode, getInstructionTag(instr), _)
382386
or

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ class Instruction extends Construction::TStageInstruction {
247247
* Gets the type of the result produced by this instruction. If the instruction does not produce
248248
* a result, its result type will be `IRVoidType`.
249249
*/
250-
cached
251-
final IRType getResultIRType() { result = this.getResultLanguageType().getIRType() }
250+
final IRType getResultIRType() { result = Construction::getInstructionResultIRType(this) }
252251

253252
/**
254253
* Gets the type of the result produced by this instruction. If the

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ private module Cached {
429429
instr = unreachedInstruction(_) and result = Language::getVoidType()
430430
}
431431

432+
cached
433+
IRType getInstructionResultIRType(Instruction instr) {
434+
result = instr.getResultLanguageType().getIRType()
435+
}
436+
432437
/**
433438
* Holds if `opcode` is the opcode that specifies the operation performed by `instr`.
434439
*

0 commit comments

Comments
 (0)