[clang] [llvm] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #93428)

2024-05-26 Thread Paulo Matos via cfe-commits

pmatos wrote:

> 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.

I will keep this bug in mind but I am taking a leave at the moment until June 
3rd. I will take a look at it then.

https://github.com/llvm/llvm-project/pull/93428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-17 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71540

>From 31adeded0d1767e1ce43fbfcba5fe72c4e34121d Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Tue, 7 Nov 2023 08:28:36 +0100
Subject: [PATCH 1/4] [WebAssembly] Refactor Wasm Reference Types as
 TargetExtType

Originally reference types were designed as pointers to different
address spaces.

More recently TargetExtType were added to LLVM IR making it easier
to represent reference types. This refactoring gets rid of wasm
reftypes as pointers and just uses target extension types to
represent them.
---
 .../test/CodeGen/WebAssembly/builtins-table.c | 16 ++--
 .../test/CodeGen/WebAssembly/wasm-externref.c |  8 +-
 clang/test/CodeGen/builtins-wasm.c|  2 +-
 llvm/include/llvm/IR/Intrinsics.h |  1 +
 llvm/include/llvm/IR/Type.h   |  2 +
 llvm/lib/CodeGen/ValueTypes.cpp   |  2 +
 llvm/lib/IR/Function.cpp  |  8 +-
 llvm/lib/IR/Type.cpp  |  7 +-
 llvm/lib/Target/WebAssembly/CMakeLists.txt|  1 -
 .../WebAssembly/Utils/WasmAddressSpaces.h |  2 -
 .../Utils/WebAssemblyTypeUtilities.h  |  5 +-
 llvm/lib/Target/WebAssembly/WebAssembly.h |  2 -
 .../WebAssembly/WebAssemblyISelLowering.cpp   |  4 -
 .../WebAssemblyLowerRefTypesIntPtrConv.cpp| 86 ---
 .../WebAssembly/WebAssemblyTargetMachine.cpp  |  2 -
 .../WebAssembly/externref-globalget.ll|  2 +-
 .../WebAssembly/externref-globalset.ll|  2 +-
 .../CodeGen/WebAssembly/externref-inttoptr.ll | 12 +--
 .../CodeGen/WebAssembly/externref-ptrtoint.ll | 11 +--
 .../CodeGen/WebAssembly/externref-tableget.ll |  2 +-
 .../CodeGen/WebAssembly/externref-tableset.ll |  2 +-
 .../WebAssembly/externref-unsized-load.ll |  4 +-
 .../WebAssembly/externref-unsized-store.ll|  4 +-
 llvm/test/CodeGen/WebAssembly/ref-null.ll |  2 +-
 llvm/test/CodeGen/WebAssembly/table-copy.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-fill.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-grow.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-size.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-types.ll  |  2 +-
 .../llvm/lib/Target/WebAssembly/BUILD.gn  |  1 -
 30 files changed, 51 insertions(+), 149 deletions(-)
 delete mode 100644 
llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

diff --git a/clang/test/CodeGen/WebAssembly/builtins-table.c 
b/clang/test/CodeGen/WebAssembly/builtins-table.c
index 74bb2442fe552fc..eeed335855e4089 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: 

[clang] [llvm] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-07 Thread Paulo Matos via cfe-commits

pmatos wrote:

> Very cool! LGTM so far. It's really nice that we can delete that entire pass 
> out of the backend. Where can I read more about these new target extension 
> types?

There's not a lot but there's something here:
https://llvm.org/docs/LangRef.html#target-extension-type

and of course, the api:
https://llvm.org/doxygen/classllvm_1_1TargetExtType.html

https://github.com/llvm/llvm-project/pull/71540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[polly] [llvm] [mlir] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-07 Thread Paulo Matos via cfe-commits

pmatos wrote:

> Please also update existing uses in `lldb`. Buildbot failure: 
> https://lab.llvm.org/buildbot/#/builders/68/builds/63101

Please see https://github.com/llvm/llvm-project/pull/71561

https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [mlir] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos closed https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [polly] [llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71029

>From 0c939b18d795e2729dde8d5e0a4ee8fa6be145c7 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Fri, 3 Nov 2023 12:03:07 +0100
Subject: [PATCH] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 13 ++--
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 53 
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/Type.h   |  5 --
 .../llvm/ProfileData/InstrProfData.inc| 12 ++--
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  8 +--
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 +--
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   | 12 ++--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  | 10 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 12 ++--
 llvm/lib/IR/Type.cpp  |  4 --
 .../Target/AArch64/AArch64ISelLowering.cpp|  9 +--
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  6 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  3 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  3 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 22 +++
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  5 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  6 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 +--
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 +--
 .../Instrumentation/GCOVProfiling.cpp |  6 +-
 .../Instrumentation/InstrProfiling.cpp| 10 ++--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  6 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  | 11 ++--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 27 +
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 60 +++
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 18 +++---
 .../OpenACC/OpenACCToLLVMIRTranslation.cpp|  6 +-
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  2 +-
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  2 +-
 polly/lib/Analysis/ScopDetection.cpp  |  2 +-
 63 files changed, 229 insertions(+), 214 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..de4ee68c0da1e79 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+llvm::PointerType::getUnqual(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = 

[clang] [llvm] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71540

>From dfe73198afa1e18fc37b5d21a6a8e6e1e3261f88 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Tue, 7 Nov 2023 08:28:36 +0100
Subject: [PATCH 1/2] [WebAssembly] Refactor Wasm Reference Types as
 TargetExtType

Originally reference types were designed as pointers to different
address spaces.

More recently TargetExtType were added to LLVM IR making it easier
to represent reference types. This refactoring gets rid of wasm
reftypes as pointers and just uses target extension types to
represent them.
---
 .../test/CodeGen/WebAssembly/builtins-table.c | 16 ++--
 .../test/CodeGen/WebAssembly/wasm-externref.c |  8 +-
 clang/test/CodeGen/builtins-wasm.c|  2 +-
 llvm/include/llvm/IR/Intrinsics.h |  1 +
 llvm/include/llvm/IR/Type.h   | 10 ++-
 llvm/lib/CodeGen/ValueTypes.cpp   |  2 +
 llvm/lib/IR/Function.cpp  |  8 +-
 llvm/lib/IR/Type.cpp  |  7 +-
 llvm/lib/Target/WebAssembly/CMakeLists.txt|  1 -
 .../WebAssembly/Utils/WasmAddressSpaces.h |  2 -
 .../Utils/WebAssemblyTypeUtilities.h  |  5 +-
 llvm/lib/Target/WebAssembly/WebAssembly.h |  2 -
 .../WebAssembly/WebAssemblyISelLowering.cpp   |  4 -
 .../WebAssemblyLowerRefTypesIntPtrConv.cpp| 86 ---
 .../WebAssembly/WebAssemblyTargetMachine.cpp  |  2 -
 .../WebAssembly/externref-globalget.ll|  2 +-
 .../WebAssembly/externref-globalset.ll|  2 +-
 .../CodeGen/WebAssembly/externref-inttoptr.ll | 12 +--
 .../CodeGen/WebAssembly/externref-ptrtoint.ll | 11 +--
 .../CodeGen/WebAssembly/externref-tableget.ll |  2 +-
 .../CodeGen/WebAssembly/externref-tableset.ll |  2 +-
 .../WebAssembly/externref-unsized-load.ll |  4 +-
 .../WebAssembly/externref-unsized-store.ll|  4 +-
 llvm/test/CodeGen/WebAssembly/ref-null.ll |  2 +-
 llvm/test/CodeGen/WebAssembly/table-copy.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-fill.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-grow.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-size.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-types.ll  |  2 +-
 .../llvm/lib/Target/WebAssembly/BUILD.gn  |  1 -
 30 files changed, 57 insertions(+), 151 deletions(-)
 delete mode 100644 
llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

diff --git a/clang/test/CodeGen/WebAssembly/builtins-table.c 
b/clang/test/CodeGen/WebAssembly/builtins-table.c
index 74bb2442fe552fc..eeed335855e4089 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: 

[clang] [llvm] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

2023-11-07 Thread Paulo Matos via cfe-commits

pmatos wrote:

Closing this as #71540 will implement the refactoring I mentioned earlier. 
Thank you for everyone's time commenting on this PR.

https://github.com/llvm/llvm-project/pull/71069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos closed https://github.com/llvm/llvm-project/pull/71069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos edited https://github.com/llvm/llvm-project/pull/71540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos edited https://github.com/llvm/llvm-project/pull/71540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-07 Thread Paulo Matos via cfe-commits

pmatos wrote:

The current patch implements successfully all the refactoring needed for 
externref. I will work on funcref next.

This refactoring was triggered by the discussion at #71069 .
Also the issue #71388 is currently blocking this. I include a workaround in the 
current patch.

https://github.com/llvm/llvm-project/pull/71540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos created 
https://github.com/llvm/llvm-project/pull/71540

Originally reference types were designed as pointers to different address 
spaces.

More recently TargetExtType were added to LLVM IR making it easier to represent 
reference types. This refactoring gets rid of wasm reftypes as pointers and 
just uses target extension types to represent them.

>From dfe73198afa1e18fc37b5d21a6a8e6e1e3261f88 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Tue, 7 Nov 2023 08:28:36 +0100
Subject: [PATCH] [WebAssembly] Refactor Wasm Reference Types as TargetExtType

Originally reference types were designed as pointers to different
address spaces.

More recently TargetExtType were added to LLVM IR making it easier
to represent reference types. This refactoring gets rid of wasm
reftypes as pointers and just uses target extension types to
represent them.
---
 .../test/CodeGen/WebAssembly/builtins-table.c | 16 ++--
 .../test/CodeGen/WebAssembly/wasm-externref.c |  8 +-
 clang/test/CodeGen/builtins-wasm.c|  2 +-
 llvm/include/llvm/IR/Intrinsics.h |  1 +
 llvm/include/llvm/IR/Type.h   | 10 ++-
 llvm/lib/CodeGen/ValueTypes.cpp   |  2 +
 llvm/lib/IR/Function.cpp  |  8 +-
 llvm/lib/IR/Type.cpp  |  7 +-
 llvm/lib/Target/WebAssembly/CMakeLists.txt|  1 -
 .../WebAssembly/Utils/WasmAddressSpaces.h |  2 -
 .../Utils/WebAssemblyTypeUtilities.h  |  5 +-
 llvm/lib/Target/WebAssembly/WebAssembly.h |  2 -
 .../WebAssembly/WebAssemblyISelLowering.cpp   |  4 -
 .../WebAssemblyLowerRefTypesIntPtrConv.cpp| 86 ---
 .../WebAssembly/WebAssemblyTargetMachine.cpp  |  2 -
 .../WebAssembly/externref-globalget.ll|  2 +-
 .../WebAssembly/externref-globalset.ll|  2 +-
 .../CodeGen/WebAssembly/externref-inttoptr.ll | 12 +--
 .../CodeGen/WebAssembly/externref-ptrtoint.ll | 11 +--
 .../CodeGen/WebAssembly/externref-tableget.ll |  2 +-
 .../CodeGen/WebAssembly/externref-tableset.ll |  2 +-
 .../WebAssembly/externref-unsized-load.ll |  4 +-
 .../WebAssembly/externref-unsized-store.ll|  4 +-
 llvm/test/CodeGen/WebAssembly/ref-null.ll |  2 +-
 llvm/test/CodeGen/WebAssembly/table-copy.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-fill.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-grow.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-size.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-types.ll  |  2 +-
 .../llvm/lib/Target/WebAssembly/BUILD.gn  |  1 -
 30 files changed, 57 insertions(+), 151 deletions(-)
 delete mode 100644 
llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

diff --git a/clang/test/CodeGen/WebAssembly/builtins-table.c 
b/clang/test/CodeGen/WebAssembly/builtins-table.c
index 74bb2442fe552fc..eeed335855e4089 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 

[clang] [polly] [llvm] [mlir] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-07 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71029

>From fe3ed6bcc6eface6e7bfa3e9b043f8287dd129b0 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Fri, 3 Nov 2023 12:03:07 +0100
Subject: [PATCH 1/4] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 13 +--
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 53 ++--
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/Type.h   |  5 --
 .../llvm/ProfileData/InstrProfData.inc| 12 +--
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  8 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 +-
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   | 12 +--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  | 10 +--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 85 ++-
 llvm/lib/IR/Type.cpp  |  4 -
 .../Target/AArch64/AArch64ISelLowering.cpp|  9 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  6 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  3 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  3 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 22 ++---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  5 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  6 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 +-
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 +-
 .../Instrumentation/GCOVProfiling.cpp |  6 +-
 .../Instrumentation/InstrProfiling.cpp| 10 +--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  6 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  | 11 +--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 27 +++---
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 60 +++--
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 18 ++--
 polly/lib/Analysis/ScopDetection.cpp  |  2 +-
 60 files changed, 281 insertions(+), 225 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..de4ee68c0da1e79 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+llvm::PointerType::getUnqual(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext()),
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+

[llvm] [polly] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71029

>From fe3ed6bcc6eface6e7bfa3e9b043f8287dd129b0 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Fri, 3 Nov 2023 12:03:07 +0100
Subject: [PATCH 1/3] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 13 +--
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 53 ++--
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/Type.h   |  5 --
 .../llvm/ProfileData/InstrProfData.inc| 12 +--
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  8 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 +-
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   | 12 +--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  | 10 +--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 85 ++-
 llvm/lib/IR/Type.cpp  |  4 -
 .../Target/AArch64/AArch64ISelLowering.cpp|  9 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  6 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  3 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  3 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 22 ++---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  5 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  6 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 +-
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 +-
 .../Instrumentation/GCOVProfiling.cpp |  6 +-
 .../Instrumentation/InstrProfiling.cpp| 10 +--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  6 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  | 11 +--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 27 +++---
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 60 +++--
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 18 ++--
 polly/lib/Analysis/ScopDetection.cpp  |  2 +-
 60 files changed, 281 insertions(+), 225 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..de4ee68c0da1e79 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+llvm::PointerType::getUnqual(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext()),
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+

[llvm] [polly] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71029

>From fe3ed6bcc6eface6e7bfa3e9b043f8287dd129b0 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Fri, 3 Nov 2023 12:03:07 +0100
Subject: [PATCH 1/2] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 13 +--
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 53 ++--
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/Type.h   |  5 --
 .../llvm/ProfileData/InstrProfData.inc| 12 +--
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  8 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 +-
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   | 12 +--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  | 10 +--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 85 ++-
 llvm/lib/IR/Type.cpp  |  4 -
 .../Target/AArch64/AArch64ISelLowering.cpp|  9 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  6 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  3 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  3 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 22 ++---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  5 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  6 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 +-
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 +-
 .../Instrumentation/GCOVProfiling.cpp |  6 +-
 .../Instrumentation/InstrProfiling.cpp| 10 +--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  6 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  | 11 +--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 27 +++---
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 60 +++--
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 18 ++--
 polly/lib/Analysis/ScopDetection.cpp  |  2 +-
 60 files changed, 281 insertions(+), 225 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..de4ee68c0da1e79 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+llvm::PointerType::getUnqual(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext()),
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+

[llvm] [polly] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71029

>From fe3ed6bcc6eface6e7bfa3e9b043f8287dd129b0 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Fri, 3 Nov 2023 12:03:07 +0100
Subject: [PATCH] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 13 +--
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 53 ++--
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/Type.h   |  5 --
 .../llvm/ProfileData/InstrProfData.inc| 12 +--
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  8 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 +-
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   | 12 +--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  | 10 +--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 85 ++-
 llvm/lib/IR/Type.cpp  |  4 -
 .../Target/AArch64/AArch64ISelLowering.cpp|  9 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  6 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  3 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  3 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 22 ++---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  5 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  6 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 +-
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 +-
 .../Instrumentation/GCOVProfiling.cpp |  6 +-
 .../Instrumentation/InstrProfiling.cpp| 10 +--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  6 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  | 11 +--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 27 +++---
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 60 +++--
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 18 ++--
 polly/lib/Analysis/ScopDetection.cpp  |  2 +-
 60 files changed, 281 insertions(+), 225 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..de4ee68c0da1e79 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+llvm::PointerType::getUnqual(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext()),
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+

[clang] [llvm] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

2023-11-06 Thread Paulo Matos via cfe-commits

pmatos wrote:

I am now investigating the use of TargetExtTypes to represent Wasm Reference 
Types.

https://github.com/llvm/llvm-project/pull/71069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71029

>From bb652ca71a8f7ff5c362fef2fdf2d265fa77e45e Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Fri, 3 Nov 2023 12:03:07 +0100
Subject: [PATCH 1/2] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 12 ++---
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 38 +++
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/Type.h   |  5 --
 .../llvm/ProfileData/InstrProfData.inc| 12 ++---
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  4 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 ++--
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   |  8 ++--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  |  4 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 14 +++---
 llvm/lib/IR/Type.cpp  |  4 --
 .../Target/AArch64/AArch64ISelLowering.cpp|  4 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  2 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  2 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  2 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 12 ++---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  2 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  4 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 ++--
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 ++--
 .../Instrumentation/GCOVProfiling.cpp |  2 +-
 .../Instrumentation/InstrProfiling.cpp| 10 ++--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  4 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  |  6 +--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 16 +++
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 48 +--
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 14 +++---
 59 files changed, 165 insertions(+), 174 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..daa2b9c14f99a35 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+llvm::PointerType::getUnqual(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext()),
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+

[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Paulo Matos via cfe-commits


@@ -1514,7 +1514,7 @@ static void CreateGCRelocates(ArrayRef 
LiveVariables,
   auto getGCRelocateDecl = [&](Type *Ty) {
 assert(isHandledGCPointerType(Ty, GC));
 auto AS = Ty->getScalarType()->getPointerAddressSpace();
-Type *NewTy = Type::getInt8PtrTy(M->getContext(), AS);
+Type *NewTy = PointerType::getUnqual(M->getContext(), AS);

pmatos wrote:

Right - thanks for pointing that out.

https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-03 Thread Paulo Matos via cfe-commits

pmatos wrote:

I pushed forced a change using PointerType::getUnqual. Would this be more 
acceptable? It certainly looks cleaner to my eyes than having 
`PointerType::get(Ctx, 0)` everywhere.

https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-03 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71029

>From bb652ca71a8f7ff5c362fef2fdf2d265fa77e45e Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Fri, 3 Nov 2023 12:03:07 +0100
Subject: [PATCH] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 12 ++---
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 38 +++
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/Type.h   |  5 --
 .../llvm/ProfileData/InstrProfData.inc| 12 ++---
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  4 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 ++--
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   |  8 ++--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  |  4 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 14 +++---
 llvm/lib/IR/Type.cpp  |  4 --
 .../Target/AArch64/AArch64ISelLowering.cpp|  4 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  2 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  2 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  2 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 12 ++---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  2 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  4 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 ++--
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 ++--
 .../Instrumentation/GCOVProfiling.cpp |  2 +-
 .../Instrumentation/InstrProfiling.cpp| 10 ++--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  4 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  |  6 +--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 16 +++
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 48 +--
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 14 +++---
 59 files changed, 165 insertions(+), 174 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..daa2b9c14f99a35 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+llvm::PointerType::getUnqual(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext()),
+  llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
+

[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-03 Thread Paulo Matos via cfe-commits

pmatos wrote:

> I have a similar concern with @arsenm about making the default address space 
> 0. Can't we just use the already existing `PointerType::getUnqual()`, instead 
> of introducing the default address space 0?

True, we could indeed just call `PointerType::getUnqual()` instead of just 
`PointerType::get()`.

https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

2023-11-03 Thread Paulo Matos via cfe-commits

pmatos wrote:

> @pmatos If you don't want to go all the way to target extension types, is it 
> possible to gracefully handle this in wasm's TTI cost model? Return an 
> invalid or very high cost in this case?

Unfortunately that actually doesn't work. We never get to the point of 
calculating a cost because before doing that we calculate in 
`SLPVectorizerPass::tryToVectorizeList` we call `TTI->getNumberOfParts(VecTy)`. 
It's deep inside getNumberOfParts that we fail because we cannot calculate how 
many parts there are. Which is fair enough, since we build a vector of 
externref that can't be built. Only later in the function we try to calculate 
the cost but by then we have asserted long before.

https://github.com/llvm/llvm-project/pull/71069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

2023-11-02 Thread Paulo Matos via cfe-commits

https://github.com/pmatos created 
https://github.com/llvm/llvm-project/pull/71069

Fixes #69894 .

>From deb62d806b4bba983d771eb87c3188a3fc3d56d5 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Tue, 31 Oct 2023 09:01:25 +0100
Subject: [PATCH 1/2] [WebAssembly] Reftypes are not valid element types

---
 llvm/lib/IR/Type.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 006278d16484c1c..b1d0f12498c3244 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -682,8 +682,11 @@ VectorType *VectorType::get(Type *ElementType, 
ElementCount EC) {
 }
 
 bool VectorType::isValidElementType(Type *ElemTy) {
+  if(PointerType *PTy = dyn_cast(ElemTy))
+return PTy->getAddressSpace() != 10 && PTy->getAddressSpace() != 20;
+
   return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
- ElemTy->isPointerTy() || ElemTy->getTypeID() == TypedPointerTyID;
+ ElemTy->getTypeID() == TypedPointerTyID;
 }
 
 
//===--===//

>From d93ec3a6ba414483efd6126fc7a953228b5e4150 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Thu, 2 Nov 2023 16:40:38 +0100
Subject: [PATCH 2/2] Add test

---
 .../CodeGen/WebAssembly/wasm-externref-novec.c   | 16 
 1 file changed, 16 insertions(+)
 create mode 100644 clang/test/CodeGen/WebAssembly/wasm-externref-novec.c

diff --git a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c 
b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
new file mode 100644
index 000..45042e3970c9343
--- /dev/null
+++ b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O2 -triple wasm32-unknown-unknown-wasm -emit-llvm -o - %s 
| FileCheck %s
+
+// From issue 69894. Reftypes need to be marked as not valid as vector 
elements.
+__externref_t foo(void);
+void bar(__externref_t);
+
+void
+test(int flag, __externref_t ref1, __externref_t ref2)
+{
+  if (flag) {
+ref1 = foo();
+ref2 = foo();
+  }
+  bar(ref1);
+  bar(ref2);
+}
\ No newline at end of file

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

2023-11-02 Thread Paulo Matos via cfe-commits

pmatos wrote:

cc: @nikic @jcranmer-intel @tlively @asb 

I am looking for suggestions for a way forward on this. Issue #69894 triggers 
the SLPVectorizer that tries to create a vector of 2 externref and calculate 
its cost. Externref is a WebAssembly type currently represented as a pointer to 
a "magical" address space (address space 10). The other reference type is 
funcref that is a pointer to address space 20.

As a pointertype, `VectorType::isValidElementType` returns true. The "obvious" 
solution is to say that if the target is webassembly and the type is a pointer 
type to address space 10 or 20, then it's not a valid element type. This is 
what I am doing (except actually checking the current target) which I am not 
sure how to obtain from `Type.cpp` at this point. However, this would introduce 
a target dependence which I think is not really something we want in 
`Type.cpp`. 

The other more radical alternative is to refactor the reference types approach 
in WebAssembly and use the new-ish TargetExtType. It feels like that's what we 
would have used had they existed when we initially worked on this. Alas, they 
didn't exist and we used the magic of address spaces to solve the issue. This 
refactoring would lead to possibly quite a bit of work, including touching 
clang to correct the lowering of these types. In addition it might also open a 
Pandora's box.

I wonder if there's a middle ground here somewhere that doesn't involve adding 
target dependence to Type.cpp but at the same time doesn't require a full 
refactoring of these types.

...

Why is the test failing?

In SLPVectorizer.cpp we are generating the type `<16 x ptr addrspace(10)>` and 
calling `llvm::TargetTransformInfo::getNumberOfParts` on it. This will down the 
line call `getTypeLegalizationCost` for this type. The MVT for an externref is 
MVT::externref. The MVT for a vector of these is `iPTR`. At some point 
`getTypeForEVT` in `ValueTypes.cpp:198` it asserts `Assertion isExtended() && 
"Type is not extended!"' failed.`.

I attempted this with a pointer to int instead of externref because it should 
work the same. And it does without failing (obviously). This is because the 
type created is `<4 x ptr>`. The MVT for a `i32` is `MVT::i32` and the MVT for 
the vector is `MVT::v4i32`. This is extended and nothing asserts.

https://github.com/llvm/llvm-project/pull/71069
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-02 Thread Paulo Matos via cfe-commits

https://github.com/pmatos edited https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-02 Thread Paulo Matos via cfe-commits

pmatos wrote:

> Nit: can you add in the description that this is a follow-up from the opaque 
> pointer transition (having an explicit motivation helps read a patch). Thanks!

you're right. done.

https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-02 Thread Paulo Matos via cfe-commits

pmatos wrote:

> I still think all the defaulted address space parameters should be purged and 
> it only invites bugs. It's a regression to introduce a new defaulted argument.

Understandable, although always writing `PointerType::get(Ctx, 0);` really 
looks weird given most of the time the second parameter is 0. So it just feels 
like it's a special constant that will suddenly be sprinkled all over the code.

https://github.com/llvm/llvm-project/pull/71029
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-02 Thread Paulo Matos via cfe-commits

https://github.com/pmatos created 
https://github.com/llvm/llvm-project/pull/71029

Replace this with PointerType::get().
Also adds AS = 0 as an optional argument to get() methods.

>From 28745bc7877747f998f658ee2f661f8312c54814 Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Thu, 2 Nov 2023 08:11:25 +0100
Subject: [PATCH] [NFC] Remove Type::getInt8PtrTy

Replace this with PointerType::get().
Also adds AS = 0 as an optional argument to get() methods.
---
 clang/lib/CodeGen/CGGPUBuiltin.cpp| 12 ++---
 clang/lib/CodeGen/CodeGenPGO.cpp  |  2 +-
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 +-
 .../clang-linker-wrapper/OffloadWrapper.cpp   | 38 +++
 llvm/examples/BrainF/BrainF.cpp   |  2 +-
 llvm/include/llvm/IR/DerivedTypes.h   |  8 ++--
 llvm/include/llvm/IR/Type.h   |  4 --
 .../llvm/ProfileData/InstrProfData.inc| 12 ++---
 llvm/lib/Analysis/StackSafetyAnalysis.cpp |  4 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +-
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|  2 +-
 llvm/lib/CodeGen/DwarfEHPrepare.cpp   |  4 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 ++--
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/CodeGen/SjLjEHPrepare.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp   |  8 ++--
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |  2 +-
 llvm/lib/Frontend/Offloading/Utility.cpp  |  4 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 14 +++---
 llvm/lib/IR/Type.cpp  |  4 --
 .../Target/AArch64/AArch64ISelLowering.cpp|  4 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  2 +-
 .../AMDGPUOpenCLEnqueuedBlockLowering.cpp |  2 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  4 +-
 .../Target/BPF/BPFAbstractMemberAccess.cpp|  2 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp |  2 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  4 +-
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp   |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp | 12 ++---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp   |  2 +-
 llvm/lib/Transforms/CFGuard/CFGuard.cpp   |  2 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|  4 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  8 ++--
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../Instrumentation/DataFlowSanitizer.cpp |  8 ++--
 .../Instrumentation/GCOVProfiling.cpp |  2 +-
 .../Instrumentation/InstrProfiling.cpp| 10 ++--
 .../Instrumentation/PGOInstrumentation.cpp|  2 +-
 .../Transforms/Scalar/LoopDataPrefetch.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Scalar/StraightLineStrengthReduce.cpp |  2 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  2 +-
 .../Utils/EntryExitInstrumenter.cpp   |  4 +-
 .../lib/Transforms/Utils/EscapeEnumerator.cpp |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  2 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |  2 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp |  2 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  |  6 +--
 llvm/tools/bugpoint/Miscompilation.cpp|  4 +-
 .../Analysis/CGSCCPassManagerTest.cpp | 16 +++
 llvm/unittests/Analysis/LazyCallGraphTest.cpp | 48 +--
 .../unittests/Analysis/MemoryBuiltinsTest.cpp |  2 +-
 .../Analysis/ScalarEvolutionTest.cpp  |  2 +-
 .../Frontend/OpenMPIRBuilderTest.cpp  |  4 +-
 llvm/unittests/FuzzMutate/OperationsTest.cpp  |  4 +-
 llvm/unittests/Linker/LinkModulesTest.cpp | 14 +++---
 61 files changed, 169 insertions(+), 177 deletions(-)

diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 75fb06de938425d..db6d80f7e0d87e6 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -23,8 +23,8 @@ using namespace CodeGen;
 
 namespace {
 llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
+  llvm::Type *ArgTypes[] = {llvm::PointerType::get(M.getContext()),
+llvm::PointerType::get(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module ) {
 llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
   const char *Name = "__llvm_omp_vprintf";
   llvm::Module  = CGM.getModule();
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-

[clang] 55aeb23 - [clang][WebAssembly] Implement support for table types and builtins

2023-06-10 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2023-06-10T15:53:13+02:00
New Revision: 55aeb23fe0084d930ecd7335092d712bd71694c7

URL: 
https://github.com/llvm/llvm-project/commit/55aeb23fe0084d930ecd7335092d712bd71694c7
DIFF: 
https://github.com/llvm/llvm-project/commit/55aeb23fe0084d930ecd7335092d712bd71694c7.diff

LOG: [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

Added: 
clang/test/CodeGen/WebAssembly/builtins-table.c
clang/test/Sema/builtins-wasm.c
clang/test/Sema/wasm-refs-and-table-ped.c
clang/test/Sema/wasm-refs-and-tables.c
clang/test/SemaCXX/wasm-refs-and-tables.cpp
llvm/include/llvm/CodeGen/WasmAddressSpaces.h

Modified: 
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
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

Removed: 
clang/test/Sema/wasm-refs.c
clang/test/SemaCXX/wasm-refs.cpp



diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index b36f2f8e3e45f..f37db774a0f7b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2313,6 +2313,138 @@ targets.
 atomic_add(a, 1);
   }
 
+WebAssembly Features
+
+
+Clang supports the WebAssembly features documented below. For further 
+information related to the semantics of the builtins, please refer to the 
`WebAssembly Specification `_.
+In this section, when we refer to reference types, we are referring to 
+WebAssembly reference types, not C++ reference types unless stated
+otherwise.
+
+``__builtin_wasm_table_set``
+
+
+This builtin function stores a value in a WebAssembly table. 
+It takes three arguments.
+The first argument is the table to store a value into, the second 
+argument is the index to which to store the value into, and the
+third argument is a value of reference type to store in the table.
+It returns nothing.
+
+.. code-block:: c++
+
+  static __externref_t table[0];
+  extern __externref_t JSObj;
+
+  void store(int index) {
+__builtin_wasm_table_set(table, index, JSObj);
+  } 
+
+``__builtin_wasm_table_get``
+
+
+This builtin function is the counterpart to ``__builtin_wasm_table_set``
+and loads a value from a WebAssembly table of reference typed values.
+It takes 2 arguments.
+The first argument is a table of reference typed values and the 
+second argument is an index from which to load the value. It returns
+the loaded reference typed value.
+
+.. code-block:: c++
+
+  static __externref_t table[0];
+  
+  __externref_t load(int index) {
+__externref_t Obj = __builtin_wasm_table_get(table, index);
+return Obj;
+  }
+
+``__builtin_wasm_table_size``
+-
+
+This builtin function returns the size of the WebAssembly table.
+Takes the table as an argument and returns an unsigned integer (``size_t``)
+with the current table size.
+
+.. code-block:: c++
+
+  typedef void (*__funcref funcref_t)();
+  static 

[clang] 9571a28 - [WebAssembly] Add tests ensuring rotates persist

2023-06-05 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2023-06-06T07:48:35+02:00
New Revision: 9571a28ee4e801a7796569d62fe037fc22cd65a4

URL: 
https://github.com/llvm/llvm-project/commit/9571a28ee4e801a7796569d62fe037fc22cd65a4
DIFF: 
https://github.com/llvm/llvm-project/commit/9571a28ee4e801a7796569d62fe037fc22cd65a4.diff

LOG: [WebAssembly] Add tests ensuring rotates persist

Due to the nature of WebAssembly, it's always better to keep
rotates instead of trying to optimize it. Commit 9485d983
disabled the generation of fsh for rotates, however these
tests ensure that future changes don't change the behaviour for
the Wasm backend that tends to have different optimization
requirements than other architectures. Also see:
https://github.com/llvm/llvm-project/issues/62703

Differential Revision: https://reviews.llvm.org/D152126

Added: 
clang/test/CodeGen/WebAssembly/wasm-rotate.c
llvm/test/CodeGen/WebAssembly/rotate-i3264.ll

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/WebAssembly/wasm-rotate.c 
b/clang/test/CodeGen/WebAssembly/wasm-rotate.c
new file mode 100644
index 0..a9579d6bdb366
--- /dev/null
+++ b/clang/test/CodeGen/WebAssembly/wasm-rotate.c
@@ -0,0 +1,53 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | 
FileCheck --check-prefix=WEBASSEMBLY32 %s
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | 
FileCheck --check-prefix=WEBASSEMBLY64 %s
+
+// WEBASSEMBLY32-LABEL: define i32 @test32
+// WEBASSEMBLY32-SAME: (i32 noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// WEBASSEMBLY32-NEXT:  entry:
+// WEBASSEMBLY32-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// WEBASSEMBLY32-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
+// WEBASSEMBLY32-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// WEBASSEMBLY32-NEXT:[[AND:%.*]] = and i32 [[TMP0]], -16711936
+// WEBASSEMBLY32-NEXT:[[TMP1:%.*]] = call i32 @llvm.fshl.i32(i32 [[AND]], 
i32 [[AND]], i32 8)
+// WEBASSEMBLY32-NEXT:ret i32 [[TMP1]]
+//
+// WEBASSEMBLY64-LABEL: define i32 @test32
+// WEBASSEMBLY64-SAME: (i32 noundef [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// WEBASSEMBLY64-NEXT:  entry:
+// WEBASSEMBLY64-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// WEBASSEMBLY64-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
+// WEBASSEMBLY64-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// WEBASSEMBLY64-NEXT:[[AND:%.*]] = and i32 [[TMP0]], -16711936
+// WEBASSEMBLY64-NEXT:[[TMP1:%.*]] = call i32 @llvm.fshl.i32(i32 [[AND]], 
i32 [[AND]], i32 8)
+// WEBASSEMBLY64-NEXT:ret i32 [[TMP1]]
+//
+unsigned int test32(unsigned int x) {
+  return __builtin_rotateleft32((x & 0xFF00FF00), 8);
+}
+
+// WEBASSEMBLY32-LABEL: define i32 @test64
+// WEBASSEMBLY32-SAME: (i32 noundef [[X:%.*]]) #[[ATTR0]] {
+// WEBASSEMBLY32-NEXT:  entry:
+// WEBASSEMBLY32-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// WEBASSEMBLY32-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
+// WEBASSEMBLY32-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// WEBASSEMBLY32-NEXT:[[CONV:%.*]] = zext i32 [[TMP0]] to i64
+// WEBASSEMBLY32-NEXT:[[AND:%.*]] = and i64 [[CONV]], -71777214294589696
+// WEBASSEMBLY32-NEXT:[[TMP1:%.*]] = call i64 @llvm.fshl.i64(i64 [[AND]], 
i64 [[AND]], i64 8)
+// WEBASSEMBLY32-NEXT:[[CONV1:%.*]] = trunc i64 [[TMP1]] to i32
+// WEBASSEMBLY32-NEXT:ret i32 [[CONV1]]
+//
+// WEBASSEMBLY64-LABEL: define i64 @test64
+// WEBASSEMBLY64-SAME: (i64 noundef [[X:%.*]]) #[[ATTR0]] {
+// WEBASSEMBLY64-NEXT:  entry:
+// WEBASSEMBLY64-NEXT:[[X_ADDR:%.*]] = alloca i64, align 8
+// WEBASSEMBLY64-NEXT:store i64 [[X]], ptr [[X_ADDR]], align 8
+// WEBASSEMBLY64-NEXT:[[TMP0:%.*]] = load i64, ptr [[X_ADDR]], align 8
+// WEBASSEMBLY64-NEXT:[[AND:%.*]] = and i64 [[TMP0]], -71777214294589696
+// WEBASSEMBLY64-NEXT:[[TMP1:%.*]] = call i64 @llvm.fshl.i64(i64 [[AND]], 
i64 [[AND]], i64 8)
+// WEBASSEMBLY64-NEXT:ret i64 [[TMP1]]
+//
+unsigned long test64(unsigned long x) {
+  return __builtin_rotateleft64((x & 0xFF00FF00FF00FF00L), 8);
+}

diff  --git a/llvm/test/CodeGen/WebAssembly/rotate-i3264.ll 
b/llvm/test/CodeGen/WebAssembly/rotate-i3264.ll
new file mode 100644
index 0..209f0e43be722
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/rotate-i3264.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 2
+; RUN: sed 's/iX/i32/g' %s | llc --mtriple=wasm32-unknown-unknown | FileCheck 
--check-prefix=I32 %s
+; RUN: sed 's/iX/i64/g' %s | llc --mtriple=wasm64-unknown-unknown | FileCheck 
--check-prefix=I64 %s
+
+declare iX @llvm.fshl.iX(iX, iX, iX)
+declare iX @llvm.fshr.iX(iX, iX, iX)
+
+; from https://github.com/llvm/llvm-project/issues/62703
+
+define iX @testLeft(iX noundef %0, iX noundef %1) {
+; I32-LABEL: 

[clang] 481e202 - [clang][doc] Fix link to SYCL compiler design doc

2023-03-28 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2023-03-28T18:09:52+02:00
New Revision: 481e20252461e730f36fb221123a853eda27cafc

URL: 
https://github.com/llvm/llvm-project/commit/481e20252461e730f36fb221123a853eda27cafc
DIFF: 
https://github.com/llvm/llvm-project/commit/481e20252461e730f36fb221123a853eda27cafc.diff

LOG: [clang][doc] Fix link to SYCL compiler design doc

Added: 


Modified: 
clang/docs/SYCLSupport.rst

Removed: 




diff  --git a/clang/docs/SYCLSupport.rst b/clang/docs/SYCLSupport.rst
index 6b529e3eb012..364d95a31047 100644
--- a/clang/docs/SYCLSupport.rst
+++ b/clang/docs/SYCLSupport.rst
@@ -10,7 +10,7 @@ Introduction
 
 This document describes the architecture of the SYCL compiler and runtime
 library. More details are provided in
-`external document 
`_\
 ,
+`external document 
`_\
 ,
 which are going to be added to clang documentation in the future.
 
 Address space handling



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8d0c889 - [clang][WebAssembly] Initial support for reference type funcref in clang

2023-03-17 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2023-03-17T18:31:44+01:00
New Revision: 8d0c889752121e62e7258570c592b905f544d36f

URL: 
https://github.com/llvm/llvm-project/commit/8d0c889752121e62e7258570c592b905f544d36f
DIFF: 
https://github.com/llvm/llvm-project/commit/8d0c889752121e62e7258570c592b905f544d36f.diff

LOG: [clang][WebAssembly] Initial support for reference type funcref in clang

This is the funcref counterpart to 890146b. We introduce a new attribute
that marks a function pointer as a funcref. It also implements builtin
__builtin_wasm_ref_null_func(), that returns a null funcref value.

Differential Revision: https://reviews.llvm.org/D128440

Added: 
clang/test/CodeGen/WebAssembly/wasm-funcref.c
clang/test/Parser/wasm-funcref.c
clang/test/SemaCXX/wasm-funcref.cpp

Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/AddressSpaces.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/DeclBase.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/DirectX.h
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Basic/Targets/SPIR.h
clang/lib/Basic/Targets/TCE.h
clang/lib/Basic/Targets/WebAssembly.h
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h
clang/lib/Format/FormatToken.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseTentative.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Sema/wasm-refs.c
clang/test/SemaTemplate/address_space-dependent.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 7c3b755a438f1..e736f827f04b4 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1227,6 +1227,10 @@ class alignas(8) Decl {
   /// have a FunctionType.
   const FunctionType *getFunctionType(bool BlocksToo = true) const;
 
+  // Looks through the Decl's underlying type to determine if it's a
+  // function pointer type.
+  bool isFunctionPointerType() const;
+
 private:
   void setAttrsImpl(const AttrVec& Attrs, ASTContext );
   void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 95a5df8699afb..9ecc29bd38fd1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4934,6 +4934,8 @@ class AttributedType : public Type, public 
llvm::FoldingSetNode {
 
   bool isMSTypeSpec() const;
 
+  bool isWebAssemblyFuncrefSpec() const;
+
   bool isCallingConv() const;
 
   std::optional getImmediateNullability() const;

diff  --git a/clang/include/clang/Basic/AddressSpaces.h 
b/clang/include/clang/Basic/AddressSpaces.h
index 2f2c5d5826bc3..7b723d508fff1 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -59,6 +59,9 @@ enum class LangAS : unsigned {
   // HLSL specific address spaces.
   hlsl_groupshared,
 
+  // Wasm specific address spaces.
+  wasm_funcref,
+
   // This denotes the count of language-specific address spaces and also
   // the offset added to the target-specific address spaces, which are usually
   // specified by address space attributes __attribute__(address_space(n))).

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 89a62e83444a3..6c55465926bf7 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -168,6 +168,12 @@ def FunctionLike : SubsetSubjectgetFunctionType(false) != nullptr}],
  "functions, function pointers">;
 
+// Function Pointer is a stricter version of FunctionLike that only allows 
function
+// pointers.
+def FunctionPointer : SubsetSubjectisFunctionPointerType()}],
+"functions pointers">;
+
 def OpenCLKernelFunction
 : SubsetSubjecthasAttr()}],
 "kernel functions">;
@@ -4131,6 +4137,13 @@ def FunctionReturnThunks : InheritableAttr,
   let Subjects = SubjectList<[Function]>;
   let Documentation = [FunctionReturnThunksDocs];
 }
+
+def WebAssemblyFuncref : TypeAttr, TargetSpecificAttr {
+  let Spellings = [Keyword<"__funcref">];
+  let Documentation = [WebAssemblyExportNameDocs];
+  let Subjects = SubjectList<[FunctionPointer], ErrorDiag>;
+}
+
 def ReadOnlyPlacement : InheritableAttr {
   let Spellings = [Clang<"enforce_read_only_placement">];
   let Subjects = 

[clang] eb66833 - [clang][WebAssembly] Initial support for reference type externref in clang

2023-01-31 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2023-01-31T17:34:01+01:00
New Revision: eb66833d19573df97034a81279eda31b8d19815b

URL: 
https://github.com/llvm/llvm-project/commit/eb66833d19573df97034a81279eda31b8d19815b
DIFF: 
https://github.com/llvm/llvm-project/commit/eb66833d19573df97034a81279eda31b8d19815b.diff

LOG: [clang][WebAssembly] Initial support for reference type externref in clang

This patch introduces a new type __externref_t that denotes a WebAssembly opaque
reference type. It also implements builtin __builtin_wasm_ref_null_extern(),
that returns a null value of __externref_t. This lays the ground work
for further builtins and reference types.

Differential Revision: https://reviews.llvm.org/D122215

Added: 
clang/include/clang/Basic/WebAssemblyReferenceTypes.def
clang/test/CodeGen/WebAssembly/wasm-externref.c
clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
clang/test/Sema/wasm-refs.c
clang/test/SemaCXX/wasm-refs.cpp

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/module.modulemap
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/NSAPI.cpp
clang/lib/AST/PrintfFormatString.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h
clang/lib/Index/USRGeneration.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReader.cpp
clang/test/CodeGen/builtins-wasm.c
clang/test/SemaTemplate/address_space-dependent.cpp
clang/tools/libclang/CIndex.cpp
llvm/include/llvm/IR/Type.h
llvm/include/llvm/Transforms/Utils.h
llvm/lib/CodeGen/ValueTypes.cpp
llvm/lib/IR/Type.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Transforms/Utils/Mem2Reg.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 0238371927e09..911ee8b215051 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1126,6 +1126,8 @@ class ASTContext : public RefCountedBase {
 #define RVV_TYPE(Name, Id, SingletonId) \
   CanQualType SingletonId;
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 
   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
   mutable QualType AutoDeductTy; // Deduction against 'auto'.
@@ -1474,6 +1476,9 @@ class ASTContext : public RefCountedBase {
   /// \pre \p EltTy must be a built-in type.
   QualType getScalableVectorType(QualType EltTy, unsigned NumElts) const;
 
+  /// Return a WebAssembly externref type.
+  QualType getWebAssemblyExternrefType() const;
+
   /// Return the unique reference to a vector type of the specified
   /// element type and size.
   ///

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 180251d7f6bd8..0252e3adbb7c3 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2029,6 +2029,10 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// Returns true for SVE scalable vector types.
   bool isSVESizelessBuiltinType() const;
 
+  /// Check if this is a WebAssembly Reference Type.
+  bool isWebAssemblyReferenceType() const;
+  bool isWebAssemblyExternrefType() const;
+
   /// Determines if this is a sizeless type supported by the
   /// 'arm_sve_vector_bits' type attribute, which can be applied to a single
   /// SVE vector or predicate, excluding tuple types such as svint32x4_t.
@@ -2640,6 +2644,9 @@ class BuiltinType : public Type {
 // RVV Types
 #define RVV_TYPE(Name, Id, SingletonId) Id,
 #include "clang/Basic/RISCVVTypes.def"
+// WebAssembly reference types
+#define WASM_TYPE(Name, Id, SingletonId) Id,
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 // All other builtin types
 #define BUILTIN_TYPE(Id, SingletonId) Id,
 #define LAST_BUILTIN_TYPE(Id) LastKind = Id

diff  --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index 

[clang] 39d8597 - [clang] Fix typo in error message

2022-10-21 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2022-10-21T12:06:28+02:00
New Revision: 39d8597927a5887bcfde2229491d793f3edcedbd

URL: 
https://github.com/llvm/llvm-project/commit/39d8597927a5887bcfde2229491d793f3edcedbd
DIFF: 
https://github.com/llvm/llvm-project/commit/39d8597927a5887bcfde2229491d793f3edcedbd.diff

LOG: [clang] Fix typo in error message

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 54eb520a47526..2a3da01febe2b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18853,7 +18853,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
   IntNo = Intrinsic::wasm_extadd_pairwise_unsigned;
   break;
 default:
-  llvm_unreachable("unexptected builtin ID");
+  llvm_unreachable("unexpected builtin ID");
 }
 
 Function *Callee = CGM.getIntrinsic(IntNo, ConvertType(E->getType()));



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0fdfeb0 - [WebAssembly] Update test to run it in opaque pointers mode

2022-06-23 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2022-06-23T14:16:33+02:00
New Revision: 0fdfeb0847dfbce9d5734f61c9fc16ed6f7dc17e

URL: 
https://github.com/llvm/llvm-project/commit/0fdfeb0847dfbce9d5734f61c9fc16ed6f7dc17e
DIFF: 
https://github.com/llvm/llvm-project/commit/0fdfeb0847dfbce9d5734f61c9fc16ed6f7dc17e.diff

LOG: [WebAssembly] Update test to run it in opaque pointers mode

When opaque pointers was enabled, -no-opaque-pointers were added to some tests 
in order not to change behaviour. We now revert this and fix the test.

Reviewed By: asb, tlively

Differential Revision: https://reviews.llvm.org/D128282

Added: 


Modified: 
clang/test/CodeGen/builtins-wasm.c

Removed: 




diff  --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index d9ea753ee86a..ea591a195cad 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -no-opaque-pointers -triple wasm32-unknown-unknown 
-target-feature +simd128 -target-feature +relaxed-simd -target-feature 
+nontrapping-fptoint -target-feature +exception-handling -target-feature 
+bulk-memory -target-feature +atomics -flax-vector-conversions=none -O3 
-emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
-// RUN: %clang_cc1 -no-opaque-pointers -triple wasm64-unknown-unknown 
-target-feature +simd128 -target-feature +relaxed-simd -target-feature 
+nontrapping-fptoint -target-feature +exception-handling -target-feature 
+bulk-memory -target-feature +atomics -flax-vector-conversions=none -O3 
-emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
-// RUN: not %clang_cc1 -no-opaque-pointers -triple wasm64-unknown-unknown 
-target-feature +nontrapping-fptoint -target-feature +exception-handling 
-target-feature +bulk-memory -target-feature +atomics 
-flax-vector-conversions=none -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s 
-check-prefixes MISSING-SIMD
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +simd128 
-target-feature +relaxed-simd -target-feature +nontrapping-fptoint 
-target-feature +exception-handling -target-feature +bulk-memory 
-target-feature +atomics -flax-vector-conversions=none -O3 -emit-llvm -o - %s | 
FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +simd128 
-target-feature +relaxed-simd -target-feature +nontrapping-fptoint 
-target-feature +exception-handling -target-feature +bulk-memory 
-target-feature +atomics -flax-vector-conversions=none -O3 -emit-llvm -o - %s | 
FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
+// RUN: not %clang_cc1 -triple wasm64-unknown-unknown -target-feature 
+nontrapping-fptoint -target-feature +exception-handling -target-feature 
+bulk-memory -target-feature +atomics -flax-vector-conversions=none -O3 
-emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes MISSING-SIMD
 
 // SIMD convenience types
 typedef signed char i8x16 __attribute((vector_size(16)));
@@ -40,13 +40,12 @@ __SIZE_TYPE__ tls_align(void) {
 
 void *tls_base(void) {
   return __builtin_wasm_tls_base();
-  // WEBASSEMBLY: call i8* @llvm.wasm.tls.base()
+  // WEBASSEMBLY: call ptr @llvm.wasm.tls.base()
 }
 
 void throw(void *obj) {
   return __builtin_wasm_throw(0, obj);
-  // WEBASSEMBLY32: call void @llvm.wasm.throw(i32 0, i8* %{{.*}})
-  // WEBASSEMBLY64: call void @llvm.wasm.throw(i32 0, i8* %{{.*}})
+  // WEBASSEMBLY: call void @llvm.wasm.throw(i32 0, ptr %{{.*}})
 }
 
 void rethrow(void) {
@@ -57,20 +56,17 @@ void rethrow(void) {
 
 int memory_atomic_wait32(int *addr, int expected, long long timeout) {
   return __builtin_wasm_memory_atomic_wait32(addr, expected, timeout);
-  // WEBASSEMBLY32: call i32 @llvm.wasm.memory.atomic.wait32(i32* %{{.*}}, i32 
%{{.*}}, i64 %{{.*}})
-  // WEBASSEMBLY64: call i32 @llvm.wasm.memory.atomic.wait32(i32* %{{.*}}, i32 
%{{.*}}, i64 %{{.*}})
+  // WEBASSEMBLY: call i32 @llvm.wasm.memory.atomic.wait32(ptr %{{.*}}, i32 
%{{.*}}, i64 %{{.*}})
 }
 
 int memory_atomic_wait64(long long *addr, long long expected, long long 
timeout) {
   return __builtin_wasm_memory_atomic_wait64(addr, expected, timeout);
-  // WEBASSEMBLY32: call i32 @llvm.wasm.memory.atomic.wait64(i64* %{{.*}}, i64 
%{{.*}}, i64 %{{.*}})
-  // WEBASSEMBLY64: call i32 @llvm.wasm.memory.atomic.wait64(i64* %{{.*}}, i64 
%{{.*}}, i64 %{{.*}})
+  // WEBASSEMBLY: call i32 @llvm.wasm.memory.atomic.wait64(ptr %{{.*}}, i64 
%{{.*}}, i64 %{{.*}})
 }
 
 unsigned int memory_atomic_notify(int *addr, unsigned int count) {
   return __builtin_wasm_memory_atomic_notify(addr, count);
-  // WEBASSEMBLY32: call i32 @llvm.wasm.memory.atomic.notify(i32* %{{.*}}, i32 
%{{.*}})
-  // WEBASSEMBLY64: call i32 @llvm.wasm.memory.atomic.notify(i32* %{{.*}}, i32 
%{{.*}})
+  // WEBASSEMBLY: call i32 @llvm.wasm.memory.atomic.notify(ptr %{{.*}}, i32 
%{{.*}})
 }
 
 int 

[clang] 968be05 - [clang] Fix crash for sizeof on VLAs

2022-01-12 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2022-01-12T16:10:58+01:00
New Revision: 968be05b8fdc1d23c055cc4963230a89efbc5967

URL: 
https://github.com/llvm/llvm-project/commit/968be05b8fdc1d23c055cc4963230a89efbc5967
DIFF: 
https://github.com/llvm/llvm-project/commit/968be05b8fdc1d23c055cc4963230a89efbc5967.diff

LOG: [clang] Fix crash for sizeof on VLAs

Adds overload of TransformToPotentiallyEvaluated for TypeSourceInfo to
properly deal with VLAs in nested calls of sizeof and typeof. Fixes
PR31042 (https://github.com/llvm/llvm-project/issues/30390).

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D27800

Added: 
clang/test/SemaCXX/pr31042.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f1e90356c8367..b4d8d1494e705 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@ class Sema final {
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult CheckUnevaluatedOperand(Expr *E);

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 229a604901244..7de43705c2b10 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,10 @@ Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo 
*TInfo,
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -16601,6 +16605,16 @@ ExprResult Sema::TransformToPotentiallyEvaluated(Expr 
*E) {
   return TransformToPE(*this).TransformExpr(E);
 }
 
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(
 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl,

diff  --git a/clang/test/SemaCXX/pr31042.cpp b/clang/test/SemaCXX/pr31042.cpp
new file mode 100644
index 0..d4995c6e4d686
--- /dev/null
+++ b/clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu 
-disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it 
semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void f1(void) {
+  int i = 0;
+  int j = sizeof(typeof(*(char(*)[i])a));
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6d0c7bc - [WebAssembly] Implementation of table.get/set for reftypes in LLVM IR

2021-10-20 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2021-10-20T10:31:31+02:00
New Revision: 6d0c7bc17de85807c286f78571235b6658999faf

URL: 
https://github.com/llvm/llvm-project/commit/6d0c7bc17de85807c286f78571235b6658999faf
DIFF: 
https://github.com/llvm/llvm-project/commit/6d0c7bc17de85807c286f78571235b6658999faf.diff

LOG: [WebAssembly] Implementation of table.get/set for reftypes in LLVM IR

This change implements new DAG nodes TABLE_GET/TABLE_SET, and lowering
methods for load and stores of reference types from IR arrays. These
global LLVM IR arrays represent tables at the Wasm level.

Differential Revision: https://reviews.llvm.org/D54

Added: 
llvm/test/CodeGen/WebAssembly/externref-tableget.ll
llvm/test/CodeGen/WebAssembly/externref-tableset.ll
llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
llvm/test/CodeGen/WebAssembly/funcref-tableset.ll

Modified: 
clang/lib/Basic/Targets/WebAssembly.h
clang/test/CodeGen/target-data.c
lld/test/wasm/lto/Inputs/archive.ll
lld/test/wasm/lto/Inputs/cache.ll
lld/test/wasm/lto/Inputs/libcall-archive.ll
lld/test/wasm/lto/Inputs/libcall-truncsfhf2.ll
lld/test/wasm/lto/Inputs/save-temps.ll
lld/test/wasm/lto/Inputs/thinlto.ll
lld/test/wasm/lto/Inputs/used.ll
lld/test/wasm/lto/archive.ll
lld/test/wasm/lto/atomics.ll
lld/test/wasm/lto/cache.ll
lld/test/wasm/lto/comdat.ll
lld/test/wasm/lto/diagnostics.ll
lld/test/wasm/lto/export.ll
lld/test/wasm/lto/import-attributes.ll
lld/test/wasm/lto/internalize-basic.ll
lld/test/wasm/lto/libcall-archive.ll
lld/test/wasm/lto/libcall-truncsfhf2.ll
lld/test/wasm/lto/lto-start.ll
lld/test/wasm/lto/new-pass-manager.ll
lld/test/wasm/lto/opt-level.ll
lld/test/wasm/lto/parallel.ll
lld/test/wasm/lto/relocatable-undefined.ll
lld/test/wasm/lto/relocatable.ll
lld/test/wasm/lto/save-temps.ll
lld/test/wasm/lto/thinlto.ll
lld/test/wasm/lto/tls.ll
lld/test/wasm/lto/undef.ll
lld/test/wasm/lto/used.ll
lld/test/wasm/lto/verify-invalid.ll
lld/test/wasm/lto/weak-undefined.ll
lld/test/wasm/lto/weak.ll
llvm/lib/Target/WebAssembly/WebAssemblyISD.def
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/WebAssembly.h 
b/clang/lib/Basic/Targets/WebAssembly.h
index 27b6576e4b7a..16534d3ef99b 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -151,9 +151,11 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
const TargetOptions )
   : WebAssemblyTargetInfo(T, Opts) {
 if (T.isOSEmscripten())
-  resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1:10:20");
+  resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
+  "S128-ni:1:10:20");
 else
-  resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20");
+  resetDataLayout(
+  "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
   }
 
 protected:
@@ -173,9 +175,11 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
 PtrDiffType = SignedLong;
 IntPtrType = SignedLong;
 if (T.isOSEmscripten())
-  resetDataLayout("e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1:10:20");
+  resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
+  "S128-ni:1:10:20");
 else
-  resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20");
+  resetDataLayout(
+  "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
   }
 
 protected:

diff  --git a/clang/test/CodeGen/target-data.c 
b/clang/test/CodeGen/target-data.c
index 0749493d788f..d702f845112b 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -108,11 +108,11 @@
 
 // RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY32
-// WEBASSEMBLY32: target datalayout = 
"e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20"
+// WEBASSEMBLY32: target datalayout = 
"e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY64
-// WEBASSEMBLY64: target datalayout = 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"
+// WEBASSEMBLY64: target datalayout = 
"e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -o - -emit-llvm %s | \
 // RUN: 

[clang] 46667a1 - [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-22 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2021-07-22T22:07:24+02:00
New Revision: 46667a10039b664b953eb70534c27627b35a267d

URL: 
https://github.com/llvm/llvm-project/commit/46667a10039b664b953eb70534c27627b35a267d
DIFF: 
https://github.com/llvm/llvm-project/commit/46667a10039b664b953eb70534c27627b35a267d.diff

LOG: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

Reland of 31859f896.

This change implements new DAG notes GLOBAL_GET/GLOBAL_SET, and
lowering methods for load and stores of reference types from IR
globals. Once the lowering creates the new nodes, tablegen pattern
matches those and converts them to Wasm global.get/set.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D104797

Added: 
llvm/test/CodeGen/WebAssembly/externref-globalget.ll
llvm/test/CodeGen/WebAssembly/externref-globalset.ll
llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
llvm/test/CodeGen/WebAssembly/externref-undef.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
llvm/test/CodeGen/WebAssembly/funcref-call.ll
llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
llvm/test/CodeGen/WebAssembly/funcref-globalset.ll

Modified: 
clang/lib/Basic/Targets/WebAssembly.h
clang/test/CodeGen/target-data.c
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/include/llvm/CodeGen/ValueTypes.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/MachineOperand.cpp
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/CodeGen/ValueTypes.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISD.def
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/WebAssembly.h 
b/clang/lib/Basic/Targets/WebAssembly.h
index a43e770eb1e8c..4a5ba25c75e7e 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -150,9 +150,9 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
const TargetOptions )
   : WebAssemblyTargetInfo(T, Opts) {
 if (T.isOSEmscripten())
-  resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1");
+  resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1:10:20");
 else
-  resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1");
+  resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20");
   }
 
 protected:
@@ -172,9 +172,9 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
 PtrDiffType = SignedLong;
 IntPtrType = SignedLong;
 if (T.isOSEmscripten())
-  resetDataLayout("e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1");
+  resetDataLayout("e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1:10:20");
 else
-  resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1");
+  resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20");
   }
 
 protected:

diff  --git a/clang/test/CodeGen/target-data.c 
b/clang/test/CodeGen/target-data.c
index 1d88984530e5b..1be01efd16515 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -108,11 +108,11 @@
 
 // RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY32
-// WEBASSEMBLY32: target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1"
+// WEBASSEMBLY32: target datalayout = 
"e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY64
-// WEBASSEMBLY64: target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
+// WEBASSEMBLY64: target datalayout = 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=LANAI

diff  --git a/llvm/include/llvm/CodeGen/TargetLowering.h 
b/llvm/include/llvm/CodeGen/TargetLowering.h
index 1cf6ac0e5f949..9b42cc9dfb3a0 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -349,7 +349,7 @@ class TargetLoweringBase {
   /// Return the in-memory pointer type for the given address space, defaults 
to
   /// the pointer type from the data layout.  FIXME: The default needs to be
   /// removed once all 

[clang] 4facbf2 - [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-07-02 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2021-07-02T09:46:28+02:00
New Revision: 4facbf213c51e4add2e8c19b08d5e58ad71c72de

URL: 
https://github.com/llvm/llvm-project/commit/4facbf213c51e4add2e8c19b08d5e58ad71c72de
DIFF: 
https://github.com/llvm/llvm-project/commit/4facbf213c51e4add2e8c19b08d5e58ad71c72de.diff

LOG: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

Reland of 31859f896.

This change implements new DAG notes GLOBAL_GET/GLOBAL_SET, and
lowering methods for load and stores of reference types from IR
globals. Once the lowering creates the new nodes, tablegen pattern
matches those and converts them to Wasm global.get/set.

Differential Revision: https://reviews.llvm.org/D104797

Added: 
llvm/test/CodeGen/WebAssembly/externref-globalget.ll
llvm/test/CodeGen/WebAssembly/externref-globalset.ll
llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
llvm/test/CodeGen/WebAssembly/externref-undef.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
llvm/test/CodeGen/WebAssembly/funcref-call.ll
llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
llvm/test/CodeGen/WebAssembly/funcref-globalset.ll

Modified: 
clang/lib/Basic/Targets/WebAssembly.h
clang/test/CodeGen/target-data.c
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/include/llvm/CodeGen/ValueTypes.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/MachineOperand.cpp
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/CodeGen/ValueTypes.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISD.def
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/WebAssembly.h 
b/clang/lib/Basic/Targets/WebAssembly.h
index b29730c5d706b..ed590fe7e3338 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -147,7 +147,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
   explicit WebAssembly32TargetInfo(const llvm::Triple ,
const TargetOptions )
   : WebAssemblyTargetInfo(T, Opts) {
-resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1");
+resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20");
   }
 
 protected:
@@ -166,7 +166,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
 SizeType = UnsignedLong;
 PtrDiffType = SignedLong;
 IntPtrType = SignedLong;
-resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1");
+resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20");
   }
 
 protected:

diff  --git a/clang/test/CodeGen/target-data.c 
b/clang/test/CodeGen/target-data.c
index 1d88984530e5b..1be01efd16515 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -108,11 +108,11 @@
 
 // RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY32
-// WEBASSEMBLY32: target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1"
+// WEBASSEMBLY32: target datalayout = 
"e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY64
-// WEBASSEMBLY64: target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
+// WEBASSEMBLY64: target datalayout = 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=LANAI

diff  --git a/llvm/include/llvm/CodeGen/TargetLowering.h 
b/llvm/include/llvm/CodeGen/TargetLowering.h
index 47d6ca43a5ac3..75894d15a9693 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -350,7 +350,7 @@ class TargetLoweringBase {
   /// Return the in-memory pointer type for the given address space, defaults 
to
   /// the pointer type from the data layout.  FIXME: The default needs to be
   /// removed once all the code is updated.
-  MVT getPointerMemTy(const DataLayout , uint32_t AS = 0) const {
+  virtual MVT getPointerMemTy(const DataLayout , uint32_t AS = 0) const {
 return MVT::getIntegerVT(DL.getPointerSizeInBits(AS));
   }
 

diff  --git a/llvm/include/llvm/CodeGen/ValueTypes.h 
b/llvm/include/llvm/CodeGen/ValueTypes.h

[clang] 31859f8 - Implementation of global.get/set for reftypes in LLVM IR

2021-06-10 Thread Paulo Matos via cfe-commits

Author: Paulo Matos
Date: 2021-06-10T10:07:45+02:00
New Revision: 31859f896cf90d64904134ce7b31230f374c3fcc

URL: 
https://github.com/llvm/llvm-project/commit/31859f896cf90d64904134ce7b31230f374c3fcc
DIFF: 
https://github.com/llvm/llvm-project/commit/31859f896cf90d64904134ce7b31230f374c3fcc.diff

LOG: Implementation of global.get/set for reftypes in LLVM IR

This change implements new DAG notes GLOBAL_GET/GLOBAL_SET, and
lowering methods for load and stores of reference types from IR
globals. Once the lowering creates the new nodes, tablegen pattern
matches those and converts them to Wasm global.get/set.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D95425

Added: 
llvm/test/CodeGen/WebAssembly/externref-globalget.ll
llvm/test/CodeGen/WebAssembly/externref-globalset.ll
llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
llvm/test/CodeGen/WebAssembly/externref-undef.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
llvm/test/CodeGen/WebAssembly/funcref-call.ll
llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
llvm/test/CodeGen/WebAssembly/funcref-globalset.ll

Modified: 
clang/lib/Basic/Targets/WebAssembly.cpp
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/include/llvm/CodeGen/ValueTypes.h
llvm/include/llvm/Support/MachineValueType.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/MachineOperand.cpp
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/CodeGen/ValueTypes.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISD.def
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 2a5055c3d534b..eade8e8d0346d 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -214,6 +214,8 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
   continue;
 }
 if (Feature == "+reference-types") {
+  // FIXME: Ensure address spaces 10 and 20 are marked as non-integral in
+  // the datalayout string.
   HasReferenceTypes = true;
   continue;
 }

diff  --git a/llvm/include/llvm/CodeGen/TargetLowering.h 
b/llvm/include/llvm/CodeGen/TargetLowering.h
index c8c4219f2820c..03a5a1bb97528 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -350,7 +350,7 @@ class TargetLoweringBase {
   /// Return the in-memory pointer type for the given address space, defaults 
to
   /// the pointer type from the data layout.  FIXME: The default needs to be
   /// removed once all the code is updated.
-  MVT getPointerMemTy(const DataLayout , uint32_t AS = 0) const {
+  virtual MVT getPointerMemTy(const DataLayout , uint32_t AS = 0) const {
 return MVT::getIntegerVT(DL.getPointerSizeInBits(AS));
   }
 

diff  --git a/llvm/include/llvm/CodeGen/ValueTypes.h 
b/llvm/include/llvm/CodeGen/ValueTypes.h
index e7346f7a75abc..4001b39dae279 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.h
+++ b/llvm/include/llvm/CodeGen/ValueTypes.h
@@ -120,6 +120,9 @@ namespace llvm {
   return changeExtendedTypeToInteger();
 }
 
+/// Test if the given EVT has zero size
+bool isZeroSized() const { return getSizeInBits() == 0; }
+
 /// Test if the given EVT is simple (as opposed to being extended).
 bool isSimple() const {
   return V.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE;
@@ -207,7 +210,9 @@ namespace llvm {
 }
 
 /// Return true if the bit size is a multiple of 8.
-bool isByteSized() const { return getSizeInBits().isKnownMultipleOf(8); }
+bool isByteSized() const {
+  return !isZeroSized() && getSizeInBits().isKnownMultipleOf(8);
+}
 
 /// Return true if the size is a power-of-two number of bytes.
 bool isRound() const {

diff  --git a/llvm/include/llvm/Support/MachineValueType.h 
b/llvm/include/llvm/Support/MachineValueType.h
index 88ae8f8e6fc4d..9b95943e484a7 100644
--- a/llvm/include/llvm/Support/MachineValueType.h
+++ b/llvm/include/llvm/Support/MachineValueType.h
@@ -1026,6 +1026,11 @@ namespace llvm {
   }
 }
 
+/// Test if the given MVT has zero size
+bool isZeroSized() const {
+  return 

Re: [PATCH] D26843: Make sizeof expression context partially evaluated

2016-11-18 Thread Paulo Matos via cfe-commits


On 18/11/16 20:30, Aaron Ballman wrote:
> On Fri, Nov 18, 2016 at 2:22 PM, Paulo Matos via cfe-commits
> <cfe-commits@lists.llvm.org> wrote:
>> pmatos added a comment.
>>
>> Apologies if I am being shallow and wasting your time but `sizeof(T::m)` 
>> doesn't compile at the moment with clang trunk. Using the same service you 
>> used before <http://melpon.org/wandbox/permlink/C4pCnoVGmS0qBUxf>.
> 
> Compile for C++11 instead of C++03.
> 

OK, I can see the problem. Interestingly, the error you get with the
patch and c++11 is the same you used to get with c++03.

I will take a look at this.

-- 
Paulo Matos
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26843: Make sizeof expression context partially evaluated

2016-11-18 Thread Paulo Matos via cfe-commits
pmatos added a comment.

Apologies if I am being shallow and wasting your time but `sizeof(T::m)` 
doesn't compile at the moment with clang trunk. Using the same service you used 
before .


https://reviews.llvm.org/D26843



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26843: Make sizeof expression context partially evaluated

2016-11-18 Thread Paulo Matos via cfe-commits
pmatos added a comment.

In https://reviews.llvm.org/D26843#599673, @EricWF wrote:

> > But that is not valid in C afaik and in C++ I get:
> > 
> >   error: invalid use of non-static data member 'm'
> > int x = sizeof(T::m);
> >~~~^
> > 
> > 
> > Can you post a full reproducible example of what the change breaks?
>
> That is a full reproducible example because it's valid C++. Clang currently 
> compiles it .


But what was in the link was:

  typedef struct { int m; } T;
  int x = sizeof(T);
  int main() {}

This is different from your initial snippet and compiles fine with my patch.


https://reviews.llvm.org/D26843



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26843: Make sizeof expression context partially evaluated

2016-11-18 Thread Paulo Matos via cfe-commits
pmatos added a comment.

In https://reviews.llvm.org/D26843#599635, @EricWF wrote:

> This isn't correct. For example this change breaks:
>
>   struct T { int m; };
>   int x = sizeof(T::m);
>


But that is not valid in C afaik and in C++ I get:

  error: invalid use of non-static data member 'm'
int x = sizeof(T::m);
   ~~~^

Can you post a full reproducible example of what the change breaks?


https://reviews.llvm.org/D26843



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26843: Make sizeof expression context partially evaluated

2016-11-18 Thread Paulo Matos via cfe-commits
pmatos created this revision.
pmatos added a reviewer: efriedma.
pmatos added a subscriber: cfe-commits.

Ensure sizeof expression context is partially evaluated so that potential 
typeof operators inside are evaluated if necessary.

Fixes PR31042.


https://reviews.llvm.org/D26843

Files:
  lib/Parse/ParseExpr.cpp


Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1881,7 +1881,10 @@
   if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
 Diag(OpTok, diag::warn_cxx98_compat_alignof);
 
-  EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated,
+  EnterExpressionEvaluationContext Unevaluated(Actions,
+  OpTok.is(tok::kw_sizeof) ?
+  Sema::PotentiallyEvaluated :
+  Sema::Unevaluated,
Sema::ReuseLambdaContextDecl);
 
   bool isCastExpr;


Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1881,7 +1881,10 @@
   if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
 Diag(OpTok, diag::warn_cxx98_compat_alignof);
 
-  EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated,
+  EnterExpressionEvaluationContext Unevaluated(Actions,
+	   OpTok.is(tok::kw_sizeof) ?
+	   Sema::PotentiallyEvaluated :
+	   Sema::Unevaluated,
Sema::ReuseLambdaContextDecl);
 
   bool isCastExpr;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits