use of jdk.vm.ci.meta.Value 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 jdk.vm.ci.meta.Value in project graal by oracle.
the class NodeLIRBuilder method getExactPhiKind.
protected LIRKind getExactPhiKind(PhiNode phi) {
LIRKind derivedKind = gen.toRegisterKind(gen.getLIRKind(phi.stamp(NodeView.DEFAULT)));
/* Collect reference information. */
for (int i = 0; i < phi.valueCount() && !derivedKind.isUnknownReference(); i++) {
ValueNode node = phi.valueAt(i);
Value value = getOperand(node);
// get ValueKind for input
final LIRKind valueKind;
if (value != null) {
valueKind = value.getValueKind(LIRKind.class);
} else {
assert isPhiInputFromBackedge(phi, i) : String.format("Input %s to phi node %s is not yet available although it is not coming from a loop back edge", node, phi);
LIRKind kind = gen.getLIRKind(node.stamp(NodeView.DEFAULT));
valueKind = gen.toRegisterKind(kind);
}
/* Merge the reference information of the derived kind and the input. */
derivedKind = LIRKind.mergeReferenceInformation(derivedKind, valueKind);
}
return derivedKind;
}
use of jdk.vm.ci.meta.Value in project graal by oracle.
the class NodeLIRBuilder method doBlock.
@Override
@SuppressWarnings("try")
public void doBlock(Block block, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
OptionValues options = graph.getOptions();
try (BlockScope blockScope = gen.getBlockScope(block)) {
setSourcePosition(null);
if (block == gen.getResult().getLIR().getControlFlowGraph().getStartBlock()) {
assert block.getPredecessorCount() == 0;
emitPrologue(graph);
} else {
assert block.getPredecessorCount() > 0;
// create phi-in value array
AbstractBeginNode begin = block.getBeginNode();
if (begin instanceof AbstractMergeNode) {
AbstractMergeNode merge = (AbstractMergeNode) begin;
LabelOp label = (LabelOp) gen.getResult().getLIR().getLIRforBlock(block).get(0);
label.setPhiValues(createPhiIn(merge));
if (Options.PrintIRWithLIR.getValue(options) && !TTY.isSuppressed()) {
TTY.println("Created PhiIn: " + label);
}
}
}
doBlockPrologue(block, options);
List<Node> nodes = blockMap.get(block);
// Allow NodeLIRBuilder subclass to specialize code generation of any interesting groups
// of instructions
matchComplexExpressions(nodes);
boolean trace = traceLIRGeneratorLevel >= 3;
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
if (node instanceof ValueNode) {
DebugContext debug = node.getDebug();
ValueNode valueNode = (ValueNode) node;
if (trace) {
TTY.println("LIRGen for " + valueNode);
}
Value operand = getOperand(valueNode);
if (operand == null) {
if (!peephole(valueNode)) {
try {
doRoot(valueNode);
} catch (GraalError e) {
throw GraalGraphError.transformAndAddContext(e, valueNode);
} catch (Throwable e) {
throw new GraalGraphError(e).addContext(valueNode);
}
}
} else if (ComplexMatchValue.INTERIOR_MATCH.equals(operand)) {
// Doesn't need to be evaluated
debug.log("interior match for %s", valueNode);
} else if (operand instanceof ComplexMatchValue) {
debug.log("complex match for %s", valueNode);
ComplexMatchValue match = (ComplexMatchValue) operand;
operand = match.evaluate(this);
if (operand != null) {
setResult(valueNode, operand);
}
} else {
// There can be cases in which the result of an instruction is already set
// before by other instructions.
}
}
}
if (!gen.hasBlockEnd(block)) {
NodeIterable<Node> successors = block.getEndNode().successors();
assert successors.count() == block.getSuccessorCount();
if (block.getSuccessorCount() != 1) {
/*
* If we have more than one successor, we cannot just use the first one. Since
* successors are unordered, this would be a random choice.
*/
throw new GraalError("Block without BlockEndOp: " + block.getEndNode());
}
gen.emitJump(getLIRBlock((FixedNode) successors.first()));
}
assert verifyBlock(gen.getResult().getLIR(), block);
}
}
use of jdk.vm.ci.meta.Value in project graal by oracle.
the class IndexedValueMap method putAll.
public void putAll(IndexedValueMap stack) {
Value[] otherValues = stack.values;
int limit = otherValues.length;
if (limit > values.length) {
while (limit > 0) {
if (otherValues[limit - 1] == null) {
limit--;
continue;
}
break;
}
if (limit > values.length) {
Value[] newValues = new Value[limit];
System.arraycopy(values, 0, newValues, 0, values.length);
values = newValues;
}
}
for (int i = 0; i < limit; i++) {
Value value = otherValues[i];
if (value != null) {
values[i] = value;
}
}
}
use of jdk.vm.ci.meta.Value in project graal by oracle.
the class LIRGenerator method emitForeignCall.
@Override
public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState frameState, Value... args) {
LIRFrameState state = null;
if (linkage.needsDebugInfo()) {
if (frameState != null) {
state = frameState;
} else {
assert needOnlyOopMaps();
state = new LIRFrameState(null, null, null);
}
}
// move the arguments into the correct location
CallingConvention linkageCc = linkage.getOutgoingCallingConvention();
res.getFrameMapBuilder().callsMethod(linkageCc);
assert linkageCc.getArgumentCount() == args.length : "argument count mismatch";
Value[] argLocations = new Value[args.length];
for (int i = 0; i < args.length; i++) {
Value arg = args[i];
AllocatableValue loc = linkageCc.getArgument(i);
emitMove(loc, arg);
argLocations[i] = loc;
}
res.setForeignCall(true);
emitForeignCallOp(linkage, linkageCc.getReturn(), argLocations, linkage.getTemporaries(), state);
if (isLegal(linkageCc.getReturn())) {
return emitMove(linkageCc.getReturn());
} else {
return null;
}
}
Aggregations