[clang][WebAssembly] Implement support for table types and builtins
authorPaulo Matos <pmatos@igalia.com>
Sat, 10 Jun 2023 13:51:05 +0000 (15:51 +0200)
committerPaulo Matos <pmatos@igalia.com>
Sat, 10 Jun 2023 13:53:13 +0000 (15:53 +0200)
commit55aeb23fe0084d930ecd7335092d712bd71694c7
tree94a886c9df610bdaf043afeb959e8acd74fad5fa
parent5b657f50b8e8dc5836fb80e566ca7569fd04c26f
[clang][WebAssembly] Implement support for table types and builtins

This commit implements support for WebAssembly table types and
respective builtins. Table tables are WebAssembly objects to store
reference types. They have a large amount of semantic restrictions
including, but not limited to, only being allowed to be declared
at the top-level as static arrays of zero-length. Not being arguments
or result of functions, not being stored ot memory, etc.

This commit introduces the __attribute__((wasm_table)) to attach to
arrays of WebAssembly reference types. And the following builtins to
manage tables:

* ref   __builtin_wasm_table_get(table, idx)
* void  __builtin_wasm_table_set(table, idx, ref)
* uint  __builtin_wasm_table_size(table)
* uint  __builtin_wasm_table_grow(table, ref, uint)
* void  __builtin_wasm_table_fill(table, idx, ref, uint)
* void  __builtin_wasm_table_copy(table, table, uint, uint, uint)

This commit also enables reference-types feature at bleeding-edge.

This is joint work with Alex Bradbury (@asb).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D139010
31 files changed:
clang/docs/LanguageExtensions.rst
clang/include/clang/AST/Type.h
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/Type.cpp
clang/lib/Basic/Targets/WebAssembly.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/WebAssembly/builtins-table.c [new file with mode: 0644]
clang/test/Sema/builtins-wasm.c [new file with mode: 0644]
clang/test/Sema/wasm-refs-and-table-ped.c [new file with mode: 0644]
clang/test/Sema/wasm-refs-and-tables.c [new file with mode: 0644]
clang/test/Sema/wasm-refs.c [deleted file]
clang/test/SemaCXX/wasm-refs-and-tables.cpp [new file with mode: 0644]
clang/test/SemaCXX/wasm-refs.cpp [deleted file]
llvm/include/llvm/CodeGen/WasmAddressSpaces.h [new file with mode: 0644]
llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp