< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/inlining/info/elem/InlineableGraph.java

Print this page




  26 
  27 import java.util.ArrayList;
  28 import java.util.List;
  29 
  30 import org.graalvm.compiler.core.common.type.Stamp;
  31 import org.graalvm.compiler.debug.DebugContext;
  32 import org.graalvm.compiler.graph.Node;
  33 import org.graalvm.compiler.graph.NodeInputList;
  34 import org.graalvm.compiler.nodes.ConstantNode;
  35 import org.graalvm.compiler.nodes.Invoke;
  36 import org.graalvm.compiler.nodes.ParameterNode;
  37 import org.graalvm.compiler.nodes.StructuredGraph;
  38 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  39 import org.graalvm.compiler.nodes.ValueNode;
  40 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  41 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  42 import org.graalvm.compiler.phases.common.inlining.InliningUtil;
  43 import org.graalvm.compiler.phases.graph.FixedNodeProbabilityCache;
  44 import org.graalvm.compiler.phases.tiers.HighTierContext;
  45 
  46 import jdk.vm.ci.meta.Constant;
  47 import jdk.vm.ci.meta.ResolvedJavaMethod;
  48 
  49 /**
  50  * <p>
  51  * Represents a feasible concrete target for inlining, whose graph has been copied already and thus
  52  * can be modified without affecting the original (usually cached) version.
  53  * </p>
  54  *
  55  * <p>
  56  * Instances of this class don't make sense in isolation but as part of an
  57  * {@link org.graalvm.compiler.phases.common.inlining.info.InlineInfo InlineInfo}.
  58  * </p>
  59  *
  60  * @see org.graalvm.compiler.phases.common.inlining.walker.InliningData#moveForward()
  61  * @see org.graalvm.compiler.phases.common.inlining.walker.CallsiteHolderExplorable
  62  */
  63 public class InlineableGraph implements Inlineable {
  64 
  65     private final StructuredGraph graph;
  66 


 142      * </p>
 143      *
 144      * @return null if no incremental canonicalization is need, a list of nodes for such
 145      *         canonicalization otherwise.
 146      */
 147     private ArrayList<Node> replaceParamsWithMoreInformativeArguments(final Invoke invoke, final HighTierContext context) {
 148         NodeInputList<ValueNode> args = invoke.callTarget().arguments();
 149         ArrayList<Node> parameterUsages = null;
 150         List<ParameterNode> params = graph.getNodes(ParameterNode.TYPE).snapshot();
 151         assert params.size() <= args.size();
 152         /*
 153          * param-nodes that aren't used (eg, as a result of canonicalization) don't occur in
 154          * `params`. Thus, in general, the sizes of `params` and `args` don't always match. Still,
 155          * it's always possible to pair a param-node with its corresponding arg-node using
 156          * param.index() as index into `args`.
 157          */
 158         for (ParameterNode param : params) {
 159             if (param.usages().isNotEmpty()) {
 160                 ValueNode arg = args.get(param.index());
 161                 if (arg.isConstant()) {
 162                     Constant constant = arg.asConstant();
 163                     parameterUsages = trackParameterUsages(param, parameterUsages);
 164                     // collect param usages before replacing the param
 165                     param.replaceAtUsagesAndDelete(graph.unique(
 166                                     ConstantNode.forConstant(arg.stamp(), constant, ((ConstantNode) arg).getStableDimension(), ((ConstantNode) arg).isDefaultStable(), context.getMetaAccess())));
 167                     // param-node gone, leaving a gap in the sequence given by param.index()
 168                 } else {
 169                     Stamp impro = improvedStamp(arg, param);
 170                     if (impro != null) {
 171                         param.setStamp(impro);
 172                         parameterUsages = trackParameterUsages(param, parameterUsages);
 173                     } else {
 174                         assert !isArgMoreInformativeThanParam(arg, param);
 175                     }
 176                 }
 177             }
 178         }
 179         assert (parameterUsages == null) || (!parameterUsages.isEmpty());
 180         return parameterUsages;
 181     }
 182 
 183     private static ArrayList<Node> trackParameterUsages(ParameterNode param, ArrayList<Node> parameterUsages) {
 184         ArrayList<Node> result = (parameterUsages == null) ? new ArrayList<>() : parameterUsages;
 185         param.usages().snapshotTo(result);
 186         return result;




  26 
  27 import java.util.ArrayList;
  28 import java.util.List;
  29 
  30 import org.graalvm.compiler.core.common.type.Stamp;
  31 import org.graalvm.compiler.debug.DebugContext;
  32 import org.graalvm.compiler.graph.Node;
  33 import org.graalvm.compiler.graph.NodeInputList;
  34 import org.graalvm.compiler.nodes.ConstantNode;
  35 import org.graalvm.compiler.nodes.Invoke;
  36 import org.graalvm.compiler.nodes.ParameterNode;
  37 import org.graalvm.compiler.nodes.StructuredGraph;
  38 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  39 import org.graalvm.compiler.nodes.ValueNode;
  40 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  41 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  42 import org.graalvm.compiler.phases.common.inlining.InliningUtil;
  43 import org.graalvm.compiler.phases.graph.FixedNodeProbabilityCache;
  44 import org.graalvm.compiler.phases.tiers.HighTierContext;
  45 

  46 import jdk.vm.ci.meta.ResolvedJavaMethod;
  47 
  48 /**
  49  * <p>
  50  * Represents a feasible concrete target for inlining, whose graph has been copied already and thus
  51  * can be modified without affecting the original (usually cached) version.
  52  * </p>
  53  *
  54  * <p>
  55  * Instances of this class don't make sense in isolation but as part of an
  56  * {@link org.graalvm.compiler.phases.common.inlining.info.InlineInfo InlineInfo}.
  57  * </p>
  58  *
  59  * @see org.graalvm.compiler.phases.common.inlining.walker.InliningData#moveForward()
  60  * @see org.graalvm.compiler.phases.common.inlining.walker.CallsiteHolderExplorable
  61  */
  62 public class InlineableGraph implements Inlineable {
  63 
  64     private final StructuredGraph graph;
  65 


 141      * </p>
 142      *
 143      * @return null if no incremental canonicalization is need, a list of nodes for such
 144      *         canonicalization otherwise.
 145      */
 146     private ArrayList<Node> replaceParamsWithMoreInformativeArguments(final Invoke invoke, final HighTierContext context) {
 147         NodeInputList<ValueNode> args = invoke.callTarget().arguments();
 148         ArrayList<Node> parameterUsages = null;
 149         List<ParameterNode> params = graph.getNodes(ParameterNode.TYPE).snapshot();
 150         assert params.size() <= args.size();
 151         /*
 152          * param-nodes that aren't used (eg, as a result of canonicalization) don't occur in
 153          * `params`. Thus, in general, the sizes of `params` and `args` don't always match. Still,
 154          * it's always possible to pair a param-node with its corresponding arg-node using
 155          * param.index() as index into `args`.
 156          */
 157         for (ParameterNode param : params) {
 158             if (param.usages().isNotEmpty()) {
 159                 ValueNode arg = args.get(param.index());
 160                 if (arg.isConstant()) {
 161                     ConstantNode constant = (ConstantNode) arg;
 162                     parameterUsages = trackParameterUsages(param, parameterUsages);
 163                     // collect param usages before replacing the param
 164                     param.replaceAtUsagesAndDelete(graph.unique(
 165                                     ConstantNode.forConstant(arg.stamp(), constant.getValue(), constant.getStableDimension(), constant.isDefaultStable(), context.getMetaAccess())));
 166                     // param-node gone, leaving a gap in the sequence given by param.index()
 167                 } else {
 168                     Stamp impro = improvedStamp(arg, param);
 169                     if (impro != null) {
 170                         param.setStamp(impro);
 171                         parameterUsages = trackParameterUsages(param, parameterUsages);
 172                     } else {
 173                         assert !isArgMoreInformativeThanParam(arg, param);
 174                     }
 175                 }
 176             }
 177         }
 178         assert (parameterUsages == null) || (!parameterUsages.isEmpty());
 179         return parameterUsages;
 180     }
 181 
 182     private static ArrayList<Node> trackParameterUsages(ParameterNode param, ArrayList<Node> parameterUsages) {
 183         ArrayList<Node> result = (parameterUsages == null) ? new ArrayList<>() : parameterUsages;
 184         param.usages().snapshotTo(result);
 185         return result;


< prev index next >