@@ -16,38 +16,45 @@ private predicate isIndirectOrBufferMemoryAccess(MemoryAccessKind kind) {
16
16
kind instanceof BufferMemoryAccess
17
17
}
18
18
19
+ private predicate hasMemoryAccess (
20
+ AddressOperand addrOperand , Allocation var , IntValue startBitOffset , boolean grouped
21
+ ) {
22
+ addressOperandAllocationAndOffset ( addrOperand , var , startBitOffset ) and
23
+ if strictcount ( Allocation alloc | addressOperandAllocationAndOffset ( addrOperand , alloc , _) ) > 1
24
+ then grouped = true
25
+ else grouped = false
26
+ }
27
+
19
28
private predicate hasResultMemoryAccess (
20
- Instruction instr , Allocation var , IRType type , Language:: LanguageType languageType ,
21
- IntValue startBitOffset , IntValue endBitOffset , boolean isMayAccess
29
+ AddressOperand address , Instruction instr , Allocation var , IRType type ,
30
+ Language:: LanguageType languageType , IntValue startBitOffset , IntValue endBitOffset ,
31
+ boolean isMayAccess , boolean grouped
22
32
) {
23
- exists ( AddressOperand addrOperand |
24
- addrOperand = instr .getResultAddressOperand ( ) and
25
- addressOperandAllocationAndOffset ( addrOperand , var , startBitOffset ) and
26
- languageType = instr .getResultLanguageType ( ) and
27
- type = languageType .getIRType ( ) and
28
- isIndirectOrBufferMemoryAccess ( instr .getResultMemoryAccess ( ) ) and
29
- ( if instr .hasResultMayMemoryAccess ( ) then isMayAccess = true else isMayAccess = false ) and
30
- if exists ( type .getByteSize ( ) )
31
- then endBitOffset = Ints:: add ( startBitOffset , Ints:: mul ( type .getByteSize ( ) , 8 ) )
32
- else endBitOffset = Ints:: unknown ( )
33
- )
33
+ address = instr .getResultAddressOperand ( ) and
34
+ hasMemoryAccess ( address , var , startBitOffset , grouped ) and
35
+ languageType = instr .getResultLanguageType ( ) and
36
+ type = languageType .getIRType ( ) and
37
+ isIndirectOrBufferMemoryAccess ( instr .getResultMemoryAccess ( ) ) and
38
+ ( if instr .hasResultMayMemoryAccess ( ) then isMayAccess = true else isMayAccess = false ) and
39
+ if exists ( type .getByteSize ( ) )
40
+ then endBitOffset = Ints:: add ( startBitOffset , Ints:: mul ( type .getByteSize ( ) , 8 ) )
41
+ else endBitOffset = Ints:: unknown ( )
34
42
}
35
43
36
44
private predicate hasOperandMemoryAccess (
37
- MemoryOperand operand , Allocation var , IRType type , Language:: LanguageType languageType ,
38
- IntValue startBitOffset , IntValue endBitOffset , boolean isMayAccess
45
+ AddressOperand address , MemoryOperand operand , Allocation var , IRType type ,
46
+ Language:: LanguageType languageType , IntValue startBitOffset , IntValue endBitOffset ,
47
+ boolean isMayAccess , boolean grouped
39
48
) {
40
- exists ( AddressOperand addrOperand |
41
- addrOperand = operand .getAddressOperand ( ) and
42
- addressOperandAllocationAndOffset ( addrOperand , var , startBitOffset ) and
43
- languageType = operand .getLanguageType ( ) and
44
- type = languageType .getIRType ( ) and
45
- isIndirectOrBufferMemoryAccess ( operand .getMemoryAccess ( ) ) and
46
- ( if operand .hasMayReadMemoryAccess ( ) then isMayAccess = true else isMayAccess = false ) and
47
- if exists ( type .getByteSize ( ) )
48
- then endBitOffset = Ints:: add ( startBitOffset , Ints:: mul ( type .getByteSize ( ) , 8 ) )
49
- else endBitOffset = Ints:: unknown ( )
50
- )
49
+ address = operand .getAddressOperand ( ) and
50
+ hasMemoryAccess ( address , var , startBitOffset , grouped ) and
51
+ languageType = operand .getLanguageType ( ) and
52
+ type = languageType .getIRType ( ) and
53
+ isIndirectOrBufferMemoryAccess ( operand .getMemoryAccess ( ) ) and
54
+ ( if operand .hasMayReadMemoryAccess ( ) then isMayAccess = true else isMayAccess = false ) and
55
+ if exists ( type .getByteSize ( ) )
56
+ then endBitOffset = Ints:: add ( startBitOffset , Ints:: mul ( type .getByteSize ( ) , 8 ) )
57
+ else endBitOffset = Ints:: unknown ( )
51
58
}
52
59
53
60
private newtype TMemoryLocation =
@@ -56,9 +63,9 @@ private newtype TMemoryLocation =
56
63
IntValue endBitOffset , boolean isMayAccess
57
64
) {
58
65
(
59
- hasResultMemoryAccess ( _, var , type , _, startBitOffset , endBitOffset , isMayAccess )
66
+ hasResultMemoryAccess ( _, _ , var , type , _, startBitOffset , endBitOffset , isMayAccess , false )
60
67
or
61
- hasOperandMemoryAccess ( _, var , type , _, startBitOffset , endBitOffset , isMayAccess )
68
+ hasOperandMemoryAccess ( _, _ , var , type , _, startBitOffset , endBitOffset , isMayAccess , false )
62
69
or
63
70
// For a stack variable, always create a memory location for the entire variable.
64
71
var .isAlwaysAllocatedOnStack ( ) and
@@ -211,13 +218,13 @@ class VariableMemoryLocation extends TVariableMemoryLocation, AllocationMemoryLo
211
218
final override Language:: LanguageType getType ( ) {
212
219
if
213
220
strictcount ( Language:: LanguageType accessType |
214
- hasResultMemoryAccess ( _, var , type , accessType , startBitOffset , endBitOffset , _) or
215
- hasOperandMemoryAccess ( _, var , type , accessType , startBitOffset , endBitOffset , _)
221
+ hasResultMemoryAccess ( _, _ , var , type , accessType , startBitOffset , endBitOffset , _, false ) or
222
+ hasOperandMemoryAccess ( _, _ , var , type , accessType , startBitOffset , endBitOffset , _, false )
216
223
) = 1
217
224
then
218
225
// All of the accesses have the same `LanguageType`, so just use that.
219
- hasResultMemoryAccess ( _, var , type , result , startBitOffset , endBitOffset , _) or
220
- hasOperandMemoryAccess ( _, var , type , result , startBitOffset , endBitOffset , _)
226
+ hasResultMemoryAccess ( _, _ , var , type , result , startBitOffset , endBitOffset , _, false ) or
227
+ hasOperandMemoryAccess ( _, _ , var , type , result , startBitOffset , endBitOffset , _, false )
221
228
else
222
229
// There is no single type for all accesses, so just use the canonical one for this `IRType`.
223
230
result = type .getCanonicalLanguageType ( )
0 commit comments