@@ -94,8 +94,9 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
94
94
95
95
cached
96
96
private newtype TDefOrUseImpl =
97
- TDefImpl ( Operand address , int indirectionIndex ) {
98
- exists ( Instruction base | isDef ( _, _, address , base , _, indirectionIndex ) |
97
+ TDefImpl ( BaseSourceVariableInstruction base , Operand address , int indirectionIndex ) {
98
+ isDef ( _, _, address , base , _, indirectionIndex ) and
99
+ (
99
100
// We only include the definition if the SSA pruning stage
100
101
// concluded that the definition is live after the write.
101
102
any ( SsaInternals0:: Def def ) .getAddressOperand ( ) = address
@@ -105,8 +106,8 @@ private newtype TDefOrUseImpl =
105
106
base .( VariableAddressInstruction ) .getAstVariable ( ) instanceof GlobalLikeVariable
106
107
)
107
108
} or
108
- TUseImpl ( Operand operand , int indirectionIndex ) {
109
- isUse ( _, operand , _ , _, indirectionIndex ) and
109
+ TUseImpl ( BaseSourceVariableInstruction base , Operand operand , int indirectionIndex ) {
110
+ isUse ( _, operand , base , _, indirectionIndex ) and
110
111
not isDef ( _, _, operand , _, _, _)
111
112
} or
112
113
TGlobalUse ( GlobalLikeVariable v , IRFunction f , int indirectionIndex ) {
@@ -193,7 +194,7 @@ abstract private class DefOrUseImpl extends TDefOrUseImpl {
193
194
194
195
/**
195
196
* Gets the instruction that computes the base of this definition or use.
196
- * This is always a `VariableAddressInstruction` or an `AllocationInstruction `.
197
+ * This is always a `VariableAddressInstruction` or an `CallInstruction `.
197
198
*/
198
199
abstract BaseSourceVariableInstruction getBase ( ) ;
199
200
@@ -265,15 +266,17 @@ abstract class DefImpl extends DefOrUseImpl {
265
266
}
266
267
267
268
private class DirectDef extends DefImpl , TDefImpl {
268
- DirectDef ( ) { this = TDefImpl ( address , ind ) }
269
+ BaseSourceVariableInstruction base ;
270
+
271
+ DirectDef ( ) { this = TDefImpl ( base , address , ind ) }
269
272
270
- override BaseSourceVariableInstruction getBase ( ) { isDef ( _ , _ , address , result , _ , _ ) }
273
+ override BaseSourceVariableInstruction getBase ( ) { result = base }
271
274
272
- override int getIndirection ( ) { isDef ( _, _, address , _ , result , ind ) }
275
+ override int getIndirection ( ) { isDef ( _, _, address , base , result , ind ) }
273
276
274
- override Node0Impl getValue ( ) { isDef ( _, result , address , _ , _, _) }
277
+ override Node0Impl getValue ( ) { isDef ( _, result , address , base , _, _) }
275
278
276
- override predicate isCertain ( ) { isDef ( true , _, address , _ , _, ind ) }
279
+ override predicate isCertain ( ) { isDef ( true , _, address , base , _, ind ) }
277
280
}
278
281
279
282
private class IteratorDef extends DefImpl , TIteratorDef {
@@ -316,57 +319,52 @@ abstract class UseImpl extends DefOrUseImpl {
316
319
317
320
abstract private class OperandBasedUse extends UseImpl {
318
321
Operand operand ;
322
+ BaseSourceVariableInstruction base ;
319
323
320
324
bindingset [ ind]
321
325
OperandBasedUse ( ) { any ( ) }
322
326
323
327
final override predicate hasIndexInBlock ( IRBlock block , int index ) {
324
328
// See the comment in `ssa0`'s `OperandBasedUse` for an explanation of this
325
329
// predicate's implementation.
326
- exists ( BaseSourceVariableInstruction base | base = this .getBase ( ) |
327
- if base .getAst ( ) = any ( Cpp:: PostfixCrementOperation c ) .getOperand ( )
328
- then
329
- exists ( Operand op , int indirectionIndex , int indirection |
330
- indirectionIndex = this .getIndirectionIndex ( ) and
331
- indirection = this .getIndirection ( ) and
332
- op =
333
- min ( Operand cand , int i |
334
- isUse ( _, cand , base , indirection , indirectionIndex ) and
335
- block .getInstruction ( i ) = cand .getUse ( )
336
- |
337
- cand order by i
338
- ) and
339
- block .getInstruction ( index ) = op .getUse ( )
340
- )
341
- else operand .getUse ( ) = block .getInstruction ( index )
342
- )
330
+ if base .getAst ( ) = any ( Cpp:: PostfixCrementOperation c ) .getOperand ( )
331
+ then
332
+ exists ( Operand op , int indirectionIndex , int indirection |
333
+ indirectionIndex = this .getIndirectionIndex ( ) and
334
+ indirection = this .getIndirection ( ) and
335
+ op =
336
+ min ( Operand cand , int i |
337
+ isUse ( _, cand , base , indirection , indirectionIndex ) and
338
+ block .getInstruction ( i ) = cand .getUse ( )
339
+ |
340
+ cand order by i
341
+ ) and
342
+ block .getInstruction ( index ) = op .getUse ( )
343
+ )
344
+ else operand .getUse ( ) = block .getInstruction ( index )
343
345
}
344
346
347
+ final override BaseSourceVariableInstruction getBase ( ) { result = base }
348
+
345
349
final Operand getOperand ( ) { result = operand }
346
350
347
351
final override Cpp:: Location getLocation ( ) { result = operand .getLocation ( ) }
348
352
}
349
353
350
354
private class DirectUse extends OperandBasedUse , TUseImpl {
351
- DirectUse ( ) { this = TUseImpl ( operand , ind ) }
352
-
353
- override int getIndirection ( ) { isUse ( _, operand , _, result , ind ) }
355
+ DirectUse ( ) { this = TUseImpl ( base , operand , ind ) }
354
356
355
- override BaseSourceVariableInstruction getBase ( ) { isUse ( _, operand , result , _ , ind ) }
357
+ override int getIndirection ( ) { isUse ( _, operand , base , result , ind ) }
356
358
357
- override predicate isCertain ( ) { isUse ( true , operand , _ , _, ind ) }
359
+ override predicate isCertain ( ) { isUse ( true , operand , base , _, ind ) }
358
360
359
361
override Node getNode ( ) { nodeHasOperand ( result , operand , ind ) }
360
362
}
361
363
362
364
private class IteratorUse extends OperandBasedUse , TIteratorUse {
363
- BaseSourceVariableInstruction container ;
364
-
365
- IteratorUse ( ) { this = TIteratorUse ( operand , container , ind ) }
365
+ IteratorUse ( ) { this = TIteratorUse ( operand , base , ind ) }
366
366
367
- override int getIndirection ( ) { isIteratorUse ( container , operand , result , ind ) }
368
-
369
- override BaseSourceVariableInstruction getBase ( ) { result = container }
367
+ override int getIndirection ( ) { isIteratorUse ( base , operand , result , ind ) }
370
368
371
369
override predicate isCertain ( ) { none ( ) }
372
370
0 commit comments