use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class CompileQueue method handleSpecialization.
private static void handleSpecialization(final HostedMethod method, MethodCallTargetNode targetNode, HostedMethod invokeTarget, HostedMethod invokeImplementation) {
if (method.getAnnotation(Specialize.class) != null && !method.compilationInfo.isDeoptTarget() && invokeTarget.getAnnotation(DeoptTest.class) != null) {
/*
* Collect the constant arguments to a method which should be specialized.
*/
if (invokeImplementation.compilationInfo.specializedArguments != null) {
VMError.shouldNotReachHere("Specialized method " + invokeImplementation.format("%H.%n(%p)") + " can only be called from one place");
}
invokeImplementation.compilationInfo.specializedArguments = new ConstantNode[targetNode.arguments().size()];
int idx = 0;
for (ValueNode argument : targetNode.arguments()) {
if (!(argument instanceof ConstantNode)) {
VMError.shouldNotReachHere("Argument " + idx + " of specialized method " + invokeImplementation.format("%H.%n(%p)") + " is not constant");
}
invokeImplementation.compilationInfo.specializedArguments[idx++] = (ConstantNode) argument;
}
}
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class CompileQueue method ensureCompiled.
protected void ensureCompiled(HostedMethod method, CompileReason reason) {
CompileTask task = new CompileTask(method, reason);
CompileTask oldTask = compilations.putIfAbsent(method, task);
if (oldTask != null) {
// Method is already scheduled for compilation.
if (oldTask.allReasons != null) {
oldTask.allReasons.add(reason);
}
return;
}
if (method.compilationInfo.specializedArguments != null) {
// Do the specialization: replace the argument locals with the constant arguments.
StructuredGraph graph = method.compilationInfo.graph;
int idx = 0;
for (ConstantNode argument : method.compilationInfo.specializedArguments) {
ParameterNode local = graph.getParameter(idx++);
if (local != null) {
local.replaceAndDelete(ConstantNode.forConstant(argument.asJavaConstant(), runtimeConfig.getProviders().getMetaAccess(), graph));
}
}
}
executor.execute(task);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class NodeLIRBuilder method createPhiOut.
private Value[] createPhiOut(AbstractMergeNode merge, AbstractEndNode pred) {
List<Value> values = new ArrayList<>();
for (PhiNode phi : merge.valuePhis()) {
ValueNode node = phi.valueAt(pred);
Value value = operand(node);
assert value != null;
if (isRegister(value)) {
/*
* Fixed register intervals are not allowed at block boundaries so we introduce a
* new Variable.
*/
value = gen.emitMove(value);
} else if (!allowObjectConstantToStackMove() && node instanceof ConstantNode && !LIRKind.isValue(value)) {
/*
* Some constants are not allowed as inputs for PHIs in certain backends. Explicitly
* create a copy of this value to force it into a register. The new variable is only
* used in the PHI.
*/
Variable result = gen.newVariable(value.getValueKind());
gen.emitMove(result, value);
value = result;
}
values.add(value);
}
return values.toArray(new Value[values.size()]);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class CountedLoopInfo method maxTripCountNode.
/**
* Returns a node that computes the maximum trip count of this loop. That is the trip count of
* this loop assuming it is not exited by an other exit than the {@linkplain #getLimitTest()
* count check}.
*
* This count is exact if {@link #isExactTripCount()} returns true.
*
* THIS VALUE SHOULD BE TREATED AS UNSIGNED.
*
* @param assumePositive if true the check that the loop is entered at all will be omitted.
*/
public ValueNode maxTripCountNode(boolean assumePositive) {
StructuredGraph graph = iv.valueNode().graph();
Stamp stamp = iv.valueNode().stamp(NodeView.DEFAULT);
ValueNode max;
ValueNode min;
ValueNode range;
ValueNode absStride;
if (iv.direction() == Direction.Up) {
absStride = iv.strideNode();
range = sub(graph, end, iv.initNode());
max = end;
min = iv.initNode();
} else {
assert iv.direction() == Direction.Down;
absStride = graph.maybeAddOrUnique(NegateNode.create(iv.strideNode(), NodeView.DEFAULT));
range = sub(graph, iv.initNode(), end);
max = iv.initNode();
min = end;
}
ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
if (oneOff) {
range = add(graph, range, one);
}
// round-away-from-zero divison: (range + stride -/+ 1) / stride
ValueNode denominator = add(graph, range, sub(graph, absStride, one));
ValueNode div = unsignedDivBefore(graph, loop.entryPoint(), denominator, absStride);
if (assumePositive) {
return div;
}
ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(max, min)), zero, div));
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class CountedLoopInfo method createOverFlowGuard.
@SuppressWarnings("try")
public GuardingNode createOverFlowGuard() {
GuardingNode overflowGuard = getOverFlowGuard();
if (overflowGuard != null) {
return overflowGuard;
}
try (DebugCloseable position = loop.loopBegin().withNodeSourcePosition()) {
IntegerStamp stamp = (IntegerStamp) iv.valueNode().stamp(NodeView.DEFAULT);
StructuredGraph graph = iv.valueNode().graph();
// we use a negated guard with a < condition to achieve a >=
CompareNode cond;
ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
if (iv.direction() == Direction.Up) {
ValueNode v1 = sub(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.maxValue(stamp.getBits()), graph), sub(graph, iv.strideNode(), one));
if (oneOff) {
v1 = sub(graph, v1, one);
}
cond = graph.unique(new IntegerLessThanNode(v1, end));
} else {
assert iv.direction() == Direction.Down;
ValueNode v1 = add(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.minValue(stamp.getBits()), graph), sub(graph, one, iv.strideNode()));
if (oneOff) {
v1 = add(graph, v1, one);
}
cond = graph.unique(new IntegerLessThanNode(end, v1));
}
assert graph.getGuardsStage().allowsFloatingGuards();
overflowGuard = graph.unique(new GuardNode(cond, AbstractBeginNode.prevBegin(loop.entryPoint()), DeoptimizationReason.LoopLimitCheck, DeoptimizationAction.InvalidateRecompile, true, // TODO gd: use speculation
JavaConstant.NULL_POINTER));
loop.loopBegin().setOverflowGuard(overflowGuard);
return overflowGuard;
}
}
Aggregations