|
79 | 79 | import com.oracle.svm.webimage.wasmgc.WasmGCJSConversion;
|
80 | 80 |
|
81 | 81 | import jdk.graal.compiler.core.common.type.AbstractObjectStamp;
|
| 82 | +import jdk.graal.compiler.core.common.type.AbstractPointerStamp; |
82 | 83 | import jdk.graal.compiler.core.common.type.PrimitiveStamp;
|
83 | 84 | import jdk.graal.compiler.core.common.type.Stamp;
|
84 | 85 | import jdk.graal.compiler.core.common.type.TypeReference;
|
@@ -242,6 +243,37 @@ protected Instruction lowerReturn(ReturnNode returnNode) {
|
242 | 243 | return new Instruction.Return(result);
|
243 | 244 | }
|
244 | 245 |
|
| 246 | + @Override |
| 247 | + protected Instruction lowerExpression(ValueNode n, WasmIRWalker.Requirements reqs) { |
| 248 | + Instruction inst = super.lowerExpression(n, reqs); |
| 249 | + |
| 250 | + /* |
| 251 | + * Produce a constant null value for always-null stamps. |
| 252 | + * |
| 253 | + * Always null stamps are a bit of a special case because they often don't have concrete |
| 254 | + * type information, which is required in WasmGC because even null-constant have a static |
| 255 | + * type. For that reason, the actual instruction are emitted as a top-level instruction and |
| 256 | + * dropped (since it may have a side effect) and we simply return a "ref.null none", which |
| 257 | + * represents the bottom type and thus satisfies all subtype checks, at all usages. |
| 258 | + */ |
| 259 | + if (n.stamp(NodeView.DEFAULT) instanceof AbstractPointerStamp pointerStamp && pointerStamp.alwaysNull()) { |
| 260 | + if (!(inst instanceof Instruction.LocalGet)) { |
| 261 | + /* |
| 262 | + * We can't just not emit the instruction, it may have side effects, so we just emit |
| 263 | + * it in the same block and ignore its output (which is guaranteed to be null). |
| 264 | + * |
| 265 | + * If the node's value was stored in a variable and would be just loaded here, we |
| 266 | + * can omit this, as there are no side-effects. |
| 267 | + */ |
| 268 | + masm.genInst(new Instruction.Drop(inst)); |
| 269 | + } |
| 270 | + |
| 271 | + return new Instruction.RefNull(WasmRefType.NONE); |
| 272 | + } else { |
| 273 | + return inst; |
| 274 | + } |
| 275 | + } |
| 276 | + |
245 | 277 | protected Instruction lowerUnwind(UnwindNode n) {
|
246 | 278 | return new Instruction.Call(masm().getKnownIds().throwTemplate.requestFunctionId(), lowerExpression(n.exception()));
|
247 | 279 | }
|
|
0 commit comments