@@ -119,27 +119,67 @@ module SemanticExprConfig {
119
119
result = block .getDisplayIndex ( )
120
120
}
121
121
122
- class SsaVariable instanceof IR:: Instruction {
123
- SsaVariable ( ) { super .hasMemoryResult ( ) }
122
+ newtype TSsaVariable =
123
+ TSsaInstruction ( IR:: Instruction instr ) { instr .hasMemoryResult ( ) } or
124
+ TSsaOperand ( IR:: Operand op ) { op .isDefinitionInexact ( ) }
124
125
125
- final string toString ( ) { result = super .toString ( ) }
126
+ class SsaVariable extends TSsaVariable {
127
+ string toString ( ) { none ( ) }
126
128
127
- final Location getLocation ( ) { result = super .getLocation ( ) }
129
+ Location getLocation ( ) { none ( ) }
130
+
131
+ IR:: Instruction asInstruction ( ) { none ( ) }
132
+
133
+ IR:: Operand asOperand ( ) { none ( ) }
134
+ }
135
+
136
+ class SsaInstructionVariable extends SsaVariable , TSsaInstruction {
137
+ IR:: Instruction instr ;
138
+
139
+ SsaInstructionVariable ( ) { this = TSsaInstruction ( instr ) }
140
+
141
+ final override string toString ( ) { result = instr .toString ( ) }
142
+
143
+ final override Location getLocation ( ) { result = instr .getLocation ( ) }
144
+
145
+ final override IR:: Instruction asInstruction ( ) { result = instr }
146
+ }
147
+
148
+ class SsaOperand extends SsaVariable , TSsaOperand {
149
+ IR:: Operand op ;
150
+
151
+ SsaOperand ( ) { this = TSsaOperand ( op ) }
152
+
153
+ final override string toString ( ) { result = op .toString ( ) }
154
+
155
+ final override Location getLocation ( ) { result = op .getLocation ( ) }
156
+
157
+ final override IR:: Operand asOperand ( ) { result = op }
128
158
}
129
159
130
- predicate explicitUpdate ( SsaVariable v , Expr sourceExpr ) { v = sourceExpr }
160
+ predicate explicitUpdate ( SsaVariable v , Expr sourceExpr ) { v . asInstruction ( ) = sourceExpr }
131
161
132
- predicate phi ( SsaVariable v ) { v instanceof IR:: PhiInstruction }
162
+ predicate phi ( SsaVariable v ) { v . asInstruction ( ) instanceof IR:: PhiInstruction }
133
163
134
- SsaVariable getAPhiInput ( SsaVariable v ) { result = v .( IR:: PhiInstruction ) .getAnInput ( ) }
164
+ SsaVariable getAPhiInput ( SsaVariable v ) {
165
+ exists ( IR:: PhiInstruction instr |
166
+ result .asInstruction ( ) = instr .getAnInput ( )
167
+ or
168
+ result .asOperand ( ) = instr .getAnInputOperand ( )
169
+ )
170
+ }
135
171
136
- Expr getAUse ( SsaVariable v ) { result .( IR:: LoadInstruction ) .getSourceValue ( ) = v }
172
+ Expr getAUse ( SsaVariable v ) { result .( IR:: LoadInstruction ) .getSourceValue ( ) = v . asInstruction ( ) }
137
173
138
174
SemType getSsaVariableType ( SsaVariable v ) {
139
- result = getSemanticType ( v .( IR :: Instruction ) .getResultIRType ( ) )
175
+ result = getSemanticType ( v .asInstruction ( ) .getResultIRType ( ) )
140
176
}
141
177
142
- BasicBlock getSsaVariableBasicBlock ( SsaVariable v ) { result = v .( IR:: Instruction ) .getBlock ( ) }
178
+ BasicBlock getSsaVariableBasicBlock ( SsaVariable v ) {
179
+ result = v .asInstruction ( ) .getBlock ( )
180
+ or
181
+ result = v .asOperand ( ) .getUse ( ) .getBlock ( )
182
+ }
143
183
144
184
private newtype TReadPosition =
145
185
TReadPositionBlock ( IR:: IRBlock block ) or
@@ -169,7 +209,7 @@ module SemanticExprConfig {
169
209
170
210
final override predicate hasRead ( SsaVariable v ) {
171
211
exists ( IR:: Operand operand |
172
- operand .getDef ( ) = v and
212
+ operand .getDef ( ) = v . asInstruction ( ) and
173
213
not operand instanceof IR:: PhiInputOperand and
174
214
operand .getUse ( ) .getBlock ( ) = block
175
215
)
@@ -188,7 +228,7 @@ module SemanticExprConfig {
188
228
189
229
final override predicate hasRead ( SsaVariable v ) {
190
230
exists ( IR:: PhiInputOperand operand |
191
- operand .getDef ( ) = v and
231
+ operand .getDef ( ) = v . asInstruction ( ) and
192
232
operand .getPredecessorBlock ( ) = pred and
193
233
operand .getUse ( ) .getBlock ( ) = succ
194
234
)
@@ -207,7 +247,12 @@ module SemanticExprConfig {
207
247
exists ( IR:: PhiInputOperand operand |
208
248
pos = TReadPositionPhiInputEdge ( operand .getPredecessorBlock ( ) , operand .getUse ( ) .getBlock ( ) )
209
249
|
210
- phi = operand .getUse ( ) and input = operand .getDef ( )
250
+ phi .asInstruction ( ) = operand .getUse ( ) and
251
+ (
252
+ input .asInstruction ( ) = operand .getDef ( )
253
+ or
254
+ input .asOperand ( ) = operand
255
+ )
211
256
)
212
257
}
213
258
@@ -224,21 +269,21 @@ module SemanticExprConfig {
224
269
225
270
override string toString ( ) {
226
271
result =
227
- min ( SsaVariable instr |
228
- instr = bound .getValueNumber ( ) .getAnInstruction ( )
272
+ min ( SsaVariable v |
273
+ v . asInstruction ( ) = bound .getValueNumber ( ) .getAnInstruction ( )
229
274
|
230
- instr
275
+ v
231
276
order by
232
- instr . ( IR :: Instruction ) .getBlock ( ) .getDisplayIndex ( ) ,
233
- instr . ( IR :: Instruction ) .getDisplayIndexInBlock ( )
277
+ v . asInstruction ( ) .getBlock ( ) .getDisplayIndex ( ) ,
278
+ v . asInstruction ( ) .getDisplayIndexInBlock ( )
234
279
) .toString ( )
235
280
}
236
281
}
237
282
238
283
predicate zeroBound ( Bound bound ) { bound instanceof IRBound:: ZeroBound }
239
284
240
285
predicate ssaBound ( Bound bound , SsaVariable v ) {
241
- v = bound .( IRBound:: ValueNumberBound ) .getValueNumber ( ) .getAnInstruction ( )
286
+ v . asInstruction ( ) = bound .( IRBound:: ValueNumberBound ) .getValueNumber ( ) .getAnInstruction ( )
242
287
}
243
288
244
289
Expr getBoundExpr ( Bound bound , int delta ) {
@@ -280,9 +325,13 @@ SemBasicBlock getSemanticBasicBlock(IR::IRBlock block) { result = block }
280
325
281
326
IR:: IRBlock getCppBasicBlock ( SemBasicBlock block ) { block = result }
282
327
283
- SemSsaVariable getSemanticSsaVariable ( IR:: Instruction instr ) { result = instr }
328
+ SemSsaVariable getSemanticSsaVariable ( IR:: Instruction instr ) {
329
+ result .( SemanticExprConfig:: SsaVariable ) .asInstruction ( ) = instr
330
+ }
284
331
285
- IR:: Instruction getCppSsaVariableInstruction ( SemSsaVariable v ) { v = result }
332
+ IR:: Instruction getCppSsaVariableInstruction ( SemSsaVariable var ) {
333
+ var .( SemanticExprConfig:: SsaVariable ) .asInstruction ( ) = result
334
+ }
286
335
287
336
SemBound getSemanticBound ( IRBound:: Bound bound ) { result = bound }
288
337
0 commit comments