Skip to content

Commit 42d079e

Browse files
authored
[WebAssembly,MC] Add ref.test_func handling to AsmParser (#139642)
This will allow us to eliminate the hand-coded webassembly here: https://github.com/python/cpython/blob/main/Python/emscripten_trampoline.c#L138
1 parent bdf7812 commit 42d079e

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
669669
if (parseFunctionTableOperand(&FunctionTable))
670670
return true;
671671
ExpectFuncType = true;
672+
} else if (Name == "ref.test") {
673+
// When we get support for wasm-gc types, this should become
674+
// ExpectRefType.
675+
ExpectFuncType = true;
672676
}
673677

674678
// Returns true if the next tokens are a catch clause

llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ multiclass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
3636
Requires<[HasReferenceTypes]>;
3737
}
3838

39+
defm REF_TEST_FUNCREF :
40+
I<(outs I32: $res),
41+
(ins TypeIndex:$type, FUNCREF: $ref),
42+
(outs),
43+
(ins TypeIndex:$type),
44+
[],
45+
"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
46+
3947
defm "" : REF_I<FUNCREF, funcref, "func">;
4048
defm "" : REF_I<EXTERNREF, externref, "extern">;
4149
defm "" : REF_I<EXNREF, exnref, "exn">;

llvm/test/MC/WebAssembly/reference-types.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ ref_null_test:
2727
drop
2828
end_function
2929

30+
# CHECK-LABEL: ref_test_test:
31+
# CHECK: ref.null_func # encoding: [0xd0,0x70]
32+
# CHECK: ref.test () -> () # encoding: [0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
33+
# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind: fixup_uleb128_i32
34+
# CHECK: ref.null_func # encoding: [0xd0,0x70]
35+
# CHECK: ref.test () -> (i32) # encoding: [0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
36+
# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind: fixup_uleb128_i32
37+
ref_test_test:
38+
.functype ref_test_test () -> (i32, i32)
39+
ref.null_func
40+
ref.test () -> ()
41+
ref.null_func
42+
ref.test () -> (i32)
43+
end_function
44+
3045
# CHECK-LABEL: ref_sig_test_funcref:
3146
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
3247
ref_sig_test_funcref:

0 commit comments

Comments
 (0)