Skip to content

Commit a26ac68

Browse files
committed
Add a way to get all SSA versions for a variable node
1 parent abf39f4 commit a26ac68

2 files changed

Lines changed: 165 additions & 0 deletions

File tree

‎src/FAST-Python-Tools-Tests/FASTPythonVariablesAnalysisTest.class.st‎

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,151 @@ print(x)'.
6969
self assertCollection: model module statements fifth arguments first allReadAccesses hasSameElements: result
7070
]
7171

72+
{ #category : 'tests' }
73+
FASTPythonVariablesAnalysisTest >> testAllSSABasicVersionsExcludesPhiVersions [
74+
| versions |
75+
self parseAndResolve: 'if z > 3:
76+
x = 2
77+
else:
78+
x = 3
79+
80+
print(x)'.
81+
82+
versions := model module statements first thenClause statements first left allSSABasicVersions.
83+
84+
self assert: versions size equals: 2.
85+
self assert: (versions noneSatisfy: [ :each | each isPhi ]).
86+
self assertCollection: (versions collect: [ :each | each version ]) asArray hasSameElements: { 1. 2 }
87+
]
88+
89+
{ #category : 'tests' }
90+
FASTPythonVariablesAnalysisTest >> testAllSSABasicVersionsFromAnyAccess [
91+
| writeAccess readAccess |
92+
self parseAndResolve: 'if z > 3:
93+
x = 2
94+
else:
95+
x = 3
96+
97+
print(x)'.
98+
99+
writeAccess := model module statements first thenClause statements first left.
100+
readAccess := model module statements last arguments first.
101+
102+
self assert: writeAccess allSSABasicVersions size equals: 2.
103+
self assert: readAccess allSSABasicVersions size equals: 2
104+
]
105+
106+
{ #category : 'tests' }
107+
FASTPythonVariablesAnalysisTest >> testAllSSABasicVersionsOnReassignedVariable [
108+
| versions |
109+
self parseAndResolve: 'x = 1
110+
111+
print(x)
112+
113+
x = 2
114+
115+
print(x)'.
116+
117+
versions := model module statements first left allSSABasicVersions.
118+
119+
self assert: versions size equals: 2.
120+
self assertCollection: (versions collect: [ :each | each version ]) asArray hasSameElements: { 1. 2 }
121+
]
122+
123+
{ #category : 'tests' }
124+
FASTPythonVariablesAnalysisTest >> testAllSSABasicVersionsOnVariableWithOneVersion [
125+
| versions |
126+
self parseAndResolve: 'x = 1
127+
128+
print(x)'.
129+
130+
versions := model module statements first left allSSABasicVersions.
131+
132+
self assert: versions size equals: 1.
133+
self assert: versions anyOne version equals: 1
134+
]
135+
136+
{ #category : 'tests' }
137+
FASTPythonVariablesAnalysisTest >> testAllSSAVersionsFromAnyAccess [
138+
| writeAccess readAccess |
139+
self parseAndResolve: 'x = 1
140+
141+
print(x)
142+
143+
x = 2
144+
145+
print(x)'.
146+
147+
writeAccess := model module statements first left.
148+
readAccess := model module statements last arguments first.
149+
150+
self assert: writeAccess allSSAVersions size equals: 2.
151+
self assert: readAccess allSSAVersions size equals: 2
152+
]
153+
154+
{ #category : 'tests' }
155+
FASTPythonVariablesAnalysisTest >> testAllSSAVersionsIncludesPhiVersion [
156+
| versions |
157+
self parseAndResolve: 'if z > 3:
158+
x = 2
159+
else:
160+
x = 3
161+
162+
print(x)'.
163+
164+
versions := model module statements first thenClause statements first left allSSAVersions.
165+
166+
self assert: versions size equals: 3.
167+
self assert: (versions count: [ :each | each isPhi ]) equals: 1
168+
]
169+
170+
{ #category : 'tests' }
171+
FASTPythonVariablesAnalysisTest >> testAllSSAVersionsOnReassignedVariable [
172+
| versions |
173+
self parseAndResolve: 'x = 1
174+
175+
print(x)
176+
177+
x = 2
178+
179+
print(x)'.
180+
181+
versions := model module statements first left allSSAVersions.
182+
183+
self assert: versions size equals: 2.
184+
self assertCollection: (versions collect: [ :each | each version ]) asArray hasSameElements: { 1. 2 }
185+
]
186+
187+
{ #category : 'tests' }
188+
FASTPythonVariablesAnalysisTest >> testAllSSAVersionsOnVariableWithOneVersion [
189+
| versions |
190+
self parseAndResolve: 'x = 1
191+
192+
print(x)'.
193+
194+
versions := model module statements first left allSSAVersions.
195+
196+
self assert: versions size equals: 1.
197+
self assert: versions anyOne version equals: 1
198+
]
199+
200+
{ #category : 'tests' }
201+
FASTPythonVariablesAnalysisTest >> testAllSSAVersionsOnlyForTheReceiverVariable [
202+
| versions |
203+
self parseAndResolve: 'x = 1
204+
205+
y = 2
206+
207+
x = 3
208+
209+
print(x)'.
210+
211+
versions := model module statements first left allSSAVersions.
212+
213+
self assert: versions size equals: 2.
214+
self assertCollection: (versions collect: [ :each | each version ]) asArray hasSameElements: { 1. 2 }
215+
]
216+
72217
{ #category : 'tests' }
73218
FASTPythonVariablesAnalysisTest >> testAllWriteAccessesOfIdentifier [
74219

‎src/FAST-Python-Tools/FASTPyEntity.extension.st‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ FASTPyEntity >> allNodesUsingMyVersion [
4040
as: Set
4141
]
4242

43+
{ #category : '*FAST-Python-Tools' }
44+
FASTPyEntity >> allSSABasicVersions [
45+
"If the receiver is a variable, return all the SSA versions of the variable without the Phi versions.
46+
47+
Requires SSA resolution."
48+
49+
^ (self localDeclaration allAccesses
50+
collect: #ssaVersion
51+
thenReject: #isPhi) asSet
52+
]
53+
54+
{ #category : '*FAST-Python-Tools' }
55+
FASTPyEntity >> allSSAVersions [
56+
"If the receiver is a variable, return all the SSA versions of the variable including the Phi versions.
57+
58+
Requires SSA resolution."
59+
60+
^ self localDeclaration allAccesses collectAsSet: #ssaVersion
61+
]
62+
4363
{ #category : '*FAST-Python-Tools' }
4464
FASTPyEntity >> callsOnVariable [
4565
"If I am a variable, return all the call nodes having my read accesses as receiver. This will group invocations and instantiations.

0 commit comments

Comments
 (0)