package org.graalvm.compiler.nodes.extended;
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
import org.graalvm.compiler.graph.NodeInputList;
import org.graalvm.compiler.nodes.DeoptBciSupplier;
import org.graalvm.compiler.nodes.DeoptimizingNode;
import org.graalvm.compiler.nodes.FrameState;
import org.graalvm.compiler.nodes.StateSplit;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.memory.MultiMemoryKill;
import org.graalvm.compiler.nodes.spi.LIRLowerable;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
import jdk.internal.vm.compiler.word.LocationIdentity;
import jdk.vm.ci.code.BytecodeFrame;
import jdk.vm.ci.meta.Value;
public interface ForeignCall extends LIRLowerable, DeoptimizingNode.DeoptDuring, MultiMemoryKill, StateSplit, DeoptBciSupplier {
NodeInputList<ValueNode> getArguments();
@Override
void setBci(int bci);
ForeignCallDescriptor getDescriptor();
@Override
default LocationIdentity[] getKilledLocationIdentities() {
return getDescriptor().getKilledLocations();
}
default Value[] operands(NodeLIRBuilderTool gen) {
Value[] operands = new Value[getArguments().size()];
for (int i = 0; i < operands.length; i++) {
operands[i] = gen.operand(getArguments().get(i));
}
return operands;
}
@Override
default void computeStateDuring(FrameState currentStateAfter) {
assert stateDuring() == null;
FrameState newStateDuring;
if ((currentStateAfter.stackSize() > 0 && currentStateAfter.stackAt(currentStateAfter.stackSize() - 1) == this) ||
(currentStateAfter.stackSize() > 1 && currentStateAfter.stackAt(currentStateAfter.stackSize() - 2) == this)) {
assert bci() != BytecodeFrame.UNKNOWN_BCI : this;
newStateDuring = currentStateAfter.duplicateModified(currentStateAfter.graph(), bci(), false, true, this.asNode().getStackKind(), null, null);
} else {
newStateDuring = currentStateAfter;
}
setStateDuring(newStateDuring);
}
@Override
default boolean canDeoptimize() {
return getDescriptor().canDeoptimize();
}
default boolean isGuaranteedSafepoint() {
return getDescriptor().isGuaranteedSafepoint();
}
@Override
default void generate(NodeLIRBuilderTool gen) {
gen.emitForeignCall(this);
}
}