< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/gen/ArithmeticLIRGenerator.java

Print this page




  33 /**
  34  * This class traverses the HIR instructions and generates LIR instructions from them.
  35  */
  36 public abstract class ArithmeticLIRGenerator implements ArithmeticLIRGeneratorTool {
  37 
  38     LIRGenerator lirGen;
  39 
  40     public LIRGenerator getLIRGen() {
  41         return lirGen;
  42     }
  43 
  44     public OptionValues getOptions() {
  45         return getLIRGen().getResult().getLIR().getOptions();
  46     }
  47     // automatic derived reference handling
  48 
  49     protected abstract boolean isNumericInteger(PlatformKind kind);
  50 
  51     protected abstract Variable emitAdd(LIRKind resultKind, Value a, Value b, boolean setFlags);
  52 


  53     @Override
  54     public final Variable emitAdd(Value aVal, Value bVal, boolean setFlags) {









  55         LIRKind resultKind;
  56         Value a = aVal;
  57         Value b = bVal;
  58 
  59         if (isNumericInteger(a.getPlatformKind())) {
  60             LIRKind aKind = a.getValueKind(LIRKind.class);
  61             LIRKind bKind = b.getValueKind(LIRKind.class);
  62             assert a.getPlatformKind() == b.getPlatformKind() : a.getPlatformKind() + " vs. " + b.getPlatformKind();
  63 
  64             if (aKind.isUnknownReference()) {
  65                 resultKind = aKind;
  66             } else if (bKind.isUnknownReference()) {
  67                 resultKind = bKind;
  68             } else if (aKind.isValue() && bKind.isValue()) {
  69                 resultKind = aKind;
  70             } else if (aKind.isValue()) {
  71                 if (bKind.isDerivedReference()) {
  72                     resultKind = bKind;
  73                 } else {
  74                     AllocatableValue allocatable = getLIRGen().asAllocatable(b);
  75                     resultKind = bKind.makeDerivedReference(allocatable);
  76                     b = allocatable;
  77                 }
  78             } else if (bKind.isValue()) {
  79                 if (aKind.isDerivedReference()) {
  80                     resultKind = aKind;
  81                 } else {
  82                     AllocatableValue allocatable = getLIRGen().asAllocatable(a);
  83                     resultKind = aKind.makeDerivedReference(allocatable);
  84                     a = allocatable;
  85                 }
  86             } else {
  87                 resultKind = aKind.makeUnknownReference();
  88             }
  89         } else {
  90             resultKind = LIRKind.combine(a, b);
  91         }
  92 
  93         return emitAdd(resultKind, a, b, setFlags);
  94     }
  95 
  96     protected abstract Variable emitSub(LIRKind resultKind, Value a, Value b, boolean setFlags);
  97 
  98     @Override
  99     public final Variable emitSub(Value aVal, Value bVal, boolean setFlags) {
 100         LIRKind resultKind;
 101         Value a = aVal;
 102         Value b = bVal;
 103 
 104         if (isNumericInteger(a.getPlatformKind())) {
 105             LIRKind aKind = a.getValueKind(LIRKind.class);
 106             LIRKind bKind = b.getValueKind(LIRKind.class);
 107             assert a.getPlatformKind() == b.getPlatformKind();
 108 
 109             if (aKind.isUnknownReference()) {
 110                 resultKind = aKind;
 111             } else if (bKind.isUnknownReference()) {
 112                 resultKind = bKind;
 113             }
 114 
 115             if (aKind.isValue() && bKind.isValue()) {
 116                 resultKind = aKind;
 117             } else if (bKind.isValue()) {
 118                 if (aKind.isDerivedReference()) {
 119                     resultKind = aKind;
 120                 } else {
 121                     AllocatableValue allocatable = getLIRGen().asAllocatable(a);
 122                     resultKind = aKind.makeDerivedReference(allocatable);
 123                     a = allocatable;
 124                 }
 125             } else if (aKind.isDerivedReference() && bKind.isDerivedReference() && aKind.getDerivedReferenceBase().equals(bKind.getDerivedReferenceBase())) {
 126                 resultKind = LIRKind.value(a.getPlatformKind());
 127             } else {
 128                 resultKind = aKind.makeUnknownReference();
 129             }
 130         } else {
 131             resultKind = LIRKind.combine(a, b);
 132         }
 133 
 134         return emitSub(resultKind, a, b, setFlags);
 135     }
 136 }


  33 /**
  34  * This class traverses the HIR instructions and generates LIR instructions from them.
  35  */
  36 public abstract class ArithmeticLIRGenerator implements ArithmeticLIRGeneratorTool {
  37 
  38     LIRGenerator lirGen;
  39 
  40     public LIRGenerator getLIRGen() {
  41         return lirGen;
  42     }
  43 
  44     public OptionValues getOptions() {
  45         return getLIRGen().getResult().getLIR().getOptions();
  46     }
  47     // automatic derived reference handling
  48 
  49     protected abstract boolean isNumericInteger(PlatformKind kind);
  50 
  51     protected abstract Variable emitAdd(LIRKind resultKind, Value a, Value b, boolean setFlags);
  52 
  53     protected abstract Variable emitSub(LIRKind resultKind, Value a, Value b, boolean setFlags);
  54 
  55     @Override
  56     public final Variable emitAdd(Value aVal, Value bVal, boolean setFlags) {
  57         return emitAddOrSub(aVal, bVal, setFlags, true);
  58     }
  59 
  60     @Override
  61     public final Variable emitSub(Value aVal, Value bVal, boolean setFlags) {
  62         return emitAddOrSub(aVal, bVal, setFlags, false);
  63     }
  64 
  65     private Variable emitAddOrSub(Value aVal, Value bVal, boolean setFlags, boolean isAdd) {
  66         LIRKind resultKind;
  67         Value a = aVal;
  68         Value b = bVal;
  69 
  70         if (isNumericInteger(a.getPlatformKind())) {
  71             LIRKind aKind = a.getValueKind(LIRKind.class);
  72             LIRKind bKind = b.getValueKind(LIRKind.class);
  73             assert a.getPlatformKind() == b.getPlatformKind() : a.getPlatformKind() + " vs. " + b.getPlatformKind();
  74 
  75             if (aKind.isUnknownReference()) {
  76                 resultKind = aKind;
  77             } else if (bKind.isUnknownReference()) {
  78                 resultKind = bKind;
  79             } else if (aKind.isValue() && bKind.isValue()) {
  80                 resultKind = aKind;
  81             } else if (aKind.isValue()) {
  82                 if (bKind.isDerivedReference()) {
  83                     resultKind = bKind;
  84                 } else {
  85                     AllocatableValue allocatable = getLIRGen().asAllocatable(b);
  86                     resultKind = bKind.makeDerivedReference(allocatable);
  87                     b = allocatable;
  88                 }
  89             } else if (bKind.isValue()) {
  90                 if (aKind.isDerivedReference()) {
  91                     resultKind = aKind;
  92                 } else {
  93                     AllocatableValue allocatable = getLIRGen().asAllocatable(a);
  94                     resultKind = aKind.makeDerivedReference(allocatable);
  95                     a = allocatable;
  96                 }
  97             } else {
  98                 resultKind = aKind.makeUnknownReference();
  99             }
 100         } else {
 101             resultKind = LIRKind.combine(a, b);
 102         }
 103 
 104         return isAdd ? emitAdd(resultKind, a, b, setFlags) : emitSub(resultKind, a, b, setFlags);
 105     }
 106 








































 107 }
< prev index next >