C++/C#: Do filtering of instructions in cached predicates

The four cached predicates used to access common properties of instructions took a `TStageInstruction` as a parameter. This requires the calling code, in `Instruction.qll`, to then join the results with `hasInstruction()` to filter out results for `TRawInstruction`s that were discarded as unreachable. By simply switching the parameter types to `Instruction`, we can force that join to happen in the cached predicate itself. This makes the various accessor predicates on `Instruction` trivially inlinable to the cached predicate, instead of being joins of two huge relations that might have to be recomputed in later stages.
This commit is contained in:
Dave Bartolomeo
2020-06-05 15:41:21 -04:00
parent e62b884b48
commit 1c32e4cc68
3 changed files with 12 additions and 12 deletions

View File

@@ -263,7 +263,7 @@ private module Cached {
}
cached
Language::AST getInstructionAST(TStageInstruction instr) {
Language::AST getInstructionAST(Instruction instr) {
instr = rawInstruction(_, _, result)
or
exists(RawIR::Instruction blockStartInstr |
@@ -282,7 +282,7 @@ private module Cached {
}
cached
Language::LanguageType getInstructionResultType(TStageInstruction instr) {
Language::LanguageType getInstructionResultType(Instruction instr) {
result = instr.(RawIR::Instruction).getResultLanguageType()
or
exists(Alias::MemoryLocation defLocation |
@@ -300,7 +300,7 @@ private module Cached {
}
cached
Opcode getInstructionOpcode(TStageInstruction instr) {
Opcode getInstructionOpcode(Instruction instr) {
instr = rawInstruction(_, result, _)
or
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
@@ -311,7 +311,7 @@ private module Cached {
}
cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
instr = rawInstruction(result, _, _)
or
instr = phiInstruction(result, _, _)

View File

@@ -263,7 +263,7 @@ private module Cached {
}
cached
Language::AST getInstructionAST(TStageInstruction instr) {
Language::AST getInstructionAST(Instruction instr) {
instr = rawInstruction(_, _, result)
or
exists(RawIR::Instruction blockStartInstr |
@@ -282,7 +282,7 @@ private module Cached {
}
cached
Language::LanguageType getInstructionResultType(TStageInstruction instr) {
Language::LanguageType getInstructionResultType(Instruction instr) {
result = instr.(RawIR::Instruction).getResultLanguageType()
or
exists(Alias::MemoryLocation defLocation |
@@ -300,7 +300,7 @@ private module Cached {
}
cached
Opcode getInstructionOpcode(TStageInstruction instr) {
Opcode getInstructionOpcode(Instruction instr) {
instr = rawInstruction(_, result, _)
or
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
@@ -311,7 +311,7 @@ private module Cached {
}
cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
instr = rawInstruction(result, _, _)
or
instr = phiInstruction(result, _, _)

View File

@@ -263,7 +263,7 @@ private module Cached {
}
cached
Language::AST getInstructionAST(TStageInstruction instr) {
Language::AST getInstructionAST(Instruction instr) {
instr = rawInstruction(_, _, result)
or
exists(RawIR::Instruction blockStartInstr |
@@ -282,7 +282,7 @@ private module Cached {
}
cached
Language::LanguageType getInstructionResultType(TStageInstruction instr) {
Language::LanguageType getInstructionResultType(Instruction instr) {
result = instr.(RawIR::Instruction).getResultLanguageType()
or
exists(Alias::MemoryLocation defLocation |
@@ -300,7 +300,7 @@ private module Cached {
}
cached
Opcode getInstructionOpcode(TStageInstruction instr) {
Opcode getInstructionOpcode(Instruction instr) {
instr = rawInstruction(_, result, _)
or
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
@@ -311,7 +311,7 @@ private module Cached {
}
cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
instr = rawInstruction(result, _, _)
or
instr = phiInstruction(result, _, _)