@@ -14,19 +14,66 @@ private newtype TOperand =
14
14
not Construction:: isInCycle ( useInstr ) and
15
15
strictcount ( Construction:: getRegisterOperandDefinition ( useInstr , tag ) ) = 1
16
16
} or
17
- TNonPhiMemoryOperand (
18
- Instruction useInstr , MemoryOperandTag tag , Instruction defInstr , Overlap overlap
19
- ) {
20
- defInstr = Construction:: getMemoryOperandDefinition ( useInstr , tag , overlap ) and
21
- not Construction:: isInCycle ( useInstr ) and
22
- strictcount ( Construction:: getMemoryOperandDefinition ( useInstr , tag , _) ) = 1
17
+ TNonPhiMemoryOperand ( Instruction useInstr , MemoryOperandTag tag ) {
18
+ useInstr .getOpcode ( ) .hasOperand ( tag )
23
19
} or
24
20
TPhiOperand (
25
21
PhiInstruction useInstr , Instruction defInstr , IRBlock predecessorBlock , Overlap overlap
26
22
) {
27
23
defInstr = Construction:: getPhiOperandDefinition ( useInstr , predecessorBlock , overlap )
28
24
}
29
25
26
+ /**
27
+ * Base class for all register operands. This is a placeholder for the IPA union type that we will
28
+ * eventually use for this purpose.
29
+ */
30
+ private class RegisterOperandBase extends TRegisterOperand {
31
+ /** Gets a textual representation of this element. */
32
+ abstract string toString ( ) ;
33
+ }
34
+
35
+ /**
36
+ * Returns the register operand with the specified parameters.
37
+ */
38
+ private RegisterOperandBase registerOperand (
39
+ Instruction useInstr , RegisterOperandTag tag , Instruction defInstr
40
+ ) {
41
+ result = TRegisterOperand ( useInstr , tag , defInstr )
42
+ }
43
+
44
+ /**
45
+ * Base class for all non-Phi memory operands. This is a placeholder for the IPA union type that we
46
+ * will eventually use for this purpose.
47
+ */
48
+ private class NonPhiMemoryOperandBase extends TNonPhiMemoryOperand {
49
+ /** Gets a textual representation of this element. */
50
+ abstract string toString ( ) ;
51
+ }
52
+
53
+ /**
54
+ * Returns the non-Phi memory operand with the specified parameters.
55
+ */
56
+ private NonPhiMemoryOperandBase nonPhiMemoryOperand ( Instruction useInstr , MemoryOperandTag tag ) {
57
+ result = TNonPhiMemoryOperand ( useInstr , tag )
58
+ }
59
+
60
+ /**
61
+ * Base class for all Phi operands. This is a placeholder for the IPA union type that we will
62
+ * eventually use for this purpose.
63
+ */
64
+ private class PhiOperandBase extends TPhiOperand {
65
+ abstract string toString ( ) ;
66
+ }
67
+
68
+ /**
69
+ * Returns the Phi operand with the specified parameters.
70
+ */
71
+ private PhiOperandBase phiOperand (
72
+ Instruction useInstr , Instruction defInstr , IRBlock predecessorBlock , Overlap overlap
73
+ ) {
74
+ result = TPhiOperand ( useInstr , defInstr , predecessorBlock , overlap )
75
+ }
76
+
30
77
/**
31
78
* A source operand of an `Instruction`. The operand represents a value consumed by the instruction.
32
79
*/
@@ -165,8 +212,8 @@ class Operand extends TOperand {
165
212
*/
166
213
class MemoryOperand extends Operand {
167
214
MemoryOperand ( ) {
168
- this = TNonPhiMemoryOperand ( _ , _ , _ , _ ) or
169
- this = TPhiOperand ( _ , _ , _ , _ )
215
+ this instanceof NonPhiMemoryOperandBase or
216
+ this instanceof PhiOperandBase
170
217
}
171
218
172
219
/**
@@ -200,18 +247,15 @@ class MemoryOperand extends Operand {
200
247
*/
201
248
class NonPhiOperand extends Operand {
202
249
Instruction useInstr ;
203
- Instruction defInstr ;
204
250
OperandTag tag ;
205
251
206
252
NonPhiOperand ( ) {
207
- this = TRegisterOperand ( useInstr , tag , defInstr ) or
208
- this = TNonPhiMemoryOperand ( useInstr , tag , defInstr , _ )
253
+ this = registerOperand ( useInstr , tag , _ ) or
254
+ this = nonPhiMemoryOperand ( useInstr , tag )
209
255
}
210
256
211
257
final override Instruction getUse ( ) { result = useInstr }
212
258
213
- final override Instruction getAnyDef ( ) { result = defInstr }
214
-
215
259
final override string getDumpLabel ( ) { result = tag .getLabel ( ) }
216
260
217
261
final override int getDumpSortOrder ( ) { result = tag .getSortOrder ( ) }
@@ -222,22 +266,41 @@ class NonPhiOperand extends Operand {
222
266
/**
223
267
* An operand that consumes a register (non-memory) result.
224
268
*/
225
- class RegisterOperand extends NonPhiOperand , TRegisterOperand {
269
+ class RegisterOperand extends NonPhiOperand , RegisterOperandBase {
226
270
override RegisterOperandTag tag ;
271
+ Instruction defInstr ;
272
+
273
+ RegisterOperand ( ) { this = registerOperand ( useInstr , tag , defInstr ) }
274
+
275
+ final override string toString ( ) { result = tag .toString ( ) }
276
+
277
+ final override Instruction getAnyDef ( ) { result = defInstr }
227
278
228
279
final override Overlap getDefinitionOverlap ( ) {
229
280
// All register results overlap exactly with their uses.
230
281
result instanceof MustExactlyOverlap
231
282
}
232
283
}
233
284
234
- class NonPhiMemoryOperand extends NonPhiOperand , MemoryOperand , TNonPhiMemoryOperand {
285
+ class NonPhiMemoryOperand extends NonPhiOperand , MemoryOperand , NonPhiMemoryOperandBase {
235
286
override MemoryOperandTag tag ;
236
- Overlap overlap ;
237
287
238
- NonPhiMemoryOperand ( ) { this = TNonPhiMemoryOperand ( useInstr , tag , defInstr , overlap ) }
288
+ NonPhiMemoryOperand ( ) { this = nonPhiMemoryOperand ( useInstr , tag ) }
239
289
240
- final override Overlap getDefinitionOverlap ( ) { result = overlap }
290
+ final override string toString ( ) { result = tag .toString ( ) }
291
+
292
+ final override Instruction getAnyDef ( ) {
293
+ result = unique( Instruction defInstr | hasDefinition ( defInstr , _) )
294
+ }
295
+
296
+ final override Overlap getDefinitionOverlap ( ) { hasDefinition ( _, result ) }
297
+
298
+ pragma [ noinline]
299
+ private predicate hasDefinition ( Instruction defInstr , Overlap overlap ) {
300
+ defInstr = Construction:: getMemoryOperandDefinition ( useInstr , tag , overlap ) and
301
+ not Construction:: isInCycle ( useInstr ) and
302
+ strictcount ( Construction:: getMemoryOperandDefinition ( useInstr , tag , _) ) = 1
303
+ }
241
304
}
242
305
243
306
class TypedOperand extends NonPhiMemoryOperand {
@@ -254,8 +317,6 @@ class TypedOperand extends NonPhiMemoryOperand {
254
317
*/
255
318
class AddressOperand extends RegisterOperand {
256
319
override AddressOperandTag tag ;
257
-
258
- override string toString ( ) { result = "Address" }
259
320
}
260
321
261
322
/**
@@ -264,8 +325,6 @@ class AddressOperand extends RegisterOperand {
264
325
*/
265
326
class BufferSizeOperand extends RegisterOperand {
266
327
override BufferSizeOperandTag tag ;
267
-
268
- override string toString ( ) { result = "BufferSize" }
269
328
}
270
329
271
330
/**
@@ -274,62 +333,48 @@ class BufferSizeOperand extends RegisterOperand {
274
333
*/
275
334
class LoadOperand extends TypedOperand {
276
335
override LoadOperandTag tag ;
277
-
278
- override string toString ( ) { result = "Load" }
279
336
}
280
337
281
338
/**
282
339
* The source value operand of a `Store` instruction.
283
340
*/
284
341
class StoreValueOperand extends RegisterOperand {
285
342
override StoreValueOperandTag tag ;
286
-
287
- override string toString ( ) { result = "StoreValue" }
288
343
}
289
344
290
345
/**
291
346
* The sole operand of a unary instruction (e.g. `Convert`, `Negate`, `Copy`).
292
347
*/
293
348
class UnaryOperand extends RegisterOperand {
294
349
override UnaryOperandTag tag ;
295
-
296
- override string toString ( ) { result = "Unary" }
297
350
}
298
351
299
352
/**
300
353
* The left operand of a binary instruction (e.g. `Add`, `CompareEQ`).
301
354
*/
302
355
class LeftOperand extends RegisterOperand {
303
356
override LeftOperandTag tag ;
304
-
305
- override string toString ( ) { result = "Left" }
306
357
}
307
358
308
359
/**
309
360
* The right operand of a binary instruction (e.g. `Add`, `CompareEQ`).
310
361
*/
311
362
class RightOperand extends RegisterOperand {
312
363
override RightOperandTag tag ;
313
-
314
- override string toString ( ) { result = "Right" }
315
364
}
316
365
317
366
/**
318
367
* The condition operand of a `ConditionalBranch` or `Switch` instruction.
319
368
*/
320
369
class ConditionOperand extends RegisterOperand {
321
370
override ConditionOperandTag tag ;
322
-
323
- override string toString ( ) { result = "Condition" }
324
371
}
325
372
326
373
/**
327
374
* The operand representing the target function of an `Call` instruction.
328
375
*/
329
376
class CallTargetOperand extends RegisterOperand {
330
377
override CallTargetOperandTag tag ;
331
-
332
- override string toString ( ) { result = "CallTarget" }
333
378
}
334
379
335
380
/**
@@ -347,43 +392,34 @@ class ArgumentOperand extends RegisterOperand {
347
392
*/
348
393
class ThisArgumentOperand extends ArgumentOperand {
349
394
override ThisArgumentOperandTag tag ;
350
-
351
- override string toString ( ) { result = "ThisArgument" }
352
395
}
353
396
354
397
/**
355
398
* An operand representing an argument to a function call.
356
399
*/
357
400
class PositionalArgumentOperand extends ArgumentOperand {
358
401
override PositionalArgumentOperandTag tag ;
359
- int argIndex ;
360
-
361
- PositionalArgumentOperand ( ) { argIndex = tag .getArgIndex ( ) }
362
-
363
- override string toString ( ) { result = "Arg(" + argIndex + ")" }
364
402
365
403
/**
366
404
* Gets the zero-based index of the argument.
367
405
*/
368
- final int getIndex ( ) { result = argIndex }
406
+ final int getIndex ( ) { result = tag . getArgIndex ( ) }
369
407
}
370
408
371
409
class SideEffectOperand extends TypedOperand {
372
410
override SideEffectOperandTag tag ;
373
-
374
- override string toString ( ) { result = "SideEffect" }
375
411
}
376
412
377
413
/**
378
414
* An operand of a `PhiInstruction`.
379
415
*/
380
- class PhiInputOperand extends MemoryOperand , TPhiOperand {
416
+ class PhiInputOperand extends MemoryOperand , PhiOperandBase {
381
417
PhiInstruction useInstr ;
382
418
Instruction defInstr ;
383
419
IRBlock predecessorBlock ;
384
420
Overlap overlap ;
385
421
386
- PhiInputOperand ( ) { this = TPhiOperand ( useInstr , defInstr , predecessorBlock , overlap ) }
422
+ PhiInputOperand ( ) { this = phiOperand ( useInstr , defInstr , predecessorBlock , overlap ) }
387
423
388
424
override string toString ( ) { result = "Phi" }
389
425
@@ -413,8 +449,6 @@ class PhiInputOperand extends MemoryOperand, TPhiOperand {
413
449
class ChiTotalOperand extends NonPhiMemoryOperand {
414
450
override ChiTotalOperandTag tag ;
415
451
416
- override string toString ( ) { result = "ChiTotal" }
417
-
418
452
final override MemoryAccessKind getMemoryAccess ( ) { result instanceof ChiTotalMemoryAccess }
419
453
}
420
454
@@ -424,7 +458,5 @@ class ChiTotalOperand extends NonPhiMemoryOperand {
424
458
class ChiPartialOperand extends NonPhiMemoryOperand {
425
459
override ChiPartialOperandTag tag ;
426
460
427
- override string toString ( ) { result = "ChiPartial" }
428
-
429
461
final override MemoryAccessKind getMemoryAccess ( ) { result instanceof ChiPartialMemoryAccess }
430
462
}
0 commit comments