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:
Jonas Jensen
2019-01-30 09:37:37 +01:00
parent fc5b9dd55e
commit 35d7fb5322
2 changed files with 16 additions and 15 deletions

View File

@@ -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) {

View File

@@ -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, _)
}
/**