src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/calc/Condition.java
changeset 48861 47f19ff9903c
parent 47216 71c04702a3d5
child 50858 2d3e99a72541
equal deleted inserted replaced
48860:5bce1b7e7800 48861:47f19ff9903c
   113                 return UnsignedMath.belowThan(left, right);
   113                 return UnsignedMath.belowThan(left, right);
   114         }
   114         }
   115         throw new IllegalArgumentException(this.toString());
   115         throw new IllegalArgumentException(this.toString());
   116     }
   116     }
   117 
   117 
       
   118     public static final class CanonicalizedCondition {
       
   119         private final CanonicalCondition canonicalCondition;
       
   120         private final boolean mirror;
       
   121         private final boolean negate;
       
   122 
       
   123         private CanonicalizedCondition(CanonicalCondition canonicalCondition, boolean mirror, boolean negate) {
       
   124             this.canonicalCondition = canonicalCondition;
       
   125             this.mirror = mirror;
       
   126             this.negate = negate;
       
   127         }
       
   128 
       
   129         public CanonicalCondition getCanonicalCondition() {
       
   130             return canonicalCondition;
       
   131         }
       
   132 
       
   133         public boolean mustMirror() {
       
   134             return mirror;
       
   135         }
       
   136 
       
   137         public boolean mustNegate() {
       
   138             return negate;
       
   139         }
       
   140     }
       
   141 
       
   142     public CanonicalizedCondition canonicalize() {
       
   143         CanonicalCondition canonicalCondition;
       
   144         switch (this) {
       
   145             case EQ:
       
   146             case NE:
       
   147                 canonicalCondition = CanonicalCondition.EQ;
       
   148                 break;
       
   149             case LT:
       
   150             case LE:
       
   151             case GT:
       
   152             case GE:
       
   153                 canonicalCondition = CanonicalCondition.LT;
       
   154                 break;
       
   155             case BT:
       
   156             case BE:
       
   157             case AT:
       
   158             case AE:
       
   159                 canonicalCondition = CanonicalCondition.BT;
       
   160                 break;
       
   161             default:
       
   162                 throw new IllegalArgumentException(this.toString());
       
   163         }
       
   164         return new CanonicalizedCondition(canonicalCondition, canonicalMirror(), canonicalNegate());
       
   165     }
       
   166 
   118     /**
   167     /**
   119      * Given a condition and its negation, this method returns true for one of the two and false for
   168      * Given a condition and its negation, this method returns true for one of the two and false for
   120      * the other one. This can be used to keep comparisons in a canonical form.
   169      * the other one. This can be used to keep comparisons in a canonical form.
   121      *
   170      *
   122      * @return true if this condition is considered to be the canonical form, false otherwise.
   171      * @return true if this condition is considered to be the canonical form, false otherwise.
   149 
   198 
   150     /**
   199     /**
   151      * Returns true if the condition needs to be mirrored to get to a canonical condition. The
   200      * Returns true if the condition needs to be mirrored to get to a canonical condition. The
   152      * result of the mirroring operation might still need to be negated to achieve a canonical form.
   201      * result of the mirroring operation might still need to be negated to achieve a canonical form.
   153      */
   202      */
   154     public boolean canonicalMirror() {
   203     private boolean canonicalMirror() {
   155         switch (this) {
   204         switch (this) {
   156             case EQ:
   205             case EQ:
   157                 return false;
   206                 return false;
   158             case NE:
   207             case NE:
   159                 return false;
   208                 return false;
   179 
   228 
   180     /**
   229     /**
   181      * Returns true if the condition needs to be negated to get to a canonical condition. The result
   230      * Returns true if the condition needs to be negated to get to a canonical condition. The result
   182      * of the negation might still need to be mirrored to achieve a canonical form.
   231      * of the negation might still need to be mirrored to achieve a canonical form.
   183      */
   232      */
   184     public boolean canonicalNegate() {
   233     private boolean canonicalNegate() {
   185         switch (this) {
   234         switch (this) {
   186             case EQ:
   235             case EQ:
   187                 return false;
   236                 return false;
   188             case NE:
   237             case NE:
   189                 return true;
   238                 return true;