< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.aarch64/src/org/graalvm/compiler/core/aarch64/AArch64LIRGenerator.java

Print this page




  35 import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag;
  36 import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
  37 import org.graalvm.compiler.core.common.LIRKind;
  38 import org.graalvm.compiler.core.common.calc.Condition;
  39 import org.graalvm.compiler.core.common.spi.LIRKindTool;
  40 import org.graalvm.compiler.debug.GraalError;
  41 import org.graalvm.compiler.lir.LIRFrameState;
  42 import org.graalvm.compiler.lir.LIRValueUtil;
  43 import org.graalvm.compiler.lir.LabelRef;
  44 import org.graalvm.compiler.lir.StandardOp;
  45 import org.graalvm.compiler.lir.SwitchStrategy;
  46 import org.graalvm.compiler.lir.Variable;
  47 import org.graalvm.compiler.lir.aarch64.AArch64AddressValue;
  48 import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp;
  49 import org.graalvm.compiler.lir.aarch64.AArch64ArrayCompareToOp;
  50 import org.graalvm.compiler.lir.aarch64.AArch64ArrayEqualsOp;
  51 import org.graalvm.compiler.lir.aarch64.AArch64ByteSwapOp;
  52 import org.graalvm.compiler.lir.aarch64.AArch64Compare;
  53 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow;
  54 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.BranchOp;

  55 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondMoveOp;
  56 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondSetOp;
  57 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.StrategySwitchOp;
  58 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.TableSwitchOp;
  59 import org.graalvm.compiler.lir.aarch64.AArch64LIRFlagsVersioned;
  60 import org.graalvm.compiler.lir.aarch64.AArch64Move;
  61 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndAddOp;
  62 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndAddLSEOp;
  63 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.CompareAndSwapOp;
  64 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndWriteOp;
  65 import org.graalvm.compiler.lir.aarch64.AArch64Move.MembarOp;
  66 import org.graalvm.compiler.lir.aarch64.AArch64PauseOp;
  67 import org.graalvm.compiler.lir.aarch64.AArch64SpeculativeBarrier;
  68 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  69 import org.graalvm.compiler.lir.gen.LIRGenerator;
  70 import org.graalvm.compiler.phases.util.Providers;
  71 
  72 import jdk.vm.ci.aarch64.AArch64;
  73 import jdk.vm.ci.aarch64.AArch64Kind;
  74 import jdk.vm.ci.code.CallingConvention;


 240     public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) {
 241         boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
 242         Condition finalCondition = mirrored ? cond.mirror() : cond;
 243         boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
 244         ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
 245         Variable result = newVariable(trueValue.getValueKind());
 246 
 247         if (isIntConstant(trueValue, 1) && isIntConstant(falseValue, 0)) {
 248             append(new CondSetOp(result, cmpCondition));
 249         } else if (isIntConstant(trueValue, 0) && isIntConstant(falseValue, 1)) {
 250             append(new CondSetOp(result, cmpCondition.negate()));
 251         } else {
 252             append(new CondMoveOp(result, cmpCondition, loadReg(trueValue), loadReg(falseValue)));
 253         }
 254         return result;
 255     }
 256 
 257     @Override
 258     public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination,
 259                     double trueDestinationProbability) {





















 260         boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
 261         Condition finalCondition = mirrored ? cond.mirror() : cond;
 262         boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
 263         ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
 264         append(new BranchOp(cmpCondition, trueDestination, falseDestination, trueDestinationProbability));
 265     }
 266 
 267     private static ConditionFlag toConditionFlag(boolean isInt, Condition cond, boolean unorderedIsTrue) {
 268         return isInt ? toIntConditionFlag(cond) : toFloatConditionFlag(cond, unorderedIsTrue);
 269     }
 270 
 271     /**
 272      * Takes a Condition and unorderedIsTrue flag and returns the correct Aarch64 specific
 273      * ConditionFlag. Note: This is only correct if the emitCompare code for floats has correctly
 274      * handled the case of 'EQ && unorderedIsTrue', respectively 'NE && !unorderedIsTrue'!
 275      */
 276     private static ConditionFlag toFloatConditionFlag(Condition cond, boolean unorderedIsTrue) {
 277         switch (cond) {
 278             case LT:
 279                 return unorderedIsTrue ? ConditionFlag.LT : ConditionFlag.LO;




  35 import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag;
  36 import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
  37 import org.graalvm.compiler.core.common.LIRKind;
  38 import org.graalvm.compiler.core.common.calc.Condition;
  39 import org.graalvm.compiler.core.common.spi.LIRKindTool;
  40 import org.graalvm.compiler.debug.GraalError;
  41 import org.graalvm.compiler.lir.LIRFrameState;
  42 import org.graalvm.compiler.lir.LIRValueUtil;
  43 import org.graalvm.compiler.lir.LabelRef;
  44 import org.graalvm.compiler.lir.StandardOp;
  45 import org.graalvm.compiler.lir.SwitchStrategy;
  46 import org.graalvm.compiler.lir.Variable;
  47 import org.graalvm.compiler.lir.aarch64.AArch64AddressValue;
  48 import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp;
  49 import org.graalvm.compiler.lir.aarch64.AArch64ArrayCompareToOp;
  50 import org.graalvm.compiler.lir.aarch64.AArch64ArrayEqualsOp;
  51 import org.graalvm.compiler.lir.aarch64.AArch64ByteSwapOp;
  52 import org.graalvm.compiler.lir.aarch64.AArch64Compare;
  53 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow;
  54 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.BranchOp;
  55 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CompareBranchZeroOp;
  56 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondMoveOp;
  57 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondSetOp;
  58 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.StrategySwitchOp;
  59 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.TableSwitchOp;
  60 import org.graalvm.compiler.lir.aarch64.AArch64LIRFlagsVersioned;
  61 import org.graalvm.compiler.lir.aarch64.AArch64Move;
  62 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndAddOp;
  63 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndAddLSEOp;
  64 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.CompareAndSwapOp;
  65 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndWriteOp;
  66 import org.graalvm.compiler.lir.aarch64.AArch64Move.MembarOp;
  67 import org.graalvm.compiler.lir.aarch64.AArch64PauseOp;
  68 import org.graalvm.compiler.lir.aarch64.AArch64SpeculativeBarrier;
  69 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  70 import org.graalvm.compiler.lir.gen.LIRGenerator;
  71 import org.graalvm.compiler.phases.util.Providers;
  72 
  73 import jdk.vm.ci.aarch64.AArch64;
  74 import jdk.vm.ci.aarch64.AArch64Kind;
  75 import jdk.vm.ci.code.CallingConvention;


 241     public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) {
 242         boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
 243         Condition finalCondition = mirrored ? cond.mirror() : cond;
 244         boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
 245         ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
 246         Variable result = newVariable(trueValue.getValueKind());
 247 
 248         if (isIntConstant(trueValue, 1) && isIntConstant(falseValue, 0)) {
 249             append(new CondSetOp(result, cmpCondition));
 250         } else if (isIntConstant(trueValue, 0) && isIntConstant(falseValue, 1)) {
 251             append(new CondSetOp(result, cmpCondition.negate()));
 252         } else {
 253             append(new CondMoveOp(result, cmpCondition, loadReg(trueValue), loadReg(falseValue)));
 254         }
 255         return result;
 256     }
 257 
 258     @Override
 259     public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination,
 260                     double trueDestinationProbability) {
 261         if (cond == Condition.EQ) {
 262             // emit cbz instruction for IsNullNode.
 263             assert !LIRValueUtil.isNullConstant(left) : "emitNullCheckBranch()'s null input should be in right.";
 264             if (LIRValueUtil.isNullConstant(right)) {
 265                 append(new CompareBranchZeroOp(asAllocatable(left), trueDestination, falseDestination, trueDestinationProbability));
 266                 return;
 267             }
 268 
 269             // emit cbz instruction for IntegerEquals when any of the inputs is zero.
 270             AArch64Kind kind = (AArch64Kind) cmpKind;
 271             if (kind.isInteger()) {
 272                 if (isIntConstant(left, 0)) {
 273                     append(new CompareBranchZeroOp(asAllocatable(right), trueDestination, falseDestination, trueDestinationProbability));
 274                     return;
 275                 } else if (isIntConstant(right, 0)) {
 276                     append(new CompareBranchZeroOp(asAllocatable(left), trueDestination, falseDestination, trueDestinationProbability));
 277                     return;
 278                 }
 279             }
 280         }
 281 
 282         boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
 283         Condition finalCondition = mirrored ? cond.mirror() : cond;
 284         boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
 285         ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
 286         append(new BranchOp(cmpCondition, trueDestination, falseDestination, trueDestinationProbability));
 287     }
 288 
 289     private static ConditionFlag toConditionFlag(boolean isInt, Condition cond, boolean unorderedIsTrue) {
 290         return isInt ? toIntConditionFlag(cond) : toFloatConditionFlag(cond, unorderedIsTrue);
 291     }
 292 
 293     /**
 294      * Takes a Condition and unorderedIsTrue flag and returns the correct Aarch64 specific
 295      * ConditionFlag. Note: This is only correct if the emitCompare code for floats has correctly
 296      * handled the case of 'EQ && unorderedIsTrue', respectively 'NE && !unorderedIsTrue'!
 297      */
 298     private static ConditionFlag toFloatConditionFlag(Condition cond, boolean unorderedIsTrue) {
 299         switch (cond) {
 300             case LT:
 301                 return unorderedIsTrue ? ConditionFlag.LT : ConditionFlag.LO;


< prev index next >