Skip to content

Commit 22d9af0

Browse files
committed
svm: fix invariant violations in the LLVM backend
1 parent 92ddd71 commit 22d9af0

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
import jdk.graal.compiler.graph.Node;
114114
import jdk.graal.compiler.lir.LIRFrameState;
115115
import jdk.graal.compiler.lir.LIRInstruction;
116+
import jdk.graal.compiler.lir.LIRValueUtil;
116117
import jdk.graal.compiler.lir.LabelRef;
117118
import jdk.graal.compiler.lir.Variable;
118119
import jdk.graal.compiler.lir.VirtualStackSlot;
@@ -582,8 +583,8 @@ public AllocatableValue asAllocatable(Value value) {
582583

583584
@Override
584585
public Variable emitMove(Value input) {
585-
if (input instanceof LLVMVariable) {
586-
return (LLVMVariable) input;
586+
if (LIRValueUtil.isVariable(input) && LIRValueUtil.asVariable(input) instanceof LLVMVariable) {
587+
return LIRValueUtil.asVariable(input);
587588
} else if (input instanceof LLVMValueWrapper) {
588589
return new LLVMVariable(getVal(input));
589590
}
@@ -619,7 +620,7 @@ public void emitMove(AllocatableValue dst, Value src) {
619620
} else if (LLVMIRBuilder.isWordType(destType) && LLVMIRBuilder.isObjectType(sourceType)) {
620621
source = builder.buildPtrToInt(source);
621622
}
622-
((LLVMVariable) dst).set(source);
623+
((LLVMVariable) LIRValueUtil.asVariable(dst)).set(source);
623624
}
624625

625626
@Override

substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/NodeLLVMBuilder.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import jdk.graal.compiler.graph.iterators.NodeIterable;
8888
import jdk.graal.compiler.lir.ConstantValue;
8989
import jdk.graal.compiler.lir.LIRFrameState;
90+
import jdk.graal.compiler.lir.LIRValueUtil;
9091
import jdk.graal.compiler.lir.Variable;
9192
import jdk.graal.compiler.nodes.AbstractBeginNode;
9293
import jdk.graal.compiler.nodes.AbstractEndNode;
@@ -224,7 +225,8 @@ public void doBlock(HIRBlock block, StructuredGraph graph, BlockMap<List<Node>>
224225
if (processedBlocks.contains(predecessor)) {
225226
ValueNode phiValue = phiNode.valueAt((AbstractEndNode) predecessor.getEndNode());
226227
LLVMValueRef value;
227-
if (operand(phiValue) instanceof LLVMPendingSpecialRegisterRead) {
228+
Value operand = operand(phiValue);
229+
if (LIRValueUtil.isVariable(operand) && LIRValueUtil.asVariable(operand) instanceof LLVMPendingSpecialRegisterRead) {
228230
/*
229231
* The pending read may need to perform instructions to load the
230232
* value, so we put them at the end of the predecessor block
@@ -508,7 +510,7 @@ public void emitInvoke(Invoke i) {
508510

509511
if (nextMemoryAccessNeedsDecompress) {
510512
computedAddress = builder.buildAddrSpaceCast(computedAddress, builder.objectType(true));
511-
LLVMValueRef heapBase = ((LLVMVariable) gen.emitReadRegister(ReservedRegisters.singleton().getHeapBaseRegister(), null)).get();
513+
LLVMValueRef heapBase = ((LLVMVariable) LIRValueUtil.asVariable(gen.emitReadRegister(ReservedRegisters.singleton().getHeapBaseRegister(), null))).get();
512514
computedAddress = builder.buildUncompress(computedAddress, heapBase, true, compressionShift);
513515
}
514516

@@ -777,14 +779,12 @@ public Value setResult(ValueNode node, Value operand) {
777779
assert kind == ValueKind.Illegal.getPlatformKind();
778780
llvmOperand = new LLVMVariable(builder.getUndef());
779781
}
780-
} else if (operand instanceof LLVMAddressValue) {
781-
LLVMAddressValue addressValue = (LLVMAddressValue) operand;
782+
} else if (operand instanceof LLVMAddressValue addressValue) {
782783
Value wrappedBase = addressValue.getBase();
783784
Value index = addressValue.getIndex();
784785

785-
if (wrappedBase instanceof LLVMPendingSpecialRegisterRead) {
786-
LLVMPendingSpecialRegisterRead pendingRead = (LLVMPendingSpecialRegisterRead) wrappedBase;
787-
if (index != null && index != Value.ILLEGAL) {
786+
if (LIRValueUtil.isVariable(wrappedBase) && LIRValueUtil.asVariable(wrappedBase) instanceof LLVMPendingSpecialRegisterRead pendingRead) {
787+
if (index != null && !index.equals(Value.ILLEGAL)) {
788788
pendingRead = new LLVMPendingSpecialRegisterRead(pendingRead, LLVMUtils.getVal(addressValue.getIndex()));
789789
}
790790
llvmOperand = pendingRead;
@@ -800,7 +800,7 @@ public Value setResult(ValueNode node, Value operand) {
800800
}
801801

802802
LLVMValueRef intermediate;
803-
if (index == null || index == Value.ILLEGAL) {
803+
if (index == null || index.equals(Value.ILLEGAL)) {
804804
intermediate = base;
805805
} else {
806806
intermediate = builder.buildGEP(base, LLVMUtils.getVal(index));

substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/runtime/LLVMExceptionUnwind.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.graalvm.nativeimage.c.struct.CStruct;
4040
import org.graalvm.word.Pointer;
4141
import org.graalvm.word.PointerBase;
42-
import org.graalvm.word.WordFactory;
4342

4443
import com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess;
4544
import com.oracle.svm.core.SubstrateOptions;
@@ -51,6 +50,7 @@
5150
import com.oracle.svm.hosted.code.CEntryPointCallStubSupport;
5251

5352
import jdk.graal.compiler.core.common.NumUtil;
53+
import jdk.graal.compiler.word.Word;
5454
import jdk.vm.ci.meta.MetaAccessProvider;
5555
import jdk.vm.ci.meta.ResolvedJavaMethod;
5656

@@ -147,7 +147,7 @@ public static ExceptionUnwind createRaiseExceptionHandler() {
147147
protected void customUnwindException(Pointer callerSP) {
148148
_Unwind_Exception exceptionStructure = UnsafeStackValue.get(_Unwind_Exception.class);
149149
exceptionStructure.set_exception_class(CurrentIsolate.getCurrentThread());
150-
exceptionStructure.set_exception_cleanup(WordFactory.nullPointer());
150+
exceptionStructure.set_exception_cleanup(Word.nullPointer());
151151
raiseException(exceptionStructure);
152152
}
153153
};

0 commit comments

Comments
 (0)