eclipse / omr

Eclipse OMR™ Cross platform components for building reliable, high performance language runtimes
http://www.eclipse.org/omr
Other
935 stars 393 forks source link

Extend the arithmetic operations for VPIntConstraint, VPLongConstraint, VPShortConstraint #5439

Open xiacijie opened 3 years ago

xiacijie commented 3 years ago

Hello,

The currently available arithmetic operations for those constraints are only add and subtract. I am thinking is it possible or will it be necessary to extend the operations to include operations such as negation, shift, multiply, division, rem, convertion and other possible operations? @andrewcraik @0xdaryl

Thanks

andrewcraik commented 3 years ago

@xiacijie if there is a need to implement additional operations on the VP constraints then a motivation and contributions will be welcome. Note that the constraints you mentioned are actually abstract types and each has a Const and Range derived type representing a single value and a range of values. If any of these APIs are added to the root class they would need support to be added on the two derived classes since the behavior will be different. Note that supporting some may become quite tricky due to having to consider potential overflow conditions and the various combinations of ranges and consts.

Do you have a particular use case in mind that requires all of these operations?

xiacijie commented 3 years ago

@andrewcraik The current use case of VPConstraint is doing abstract interpretation for java bytecode. Abstract interpretation produces abstract values. So TR::VPConstraintis used as constraints for those abstract values. For example, when encountering an iconst1, we create an abstract value with constraint VPIntConst(1). For other byte code such as ineg, a negation of the constraint is required. imul ,idiv requires performing multiplication and divisions on the constraints.

andrewcraik commented 3 years ago

For a VPConst constraint you can do the operation on the constant and then create a new VPConst even without implementing it on the constraint. Doing it on a range can be more tricky - we could if it was sufficiently useful.