mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
C++: Fix TranslatedElement.getInstruction perf
This relation was almost 40x the size it needed to be on Wireshark because it lacked a restriction on the `tag` parameter. To implement that restriction efficiently, I had to split the relation in two to dictate the join order. With the fix, `getInstruction` now computes the same as `getInstructionTranslatedElementAndTag`, so the latter could be simplified. I made a corresponding change to `TranslatedElement.getTempVariable` for the sake of consistency.
This commit is contained in:
@@ -15,20 +15,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
|
||||
@@ -179,8 +171,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) {
|
||||
|
||||
@@ -633,12 +633,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()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -646,7 +652,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