< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/type/ArithmeticOpTable.java

Print this page




  79     private final ShiftOp<UShr> ushr;
  80 
  81     private final UnaryOp<Abs> abs;
  82     private final UnaryOp<Sqrt> sqrt;
  83 
  84     private final IntegerConvertOp<ZeroExtend> zeroExtend;
  85     private final IntegerConvertOp<SignExtend> signExtend;
  86     private final IntegerConvertOp<Narrow> narrow;
  87 
  88     private final FloatConvertOp[] floatConvert;
  89     private final int hash;
  90 
  91     public static ArithmeticOpTable forStamp(Stamp s) {
  92         if (s instanceof ArithmeticStamp) {
  93             return ((ArithmeticStamp) s).getOps();
  94         } else {
  95             return EMPTY;
  96         }
  97     }
  98 
















  99     public static final ArithmeticOpTable EMPTY = new ArithmeticOpTable(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
 100 
 101     public interface ArithmeticOpWrapper {
 102 
 103         <OP> UnaryOp<OP> wrapUnaryOp(UnaryOp<OP> op);
 104 
 105         <OP> BinaryOp<OP> wrapBinaryOp(BinaryOp<OP> op);
 106 
 107         <OP> ShiftOp<OP> wrapShiftOp(ShiftOp<OP> op);
 108 
 109         <OP> IntegerConvertOp<OP> wrapIntegerConvertOp(IntegerConvertOp<OP> op);
 110 
 111         FloatConvertOp wrapFloatConvertOp(FloatConvertOp op);
 112     }
 113 
 114     private static <T> T wrapIfNonNull(Function<T, T> wrapper, T obj) {
 115         if (obj == null) {
 116             return null;
 117         } else {
 118             return wrapper.apply(obj);


 545             }
 546         }
 547 
 548         public abstract static class Xor extends BinaryOp<Xor> {
 549 
 550             protected Xor(boolean associative, boolean commutative) {
 551                 super("^", associative, commutative);
 552             }
 553         }
 554 
 555         private final boolean associative;
 556         private final boolean commutative;
 557 
 558         protected BinaryOp(String operation, boolean associative, boolean commutative) {
 559             super(operation);
 560             this.associative = associative;
 561             this.commutative = commutative;
 562         }
 563 
 564         /**
 565          * Apply the operation to two {@linkplain Constant Constants}.



 566          */
 567         public abstract Constant foldConstant(Constant a, Constant b);
 568 
 569         /**
 570          * Apply the operation to two {@linkplain Stamp Stamps}.
 571          */
 572         public abstract Stamp foldStamp(Stamp a, Stamp b);
 573 
 574         /**
 575          * Checks whether this operation is associative. An operation is associative when
 576          * {@code (a . b) . c == a . (b . c)} for all a, b, c. Note that you still have to be
 577          * careful with inverses. For example the integer subtraction operation will report
 578          * {@code true} here, since you can still reassociate as long as the correct negations are
 579          * inserted.
 580          */
 581         public final boolean isAssociative() {
 582             return associative;
 583         }
 584 
 585         /**




  79     private final ShiftOp<UShr> ushr;
  80 
  81     private final UnaryOp<Abs> abs;
  82     private final UnaryOp<Sqrt> sqrt;
  83 
  84     private final IntegerConvertOp<ZeroExtend> zeroExtend;
  85     private final IntegerConvertOp<SignExtend> signExtend;
  86     private final IntegerConvertOp<Narrow> narrow;
  87 
  88     private final FloatConvertOp[] floatConvert;
  89     private final int hash;
  90 
  91     public static ArithmeticOpTable forStamp(Stamp s) {
  92         if (s instanceof ArithmeticStamp) {
  93             return ((ArithmeticStamp) s).getOps();
  94         } else {
  95             return EMPTY;
  96         }
  97     }
  98 
  99     public BinaryOp<?>[] getBinaryOps() {
 100         return new BinaryOp<?>[]{add, sub, mul, mulHigh, umulHigh, div, rem, and, or, xor};
 101     }
 102 
 103     public UnaryOp<?>[] getUnaryOps() {
 104         return new UnaryOp<?>[]{neg, not, abs, sqrt};
 105     }
 106 
 107     public ShiftOp<?>[] getShiftOps() {
 108         return new ShiftOp<?>[]{shl, shr, ushr};
 109     }
 110 
 111     public IntegerConvertOp<?>[] getIntegerConvertOps() {
 112         return new IntegerConvertOp<?>[]{zeroExtend, signExtend, narrow};
 113     }
 114 
 115     public static final ArithmeticOpTable EMPTY = new ArithmeticOpTable(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
 116 
 117     public interface ArithmeticOpWrapper {
 118 
 119         <OP> UnaryOp<OP> wrapUnaryOp(UnaryOp<OP> op);
 120 
 121         <OP> BinaryOp<OP> wrapBinaryOp(BinaryOp<OP> op);
 122 
 123         <OP> ShiftOp<OP> wrapShiftOp(ShiftOp<OP> op);
 124 
 125         <OP> IntegerConvertOp<OP> wrapIntegerConvertOp(IntegerConvertOp<OP> op);
 126 
 127         FloatConvertOp wrapFloatConvertOp(FloatConvertOp op);
 128     }
 129 
 130     private static <T> T wrapIfNonNull(Function<T, T> wrapper, T obj) {
 131         if (obj == null) {
 132             return null;
 133         } else {
 134             return wrapper.apply(obj);


 561             }
 562         }
 563 
 564         public abstract static class Xor extends BinaryOp<Xor> {
 565 
 566             protected Xor(boolean associative, boolean commutative) {
 567                 super("^", associative, commutative);
 568             }
 569         }
 570 
 571         private final boolean associative;
 572         private final boolean commutative;
 573 
 574         protected BinaryOp(String operation, boolean associative, boolean commutative) {
 575             super(operation);
 576             this.associative = associative;
 577             this.commutative = commutative;
 578         }
 579 
 580         /**
 581          * Applies this operation to {@code a} and {@code b}.
 582          *
 583          * @return the result of applying this operation or {@code null} if applying it would raise
 584          *         an exception (e.g., {@link ArithmeticException} for dividing by 0)
 585          */
 586         public abstract Constant foldConstant(Constant a, Constant b);
 587 
 588         /**
 589          * Apply the operation to two {@linkplain Stamp Stamps}.
 590          */
 591         public abstract Stamp foldStamp(Stamp a, Stamp b);
 592 
 593         /**
 594          * Checks whether this operation is associative. An operation is associative when
 595          * {@code (a . b) . c == a . (b . c)} for all a, b, c. Note that you still have to be
 596          * careful with inverses. For example the integer subtraction operation will report
 597          * {@code true} here, since you can still reassociate as long as the correct negations are
 598          * inserted.
 599          */
 600         public final boolean isAssociative() {
 601             return associative;
 602         }
 603 
 604         /**


< prev index next >