[clang] [llvm] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #93428)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 26 14:30:25 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-webassembly
Author: Lucile Rose Nihlen (lnihlen)
<details>
<summary>Changes</summary>
This is a re-application of #<!-- -->71540, with the hopes I can get some help from @<!-- -->pmatos and others to finish it. Right now the '../clang/test/CodeGen/WebAssembly/wasm-funcref.c' test fails with an assertion trying to cast the target("wasm.funcref") instruction to a pointer. Looking in to that further but wanted to checkpoint the code here from the first patch.
---
Patch is 40.56 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/93428.diff
40 Files Affected:
- (modified) clang/test/CodeGen/WebAssembly/builtins-table.c (+8-8)
- (modified) clang/test/CodeGen/WebAssembly/wasm-externref.c (+5-4)
- (modified) clang/test/CodeGen/WebAssembly/wasm-funcref.c (+20-20)
- (modified) clang/test/CodeGen/builtins-wasm.c (+1-1)
- (modified) llvm/include/llvm/IR/Intrinsics.h (+2)
- (modified) llvm/include/llvm/IR/IntrinsicsWebAssembly.td (+7)
- (modified) llvm/lib/CodeGen/ValueTypes.cpp (+4)
- (modified) llvm/lib/IR/Function.cpp (+12-2)
- (modified) llvm/lib/IR/Type.cpp (+6-4)
- (modified) llvm/lib/Target/WebAssembly/CMakeLists.txt (-1)
- (modified) llvm/lib/Target/WebAssembly/Utils/WasmAddressSpaces.h (-4)
- (modified) llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h (+4-6)
- (modified) llvm/lib/Target/WebAssembly/WebAssembly.h (-2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISD.def (+3)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+1-21)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h (-3)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td (+8)
- (removed) llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp (-86)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp (-2)
- (modified) llvm/test/CodeGen/WebAssembly/externref-globalget.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/externref-globalset.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll (+3-9)
- (modified) llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/externref-tableget.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/externref-tableset.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll (+2-2)
- (modified) llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll (+2-2)
- (modified) llvm/test/CodeGen/WebAssembly/funcref-call.ll (+7-3)
- (modified) llvm/test/CodeGen/WebAssembly/funcref-globalget.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/funcref-globalset.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/funcref-table_call.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/funcref-tableget.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/funcref-tableset.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/ref-null.ll (+2-2)
- (modified) llvm/test/CodeGen/WebAssembly/table-copy.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/table-fill.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/table-grow.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/table-size.ll (+1-1)
- (modified) llvm/test/CodeGen/WebAssembly/table-types.ll (+2-2)
- (modified) llvm/utils/gn/secondary/llvm/lib/Target/WebAssembly/BUILD.gn (-1)
``````````diff
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table.c b/clang/test/CodeGen/WebAssembly/builtins-table.c
index 74bb2442fe552..eeed335855e40 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table.c
@@ -7,17 +7,17 @@ static __externref_t table[0];
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
// CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT: ret ptr addrspace(10) [[TMP0]]
+// CHECK-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
+// CHECK-NEXT: ret target("wasm.externref") [[TMP0]]
//
__externref_t test_builtin_wasm_table_get(int index) {
return __builtin_wasm_table_get(table, index);
}
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]])
// CHECK-NEXT: ret void
//
void test_builtin_wasm_table_set(int index, __externref_t ref) {
@@ -35,9 +35,9 @@ int test_builtin_wasm_table_size() {
}
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// CHECK-SAME: (ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i32 [[NELEM]])
+// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @table, target("wasm.externref") [[REF]], i32 [[NELEM]])
// CHECK-NEXT: ret i32 [[TMP0]]
//
int test_builtin_wasm_table_grow(__externref_t ref, int nelem) {
@@ -45,9 +45,9 @@ int test_builtin_wasm_table_grow(__externref_t ref, int nelem) {
}
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]], i32 [[NELEM]])
+// CHECK-NEXT: call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]], i32 [[NELEM]])
// CHECK-NEXT: ret void
//
void test_builtin_wasm_table_fill(int index, __externref_t ref, int nelem) {
diff --git a/clang/test/CodeGen/WebAssembly/wasm-externref.c b/clang/test/CodeGen/WebAssembly/wasm-externref.c
index 788438bb4a86a..38f3d7289c8d4 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-externref.c
+++ b/clang/test/CodeGen/WebAssembly/wasm-externref.c
@@ -7,12 +7,13 @@ void helper(externref_t);
// CHECK-LABEL: @handle(
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[OBJ_ADDR:%.*]] = alloca ptr addrspace(10), align 1
-// CHECK-NEXT: store ptr addrspace(10) [[OBJ:%.*]], ptr [[OBJ_ADDR]], align 1
-// CHECK-NEXT: [[TMP0:%.*]] = load ptr addrspace(10), ptr [[OBJ_ADDR]], align 1
-// CHECK-NEXT: call void @helper(ptr addrspace(10) [[TMP0]])
+// CHECK-NEXT: [[OBJ_ADDR:%.*]] = alloca target("wasm.externref"), align 1
+// CHECK-NEXT: store target("wasm.externref") [[OBJ:%.*]], ptr [[OBJ_ADDR]], align 1
+// CHECK-NEXT: [[TMP0:%.*]] = load target("wasm.externref"), ptr [[OBJ_ADDR]], align 1
+// CHECK-NEXT: call void @helper(target("wasm.externref") [[TMP0]])
// CHECK-NEXT: ret void
//
void handle(externref_t obj) {
helper(obj);
}
+
diff --git a/clang/test/CodeGen/WebAssembly/wasm-funcref.c b/clang/test/CodeGen/WebAssembly/wasm-funcref.c
index f01af0db321dd..fa45d87cda74c 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-funcref.c
+++ b/clang/test/CodeGen/WebAssembly/wasm-funcref.c
@@ -8,8 +8,8 @@ typedef int (*fn_t)(int);
// Null funcref builtin call
// CHECK-LABEL: @get_null(
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
-// CHECK-NEXT: ret ptr addrspace(20) [[TMP0]]
+// CHECK-NEXT: [[TMP0:%.*]] = call target("wasm.funcref") @llvm.wasm.ref.null.func()
+// CHECK-NEXT: ret target("wasm.funcref") [[TMP0]]
//
funcref_t get_null() {
return __builtin_wasm_ref_null_func();
@@ -19,8 +19,8 @@ funcref_t get_null() {
// default return value for builtin is a funcref with function type () -> ().
// CHECK-LABEL: @get_null_ii(
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
-// CHECK-NEXT: ret ptr addrspace(20) [[TMP0]]
+// CHECK-NEXT: [[TMP0:%.*]] = call target("wasm.funcref") @llvm.wasm.ref.null.func()
+// CHECK-NEXT: ret target("wasm.funcref") [[TMP0]]
//
fn_funcref_t get_null_ii() {
return (fn_funcref_t) __builtin_wasm_ref_null_func();
@@ -29,10 +29,10 @@ fn_funcref_t get_null_ii() {
// Identity function for funcref.
// CHECK-LABEL: @identity(
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
-// CHECK-NEXT: store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
-// CHECK-NEXT: [[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
-// CHECK-NEXT: ret ptr addrspace(20) [[TMP0]]
+// CHECK-NEXT: [[FN_ADDR:%.*]] = alloca target("wasm.funcref"), align 4
+// CHECK-NEXT: store target("wasm.funcref") [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT: [[TMP0:%.*]] = load target("wasm.funcref"), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT: ret target("wasm.funcref") [[TMP0]]
//
funcref_t identity(funcref_t fn) {
return fn;
@@ -43,10 +43,10 @@ void helper(funcref_t);
// Pass funcref ref as an argument to a helper function.
// CHECK-LABEL: @handle(
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
-// CHECK-NEXT: store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
-// CHECK-NEXT: [[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
-// CHECK-NEXT: call void @helper(ptr addrspace(20) noundef [[TMP0]])
+// CHECK-NEXT: [[FN_ADDR:%.*]] = alloca target("wasm.funcref"), align 4
+// CHECK-NEXT: store target("wasm.funcref") [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT: [[TMP0:%.*]] = load target("wasm.funcref"), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT: call void @helper(target("wasm.funcref") noundef [[TMP0]])
// CHECK-NEXT: ret i32 0
//
int handle(funcref_t fn) {
@@ -60,8 +60,8 @@ int handle(funcref_t fn) {
// CHECK-NEXT: [[FNPTR_ADDR:%.*]] = alloca ptr, align 4
// CHECK-NEXT: store ptr [[FNPTR:%.*]], ptr [[FNPTR_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[FNPTR_ADDR]], align 4
-// CHECK-NEXT: [[TMP1:%.*]] = addrspacecast ptr [[TMP0]] to ptr addrspace(20)
-// CHECK-NEXT: ret ptr addrspace(20) [[TMP1]]
+// CHECK-NEXT: [[TMP1:%.*]] = addrspacecast ptr [[TMP0]] to target("wasm.funcref")
+// CHECK-NEXT: ret target("wasm.funcref") [[TMP1]]
//
fn_funcref_t get_ref(fn_t fnptr) {
return (fn_funcref_t) fnptr;
@@ -70,13 +70,13 @@ fn_funcref_t get_ref(fn_t fnptr) {
// Call funcref
// CHECK-LABEL: @call_fn(
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[REF_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT: [[REF_ADDR:%.*]] = alloca target("wasm.funcref"), align 4
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
-// CHECK-NEXT: store ptr addrspace(20) [[REF:%.*]], ptr [[REF_ADDR]], align 4
+// CHECK-NEXT: store target("wasm.funcref") [[REF:%.*]], ptr [[REF_ADDR]], align 4
// CHECK-NEXT: store i32 [[X:%.*]], ptr [[X_ADDR]], align 4
-// CHECK-NEXT: [[TMP0:%.*]] = load ptr addrspace(20), ptr [[REF_ADDR]], align 4
+// CHECK-NEXT: [[TMP0:%.*]] = load target("wasm.funcref"), ptr [[REF_ADDR]], align 4
// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[X_ADDR]], align 4
-// CHECK-NEXT: [[CALL:%.*]] = call addrspace(20) i32 [[TMP0]](i32 noundef [[TMP1]])
+// CHECK-NEXT: [[CALL:%.*]] = call i32 [[TMP0]](i32 noundef [[TMP1]])
// CHECK-NEXT: ret i32 [[CALL]]
//
int call_fn(fn_funcref_t ref, int x) {
@@ -91,8 +91,8 @@ typedef fn_funcref_t (*builtin_refnull_t)();
// CHECK-NEXT: [[REFNULL_ADDR:%.*]] = alloca ptr, align 4
// CHECK-NEXT: store ptr [[REFNULL:%.*]], ptr [[REFNULL_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[REFNULL_ADDR]], align 4
-// CHECK-NEXT: [[CALL:%.*]] = call ptr addrspace(20) [[TMP0]]()
-// CHECK-NEXT: ret ptr addrspace(20) [[CALL]]
+// CHECK-NEXT: [[CALL:%.*]] = call target("wasm.funcref") [[TMP0]]()
+// CHECK-NEXT: ret target("wasm.funcref") [[CALL]]
//
fn_funcref_t get_null_fptr(builtin_refnull_t refnull) {
return refnull();
diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c
index 93a6ab06081c9..4c6fc1e6b6bb3 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -827,6 +827,6 @@ float extract_lane_f16x8(f16x8 a, int i) {
}
__externref_t externref_null() {
return __builtin_wasm_ref_null_extern();
- // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern()
+ // WEBASSEMBLY: tail call target("wasm.externref") @llvm.wasm.ref.null.extern()
// WEBASSEMBLY-NEXT: ret
}
diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h
index f79df522dc805..88b28eb362087 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -144,6 +144,8 @@ namespace Intrinsic {
AMX,
PPCQuad,
AArch64Svcount,
+ WasmExternref,
+ WasmFuncref,
} Kind;
union {
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index 237f268784bb0..7384a0d8c726e 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -38,6 +38,13 @@ def int_wasm_ref_is_null_func :
DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_funcref_ty],
[IntrNoMem], "llvm.wasm.ref.is_null.func">;
+//===----------------------------------------------------------------------===//
+// funcref target ext type -> pointer intrinsic
+//===----------------------------------------------------------------------===//
+def int_wasm_funcref_to_ptr:
+ DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_funcref_ty],
+ [IntrNoMem], "llvm.wasm.funcref.to_ptr">;
+
//===----------------------------------------------------------------------===//
// Table intrinsics
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index 3d5c58d282da5..d2d6696f03dbb 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -604,6 +604,10 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
TargetExtType *TargetExtTy = cast<TargetExtType>(Ty);
if (TargetExtTy->getName() == "aarch64.svcount")
return MVT(MVT::aarch64svcount);
+ else if (TargetExtTy->getName() == "wasm.externref")
+ return MVT(MVT::externref);
+ else if (TargetExtTy->getName() == "wasm.funcref")
+ return MVT(MVT::funcref);
else if (TargetExtTy->getName().starts_with("spirv."))
return MVT(MVT::spirvbuiltin);
if (HandleUnknown)
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index bd06ff82a15a5..40964c7a33eaa 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -1209,10 +1209,10 @@ static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
DecodeIITType(NextElt, Infos, Info, OutputTable);
return;
case IIT_EXTERNREF:
- OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
+ OutputTable.push_back(IITDescriptor::get(IITDescriptor::WasmExternref, 0));
return;
case IIT_FUNCREF:
- OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
+ OutputTable.push_back(IITDescriptor::get(IITDescriptor::WasmFuncref, 0));
return;
case IIT_PTR:
OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
@@ -1365,6 +1365,10 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
case IITDescriptor::PPCQuad: return Type::getPPC_FP128Ty(Context);
case IITDescriptor::AArch64Svcount:
return TargetExtType::get(Context, "aarch64.svcount");
+ case IITDescriptor::WasmExternref:
+ return TargetExtType::get(Context, "wasm.externref");
+ case IITDescriptor::WasmFuncref:
+ return TargetExtType::get(Context, "wasm.funcref");
case IITDescriptor::Integer:
return IntegerType::get(Context, D.Integer_Width);
@@ -1550,6 +1554,12 @@ static bool matchIntrinsicType(
case IITDescriptor::AArch64Svcount:
return !isa<TargetExtType>(Ty) ||
cast<TargetExtType>(Ty)->getName() != "aarch64.svcount";
+ case IITDescriptor::WasmExternref:
+ return !isa<TargetExtType>(Ty) ||
+ cast<TargetExtType>(Ty)->getName() != "wasm.externref";
+ case IITDescriptor::WasmFuncref:
+ return !isa<TargetExtType>(Ty) ||
+ cast<TargetExtType>(Ty)->getName() != "wasm.funcref";
case IITDescriptor::Vector: {
VectorType *VT = dyn_cast<VectorType>(Ty);
return !VT || VT->getElementCount() != D.Vector_Width ||
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 5c61ad9f000b0..3fdc4310a89fd 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -260,14 +260,12 @@ IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {
}
Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
- // opaque pointer in addrspace(10)
- static PointerType *Ty = PointerType::get(C, 10);
+ static TargetExtType *Ty = TargetExtType::get(C, "wasm.externref", {}, {});
return Ty;
}
Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
- // opaque pointer in addrspace(20)
- static PointerType *Ty = PointerType::get(C, 20);
+ static TargetExtType *Ty = TargetExtType::get(C, "wasm.funcref", {}, {});
return Ty;
}
@@ -845,6 +843,10 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
TargetExtType::HasZeroInit);
+ // Opaque types in the WebAssembly name space.
+ if (Name.starts_with("wasm."))
+ return TargetTypeInfo(PointerType::getUnqual(C), TargetExtType::HasZeroInit, TargetExtType::CanBeGlobal);
+
return TargetTypeInfo(Type::getVoidTy(C));
}
diff --git a/llvm/lib/Target/WebAssembly/CMakeLists.txt b/llvm/lib/Target/WebAssembly/CMakeLists.txt
index 1e83cbeac50d6..b5f9aeb8aa0ba 100644
--- a/llvm/lib/Target/WebAssembly/CMakeLists.txt
+++ b/llvm/lib/Target/WebAssembly/CMakeLists.txt
@@ -36,7 +36,6 @@ add_llvm_target(WebAssemblyCodeGen
WebAssemblyInstrInfo.cpp
WebAssemblyLowerBrUnless.cpp
WebAssemblyLowerEmscriptenEHSjLj.cpp
- WebAssemblyLowerRefTypesIntPtrConv.cpp
WebAssemblyMachineFunctionInfo.cpp
WebAssemblyMCInstLower.cpp
WebAssemblyMCLowerPrePass.cpp
diff --git a/llvm/lib/Target/WebAssembly/Utils/WasmAddressSpaces.h b/llvm/lib/Target/WebAssembly/Utils/WasmAddressSpaces.h
index 2239badca69c3..72853d479ed26 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WasmAddressSpaces.h
+++ b/llvm/lib/Target/WebAssembly/Utils/WasmAddressSpaces.h
@@ -25,10 +25,6 @@ enum WasmAddressSpace : unsigned {
// to these pointers are lowered to global.get / global.set or local.get /
// local.set, as appropriate.
WASM_ADDRESS_SPACE_VAR = 1,
- // A non-integral address space for externref values
- WASM_ADDRESS_SPACE_EXTERNREF = 10,
- // A non-integral address space for funcref values
- WASM_ADDRESS_SPACE_FUNCREF = 20,
};
inline bool isDefaultAddressSpace(unsigned AS) {
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
index 87660947e7de1..8e7ef92e8c677 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -28,16 +28,14 @@ namespace WebAssembly {
/// Return true if this is a WebAssembly Externref Type.
inline bool isWebAssemblyExternrefType(const Type *Ty) {
- return Ty->isPointerTy() &&
- Ty->getPointerAddressSpace() ==
- WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
+ const TargetExtType *TargetTy = dyn_cast<TargetExtType>(Ty);
+ return TargetTy && TargetTy->getName() == "wasm.externref";
}
/// Return true if this is a WebAssembly Funcref Type.
inline bool isWebAssemblyFuncrefType(const Type *Ty) {
- return Ty->isPointerTy() &&
- Ty->getPointerAddressSpace() ==
- WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
+ const TargetExtType *TargetTy = dyn_cast<TargetExtType>(Ty);
+ return TargetTy && TargetTy->getName() == "wasm.funcref";
}
/// Return true if this is a WebAssembly Reference Type.
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.h b/llvm/lib/Target/WebAssembly/WebAssembly.h
index 7fc8546248f16..6c84bc979ae4e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.h
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.h
@@ -29,7 +29,6 @@ ModulePass *createWebAssemblyLowerEmscriptenEHSjLj();
ModulePass *createWebAssemblyAddMissingPrototypes();
ModulePass *createWebAssemblyFixFunctionBitcasts();
FunctionPass *createWebAssemblyOptimizeReturned();
-FunctionPass *createWebAssemblyLowerRefTypesIntPtrConv();
FunctionPass *createWebAssemblyRefTypeMem2Local();
// ISel and immediate followup passes.
@@ -76,7 +75,6 @@ void initializeWebAssemblyFixIrreducibleControlFlowPass(PassRegistry &);
void initializeWebAssemblyLateEHPreparePass(PassRegistry &);
void initializeWebAssemblyLowerBrUnlessPass(PassRegistry &);
void initializeWebAssemblyLowerEmscriptenEHSjLjPass(PassRegistry &);
-void initializeWebAssemblyLowerRefTypesIntPtrConvPass(PassRegistry &);
void initializeWebAssemblyMCLowerPrePassPass(PassRegistry &);
void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &);
void initializeWebAssemblyNullifyDebugValueListsPass(PassRegistry &);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISD.def b/llvm/lib/Target/WebAssembly/WebAssemblyISD.def
index b8954f4693f0a..fb37b79781715 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISD.def
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISD.def
@@ -45,6 +45,9 @@ HANDLE_NODETYPE(DEMOTE_ZERO)
HANDLE_NODETYPE(MEMORY_COPY)
HANDLE_NODETYPE(MEMORY_FILL)
+// Pointer conversion intrinsic for funcref
+HANDLE_NODETYPE(FUNCREF_TO_PTR)
+
// Memory intrinsics
HANDLE_MEM_NODETYPE(GLOBAL_GET)
HANDLE_MEM_NODETYPE(GLOBAL_SET)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 518b6932a0c87..b640467cbc6f2 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -365,24 +365,6 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
setMinimumJumpTableEntries(2);
}
-MVT WebAssemblyTargetLowering::getPointerTy(const DataLayout &DL,
- uint32_t AS) const {
- if (AS == WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF)
- return MVT::externref;
- if (AS == WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF)
- return MVT::funcref;
- return TargetLowering::getPointerTy(DL, AS);
-}
-
-MVT WebAssemblyTargetLowering::getPointerMemTy(const DataLayout &DL,
- uint32_t AS) const {
- if (AS == WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF)
- return MVT::externref;
- if (AS == WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF)
- return MVT::funcref;
- return TargetLowering::getPoin...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/93428
More information about the llvm-commits
mailing list