Skip to content

Commit f704127

Browse files
patrick96peter-hofer
authored andcommitted
Lower FloatingWordCastNode in Web Image
1 parent 96fdf86 commit f704127

File tree

5 files changed

+46
-37
lines changed

5 files changed

+46
-37
lines changed

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/codegen/WebImageJSNodeLowerer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode;
4545
import com.oracle.svm.core.genscavenge.graal.nodes.FormatArrayNode;
4646
import com.oracle.svm.core.genscavenge.graal.nodes.FormatObjectNode;
47+
import com.oracle.svm.core.graal.nodes.FloatingWordCastNode;
4748
import com.oracle.svm.core.graal.nodes.LoweredDeadEndNode;
4849
import com.oracle.svm.core.graal.nodes.ReadCallerStackPointerNode;
4950
import com.oracle.svm.core.graal.nodes.ReadReturnAddressNode;
@@ -334,6 +335,8 @@ protected void dispatch(Node node) {
334335
lower(readIdentityHashCodeNode);
335336
} else if (node instanceof WriteIdentityHashCodeNode writeIdentityHashCodeNode) {
336337
lower(writeIdentityHashCodeNode);
338+
} else if (node instanceof FloatingWordCastNode floatingWordCastNode) {
339+
lower(floatingWordCastNode);
337340
} else {
338341
super.dispatch(node);
339342
}
@@ -968,6 +971,10 @@ protected void lower(WordCastNode node) {
968971
lowerValue(node.getInput());
969972
}
970973

974+
protected void lower(FloatingWordCastNode node) {
975+
lowerValue(node.getInput());
976+
}
977+
971978
@Override
972979
protected void lower(InstanceOfNode node) {
973980
CodeBuffer masm = codeGenTool.getCodeBuffer();

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/options/WebImageOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static final class DebugOptions {
126126
public static final HostedOptionKey<Boolean> RuntimeDebugChecks = new HostedOptionKey<>(false);
127127

128128
@Option(help = "Enable verification phases.")//
129-
public static final OptionKey<Boolean> VerificationPhases = new OptionKey<>(false);
129+
public static final HostedOptionKey<Boolean> VerificationPhases = new HostedOptionKey<>(false);
130130

131131
@Option(help = "Dump type control graph, a graph of dependencies between types, methods, and inspected objects.")//
132132
public static final OptionKey<Boolean> DumpTypeControlGraph = new OptionKey<>(false);

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/codegen/WebImageWasmLMNodeLowerer.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -429,40 +429,6 @@ private Instruction lowerReadReservedRegister(Register register) {
429429
}
430430
}
431431

432-
private Instruction lowerWordCast(WordCastNode n) {
433-
ValueNode input = n.getInput();
434-
Instruction value = lowerExpression(input);
435-
436-
int inputBits = util.typeForNode(input).asPrimitive().getBitCount();
437-
int outputBits = util.typeForNode(n).asPrimitive().getBitCount();
438-
439-
/*
440-
* TODO GR-42105 word types are 64-bit while objects are 32-bits. Add 32-bit architecture,
441-
* then we can probably save both the wrap and extend operations.
442-
*/
443-
if (inputBits == outputBits) {
444-
return value;
445-
} else if (inputBits == 32 && outputBits == 64) {
446-
return Unary.Op.I64ExtendI32U.create(value);
447-
} else if (inputBits == 64 && outputBits == 32) {
448-
return Unary.Op.I32Wrap64.create(value);
449-
} else {
450-
throw GraalError.unimplemented(n + ", inputBits=" + inputBits + ", outputBits=" + outputBits); // ExcludeFromJacocoGeneratedReport
451-
}
452-
}
453-
454-
private Instruction lowerFloatingWordCast(FloatingWordCastNode n) {
455-
ValueNode input = n.getInput();
456-
457-
Instruction value = lowerExpression(input);
458-
/*
459-
* TODO GR-42105 the input is a 64-bit word type, add architecture to ensure word type is 32
460-
* bit and we don't need to i32.wrap64 instruction.
461-
*/
462-
assert input.getStackKind().getBitCount() == 64 : input.getStackKind();
463-
return Unary.Op.I32Wrap64.create(value);
464-
}
465-
466432
private Instruction lowerWasmAddressBase(WasmAddressNode n) {
467433
ValueNode baseNode = n.getBase();
468434

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/codegen/WebImageWasmNodeLowerer.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Objects;
4040
import java.util.Set;
4141

42+
import com.oracle.svm.core.graal.nodes.FloatingWordCastNode;
4243
import com.oracle.svm.core.graal.nodes.ReadExceptionObjectNode;
4344
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
4445
import com.oracle.svm.core.snippets.SnippetRuntime;
@@ -1144,6 +1145,35 @@ protected Instruction lowerReadException(@SuppressWarnings("unused") ReadExcepti
11441145
return exceptionObjectVariable.getter();
11451146
}
11461147

1148+
protected Instruction lowerWordCast(WordCastNode n) {
1149+
return lowerWordCast(n, n.getInput());
1150+
}
1151+
1152+
protected Instruction lowerFloatingWordCast(FloatingWordCastNode n) {
1153+
return lowerWordCast(n, n.getInput());
1154+
}
1155+
1156+
protected Instruction lowerWordCast(ValueNode castNode, ValueNode input) {
1157+
Instruction value = lowerExpression(input);
1158+
1159+
int inputBits = util.typeForNode(input).asPrimitive().getBitCount();
1160+
int outputBits = util.typeForNode(castNode).asPrimitive().getBitCount();
1161+
1162+
/*
1163+
* TODO GR-42105 word types are 64-bit while objects are 32-bits. Add 32-bit architecture,
1164+
* then we can probably save both the wrap and extend operations.
1165+
*/
1166+
if (inputBits == outputBits) {
1167+
return value;
1168+
} else if (inputBits == 32 && outputBits == 64) {
1169+
return Unary.Op.I64ExtendI32U.create(value);
1170+
} else if (inputBits == 64 && outputBits == 32) {
1171+
return Unary.Op.I32Wrap64.create(value);
1172+
} else {
1173+
throw GraalError.unimplemented(castNode + ", inputBits=" + inputBits + ", outputBits=" + outputBits); // ExcludeFromJacocoGeneratedReport
1174+
}
1175+
}
1176+
11471177
// region Unsupported operations
11481178
private static void genUnreachable(Object comment) {
11491179
GraalError.shouldNotReachHere(String.valueOf(comment));

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/codegen/WebImageWasmGCNodeLowerer.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
3434
import com.oracle.graal.pointsto.results.StrengthenGraphs;
35+
import com.oracle.svm.core.graal.nodes.FloatingWordCastNode;
3536
import com.oracle.svm.core.graal.nodes.LoweredDeadEndNode;
3637
import com.oracle.svm.core.graal.nodes.ReadExceptionObjectNode;
3738
import com.oracle.svm.core.hub.DynamicHub;
@@ -45,6 +46,7 @@
4546
import com.oracle.svm.hosted.webimage.js.JSBody;
4647
import com.oracle.svm.hosted.webimage.js.JSBodyNode;
4748
import com.oracle.svm.hosted.webimage.js.JSBodyWithExceptionNode;
49+
import com.oracle.svm.hosted.webimage.options.WebImageOptions;
4850
import com.oracle.svm.hosted.webimage.wasm.WasmJSCounterparts;
4951
import com.oracle.svm.hosted.webimage.wasm.WebImageWasmOptions;
5052
import com.oracle.svm.hosted.webimage.wasm.ast.Instruction;
@@ -283,11 +285,14 @@ protected Instruction dispatch(ValueNode n, WasmIRWalker.Requirements reqs) {
283285
case JSBodyNode jsBody -> lowerJSBody(jsBody);
284286
case JSBodyWithExceptionNode jsBody -> lowerJSBody(jsBody);
285287
case WordCastNode wordCast -> lowerWordCast(wordCast);
288+
case FloatingWordCastNode wordCast -> lowerFloatingWordCast(wordCast);
286289
default -> {
287290
assert !isForbiddenNode(n) : reportForbiddenNode(n);
291+
if (WebImageOptions.DebugOptions.VerificationPhases.getValue()) {
292+
throw GraalError.shouldNotReachHere("Tried to lower unknown node: " + n);
293+
}
288294
// TODO GR-47009 Stop generating stub code.
289295
yield getStub(n);
290-
// throw GraalError.shouldNotReachHere("Tried to lower unknown node: " + n);
291296
}
292297
};
293298
}
@@ -1078,7 +1083,8 @@ private <T extends FixedNode & JSBody> Instruction lowerJSBody(T jsBody) {
10781083
return returnValue;
10791084
}
10801085

1081-
private Instruction lowerWordCast(WordCastNode n) {
1086+
@Override
1087+
protected Instruction lowerWordCast(WordCastNode n) {
10821088
// TODO GR-60168 Eliminate WordCastNodes completely. They are fundamentally not supportable
10831089
// under WasmGC
10841090
logError("This method should never be reached and cannot be supported.");

0 commit comments

Comments
 (0)