Skip to content

Commit 947634f

Browse files
committed
C++: Speed up getInstructionOperandDefinition
A part of `SSAConstruction.getInstructionOperandDefinition` was more expensive than it had to be. On a ChakraCore snapshot, this changes the tuple counts from 3020569 ~2% {3} r40 = JOIN OperandTag::TUnmodeledUseOperand#f WITH Instruction::Instruction::getFunction_dispred#ff CARTESIAN PRODUCT OUTPUT FIELDS {Instruction::Instruction::getFunction_dispred#ff.<0>,OperandTag::TUnmodeledUseOperand#f.<0>,Instruction::Instruction::getFunction_dispred#ff.<1>} 62405 ~0% {3} r41 = JOIN r40 WITH Instruction::UnmodeledUseInstruction#class#fffffff ON r40.<0>=Instruction::UnmodeledUseInstruction#class#fffffff.<0> OUTPUT FIELDS {r40.<2>,r40.<1>,r40.<0>} 2868421 ~1% {3} r42 = JOIN r41 WITH Instruction::Instruction::getFunction_dispred#ff_10#join_rhs ON r41.<0>=Instruction::Instruction::getFunction_dispred#ff_10#join_rhs.<0> OUTPUT FIELDS {Instruction::Instruction::getFunction_dispred#ff_10#join_rhs.<1>,r41.<1>,r41.<2>} 62405 ~0% {3} r43 = JOIN r42 WITH Instruction::UnmodeledDefinitionInstruction#class#fffffff ON r42.<0>=Instruction::UnmodeledDefinitionInstruction#class#fffffff.<0> OUTPUT FIELDS {r42.<2>,r42.<1>,r42.<0>} to (0s) Starting to evaluate predicate SSAConstruction::Cached::getUnmodeledUseInstruction#ff (0s) Tuple counts: 62405 ~0% {2} r1 = JOIN Instruction::UnmodeledUseInstruction#class#fffffff WITH Instruction::Instruction::getFunction_dispred#ff ON Instruction::UnmodeledUseInstruction#class#fffffff.<0>=Instruction::Instruction::getFunction_dispred#ff.<0> OUTPUT FIELDS {Instruction::Instruction::getFunction_dispred#ff.<1>,Instruction::Instruction::getFunction_dispred#ff.<0>} return r1 ... 75716 ~0% {3} r40 = JOIN OperandTag::TUnmodeledUseOperand#f WITH FunctionIR::FunctionIR::getUnmodeledDefinitionInstruction#ff CARTESIAN PRODUCT OUTPUT FIELDS {FunctionIR::FunctionIR::getUnmodeledDefinitionInstruction#ff.<0>,OperandTag::TUnmodeledUseOperand#f.<0>,FunctionIR::FunctionIR::getUnmodeledDefinitionInstruction#ff.<1>} 62405 ~0% {3} r41 = JOIN r40 WITH FunctionIR::FunctionIR::getUnmodeledUseInstruction#ff ON r40.<0>=FunctionIR::FunctionIR::getUnmodeledUseInstruction#ff.<0> OUTPUT FIELDS {FunctionIR::FunctionIR::getUnmodeledUseInstruction#ff.<1>,r40.<1>,r40.<2>}
1 parent fc5b9dd commit 947634f

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/FunctionIR.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class FunctionIR extends TFunctionIR {
5656
result.getFunctionIR() = this
5757
}
5858

59+
pragma[noinline]
60+
final UnmodeledUseInstruction getUnmodeledUseInstruction() {
61+
result.getFunctionIR() = this
62+
}
63+
5964
/**
6065
* Gets the single return instruction for this function.
6166
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ cached private module Cached {
192192
instruction.getTag() = ChiTag(getOldInstruction(result)) and
193193
tag instanceof ChiPartialOperandTag
194194
or
195-
instruction instanceof UnmodeledUseInstruction and
196-
tag instanceof UnmodeledUseOperandTag and
197-
result instanceof UnmodeledDefinitionInstruction and
198-
instruction.getFunction() = result.getFunction()
195+
exists(FunctionIR f |
196+
tag instanceof UnmodeledUseOperandTag and
197+
result = f.getUnmodeledDefinitionInstruction() and
198+
instruction = f.getUnmodeledUseInstruction()
199+
)
199200
or
200201
tag instanceof ChiTotalOperandTag and
201202
result = getChiInstructionTotalOperand(instruction)

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/FunctionIR.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class FunctionIR extends TFunctionIR {
5656
result.getFunctionIR() = this
5757
}
5858

59+
pragma[noinline]
60+
final UnmodeledUseInstruction getUnmodeledUseInstruction() {
61+
result.getFunctionIR() = this
62+
}
63+
5964
/**
6065
* Gets the single return instruction for this function.
6166
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/FunctionIR.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class FunctionIR extends TFunctionIR {
5656
result.getFunctionIR() = this
5757
}
5858

59+
pragma[noinline]
60+
final UnmodeledUseInstruction getUnmodeledUseInstruction() {
61+
result.getFunctionIR() = this
62+
}
63+
5964
/**
6065
* Gets the single return instruction for this function.
6166
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ cached private module Cached {
192192
instruction.getTag() = ChiTag(getOldInstruction(result)) and
193193
tag instanceof ChiPartialOperandTag
194194
or
195-
instruction instanceof UnmodeledUseInstruction and
196-
tag instanceof UnmodeledUseOperandTag and
197-
result instanceof UnmodeledDefinitionInstruction and
198-
instruction.getFunction() = result.getFunction()
195+
exists(FunctionIR f |
196+
tag instanceof UnmodeledUseOperandTag and
197+
result = f.getUnmodeledDefinitionInstruction() and
198+
instruction = f.getUnmodeledUseInstruction()
199+
)
199200
or
200201
tag instanceof ChiTotalOperandTag and
201202
result = getChiInstructionTotalOperand(instruction)

0 commit comments

Comments
 (0)