Skip to content

Commit 7345c92

Browse files
Merge pull request #857 from jbj/ir-getInstruction
C++: Fix TranslatedElement.getInstruction perf
2 parents 411c285 + 35d7fb5 commit 7345c92

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,12 @@ class InstructionTagType extends TInstructionTag {
1616

1717
private TranslatedElement getInstructionTranslatedElement(
1818
Instruction instruction) {
19-
result = getInstructionTranslatedElementAndTag(instruction, _)
19+
instruction = result.getInstruction(_)
2020
}
2121

2222
private TranslatedElement getInstructionTranslatedElementAndTag(
2323
Instruction instruction, InstructionTag tag) {
24-
result.getAST() = instruction.getAST() and
25-
tag = instruction.getTag() and
26-
result.hasInstruction(_, tag, _, _)
27-
}
28-
29-
private TranslatedElement getTempVariableTranslatedElement(
30-
IRTempVariable var) {
31-
result.getAST() = var.getAST() and
32-
result.hasTempVariable(var.getTag(), _)
24+
instruction = result.getInstruction(tag)
3325
}
3426

3527
import Cached
@@ -262,8 +254,10 @@ cached private module Cached {
262254
import CachedForDebugging
263255
cached private module CachedForDebugging {
264256
cached string getTempVariableUniqueId(IRTempVariable var) {
265-
result = getTempVariableTranslatedElement(var).getId() + ":" +
266-
getTempVariableTagId(var.getTag())
257+
exists(TranslatedElement element |
258+
var = element.getTempVariable(_) and
259+
result = element.getId() + ":" + getTempVariableTagId(var.getTag())
260+
)
267261
}
268262

269263
cached string getInstructionUniqueId(Instruction instruction) {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,20 +619,27 @@ abstract class TranslatedElement extends TTranslatedElement {
619619
none()
620620
}
621621

622+
pragma[noinline]
623+
private predicate hasInstructionWithTagAndAst(InstructionTag tag, Locatable ast) {
624+
hasInstruction(_, tag, _, _) and
625+
ast = getAST()
626+
}
627+
622628
/**
623629
* Gets the instruction generated by this element with tag `tag`.
624630
*/
625631
final Instruction getInstruction(InstructionTag tag) {
626-
result.getAST() = getAST() and
627-
result.getTag() = tag
632+
hasInstructionWithTagAndAst(tag, result.getAST()) and
633+
tag = result.getTag()
628634
}
629635

630636
/**
631637
* Gets the temporary variable generated by this element with tag `tag`.
632638
*/
633639
final IRTempVariable getTempVariable(TempVariableTag tag) {
634640
result.getAST() = getAST() and
635-
result.getTag() = tag
641+
result.getTag() = tag and
642+
hasTempVariable(tag, _)
636643
}
637644

638645
/**

0 commit comments

Comments
 (0)