package org.graalvm.compiler.lir.gen;
import org.graalvm.compiler.core.common.CompressEncoding;
import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.core.common.calc.Condition;
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
import org.graalvm.compiler.core.common.spi.CodeGenProviders;
import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.lir.LIRFrameState;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.LabelRef;
import org.graalvm.compiler.lir.Variable;
import org.graalvm.compiler.lir.VirtualStackSlot;
import jdk.vm.ci.code.CodeCacheProvider;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.code.RegisterConfig;
import jdk.vm.ci.code.StackSlot;
import jdk.vm.ci.code.TargetDescription;
import jdk.vm.ci.code.ValueKindFactory;
import jdk.vm.ci.meta.AllocatableValue;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.PlatformKind;
import jdk.vm.ci.meta.Value;
import jdk.vm.ci.meta.ValueKind;
public interface LIRGeneratorTool extends DiagnosticLIRGeneratorTool, ValueKindFactory<LIRKind> {
interface MoveFactory {
@SuppressWarnings("unused")
default boolean mayEmbedConstantLoad(Constant constant) {
return false;
}
boolean canInlineConstant(Constant constant);
boolean allowConstantToStackMove(Constant constant);
LIRInstruction createMove(AllocatableValue result, Value input);
LIRInstruction createStackMove(AllocatableValue result, AllocatableValue input);
LIRInstruction createLoad(AllocatableValue result, Constant input);
LIRInstruction createStackLoad(AllocatableValue result, Constant input);
}
abstract class BlockScope implements AutoCloseable {
public abstract AbstractBlockBase<?> getCurrentBlock();
@Override
public abstract void close();
}
ArithmeticLIRGeneratorTool getArithmetic();
CodeGenProviders getProviders();
TargetDescription target();
MetaAccessProvider getMetaAccess();
CodeCacheProvider getCodeCache();
ForeignCallsProvider getForeignCalls();
AbstractBlockBase<?> getCurrentBlock();
LIRGenerationResult getResult();
RegisterConfig getRegisterConfig();
MoveFactory getMoveFactory();
MoveFactory getSpillMoveFactory();
boolean canInlineConstant(Constant constant);
boolean mayEmbedConstantLoad(Constant constant);
Value emitConstant(LIRKind kind, Constant constant);
Value emitJavaConstant(JavaConstant constant);
<K extends ValueKind<K>> K toRegisterKind(K kind);
AllocatableValue emitLoadConstant(ValueKind<?> kind, Constant constant);
void emitNullCheck(Value address, LIRFrameState state);
Variable emitLogicCompareAndSwap(LIRKind accessKind, Value address, Value expectedValue, Value newValue, Value trueValue, Value falseValue);
Value emitValueCompareAndSwap(LIRKind accessKind, Value address, Value expectedValue, Value newValue);
default Value emitAtomicReadAndAdd(Value address, ValueKind<?> valueKind, Value delta) {
throw GraalError.unimplemented();
}
default Value emitAtomicReadAndWrite(Value address, ValueKind<?> valueKind, Value newValue) {
throw GraalError.unimplemented();
}
void emitDeoptimize(Value actionAndReason, Value failedSpeculation, LIRFrameState state);
Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args);
Variable newVariable(ValueKind<?> kind);
Variable emitMove(Value input);
void emitMove(AllocatableValue dst, Value src);
Variable emitReadRegister(Register register, ValueKind<?> kind);
void emitWriteRegister(Register dst, Value src, ValueKind<?> wordStamp);
void emitMoveConstant(AllocatableValue dst, Constant src);
Variable emitAddress(AllocatableValue stackslot);
void emitMembar(int barriers);
void emitUnwind(Value operand);
void emitReturn(JavaKind javaKind, Value input);
AllocatableValue asAllocatable(Value value);
Variable load(Value value);
<I extends LIRInstruction> I append(I op);
void emitJump(LabelRef label);
Variable emitConditionalMove(PlatformKind cmpKind, Value leftVal, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue);
Variable emitIntegerTestMove(Value leftVal, Value right, Value trueValue, Value falseValue);
Variable emitByteSwap(Value operand);
@SuppressWarnings("unused")
default Variable emitArrayCompareTo(JavaKind kind1, JavaKind kind2, Value array1, Value array2, Value length1, Value length2) {
throw GraalError.unimplemented("String.compareTo substitution is not implemented on this architecture");
}
@SuppressWarnings("unused")
default Variable emitArrayEquals(JavaKind kind, Value array1, Value array2, Value length, boolean directPointers) {
throw GraalError.unimplemented("Array.equals substitution is not implemented on this architecture");
}
@SuppressWarnings("unused")
default Variable emitArrayEquals(JavaKind kind1, JavaKind kind2, Value array1, Value array2, Value length, boolean directPointers) {
throw GraalError.unimplemented("Array.equals with different types substitution is not implemented on this architecture");
}
@SuppressWarnings("unused")
default Variable emitArrayIndexOf(JavaKind arrayKind, JavaKind valueKind, boolean findTwoConsecutive, Value sourcePointer, Value sourceCount, Value fromIndex, Value... searchValues) {
throw GraalError.unimplemented("String.indexOf substitution is not implemented on this architecture");
}
@SuppressWarnings("unused")
default void emitStringLatin1Inflate(Value src, Value dst, Value len) {
throw GraalError.unimplemented("StringLatin1.inflate substitution is not implemented on this architecture");
}
@SuppressWarnings("unused")
default Variable emitStringUTF16Compress(Value src, Value dst, Value len) {
throw GraalError.unimplemented("StringUTF16.compress substitution is not implemented on this architecture");
}
void emitBlackhole(Value operand);
LIRKind getLIRKind(Stamp stamp);
void emitPause();
void emitPrefetchAllocate(Value address);
Value emitCompress(Value pointer, CompressEncoding encoding, boolean nonNull);
Value emitUncompress(Value pointer, CompressEncoding encoding, boolean nonNull);
default void emitConvertNullToZero(AllocatableValue result, Value input) {
emitMove(result, input);
}
default void emitConvertZeroToNull(AllocatableValue result, Value input) {
emitMove(result, input);
}
void emitSpeculationFence();
default VirtualStackSlot allocateStackSlots(int slots) {
return getResult().getFrameMapBuilder().allocateStackSlots(slots);
}
default Value emitReadCallerStackPointer(Stamp wordStamp) {
return emitAddress(StackSlot.get(getLIRKind(wordStamp), 0, true));
}
default Value emitReadReturnAddress(Stamp wordStamp, int returnAddressSize) {
return emitMove(StackSlot.get(getLIRKind(wordStamp), -returnAddressSize, true));
}
@SuppressWarnings("unused")
default void emitZeroMemory(Value address, Value length, boolean isAligned) {
throw GraalError.unimplemented("Bulk zeroing is not implemented on this architecture");
}
}