@@ -119,27 +119,67 @@ module SemanticExprConfig {
119119 result = block .getDisplayIndex ( )
120120 }
121121
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 ( ) }
124125
125- final string toString ( ) { result = super .toString ( ) }
126+ class SsaVariable extends TSsaVariable {
127+ string toString ( ) { none ( ) }
126128
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 }
128158 }
129159
130- predicate explicitUpdate ( SsaVariable v , Expr sourceExpr ) { v = sourceExpr }
160+ predicate explicitUpdate ( SsaVariable v , Expr sourceExpr ) { v . asInstruction ( ) = sourceExpr }
131161
132- predicate phi ( SsaVariable v ) { v instanceof IR:: PhiInstruction }
162+ predicate phi ( SsaVariable v ) { v . asInstruction ( ) instanceof IR:: PhiInstruction }
133163
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+ }
135171
136- Expr getAUse ( SsaVariable v ) { result .( IR:: LoadInstruction ) .getSourceValue ( ) = v }
172+ Expr getAUse ( SsaVariable v ) { result .( IR:: LoadInstruction ) .getSourceValue ( ) = v . asInstruction ( ) }
137173
138174 SemType getSsaVariableType ( SsaVariable v ) {
139- result = getSemanticType ( v .( IR :: Instruction ) .getResultIRType ( ) )
175+ result = getSemanticType ( v .asInstruction ( ) .getResultIRType ( ) )
140176 }
141177
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+ }
143183
144184 private newtype TReadPosition =
145185 TReadPositionBlock ( IR:: IRBlock block ) or
@@ -169,7 +209,9 @@ module SemanticExprConfig {
169209
170210 final override predicate hasRead ( SsaVariable v ) {
171211 exists ( IR:: Operand operand |
172- operand .getDef ( ) = v and not operand instanceof IR:: PhiInputOperand
212+ operand .getDef ( ) = v .asInstruction ( ) and
213+ not operand instanceof IR:: PhiInputOperand and
214+ operand .getUse ( ) .getBlock ( ) = block
173215 )
174216 }
175217 }
@@ -186,7 +228,7 @@ module SemanticExprConfig {
186228
187229 final override predicate hasRead ( SsaVariable v ) {
188230 exists ( IR:: PhiInputOperand operand |
189- operand .getDef ( ) = v and
231+ operand .getDef ( ) = v . asInstruction ( ) and
190232 operand .getPredecessorBlock ( ) = pred and
191233 operand .getUse ( ) .getBlock ( ) = succ
192234 )
@@ -205,17 +247,16 @@ module SemanticExprConfig {
205247 exists ( IR:: PhiInputOperand operand |
206248 pos = TReadPositionPhiInputEdge ( operand .getPredecessorBlock ( ) , operand .getUse ( ) .getBlock ( ) )
207249 |
208- 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+ )
209256 )
210257 }
211258
212259 class Bound instanceof IRBound:: Bound {
213- Bound ( ) {
214- this instanceof IRBound:: ZeroBound
215- or
216- this .( IRBound:: ValueNumberBound ) .getValueNumber ( ) .getAnInstruction ( ) instanceof SsaVariable
217- }
218-
219260 string toString ( ) { result = super .toString ( ) }
220261
221262 final Location getLocation ( ) { result = super .getLocation ( ) }
@@ -228,21 +269,21 @@ module SemanticExprConfig {
228269
229270 override string toString ( ) {
230271 result =
231- min ( SsaVariable instr |
232- instr = bound .getValueNumber ( ) .getAnInstruction ( )
272+ min ( SsaVariable v |
273+ v . asInstruction ( ) = bound .getValueNumber ( ) .getAnInstruction ( )
233274 |
234- instr
275+ v
235276 order by
236- instr . ( IR :: Instruction ) .getBlock ( ) .getDisplayIndex ( ) ,
237- instr . ( IR :: Instruction ) .getDisplayIndexInBlock ( )
277+ v . asInstruction ( ) .getBlock ( ) .getDisplayIndex ( ) ,
278+ v . asInstruction ( ) .getDisplayIndexInBlock ( )
238279 ) .toString ( )
239280 }
240281 }
241282
242283 predicate zeroBound ( Bound bound ) { bound instanceof IRBound:: ZeroBound }
243284
244285 predicate ssaBound ( Bound bound , SsaVariable v ) {
245- v = bound .( IRBound:: ValueNumberBound ) .getValueNumber ( ) .getAnInstruction ( )
286+ v . asInstruction ( ) = bound .( IRBound:: ValueNumberBound ) .getValueNumber ( ) .getAnInstruction ( )
246287 }
247288
248289 Expr getBoundExpr ( Bound bound , int delta ) {
@@ -251,22 +292,20 @@ module SemanticExprConfig {
251292
252293 class Guard = IRGuards:: IRGuardCondition ;
253294
254- predicate guard ( Guard guard , BasicBlock block ) {
255- block = guard .( IRGuards:: IRGuardCondition ) .getBlock ( )
256- }
295+ predicate guard ( Guard guard , BasicBlock block ) { block = guard .getBlock ( ) }
257296
258297 Expr getGuardAsExpr ( Guard guard ) { result = guard }
259298
260299 predicate equalityGuard ( Guard guard , Expr e1 , Expr e2 , boolean polarity ) {
261- guard .( IRGuards :: IRGuardCondition ) . comparesEq ( e1 .getAUse ( ) , e2 .getAUse ( ) , 0 , true , polarity )
300+ guard .comparesEq ( e1 .getAUse ( ) , e2 .getAUse ( ) , 0 , true , polarity )
262301 }
263302
264303 predicate guardDirectlyControlsBlock ( Guard guard , BasicBlock controlled , boolean branch ) {
265- guard .( IRGuards :: IRGuardCondition ) . controls ( controlled , branch )
304+ guard .controls ( controlled , branch )
266305 }
267306
268307 predicate guardHasBranchEdge ( Guard guard , BasicBlock bb1 , BasicBlock bb2 , boolean branch ) {
269- guard .( IRGuards :: IRGuardCondition ) . controlsEdge ( bb1 , bb2 , branch )
308+ guard .controlsEdge ( bb1 , bb2 , branch )
270309 }
271310
272311 Guard comparisonGuard ( Expr e ) { result = e }
@@ -284,9 +323,13 @@ SemBasicBlock getSemanticBasicBlock(IR::IRBlock block) { result = block }
284323
285324IR:: IRBlock getCppBasicBlock ( SemBasicBlock block ) { block = result }
286325
287- SemSsaVariable getSemanticSsaVariable ( IR:: Instruction instr ) { result = instr }
326+ SemSsaVariable getSemanticSsaVariable ( IR:: Instruction instr ) {
327+ result .( SemanticExprConfig:: SsaVariable ) .asInstruction ( ) = instr
328+ }
288329
289- IR:: Instruction getCppSsaVariableInstruction ( SemSsaVariable v ) { v = result }
330+ IR:: Instruction getCppSsaVariableInstruction ( SemSsaVariable var ) {
331+ var .( SemanticExprConfig:: SsaVariable ) .asInstruction ( ) = result
332+ }
290333
291334SemBound getSemanticBound ( IRBound:: Bound bound ) { result = bound }
292335
0 commit comments