Skip to content

Commit eb987d5

Browse files
C++: Make Instruction.toString() less expensive
Previously, `Instruction.toString()` returned the same string that is used in IR dumps, which requires numbering all instructions and generating a unique string for each instruction. This is too expensive on large snapshots. I've moved the original code into the new `Instruction.getDumpString()`, and made `Instruction.toString()` just return the opcode plus `getAST().toString()`.
1 parent 89183bd commit eb987d5

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ class Instruction extends Construction::TInstruction {
133133
}
134134

135135
final string toString() {
136+
result = getOpcode().toString() + ": " + getAST().toString()
137+
}
138+
139+
/**
140+
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
141+
* would be printed by PrintIR.ql. For example:
142+
*
143+
* `mu0_28(int) = Store r0_26, r0_27`
144+
*/
145+
final string getDumpString() {
136146
result = getResultString() + " = " + getOperationString() + " " + getOperandsString()
137147
}
138148

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ class Instruction extends Construction::TInstruction {
133133
}
134134

135135
final string toString() {
136+
result = getOpcode().toString() + ": " + getAST().toString()
137+
}
138+
139+
/**
140+
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
141+
* would be printed by PrintIR.ql. For example:
142+
*
143+
* `mu0_28(int) = Store r0_26, r0_27`
144+
*/
145+
final string getDumpString() {
136146
result = getResultString() + " = " + getOperationString() + " " + getOperandsString()
137147
}
138148

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ class Instruction extends Construction::TInstruction {
133133
}
134134

135135
final string toString() {
136+
result = getOpcode().toString() + ": " + getAST().toString()
137+
}
138+
139+
/**
140+
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
141+
* would be printed by PrintIR.ql. For example:
142+
*
143+
* `mu0_28(int) = Store r0_26, r0_27`
144+
*/
145+
final string getDumpString() {
136146
result = getResultString() + " = " + getOperationString() + " " + getOperandsString()
137147
}
138148

0 commit comments

Comments
 (0)