src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceRegisterAllocationPolicy.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceRegisterAllocationPolicy.java

Print this page




  29 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
  30 import org.graalvm.compiler.lir.LIR;
  31 import org.graalvm.compiler.lir.alloc.trace.TraceAllocationPhase.TraceAllocationContext;
  32 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  33 import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
  34 
  35 import jdk.vm.ci.code.TargetDescription;
  36 import jdk.vm.ci.common.JVMCIError;
  37 import jdk.vm.ci.meta.AllocatableValue;
  38 
  39 /**
  40  * Manages the selection of allocation strategies.
  41  */
  42 public final class TraceRegisterAllocationPolicy {
  43 
  44     protected abstract class AllocationStrategy {
  45         TraceAllocationPhase<TraceAllocationContext> allocator;
  46 
  47         public final TraceAllocationPhase<TraceAllocationContext> getAllocator() {
  48             if (allocator == null) {
  49                 allocator = initAllocator(target, lirGenRes, spillMoveFactory, registerAllocationConfig, cachedStackSlots, resultTraces, neverSpillConstants, strategies);
  50             }
  51             return allocator;
  52         }
  53 
  54         protected final LIR getLIR() {
  55             return lirGenRes.getLIR();
  56         }
  57 
  58         protected final LIRGenerationResult getLIRGenerationResult() {
  59             return lirGenRes;
  60         }
  61 
  62         protected final TraceBuilderResult getTraceBuilderResult() {
  63             return resultTraces;
  64         }
  65 
  66         /**
  67          * Returns {@code true} if the allocation strategy should be used for {@code trace}.
  68          */
  69         public abstract boolean shouldApplyTo(Trace trace);
  70 
  71         @SuppressWarnings("hiding")
  72         protected abstract TraceAllocationPhase<TraceAllocationContext> initAllocator(TargetDescription target, LIRGenerationResult lirGenRes, MoveFactory spillMoveFactory,
  73                         RegisterAllocationConfig registerAllocationConfig, AllocatableValue[] cachedStackSlots, TraceBuilderResult resultTraces, boolean neverSpillConstant,
  74                         ArrayList<AllocationStrategy> strategies);
  75     }
  76 
  77     private final TargetDescription target;
  78     private final LIRGenerationResult lirGenRes;
  79     private final MoveFactory spillMoveFactory;
  80     private final RegisterAllocationConfig registerAllocationConfig;
  81     private final AllocatableValue[] cachedStackSlots;
  82     private final TraceBuilderResult resultTraces;
  83     private final boolean neverSpillConstants;

  84 
  85     private final ArrayList<AllocationStrategy> strategies;
  86 
  87     public TraceRegisterAllocationPolicy(TargetDescription target, LIRGenerationResult lirGenRes, MoveFactory spillMoveFactory, RegisterAllocationConfig registerAllocationConfig,
  88                     AllocatableValue[] cachedStackSlots, TraceBuilderResult resultTraces, boolean neverSpillConstant) {
  89         this.target = target;
  90         this.lirGenRes = lirGenRes;
  91         this.spillMoveFactory = spillMoveFactory;
  92         this.registerAllocationConfig = registerAllocationConfig;
  93         this.cachedStackSlots = cachedStackSlots;
  94         this.resultTraces = resultTraces;
  95         this.neverSpillConstants = neverSpillConstant;

  96 
  97         this.strategies = new ArrayList<>(3);
  98     }
  99 
 100     public void appendStrategy(AllocationStrategy strategy) {
 101         strategies.add(strategy);
 102     }
 103 
 104     public TraceAllocationPhase<TraceAllocationContext> selectStrategy(Trace trace) {
 105         for (AllocationStrategy strategy : strategies) {
 106             if (strategy.shouldApplyTo(trace)) {
 107                 return strategy.getAllocator();
 108             }
 109         }
 110         throw JVMCIError.shouldNotReachHere("No Allocation Strategy found!");
 111     }
 112 
 113 }


  29 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
  30 import org.graalvm.compiler.lir.LIR;
  31 import org.graalvm.compiler.lir.alloc.trace.TraceAllocationPhase.TraceAllocationContext;
  32 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  33 import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
  34 
  35 import jdk.vm.ci.code.TargetDescription;
  36 import jdk.vm.ci.common.JVMCIError;
  37 import jdk.vm.ci.meta.AllocatableValue;
  38 
  39 /**
  40  * Manages the selection of allocation strategies.
  41  */
  42 public final class TraceRegisterAllocationPolicy {
  43 
  44     protected abstract class AllocationStrategy {
  45         TraceAllocationPhase<TraceAllocationContext> allocator;
  46 
  47         public final TraceAllocationPhase<TraceAllocationContext> getAllocator() {
  48             if (allocator == null) {
  49                 allocator = initAllocator(target, lirGenRes, spillMoveFactory, registerAllocationConfig, cachedStackSlots, resultTraces, neverSpillConstants, livenessInfo, strategies);
  50             }
  51             return allocator;
  52         }
  53 
  54         protected final LIR getLIR() {
  55             return lirGenRes.getLIR();
  56         }
  57 
  58         protected final LIRGenerationResult getLIRGenerationResult() {
  59             return lirGenRes;
  60         }
  61 
  62         protected final TraceBuilderResult getTraceBuilderResult() {
  63             return resultTraces;
  64         }
  65 
  66         /**
  67          * Returns {@code true} if the allocation strategy should be used for {@code trace}.
  68          */
  69         public abstract boolean shouldApplyTo(Trace trace);
  70 
  71         @SuppressWarnings("hiding")
  72         protected abstract TraceAllocationPhase<TraceAllocationContext> initAllocator(TargetDescription target, LIRGenerationResult lirGenRes, MoveFactory spillMoveFactory,
  73                         RegisterAllocationConfig registerAllocationConfig, AllocatableValue[] cachedStackSlots, TraceBuilderResult resultTraces, boolean neverSpillConstant,
  74                         GlobalLivenessInfo livenessInfo, ArrayList<AllocationStrategy> strategies);
  75     }
  76 
  77     private final TargetDescription target;
  78     private final LIRGenerationResult lirGenRes;
  79     private final MoveFactory spillMoveFactory;
  80     private final RegisterAllocationConfig registerAllocationConfig;
  81     private final AllocatableValue[] cachedStackSlots;
  82     private final TraceBuilderResult resultTraces;
  83     private final boolean neverSpillConstants;
  84     private final GlobalLivenessInfo livenessInfo;
  85 
  86     private final ArrayList<AllocationStrategy> strategies;
  87 
  88     public TraceRegisterAllocationPolicy(TargetDescription target, LIRGenerationResult lirGenRes, MoveFactory spillMoveFactory, RegisterAllocationConfig registerAllocationConfig,
  89                     AllocatableValue[] cachedStackSlots, TraceBuilderResult resultTraces, boolean neverSpillConstant, GlobalLivenessInfo livenessInfo) {
  90         this.target = target;
  91         this.lirGenRes = lirGenRes;
  92         this.spillMoveFactory = spillMoveFactory;
  93         this.registerAllocationConfig = registerAllocationConfig;
  94         this.cachedStackSlots = cachedStackSlots;
  95         this.resultTraces = resultTraces;
  96         this.neverSpillConstants = neverSpillConstant;
  97         this.livenessInfo = livenessInfo;
  98 
  99         this.strategies = new ArrayList<>(3);
 100     }
 101 
 102     public void appendStrategy(AllocationStrategy strategy) {
 103         strategies.add(strategy);
 104     }
 105 
 106     public TraceAllocationPhase<TraceAllocationContext> selectStrategy(Trace trace) {
 107         for (AllocationStrategy strategy : strategies) {
 108             if (strategy.shouldApplyTo(trace)) {
 109                 return strategy.getAllocator();
 110             }
 111         }
 112         throw JVMCIError.shouldNotReachHere("No Allocation Strategy found!");
 113     }
 114 
 115 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceRegisterAllocationPolicy.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File