Skip to content

Commit ded377b

Browse files
committed
C++: Reorder getInstructionOpcode to produce better RA.
1 parent 5bcf810 commit ded377b

File tree

9 files changed

+27
-22
lines changed

9 files changed

+27
-22
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ private module Cached {
339339
}
340340

341341
cached
342-
Opcode getInstructionOpcode(Instruction instr) {
343-
result = getOldInstruction(instr).getOpcode()
342+
predicate getInstructionOpcode(Opcode opcode, Instruction instr) {
343+
opcode = getOldInstruction(instr).getOpcode()
344344
or
345-
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
345+
instr = phiInstruction(_, _) and opcode instanceof Opcode::Phi
346346
or
347-
instr = chiInstruction(_) and result instanceof Opcode::Chi
347+
instr = chiInstruction(_) and opcode instanceof Opcode::Chi
348348
or
349-
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
349+
instr = unreachedInstruction(_) and opcode instanceof Opcode::Unreached
350350
}
351351

352352
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ private module Cached {
339339
}
340340

341341
cached
342-
Opcode getInstructionOpcode(Instruction instr) {
343-
result = getOldInstruction(instr).getOpcode()
342+
predicate getInstructionOpcode(Opcode opcode, Instruction instr) {
343+
opcode = getOldInstruction(instr).getOpcode()
344344
or
345-
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
345+
instr = phiInstruction(_, _) and opcode instanceof Opcode::Phi
346346
or
347-
instr = chiInstruction(_) and result instanceof Opcode::Chi
347+
instr = chiInstruction(_) and opcode instanceof Opcode::Chi
348348
or
349-
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
349+
instr = unreachedInstruction(_) and opcode instanceof Opcode::Unreached
350350
}
351351

352352
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/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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ private module Cached {
339339
}
340340

341341
cached
342-
Opcode getInstructionOpcode(Instruction instr) {
343-
result = getOldInstruction(instr).getOpcode()
342+
predicate getInstructionOpcode(Opcode opcode, Instruction instr) {
343+
opcode = getOldInstruction(instr).getOpcode()
344344
or
345-
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
345+
instr = phiInstruction(_, _) and opcode instanceof Opcode::Phi
346346
or
347-
instr = chiInstruction(_) and result instanceof Opcode::Chi
347+
instr = chiInstruction(_) and opcode instanceof Opcode::Chi
348348
or
349-
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
349+
instr = unreachedInstruction(_) and opcode instanceof Opcode::Unreached
350350
}
351351

352352
cached

0 commit comments

Comments
 (0)