use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class SnippetTemplate method bind.
/**
* Gets the instantiation-time bindings to this template's parameters.
*
* @return the map that will be used to bind arguments to parameters when inlining this template
*/
private EconomicMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider metaAccess, Arguments args) {
EconomicMap<Node, Node> replacements = EconomicMap.create(Equivalence.IDENTITY);
assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")";
for (int i = 0; i < parameters.length; i++) {
Object parameter = parameters[i];
assert parameter != null : this + " has no parameter named " + args.info.getParameterName(i);
Object argument = args.values[i];
if (parameter instanceof ParameterNode) {
if (argument instanceof ValueNode) {
replacements.put((ParameterNode) parameter, (ValueNode) argument);
} else {
JavaKind kind = ((ParameterNode) parameter).getStackKind();
assert argument != null || kind == JavaKind.Object : this + " cannot accept null for non-object parameter named " + args.info.getParameterName(i);
JavaConstant constant = forBoxed(argument, kind);
replacements.put((ParameterNode) parameter, ConstantNode.forConstant(constant, metaAccess, replaceeGraph));
}
} else if (parameter instanceof ParameterNode[]) {
ParameterNode[] params = (ParameterNode[]) parameter;
Varargs varargs = (Varargs) argument;
int length = params.length;
List<?> list = null;
Object array = null;
if (varargs.value instanceof List) {
list = (List<?>) varargs.value;
assert list.size() == length : length + " != " + list.size();
} else {
array = varargs.value;
assert array != null && array.getClass().isArray();
assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
}
for (int j = 0; j < length; j++) {
ParameterNode param = params[j];
assert param != null;
Object value = list != null ? list.get(j) : Array.get(array, j);
if (value instanceof ValueNode) {
replacements.put(param, (ValueNode) value);
} else {
JavaConstant constant = forBoxed(value, param.getStackKind());
ConstantNode element = ConstantNode.forConstant(constant, metaAccess, replaceeGraph);
replacements.put(param, element);
}
}
} else {
assert parameter.equals(CONSTANT_PARAMETER) || parameter.equals(UNUSED_PARAMETER) : "unexpected entry for parameter: " + args.info.getParameterName(i) + " -> " + parameter;
}
}
return replacements;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class ArrayEqualsNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (tool.allUsagesAvailable() && hasNoUsages()) {
return null;
}
ValueNode a1 = GraphUtil.unproxify(array1);
ValueNode a2 = GraphUtil.unproxify(array2);
if (a1 == a2) {
return ConstantNode.forBoolean(true);
}
if (a1.isConstant() && a2.isConstant() && length.isConstant()) {
ConstantNode c1 = (ConstantNode) a1;
ConstantNode c2 = (ConstantNode) a2;
if (c1.getStableDimension() >= 1 && c2.getStableDimension() >= 1) {
boolean ret = arrayEquals(tool.getConstantReflection(), c1.asJavaConstant(), c2.asJavaConstant(), length.asJavaConstant().asInt());
return ConstantNode.forBoolean(ret);
}
}
return this;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class RemNode method create.
public static ValueNode create(ValueNode forX, ValueNode forY, NodeView view) {
BinaryOp<Rem> op = ArithmeticOpTable.forStamp(forX.stamp(view)).getRem();
Stamp stamp = op.foldStamp(forX.stamp(view), forY.stamp(view));
ConstantNode tryConstantFold = tryConstantFold(op, forX, forY, stamp, view);
if (tryConstantFold != null) {
return tryConstantFold;
}
return new RemNode(forX, forY);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class MulNode method create.
public static ValueNode create(ValueNode x, ValueNode y, NodeView view) {
BinaryOp<Mul> op = ArithmeticOpTable.forStamp(x.stamp(view)).getMul();
Stamp stamp = op.foldStamp(x.stamp(view), y.stamp(view));
ConstantNode tryConstantFold = tryConstantFold(op, x, y, stamp, view);
if (tryConstantFold != null) {
return tryConstantFold;
}
return canonical(null, op, stamp, x, y, view);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class OrNode method create.
public static ValueNode create(ValueNode x, ValueNode y, NodeView view) {
BinaryOp<Or> op = ArithmeticOpTable.forStamp(x.stamp(view)).getOr();
Stamp stamp = op.foldStamp(x.stamp(view), y.stamp(view));
ConstantNode tryConstantFold = tryConstantFold(op, x, y, stamp, view);
if (tryConstantFold != null) {
return tryConstantFold;
}
return canonical(null, op, stamp, x, y, view);
}
Aggregations