mirror of
https://github.com/github/codeql.git
synced 2026-05-03 12:45:27 +02:00
Merge pull request #857 from jbj/ir-getInstruction
C++: Fix TranslatedElement.getInstruction perf
This commit is contained in:
@@ -16,20 +16,12 @@ class InstructionTagType extends TInstructionTag {
|
||||
|
||||
private TranslatedElement getInstructionTranslatedElement(
|
||||
Instruction instruction) {
|
||||
result = getInstructionTranslatedElementAndTag(instruction, _)
|
||||
instruction = result.getInstruction(_)
|
||||
}
|
||||
|
||||
private TranslatedElement getInstructionTranslatedElementAndTag(
|
||||
Instruction instruction, InstructionTag tag) {
|
||||
result.getAST() = instruction.getAST() and
|
||||
tag = instruction.getTag() and
|
||||
result.hasInstruction(_, tag, _, _)
|
||||
}
|
||||
|
||||
private TranslatedElement getTempVariableTranslatedElement(
|
||||
IRTempVariable var) {
|
||||
result.getAST() = var.getAST() and
|
||||
result.hasTempVariable(var.getTag(), _)
|
||||
instruction = result.getInstruction(tag)
|
||||
}
|
||||
|
||||
import Cached
|
||||
@@ -262,8 +254,10 @@ cached private module Cached {
|
||||
import CachedForDebugging
|
||||
cached private module CachedForDebugging {
|
||||
cached string getTempVariableUniqueId(IRTempVariable var) {
|
||||
result = getTempVariableTranslatedElement(var).getId() + ":" +
|
||||
getTempVariableTagId(var.getTag())
|
||||
exists(TranslatedElement element |
|
||||
var = element.getTempVariable(_) and
|
||||
result = element.getId() + ":" + getTempVariableTagId(var.getTag())
|
||||
)
|
||||
}
|
||||
|
||||
cached string getInstructionUniqueId(Instruction instruction) {
|
||||
|
||||
@@ -619,12 +619,18 @@ abstract class TranslatedElement extends TTranslatedElement {
|
||||
none()
|
||||
}
|
||||
|
||||
pragma[noinline]
|
||||
private predicate hasInstructionWithTagAndAst(InstructionTag tag, Locatable ast) {
|
||||
hasInstruction(_, tag, _, _) and
|
||||
ast = getAST()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instruction generated by this element with tag `tag`.
|
||||
*/
|
||||
final Instruction getInstruction(InstructionTag tag) {
|
||||
result.getAST() = getAST() and
|
||||
result.getTag() = tag
|
||||
hasInstructionWithTagAndAst(tag, result.getAST()) and
|
||||
tag = result.getTag()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -632,7 +638,8 @@ abstract class TranslatedElement extends TTranslatedElement {
|
||||
*/
|
||||
final IRTempVariable getTempVariable(TempVariableTag tag) {
|
||||
result.getAST() = getAST() and
|
||||
result.getTag() = tag
|
||||
result.getTag() = tag and
|
||||
hasTempVariable(tag, _)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user