Skip to content

Commit 390ee3a

Browse files
authored
Merge pull request github#5829 from MathiasVP/reorder-get-instruction-opcode
C++: Reorder getInstructionOpcode
2 parents f03c99a + 066cdb5 commit 390ee3a

File tree

10 files changed

+47
-24
lines changed

10 files changed

+47
-24
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ class Instruction extends Construction::TStageInstruction {
297297
/**
298298
* Gets the opcode that specifies the operation performed by this instruction.
299299
*/
300-
final Opcode getOpcode() { result = Construction::getInstructionOpcode(this) }
300+
pragma[inline]
301+
final Opcode getOpcode() { Construction::getInstructionOpcode(result, this) }
301302

302303
/**
303304
* Gets all direct uses of the result of this instruction. The result can be

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,21 @@ private module Cached {
338338
instr = unreachedInstruction(_) and result = Language::getVoidType()
339339
}
340340

341+
/**
342+
* Holds if `opcode` is the opcode that specifies the operation performed by `instr`.
343+
*
344+
* The parameters are ordered such that they produce a clean join (with no need for reordering)
345+
* in the characteristic predicates of the `Instruction` subclasses.
346+
*/
341347
cached
342-
Opcode getInstructionOpcode(Instruction instr) {
343-
result = getOldInstruction(instr).getOpcode()
348+
predicate getInstructionOpcode(Opcode opcode, Instruction instr) {
349+
opcode = getOldInstruction(instr).getOpcode()
344350
or
345-
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
351+
instr = phiInstruction(_, _) and opcode instanceof Opcode::Phi
346352
or
347-
instr = chiInstruction(_) and result instanceof Opcode::Chi
353+
instr = chiInstruction(_) and opcode instanceof Opcode::Chi
348354
or
349-
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
355+
instr = unreachedInstruction(_) and opcode instanceof Opcode::Unreached
350356
}
351357

352358
cached

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ class Instruction extends Construction::TStageInstruction {
297297
/**
298298
* Gets the opcode that specifies the operation performed by this instruction.
299299
*/
300-
final Opcode getOpcode() { result = Construction::getInstructionOpcode(this) }
300+
pragma[inline]
301+
final Opcode getOpcode() { Construction::getInstructionOpcode(result, this) }
301302

302303
/**
303304
* Gets all direct uses of the result of this instruction. The result can be

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ CppType getInstructionResultType(TStageInstruction instr) {
360360
getInstructionTranslatedElement(instr).hasInstruction(_, getInstructionTag(instr), result)
361361
}
362362

363-
Opcode getInstructionOpcode(TStageInstruction instr) {
364-
getInstructionTranslatedElement(instr).hasInstruction(result, getInstructionTag(instr), _)
363+
predicate getInstructionOpcode(Opcode opcode, TStageInstruction instr) {
364+
getInstructionTranslatedElement(instr).hasInstruction(opcode, getInstructionTag(instr), _)
365365
}
366366

367367
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ class Instruction extends Construction::TStageInstruction {
297297
/**
298298
* Gets the opcode that specifies the operation performed by this instruction.
299299
*/
300-
final Opcode getOpcode() { result = Construction::getInstructionOpcode(this) }
300+
pragma[inline]
301+
final Opcode getOpcode() { Construction::getInstructionOpcode(result, this) }
301302

302303
/**
303304
* Gets all direct uses of the result of this instruction. The result can be

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,21 @@ private module Cached {
338338
instr = unreachedInstruction(_) and result = Language::getVoidType()
339339
}
340340

341+
/**
342+
* Holds if `opcode` is the opcode that specifies the operation performed by `instr`.
343+
*
344+
* The parameters are ordered such that they produce a clean join (with no need for reordering)
345+
* in the characteristic predicates of the `Instruction` subclasses.
346+
*/
341347
cached
342-
Opcode getInstructionOpcode(Instruction instr) {
343-
result = getOldInstruction(instr).getOpcode()
348+
predicate getInstructionOpcode(Opcode opcode, Instruction instr) {
349+
opcode = getOldInstruction(instr).getOpcode()
344350
or
345-
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
351+
instr = phiInstruction(_, _) and opcode instanceof Opcode::Phi
346352
or
347-
instr = chiInstruction(_) and result instanceof Opcode::Chi
353+
instr = chiInstruction(_) and opcode instanceof Opcode::Chi
348354
or
349-
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
355+
instr = unreachedInstruction(_) and opcode instanceof Opcode::Unreached
350356
}
351357

352358
cached

csharp/ql/src/experimental/ir/implementation/raw/Instruction.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ class Instruction extends Construction::TStageInstruction {
297297
/**
298298
* Gets the opcode that specifies the operation performed by this instruction.
299299
*/
300-
final Opcode getOpcode() { result = Construction::getInstructionOpcode(this) }
300+
pragma[inline]
301+
final Opcode getOpcode() { Construction::getInstructionOpcode(result, this) }
301302

302303
/**
303304
* Gets all direct uses of the result of this instruction. The result can be

csharp/ql/src/experimental/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ import Cached
165165
cached
166166
private module Cached {
167167
cached
168-
Opcode getInstructionOpcode(TRawInstruction instr) {
168+
predicate getInstructionOpcode(Opcode opcode, TRawInstruction instr) {
169169
exists(TranslatedElement element, InstructionTag tag |
170170
instructionOrigin(instr, element, tag) and
171-
element.hasInstruction(result, tag, _)
171+
element.hasInstruction(opcode, tag, _)
172172
)
173173
}
174174

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ class Instruction extends Construction::TStageInstruction {
297297
/**
298298
* Gets the opcode that specifies the operation performed by this instruction.
299299
*/
300-
final Opcode getOpcode() { result = Construction::getInstructionOpcode(this) }
300+
pragma[inline]
301+
final Opcode getOpcode() { Construction::getInstructionOpcode(result, this) }
301302

302303
/**
303304
* Gets all direct uses of the result of this instruction. The result can be

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,21 @@ private module Cached {
338338
instr = unreachedInstruction(_) and result = Language::getVoidType()
339339
}
340340

341+
/**
342+
* Holds if `opcode` is the opcode that specifies the operation performed by `instr`.
343+
*
344+
* The parameters are ordered such that they produce a clean join (with no need for reordering)
345+
* in the characteristic predicates of the `Instruction` subclasses.
346+
*/
341347
cached
342-
Opcode getInstructionOpcode(Instruction instr) {
343-
result = getOldInstruction(instr).getOpcode()
348+
predicate getInstructionOpcode(Opcode opcode, Instruction instr) {
349+
opcode = getOldInstruction(instr).getOpcode()
344350
or
345-
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
351+
instr = phiInstruction(_, _) and opcode instanceof Opcode::Phi
346352
or
347-
instr = chiInstruction(_) and result instanceof Opcode::Chi
353+
instr = chiInstruction(_) and opcode instanceof Opcode::Chi
348354
or
349-
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
355+
instr = unreachedInstruction(_) and opcode instanceof Opcode::Unreached
350356
}
351357

352358
cached

0 commit comments

Comments
 (0)