LLVM ABI Annotations (PR #67502)

2023-10-27 Thread Tom Stellard via cfe-commits

tstellar wrote:

I'm working on rebasing this.

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


[clang] [NFC][Clang] Fix potential deref of end iterator (PR #70193)

2023-10-27 Thread Shafik Yaghmour via cfe-commits


@@ -65,7 +65,7 @@ class CXXFieldCollector {
 
   /// getCurFields - Pointer to array of fields added to the currently parsed
   /// class.
-  FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); }

shafik wrote:

I think this is basically [cwg232](https://wg21.link/cwg232) this is ok b/c we 
are not doing an lvalue-to-rvalue conversion but only using it to take the 
address of. 

CC @zygoloid 

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2023-10-27 Thread Shafik Yaghmour via cfe-commits


@@ -11773,7 +11786,25 @@ QualType Sema::CheckShiftOperands(ExprResult , 
ExprResult ,
   isScopedEnumerationType(RHSType)) {
 return InvalidOperands(Loc, LHS, RHS);
   }
-  DiagnoseBadShiftValues(*this, LHS, RHS, Loc, Opc, LHSType);
+
+  BadShiftValueKind BSVKind =
+  DiagnoseBadShiftValues(*this, LHS, RHS, Loc, Opc, LHSType);
+  if (ExprEvalContexts.back().isConstantEvaluated()) {

shafik wrote:

This feels pretty hacky but perhaps I am not fully understanding the solution.

Can you update the description with more details on why this is a good approach 
to the problem.

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


[clang] [mlir] Add config for PDL (PR #69927)

2023-10-27 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Need to iterate a bit more on framing the problem:

> MLIR is a general infrastructure and as far as possible no dialect is 
> intended to be special or privileged

Yes, and you can use MLIR without PDL, it's not a mandatory component. I 
believe that the minimal examples `mlir-cat` and `mlir-minimal-opt` don't have 
PDL linked in (so you can already have your *-opt tool without it!

> Users should be able to use MLIR and the parts they need to customize for 
> their solution (e.g., one doesn't have to include any dialect except the ones 
> one uses). 

I don't see PDL as "just a dialect": I see it more as an infrastructure 
component. 
That is no one will have PDL used within their IR! 
It isn't comparable to any other dialect and completely unique from this point 
of view (do we have other dialects that aren't targeting user-written 
compilers? The transform dialect might be in-between)

> Many parts are elided when not referenced (LTO DCE'd etc), but this is not 
> possible with PDL given how its integrated with the common rewrite drivers. 
> This results in it always being included even when not used.

Now that seems more accurate to me: the dependency on PDL is only from the 
rewrite drivers, which is a "bring your own" thing by the way.
So the underlying question for motivating this here would be better framed IMO 
as "should we have an option to build the GreedyPatternRewriter without PDL?" 
I see it less as a strong need here (because again, bring your own driver if 
you don't like it).

Without a stronger case, this seems like something I would be supportive if we 
can make it minimally intrusive: that is localize the changes to a maximum and 
not spread through the codebase.
There are far too many #ifdef  to me right now, this may need some more 
refactoring first to avoid this and make PDL a more proper "separate component" 
inside libMLIRRewrite so that is can be enabled/disabled more naturally.

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-27 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/67166

>From 686eff52ac0878fa9545481eaf32b47350c68be8 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Fri, 22 Sep 2023 08:21:21 -0500
Subject: [PATCH 1/7] [InstSimplify] Add tests for simplify `llvm.ptrmask`; NFC

Differential Revision: https://reviews.llvm.org/D156632
---
 llvm/test/Transforms/InstSimplify/ptrmask.ll | 366 +++
 1 file changed, 366 insertions(+)
 create mode 100644 llvm/test/Transforms/InstSimplify/ptrmask.ll

diff --git a/llvm/test/Transforms/InstSimplify/ptrmask.ll 
b/llvm/test/Transforms/InstSimplify/ptrmask.ll
new file mode 100644
index 000..4945d4bc0edf625
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ptrmask.ll
@@ -0,0 +1,366 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+target datalayout = "p1:64:64:64:32"
+
+declare ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr addrspace(1) , i32)
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+
+declare <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1) 
>, <2 x i32>)
+declare <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr>, <2 x i64>)
+
+define ptr @ptrmask_simplify_poison_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
poison)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 poison)
+  ret ptr %r
+}
+
+define <2 x ptr addrspace(1) > @ptrmask_simplify_poison_mask_vec(<2 x ptr 
addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> @ptrmask_simplify_poison_mask_vec
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> poison)
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> poison)
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define <2 x ptr addrspace(1) > 
@ptrmask_simplify_poison_and_zero_i32_vec_fail(<2 x ptr addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> 
@ptrmask_simplify_poison_and_zero_i32_vec_fail
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> )
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> )
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define <2 x ptr> @ptrmask_simplify_undef_and_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_undef_and_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr> @ptrmask_simplify_poison_and_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_poison_and_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr> @ptrmask_simplify_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr addrspace(1) > @ptrmask_simplify_ones_i32_vec(<2 x ptr 
addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> @ptrmask_simplify_ones_i32_vec
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> )
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> )
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define ptr addrspace(1) @ptrmask_simplify_undef_mask(ptr addrspace(1) %p) {
+; CHECK-LABEL: define ptr addrspace(1) @ptrmask_simplify_undef_mask
+; CHECK-SAME: (ptr addrspace(1) [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr 
addrspace(1) [[P]], i32 undef)
+; CHECK-NEXT:ret ptr addrspace(1) [[R]]
+;
+  %r = call ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr addrspace(1) %p, i32 
undef)
+  ret ptr addrspace(1) %r
+}
+
+define 

[clang] [Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku (PR #70434)

2023-10-27 Thread Brad Smith via cfe-commits

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


[clang] [Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku (PR #70434)

2023-10-27 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70434

>From 2aa78e266b76286c38a071999274f496722a56f0 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 27 Oct 2023 05:13:59 -0400
Subject: [PATCH] [Driver] Silence stdlib warning when linking C on *BSD /
 Solaris / Haiku

Same as 12b87f6ef720080fab1e2d48ca2d8c5ba478ee5d and the addition to Gnu.
---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 3 +++
 clang/lib/Driver/ToolChains/FreeBSD.cpp   | 6 +++---
 clang/lib/Driver/ToolChains/Haiku.cpp | 3 +++
 clang/lib/Driver/ToolChains/NetBSD.cpp| 3 +++
 clang/lib/Driver/ToolChains/OpenBSD.cpp   | 3 +++
 clang/lib/Driver/ToolChains/Solaris.cpp   | 2 ++
 6 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index ed7f751adc0efaf..cced977bf029256 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -144,6 +144,9 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index e7d9e9fc4c8..0b70ac7b76e6765 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -291,6 +291,9 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
@@ -364,9 +367,6 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);
 
-  // Silence warnings when linking C code with a C++ '-stdlib' argument.
-  Args.ClaimAllArgs(options::OPT_stdlib_EQ);
-
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index b940150788f65c7..1df9c7b08879e45 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -95,6 +95,9 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 if (D.CCCIsCXX() && ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 7a1d4561c6f2f4f..cfde8d40a77ae16 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -315,6 +315,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 16a311be31be7bc..c5255573baf3ca5 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -214,6 +214,9 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 

[clang] [Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku (PR #70434)

2023-10-27 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70434

>From ae7bf5b42a62f0c20592e07af2f9e746aaa2231c Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 27 Oct 2023 05:13:59 -0400
Subject: [PATCH] [Driver] Silence stdlib warning when linking C on *BSD /
 Solaris / Haiku

Same as 12b87f6ef720080fab1e2d48ca2d8c5ba478ee5d
---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 3 +++
 clang/lib/Driver/ToolChains/FreeBSD.cpp   | 6 +++---
 clang/lib/Driver/ToolChains/Haiku.cpp | 3 +++
 clang/lib/Driver/ToolChains/NetBSD.cpp| 3 +++
 clang/lib/Driver/ToolChains/OpenBSD.cpp   | 3 +++
 clang/lib/Driver/ToolChains/Solaris.cpp   | 2 ++
 6 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index ed7f751adc0efaf..cced977bf029256 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -144,6 +144,9 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index e7d9e9fc4c8..0b70ac7b76e6765 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -291,6 +291,9 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
@@ -364,9 +367,6 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);
 
-  // Silence warnings when linking C code with a C++ '-stdlib' argument.
-  Args.ClaimAllArgs(options::OPT_stdlib_EQ);
-
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index b940150788f65c7..1df9c7b08879e45 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -95,6 +95,9 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 if (D.CCCIsCXX() && ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 7a1d4561c6f2f4f..cfde8d40a77ae16 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -315,6 +315,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 16a311be31be7bc..c5255573baf3ca5 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -214,6 +214,9 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 

[clang] [Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku (PR #70434)

2023-10-27 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/70434

>From 7b884f2d1bc366d20f553b54aaca5c7dd8afe487 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 27 Oct 2023 05:13:59 -0400
Subject: [PATCH] [Driver] Silence stdlib warning when linking C on *BSD /
 Solaris / Haiku

Same as 12b87f6ef720080fab1e2d48ca2d8c5ba478ee5d
---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 3 +++
 clang/lib/Driver/ToolChains/FreeBSD.cpp   | 6 +++---
 clang/lib/Driver/ToolChains/Haiku.cpp | 3 +++
 clang/lib/Driver/ToolChains/NetBSD.cpp| 3 +++
 clang/lib/Driver/ToolChains/OpenBSD.cpp   | 3 +++
 clang/lib/Driver/ToolChains/Solaris.cpp   | 3 +++
 6 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index ed7f751adc0efaf..cced977bf029256 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -144,6 +144,9 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index e7d9e9fc4c8..0b70ac7b76e6765 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -291,6 +291,9 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
@@ -364,9 +367,6 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);
 
-  // Silence warnings when linking C code with a C++ '-stdlib' argument.
-  Args.ClaimAllArgs(options::OPT_stdlib_EQ);
-
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index b940150788f65c7..1df9c7b08879e45 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -95,6 +95,9 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 if (D.CCCIsCXX() && ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 7a1d4561c6f2f4f..cfde8d40a77ae16 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -315,6 +315,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 16a311be31be7bc..c5255573baf3ca5 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -214,6 +214,9 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 

[clang] a8e0acf - [Driver][NFC] Fix a typo in the function name

2023-10-27 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-10-27T22:10:05-04:00
New Revision: a8e0acf660639078a7e5341dd6ec82326d3b796b

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

LOG: [Driver][NFC] Fix a typo in the function name

Added: 


Modified: 
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Haiku.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/lib/Driver/ToolChains/OpenBSD.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 500dd98665075b1..ed7f751adc0efaf 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -147,7 +147,7 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
-// AddRuntTimeLibs).
+// AddRunTimeLibs).
 if (D.IsFlangMode()) {
   addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
   addFortranRuntimeLibs(ToolChain, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index a5be32b4a2f07fd..e7d9e9fc4c8 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -294,7 +294,7 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
-// AddRuntTimeLibs).
+// AddRunTimeLibs).
 if (D.IsFlangMode()) {
   addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
   addFortranRuntimeLibs(ToolChain, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 2515f85432d7542..5237951f84cce03 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -573,7 +573,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
   // Additional linker set-up and flags for Fortran. This is required in order
   // to generate executables. As Fortran runtime depends on the C runtime,
   // these dependencies need to be listed before the C runtime below (i.e.
-  // AddRuntTimeLibs).
+  // AddRunTimeLibs).
   if (D.IsFlangMode()) {
 addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
 addFortranRuntimeLibs(ToolChain, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index 172f16cc46e328e..b940150788f65c7 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -98,7 +98,7 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
-// AddRuntTimeLibs).
+// AddRunTimeLibs).
 if (D.IsFlangMode()) {
   addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
   addFortranRuntimeLibs(ToolChain, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 245553d46055a27..7a1d4561c6f2f4f 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -318,7 +318,7 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
-// AddRuntTimeLibs).
+// AddRunTimeLibs).
 if (D.IsFlangMode()) {
   addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
   addFortranRuntimeLibs(ToolChain, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 4e14c3d140a1da2..16a311be31be7bc 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -217,7 +217,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be 

[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-27 Thread Fangrui Song via cfe-commits

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-27 Thread Fangrui Song via cfe-commits


@@ -96,13 +97,39 @@ bool MultilibSet::select(const Multilib::flags_list ,
  llvm::SmallVector ) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
-  llvm::copy_if(Multilibs, std::back_inserter(Selected),
-[](const Multilib ) {
-  for (const std::string  : M.flags())
-if (!FlagSet.contains(F))
-  return false;
-  return true;
-});
+
+  // Decide which multilibs we're going to select at all
+  std::vector IsSelected(Multilibs.size(), false);
+  std::map ExclusiveGroupMembers;
+  for (size_t i = 0, e = Multilibs.size(); i < e; ++i) {
+const Multilib  = Multilibs[i];
+
+// If this multilib doesn't match all our flags, don't select it
+if (!llvm::all_of(M.flags(), [](const std::string ) {
+  return FlagSet.contains(F);
+}))
+  continue;
+
+// If this multilib has the same ExclusiveGroup as one we've already
+// selected, de-select the previous one
+const std::string  = M.exclusiveGroup();
+if (!group.empty()) {

MaskRay wrote:

Thanks for the update, but the new code still has the duplicate hash table 
lookup/insert problem, which can be fixed by using try_emplace.

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-27 Thread Fangrui Song via cfe-commits


@@ -96,13 +98,36 @@ bool MultilibSet::select(const Multilib::flags_list ,
  llvm::SmallVector ) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
-  llvm::copy_if(Multilibs, std::back_inserter(Selected),
-[](const Multilib ) {
-  for (const std::string  : M.flags())
-if (!FlagSet.contains(F))
-  return false;
-  return true;
-});
+
+  // Decide which multilibs we're going to select at all.
+  llvm::DenseSet ExclusiveGroupsSelected;
+

MaskRay wrote:

The common llvm-project style does not typically insert a blank line after a 
variable declaration, different from the Linux kernel style.

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-27 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,70 @@
+# REQUIRES: shell

MaskRay wrote:

If `LIT_USE_INTERNAL_SHELL=1 llvm-lit ..` passes, you can remove `# REQUIRES: 
shell` (dependency on an external shell)

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-27 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.

Looks good to me, but other reviewers likely have opinions

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


[clang-tools-extra] [clangd] Support `-specs` arguments when querying the driver. (PR #70285)

2023-10-27 Thread Chris Carlon via cfe-commits

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


[clang-tools-extra] [clangd] Support `-specs` arguments when querying the driver. (PR #70285)

2023-10-27 Thread Chris Carlon via cfe-commits

https://github.com/cjc25 updated https://github.com/llvm/llvm-project/pull/70285

>From 4d975b63f802f6e766d4a2cd0b6122bd0ca1e596 Mon Sep 17 00:00:00 2001
From: Chris Carlon 
Date: Tue, 24 Oct 2023 22:21:59 -0400
Subject: [PATCH] [clangd] Support `-specs` arguments when querying the driver.

Similarly to commit 3935a29, forward spec file arguments to the driver if they
appear in the compile database. Spec files can affect the include search path.

fixes clangd/clangd#1410
---
 .../clangd/SystemIncludeExtractor.cpp | 30 ---
 .../clangd/test/system-include-extractor.test |  8 +++--
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index a86f152c3bf364e..ea98c7d948a2f6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -89,13 +89,14 @@ struct DriverArgs {
   std::string ISysroot;
   std::string Target;
   std::string Stdlib;
+  llvm::SmallVector Specs;
 
   bool operator==(const DriverArgs ) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot, Target, Stdlib) ==
+Sysroot, ISysroot, Target, Stdlib, Specs) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target,
-RHS.Stdlib);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target, 
RHS.Stdlib,
+RHS.Specs);
   }
 
   DriverArgs(const tooling::CompileCommand , llvm::StringRef File) {
@@ -145,6 +146,17 @@ struct DriverArgs {
   Stdlib = Cmd.CommandLine[I + 1];
   } else if (Arg.consume_front("-stdlib=")) {
 Stdlib = Arg.str();
+  } else if (Arg.startswith("-specs=")) {
+// clang requires a single token like `-specs=file` or `--specs=file`,
+// but gcc will accept two tokens like `--specs file`. Since the
+// compilation database is presumably correct, we just forward the 
flags
+// as-is.
+Specs.push_back(Arg.str());
+  } else if (Arg.startswith("--specs=")) {
+Specs.push_back(Arg.str());
+  } else if (Arg == "--specs" && I + 1 < E) {
+Specs.push_back(Arg.str());
+Specs.push_back(Cmd.CommandLine[I + 1]);
   }
 }
 
@@ -186,6 +198,11 @@ struct DriverArgs {
   Args.append({"-target", Target});
 if (!Stdlib.empty())
   Args.append({"--stdlib", Stdlib});
+
+for (llvm::StringRef Spec : Specs) {
+  Args.push_back(Spec);
+}
+
 return Args;
   }
 
@@ -210,7 +227,7 @@ template <> struct DenseMapInfo {
 return Driver;
   }
   static unsigned getHashValue(const DriverArgs ) {
-return llvm::hash_value(std::tuple{
+unsigned FixedFieldsHash = llvm::hash_value(std::tuple{
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
@@ -220,6 +237,11 @@ template <> struct DenseMapInfo {
 Val.Target,
 Val.Stdlib,
 });
+
+unsigned SpecsHash =
+llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+
+return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }
   static bool isEqual(const DriverArgs , const DriverArgs ) {
 return LHS == RHS;
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index cbb3018b2fa7349..4ccc0936713246b 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -19,6 +19,10 @@
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"--stdlib libc++"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-specs=test.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs=test2.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# Check that clangd drops other flags like -lc++, which don't affect includes
+# RUN: echo '[ -n "${args##*"-lc++"*}" ] || exit' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -38,7 +42,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot -stdlib=libc++", "file": "the-file.cpp"}]' > 
%t.dir/compile_commands.json
+# 

[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as

silee2 wrote:

I don't know. My goal was to make no change to existing Vulkan workflow. 

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+const mlir::spirv::TargetEnv  =
+getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+if (memoryModel == spirv::MemoryModel::OpenCL) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+mlir::spirv::TargetEnvAttr targetAttr =

silee2 wrote:

Now the lambda returns boolean and cannot be used. Also that line is from the 
original code. I just moved it up a bit since I needed access to targetAttr 
before memory space mapping.

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+const mlir::spirv::TargetEnv  =
+getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =

silee2 wrote:

That is a great idea. Thanks! Updated the lambda.


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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -108,6 +147,31 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
+  // In case of OpenCL, gpu.func in original gpu.module needs to replaced with

silee2 wrote:

Updated comment.

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.

silee2 wrote:

Thank for the suggestion. Updated comment.

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-10-27 Thread Owen Pan via cfe-commits

owenca wrote:

> #67911 is a pull request, not an issue, i'm not sure what you're referring to

I think it was a typo. It should be #67991.

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();

silee2 wrote:

Thanks! That simplifies the code a lot.

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =

silee2 wrote:

Removed usage of target.

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.

silee2 wrote:

Done.

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


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.

silee2 wrote:

Done.

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -143,11 +145,12 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
   // In case of OpenCL, gpu.func in original gpu.module needs to replaced with
   // an empty func.func with same arguments as gpu.func. And it also needs
   // gpu.kernel attribute set.
   module.walk([&](gpu::GPUModuleOp moduleOp) {
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

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


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -143,11 +145,12 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
   // In case of OpenCL, gpu.func in original gpu.module needs to replaced with
   // an empty func.func with same arguments as gpu.func. And it also needs
   // gpu.kernel attribute set.
   module.walk([&](gpu::GPUModuleOp moduleOp) {
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);
 FailureOr memoryModel =
 spirv::getMemoryModel(targetEnv);
 if (failed(memoryModel))
   return signalPassFailure();
-(memoryModel == spirv::MemoryModel::OpenCL)
-? builder.setInsertionPoint(moduleOp.getBody(),
-moduleOp.getBody()->begin())
-: builder.setInsertionPoint(moduleOp.getOperation());
+if (memoryModel == spirv::MemoryModel::OpenCL) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
-auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+mlir::spirv::TargetEnvAttr targetAttr = 
spirv::lookupTargetEnvOrDefault(gpuModule);

silee2 wrote:

Removed mlir::

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-10-27 Thread Owen Pan via cfe-commits

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


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);
 FailureOr memoryModel =
 spirv::getMemoryModel(targetEnv);
 if (failed(memoryModel))
   return signalPassFailure();
-(memoryModel == spirv::MemoryModel::OpenCL)
-? builder.setInsertionPoint(moduleOp.getBody(),
-moduleOp.getBody()->begin())
-: builder.setInsertionPoint(moduleOp.getOperation());
+if (memoryModel == spirv::MemoryModel::OpenCL) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
-auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+mlir::spirv::TargetEnvAttr targetAttr = 
spirv::lookupTargetEnvOrDefault(gpuModule);

silee2 wrote:

Removed mlir::

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

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


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

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


[clang] [clang-format][NFC] Delete TT_LambdaArrow (PR #70519)

2023-10-27 Thread Emilia Kond via cfe-commits

https://github.com/rymiel approved this pull request.

Surprised this works!

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69941

>From 7ca3f97b5ee6e5cefd94afd3b090d0dba2120cea Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 16:25:15 +
Subject: [PATCH 1/6] [MLIR] Update convert-gpu-to-spirv pass to prepare using
 GPU compilation pipeline for OpenCL kernels.

This includes a couple of changes to pass behavior for OpenCL kernels.
Vulkan shaders are not impacted by the changes.

1. SPIRV module is placed inside GPU module. This change is required for
gpu-module-to-binary to work correctly as it expects kernel function to be
inside the GPU module.
2. A dummy func.func with same kernel name as gpu.func is created.
GPU compilation pipeline defers lowering of gpu launch kernel op.
Since spirv.func is not directly tied to gpu launch kernel,
a dummy func.func is required to avoid legalization issues.
3. Use correct mapping when mapping MemRef memory space to SPIR-V storage class 
for OpenCL kernels.
---
 mlir/include/mlir/Conversion/Passes.td|  5 +-
 .../Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp  | 76 ---
 .../Conversion/GPUToSPIRV/module-opencl.mlir  |  4 +
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 274784fe4a7b29c..652ef5ad95158ca 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -578,7 +578,10 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", 
"ModuleOp"> {
 to control the set and binding if wanted.
   }];
   let constructor = "mlir::createConvertGPUToSPIRVPass()";
-  let dependentDialects = ["spirv::SPIRVDialect"];
+  let dependentDialects = [
+"spirv::SPIRVDialect",
+"func::FuncDialect",
+  ];
   let options = [
 Option<"use64bitIndex", "use-64bit-index",
"bool", /*default=*/"false",
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 272e3de8723aeb6..35ee0d7038a2c9a 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -17,6 +17,7 @@
 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
@@ -54,22 +55,63 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [=](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+(memoryModel == spirv::MemoryModel::OpenCL)
+? builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin())
+: builder.setInsertionPoint(moduleOp.getOperation());
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
   std::unique_ptr target =
   

[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-10-27 Thread Owen Pan via cfe-commits

https://github.com/owenca requested changes to this pull request.

Please refer to the 
[policy](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options)
 for adding new options.

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-10-27 Thread Emilia Kond via cfe-commits


@@ -4648,6 +4648,10 @@ struct FormatStyle {
   /// \version 11
   std::vector WhitespaceSensitiveMacros;
 
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;

rymiel wrote:

(this applies to not just here, but below on line 4818, and in Format.cpp, and 
in ConfigParseTest.cpp)

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


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69941

>From 7ca3f97b5ee6e5cefd94afd3b090d0dba2120cea Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 16:25:15 +
Subject: [PATCH 1/5] [MLIR] Update convert-gpu-to-spirv pass to prepare using
 GPU compilation pipeline for OpenCL kernels.

This includes a couple of changes to pass behavior for OpenCL kernels.
Vulkan shaders are not impacted by the changes.

1. SPIRV module is placed inside GPU module. This change is required for
gpu-module-to-binary to work correctly as it expects kernel function to be
inside the GPU module.
2. A dummy func.func with same kernel name as gpu.func is created.
GPU compilation pipeline defers lowering of gpu launch kernel op.
Since spirv.func is not directly tied to gpu launch kernel,
a dummy func.func is required to avoid legalization issues.
3. Use correct mapping when mapping MemRef memory space to SPIR-V storage class 
for OpenCL kernels.
---
 mlir/include/mlir/Conversion/Passes.td|  5 +-
 .../Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp  | 76 ---
 .../Conversion/GPUToSPIRV/module-opencl.mlir  |  4 +
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 274784fe4a7b29c..652ef5ad95158ca 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -578,7 +578,10 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", 
"ModuleOp"> {
 to control the set and binding if wanted.
   }];
   let constructor = "mlir::createConvertGPUToSPIRVPass()";
-  let dependentDialects = ["spirv::SPIRVDialect"];
+  let dependentDialects = [
+"spirv::SPIRVDialect",
+"func::FuncDialect",
+  ];
   let options = [
 Option<"use64bitIndex", "use-64bit-index",
"bool", /*default=*/"false",
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 272e3de8723aeb6..35ee0d7038a2c9a 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -17,6 +17,7 @@
 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
@@ -54,22 +55,63 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [=](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+(memoryModel == spirv::MemoryModel::OpenCL)
+? builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin())
+: builder.setInsertionPoint(moduleOp.getOperation());
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
   std::unique_ptr target =
   

[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69941

>From 7ca3f97b5ee6e5cefd94afd3b090d0dba2120cea Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 16:25:15 +
Subject: [PATCH 1/5] [MLIR] Update convert-gpu-to-spirv pass to prepare using
 GPU compilation pipeline for OpenCL kernels.

This includes a couple of changes to pass behavior for OpenCL kernels.
Vulkan shaders are not impacted by the changes.

1. SPIRV module is placed inside GPU module. This change is required for
gpu-module-to-binary to work correctly as it expects kernel function to be
inside the GPU module.
2. A dummy func.func with same kernel name as gpu.func is created.
GPU compilation pipeline defers lowering of gpu launch kernel op.
Since spirv.func is not directly tied to gpu launch kernel,
a dummy func.func is required to avoid legalization issues.
3. Use correct mapping when mapping MemRef memory space to SPIR-V storage class 
for OpenCL kernels.
---
 mlir/include/mlir/Conversion/Passes.td|  5 +-
 .../Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp  | 76 ---
 .../Conversion/GPUToSPIRV/module-opencl.mlir  |  4 +
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 274784fe4a7b29c..652ef5ad95158ca 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -578,7 +578,10 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", 
"ModuleOp"> {
 to control the set and binding if wanted.
   }];
   let constructor = "mlir::createConvertGPUToSPIRVPass()";
-  let dependentDialects = ["spirv::SPIRVDialect"];
+  let dependentDialects = [
+"spirv::SPIRVDialect",
+"func::FuncDialect",
+  ];
   let options = [
 Option<"use64bitIndex", "use-64bit-index",
"bool", /*default=*/"false",
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 272e3de8723aeb6..35ee0d7038a2c9a 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -17,6 +17,7 @@
 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
@@ -54,22 +55,63 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [=](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+(memoryModel == spirv::MemoryModel::OpenCL)
+? builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin())
+: builder.setInsertionPoint(moduleOp.getOperation());
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
   std::unique_ptr target =
   

[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-10-27 Thread Emilia Kond via cfe-commits

rymiel wrote:

https://github.com/llvm/llvm-project/pull/67911 is a pull request, not an 
issue, i'm not sure what you're referring to

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


[PATCH] D91442: [clang][Driver] Handle risvc in Baremetal.cpp.

2023-10-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.
Herald added subscribers: wangpc, luke, sunshaoce, arichardson.
Herald added a project: All.



Comment at: clang/lib/Driver/ToolChains/RISCVToolchain.cpp:40
+ const llvm::opt::ArgList ) {
+  if (Args.getLastArg(options::OPT_gcc_toolchain))
+return true;

This logic (if `--gcc-toolchain=` is available or `lib/crt0.o` is present, 
select `RISCVToolChain`; otherwise `BareMetal`) is strange.

Can someone shed light on what this `RISCVToolChain` is intended and which 
`crt0.o` is used?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91442/new/

https://reviews.llvm.org/D91442

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-27 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/67166

>From 686eff52ac0878fa9545481eaf32b47350c68be8 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Fri, 22 Sep 2023 08:21:21 -0500
Subject: [PATCH 1/8] [InstSimplify] Add tests for simplify `llvm.ptrmask`; NFC

Differential Revision: https://reviews.llvm.org/D156632
---
 llvm/test/Transforms/InstSimplify/ptrmask.ll | 366 +++
 1 file changed, 366 insertions(+)
 create mode 100644 llvm/test/Transforms/InstSimplify/ptrmask.ll

diff --git a/llvm/test/Transforms/InstSimplify/ptrmask.ll 
b/llvm/test/Transforms/InstSimplify/ptrmask.ll
new file mode 100644
index 000..4945d4bc0edf625
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ptrmask.ll
@@ -0,0 +1,366 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+target datalayout = "p1:64:64:64:32"
+
+declare ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr addrspace(1) , i32)
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+
+declare <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1) 
>, <2 x i32>)
+declare <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr>, <2 x i64>)
+
+define ptr @ptrmask_simplify_poison_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
poison)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 poison)
+  ret ptr %r
+}
+
+define <2 x ptr addrspace(1) > @ptrmask_simplify_poison_mask_vec(<2 x ptr 
addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> @ptrmask_simplify_poison_mask_vec
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> poison)
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> poison)
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define <2 x ptr addrspace(1) > 
@ptrmask_simplify_poison_and_zero_i32_vec_fail(<2 x ptr addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> 
@ptrmask_simplify_poison_and_zero_i32_vec_fail
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> )
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> )
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define <2 x ptr> @ptrmask_simplify_undef_and_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_undef_and_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr> @ptrmask_simplify_poison_and_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_poison_and_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr> @ptrmask_simplify_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr addrspace(1) > @ptrmask_simplify_ones_i32_vec(<2 x ptr 
addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> @ptrmask_simplify_ones_i32_vec
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> )
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> )
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define ptr addrspace(1) @ptrmask_simplify_undef_mask(ptr addrspace(1) %p) {
+; CHECK-LABEL: define ptr addrspace(1) @ptrmask_simplify_undef_mask
+; CHECK-SAME: (ptr addrspace(1) [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr 
addrspace(1) [[P]], i32 undef)
+; CHECK-NEXT:ret ptr addrspace(1) [[R]]
+;
+  %r = call ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr addrspace(1) %p, i32 
undef)
+  ret ptr addrspace(1) %r
+}
+
+define 

[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-10-27 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/66583

>From 8f5e9e6024b0db8f251625669adbc5d607da83cb Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 16 Sep 2023 16:24:13 +0200
Subject: [PATCH 01/19] [clang-tidy] add modernize-use-std-numbers check

This check finds constants and function calls to math functions that can be 
replaced
with c++20's mathematical constants ('numbers' header) and offers fixit-hints.
Does not match the use of variables or macros with that value and instead, 
offers a replacement
at the definition of said variables and macros.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseStdNumbersCheck.cpp  | 377 ++
 .../clang-tidy/modernize/UseStdNumbersCheck.h |  37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   3 +-
 .../checks/modernize/use-std-numbers.rst  |  25 ++
 .../checkers/modernize/use-std-numbers.cpp| 205 ++
 8 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..d82353d74fbd0d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  UseStdNumbersCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..73584e20166f66a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -18,6 +18,7 @@
 #include "MacroToEnumCheck.h"
 #include "MakeSharedCheck.h"
 #include "MakeUniqueCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "PassByValueCheck.h"
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-macro-to-enum");
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 000..c23dc6671013bc3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,377 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr double Pi = 

[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-27 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for the contribution and sorry about the delay! I'm getting around to 
review this pull request (already done a few others). Please wait a bit. 

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


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-27 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for the contribution and sorry about the delay! I'm getting around to 
review this pull request (already done a few others). Please wait a bit. 

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


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread James E T Smith via cfe-commits

jamesETsmith wrote:

The strategy using `ProxyDiffTBase` is implemented in 88e271a. Initially, it 
caused a bunch of errors elsewhere because the compiler generated `==` and 
`<=>` member functions would cause checks like 
`std::totally_ordered_with, Proxy&>` to fail (see 
https://godbolt.org/z/nqMn1jhYx). To address that I just implemented those 
functions, I hope that's ok.

I noticed that `test_iterators.h` isn't formatted (at least not with 
clang-format 17) so I opted not to format that file after making changes to 
keep the diffs clearer. I can format that as soon as we're done tinkering in it.

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


[clang] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/11] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/11] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[PATCH] D126132: [clang-format] Fix a crash on lambda trailing return type

2023-10-27 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.
Herald added a reviewer: rymiel.

In D126132#3546767 , 
@HazardyKnusperkeks wrote:

> One should define what is the difference between `TT_LambdaArrow` and 
> `TT_TrailingReturnArrow`. But if there is a difference, then the lambda 
> arrows should stay `TT_LambdaArrow`, right?

It seems there is no difference. See 
https://github.com/llvm/llvm-project/pull/70519.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126132/new/

https://reviews.llvm.org/D126132

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


[clang] [clang-format][NFC] Delete TT_LambdaArrow (PR #70519)

2023-10-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

It's one type of TT_TrailingReturnArrow.

---
Full diff: https://github.com/llvm/llvm-project/pull/70519.diff


5 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+5-3) 
- (modified) clang/lib/Format/FormatToken.h (+1-2) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+16-18) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+6-6) 


``diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3b28f84fd8417d3..3a829cdedb77fc7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -813,8 +813,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
 CurrentState.ContainsUnwrappedBuilder = true;
   }
 
-  if (Current.is(TT_LambdaArrow) && Style.Language == FormatStyle::LK_Java)
+  if (Current.is(TT_TrailingReturnArrow) &&
+  Style.Language == FormatStyle::LK_Java) {
 CurrentState.NoLineBreak = true;
+  }
   if (Current.isMemberAccess() && Previous.is(tok::r_paren) &&
   (Previous.MatchingParen &&
(Previous.TotalLength - Previous.MatchingParen->TotalLength > 10))) {
@@ -969,7 +971,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState 
,
   //
   // is common and should be formatted like a free-standing function. The same
   // goes for wrapping before the lambda return type arrow.
-  if (Current.isNot(TT_LambdaArrow) &&
+  if (Current.isNot(TT_TrailingReturnArrow) &&
   (!Style.isJavaScript() || Current.NestingLevel != 0 ||
!PreviousNonComment || PreviousNonComment->isNot(tok::equal) ||
!Current.isOneOf(Keywords.kw_async, Keywords.kw_function))) {
@@ -1548,7 +1550,7 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState ,
   }
   if (Current.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Newline)
 CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
-  if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
+  if (Current.isOneOf(TT_LambdaLSquare, TT_TrailingReturnArrow))
 CurrentState.LastSpace = State.Column;
   if (Current.is(TT_RequiresExpression) &&
   Style.RequiresExpressionIndentation == FormatStyle::REI_Keyword) {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index acd24f836199da1..87f6a76ec5bfd39 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -100,7 +100,6 @@ namespace format {
   TYPE(JsTypeColon)
\
   TYPE(JsTypeOperator) 
\
   TYPE(JsTypeOptionalQuestion) 
\
-  TYPE(LambdaArrow)
\
   TYPE(LambdaLBrace)   
\
   TYPE(LambdaLSquare)  
\
   TYPE(LeadingJavaAnnotation)  
\
@@ -690,7 +689,7 @@ struct FormatToken {
   bool isMemberAccess() const {
 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
!isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
-TT_LambdaArrow, TT_LeadingJavaAnnotation);
+TT_LeadingJavaAnnotation);
   }
 
   bool isUnaryOperator() const {
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e0ea8bcdb07a32b..9ec8b93e39fd23a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -766,7 +766,8 @@ class AnnotatingParser {
 }
 // An arrow after an ObjC method expression is not a lambda arrow.
 if (CurrentToken->getType() == TT_ObjCMethodExpr &&
-CurrentToken->Next && CurrentToken->Next->is(TT_LambdaArrow)) {
+CurrentToken->Next &&
+CurrentToken->Next->is(TT_TrailingReturnArrow)) {
   CurrentToken->Next->overwriteFixedType(TT_Unknown);
 }
 Left->MatchingParen = CurrentToken;
@@ -1409,10 +1410,8 @@ class AnnotatingParser {
   }
   break;
 case tok::arrow:
-  if (Tok->isNot(TT_LambdaArrow) && Tok->Previous &&
-  Tok->Previous->is(tok::kw_noexcept)) {
+  if (Tok->Previous && Tok->Previous->is(tok::kw_noexcept))
 Tok->setType(TT_TrailingReturnArrow);
-  }
   break;
 default:
   break;
@@ -1689,11 +1688,11 @@ class AnnotatingParser {
 TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro, TT_IfMacro,
 TT_ForEachMacro, TT_TypenameMacro, TT_FunctionLBrace,
 TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_FatArrow,
-TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
-

[clang] [clang-format][NFC] Delete TT_LambdaArrow (PR #70519)

2023-10-27 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/70519

It's one type of TT_TrailingReturnArrow.

>From 64d622264f2e3cd3345f741965f450daa00bac5e Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 27 Oct 2023 15:33:40 -0700
Subject: [PATCH] [clang-format][NFC] Delete TT_LambdaArrow

It's one type of TT_TrailingReturnArrow.
---
 clang/lib/Format/ContinuationIndenter.cpp |  8 +++--
 clang/lib/Format/FormatToken.h|  3 +-
 clang/lib/Format/TokenAnnotator.cpp   | 34 +--
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 12 +++
 5 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3b28f84fd8417d3..3a829cdedb77fc7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -813,8 +813,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
 CurrentState.ContainsUnwrappedBuilder = true;
   }
 
-  if (Current.is(TT_LambdaArrow) && Style.Language == FormatStyle::LK_Java)
+  if (Current.is(TT_TrailingReturnArrow) &&
+  Style.Language == FormatStyle::LK_Java) {
 CurrentState.NoLineBreak = true;
+  }
   if (Current.isMemberAccess() && Previous.is(tok::r_paren) &&
   (Previous.MatchingParen &&
(Previous.TotalLength - Previous.MatchingParen->TotalLength > 10))) {
@@ -969,7 +971,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState 
,
   //
   // is common and should be formatted like a free-standing function. The same
   // goes for wrapping before the lambda return type arrow.
-  if (Current.isNot(TT_LambdaArrow) &&
+  if (Current.isNot(TT_TrailingReturnArrow) &&
   (!Style.isJavaScript() || Current.NestingLevel != 0 ||
!PreviousNonComment || PreviousNonComment->isNot(tok::equal) ||
!Current.isOneOf(Keywords.kw_async, Keywords.kw_function))) {
@@ -1548,7 +1550,7 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState ,
   }
   if (Current.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Newline)
 CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
-  if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
+  if (Current.isOneOf(TT_LambdaLSquare, TT_TrailingReturnArrow))
 CurrentState.LastSpace = State.Column;
   if (Current.is(TT_RequiresExpression) &&
   Style.RequiresExpressionIndentation == FormatStyle::REI_Keyword) {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index acd24f836199da1..87f6a76ec5bfd39 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -100,7 +100,6 @@ namespace format {
   TYPE(JsTypeColon)
\
   TYPE(JsTypeOperator) 
\
   TYPE(JsTypeOptionalQuestion) 
\
-  TYPE(LambdaArrow)
\
   TYPE(LambdaLBrace)   
\
   TYPE(LambdaLSquare)  
\
   TYPE(LeadingJavaAnnotation)  
\
@@ -690,7 +689,7 @@ struct FormatToken {
   bool isMemberAccess() const {
 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
!isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
-TT_LambdaArrow, TT_LeadingJavaAnnotation);
+TT_LeadingJavaAnnotation);
   }
 
   bool isUnaryOperator() const {
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e0ea8bcdb07a32b..9ec8b93e39fd23a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -766,7 +766,8 @@ class AnnotatingParser {
 }
 // An arrow after an ObjC method expression is not a lambda arrow.
 if (CurrentToken->getType() == TT_ObjCMethodExpr &&
-CurrentToken->Next && CurrentToken->Next->is(TT_LambdaArrow)) {
+CurrentToken->Next &&
+CurrentToken->Next->is(TT_TrailingReturnArrow)) {
   CurrentToken->Next->overwriteFixedType(TT_Unknown);
 }
 Left->MatchingParen = CurrentToken;
@@ -1409,10 +1410,8 @@ class AnnotatingParser {
   }
   break;
 case tok::arrow:
-  if (Tok->isNot(TT_LambdaArrow) && Tok->Previous &&
-  Tok->Previous->is(tok::kw_noexcept)) {
+  if (Tok->Previous && Tok->Previous->is(tok::kw_noexcept))
 Tok->setType(TT_TrailingReturnArrow);
-  }
   break;
 default:
   break;
@@ -1689,11 +1688,11 @@ class AnnotatingParser {
 TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro, TT_IfMacro,
 TT_ForEachMacro, TT_TypenameMacro, TT_FunctionLBrace,
  

[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-27 Thread via cfe-commits

goldsteinn wrote:

> The InstCombine/ptrmask.ll test is failing in CI.

Bah, forgot to rebase the instcombine ptrmask tests ontop of simplication fix.

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


[clang] [AMDGPU] make v32i16/v32f16 legal (PR #70484)

2023-10-27 Thread Changpeng Fang via cfe-commits

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


[clang] [LLVM][DWARF] Add support for monolithic types in .debug_names (PR #70512)

2023-10-27 Thread Alexander Yermolovich via cfe-commits

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-10-27 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] Bfi precision (PR #66285)

2023-10-27 Thread Matthias Braun via cfe-commits

MatzeB wrote:

And digging even deeper:
- FWIW I noticed that I only used `clang -c` as benchmark previously, should 
have used `clang -c -O3` resulting in this:
```
Old-BFI:  insn: 37,821,687,947  (baseline)
New-BFI:  insn: 38,133,312,923  +0.82%
Old-BFI, no-cold: insn: 37,423,365,184  -1.05%
New-BFI, no-cold: insn: 37,438,736,713  -1.01%
```
- The problematic part of the code that is inlined/not-inlined is actually 
marked as `LLVM_UNLIKELY` here: 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/DenseMap.h#L607
  and intuitively one would think that it is probably best to not inline `grow` 
 (as will happen with the new BFI version)
- In practice not-inlining `grow` mostly ends up being worse because of 
knock-on effects as far as I can tell. These are the inlining decisions I 
noticed for the most prominent situation:
- `grow` inlined (Old-BFI):
 - Instruction::getMetadataImpl
 -> Value::getMetadata   not inlined
 -> DenseMap::operator[] inlined
 -> DenseMap::FindAndConstruct   inlined
 -> DenseMap::InsertIntoBucket   not inlined, size
   likely too big with `grow` inlined here
 -> DenseMap::grow   inlined
- `grow` inlined (New-BFI):
 - Instruction::getMadataImpl
 -> Value::getMetadata  inlined
 -> DenseMap::operator[]inlined
 -> DenseMap::FindAndConstruct  not inlined, size
 -> DenseMap::InsertIntoBucket  inlined
 -> DenseMap::grow  not inlined
 
Though if you look into this then I would state that the code got better for 
the wrong reasons! Not inlining `grow` is a sensible decision in this context 
and the `LLVM_UNLIKELY` annotation makes sense (I actually added some counters 
and see the unlikely branch taken somewhere between 1% and 10% of the cases 
depending on inputs, so seems sensible).

Unfortunately the particular code here `getMetadataImpl` never inserts new 
things into the map, but unfortunately `operator[]` gives you that behavior by 
default so nobody noticed. So not inlining `InsertIntoBucket` happened to be a 
great decision previously that the compiler did by accident without having good 
data to support this. Now with better but still insufficient data (as this is 
PGO) we happen to make the decisions that ends up being worse.

Long story short: This ended up another of the many stories where the compiler 
cannot make the right inlining decisions without having actual runtime data. It 
tends to make a better decision based on the data that ends up being wrong 
anyway here. I'm gonna leave things as is and rather put up some improvements 
to LLVM code instead!

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


[clang] [LLVM][DWARF] Add support for monolithic types in .debug_names (PR #70512)

2023-10-27 Thread Alexander Yermolovich via cfe-commits

https://github.com/ayermolo updated 
https://github.com/llvm/llvm-project/pull/70512

>From 1c6a604df93b833c3bb9c7d34f4f27415592dbe5 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich 
Date: Thu, 5 Oct 2023 12:39:02 -0700
Subject: [PATCH] [LLVM][DWARF] Add support for monolithic types in
 .debug_names

Enable Type Units with DWARF5 accelerator tables for monolithic DWARF.
Implementation relies on linker to tombstone offset in LocalTU list to -1 when
it deduplciates type units using COMDAT.
---
 llvm/include/llvm/CodeGen/AccelTable.h|  64 +--
 llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp| 173 --
 .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h |   2 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  37 +++-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h  |  12 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp |   4 +
 llvm/lib/CodeGen/AsmPrinter/DwarfFile.h   |  20 ++
 llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp |   6 +
 llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h   |  15 ++
 llvm/lib/DWARFLinker/DWARFStreamer.cpp|  18 +-
 .../DWARFLinkerParallel/DWARFEmitterImpl.cpp  |  13 +-
 .../test/DebugInfo/X86/accel-tables-dwarf5.ll |   1 -
 .../test/DebugInfo/X86/debug-names-dwarf64.ll |   8 +-
 .../X86/debug-names-types-monolithic.ll   | 163 +
 .../DebugInfo/X86/debug-names-types-split.ll  |  57 ++
 .../ARM/dwarf5-dwarf4-combination-macho.test  |  14 +-
 16 files changed, 503 insertions(+), 104 deletions(-)
 create mode 100644 llvm/test/DebugInfo/X86/debug-names-types-monolithic.ll
 create mode 100644 llvm/test/DebugInfo/X86/debug-names-types-split.ll

diff --git a/llvm/include/llvm/CodeGen/AccelTable.h 
b/llvm/include/llvm/CodeGen/AccelTable.h
index d4e21b2ac8e7ebc..d948b7d82b85979 100644
--- a/llvm/include/llvm/CodeGen/AccelTable.h
+++ b/llvm/include/llvm/CodeGen/AccelTable.h
@@ -16,7 +16,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/CodeGen/DIE.h"
@@ -104,10 +103,13 @@
 namespace llvm {
 
 class AsmPrinter;
-class DwarfCompileUnit;
+class DwarfUnit;
 class DwarfDebug;
+class DwarfTypeUnit;
 class MCSymbol;
 class raw_ostream;
+struct TypeUnitMetaInfo;
+using TUVectorTy = SmallVector;
 
 /// Interface which the different types of accelerator table data have to
 /// conform. It serves as a base class for different values of the template
@@ -197,6 +199,9 @@ template  class AccelTable : public 
AccelTableBase {
 
   template 
   void addName(DwarfStringPoolEntryRef Name, Types &&... Args);
+  void clear() { Entries.clear(); }
+  void addEntries(AccelTable );
+  const StringEntries getEntries() const { return Entries; }
 };
 
 template 
@@ -250,11 +255,21 @@ class AppleAccelTableData : public AccelTableData {
 /// emitDWARF5AccelTable function.
 class DWARF5AccelTableData : public AccelTableData {
 public:
+  struct AttributeEncoding {
+dwarf::Index Index;
+dwarf::Form Form;
+  };
   static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
 
-  DWARF5AccelTableData(const DIE , const DwarfCompileUnit );
-  DWARF5AccelTableData(uint64_t DieOffset, unsigned DieTag, unsigned CUIndex)
-  : OffsetVal(DieOffset), DieTag(DieTag), UnitID(CUIndex) {}
+  DWARF5AccelTableData(const DIE , const DwarfUnit ,
+   const bool IsTU = false);
+  DWARF5AccelTableData(const uint64_t DieOffset, const unsigned DieTag,
+   const unsigned Index, const bool IsTU = false)
+  : OffsetVal(DieOffset) {
+Data.DieTag = DieTag;
+Data.UnitID = Index;
+Data.IsTU = IsTU;
+  }
 
 #ifndef NDEBUG
   void print(raw_ostream ) const override;
@@ -265,18 +280,25 @@ class DWARF5AccelTableData : public AccelTableData {
"Accessing DIE Offset before normalizing.");
 return std::get(OffsetVal);
   }
-  unsigned getDieTag() const { return DieTag; }
-  unsigned getUnitID() const { return UnitID; }
+  unsigned getDieTag() const { return Data.DieTag; }
+  unsigned getUnitID() const { return Data.UnitID; }
+  bool isTU() const { return Data.IsTU; }
   void normalizeDIEToOffset() {
 assert(std::holds_alternative(OffsetVal) &&
"Accessing offset after normalizing.");
 OffsetVal = std::get(OffsetVal)->getOffset();
   }
+  bool isNormalized() const {
+return std::holds_alternative(OffsetVal);
+  }
 
 protected:
   std::variant OffsetVal;
-  unsigned DieTag;
-  unsigned UnitID;
+  struct MetaData {
+uint32_t DieTag : 16;
+uint32_t UnitID : 15;
+uint32_t IsTU : 1;
+  } Data;
 
   uint64_t order() const override { return getDieOffset(); }
 };
@@ -288,7 +310,19 @@ class DWARF5AccelTable : public 
AccelTable {
   void convertDieToOffset() {
 for (auto  : Entries) {
   for (AccelTableData *Value : Entry.second.Values) {
-static_cast(Value)->normalizeDIEToOffset();
+

[clang] [LLVM][DWARF] Add support for monolithic types in .debug_names (PR #70512)

2023-10-27 Thread Jonas Devlieghere via cfe-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/70512

>From 1c6a604df93b833c3bb9c7d34f4f27415592dbe5 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich 
Date: Thu, 5 Oct 2023 12:39:02 -0700
Subject: [PATCH] [LLVM][DWARF] Add support for monolithic types in
 .debug_names

Enable Type Units with DWARF5 accelerator tables for monolithic DWARF.
Implementation relies on linker to tombstone offset in LocalTU list to -1 when
it deduplciates type units using COMDAT.
---
 llvm/include/llvm/CodeGen/AccelTable.h|  64 +--
 llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp| 173 --
 .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h |   2 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  37 +++-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h  |  12 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp |   4 +
 llvm/lib/CodeGen/AsmPrinter/DwarfFile.h   |  20 ++
 llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp |   6 +
 llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h   |  15 ++
 llvm/lib/DWARFLinker/DWARFStreamer.cpp|  18 +-
 .../DWARFLinkerParallel/DWARFEmitterImpl.cpp  |  13 +-
 .../test/DebugInfo/X86/accel-tables-dwarf5.ll |   1 -
 .../test/DebugInfo/X86/debug-names-dwarf64.ll |   8 +-
 .../X86/debug-names-types-monolithic.ll   | 163 +
 .../DebugInfo/X86/debug-names-types-split.ll  |  57 ++
 .../ARM/dwarf5-dwarf4-combination-macho.test  |  14 +-
 16 files changed, 503 insertions(+), 104 deletions(-)
 create mode 100644 llvm/test/DebugInfo/X86/debug-names-types-monolithic.ll
 create mode 100644 llvm/test/DebugInfo/X86/debug-names-types-split.ll

diff --git a/llvm/include/llvm/CodeGen/AccelTable.h 
b/llvm/include/llvm/CodeGen/AccelTable.h
index d4e21b2ac8e7ebc..d948b7d82b85979 100644
--- a/llvm/include/llvm/CodeGen/AccelTable.h
+++ b/llvm/include/llvm/CodeGen/AccelTable.h
@@ -16,7 +16,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/CodeGen/DIE.h"
@@ -104,10 +103,13 @@
 namespace llvm {
 
 class AsmPrinter;
-class DwarfCompileUnit;
+class DwarfUnit;
 class DwarfDebug;
+class DwarfTypeUnit;
 class MCSymbol;
 class raw_ostream;
+struct TypeUnitMetaInfo;
+using TUVectorTy = SmallVector;
 
 /// Interface which the different types of accelerator table data have to
 /// conform. It serves as a base class for different values of the template
@@ -197,6 +199,9 @@ template  class AccelTable : public 
AccelTableBase {
 
   template 
   void addName(DwarfStringPoolEntryRef Name, Types &&... Args);
+  void clear() { Entries.clear(); }
+  void addEntries(AccelTable );
+  const StringEntries getEntries() const { return Entries; }
 };
 
 template 
@@ -250,11 +255,21 @@ class AppleAccelTableData : public AccelTableData {
 /// emitDWARF5AccelTable function.
 class DWARF5AccelTableData : public AccelTableData {
 public:
+  struct AttributeEncoding {
+dwarf::Index Index;
+dwarf::Form Form;
+  };
   static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
 
-  DWARF5AccelTableData(const DIE , const DwarfCompileUnit );
-  DWARF5AccelTableData(uint64_t DieOffset, unsigned DieTag, unsigned CUIndex)
-  : OffsetVal(DieOffset), DieTag(DieTag), UnitID(CUIndex) {}
+  DWARF5AccelTableData(const DIE , const DwarfUnit ,
+   const bool IsTU = false);
+  DWARF5AccelTableData(const uint64_t DieOffset, const unsigned DieTag,
+   const unsigned Index, const bool IsTU = false)
+  : OffsetVal(DieOffset) {
+Data.DieTag = DieTag;
+Data.UnitID = Index;
+Data.IsTU = IsTU;
+  }
 
 #ifndef NDEBUG
   void print(raw_ostream ) const override;
@@ -265,18 +280,25 @@ class DWARF5AccelTableData : public AccelTableData {
"Accessing DIE Offset before normalizing.");
 return std::get(OffsetVal);
   }
-  unsigned getDieTag() const { return DieTag; }
-  unsigned getUnitID() const { return UnitID; }
+  unsigned getDieTag() const { return Data.DieTag; }
+  unsigned getUnitID() const { return Data.UnitID; }
+  bool isTU() const { return Data.IsTU; }
   void normalizeDIEToOffset() {
 assert(std::holds_alternative(OffsetVal) &&
"Accessing offset after normalizing.");
 OffsetVal = std::get(OffsetVal)->getOffset();
   }
+  bool isNormalized() const {
+return std::holds_alternative(OffsetVal);
+  }
 
 protected:
   std::variant OffsetVal;
-  unsigned DieTag;
-  unsigned UnitID;
+  struct MetaData {
+uint32_t DieTag : 16;
+uint32_t UnitID : 15;
+uint32_t IsTU : 1;
+  } Data;
 
   uint64_t order() const override { return getDieOffset(); }
 };
@@ -288,7 +310,19 @@ class DWARF5AccelTable : public 
AccelTable {
   void convertDieToOffset() {
 for (auto  : Entries) {
   for (AccelTableData *Value : Entry.second.Values) {
-static_cast(Value)->normalizeDIEToOffset();
+

[clang] [AMDGPU] make v32i16/v32f16 legal (PR #70484)

2023-10-27 Thread Stanislav Mekhanoshin via cfe-commits

https://github.com/rampitec approved this pull request.


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


[clang] [clang] Better bitfield access units (PR #65742)

2023-10-27 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I'm planning to take a closer look at this when I have more time.  Sorry I 
haven't been more responsive here.

One very brief note: in the comments in the code, you might want to distinguish 
between the semantic width of a bitfield (i.e. the C standard notion of a 
"memory location", which has ABI significance), vs. the accesses we choose to 
generate (we don't need to generate no-op reads/writes).

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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-27 Thread Sergei Barannikov via cfe-commits


@@ -274,20 +274,27 @@ class DefaultIntArgument : 
IntArgument {
 }
 
 // This argument is more complex, it includes the enumerator type name,
-// a list of strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// a list of possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,

s-barannikov wrote:

I'm not sure I understand, could you elaborate?


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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-10-27 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/66583

>From 8f5e9e6024b0db8f251625669adbc5d607da83cb Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 16 Sep 2023 16:24:13 +0200
Subject: [PATCH 01/17] [clang-tidy] add modernize-use-std-numbers check

This check finds constants and function calls to math functions that can be 
replaced
with c++20's mathematical constants ('numbers' header) and offers fixit-hints.
Does not match the use of variables or macros with that value and instead, 
offers a replacement
at the definition of said variables and macros.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseStdNumbersCheck.cpp  | 377 ++
 .../clang-tidy/modernize/UseStdNumbersCheck.h |  37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   3 +-
 .../checks/modernize/use-std-numbers.rst  |  25 ++
 .../checkers/modernize/use-std-numbers.cpp| 205 ++
 8 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..d82353d74fbd0d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  UseStdNumbersCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..73584e20166f66a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -18,6 +18,7 @@
 #include "MacroToEnumCheck.h"
 #include "MakeSharedCheck.h"
 #include "MakeUniqueCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "PassByValueCheck.h"
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-macro-to-enum");
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 000..c23dc6671013bc3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,377 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr double Pi = 

[clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-10-27 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-27 Thread Sergei Barannikov via cfe-commits

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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-27 Thread Sergei Barannikov via cfe-commits


@@ -886,7 +893,7 @@ def ARMInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
   // must match.
   let Spellings = [GCC<"interrupt">];
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,

s-barannikov wrote:

It appears that named arguments can only be specified [after all positional 
arguments](https://github.com/llvm/llvm-project/commit/91ccbc6c1c4c121935ee4fbfa0db13ad86590a59#diff-059342ba8068cf430c4000171f8873858823c8fd473cc38aa1dc719bf0b8104aR3194-R3197).
If I move `is_string` before `opt`, this can break downstream code because 
values supplied for `opt` will now be passed to `is_string. The other option is 
to make `is_string` optional and to move it to the end of the list, but I 
really wouldn't want to do this because there is no valid default value for 
this argument.


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


[clang] [clang] Language to String function (PR #69487)

2023-10-27 Thread Yusra Syeda via cfe-commits

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


[clang] 703895b - [clang] Language to String function (#69487)

2023-10-27 Thread via cfe-commits

Author: Yusra Syeda
Date: 2023-10-27T17:22:49-04:00
New Revision: 703895b131720682a3ca596a96a7c94fb281c0e4

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

LOG: [clang] Language to String function (#69487)

This PR adds a function which converts the language to string. This is
intended to be used by the z/OS target, see the patch here:
https://github.com/llvm/llvm-project/pull/68926

-

Co-authored-by: Yusra Syeda 

Added: 


Modified: 
clang/include/clang/Basic/LangStandard.h
clang/lib/Basic/LangStandards.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 6356f16acc811e0..bc49669a82ad2db 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -43,6 +43,7 @@ enum class Language : uint8_t {
   HLSL,
   ///@}
 };
+StringRef languageToString(Language L);
 
 enum LangFeatures {
   LineComment = (1 << 0),

diff  --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index af9cf4f273920ee..ab09c7221dda92f 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -13,6 +13,39 @@
 #include "llvm/TargetParser/Triple.h"
 using namespace clang;
 
+StringRef clang::languageToString(Language L) {
+  switch (L) {
+  case Language::Unknown:
+return "Unknown";
+  case Language::Asm:
+return "Asm";
+  case Language::LLVM_IR:
+return "LLVM IR";
+  case Language::C:
+return "C";
+  case Language::CXX:
+return "C++";
+  case Language::ObjC:
+return "Objective-C";
+  case Language::ObjCXX:
+return "Objective-C++";
+  case Language::OpenCL:
+return "OpenCL";
+  case Language::OpenCLCXX:
+return "OpenCLC++";
+  case Language::CUDA:
+return "CUDA";
+  case Language::RenderScript:
+return "RenderScript";
+  case Language::HIP:
+return "HIP";
+  case Language::HLSL:
+return "HLSL";
+  }
+
+  llvm_unreachable("unhandled language kind");
+}
+
 #define LANGSTANDARD(id, name, lang, desc, features)   
\
   static const LangStandard Lang_##id = {name, desc, features, Language::lang};
 #include "clang/Basic/LangStandards.def"



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


[clang] [clang] Language to String function (PR #69487)

2023-10-27 Thread Yusra Syeda via cfe-commits

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-10-27 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Also, you might want to consider marking the offset immarg, instead of trying 
to handle variable offsets in isel.

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-10-27 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic commented:

Could you briefly comment on the tradeoff of adding an argument to the 
intrinsic, vs. pattern-matching constant offsets to the existing intrinsic?

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-10-27 Thread Eli Friedman via cfe-commits


@@ -292,7 +292,42 @@ define void @ldr_with_off_16mulvl(ptr %ptr) {
   %vscale = call i64 @llvm.vscale.i64()
   %mulvl = mul i64 %vscale, 256
   %base = getelementptr i8, ptr %ptr, i64 %mulvl
-  call void @llvm.aarch64.sme.ldr(i32 16, ptr %base)
+  call void @llvm.aarch64.sme.ldr(i32 16, ptr %base, i32 0)
+  ret void;
+}
+
+define void @ldr_with_off_var(ptr %base, i32 %off) {
+; CHECK-LABEL: ldr_with_off_var:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdsvl x8, #1
+; CHECK-NEXT:// kill: def $w1 killed $w1 def $x1
+; CHECK-NEXT:mov w12, #16 // =0x10
+; CHECK-NEXT:madd x8, x8, x1, x0
+; CHECK-NEXT:ldr za[w12, 0], [x8]
+; CHECK-NEXT:ret
+  call void @llvm.aarch64.sme.ldr(i32 16, ptr %base, i32 %off)
+  ret void;
+}
+
+define void @ldr_with_off_15imm(ptr %base) {
+; CHECK-LABEL: ldr_with_off_15imm:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:mov w12, #16 // =0x10
+; CHECK-NEXT:ldr za[w12, 15], [x0, #15, mul vl]
+; CHECK-NEXT:ret
+  call void @llvm.aarch64.sme.ldr(i32 16, ptr %base, i32 15)
+  ret void;
+}
+
+define void @ldr_with_off_16imm(ptr %base) {
+; CHECK-LABEL: ldr_with_off_16imm:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdsvl x8, #1
+; CHECK-NEXT:mov w12, #16 // =0x10
+; CHECK-NEXT:madd x8, x8, x12, x0
+; CHECK-NEXT:ldr za[w12, 0], [x8]

efriedma-quic wrote:

This looks suspicious; shouldn't w12 contain 16+16=32?

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-10-27 Thread Eli Friedman via cfe-commits

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-27 Thread Nikita Popov via cfe-commits

nikic wrote:

The InstCombine/ptrmask.ll test is failing in CI.

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-27 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson commented:

All my comments have been resolved, thank you very much!

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-10-27 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/66583

>From 8f5e9e6024b0db8f251625669adbc5d607da83cb Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 16 Sep 2023 16:24:13 +0200
Subject: [PATCH 01/16] [clang-tidy] add modernize-use-std-numbers check

This check finds constants and function calls to math functions that can be 
replaced
with c++20's mathematical constants ('numbers' header) and offers fixit-hints.
Does not match the use of variables or macros with that value and instead, 
offers a replacement
at the definition of said variables and macros.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseStdNumbersCheck.cpp  | 377 ++
 .../clang-tidy/modernize/UseStdNumbersCheck.h |  37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   3 +-
 .../checks/modernize/use-std-numbers.rst  |  25 ++
 .../checkers/modernize/use-std-numbers.cpp| 205 ++
 8 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..d82353d74fbd0d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  UseStdNumbersCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..73584e20166f66a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -18,6 +18,7 @@
 #include "MacroToEnumCheck.h"
 #include "MakeSharedCheck.h"
 #include "MakeUniqueCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "PassByValueCheck.h"
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-macro-to-enum");
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 000..c23dc6671013bc3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,377 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr double Pi = 

[clang] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread James E T Smith via cfe-commits

jamesETsmith wrote:

That's much cleaner than what I was coming up with, thanks!

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-10-27 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/66583

>From 8f5e9e6024b0db8f251625669adbc5d607da83cb Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 16 Sep 2023 16:24:13 +0200
Subject: [PATCH 01/15] [clang-tidy] add modernize-use-std-numbers check

This check finds constants and function calls to math functions that can be 
replaced
with c++20's mathematical constants ('numbers' header) and offers fixit-hints.
Does not match the use of variables or macros with that value and instead, 
offers a replacement
at the definition of said variables and macros.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseStdNumbersCheck.cpp  | 377 ++
 .../clang-tidy/modernize/UseStdNumbersCheck.h |  37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   3 +-
 .../checks/modernize/use-std-numbers.rst  |  25 ++
 .../checkers/modernize/use-std-numbers.cpp| 205 ++
 8 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..d82353d74fbd0d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  UseStdNumbersCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..73584e20166f66a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -18,6 +18,7 @@
 #include "MacroToEnumCheck.h"
 #include "MakeSharedCheck.h"
 #include "MakeUniqueCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "PassByValueCheck.h"
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-macro-to-enum");
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 000..c23dc6671013bc3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,377 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr double Pi = 

[clang] [CGExprConstant] stop calling into ConstExprEmitter for Reference type destinations (PR #70366)

2023-10-27 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[PATCH] D71659: [clang-format] Added new option to allow setting spaces before and after the operator

2023-10-27 Thread Owen Pan via Phabricator via cfe-commits
owenpan commandeered this revision.
owenpan edited reviewers, added: Luis; removed: owenpan.
Herald added a project: All.
Herald added reviewers: rymiel, HazardyKnusperkeks.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to clang/include/clang/Format/Format.h but does 
not contain an update to ClangFormatStyleOptions.rst

ClangFormatStyleOptions.rst is generated via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71659/new/

https://reviews.llvm.org/D71659

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


[clang] [CGExprConstant] stop calling into ConstExprEmitter for Reference type destinations (PR #70366)

2023-10-27 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers updated 
https://github.com/llvm/llvm-project/pull/70366

>From 52e5c1083f82c045dc0af26badf159e8b1593bd1 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers 
Date: Thu, 26 Oct 2023 11:11:29 -0700
Subject: [PATCH 1/3] [CGExprConstant] stop evaluating StringLiterals for
 non-ConstantArrayTypes

Fixes a bug introduced by
commit b54294e2c959 ("[clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] 
try ConstExprEmitter fast-path first")

In the added test case, the QualType is a LValueReferenceType.
  LValueReferenceType 0x558412998d90 'const char (&)[41]'
  `-ParenType 0x558412998d30 'const char[41]' sugar
`-ConstantArrayType 0x558412998cf0 'const char[41]' 41
  `-QualType 0x55841294c271 'const char' const
`-BuiltinType 0x55841294c270 'char'
---
 clang/lib/CodeGen/CGExprConstant.cpp   | 3 +++
 clang/test/CodeGenCXX/const-init-cxx11.cpp | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 9b67a8b3335a165..0706647bf45466d 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Sequence.h"
@@ -1358,6 +1359,8 @@ class ConstExprEmitter :
   }
 
   llvm::Constant *VisitStringLiteral(StringLiteral *E, QualType T) {
+if (!isa(T.getDesugaredType(CGM.getContext(
+  return nullptr;
 // This is a string literal initializing an array in an initializer.
 return CGM.GetConstantArrayFromStringLiteral(E);
   }
diff --git a/clang/test/CodeGenCXX/const-init-cxx11.cpp 
b/clang/test/CodeGenCXX/const-init-cxx11.cpp
index d22d78d2b94edb5..3a12fe444f137bf 100644
--- a/clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ b/clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -424,6 +424,8 @@ namespace DR2126 {
 // CHECK: @_ZN33ClassTemplateWithStaticDataMember3useE ={{.*}} constant ptr 
@_ZGRN33ClassTemplateWithStaticDataMember1SIvE1aE_
 // CHECK: @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_ = 
linkonce_odr hidden constant i32 5, comdat
 // CHECK: @_ZN39ClassTemplateWithHiddenStaticDataMember3useE ={{.*}} constant 
ptr @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_
+// CHECK: @.str.[[STR:[0-9]+]] ={{.*}} constant [9 x i8] c"12345678\00"
+// CHECK-NEXT: @e = global %struct.PR69979 { ptr @.str.[[STR]] }
 // CHECK: @_ZGRZN20InlineStaticConstRef3funEvE1i_ = linkonce_odr constant i32 
10, comdat
 // CHECK20: @_ZZN12LocalVarInit4dtorEvE1a = internal constant {{.*}} i32 103
 
@@ -632,6 +634,10 @@ struct X {
 const char *f() { return ::p; }
 }
 
+struct PR69979 {
+  const char ()[9];
+} e {"12345678"};
+
 // VirtualMembers::TemplateClass::templateMethod() must be defined in this TU,
 // not just declared.
 // CHECK: define linkonce_odr void 
@_ZN14VirtualMembers13TemplateClassIiE14templateMethodEv(ptr {{[^,]*}} %this)

>From 4cff8f0f1cb4bba84f32d3953a5abfafd13c6b09 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers 
Date: Fri, 27 Oct 2023 13:47:28 -0700
Subject: [PATCH 2/3] skip calling into ConstExprEmitter for reference type
 destinations instead

---
 clang/lib/CodeGen/CGExprConstant.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 0706647bf45466d..7eb28ae4c4ff173 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1359,8 +1359,6 @@ class ConstExprEmitter :
   }
 
   llvm::Constant *VisitStringLiteral(StringLiteral *E, QualType T) {
-if (!isa(T.getDesugaredType(CGM.getContext(
-  return nullptr;
 // This is a string literal initializing an array in an initializer.
 return CGM.GetConstantArrayFromStringLiteral(E);
   }
@@ -1778,9 +1776,10 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const 
Expr *E,
 QualType destType) {
   assert(!destType->isVoidType() && "can't emit a void constant");
 
-  if (llvm::Constant *C =
-  ConstExprEmitter(*this).Visit(const_cast(E), destType))
-return C;
+  if (!destType->isReferenceType())
+if (llvm::Constant *C =
+ConstExprEmitter(*this).Visit(const_cast(E), destType))
+  return C;
 
   Expr::EvalResult Result;
 

>From 9a33ea9b7655b510d489eede1359801e0107ff50 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers 
Date: Fri, 27 Oct 2023 13:49:46 -0700
Subject: [PATCH 3/3] remove unnecessary header

---
 clang/lib/CodeGen/CGExprConstant.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 7eb28ae4c4ff173..3f508032e30d658 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -22,7 +22,6 @@
 

[clang] [CGExprConstant] stop calling into ConstExprEmitter for Reference type destinations (PR #70366)

2023-10-27 Thread Nick Desaulniers via cfe-commits

nickdesaulniers wrote:

> I think I'd prefer to avoid calling into ConstExprEmitter at all for cases 
> involving reference binding. I think we've sort of discussed this before. 
> Maybe add a check to tryEmitPrivate()? (We already have a check in 
> tryEmitPrivateForVarInit().)

Done in 
https://github.com/llvm/llvm-project/pull/70366/commits/4cff8f0f1cb4bba84f32d3953a5abfafd13c6b09
 PTAL @efriedma-quic 

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


[clang] [CGExprConstant] stop calling into ConstExprEmitter for Reference type destinations (PR #70366)

2023-10-27 Thread Nick Desaulniers via cfe-commits

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


[clang] [CGExprConstant] stop evaluating StringLiterals for non-ConstantArrayTypes (PR #70366)

2023-10-27 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers updated 
https://github.com/llvm/llvm-project/pull/70366

>From 52e5c1083f82c045dc0af26badf159e8b1593bd1 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers 
Date: Thu, 26 Oct 2023 11:11:29 -0700
Subject: [PATCH 1/2] [CGExprConstant] stop evaluating StringLiterals for
 non-ConstantArrayTypes

Fixes a bug introduced by
commit b54294e2c959 ("[clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] 
try ConstExprEmitter fast-path first")

In the added test case, the QualType is a LValueReferenceType.
  LValueReferenceType 0x558412998d90 'const char (&)[41]'
  `-ParenType 0x558412998d30 'const char[41]' sugar
`-ConstantArrayType 0x558412998cf0 'const char[41]' 41
  `-QualType 0x55841294c271 'const char' const
`-BuiltinType 0x55841294c270 'char'
---
 clang/lib/CodeGen/CGExprConstant.cpp   | 3 +++
 clang/test/CodeGenCXX/const-init-cxx11.cpp | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 9b67a8b3335a165..0706647bf45466d 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Sequence.h"
@@ -1358,6 +1359,8 @@ class ConstExprEmitter :
   }
 
   llvm::Constant *VisitStringLiteral(StringLiteral *E, QualType T) {
+if (!isa(T.getDesugaredType(CGM.getContext(
+  return nullptr;
 // This is a string literal initializing an array in an initializer.
 return CGM.GetConstantArrayFromStringLiteral(E);
   }
diff --git a/clang/test/CodeGenCXX/const-init-cxx11.cpp 
b/clang/test/CodeGenCXX/const-init-cxx11.cpp
index d22d78d2b94edb5..3a12fe444f137bf 100644
--- a/clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ b/clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -424,6 +424,8 @@ namespace DR2126 {
 // CHECK: @_ZN33ClassTemplateWithStaticDataMember3useE ={{.*}} constant ptr 
@_ZGRN33ClassTemplateWithStaticDataMember1SIvE1aE_
 // CHECK: @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_ = 
linkonce_odr hidden constant i32 5, comdat
 // CHECK: @_ZN39ClassTemplateWithHiddenStaticDataMember3useE ={{.*}} constant 
ptr @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_
+// CHECK: @.str.[[STR:[0-9]+]] ={{.*}} constant [9 x i8] c"12345678\00"
+// CHECK-NEXT: @e = global %struct.PR69979 { ptr @.str.[[STR]] }
 // CHECK: @_ZGRZN20InlineStaticConstRef3funEvE1i_ = linkonce_odr constant i32 
10, comdat
 // CHECK20: @_ZZN12LocalVarInit4dtorEvE1a = internal constant {{.*}} i32 103
 
@@ -632,6 +634,10 @@ struct X {
 const char *f() { return ::p; }
 }
 
+struct PR69979 {
+  const char ()[9];
+} e {"12345678"};
+
 // VirtualMembers::TemplateClass::templateMethod() must be defined in this TU,
 // not just declared.
 // CHECK: define linkonce_odr void 
@_ZN14VirtualMembers13TemplateClassIiE14templateMethodEv(ptr {{[^,]*}} %this)

>From 4cff8f0f1cb4bba84f32d3953a5abfafd13c6b09 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers 
Date: Fri, 27 Oct 2023 13:47:28 -0700
Subject: [PATCH 2/2] skip calling into ConstExprEmitter for reference type
 destinations instead

---
 clang/lib/CodeGen/CGExprConstant.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 0706647bf45466d..7eb28ae4c4ff173 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1359,8 +1359,6 @@ class ConstExprEmitter :
   }
 
   llvm::Constant *VisitStringLiteral(StringLiteral *E, QualType T) {
-if (!isa(T.getDesugaredType(CGM.getContext(
-  return nullptr;
 // This is a string literal initializing an array in an initializer.
 return CGM.GetConstantArrayFromStringLiteral(E);
   }
@@ -1778,9 +1776,10 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const 
Expr *E,
 QualType destType) {
   assert(!destType->isVoidType() && "can't emit a void constant");
 
-  if (llvm::Constant *C =
-  ConstExprEmitter(*this).Visit(const_cast(E), destType))
-return C;
+  if (!destType->isReferenceType())
+if (llvm::Constant *C =
+ConstExprEmitter(*this).Visit(const_cast(E), destType))
+  return C;
 
   Expr::EvalResult Result;
 

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


[clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-10-27 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Robustify openmp test (PR #69739)

2023-10-27 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

@jdoerfert thanks for that, here's an update that focusses the check-not more 
precisely.

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


[clang] [clang] Robustify openmp test (PR #69739)

2023-10-27 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan updated 
https://github.com/llvm/llvm-project/pull/69739

>From bb391aa466577f4187af6b284ee5107090778a03 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Fri, 20 Oct 2023 11:43:08 -0400
Subject: [PATCH 1/2] [clang] Robustify open mp test

If the source path contains 'alias' this would spuriously fail.  Be
more specific about not wanting [no]alias annotations.
---
 clang/test/OpenMP/declare_variant_device_kind_codegen.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp 
b/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp
index daa14f1e3a93129..aec71bd5b5da20e 100644
--- a/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp
+++ b/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp
@@ -80,7 +80,7 @@
 
 // expected-no-diagnostics
 
-// CHECK-NOT: alias
+// CHECK-NOT: {{ (no)?alias }}
 
 // CHECK-NOT: ret i32 {{1|4|81|84}}
 // CHECK-DAG: declare {{.*}}i32 @_Z5bazzzv()

>From 47ccce0676a39eb64e5305325d88b9b101e03a26 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Fri, 27 Oct 2023 16:38:11 -0400
Subject: [PATCH 2/2] [clang] Robustify open mp test

If the source path contains 'alias' this would spuriously fail.  Be
more specific about not wanting global aliases, which is what
introduced this check.
---
 clang/test/OpenMP/declare_variant_device_kind_codegen.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp 
b/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp
index aec71bd5b5da20e..4f9a86f1e0080d9 100644
--- a/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp
+++ b/clang/test/OpenMP/declare_variant_device_kind_codegen.cpp
@@ -80,7 +80,8 @@
 
 // expected-no-diagnostics
 
-// CHECK-NOT: {{ (no)?alias }}
+// Verify no unexpected global symbol aliasing
+// CHECK-NOT: @{{[^ ]+}} = {{.*}}alias
 
 // CHECK-NOT: ret i32 {{1|4|81|84}}
 // CHECK-DAG: declare {{.*}}i32 @_Z5bazzzv()

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


[clang] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread via cfe-commits

philnik777 wrote:

You can add a base class like this: https://godbolt.org/z/ccG7jcqee

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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-27 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70381

>From 3fe63f81fcb999681daa11b2890c82fda3aaeef5 Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 26 Oct 2023 22:31:43 +0200
Subject: [PATCH] [clang] Change representation of CurLexerKind

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on
compile time tracker are consistent and range form -0.05% to -0.20%
for NewPM-O0-g, see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef=608c85ec1283638db949d73e062bcc3355001ce4=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)
---
 clang/include/clang/Lex/Preprocessor.h| 46 +++-
 clang/lib/Lex/PPCaching.cpp   |  8 +--
 clang/lib/Lex/PPLexerChange.cpp   | 20 +++
 clang/lib/Lex/Preprocessor.cpp| 67 ++-
 clang/utils/ClangVisualizers/clang.natvis |  2 +-
 5 files changed, 62 insertions(+), 81 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 18d88407ae12c90..634d3924aa2248b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = _Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -1914,7 +1909,7 @@ class Preprocessor {
 
   /// Recompute the current lexer kind based on the CurLexer/
   /// CurTokenLexer pointers.
-  void recomputeCurLexerKind();
+  void recomputeCurLexerCallback();
 
   /// Returns true if incremental processing is enabled
   bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+CurLexerCallback = 

[clang] [clang][NFC] Assert not llvm_unreachable (PR #70149)

2023-10-27 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs approved this pull request.


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


[clang] [CGExprConstant] stop evaluating StringLiterals for non-ConstantArrayTypes (PR #70366)

2023-10-27 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I think I'd prefer to avoid calling into ConstExprEmitter at all for cases 
involving reference binding.  I think we've sort of discussed this before.  
Maybe add a check to tryEmitPrivate()?  (We already have a check in 
tryEmitPrivateForVarInit().)

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


[clang-tools-extra] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-10-27 Thread Utkarsh Saxena via cfe-commits


@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+
+#define CORO_TYPE [[clang::annotate("coro_type")]]
+#define CORO_UNSAFE [[clang::annotate("coro_unsafe")]]
+
+template  struct CORO_TYPE Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T );
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+template  using Co = Gen;
+
+Gen foo_coro(const int& b);
+
+Gen plain_return_foo_decl(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+Gen foo_coro(const int& b) {
+  if (b > 0)
+co_return 1;
+  co_return 2;
+}
+
+int getInt() { return 0; }
+
+Co bar_coro(const int , int c) {
+  int x = co_await foo_coro(b);
+  int y = co_await foo_coro(1);

usx95 wrote:

This is because we never emit warnings for `auto x = SomeFunc(foo_coro(1));`
For `co_await` expr, the `func` is `await_transform`. See 
https://godbolt.org/z/soxK1KsWc
The only implementation of awaiter which could be problematic and go undetected 
is when it schedules the foo_coro on other thread.

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-27 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/67166

>From 24c65907e7e6792e2d5395102992ce3cdb42fb6d Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Fri, 22 Sep 2023 08:21:21 -0500
Subject: [PATCH 1/7] [InstSimplify] Add tests for simplify `llvm.ptrmask`; NFC

Differential Revision: https://reviews.llvm.org/D156632
---
 llvm/test/Transforms/InstSimplify/ptrmask.ll | 366 +++
 1 file changed, 366 insertions(+)
 create mode 100644 llvm/test/Transforms/InstSimplify/ptrmask.ll

diff --git a/llvm/test/Transforms/InstSimplify/ptrmask.ll 
b/llvm/test/Transforms/InstSimplify/ptrmask.ll
new file mode 100644
index 000..4945d4bc0edf625
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ptrmask.ll
@@ -0,0 +1,366 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+target datalayout = "p1:64:64:64:32"
+
+declare ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr addrspace(1) , i32)
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+
+declare <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1) 
>, <2 x i32>)
+declare <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr>, <2 x i64>)
+
+define ptr @ptrmask_simplify_poison_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
poison)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 poison)
+  ret ptr %r
+}
+
+define <2 x ptr addrspace(1) > @ptrmask_simplify_poison_mask_vec(<2 x ptr 
addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> @ptrmask_simplify_poison_mask_vec
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> poison)
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> poison)
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define <2 x ptr addrspace(1) > 
@ptrmask_simplify_poison_and_zero_i32_vec_fail(<2 x ptr addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> 
@ptrmask_simplify_poison_and_zero_i32_vec_fail
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> )
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> )
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define <2 x ptr> @ptrmask_simplify_undef_and_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_undef_and_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr> @ptrmask_simplify_poison_and_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_poison_and_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr> @ptrmask_simplify_ones_vec(<2 x ptr> %p) {
+; CHECK-LABEL: define <2 x ptr> @ptrmask_simplify_ones_vec
+; CHECK-SAME: (<2 x ptr> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr> @llvm.ptrmask.v2p0.v2i64(<2 x ptr> 
[[P]], <2 x i64> )
+; CHECK-NEXT:ret <2 x ptr> [[R]]
+;
+  %r = call <2 x ptr> @llvm.ptrmask.v2p1.v2i64(<2 x ptr> %p, <2 x i64> )
+  ret <2 x ptr> %r
+}
+
+define <2 x ptr addrspace(1) > @ptrmask_simplify_ones_i32_vec(<2 x ptr 
addrspace(1) > %p) {
+; CHECK-LABEL: define <2 x ptr addrspace(1)> @ptrmask_simplify_ones_i32_vec
+; CHECK-SAME: (<2 x ptr addrspace(1)> [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call <2 x ptr addrspace(1)> 
@llvm.ptrmask.v2p1.v2i32(<2 x ptr addrspace(1)> [[P]], <2 x i32> )
+; CHECK-NEXT:ret <2 x ptr addrspace(1)> [[R]]
+;
+  %r = call <2 x ptr addrspace(1) > @llvm.ptrmask.v2p1.v2i32(<2 x ptr 
addrspace(1) > %p, <2 x i32> )
+  ret <2 x ptr addrspace(1) > %r
+}
+
+define ptr addrspace(1) @ptrmask_simplify_undef_mask(ptr addrspace(1) %p) {
+; CHECK-LABEL: define ptr addrspace(1) @ptrmask_simplify_undef_mask
+; CHECK-SAME: (ptr addrspace(1) [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr 
addrspace(1) [[P]], i32 undef)
+; CHECK-NEXT:ret ptr addrspace(1) [[R]]
+;
+  %r = call ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr addrspace(1) %p, i32 
undef)
+  ret ptr addrspace(1) %r
+}
+
+define 

[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-27 Thread via cfe-commits


@@ -6411,6 +6411,40 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value 
*Op0, Value *Op1,
   return Constant::getNullValue(ReturnType);
 break;
   }
+  case Intrinsic::ptrmask: {
+if (isa(Op0) || isa(Op1))
+  return PoisonValue::get(Op0->getType());
+
+// NOTE: We can't apply this simplifications based on the value of Op1
+// because we need to preserve provenance.
+if (Q.isUndefValue(Op0) || match(Op0, m_Zero()))
+  return Constant::getNullValue(Op0->getType());
+
+if (Op1->getType()->getScalarSizeInBits() ==

goldsteinn wrote:

Ah you're right. Done :)

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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-27 Thread via cfe-commits

serge-sans-paille wrote:

Agreed. Sorry I pushed --force my change out of habit :-/

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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-27 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70381

>From 6a41a1f9a48135fe1a43b70904e105fe638189ce Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 26 Oct 2023 22:31:43 +0200
Subject: [PATCH] [clang] Change representation of CurLexerKind

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on
compile time tracker are consistent and range form -0.05% to -0.20%
for NewPM-O0-g, see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef=608c85ec1283638db949d73e062bcc3355001ce4=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)
---
 clang/include/clang/Lex/Preprocessor.h | 44 ++
 clang/lib/Lex/Preprocessor.cpp | 41 ++--
 2 files changed, 33 insertions(+), 52 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 18d88407ae12c90..2d59918c039b115 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = _Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+CurLexerCallback = IncludeMacroStack.back().CurLexerCallback;
 IncludeMacroStack.pop_back();
   }
 
@@ -2899,6 +2895,26 @@ class Preprocessor {
   /// \return true iff this PP is currently in a "-Wunsafe-buffer-usage"
   ///  opt-out region
   bool isPPInSafeBufferOptOutRegion(SourceLocation );
+
+private:
+  /// Helper functions to forward lexing to the actual lexer. They all share 
the
+  /// same signature.
+  static bool CLK_Lexer(Preprocessor , Token ) {
+return P.CurLexer->Lex(Result);
+  }
+  static bool 

[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-10-27 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70381

>From 7711f8c85c7e106b2662d1a2505f91f0417fac5a Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 26 Oct 2023 22:31:43 +0200
Subject: [PATCH] [clang] Change representation of CurLexerKind

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on
compile time tracker are consistent and range form -0.05% to -0.20%
for NewPM-O0-g, see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef=608c85ec1283638db949d73e062bcc3355001ce4=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)
---
 clang/include/clang/Lex/Preprocessor.h | 44 ++
 clang/lib/Lex/Preprocessor.cpp | 41 ++--
 2 files changed, 33 insertions(+), 52 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 18d88407ae12c90..2d59918c039b115 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = _Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+CurLexerCallback = IncludeMacroStack.back().CurLexerCallback;
 IncludeMacroStack.pop_back();
   }
 
@@ -2899,6 +2895,26 @@ class Preprocessor {
   /// \return true iff this PP is currently in a "-Wunsafe-buffer-usage"
   ///  opt-out region
   bool isPPInSafeBufferOptOutRegion(SourceLocation );
+
+private:
+  /// Helper functions to forward lexing to the actual lexer. They all share 
the
+  /// same signature.
+  static bool CLK_Lexer(Preprocessor , Token ) {
+return P.CurLexer->Lex(Result);
+  }
+  static bool 

[clang] 5c15922 - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-10-27 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-10-27T14:59:42-05:00
New Revision: 5c159222627e2201bee73c401be3b76f995b2336

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque pointer cleanup effort. NFC.

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 4d4c94d008c9dfc..9e4319d27858e6f 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1358,7 +1358,6 @@ llvm::Value 
*CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
  "Pointer should be in alloca address space");
   llvm::Value *SizeV = llvm::ConstantInt::get(
   Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue());
-  Addr = Builder.CreateBitCast(Addr, AllocaInt8PtrTy);
   llvm::CallInst *C =
   Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});
   C->setDoesNotThrow();
@@ -1369,7 +1368,6 @@ void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, 
llvm::Value *Addr) {
   assert(Addr->getType()->getPointerAddressSpace() ==
  CGM.getDataLayout().getAllocaAddrSpace() &&
  "Pointer should be in alloca address space");
-  Addr = Builder.CreateBitCast(Addr, AllocaInt8PtrTy);
   llvm::CallInst *C =
   Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});
   C->setDoesNotThrow();

diff  --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b639..4bd8462ab5f8be6 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1106,9 +1106,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
   if (EndOfInit.isValid()) {
-auto FinishedPtr =
-  Builder.CreateBitCast(CurPtr.getPointer(), BeginPtr.getType());
-Builder.CreateStore(FinishedPtr, EndOfInit);
+Builder.CreateStore(CurPtr.getPointer(), EndOfInit);
   }
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two

diff  --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp 
b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
index 3d2b1b8b2f78d31..15c4a3e706c9d9a 100644
--- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -367,8 +367,6 @@ template  struct GenFuncBase {
 CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
 llvm::Value *DstArrayEnd = CGF.Builder.CreateInBoundsGEP(
 CGF.Int8Ty, DstAddr.getPointer(), SizeInBytes);
-DstArrayEnd = CGF.Builder.CreateBitCast(
-DstArrayEnd, CGF.CGM.Int8PtrPtrTy, "dstarray.end");
 llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();
 
 // Create the header block and insert the phi instructions.

diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d623f8f63ae56c4..b6f941052abee85 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4449,7 +4449,7 @@ void MicrosoftCXXABI::emitThrow(CodeGenFunction , 
const CXXThrowExpr *E) {
 
   // Call into the runtime to throw the exception.
   llvm::Value *Args[] = {
-CGF.Builder.CreateBitCast(AI.getPointer(), CGM.Int8PtrTy),
+AI.getPointer(),
 TI
   };
   CGF.EmitNoreturnRuntimeCallOrInvoke(getThrowFn(), Args);



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


[clang] [OpenMP][AMDGPU] Do not include 'ockl' implementations in OpenMP (PR #70462)

2023-10-27 Thread Joseph Huber via cfe-commits

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


[clang] 5513d58 - [OpenMP][AMDGPU] Do not include 'ockl' implementations in OpenMP (#70462)

2023-10-27 Thread via cfe-commits

Author: Joseph Huber
Date: 2023-10-27T14:56:29-05:00
New Revision: 5513d58ad5da093ac94ec511e575b1d27606b737

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

LOG: [OpenMP][AMDGPU] Do not include 'ockl' implementations in OpenMP (#70462)

Summary:
The 'ockl' bitcode library from the ROCm device library contains several
implementations of functions like `printf` and `malloc`. We currently do
not depend on these in the OpenMP toolchain, so we shouldn't be linking
them. The primary motivation behind this change is the library rewriting
calls to `printf` and pulling in other unused 'hostcall' routines.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/test/Driver/amdgpu-openmp-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index d4b33ad551c433e..cad206ea4df1bc5 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -951,7 +951,8 @@ RocmInstallationDetector::getCommonBitcodeLibs(
   auto AddBCLib = [&](StringRef BCFile) { BCLibs.push_back(BCFile.str()); };
 
   AddBCLib(getOCMLPath());
-  AddBCLib(getOCKLPath());
+  if (!isOpenMP)
+AddBCLib(getOCKLPath());
   AddBCLib(getDenormalsAreZeroPath(DAZ));
   AddBCLib(getUnsafeMathPath(UnsafeMathOpt || FastRelaxedMath));
   AddBCLib(getFiniteOnlyPath(FiniteOnly || FastRelaxedMath));

diff  --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 06b6ed324e74eca..f38486ad073 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -56,7 +56,7 @@
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx803 
\
 // RUN:   --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode 
-fopenmp-new-driver %s  2>&1 | \
 // RUN: FileCheck %s --check-prefix=CHECK-LIB-DEVICE
-// CHECK-LIB-DEVICE: "-cc1" 
{{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
+// CHECK-LIB-DEVICE: "-cc1" 
{{.*}}ocml.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
 
 // RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx803 
-nogpulib \
 // RUN:   --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode 
-fopenmp-new-driver %s  2>&1 | \



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


  1   2   3   4   >