package org.graalvm.compiler.phases.common.inlining;
import java.util.Map;
import org.graalvm.compiler.nodes.Invoke;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.options.Option;
import org.graalvm.compiler.options.OptionType;
import org.graalvm.compiler.options.OptionValue;
import org.graalvm.compiler.phases.common.AbstractInliningPhase;
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
import org.graalvm.compiler.phases.common.inlining.policy.GreedyInliningPolicy;
import org.graalvm.compiler.phases.common.inlining.policy.InliningPolicy;
import org.graalvm.compiler.phases.common.inlining.walker.InliningData;
import org.graalvm.compiler.phases.tiers.HighTierContext;
public class InliningPhase extends AbstractInliningPhase {
public static class Options {
@Option(help = "Unconditionally inline intrinsics", type = OptionType.Debug)
public static final OptionValue<Boolean> AlwaysInlineIntrinsics = new OptionValue<>(false);
@Option(help = "Per-compilation method inlining exploration limit before giving up (use 0 to disable)", type = OptionType.Debug)
public static final OptionValue<Integer> MethodInlineBailoutLimit = new OptionValue<>(5000);
}
private final InliningPolicy inliningPolicy;
private final CanonicalizerPhase canonicalizer;
private int maxMethodPerInlining = Integer.MAX_VALUE;
public InliningPhase(CanonicalizerPhase canonicalizer) {
this(new GreedyInliningPolicy(null), canonicalizer);
}
public InliningPhase(Map<Invoke, Double> hints, CanonicalizerPhase canonicalizer) {
this(new GreedyInliningPolicy(hints), canonicalizer);
}
public InliningPhase(InliningPolicy policy, CanonicalizerPhase canonicalizer) {
this.inliningPolicy = policy;
this.canonicalizer = canonicalizer;
}
public CanonicalizerPhase getCanonicalizer() {
return canonicalizer;
}
@Override
public float codeSizeIncrease() {
return 10_000f;
}
public void setMaxMethodsPerInlining(int max) {
maxMethodPerInlining = max;
}
@Override
protected void run(final StructuredGraph graph, final HighTierContext context) {
final InliningData data = new InliningData(graph, context, maxMethodPerInlining, canonicalizer, inliningPolicy);
int count = 0;
assert data.repOK();
int limit = Options.MethodInlineBailoutLimit.getValue();
while (data.hasUnprocessedGraphs()) {
boolean wasInlined = data.moveForward();
assert data.repOK();
count++;
if (!wasInlined) {
if (limit > 0 && count == limit) {
break;
}
}
}
assert data.inliningDepth() == 0 || count == limit;
assert data.graphCount() == 0 || count == limit;
}
}