Skip to content

Commit 89a59d5

Browse files
author
Robert Marsh
committed
C++: comments about shared Operand IPA type
1 parent 1e08c11 commit 89a59d5

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ private import Imports::OperandTag
1313
private import Imports::TOperand
1414
private import internal.OperandInternal
1515

16-
class TOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
16+
/**
17+
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
18+
* of `TOperand` that are used in this stage.
19+
*/
20+
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
1721

1822
/**
1923
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2024
* (the defining instruction) in another instruction (the use instruction)
2125
*/
22-
class Operand extends TOperand {
26+
class Operand extends TStageOperand {
2327
/** Gets a textual representation of this element. */
2428
string toString() { result = "Operand" }
2529

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ private module Cached {
4343
class TStageInstruction =
4444
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
4545

46-
class TStageOperand =
47-
TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
48-
4946
cached
5047
predicate hasInstruction(TStageInstruction instr) {
5148
instr instanceof TRawInstruction and instr instanceof OldInstruction

cpp/ql/src/semmle/code/cpp/ir/implementation/internal/TOperand.qll

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ private import semmle.code.cpp.ir.implementation.unaliased_ssa.IR as Unaliased
88
private import semmle.code.cpp.ir.implementation.aliased_ssa.IR as Aliased
99
private import semmle.code.cpp.ir.internal.Overlap
1010

11+
/**
12+
* Provides the newtype used to represent operands across all phases of the IR.
13+
*/
1114
private module Internal {
15+
16+
/**
17+
* An IR operand. `TOperand` is shared across all phases of the IR. There are branches of this
18+
* type for operands created directly from the AST (`TRegisterOperand` and `TNonSSAMemoryOperand`),
19+
* for operands computed by each stage of SSA construction (`T*PhiOperand` and
20+
* `TAliasedChiOperand`), and a placehold branch for operands that do not exist in a given
21+
* stage of IR construction (`TNoOperand`).
22+
*/
1223
cached
1324
newtype TOperand =
1425
// RAW
@@ -51,6 +62,10 @@ private module Internal {
5162
}
5263
}
5364

65+
/**
66+
* Reexports some branches from `TOperand` so they can be used in stage modules without importing
67+
* `TOperand` itself.
68+
*/
5469
private module Shared {
5570
class TRegisterOperand = Internal::TRegisterOperand;
5671

@@ -73,6 +88,12 @@ private module Shared {
7388
}
7489
}
7590

91+
/**
92+
* Provides wrappers for the constructors of each branch of `TOperand` that is used by the
93+
* raw IR stage.
94+
* These wrappers are not parameterized because it is not possible to invoke an IPA constructor via
95+
* a class alias.
96+
*/
7697
module RawOperands {
7798
import Shared
7899

@@ -96,9 +117,12 @@ module RawOperands {
96117
TChiOperand chiOperand(Raw::Instruction useInstr, ChiOperandTag tag) { none() }
97118
}
98119

99-
// TODO: can we get everything into either here or Operand.qll?
100-
// TODO: can we put `TStageOperand` in Construction? Might break something about the module caching setup, `Operand` is currently after everything in SSAConstruction
101-
// TODO: share empty ChiOperand?
120+
/**
121+
* Provides wrappers for the constructors of each branch of `TOperand` that is used by the
122+
* unaliased SSA stage.
123+
* These wrappers are not parameterized because it is not possible to invoke an IPA constructor via
124+
* a class alias.
125+
*/
102126
module UnliasedSSAOperands {
103127
import Shared
104128

@@ -122,6 +146,12 @@ module UnliasedSSAOperands {
122146
TChiOperand chiOperand(Unaliased::Instruction useInstr, ChiOperandTag tag) { none() }
123147
}
124148

149+
/**
150+
* Provides wrappers for the constructors of each branch of `TOperand` that is used by the
151+
* asliased SSA stage.
152+
* These wrappers are not parameterized because it is not possible to invoke an IPA constructor via
153+
* a class alias.
154+
*/
125155
module AliasedSSAOperands {
126156
import Shared
127157

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ private import Imports::OperandTag
1313
private import Imports::TOperand
1414
private import internal.OperandInternal
1515

16-
class TOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
16+
/**
17+
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
18+
* of `TOperand` that are used in this stage.
19+
*/
20+
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
1721

1822
/**
1923
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2024
* (the defining instruction) in another instruction (the use instruction)
2125
*/
22-
class Operand extends TOperand {
26+
class Operand extends TStageOperand {
2327
/** Gets a textual representation of this element. */
2428
string toString() { result = "Operand" }
2529

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ private import Imports::OperandTag
1313
private import Imports::TOperand
1414
private import internal.OperandInternal
1515

16-
class TOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
16+
/**
17+
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
18+
* of `TOperand` that are used in this stage.
19+
*/
20+
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
1721

1822
/**
1923
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2024
* (the defining instruction) in another instruction (the use instruction)
2125
*/
22-
class Operand extends TOperand {
26+
class Operand extends TStageOperand {
2327
/** Gets a textual representation of this element. */
2428
string toString() { result = "Operand" }
2529

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ private module Cached {
4343
class TStageInstruction =
4444
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
4545

46-
class TStageOperand =
47-
TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
48-
4946
cached
5047
predicate hasInstruction(TStageInstruction instr) {
5148
instr instanceof TRawInstruction and instr instanceof OldInstruction

0 commit comments

Comments
 (0)