@@ -19,29 +19,29 @@ newtype TValueNumber =
1919 fieldAddressValueNumber ( _, irFunc , field , objectAddress )
2020 } or
2121 TBinaryValueNumber (
22- IRFunction irFunc , Opcode opcode , IRType type , TValueNumber leftOperand ,
22+ IRFunction irFunc , Opcode opcode , TValueNumber leftOperand ,
2323 TValueNumber rightOperand
2424 ) {
25- binaryValueNumber ( _, irFunc , opcode , type , leftOperand , rightOperand )
25+ binaryValueNumber ( _, irFunc , opcode , leftOperand , rightOperand )
2626 } or
2727 TPointerArithmeticValueNumber (
28- IRFunction irFunc , Opcode opcode , IRType type , int elementSize , TValueNumber leftOperand ,
28+ IRFunction irFunc , Opcode opcode , int elementSize , TValueNumber leftOperand ,
2929 TValueNumber rightOperand
3030 ) {
31- pointerArithmeticValueNumber ( _, irFunc , opcode , type , elementSize , leftOperand , rightOperand )
31+ pointerArithmeticValueNumber ( _, irFunc , opcode , elementSize , leftOperand , rightOperand )
3232 } or
33- TUnaryValueNumber ( IRFunction irFunc , Opcode opcode , IRType type , TValueNumber operand ) {
34- unaryValueNumber ( _, irFunc , opcode , type , operand )
33+ TUnaryValueNumber ( IRFunction irFunc , Opcode opcode , TValueNumber operand ) {
34+ unaryValueNumber ( _, irFunc , opcode , operand )
3535 } or
3636 TInheritanceConversionValueNumber (
3737 IRFunction irFunc , Opcode opcode , Class baseClass , Class derivedClass , TValueNumber operand
3838 ) {
3939 inheritanceConversionValueNumber ( _, irFunc , opcode , baseClass , derivedClass , operand )
4040 } or
4141 TLoadTotalOverlapValueNumber (
42- IRFunction irFunc , IRType type , TValueNumber memOperand , TValueNumber operand
42+ IRFunction irFunc , TValueNumber memOperand , TValueNumber operand
4343 ) {
44- loadTotalOverlapValueNumber ( _, irFunc , type , memOperand , operand )
44+ loadTotalOverlapValueNumber ( _, irFunc , memOperand , operand )
4545 } or
4646 TUniqueValueNumber ( IRFunction irFunc , Instruction instr ) { uniqueValueNumber ( instr , irFunc ) }
4747
@@ -99,14 +99,30 @@ private predicate numberableInstruction(Instruction instr) {
9999 instr instanceof LoadTotalOverlapInstruction
100100}
101101
102+ predicate multipleValueNumbers ( Instruction instr , int n ) {
103+ n > 1 and
104+ (
105+ n = strictcount ( IRFunction irFunc , Language:: AST ast | variableAddressValueNumber ( instr , irFunc , ast ) )
106+ or
107+ n = strictcount ( IRFunction irFunc , Language:: AST var | initializeParameterValueNumber ( instr , irFunc , var ) )
108+ or
109+ n = strictcount ( IRFunction irFunc | initializeThisValueNumber ( instr , irFunc ) )
110+ or
111+ n = strictcount ( IRFunction irFunc , IRType type , string value | constantValueNumber ( instr , irFunc , type , value ) )
112+ or
113+ n = strictcount ( IRFunction irFunc , IRType type , string value | stringConstantValueNumber ( instr , irFunc , type , value ) )
114+ )
115+ }
116+
102117private predicate variableAddressValueNumber (
103118 VariableAddressInstruction instr , IRFunction irFunc , Language:: AST ast
104119) {
105120 instr .getEnclosingIRFunction ( ) = irFunc and
106121 // The underlying AST element is used as value-numbering key instead of the
107122 // `IRVariable` to work around a problem where a variable or expression with
108123 // multiple types gives rise to multiple `IRVariable`s.
109- instr .getIRVariable ( ) .getAST ( ) = ast
124+ instr .getIRVariable ( ) .getAST ( ) = ast and
125+ strictcount ( instr .getIRVariable ( ) .getAST ( ) ) = 1
110126}
111127
112128private predicate initializeParameterValueNumber (
@@ -149,38 +165,35 @@ private predicate fieldAddressValueNumber(
149165}
150166
151167private predicate binaryValueNumber (
152- BinaryInstruction instr , IRFunction irFunc , Opcode opcode , IRType type , TValueNumber leftOperand ,
168+ BinaryInstruction instr , IRFunction irFunc , Opcode opcode , TValueNumber leftOperand ,
153169 TValueNumber rightOperand
154170) {
155171 instr .getEnclosingIRFunction ( ) = irFunc and
156172 not instr instanceof PointerArithmeticInstruction and
157173 instr .getOpcode ( ) = opcode and
158- instr .getResultIRType ( ) = type and
159174 tvalueNumber ( instr .getLeft ( ) ) = leftOperand and
160175 tvalueNumber ( instr .getRight ( ) ) = rightOperand
161176}
162177
163178private predicate pointerArithmeticValueNumber (
164- PointerArithmeticInstruction instr , IRFunction irFunc , Opcode opcode , IRType type ,
179+ PointerArithmeticInstruction instr , IRFunction irFunc , Opcode opcode ,
165180 int elementSize , TValueNumber leftOperand , TValueNumber rightOperand
166181) {
167182 instr .getEnclosingIRFunction ( ) = irFunc and
168183 instr .getOpcode ( ) = opcode and
169- instr .getResultIRType ( ) = type and
170184 instr .getElementSize ( ) = elementSize and
171185 tvalueNumber ( instr .getLeft ( ) ) = leftOperand and
172186 tvalueNumber ( instr .getRight ( ) ) = rightOperand
173187}
174188
175189private predicate unaryValueNumber (
176- UnaryInstruction instr , IRFunction irFunc , Opcode opcode , IRType type , TValueNumber operand
190+ UnaryInstruction instr , IRFunction irFunc , Opcode opcode , TValueNumber operand
177191) {
178192 instr .getEnclosingIRFunction ( ) = irFunc and
179193 not instr instanceof InheritanceConversionInstruction and
180194 not instr instanceof CopyInstruction and
181195 not instr instanceof FieldAddressInstruction and
182196 instr .getOpcode ( ) = opcode and
183- instr .getResultIRType ( ) = type and
184197 tvalueNumber ( instr .getUnary ( ) ) = operand
185198}
186199
@@ -196,11 +209,10 @@ private predicate inheritanceConversionValueNumber(
196209}
197210
198211private predicate loadTotalOverlapValueNumber (
199- LoadTotalOverlapInstruction instr , IRFunction irFunc , IRType type , TValueNumber memOperand ,
212+ LoadTotalOverlapInstruction instr , IRFunction irFunc , TValueNumber memOperand ,
200213 TValueNumber operand
201214) {
202215 instr .getEnclosingIRFunction ( ) = irFunc and
203- instr .getResultIRType ( ) = type and
204216 tvalueNumber ( instr .getAnOperand ( ) .( MemoryOperand ) .getAnyDef ( ) ) = memOperand and
205217 tvalueNumberOfOperand ( instr .getAnOperand ( ) .( AddressOperand ) ) = operand
206218}
@@ -270,14 +282,14 @@ private TValueNumber nonUniqueValueNumber(Instruction instr) {
270282 result = TFieldAddressValueNumber ( irFunc , field , objectAddress )
271283 )
272284 or
273- exists ( Opcode opcode , IRType type , TValueNumber leftOperand , TValueNumber rightOperand |
274- binaryValueNumber ( instr , irFunc , opcode , type , leftOperand , rightOperand ) and
275- result = TBinaryValueNumber ( irFunc , opcode , type , leftOperand , rightOperand )
285+ exists ( Opcode opcode , TValueNumber leftOperand , TValueNumber rightOperand |
286+ binaryValueNumber ( instr , irFunc , opcode , leftOperand , rightOperand ) and
287+ result = TBinaryValueNumber ( irFunc , opcode , leftOperand , rightOperand )
276288 )
277289 or
278- exists ( Opcode opcode , IRType type , TValueNumber operand |
279- unaryValueNumber ( instr , irFunc , opcode , type , operand ) and
280- result = TUnaryValueNumber ( irFunc , opcode , type , operand )
290+ exists ( Opcode opcode , TValueNumber operand |
291+ unaryValueNumber ( instr , irFunc , opcode , operand ) and
292+ result = TUnaryValueNumber ( irFunc , opcode , operand )
281293 )
282294 or
283295 exists (
@@ -288,18 +300,18 @@ private TValueNumber nonUniqueValueNumber(Instruction instr) {
288300 )
289301 or
290302 exists (
291- Opcode opcode , IRType type , int elementSize , TValueNumber leftOperand ,
303+ Opcode opcode , int elementSize , TValueNumber leftOperand ,
292304 TValueNumber rightOperand
293305 |
294- pointerArithmeticValueNumber ( instr , irFunc , opcode , type , elementSize , leftOperand ,
306+ pointerArithmeticValueNumber ( instr , irFunc , opcode , elementSize , leftOperand ,
295307 rightOperand ) and
296308 result =
297- TPointerArithmeticValueNumber ( irFunc , opcode , type , elementSize , leftOperand , rightOperand )
309+ TPointerArithmeticValueNumber ( irFunc , opcode , elementSize , leftOperand , rightOperand )
298310 )
299311 or
300- exists ( IRType type , TValueNumber memOperand , TValueNumber operand |
301- loadTotalOverlapValueNumber ( instr , irFunc , type , memOperand , operand ) and
302- result = TLoadTotalOverlapValueNumber ( irFunc , type , memOperand , operand )
312+ exists ( TValueNumber memOperand , TValueNumber operand |
313+ loadTotalOverlapValueNumber ( instr , irFunc , memOperand , operand ) and
314+ result = TLoadTotalOverlapValueNumber ( irFunc , memOperand , operand )
303315 )
304316 or
305317 // The value number of a copy is just the value number of its source value.
0 commit comments