[llvm-branch-commits] [llvm] [AArch64][ISel] Select constructive SVE2 ext instruction (PR #151730)

2025-08-04 Thread Sander de Smalen via llvm-branch-commits


@@ -4069,6 +4069,22 @@ let Predicates = [HasSVE2_or_SME] in {
   let AddedComplexity = 2 in {
 def : Pat<(nxv16i8 (AArch64ext nxv16i8:$zn1, nxv16i8:$zn2, (i32 
imm0_255:$imm))),
   (EXT_ZZI_B (REG_SEQUENCE ZPR2, $zn1, zsub0, $zn2, zsub1), 
imm0_255:$imm)>;
+
+foreach VT = [nxv16i8] in
+  def : Pat<(VT (vector_splice VT:$Z1, VT:$Z2, (i64 (sve_ext_imm_0_255 
i32:$index,
+(EXT_ZZI_B  (REG_SEQUENCE ZPR2, $Z1, zsub0, $Z2, zsub1), 
imm0_255:$index)>;

sdesmalen-arm wrote:

Before I send you off on a wild goose chase, it seems I made this mistake in 
thinking before as in there _is_ a subtle difference between the two: 
https://github.com/llvm/llvm-project/pull/114411#discussion_r1824649219

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


[llvm-branch-commits] [llvm] [LoongArch] Implement isLegalAddressingMode for lsx/lasx (PR #151917)

2025-08-04 Thread via llvm-branch-commits

https://github.com/zhaoqi5 created 
https://github.com/llvm/llvm-project/pull/151917

TODO: Only add tests for general vector load and store. Maybe consider adding 
more cases?

>From e72f55129bd953cfc3b1e077dfc7a626e2ba4412 Mon Sep 17 00:00:00 2001
From: Qi Zhao 
Date: Mon, 28 Jul 2025 19:36:40 +0800
Subject: [PATCH] [LoongArch] Implement isLegalAddressingMode for lsx/lasx

TODO: Only add tests for general vector load and store.
Maybe consider adding more cases?
---
 .../LoongArch/LoongArchISelLowering.cpp   | 22 ---
 .../CodeGen/LoongArch/lasx/loop-reduce.ll | 19 
 .../test/CodeGen/LoongArch/lsx/loop-reduce.ll | 11 +-
 3 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index a5bf0e57e3053..529a6d7063106 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -8385,7 +8385,14 @@ bool 
LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
   //  2. reg + 12-bit signed offset
   //  3. reg + 14-bit signed offset left-shifted by 2
   //  4. reg1 + reg2
-  // TODO: Add more checks after support vector extension.
+  //
+  // LoongArch LSX/LASX vector extension has three basic addressing modes:
+  //  1. reg + 12-bit signed offset
+  //  2. reg + {12/11/10/9}-bit or 8-bit signed offset multiplied by element
+  //  width. ie.
+  // si8,  si8<<1,  si8<<2, si8<<3
+  //si12, si11<<1, si10<<2, si9<<3
+  //  3. reg1 + reg2
 
   // No global is ever allowed as a base.
   if (AM.BaseGV)
@@ -8393,8 +8400,17 @@ bool 
LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
 
   // Require a 12-bit signed offset or 14-bit signed offset left-shifted by 2
   // with `UAL` feature.
-  if (!isInt<12>(AM.BaseOffs) &&
-  !(isShiftedInt<14, 2>(AM.BaseOffs) && Subtarget.hasUAL()))
+  if (!isInt<12>(AM.BaseOffs) && !(isShiftedInt<14, 2>(AM.BaseOffs) &&
+   Subtarget.hasUAL() && !isa(Ty)))
+return false;
+
+  // FIXME: Is it necessary and possible to perform fine-grained processing
+  // according to vector element types?
+  if (Subtarget.hasExtLSX() && isa(Ty) &&
+  !(isInt<8>(AM.BaseOffs) || isShiftedInt<8, 1>(AM.BaseOffs) ||
+isShiftedInt<8, 2>(AM.BaseOffs) || isShiftedInt<8, 3>(AM.BaseOffs) ||
+isShiftedInt<11, 1>(AM.BaseOffs) || isShiftedInt<10, 2>(AM.BaseOffs) ||
+isShiftedInt<9, 3>(AM.BaseOffs)))
 return false;
 
   switch (AM.Scale) {
diff --git a/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll 
b/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll
index 9739d3012bf3c..6c8bfd2e287e7 100644
--- a/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll
+++ b/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll
@@ -10,26 +10,25 @@
 define dso_local void @foo() local_unnamed_addr {
 ; CHECK-LABEL: foo:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:lu12i.w $a0, -2
-; CHECK-NEXT:pcalau12i $a1, %pc_hi20(.LCPI0_0)
-; CHECK-NEXT:xvld $xr0, $a1, %pc_lo12(.LCPI0_0)
-; CHECK-NEXT:pcalau12i $a1, %pc_hi20(.LCPI0_1)
-; CHECK-NEXT:xvld $xr1, $a1, %pc_lo12(.LCPI0_1)
+; CHECK-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_0)
+; CHECK-NEXT:xvld $xr0, $a0, %pc_lo12(.LCPI0_0)
+; CHECK-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_1)
+; CHECK-NEXT:xvld $xr1, $a0, %pc_lo12(.LCPI0_1)
+; CHECK-NEXT:ori $a0, $zero, 1024
 ; CHECK-NEXT:pcalau12i $a1, %pc_hi20(a)
 ; CHECK-NEXT:addi.d $a1, $a1, %pc_lo12(a)
-; CHECK-NEXT:lu12i.w $a2, 2
 ; CHECK-NEXT:.p2align 4, , 16
 ; CHECK-NEXT:  .LBB0_1: # %vector.body
 ; CHECK-NEXT:# =>This Inner Loop Header: Depth=1
-; CHECK-NEXT:add.d $a3, $a1, $a0
-; CHECK-NEXT:xvldx $xr2, $a3, $a2
+; CHECK-NEXT:xvld $xr2, $a1, 0
 ; CHECK-NEXT:xvpermi.d $xr3, $xr2, 78
 ; CHECK-NEXT:xvori.b $xr4, $xr0, 0
 ; CHECK-NEXT:xvshuf.d $xr4, $xr0, $xr3
 ; CHECK-NEXT:xvori.b $xr3, $xr1, 0
 ; CHECK-NEXT:xvshuf.w $xr3, $xr4, $xr2
-; CHECK-NEXT:addi.d $a0, $a0, 16
-; CHECK-NEXT:xvstx $xr3, $a3, $a2
+; CHECK-NEXT:xvst $xr3, $a1, 0
+; CHECK-NEXT:addi.d $a0, $a0, -2
+; CHECK-NEXT:addi.d $a1, $a1, 16
 ; CHECK-NEXT:bnez $a0, .LBB0_1
 ; CHECK-NEXT:  # %bb.2: # %for.end
 ; CHECK-NEXT:ret
diff --git a/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll 
b/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll
index fbb4d060c9412..9d3be735efa12 100644
--- a/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll
+++ b/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll
@@ -10,18 +10,17 @@
 define dso_local void @foo() local_unnamed_addr {
 ; CHECK-LABEL: foo:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:lu12i.w $a0, -2
+; CHECK-NEXT:ori $a0, $zero, 1024
 ; CHECK-NEXT:pcalau12i $a1, %pc_hi20(a)
 ; CHECK-NEXT:addi.d $a1, $a1, %pc_lo12(a)
-; CHECK-NEXT:lu12i.w $a2, 2
 ; CHECK-NEXT:.p2align 4, , 16
 ; CHECK-NEXT:  .LBB0_1: # %vector.b

[llvm-branch-commits] [llvm] [LoongArch] Implement isLegalAddressingMode for lsx/lasx (PR #151917)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: ZhaoQi (zhaoqi5)


Changes

TODO: Only add tests for general vector load and store. Maybe consider adding 
more cases?

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


3 Files Affected:

- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+19-3) 
- (modified) llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll (+9-10) 
- (modified) llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll (+5-6) 


``diff
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index a5bf0e57e3053..529a6d7063106 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -8385,7 +8385,14 @@ bool 
LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
   //  2. reg + 12-bit signed offset
   //  3. reg + 14-bit signed offset left-shifted by 2
   //  4. reg1 + reg2
-  // TODO: Add more checks after support vector extension.
+  //
+  // LoongArch LSX/LASX vector extension has three basic addressing modes:
+  //  1. reg + 12-bit signed offset
+  //  2. reg + {12/11/10/9}-bit or 8-bit signed offset multiplied by element
+  //  width. ie.
+  // si8,  si8<<1,  si8<<2, si8<<3
+  //si12, si11<<1, si10<<2, si9<<3
+  //  3. reg1 + reg2
 
   // No global is ever allowed as a base.
   if (AM.BaseGV)
@@ -8393,8 +8400,17 @@ bool 
LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
 
   // Require a 12-bit signed offset or 14-bit signed offset left-shifted by 2
   // with `UAL` feature.
-  if (!isInt<12>(AM.BaseOffs) &&
-  !(isShiftedInt<14, 2>(AM.BaseOffs) && Subtarget.hasUAL()))
+  if (!isInt<12>(AM.BaseOffs) && !(isShiftedInt<14, 2>(AM.BaseOffs) &&
+   Subtarget.hasUAL() && !isa(Ty)))
+return false;
+
+  // FIXME: Is it necessary and possible to perform fine-grained processing
+  // according to vector element types?
+  if (Subtarget.hasExtLSX() && isa(Ty) &&
+  !(isInt<8>(AM.BaseOffs) || isShiftedInt<8, 1>(AM.BaseOffs) ||
+isShiftedInt<8, 2>(AM.BaseOffs) || isShiftedInt<8, 3>(AM.BaseOffs) ||
+isShiftedInt<11, 1>(AM.BaseOffs) || isShiftedInt<10, 2>(AM.BaseOffs) ||
+isShiftedInt<9, 3>(AM.BaseOffs)))
 return false;
 
   switch (AM.Scale) {
diff --git a/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll 
b/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll
index 9739d3012bf3c..6c8bfd2e287e7 100644
--- a/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll
+++ b/llvm/test/CodeGen/LoongArch/lasx/loop-reduce.ll
@@ -10,26 +10,25 @@
 define dso_local void @foo() local_unnamed_addr {
 ; CHECK-LABEL: foo:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:lu12i.w $a0, -2
-; CHECK-NEXT:pcalau12i $a1, %pc_hi20(.LCPI0_0)
-; CHECK-NEXT:xvld $xr0, $a1, %pc_lo12(.LCPI0_0)
-; CHECK-NEXT:pcalau12i $a1, %pc_hi20(.LCPI0_1)
-; CHECK-NEXT:xvld $xr1, $a1, %pc_lo12(.LCPI0_1)
+; CHECK-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_0)
+; CHECK-NEXT:xvld $xr0, $a0, %pc_lo12(.LCPI0_0)
+; CHECK-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_1)
+; CHECK-NEXT:xvld $xr1, $a0, %pc_lo12(.LCPI0_1)
+; CHECK-NEXT:ori $a0, $zero, 1024
 ; CHECK-NEXT:pcalau12i $a1, %pc_hi20(a)
 ; CHECK-NEXT:addi.d $a1, $a1, %pc_lo12(a)
-; CHECK-NEXT:lu12i.w $a2, 2
 ; CHECK-NEXT:.p2align 4, , 16
 ; CHECK-NEXT:  .LBB0_1: # %vector.body
 ; CHECK-NEXT:# =>This Inner Loop Header: Depth=1
-; CHECK-NEXT:add.d $a3, $a1, $a0
-; CHECK-NEXT:xvldx $xr2, $a3, $a2
+; CHECK-NEXT:xvld $xr2, $a1, 0
 ; CHECK-NEXT:xvpermi.d $xr3, $xr2, 78
 ; CHECK-NEXT:xvori.b $xr4, $xr0, 0
 ; CHECK-NEXT:xvshuf.d $xr4, $xr0, $xr3
 ; CHECK-NEXT:xvori.b $xr3, $xr1, 0
 ; CHECK-NEXT:xvshuf.w $xr3, $xr4, $xr2
-; CHECK-NEXT:addi.d $a0, $a0, 16
-; CHECK-NEXT:xvstx $xr3, $a3, $a2
+; CHECK-NEXT:xvst $xr3, $a1, 0
+; CHECK-NEXT:addi.d $a0, $a0, -2
+; CHECK-NEXT:addi.d $a1, $a1, 16
 ; CHECK-NEXT:bnez $a0, .LBB0_1
 ; CHECK-NEXT:  # %bb.2: # %for.end
 ; CHECK-NEXT:ret
diff --git a/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll 
b/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll
index fbb4d060c9412..9d3be735efa12 100644
--- a/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll
+++ b/llvm/test/CodeGen/LoongArch/lsx/loop-reduce.ll
@@ -10,18 +10,17 @@
 define dso_local void @foo() local_unnamed_addr {
 ; CHECK-LABEL: foo:
 ; CHECK:   # %bb.0: # %entry
-; CHECK-NEXT:lu12i.w $a0, -2
+; CHECK-NEXT:ori $a0, $zero, 1024
 ; CHECK-NEXT:pcalau12i $a1, %pc_hi20(a)
 ; CHECK-NEXT:addi.d $a1, $a1, %pc_lo12(a)
-; CHECK-NEXT:lu12i.w $a2, 2
 ; CHECK-NEXT:.p2align 4, , 16
 ; CHECK-NEXT:  .LBB0_1: # %vector.body
 ; CHECK-NEXT:# =>This Inner Loop Header: Depth=1
-; CHECK-NEXT:add.d $a3, $a1, $a0
-; CHECK-NEXT:vldx $vr0, $a3, $a2
+; CHECK-NEXT:vld $vr0, $a1, 0
 ; CHECK-NEXT:vshuf4i.w $vr0, $vr0, 9
-; CHECK-NEX

[llvm-branch-commits] [llvm] [LoongArch] Implement isLegalAddressingMode for lsx/lasx (PR #151917)

2025-08-04 Thread via llvm-branch-commits

zhaoqi5 wrote:

Influence to llvm-test-suite: 
https://github.com/zhaoqi5/llvm-test-suite/commit/ea9235a57671c02aa91f6bc9ab5b32c1d282b7fc.

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


[llvm-branch-commits] [clang] release/21.x: [Driver][MinGW] Always put libc argument last, even if non-standard (#149434) (PR #151933)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/151933

Backport 7f470586e10543aa12efc7e04d4d4ac814eaca35

Requested by: @mstorsjo

>From b4f45dd745ce171cdb964dab4cc085b6ad2ffe0c Mon Sep 17 00:00:00 2001
From: Keno Fischer 
Date: Wed, 30 Jul 2025 01:09:27 -0400
Subject: [PATCH] [Driver][MinGW] Always put libc argument last, even if
 non-standard (#149434)

I was attempting to build openblas with clang in msys2's `ucrt64`
environment (I'm aware of the `clang64` environment, but I wanted
libstdc++). The openblas link failed with the following:

```
clang -march=native -mtune=native -m64  -O2 -fno-asynchronous-unwind-tables -O2 
-DSMALL_MATRIX_OPT -DMS_ABI -DMAX_STACK_ALLOC=2048 -Wall -m64 
-DF_INTERFACE_GFORT -DDYNAMIC_ARCH -DSMP_SERVER -DNO_WARMUP 
-DMAX_CPU_NUMBER=512 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 
-DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -UASMNAME -UASMFNAME 
-UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME= -DASMFNAME=_ -DNAME=_ 
-DCNAME= -DCHAR_NAME=\"_\" -DCHAR_CNAME=\"\" -DNO_AFFINITY -I..  
libopenblas64_.def dllinit.obj \
-shared -o ../libopenblas64_.dll -Wl,--out-implib,../libopenblas64_.dll.a \
-Wl,--whole-archive ../libopenblas64_p-r0.3.29.a -Wl,--no-whole-archive 
-LC:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0 
-LC:/msys64/ucrt64/bin/../lib/gcc 
-LC:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/lib/../lib
 -LC:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../lib 
-LC:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/lib
 -LC:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../..  
-lgfortran -lmingwex -lmsvcrt -lquadmath -lm -lpthread -lmingwex -lmsvcrt  
-defaultlib:advapi32 -lgfortran -defaultlib:advapi32 -lgfortran

C:/msys64/ucrt64/bin/ld: 
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):
 in function `__report_error':
D:/W/B/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:157:(.text+0x59): 
undefined reference to `abort'
C:/msys64/ucrt64/bin/ld: 
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-tlsthrd.o):
 in function `___w64_mingwthr_add_key_dtor':
D:/W/B/src/mingw-w64/mingw-w64-crt/crt/tlsthrd.c:48:(.text+0xa5): undefined 
reference to `calloc'
C:/msys64/ucrt64/bin/ld: 
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-pesect.o):
 in function `_FindPESectionByName':
D:/W/B/src/mingw-w64/mingw-w64-crt/crt/pesect.c:79:(.text+0xfd): undefined 
reference to `strncmp'
```

These symbols come from the `-lmingw32` dep that the driver added and
are ordinarily found in `-lmsvcrt`, which got skipped here, because
openblas passed `-lmsvcrt` explicitly earlier in the link line. Since we
always add these libraries at the end here, I think that clang is "at
fault" (as opposed to a user or packaging mistake) and should have added
some crt here.

To preserve the intent of letting the user override which crt is chosen,
duplicate the (first) user chosen crt `-l` into this position, although
we should perhaps consider an explicit `-mcrtdll` like gcc has as well.

(cherry picked from commit 7f470586e10543aa12efc7e04d4d4ac814eaca35)
---
 clang/lib/Driver/ToolChains/MinGW.cpp | 11 +--
 clang/test/Driver/mingw-msvcrt.c  |  8 
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index b2e36ae6f97c3..4894e6a52e93d 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -85,11 +85,18 @@ void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
-  for (auto Lib : Args.getAllArgValues(options::OPT_l))
+  for (auto Lib : Args.getAllArgValues(options::OPT_l)) {
 if (StringRef(Lib).starts_with("msvcr") ||
 StringRef(Lib).starts_with("ucrt") ||
-StringRef(Lib).starts_with("crtdll"))
+StringRef(Lib).starts_with("crtdll")) {
+  std::string CRTLib = (llvm::Twine("-l") + Lib).str();
+  // Respect the user's chosen crt variant, but still provide it
+  // again as the last linker argument, because some of the libraries
+  // we added above may depend on it.
+  CmdArgs.push_back(Args.MakeArgStringRef(CRTLib));
   return;
+}
+  }
   CmdArgs.push_back("-lmsvcrt");
 }
 
diff --git a/clang/test/Driver/mingw-msvcrt.c b/clang/test/Driver/mingw-msvcrt.c
index 340ce1f57b0f8..e1648630476a0 100644
--- a/clang/test/Driver/mingw-msvcrt.c
+++ b/clang/test/Driver/mingw-msvcrt.c
@@ -7,10 +7,10 @@
 // CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32"
 // CHECK_DEFAULT-SAME: "-lmsvcrt" "-lkernel32" "{{.*}}crtend.o"
 // CHECK_MSVCR120: "-lmsvcr120"
-// CHECK_MSVCR120-SAME: "-lmingwex" "-la

[llvm-branch-commits] [clang] release/21.x: [Driver][MinGW] Always put libc argument last, even if non-standard (#149434) (PR #151933)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/151933
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver][MinGW] Always put libc argument last, even if non-standard (#149434) (PR #151933)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:

@mstorsjo What do you think about merging this PR to the release branch?

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


[llvm-branch-commits] [clang] release/21.x: [Driver][MinGW] Always put libc argument last, even if non-standard (#149434) (PR #151933)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport 7f470586e10543aa12efc7e04d4d4ac814eaca35

Requested by: @mstorsjo

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+9-2) 
- (modified) clang/test/Driver/mingw-msvcrt.c (+4-4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index b2e36ae6f97c3..4894e6a52e93d 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -85,11 +85,18 @@ void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
-  for (auto Lib : Args.getAllArgValues(options::OPT_l))
+  for (auto Lib : Args.getAllArgValues(options::OPT_l)) {
 if (StringRef(Lib).starts_with("msvcr") ||
 StringRef(Lib).starts_with("ucrt") ||
-StringRef(Lib).starts_with("crtdll"))
+StringRef(Lib).starts_with("crtdll")) {
+  std::string CRTLib = (llvm::Twine("-l") + Lib).str();
+  // Respect the user's chosen crt variant, but still provide it
+  // again as the last linker argument, because some of the libraries
+  // we added above may depend on it.
+  CmdArgs.push_back(Args.MakeArgStringRef(CRTLib));
   return;
+}
+  }
   CmdArgs.push_back("-lmsvcrt");
 }
 
diff --git a/clang/test/Driver/mingw-msvcrt.c b/clang/test/Driver/mingw-msvcrt.c
index 340ce1f57b0f8..e1648630476a0 100644
--- a/clang/test/Driver/mingw-msvcrt.c
+++ b/clang/test/Driver/mingw-msvcrt.c
@@ -7,10 +7,10 @@
 // CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32"
 // CHECK_DEFAULT-SAME: "-lmsvcrt" "-lkernel32" "{{.*}}crtend.o"
 // CHECK_MSVCR120: "-lmsvcr120"
-// CHECK_MSVCR120-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_MSVCR120-SAME: "-lmingwex" "-lmsvcr120" "-ladvapi32"
 // CHECK_UCRTBASE: "-lucrtbase"
-// CHECK_UCRTBASE-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_UCRTBASE-SAME: "-lmingwex" "-lucrtbase" "-ladvapi32"
 // CHECK_UCRT: "-lucrt"
-// CHECK_UCRT-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_UCRT-SAME: "-lmingwex" "-lucrt" "-ladvapi32"
 // CHECK_CRTDLL: "-lcrtdll"
-// CHECK_CRTDLL-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_CRTDLL-SAME: "-lmingwex" "-lcrtdll" "-ladvapi32"

``




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


[llvm-branch-commits] [clang] release/21.x: [Driver][MinGW] Always put libc argument last, even if non-standard (#149434) (PR #151933)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (llvmbot)


Changes

Backport 7f470586e10543aa12efc7e04d4d4ac814eaca35

Requested by: @mstorsjo

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+9-2) 
- (modified) clang/test/Driver/mingw-msvcrt.c (+4-4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index b2e36ae6f97c3..4894e6a52e93d 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -85,11 +85,18 @@ void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
-  for (auto Lib : Args.getAllArgValues(options::OPT_l))
+  for (auto Lib : Args.getAllArgValues(options::OPT_l)) {
 if (StringRef(Lib).starts_with("msvcr") ||
 StringRef(Lib).starts_with("ucrt") ||
-StringRef(Lib).starts_with("crtdll"))
+StringRef(Lib).starts_with("crtdll")) {
+  std::string CRTLib = (llvm::Twine("-l") + Lib).str();
+  // Respect the user's chosen crt variant, but still provide it
+  // again as the last linker argument, because some of the libraries
+  // we added above may depend on it.
+  CmdArgs.push_back(Args.MakeArgStringRef(CRTLib));
   return;
+}
+  }
   CmdArgs.push_back("-lmsvcrt");
 }
 
diff --git a/clang/test/Driver/mingw-msvcrt.c b/clang/test/Driver/mingw-msvcrt.c
index 340ce1f57b0f8..e1648630476a0 100644
--- a/clang/test/Driver/mingw-msvcrt.c
+++ b/clang/test/Driver/mingw-msvcrt.c
@@ -7,10 +7,10 @@
 // CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32"
 // CHECK_DEFAULT-SAME: "-lmsvcrt" "-lkernel32" "{{.*}}crtend.o"
 // CHECK_MSVCR120: "-lmsvcr120"
-// CHECK_MSVCR120-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_MSVCR120-SAME: "-lmingwex" "-lmsvcr120" "-ladvapi32"
 // CHECK_UCRTBASE: "-lucrtbase"
-// CHECK_UCRTBASE-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_UCRTBASE-SAME: "-lmingwex" "-lucrtbase" "-ladvapi32"
 // CHECK_UCRT: "-lucrt"
-// CHECK_UCRT-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_UCRT-SAME: "-lmingwex" "-lucrt" "-ladvapi32"
 // CHECK_CRTDLL: "-lcrtdll"
-// CHECK_CRTDLL-SAME: "-lmingwex" "-ladvapi32"
+// CHECK_CRTDLL-SAME: "-lmingwex" "-lcrtdll" "-ladvapi32"

``




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


[llvm-branch-commits] [clang] release/21.x: [Driver][MinGW] Always put libc argument last, even if non-standard (#149434) (PR #151933)

2025-08-04 Thread Martin Storsjö via llvm-branch-commits

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

LGTM

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


[llvm-branch-commits] [flang] release/21.x: [Flang] Fix crash with parametrized derived types usage (#150289) (PR #151937)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/151937
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] release/21.x: [Flang] Fix crash with parametrized derived types usage (#150289) (PR #151937)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:

@tblah What do you think about merging this PR to the release branch?

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


[llvm-branch-commits] [flang] release/21.x: [Flang] Fix crash with parametrized derived types usage (#150289) (PR #151937)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: None (llvmbot)


Changes

Backport 89e4d9f

Requested by: @tblah

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


2 Files Affected:

- (modified) flang/lib/Lower/Mangler.cpp (+12-2) 
- (added) flang/test/Lower/parametrized-derived-types.f90 (+19) 


``diff
diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index 1333e3fe349d1..e1ae86a1b5bb2 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -224,8 +224,18 @@ std::string Fortran::lower::mangle::mangleName(
   assert(paramExpr && "derived type kind param not explicit");
   std::optional init =
   Fortran::evaluate::ToInt64(paramValue->GetExplicit());
-  assert(init && "derived type kind param is not constant");
-  kinds.emplace_back(*init);
+  // TODO: put the assertion check back when parametrized derived types
+  // are supported:
+  // assert(init && "derived type kind param is not constant");
+  //
+  // The init parameter above will require a FoldingContext for proper
+  // expression evaluation to an integer constant, otherwise the
+  // compiler may crash here (see example in issue #127424).
+  if (!init) {
+TODO_NOLOC("parameterized derived types");
+  } else {
+kinds.emplace_back(*init);
+  }
 }
   }
   return fir::NameUniquer::doType(modules, procs, blockId, symbolName, kinds);
diff --git a/flang/test/Lower/parametrized-derived-types.f90 
b/flang/test/Lower/parametrized-derived-types.f90
new file mode 100644
index 0..97a40c9169d2b
--- /dev/null
+++ b/flang/test/Lower/parametrized-derived-types.f90
@@ -0,0 +1,19 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! XFAIL: *
+program main
+  TYPE ty(k1,k2)
+ INTEGER ,KIND::k1,k2=5
+ INTEGER::arr(k1:k2)=10
+ CHARACTER(LEN=k2)::CHARACTER
+  END TYPE ty
+  TYPE,EXTENDS(ty)::ty1(k3)
+ INTEGER,KIND ::k3=4
+ TYPE(ty(2,k3+1))::cmp_ty = ty(2,k3+1)(55,'HI')
+  END TYPE ty1
+  TYPE ty2(l1, l2)
+  !ERROR: not yet implemented: parameterized derived types
+ INTEGER,LEN ::l1,l2
+ TYPE(ty1(2,5)), ALLOCATABLE::ty1_cmp(:)
+  END TYPE ty2
+  TYPE(ty2(4,8)) ::ty2_obj
+end program main

``




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


[llvm-branch-commits] [flang] release/21.x: [Flang] Fix crash with parametrized derived types usage (#150289) (PR #151937)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/151937

Backport 89e4d9f

Requested by: @tblah

>From bfff2eb3e5216113c2e4cac56c0a0a0e49d38256 Mon Sep 17 00:00:00 2001
From: Carlos Seo 
Date: Fri, 1 Aug 2025 11:20:09 -0300
Subject: [PATCH] [Flang] Fix crash with parametrized derived types usage
 (#150289)

The current mangleName implementation doesn't take a FoldingContext,
which prevents the proper evaluation of expressions containing parameter
references to an integer constant. Since parametrized derived types are
not yet implemented, the compiler will crash there in some cases (see
example in issue #127424).

This is a workaround so that doesn't happen until the feature is
properly implemented.

Fixes #127424

(cherry picked from commit 89e4d9f905f7abbf5803c011ab6fba26796ced30)
---
 flang/lib/Lower/Mangler.cpp   | 14 --
 .../test/Lower/parametrized-derived-types.f90 | 19 +++
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Lower/parametrized-derived-types.f90

diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index 1333e3fe349d1..e1ae86a1b5bb2 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -224,8 +224,18 @@ std::string Fortran::lower::mangle::mangleName(
   assert(paramExpr && "derived type kind param not explicit");
   std::optional init =
   Fortran::evaluate::ToInt64(paramValue->GetExplicit());
-  assert(init && "derived type kind param is not constant");
-  kinds.emplace_back(*init);
+  // TODO: put the assertion check back when parametrized derived types
+  // are supported:
+  // assert(init && "derived type kind param is not constant");
+  //
+  // The init parameter above will require a FoldingContext for proper
+  // expression evaluation to an integer constant, otherwise the
+  // compiler may crash here (see example in issue #127424).
+  if (!init) {
+TODO_NOLOC("parameterized derived types");
+  } else {
+kinds.emplace_back(*init);
+  }
 }
   }
   return fir::NameUniquer::doType(modules, procs, blockId, symbolName, kinds);
diff --git a/flang/test/Lower/parametrized-derived-types.f90 
b/flang/test/Lower/parametrized-derived-types.f90
new file mode 100644
index 0..97a40c9169d2b
--- /dev/null
+++ b/flang/test/Lower/parametrized-derived-types.f90
@@ -0,0 +1,19 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! XFAIL: *
+program main
+  TYPE ty(k1,k2)
+ INTEGER ,KIND::k1,k2=5
+ INTEGER::arr(k1:k2)=10
+ CHARACTER(LEN=k2)::CHARACTER
+  END TYPE ty
+  TYPE,EXTENDS(ty)::ty1(k3)
+ INTEGER,KIND ::k3=4
+ TYPE(ty(2,k3+1))::cmp_ty = ty(2,k3+1)(55,'HI')
+  END TYPE ty1
+  TYPE ty2(l1, l2)
+  !ERROR: not yet implemented: parameterized derived types
+ INTEGER,LEN ::l1,l2
+ TYPE(ty1(2,5)), ALLOCATABLE::ty1_cmp(:)
+  END TYPE ty2
+  TYPE(ty2(4,8)) ::ty2_obj
+end program main

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


[llvm-branch-commits] [clang] [llvm] [OpenMP][clang] 6.0: num_threads strict (part 3: codegen) (PR #146405)

2025-08-04 Thread Robert Imschweiler via llvm-branch-commits


@@ -1260,21 +1260,30 @@ void 
CGOpenMPRuntimeGPU::emitParallelCall(CodeGenFunction &CGF,
   NumThreadsVal = Bld.CreateZExtOrTrunc(NumThreadsVal, CGF.Int32Ty);
 
 assert(IfCondVal && "Expected a value");
+RuntimeFunction FnID = OMPRTL___kmpc_parallel_51;
 llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
-llvm::Value *Args[] = {
-RTLoc,
-getThreadID(CGF, Loc),
-IfCondVal,
-NumThreadsVal,
-llvm::ConstantInt::get(CGF.Int32Ty, -1),
-FnPtr,
-ID,
-Bld.CreateBitOrPointerCast(CapturedVarsAddrs.emitRawPointer(CGF),
-   CGF.VoidPtrPtrTy),
-llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())};
-CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
-CGM.getModule(), OMPRTL___kmpc_parallel_51),
-Args);
+llvm::SmallVector Args(
+{RTLoc, getThreadID(CGF, Loc), IfCondVal, NumThreadsVal,
+ llvm::ConstantInt::get(CGF.Int32Ty, -1), FnPtr, ID,
+ Bld.CreateBitOrPointerCast(CapturedVarsAddrs.emitRawPointer(CGF),
+CGF.VoidPtrPtrTy),
+ llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())});
+if (NumThreadsModifier == OMPC_NUMTHREADS_strict) {
+  FnID = OMPRTL___kmpc_parallel_60;
+  // OpenMP 6.0, 10.4: "If no severity clause is specified then the effect
+  // is as if sev-level is fatal."
+  Args.append(
+  {llvm::ConstantInt::get(CGM.Int32Ty, true),
+   llvm::ConstantInt::get(CGM.Int32Ty,
+  Severity == OMPC_SEVERITY_warning ? 1 : 2)});
+  if (Message)
+
Args.push_back(CGF.EmitStringLiteralLValue(cast(Message))
+   .getPointer(CGF));

ro-i wrote:

done

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


[llvm-branch-commits] [llvm] [AArch64][ISel] Select constructive SVE2 ext instruction (PR #151730)

2025-08-04 Thread Sander de Smalen via llvm-branch-commits


@@ -4069,6 +4069,22 @@ let Predicates = [HasSVE2_or_SME] in {
   let AddedComplexity = 2 in {
 def : Pat<(nxv16i8 (AArch64ext nxv16i8:$zn1, nxv16i8:$zn2, (i32 
imm0_255:$imm))),
   (EXT_ZZI_B (REG_SEQUENCE ZPR2, $zn1, zsub0, $zn2, zsub1), 
imm0_255:$imm)>;
+
+foreach VT = [nxv16i8] in
+  def : Pat<(VT (vector_splice VT:$Z1, VT:$Z2, (i64 (sve_ext_imm_0_255 
i32:$index,
+(EXT_ZZI_B  (REG_SEQUENCE ZPR2, $Z1, zsub0, $Z2, zsub1), 
imm0_255:$index)>;

sdesmalen-arm wrote:

Why does this result in different output as the pattern above? is this because 
of the change you've made in #151729?

I would actually expect `vector_splice` and `AArch64ISD::EXT` to have the same 
semantics (and if there isn't some subtle difference between `AArch64ISD::EXT` 
and `ISD::VECTOR_SPLICE`, then I think we should remove the former)

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


[llvm-branch-commits] [libcxx] release/21.x: [libc++][hardening] Add a greppable prefix to assertion messages. (#150560) (PR #151921)

2025-08-04 Thread Konstantin Varlamov via llvm-branch-commits

https://github.com/var-const approved this pull request.


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


[llvm-branch-commits] [clang] [llvm] [OpenMP][clang] 6.0: num_threads strict (part 3: codegen) (PR #146405)

2025-08-04 Thread Alexey Bataev via llvm-branch-commits

https://github.com/alexey-bataev approved this pull request.


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


[llvm-branch-commits] [clang] [LifetimeSafety] Add language option for experimental lifetime safety… (PR #152027)

2025-08-04 Thread Utkarsh Saxena via llvm-branch-commits

https://github.com/usx95 milestoned 
https://github.com/llvm/llvm-project/pull/152027
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Add language option for experimental lifetime safety… (PR #152027)

2025-08-04 Thread Utkarsh Saxena via llvm-branch-commits

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


[llvm-branch-commits] [clang] [LifetimeSafety] Add language option for experimental lifetime safety… (PR #152027)

2025-08-04 Thread Utkarsh Saxena via llvm-branch-commits

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


[llvm-branch-commits] [flang] [flang][OpenMP] Make OpenMPCriticalConstruct follow block structure (PR #152007)

2025-08-04 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/152007

>From d57337ec742dd2ace259ab7599b587265723840d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 4 Aug 2025 07:59:47 -0500
Subject: [PATCH 1/2] [flang][OpenMP] Make OpenMPCriticalConstruct follow block
 structure

This allows not having the END CRITICAL directive in certain situations.
Update semantic checks and symbol resolution.
---
 flang/include/flang/Parser/parse-tree.h   |   6 +-
 .../flang}/Semantics/openmp-utils.h   |   0
 flang/lib/Lower/OpenMP/OpenMP.cpp |  24 +++-
 flang/lib/Parser/openmp-parsers.cpp   |  13 +-
 flang/lib/Parser/unparse.cpp  |   4 +-
 flang/lib/Semantics/check-omp-atomic.cpp  |   2 +-
 flang/lib/Semantics/check-omp-loop.cpp|   2 +-
 .../lib/Semantics/check-omp-metadirective.cpp |   3 +-
 flang/lib/Semantics/check-omp-structure.cpp   | 124 --
 flang/lib/Semantics/openmp-utils.cpp  |   2 +-
 flang/lib/Semantics/resolve-directives.cpp|   6 +-
 flang/lib/Semantics/resolve-names.cpp |  69 +-
 flang/lib/Semantics/unparse-with-symbols.cpp  |  14 --
 .../OpenMP/critical-unparse-with-symbols.f90  |   4 +-
 .../test/Semantics/OpenMP/sync-critical01.f90 |   8 +-
 .../test/Semantics/OpenMP/sync-critical02.f90 |   8 +-
 16 files changed, 155 insertions(+), 134 deletions(-)
 rename flang/{lib => include/flang}/Semantics/openmp-utils.h (100%)

diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 8302e40984af0..e72190f019dd1 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4986,9 +4986,9 @@ struct OmpEndCriticalDirective {
   CharBlock source;
   std::tuple> t;
 };
-struct OpenMPCriticalConstruct {
-  TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct);
-  std::tuple t;
+
+struct OpenMPCriticalConstruct : public OmpBlockConstruct {
+  INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct, 
OmpBlockConstruct);
 };
 
 // 2.11.3 allocate -> ALLOCATE [(variable-name-list)] [clause]
diff --git a/flang/lib/Semantics/openmp-utils.h 
b/flang/include/flang/Semantics/openmp-utils.h
similarity index 100%
rename from flang/lib/Semantics/openmp-utils.h
rename to flang/include/flang/Semantics/openmp-utils.h
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index d1efd8e8d2ca7..f7a7dd8fbe6a0 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -34,6 +34,7 @@
 #include "flang/Parser/openmp-utils.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/openmp-directive-sets.h"
+#include "flang/Semantics/openmp-utils.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Support/Flags.h"
 #include "flang/Support/OpenMP-utils.h"
@@ -3797,18 +3798,29 @@ static void genOMP(lower::AbstractConverter &converter, 
lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPCriticalConstruct &criticalConstruct) {
-  const auto &cd = std::get(criticalConstruct.t);
-  List clauses =
-  makeClauses(std::get(cd.t), semaCtx);
+  const parser::OmpDirectiveSpecification &beginSpec =
+  criticalConstruct.BeginDir();
+  List clauses = makeClauses(beginSpec.Clauses(), semaCtx);
 
   ConstructQueue queue{buildConstructQueue(
-  converter.getFirOpBuilder().getModule(), semaCtx, eval, cd.source,
+  converter.getFirOpBuilder().getModule(), semaCtx, eval, beginSpec.source,
   llvm::omp::Directive::OMPD_critical, clauses)};
 
-  const auto &name = std::get>(cd.t);
+  std::optional critName;
+  const parser::OmpArgumentList &args = beginSpec.Arguments();
+  if (!args.v.empty()) {
+// All of these things should be guaranteed to exist after semantic checks.
+auto *object = parser::Unwrap(args.v.front());
+assert(object && "Expecting object as argument");
+auto *designator = semantics::omp::GetDesignatorFromObj(*object);
+assert(designator && "Expecting desginator in argument");
+auto *name = semantics::getDesignatorNameIfDataRef(*designator);
+assert(name && "Expecting dataref in designator");
+critName = *name;
+  }
   mlir::Location currentLocation = converter.getCurrentLocation();
   genCriticalOp(converter, symTable, semaCtx, eval, currentLocation, queue,
-queue.begin(), name);
+queue.begin(), critName);
 }
 
 static void genOMP(lower::AbstractConverter &converter, lower::SymMap 
&symTable,
diff --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 84d1e81bfd9be..ab23e7d70de4f 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1758,17 +1758,8 @@ 
TYPE_PARSER(sourced(construct(
 TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
-// 2.13.2 OMP CRITICAL
-TYPE_PARSER(sta

[llvm-branch-commits] [flang] [flang][OpenMP] Make OpenMPCriticalConstruct follow block structure (PR #152007)

2025-08-04 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- 
flang/include/flang/Parser/parse-tree.h flang/lib/Lower/OpenMP/OpenMP.cpp 
flang/lib/Parser/openmp-parsers.cpp flang/lib/Parser/unparse.cpp 
flang/lib/Semantics/check-omp-atomic.cpp flang/lib/Semantics/check-omp-loop.cpp 
flang/lib/Semantics/check-omp-metadirective.cpp 
flang/lib/Semantics/check-omp-structure.cpp 
flang/lib/Semantics/openmp-utils.cpp flang/lib/Semantics/resolve-directives.cpp 
flang/lib/Semantics/resolve-names.cpp 
flang/lib/Semantics/unparse-with-symbols.cpp 
flang/include/flang/Semantics/openmp-utils.h
``





View the diff from clang-format here.


``diff
diff --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index ab23e7d70..46b148610 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1758,8 +1758,8 @@ 
TYPE_PARSER(sourced(construct(
 TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
-TYPE_PARSER(construct(OmpBlockConstructParser{
-llvm::omp::Directive::OMPD_critical}))
+TYPE_PARSER(construct(
+OmpBlockConstructParser{llvm::omp::Directive::OMPD_critical}))
 
 // 2.11.3 Executable Allocate directive
 TYPE_PARSER(

``




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


[llvm-branch-commits] [flang] [flang][OpenMP] Make OpenMPCriticalConstruct follow block structure (PR #152007)

2025-08-04 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/152007

This allows not having the END CRITICAL directive in certain situations. Update 
semantic checks and symbol resolution.

>From d57337ec742dd2ace259ab7599b587265723840d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 4 Aug 2025 07:59:47 -0500
Subject: [PATCH] [flang][OpenMP] Make OpenMPCriticalConstruct follow block
 structure

This allows not having the END CRITICAL directive in certain situations.
Update semantic checks and symbol resolution.
---
 flang/include/flang/Parser/parse-tree.h   |   6 +-
 .../flang}/Semantics/openmp-utils.h   |   0
 flang/lib/Lower/OpenMP/OpenMP.cpp |  24 +++-
 flang/lib/Parser/openmp-parsers.cpp   |  13 +-
 flang/lib/Parser/unparse.cpp  |   4 +-
 flang/lib/Semantics/check-omp-atomic.cpp  |   2 +-
 flang/lib/Semantics/check-omp-loop.cpp|   2 +-
 .../lib/Semantics/check-omp-metadirective.cpp |   3 +-
 flang/lib/Semantics/check-omp-structure.cpp   | 124 --
 flang/lib/Semantics/openmp-utils.cpp  |   2 +-
 flang/lib/Semantics/resolve-directives.cpp|   6 +-
 flang/lib/Semantics/resolve-names.cpp |  69 +-
 flang/lib/Semantics/unparse-with-symbols.cpp  |  14 --
 .../OpenMP/critical-unparse-with-symbols.f90  |   4 +-
 .../test/Semantics/OpenMP/sync-critical01.f90 |   8 +-
 .../test/Semantics/OpenMP/sync-critical02.f90 |   8 +-
 16 files changed, 155 insertions(+), 134 deletions(-)
 rename flang/{lib => include/flang}/Semantics/openmp-utils.h (100%)

diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 8302e40984af0..e72190f019dd1 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4986,9 +4986,9 @@ struct OmpEndCriticalDirective {
   CharBlock source;
   std::tuple> t;
 };
-struct OpenMPCriticalConstruct {
-  TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct);
-  std::tuple t;
+
+struct OpenMPCriticalConstruct : public OmpBlockConstruct {
+  INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct, 
OmpBlockConstruct);
 };
 
 // 2.11.3 allocate -> ALLOCATE [(variable-name-list)] [clause]
diff --git a/flang/lib/Semantics/openmp-utils.h 
b/flang/include/flang/Semantics/openmp-utils.h
similarity index 100%
rename from flang/lib/Semantics/openmp-utils.h
rename to flang/include/flang/Semantics/openmp-utils.h
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index d1efd8e8d2ca7..f7a7dd8fbe6a0 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -34,6 +34,7 @@
 #include "flang/Parser/openmp-utils.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/openmp-directive-sets.h"
+#include "flang/Semantics/openmp-utils.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Support/Flags.h"
 #include "flang/Support/OpenMP-utils.h"
@@ -3797,18 +3798,29 @@ static void genOMP(lower::AbstractConverter &converter, 
lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPCriticalConstruct &criticalConstruct) {
-  const auto &cd = std::get(criticalConstruct.t);
-  List clauses =
-  makeClauses(std::get(cd.t), semaCtx);
+  const parser::OmpDirectiveSpecification &beginSpec =
+  criticalConstruct.BeginDir();
+  List clauses = makeClauses(beginSpec.Clauses(), semaCtx);
 
   ConstructQueue queue{buildConstructQueue(
-  converter.getFirOpBuilder().getModule(), semaCtx, eval, cd.source,
+  converter.getFirOpBuilder().getModule(), semaCtx, eval, beginSpec.source,
   llvm::omp::Directive::OMPD_critical, clauses)};
 
-  const auto &name = std::get>(cd.t);
+  std::optional critName;
+  const parser::OmpArgumentList &args = beginSpec.Arguments();
+  if (!args.v.empty()) {
+// All of these things should be guaranteed to exist after semantic checks.
+auto *object = parser::Unwrap(args.v.front());
+assert(object && "Expecting object as argument");
+auto *designator = semantics::omp::GetDesignatorFromObj(*object);
+assert(designator && "Expecting desginator in argument");
+auto *name = semantics::getDesignatorNameIfDataRef(*designator);
+assert(name && "Expecting dataref in designator");
+critName = *name;
+  }
   mlir::Location currentLocation = converter.getCurrentLocation();
   genCriticalOp(converter, symTable, semaCtx, eval, currentLocation, queue,
-queue.begin(), name);
+queue.begin(), critName);
 }
 
 static void genOMP(lower::AbstractConverter &converter, lower::SymMap 
&symTable,
diff --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 84d1e81bfd9be..ab23e7d70de4f 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1758,17 +1758,8 @@ 
TYPE_PARSER(source

[llvm-branch-commits] [flang] [flang][OpenMP] Make OpenMPCriticalConstruct follow block structure (PR #152007)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-parser

Author: Krzysztof Parzyszek (kparzysz)


Changes

This allows not having the END CRITICAL directive in certain situations. Update 
semantic checks and symbol resolution.

---

Patch is 24.11 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/152007.diff


16 Files Affected:

- (modified) flang/include/flang/Parser/parse-tree.h (+3-3) 
- (renamed) flang/include/flang/Semantics/openmp-utils.h () 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+18-6) 
- (modified) flang/lib/Parser/openmp-parsers.cpp (+2-11) 
- (modified) flang/lib/Parser/unparse.cpp (+1-3) 
- (modified) flang/lib/Semantics/check-omp-atomic.cpp (+1-1) 
- (modified) flang/lib/Semantics/check-omp-loop.cpp (+1-1) 
- (modified) flang/lib/Semantics/check-omp-metadirective.cpp (+1-2) 
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+81-43) 
- (modified) flang/lib/Semantics/openmp-utils.cpp (+1-1) 
- (modified) flang/lib/Semantics/resolve-directives.cpp (+3-3) 
- (modified) flang/lib/Semantics/resolve-names.cpp (+33-36) 
- (modified) flang/lib/Semantics/unparse-with-symbols.cpp (-14) 
- (modified) flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90 (+2-2) 
- (modified) flang/test/Semantics/OpenMP/sync-critical01.f90 (+4-4) 
- (modified) flang/test/Semantics/OpenMP/sync-critical02.f90 (+4-4) 


``diff
diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 8302e40984af0..e72190f019dd1 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4986,9 +4986,9 @@ struct OmpEndCriticalDirective {
   CharBlock source;
   std::tuple> t;
 };
-struct OpenMPCriticalConstruct {
-  TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct);
-  std::tuple t;
+
+struct OpenMPCriticalConstruct : public OmpBlockConstruct {
+  INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct, 
OmpBlockConstruct);
 };
 
 // 2.11.3 allocate -> ALLOCATE [(variable-name-list)] [clause]
diff --git a/flang/lib/Semantics/openmp-utils.h 
b/flang/include/flang/Semantics/openmp-utils.h
similarity index 100%
rename from flang/lib/Semantics/openmp-utils.h
rename to flang/include/flang/Semantics/openmp-utils.h
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index d1efd8e8d2ca7..f7a7dd8fbe6a0 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -34,6 +34,7 @@
 #include "flang/Parser/openmp-utils.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/openmp-directive-sets.h"
+#include "flang/Semantics/openmp-utils.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Support/Flags.h"
 #include "flang/Support/OpenMP-utils.h"
@@ -3797,18 +3798,29 @@ static void genOMP(lower::AbstractConverter &converter, 
lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPCriticalConstruct &criticalConstruct) {
-  const auto &cd = std::get(criticalConstruct.t);
-  List clauses =
-  makeClauses(std::get(cd.t), semaCtx);
+  const parser::OmpDirectiveSpecification &beginSpec =
+  criticalConstruct.BeginDir();
+  List clauses = makeClauses(beginSpec.Clauses(), semaCtx);
 
   ConstructQueue queue{buildConstructQueue(
-  converter.getFirOpBuilder().getModule(), semaCtx, eval, cd.source,
+  converter.getFirOpBuilder().getModule(), semaCtx, eval, beginSpec.source,
   llvm::omp::Directive::OMPD_critical, clauses)};
 
-  const auto &name = std::get>(cd.t);
+  std::optional critName;
+  const parser::OmpArgumentList &args = beginSpec.Arguments();
+  if (!args.v.empty()) {
+// All of these things should be guaranteed to exist after semantic checks.
+auto *object = parser::Unwrap(args.v.front());
+assert(object && "Expecting object as argument");
+auto *designator = semantics::omp::GetDesignatorFromObj(*object);
+assert(designator && "Expecting desginator in argument");
+auto *name = semantics::getDesignatorNameIfDataRef(*designator);
+assert(name && "Expecting dataref in designator");
+critName = *name;
+  }
   mlir::Location currentLocation = converter.getCurrentLocation();
   genCriticalOp(converter, symTable, semaCtx, eval, currentLocation, queue,
-queue.begin(), name);
+queue.begin(), critName);
 }
 
 static void genOMP(lower::AbstractConverter &converter, lower::SymMap 
&symTable,
diff --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 84d1e81bfd9be..ab23e7d70de4f 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1758,17 +1758,8 @@ 
TYPE_PARSER(sourced(construct(
 TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
-// 2.13.2 OMP CRITICAL
-TYPE_PARSER(startOmpLine >>
-sourced(construct(
-

[llvm-branch-commits] [flang] [flang][OpenMP] Make OpenMPCriticalConstruct follow block structure (PR #152007)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

This allows not having the END CRITICAL directive in certain situations. Update 
semantic checks and symbol resolution.

---

Patch is 24.11 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/152007.diff


16 Files Affected:

- (modified) flang/include/flang/Parser/parse-tree.h (+3-3) 
- (renamed) flang/include/flang/Semantics/openmp-utils.h () 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+18-6) 
- (modified) flang/lib/Parser/openmp-parsers.cpp (+2-11) 
- (modified) flang/lib/Parser/unparse.cpp (+1-3) 
- (modified) flang/lib/Semantics/check-omp-atomic.cpp (+1-1) 
- (modified) flang/lib/Semantics/check-omp-loop.cpp (+1-1) 
- (modified) flang/lib/Semantics/check-omp-metadirective.cpp (+1-2) 
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+81-43) 
- (modified) flang/lib/Semantics/openmp-utils.cpp (+1-1) 
- (modified) flang/lib/Semantics/resolve-directives.cpp (+3-3) 
- (modified) flang/lib/Semantics/resolve-names.cpp (+33-36) 
- (modified) flang/lib/Semantics/unparse-with-symbols.cpp (-14) 
- (modified) flang/test/Parser/OpenMP/critical-unparse-with-symbols.f90 (+2-2) 
- (modified) flang/test/Semantics/OpenMP/sync-critical01.f90 (+4-4) 
- (modified) flang/test/Semantics/OpenMP/sync-critical02.f90 (+4-4) 


``diff
diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 8302e40984af0..e72190f019dd1 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4986,9 +4986,9 @@ struct OmpEndCriticalDirective {
   CharBlock source;
   std::tuple> t;
 };
-struct OpenMPCriticalConstruct {
-  TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct);
-  std::tuple t;
+
+struct OpenMPCriticalConstruct : public OmpBlockConstruct {
+  INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct, 
OmpBlockConstruct);
 };
 
 // 2.11.3 allocate -> ALLOCATE [(variable-name-list)] [clause]
diff --git a/flang/lib/Semantics/openmp-utils.h 
b/flang/include/flang/Semantics/openmp-utils.h
similarity index 100%
rename from flang/lib/Semantics/openmp-utils.h
rename to flang/include/flang/Semantics/openmp-utils.h
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index d1efd8e8d2ca7..f7a7dd8fbe6a0 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -34,6 +34,7 @@
 #include "flang/Parser/openmp-utils.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/openmp-directive-sets.h"
+#include "flang/Semantics/openmp-utils.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Support/Flags.h"
 #include "flang/Support/OpenMP-utils.h"
@@ -3797,18 +3798,29 @@ static void genOMP(lower::AbstractConverter &converter, 
lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPCriticalConstruct &criticalConstruct) {
-  const auto &cd = std::get(criticalConstruct.t);
-  List clauses =
-  makeClauses(std::get(cd.t), semaCtx);
+  const parser::OmpDirectiveSpecification &beginSpec =
+  criticalConstruct.BeginDir();
+  List clauses = makeClauses(beginSpec.Clauses(), semaCtx);
 
   ConstructQueue queue{buildConstructQueue(
-  converter.getFirOpBuilder().getModule(), semaCtx, eval, cd.source,
+  converter.getFirOpBuilder().getModule(), semaCtx, eval, beginSpec.source,
   llvm::omp::Directive::OMPD_critical, clauses)};
 
-  const auto &name = std::get>(cd.t);
+  std::optional critName;
+  const parser::OmpArgumentList &args = beginSpec.Arguments();
+  if (!args.v.empty()) {
+// All of these things should be guaranteed to exist after semantic checks.
+auto *object = parser::Unwrap(args.v.front());
+assert(object && "Expecting object as argument");
+auto *designator = semantics::omp::GetDesignatorFromObj(*object);
+assert(designator && "Expecting desginator in argument");
+auto *name = semantics::getDesignatorNameIfDataRef(*designator);
+assert(name && "Expecting dataref in designator");
+critName = *name;
+  }
   mlir::Location currentLocation = converter.getCurrentLocation();
   genCriticalOp(converter, symTable, semaCtx, eval, currentLocation, queue,
-queue.begin(), name);
+queue.begin(), critName);
 }
 
 static void genOMP(lower::AbstractConverter &converter, lower::SymMap 
&symTable,
diff --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 84d1e81bfd9be..ab23e7d70de4f 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1758,17 +1758,8 @@ 
TYPE_PARSER(sourced(construct(
 TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
-// 2.13.2 OMP CRITICAL
-TYPE_PARSER(startOmpLine >>
-sourced(construct(
-verbatim("END CRITICAL"_tok), maybe(p

[llvm-branch-commits] [flang] [flang][OpenMP] Insert CRITICAL construct names into global scope (PR #152004)

2025-08-04 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/152004

They were inserted in the current scope.

OpenMP spec (all versions):
The names of critical constructs are global entities of the program. If a name 
conflicts with any other entity, the behavior of the program is unspecified.

>From 4187a39e449369fa8e9b4917e1b2af91ebbb057d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 4 Aug 2025 11:58:35 -0500
Subject: [PATCH] [flang][OpenMP] Insert CRITICAL construct names into global
 scope

OpenMP spec (all versions):
The names of critical constructs are global entities of the program.
If a name conflicts with any other entity, the behavior of the program
is unspecified.
---
 flang/lib/Semantics/resolve-directives.cpp|  9 
 flang/lib/Semantics/resolve-names.cpp | 44 +++
 .../OpenMP/critical-global-conflict.f90   | 15 +++
 .../OpenMP/critical_within_default.f90|  7 ++-
 4 files changed, 65 insertions(+), 10 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/critical-global-conflict.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp 
b/flang/lib/Semantics/resolve-directives.cpp
index bb28cfb61764f..64bb27962faab 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2125,17 +2125,8 @@ bool OmpAttributeVisitor::Pre(const 
parser::OpenMPSectionConstruct &x) {
 
 bool OmpAttributeVisitor::Pre(const parser::OpenMPCriticalConstruct &x) {
   const auto &beginCriticalDir{std::get(x.t)};
-  const auto &endCriticalDir{std::get(x.t)};
   PushContext(beginCriticalDir.source, llvm::omp::Directive::OMPD_critical);
   GetContext().withinConstruct = true;
-  if (const auto &criticalName{
-  std::get>(beginCriticalDir.t)}) {
-ResolveOmpName(*criticalName, Symbol::Flag::OmpCriticalLock);
-  }
-  if (const auto &endCriticalName{
-  std::get>(endCriticalDir.t)}) {
-ResolveOmpName(*endCriticalName, Symbol::Flag::OmpCriticalLock);
-  }
   return true;
 }
 
diff --git a/flang/lib/Semantics/resolve-names.cpp 
b/flang/lib/Semantics/resolve-names.cpp
index 25b13700cd3ab..86201ebee8bdf 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1593,6 +1593,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OmpCriticalDirective &x) {
 AddOmpSourceRange(x.source);
+// Manually resolve names in CRITICAL directives. This is because these
+// names do not denote Fortran objects, and the CRITICAL directive causes
+// them to be "auto-declared", i.e. inserted into the global scope.
+// More specifically, they are not expected to have explicit declarations,
+// and if they do the behavior is unspeficied.
+if (auto &maybeName{std::get>(x.t)}) {
+  ResolveCriticalName(*maybeName);
+}
 return true;
   }
   void Post(const parser::OmpCriticalDirective &) {
@@ -1600,6 +1608,10 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OmpEndCriticalDirective &x) {
 AddOmpSourceRange(x.source);
+// Manually resolve names in CRITICAL directives.
+if (auto &maybeName{std::get>(x.t)}) {
+  ResolveCriticalName(*maybeName);
+}
 return true;
   }
   void Post(const parser::OmpEndCriticalDirective &) {
@@ -1720,6 +1732,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
   const std::optional &clauses,
   const T &wholeConstruct);
 
+  void ResolveCriticalName(const parser::Name &name);
+
   int metaLevel_{0};
   const parser::OmpMetadirectiveDirective *metaDirective_{nullptr};
 };
@@ -1947,6 +1961,36 @@ void OmpVisitor::ProcessReductionSpecifier(
   }
 }
 
+void OmpVisitor::ResolveCriticalName(const parser::Name &name) {
+  auto &globalScope{[&]() -> Scope & {
+for (Scope *s{&currScope()};; s = &s->parent()) {
+  if (s->IsTopLevel()) {
+return *s;
+  }
+}
+llvm_unreachable("Cannot find global scope");
+  }()};
+
+  auto findSymbol{[&](const parser::Name &n) {
+if (auto *s{FindSymbol(n)}) {
+  return s;
+} else {
+  return FindInScope(globalScope, n);
+}
+  }};
+
+  if (auto *symbol{findSymbol(name)}) {
+if (!symbol->test(Symbol::Flag::OmpCriticalLock)) {
+  SayWithDecl(name, *symbol,
+  "CRITICAL construct name '%s' conflicts with a previous 
declaration"_warn_en_US,
+  name.ToString());
+}
+  } else {
+name.symbol = &MakeSymbol(globalScope, name.source, Attrs{});
+name.symbol->set(Symbol::Flag::OmpCriticalLock);
+  }
+}
+
 bool OmpVisitor::Pre(const parser::OmpDirectiveSpecification &x) {
   AddOmpSourceRange(x.source);
   if (metaLevel_ == 0) {
diff --git a/flang/test/Semantics/OpenMP/critical-global-conflict.f90 
b/flang/test/Semantics/OpenMP/critical-global-conflict.f90
new file mode 100644
index 0..cee6f2f14b373
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/critical-global-conflict

[llvm-branch-commits] [flang] [flang][OpenMP] Insert CRITICAL construct names into global scope (PR #152004)

2025-08-04 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/152004

>From 4187a39e449369fa8e9b4917e1b2af91ebbb057d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 4 Aug 2025 11:58:35 -0500
Subject: [PATCH 1/2] [flang][OpenMP] Insert CRITICAL construct names into
 global scope

OpenMP spec (all versions):
The names of critical constructs are global entities of the program.
If a name conflicts with any other entity, the behavior of the program
is unspecified.
---
 flang/lib/Semantics/resolve-directives.cpp|  9 
 flang/lib/Semantics/resolve-names.cpp | 44 +++
 .../OpenMP/critical-global-conflict.f90   | 15 +++
 .../OpenMP/critical_within_default.f90|  7 ++-
 4 files changed, 65 insertions(+), 10 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/critical-global-conflict.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp 
b/flang/lib/Semantics/resolve-directives.cpp
index bb28cfb61764f..64bb27962faab 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2125,17 +2125,8 @@ bool OmpAttributeVisitor::Pre(const 
parser::OpenMPSectionConstruct &x) {
 
 bool OmpAttributeVisitor::Pre(const parser::OpenMPCriticalConstruct &x) {
   const auto &beginCriticalDir{std::get(x.t)};
-  const auto &endCriticalDir{std::get(x.t)};
   PushContext(beginCriticalDir.source, llvm::omp::Directive::OMPD_critical);
   GetContext().withinConstruct = true;
-  if (const auto &criticalName{
-  std::get>(beginCriticalDir.t)}) {
-ResolveOmpName(*criticalName, Symbol::Flag::OmpCriticalLock);
-  }
-  if (const auto &endCriticalName{
-  std::get>(endCriticalDir.t)}) {
-ResolveOmpName(*endCriticalName, Symbol::Flag::OmpCriticalLock);
-  }
   return true;
 }
 
diff --git a/flang/lib/Semantics/resolve-names.cpp 
b/flang/lib/Semantics/resolve-names.cpp
index 25b13700cd3ab..86201ebee8bdf 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1593,6 +1593,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OmpCriticalDirective &x) {
 AddOmpSourceRange(x.source);
+// Manually resolve names in CRITICAL directives. This is because these
+// names do not denote Fortran objects, and the CRITICAL directive causes
+// them to be "auto-declared", i.e. inserted into the global scope.
+// More specifically, they are not expected to have explicit declarations,
+// and if they do the behavior is unspeficied.
+if (auto &maybeName{std::get>(x.t)}) {
+  ResolveCriticalName(*maybeName);
+}
 return true;
   }
   void Post(const parser::OmpCriticalDirective &) {
@@ -1600,6 +1608,10 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OmpEndCriticalDirective &x) {
 AddOmpSourceRange(x.source);
+// Manually resolve names in CRITICAL directives.
+if (auto &maybeName{std::get>(x.t)}) {
+  ResolveCriticalName(*maybeName);
+}
 return true;
   }
   void Post(const parser::OmpEndCriticalDirective &) {
@@ -1720,6 +1732,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
   const std::optional &clauses,
   const T &wholeConstruct);
 
+  void ResolveCriticalName(const parser::Name &name);
+
   int metaLevel_{0};
   const parser::OmpMetadirectiveDirective *metaDirective_{nullptr};
 };
@@ -1947,6 +1961,36 @@ void OmpVisitor::ProcessReductionSpecifier(
   }
 }
 
+void OmpVisitor::ResolveCriticalName(const parser::Name &name) {
+  auto &globalScope{[&]() -> Scope & {
+for (Scope *s{&currScope()};; s = &s->parent()) {
+  if (s->IsTopLevel()) {
+return *s;
+  }
+}
+llvm_unreachable("Cannot find global scope");
+  }()};
+
+  auto findSymbol{[&](const parser::Name &n) {
+if (auto *s{FindSymbol(n)}) {
+  return s;
+} else {
+  return FindInScope(globalScope, n);
+}
+  }};
+
+  if (auto *symbol{findSymbol(name)}) {
+if (!symbol->test(Symbol::Flag::OmpCriticalLock)) {
+  SayWithDecl(name, *symbol,
+  "CRITICAL construct name '%s' conflicts with a previous 
declaration"_warn_en_US,
+  name.ToString());
+}
+  } else {
+name.symbol = &MakeSymbol(globalScope, name.source, Attrs{});
+name.symbol->set(Symbol::Flag::OmpCriticalLock);
+  }
+}
+
 bool OmpVisitor::Pre(const parser::OmpDirectiveSpecification &x) {
   AddOmpSourceRange(x.source);
   if (metaLevel_ == 0) {
diff --git a/flang/test/Semantics/OpenMP/critical-global-conflict.f90 
b/flang/test/Semantics/OpenMP/critical-global-conflict.f90
new file mode 100644
index 0..cee6f2f14b373
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/critical-global-conflict.f90
@@ -0,0 +1,15 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -Werror
+
+subroutine g
+end
+
+subroutine f(x)
+  implicit none
+  integer :: x
+
+!ERROR: CRITICAL construct name 'f' conflicts with a previ

[llvm-branch-commits] [flang] [flang][OpenMP] Insert CRITICAL construct names into global scope (PR #152004)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

They were inserted in the current scope.

OpenMP spec (all versions):
The names of critical constructs are global entities of the program. If a name 
conflicts with any other entity, the behavior of the program is unspecified.

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


4 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (-9) 
- (modified) flang/lib/Semantics/resolve-names.cpp (+44) 
- (added) flang/test/Semantics/OpenMP/critical-global-conflict.f90 (+15) 
- (modified) flang/test/Semantics/OpenMP/critical_within_default.f90 (+6-1) 


``diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp 
b/flang/lib/Semantics/resolve-directives.cpp
index bb28cfb61764f..64bb27962faab 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2125,17 +2125,8 @@ bool OmpAttributeVisitor::Pre(const 
parser::OpenMPSectionConstruct &x) {
 
 bool OmpAttributeVisitor::Pre(const parser::OpenMPCriticalConstruct &x) {
   const auto &beginCriticalDir{std::get(x.t)};
-  const auto &endCriticalDir{std::get(x.t)};
   PushContext(beginCriticalDir.source, llvm::omp::Directive::OMPD_critical);
   GetContext().withinConstruct = true;
-  if (const auto &criticalName{
-  std::get>(beginCriticalDir.t)}) {
-ResolveOmpName(*criticalName, Symbol::Flag::OmpCriticalLock);
-  }
-  if (const auto &endCriticalName{
-  std::get>(endCriticalDir.t)}) {
-ResolveOmpName(*endCriticalName, Symbol::Flag::OmpCriticalLock);
-  }
   return true;
 }
 
diff --git a/flang/lib/Semantics/resolve-names.cpp 
b/flang/lib/Semantics/resolve-names.cpp
index 25b13700cd3ab..86201ebee8bdf 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1593,6 +1593,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OmpCriticalDirective &x) {
 AddOmpSourceRange(x.source);
+// Manually resolve names in CRITICAL directives. This is because these
+// names do not denote Fortran objects, and the CRITICAL directive causes
+// them to be "auto-declared", i.e. inserted into the global scope.
+// More specifically, they are not expected to have explicit declarations,
+// and if they do the behavior is unspeficied.
+if (auto &maybeName{std::get>(x.t)}) {
+  ResolveCriticalName(*maybeName);
+}
 return true;
   }
   void Post(const parser::OmpCriticalDirective &) {
@@ -1600,6 +1608,10 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OmpEndCriticalDirective &x) {
 AddOmpSourceRange(x.source);
+// Manually resolve names in CRITICAL directives.
+if (auto &maybeName{std::get>(x.t)}) {
+  ResolveCriticalName(*maybeName);
+}
 return true;
   }
   void Post(const parser::OmpEndCriticalDirective &) {
@@ -1720,6 +1732,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
   const std::optional &clauses,
   const T &wholeConstruct);
 
+  void ResolveCriticalName(const parser::Name &name);
+
   int metaLevel_{0};
   const parser::OmpMetadirectiveDirective *metaDirective_{nullptr};
 };
@@ -1947,6 +1961,36 @@ void OmpVisitor::ProcessReductionSpecifier(
   }
 }
 
+void OmpVisitor::ResolveCriticalName(const parser::Name &name) {
+  auto &globalScope{[&]() -> Scope & {
+for (Scope *s{&currScope()};; s = &s->parent()) {
+  if (s->IsTopLevel()) {
+return *s;
+  }
+}
+llvm_unreachable("Cannot find global scope");
+  }()};
+
+  auto findSymbol{[&](const parser::Name &n) {
+if (auto *s{FindSymbol(n)}) {
+  return s;
+} else {
+  return FindInScope(globalScope, n);
+}
+  }};
+
+  if (auto *symbol{findSymbol(name)}) {
+if (!symbol->test(Symbol::Flag::OmpCriticalLock)) {
+  SayWithDecl(name, *symbol,
+  "CRITICAL construct name '%s' conflicts with a previous 
declaration"_warn_en_US,
+  name.ToString());
+}
+  } else {
+name.symbol = &MakeSymbol(globalScope, name.source, Attrs{});
+name.symbol->set(Symbol::Flag::OmpCriticalLock);
+  }
+}
+
 bool OmpVisitor::Pre(const parser::OmpDirectiveSpecification &x) {
   AddOmpSourceRange(x.source);
   if (metaLevel_ == 0) {
diff --git a/flang/test/Semantics/OpenMP/critical-global-conflict.f90 
b/flang/test/Semantics/OpenMP/critical-global-conflict.f90
new file mode 100644
index 0..cee6f2f14b373
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/critical-global-conflict.f90
@@ -0,0 +1,15 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -Werror
+
+subroutine g
+end
+
+subroutine f(x)
+  implicit none
+  integer :: x
+
+!ERROR: CRITICAL construct name 'f' conflicts with a previous declaration
+  !$omp critical(f)
+  x = 0
+!ERROR: CRITICAL construct name 'f' conflicts with a previous declaration
+  !$omp end critical(f)
+end
diff --git a/f

[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread Corentin Jabot via llvm-branch-commits

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


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


[llvm-branch-commits] [flang] [llvm] [MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (PR #151989)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: Akash Banerjee (TIFitis)


Changes

Add a new AutomapToTargetData pass. This gathers the declare target enter 
variables which have the AUTOMAP modifier. And adds 
omp.declare_target_enter/exit mapping directives for fir.alloca and fir.free 
oeprations on the AUTOMAP enabled variables.

Automap Ref: OpenMP 6.0 section 7.9.7.

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


6 Files Affected:

- (modified) flang/include/flang/Optimizer/OpenMP/Passes.td (+11) 
- (added) flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp (+171) 
- (modified) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+1) 
- (modified) flang/lib/Optimizer/Passes/Pipelines.cpp (+6-6) 
- (added) flang/test/Transforms/omp-automap-to-target-data.fir (+40) 
- (added) offload/test/offloading/fortran/declare-target-automap.f90 (+36) 


``diff
diff --git a/flang/include/flang/Optimizer/OpenMP/Passes.td 
b/flang/include/flang/Optimizer/OpenMP/Passes.td
index 704faf0ccd856..0bff58f0f6394 100644
--- a/flang/include/flang/Optimizer/OpenMP/Passes.td
+++ b/flang/include/flang/Optimizer/OpenMP/Passes.td
@@ -112,4 +112,15 @@ def GenericLoopConversionPass
   ];
 }
 
+def AutomapToTargetDataPass
+: Pass<"omp-automap-to-target-data", "::mlir::ModuleOp"> {
+  let summary = "Insert OpenMP target data operations for AUTOMAP variables";
+  let description = [{
+Inserts `omp.target_enter_data` and `omp.target_exit_data` operations to
+map variables marked with the `AUTOMAP` modifier when their allocation
+or deallocation is detected in the FIR.
+  }];
+  let dependentDialects = ["mlir::omp::OpenMPDialect"];
+}
+
 #endif //FORTRAN_OPTIMIZER_OPENMP_PASSES
diff --git a/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp 
b/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
new file mode 100644
index 0..c4937f1e90ee3
--- /dev/null
+++ b/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
@@ -0,0 +1,171 @@
+//===- AutomapToTargetData.cpp ---===//
+//
+// 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 "flang/Optimizer/Builder/DirectivesCommon.h"
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Builder/HLFIRTools.h"
+#include "flang/Optimizer/Dialect/FIROps.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Optimizer/HLFIR/HLFIROps.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/Pass/Pass.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
+#include 
+
+namespace flangomp {
+#define GEN_PASS_DEF_AUTOMAPTOTARGETDATAPASS
+#include "flang/Optimizer/OpenMP/Passes.h.inc"
+} // namespace flangomp
+
+using namespace mlir;
+
+namespace {
+class AutomapToTargetDataPass
+: public flangomp::impl::AutomapToTargetDataPassBase<
+  AutomapToTargetDataPass> {
+  // Returns true if the variable has a dynamic size and therefore requires
+  // bounds operations to describe its extents.
+  bool needsBoundsOps(Value var) {
+assert(isa(var.getType()) &&
+   "only pointer like types expected");
+Type t = fir::unwrapRefType(var.getType());
+if (Type inner = fir::dyn_cast_ptrOrBoxEleTy(t))
+  return fir::hasDynamicSize(inner);
+return fir::hasDynamicSize(t);
+  }
+
+  // Generate MapBoundsOp operations for the variable if required.
+  void genBoundsOps(fir::FirOpBuilder &builder, Value var,
+SmallVectorImpl &boundsOps) {
+Location loc = var.getLoc();
+fir::factory::AddrAndBoundsInfo info =
+fir::factory::getDataOperandBaseAddr(builder, var,
+ /*isOptional=*/false, loc);
+fir::ExtendedValue exv =
+hlfir::translateToExtendedValue(loc, builder, hlfir::Entity{info.addr},
+/*contiguousHint=*/true)
+.first;
+SmallVector tmp =
+fir::factory::genImplicitBoundsOps(
+builder, info, exv, /*dataExvIsAssumedSize=*/false, loc);
+llvm::append_range(boundsOps, tmp);
+  }
+
+  void findRelatedAllocmemFreemem(fir::AddrOfOp addressOfOp,
+  llvm::SmallVector &allocmems,
+  llvm::SmallVector &freemems) {
+assert(addressOfOp->hasOneUse() && "op must have single use");
+
+auto declaredRef =
+cast(*addressOfOp->getUsers().begin())->getResult(0);
+
+for (Operation *refUser : declaredRef.getUsers()) {
+  if (auto storeOp = dyn_cast(refUser))
+if (auto emboxOp = storeOp.getValue().getDefiningOp())
+  if (auto allocmemOp =
+  emboxOp.getOperand(0).getDefiningOp())
+  

[llvm-branch-commits] [flang] [llvm] [MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (PR #151989)

2025-08-04 Thread Akash Banerjee via llvm-branch-commits

https://github.com/TIFitis created 
https://github.com/llvm/llvm-project/pull/151989

Add a new AutomapToTargetData pass. This gathers the declare target enter 
variables which have the AUTOMAP modifier. And adds 
omp.declare_target_enter/exit mapping directives for fir.alloca and fir.free 
oeprations on the AUTOMAP enabled variables.

Automap Ref: OpenMP 6.0 section 7.9.7.

>From 9f050593054e3c4d01cd17a5f6c918386ab3896e Mon Sep 17 00:00:00 2001
From: Akash Banerjee 
Date: Thu, 31 Jul 2025 19:48:15 +0100
Subject: [PATCH] [MLIR][OpenMP] Add a new AutomapToTargetData conversion pass
 in FIR

Add a new AutomapToTargetData pass. This gathers the declare target enter 
variables which have the AUTOMAP modifier.
And adds omp.declare_target_enter/exit mapping directives for fir.alloca and 
fir.free oeprations on the AUTOMAP enabled variables.
---
 .../include/flang/Optimizer/OpenMP/Passes.td  |  11 ++
 .../Optimizer/OpenMP/AutomapToTargetData.cpp  | 171 ++
 flang/lib/Optimizer/OpenMP/CMakeLists.txt |   1 +
 flang/lib/Optimizer/Passes/Pipelines.cpp  |  12 +-
 .../Transforms/omp-automap-to-target-data.fir |  40 
 .../fortran/declare-target-automap.f90|  36 
 6 files changed, 265 insertions(+), 6 deletions(-)
 create mode 100644 flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
 create mode 100644 flang/test/Transforms/omp-automap-to-target-data.fir
 create mode 100644 offload/test/offloading/fortran/declare-target-automap.f90

diff --git a/flang/include/flang/Optimizer/OpenMP/Passes.td 
b/flang/include/flang/Optimizer/OpenMP/Passes.td
index 704faf0ccd856..0bff58f0f6394 100644
--- a/flang/include/flang/Optimizer/OpenMP/Passes.td
+++ b/flang/include/flang/Optimizer/OpenMP/Passes.td
@@ -112,4 +112,15 @@ def GenericLoopConversionPass
   ];
 }
 
+def AutomapToTargetDataPass
+: Pass<"omp-automap-to-target-data", "::mlir::ModuleOp"> {
+  let summary = "Insert OpenMP target data operations for AUTOMAP variables";
+  let description = [{
+Inserts `omp.target_enter_data` and `omp.target_exit_data` operations to
+map variables marked with the `AUTOMAP` modifier when their allocation
+or deallocation is detected in the FIR.
+  }];
+  let dependentDialects = ["mlir::omp::OpenMPDialect"];
+}
+
 #endif //FORTRAN_OPTIMIZER_OPENMP_PASSES
diff --git a/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp 
b/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
new file mode 100644
index 0..c4937f1e90ee3
--- /dev/null
+++ b/flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp
@@ -0,0 +1,171 @@
+//===- AutomapToTargetData.cpp ---===//
+//
+// 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 "flang/Optimizer/Builder/DirectivesCommon.h"
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Builder/HLFIRTools.h"
+#include "flang/Optimizer/Dialect/FIROps.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Optimizer/HLFIR/HLFIROps.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/Pass/Pass.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
+#include 
+
+namespace flangomp {
+#define GEN_PASS_DEF_AUTOMAPTOTARGETDATAPASS
+#include "flang/Optimizer/OpenMP/Passes.h.inc"
+} // namespace flangomp
+
+using namespace mlir;
+
+namespace {
+class AutomapToTargetDataPass
+: public flangomp::impl::AutomapToTargetDataPassBase<
+  AutomapToTargetDataPass> {
+  // Returns true if the variable has a dynamic size and therefore requires
+  // bounds operations to describe its extents.
+  bool needsBoundsOps(Value var) {
+assert(isa(var.getType()) &&
+   "only pointer like types expected");
+Type t = fir::unwrapRefType(var.getType());
+if (Type inner = fir::dyn_cast_ptrOrBoxEleTy(t))
+  return fir::hasDynamicSize(inner);
+return fir::hasDynamicSize(t);
+  }
+
+  // Generate MapBoundsOp operations for the variable if required.
+  void genBoundsOps(fir::FirOpBuilder &builder, Value var,
+SmallVectorImpl &boundsOps) {
+Location loc = var.getLoc();
+fir::factory::AddrAndBoundsInfo info =
+fir::factory::getDataOperandBaseAddr(builder, var,
+ /*isOptional=*/false, loc);
+fir::ExtendedValue exv =
+hlfir::translateToExtendedValue(loc, builder, hlfir::Entity{info.addr},
+/*contiguousHint=*/true)
+.first;
+SmallVector tmp =
+fir::factory::genImplicitBoundsOps(
+builder, info, exv, /*dataExvIsAssumedSize=*/false, loc);
+llvm::append_range(boundsOps, tmp);
+  }
+
+  void findRelatedAllocmemFreemem(fir::Add

[llvm-branch-commits] [llvm] [AMDGPU][SDAG] DAGCombine PTRADD -> disjoint OR (PR #146075)

2025-08-04 Thread Matt Arsenault via llvm-branch-commits

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


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


[llvm-branch-commits] [flang] [llvm] [MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (PR #151989)

2025-08-04 Thread Akash Banerjee via llvm-branch-commits

https://github.com/TIFitis edited 
https://github.com/llvm/llvm-project/pull/151989
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [PHIElimination] Reuse existing COPY in predecessor basic block (Take Two) (PR #146806)

2025-08-04 Thread Guy David via llvm-branch-commits

https://github.com/guy-david edited 
https://github.com/llvm/llvm-project/pull/146806
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] ed1f9d8 - Revert "[VectorCombine] Shrink loads used in shufflevector rebroadcasts (#128…"

2025-08-04 Thread via llvm-branch-commits

Author: Simon Pilgrim
Date: 2025-08-04T14:27:53+01:00
New Revision: ed1f9d869daae57a7dd0b037b560a2b6d5f52997

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

LOG: Revert "[VectorCombine] Shrink loads used in shufflevector rebroadcasts 
(#128…"

This reverts commit 1feed444aa065ff94ce63250a00de188001617be.

Added: 


Modified: 
clang/test/CodeGenOpenCL/preserve_vec3.cl
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
llvm/test/Transforms/PhaseOrdering/X86/vec-load-combine.ll
llvm/test/Transforms/VectorCombine/X86/load-inseltpoison.ll
llvm/test/Transforms/VectorCombine/X86/load-widening.ll
llvm/test/Transforms/VectorCombine/X86/shuffle-of-shuffles.ll

Removed: 
llvm/test/Transforms/VectorCombine/load-shufflevector.ll



diff  --git a/clang/test/CodeGenOpenCL/preserve_vec3.cl 
b/clang/test/CodeGenOpenCL/preserve_vec3.cl
index e73657e30d884..49ebae6fc7013 100644
--- a/clang/test/CodeGenOpenCL/preserve_vec3.cl
+++ b/clang/test/CodeGenOpenCL/preserve_vec3.cl
@@ -11,8 +11,8 @@ typedef float float4 __attribute__((ext_vector_type(4)));
 // CHECK-LABEL: define dso_local spir_kernel void @foo(
 // CHECK-SAME: ptr addrspace(1) noundef readonly align 16 captures(none) 
[[A:%.*]], ptr addrspace(1) noundef writeonly align 16 captures(none) 
initializes((0, 16)) [[B:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] 
!kernel_arg_addr_space [[META3:![0-9]+]] !kernel_arg_access_qual 
[[META4:![0-9]+]] !kernel_arg_type [[META5:![0-9]+]] !kernel_arg_base_type 
[[META6:![0-9]+]] !kernel_arg_type_qual [[META7:![0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
-// CHECK-NEXT:[[TMP0:%.*]] = load <3 x float>, ptr addrspace(1) [[A]], 
align 16
-// CHECK-NEXT:[[EXTRACTVEC1:%.*]] = shufflevector <3 x float> [[TMP0]], <3 
x float> poison, <4 x i32> 
+// CHECK-NEXT:[[LOADVECN:%.*]] = load <4 x float>, ptr addrspace(1) [[A]], 
align 16
+// CHECK-NEXT:[[EXTRACTVEC1:%.*]] = shufflevector <4 x float> 
[[LOADVECN]], <4 x float> poison, <4 x i32> 
 // CHECK-NEXT:store <4 x float> [[EXTRACTVEC1]], ptr addrspace(1) [[B]], 
align 16, !tbaa [[TBAA8:![0-9]+]]
 // CHECK-NEXT:ret void
 //
@@ -23,8 +23,8 @@ void kernel foo(global float3 *a, global float3 *b) {
 // CHECK-LABEL: define dso_local spir_kernel void @float4_to_float3(
 // CHECK-SAME: ptr addrspace(1) noundef writeonly align 16 captures(none) 
initializes((0, 16)) [[A:%.*]], ptr addrspace(1) noundef readonly align 16 
captures(none) [[B:%.*]]) local_unnamed_addr #[[ATTR0]] !kernel_arg_addr_space 
[[META3]] !kernel_arg_access_qual [[META4]] !kernel_arg_type [[META11:![0-9]+]] 
!kernel_arg_base_type [[META12:![0-9]+]] !kernel_arg_type_qual [[META7]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
-// CHECK-NEXT:[[TMP0:%.*]] = load <3 x float>, ptr addrspace(1) [[B]], 
align 16, !tbaa [[TBAA8]]
-// CHECK-NEXT:[[EXTRACTVEC:%.*]] = shufflevector <3 x float> [[TMP0]], <3 
x float> poison, <4 x i32> 
+// CHECK-NEXT:[[TMP0:%.*]] = load <4 x float>, ptr addrspace(1) [[B]], 
align 16, !tbaa [[TBAA8]]
+// CHECK-NEXT:[[EXTRACTVEC:%.*]] = shufflevector <4 x float> [[TMP0]], <4 
x float> poison, <4 x i32> 
 // CHECK-NEXT:store <4 x float> [[EXTRACTVEC]], ptr addrspace(1) [[A]], 
align 16, !tbaa [[TBAA8]]
 // CHECK-NEXT:ret void
 //
@@ -35,8 +35,8 @@ void kernel float4_to_float3(global float3 *a, global float4 
*b) {
 // CHECK-LABEL: define dso_local spir_kernel void @float3_to_float4(
 // CHECK-SAME: ptr addrspace(1) noundef readonly align 16 captures(none) 
[[A:%.*]], ptr addrspace(1) noundef writeonly align 16 captures(none) 
initializes((0, 16)) [[B:%.*]]) local_unnamed_addr #[[ATTR0]] 
!kernel_arg_addr_space [[META3]] !kernel_arg_access_qual [[META4]] 
!kernel_arg_type [[META11]] !kernel_arg_base_type [[META12]] 
!kernel_arg_type_qual [[META7]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
-// CHECK-NEXT:[[TMP0:%.*]] = load <3 x float>, ptr addrspace(1) [[A]], 
align 16
-// CHECK-NEXT:[[ASTYPE:%.*]] = shufflevector <3 x float> [[TMP0]], <3 x 
float> poison, <4 x i32> 
+// CHECK-NEXT:[[LOADVECN:%.*]] = load <4 x float>, ptr addrspace(1) [[A]], 
align 16
+// CHECK-NEXT:[[ASTYPE:%.*]] = shufflevector <4 x float> [[LOADVECN]], <4 
x float> poison, <4 x i32> 
 // CHECK-NEXT:store <4 x float> [[ASTYPE]], ptr addrspace(1) [[B]], align 
16, !tbaa [[TBAA8]]
 // CHECK-NEXT:ret void
 //
@@ -47,9 +47,9 @@ void kernel float3_to_float4(global float3 *a, global float4 
*b) {
 // CHECK-LABEL: define dso_local spir_kernel void @float3_to_double2(
 // CHECK-SAME: ptr addrspace(1) noundef readonly align 16 captures(none) 
[[A:%.*]], ptr addrspace(1) noundef writeonly align 16 captures(none) 
initializes((0, 16)) [[B:%.*]]) local_unnamed_addr #[[ATTR0]] 
!kernel_arg_addr_space [[META3]] !kernel_arg_access_qual [[META4]] 
!kernel_arg_type [[ME

[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/151999

Backport cb50d78

Requested by: @AaronBallman

>From 8c4a9ae3b05636463ae2d24600ab4345d943a502 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 4 Aug 2025 12:46:53 -0400
Subject: [PATCH] [C] static_assert in a for loop is not an extension (#151955)

The original wording can be squinted at to pretend this was always
allowed. GCC squints at it that way, so we're doing the same and no
longer issuing an extension diagnostic for use of static_assert in the
condition-1 of a for loop in C.

Fixes #149633

(cherry picked from commit cb50d78a0063244434d883d89ddda7f74abbffc9)
---
 clang/lib/Sema/SemaStmt.cpp | 6 +-
 clang/test/Sema/for.c   | 3 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f85826aecadf3..f46be75bda20f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2287,7 +2287,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   // we can diagnose if we don't see any variable declarations. This
   // covers a case like declaring a typedef, function, or structure
   // type rather than a variable.
-  NonVarSeen = DI;
+  //
+  // Note, _Static_assert is acceptable because it does not declare an
+  // identifier at all, so "for object having" does not apply.
+  if (!isa(DI))
+NonVarSeen = DI;
 }
   }
   // Diagnose if we saw a non-variable declaration but no variable
diff --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index e16169aac0c4c..35c4720ef3305 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -26,6 +26,5 @@ void b11 (void) { for (static _Thread_local struct { int i; } 
s;s.i;); } /* c11-
 #endif
 
 void b12(void) {
-  for(_Static_assert(1, "");;) {} /* c11-warning {{non-variable declaration in 
'for' loop is a C23 extension}}
- c23-warning {{non-variable declaration in 
'for' loop is incompatible with C standards before C23}} */
+  for(_Static_assert(1, "");;) {} /* okay, _Static_assert declares *no* 
identifiers */
 }

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


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:

@cor3ntin What do you think about merging this PR to the release branch?

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


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport cb50d78

Requested by: @AaronBallman

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaStmt.cpp (+5-1) 
- (modified) clang/test/Sema/for.c (+1-2) 


``diff
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f85826aecadf3..f46be75bda20f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2287,7 +2287,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   // we can diagnose if we don't see any variable declarations. This
   // covers a case like declaring a typedef, function, or structure
   // type rather than a variable.
-  NonVarSeen = DI;
+  //
+  // Note, _Static_assert is acceptable because it does not declare an
+  // identifier at all, so "for object having" does not apply.
+  if (!isa(DI))
+NonVarSeen = DI;
 }
   }
   // Diagnose if we saw a non-variable declaration but no variable
diff --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index e16169aac0c4c..35c4720ef3305 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -26,6 +26,5 @@ void b11 (void) { for (static _Thread_local struct { int i; } 
s;s.i;); } /* c11-
 #endif
 
 void b12(void) {
-  for(_Static_assert(1, "");;) {} /* c11-warning {{non-variable declaration in 
'for' loop is a C23 extension}}
- c23-warning {{non-variable declaration in 
'for' loop is incompatible with C standards before C23}} */
+  for(_Static_assert(1, "");;) {} /* okay, _Static_assert declares *no* 
identifiers */
 }

``




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


[llvm-branch-commits] [libcxx] [libcxxabi] [llvm] release/21.x: [libc++][hardening] Introduce assertion semantics. (#149459) (PR #151095)

2025-08-04 Thread Konstantin Varlamov via llvm-branch-commits

var-const wrote:

@tru Thank you (both for merging and for letting me know)!

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


[llvm-branch-commits] [clang] release/21.x: Thread safety analysis: Don't warn on acquiring reentrant capability (#150857) (PR #151889)

2025-08-04 Thread Marco Elver via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] [AArch64][ISel] Select constructive SVE2 ext instruction (PR #151730)

2025-08-04 Thread Gaëtan Bossu via llvm-branch-commits


@@ -4069,6 +4069,22 @@ let Predicates = [HasSVE2_or_SME] in {
   let AddedComplexity = 2 in {
 def : Pat<(nxv16i8 (AArch64ext nxv16i8:$zn1, nxv16i8:$zn2, (i32 
imm0_255:$imm))),
   (EXT_ZZI_B (REG_SEQUENCE ZPR2, $zn1, zsub0, $zn2, zsub1), 
imm0_255:$imm)>;
+
+foreach VT = [nxv16i8] in
+  def : Pat<(VT (vector_splice VT:$Z1, VT:$Z2, (i64 (sve_ext_imm_0_255 
i32:$index,
+(EXT_ZZI_B  (REG_SEQUENCE ZPR2, $Z1, zsub0, $Z2, zsub1), 
imm0_255:$index)>;

gbossu wrote:

What do you mean by different output? Do you mean that if you replce the splice 
intrisics with AArch64's EXT intrinsics, then 
`llvm/test/CodeGen/AArch64/sve-vector-splice.ll` has different CHECK lines?

For a generic splice with two inputs, I'd expect the output to be the same. The 
change I made in the first PR is only for "subvector-extract" splice 
instructions created when lowering vector_extract, where we can mark the second 
input as `undef`.

When you say removing the former, do you mean removing the pattern? Or the 
intrinsic altogether? I would need to refresh my brain after the week-end but I 
think llvm's vector_splice, AArch64 EXT and AArch64 SPLICE all have slightly 
different semantics (especially for negative indices).

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


[llvm-branch-commits] [llvm] [DataLayout][LangRef] Split non-integral and unstable pointer properties (PR #105735)

2025-08-04 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

That sounds fine as long as the plan is to remove the isNonIntegralPointer() 
method in the future, in favor of more precise checks.

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


[llvm-branch-commits] [llvm] [AArch64][ISel] Select constructive SVE2 ext instruction (PR #151730)

2025-08-04 Thread Sander de Smalen via llvm-branch-commits


@@ -4069,6 +4069,22 @@ let Predicates = [HasSVE2_or_SME] in {
   let AddedComplexity = 2 in {
 def : Pat<(nxv16i8 (AArch64ext nxv16i8:$zn1, nxv16i8:$zn2, (i32 
imm0_255:$imm))),
   (EXT_ZZI_B (REG_SEQUENCE ZPR2, $zn1, zsub0, $zn2, zsub1), 
imm0_255:$imm)>;
+
+foreach VT = [nxv16i8] in
+  def : Pat<(VT (vector_splice VT:$Z1, VT:$Z2, (i64 (sve_ext_imm_0_255 
i32:$index,
+(EXT_ZZI_B  (REG_SEQUENCE ZPR2, $Z1, zsub0, $Z2, zsub1), 
imm0_255:$index)>;

sdesmalen-arm wrote:

> What do you mean by different output? Do you mean that if you replce the 
> splice intrisics with AArch64's EXT intrinsics, then 
> llvm/test/CodeGen/AArch64/sve-vector-splice.ll has different CHECK lines?

What I meant was that if the output would be the same, you probably wouldn't 
have added this pattern. So I'm basically asking "why wouldn't the above 
pattern already cover this?".

> When you say removing the former, do you mean removing the pattern?

I mean removing `AArch64ISD::EXT` in favour of `ISD::VECTOR_SPLICE`. The EXT 
and SPLICE _SVE instructions_ are indeed different (the former takes an 
immediate, the latter a predicate), but I think the `AArch64ISD::EXT` and 
`ISD::VECTOR_SPLICE` _SelectionDAG nodes_ are practically the same. Before SVE 
we didn't have to create a new ISD node for this because `ISD::VECTOR_SHUFFLE` 
described this pattern sufficiently, but that couldn't be used for scalable 
vectors and so we added the generic `ISD::VECTOR_SPLICE`. At the time there 
probably wasn't an incentive to replace uses of `AArch64ISD::EXT` by 
`ISD::VECTOR_SPLICE`, but if code-gen is different depending on which node we 
try to match, then I think there's an incentive to merge the two.

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


[llvm-branch-commits] [llvm] [AArch64][ISel] Select constructive SVE2 ext instruction (PR #151730)

2025-08-04 Thread Gaëtan Bossu via llvm-branch-commits


@@ -4069,6 +4069,22 @@ let Predicates = [HasSVE2_or_SME] in {
   let AddedComplexity = 2 in {
 def : Pat<(nxv16i8 (AArch64ext nxv16i8:$zn1, nxv16i8:$zn2, (i32 
imm0_255:$imm))),
   (EXT_ZZI_B (REG_SEQUENCE ZPR2, $zn1, zsub0, $zn2, zsub1), 
imm0_255:$imm)>;
+
+foreach VT = [nxv16i8] in
+  def : Pat<(VT (vector_splice VT:$Z1, VT:$Z2, (i64 (sve_ext_imm_0_255 
i32:$index,
+(EXT_ZZI_B  (REG_SEQUENCE ZPR2, $Z1, zsub0, $Z2, zsub1), 
imm0_255:$index)>;

gbossu wrote:

I'll check about removing the EXT intrinsic then. 👍  I needed the new pattern 
because SDAG lowers the `vector_extract` nodes to `vector_splice`, not 
AArch64's `EXT`.

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


[llvm-branch-commits] [llvm] [DataLayout][LangRef] Split non-integral and unstable pointer properties (PR #105735)

2025-08-04 Thread Alexander Richardson via llvm-branch-commits

arichardson wrote:

> That sounds fine as long as the plan is to remove the isNonIntegralPointer() 
> method in the future, in favor of more precise checks.

Yes that is absolutely the goal. Will try to update with these changes shortly.

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


[llvm-branch-commits] [llvm] [AArch64][ISel] Select constructive SVE2 ext instruction (PR #151730)

2025-08-04 Thread Paul Walker via llvm-branch-commits

paulwalker-arm wrote:

Would it be better to start by adding `movpfrx` for `ext`? At least for some 
cores these are fused and so you can get the free move without introducing this 
[potential 
issue](https://github.com/llvm/llvm-project/pull/151729/files/ebcb4929004ae3f08b2ca3d5d246f29aa73600e1#diff-6291e4657dea1f4fecdcb9dc96bfb014f79d4c617f080b2f033943e52732cf69).

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


[llvm-branch-commits] [libc++] Introduce __force_nonstandard_layout base class for pointer field protection (PR #151652)

2025-08-04 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

C++23 has this to say on reinterpret_casts:

> When a prvalue v of object pointer type is converted to the object pointer 
> type “pointer to cv T”, the result is static_cast(static_cast void*>(v)).

and on static_casts it says:

> A prvalue of type “pointer to cv1 void” can be converted to a prvalue of type 
> “pointer to cv2 T”, where T is an object type and cv2 is the same 
> cv-qualification as, or greater cv-qualification than, cv1. If the original 
> pointer value represents the address A of a byte in memory and A does not 
> satisfy the alignment requirement of T, then the resulting pointer value is 
> unspecified. Otherwise, if the original pointer value points to an object a, 
> and there is an object b of type T (ignoring cv-qualification) that is 
> pointer-interconvertible (6.8.3) with a, the result is a pointer to b. 
> Otherwise, the pointer value is unchanged by the conversion.

The standard permits pointers to different layout-incompatible types to have 
different representations:

> The value representation of pointer types is implementation-defined. Pointers 
> to layout-compatible types shall have the same value representation and 
> alignment requirements

So as long as `std::unique_ptr` is non-standard-layout (making it 
layout-incompatible and non-pointer-interconvertible with its field), we can 
simply declare that the abstract machine operates as-if the value 
representations of `std::unique_ptr *` and `int **` are different, which 
results in UB when using the unchanged pointer value.

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


[llvm-branch-commits] [llvm] Add deactivation symbol operand to ConstantPtrAuth. (PR #133537)

2025-08-04 Thread Eli Friedman via llvm-branch-commits


@@ -2627,6 +2627,11 @@ void Verifier::visitConstantPtrAuth(const 
ConstantPtrAuth *CPA) {
 
   Check(CPA->getDiscriminator()->getBitWidth() == 64,
 "signed ptrauth constant discriminator must be i64 constant integer");
+
+  Check(isa(CPA->getDeactivationSymbol()) ||
+CPA->getDeactivationSymbol()->isNullValue(),

efriedma-quic wrote:

Maybe also check `CPA->getDeactivationSymbol()->getType()->isPointerTy()`?

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


[llvm-branch-commits] [clang] [LifetimeSafety] Add language option for experimental lifetime safety… (PR #152027)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes

… (#149592)

Add a language option flag for experimental lifetime safety analysis in C++.

This change provides a language option to control the experimental lifetime 
safety analysis feature, making it more explicit and easier to enable/disable. 
Previously, the feature was controlled indirectly through a diagnostic warning 
flag, which we do not want to accidentally enable with `-Weverything` (atm)!

- Added a new language option `EnableLifetimeSafety` in `LangOptions.def` for 
experimental lifetime safety analysis in C++
- Added corresponding driver options `-fexperimental-lifetime-safety` and 
`-fno-experimental-lifetime-safety` in `Options.td`
- Modified `AnalysisBasedWarnings.cpp` to use the new language option flag 
instead of checking if a specific diagnostic is ignored
- Updated a test case to use the new flag instead of relying on the warning 
flag alone

(cherry picked from commit 0d0478903474b2e53c874427e3d6eb2ed7567e50)
Fixes: https://github.com/llvm/llvm-project/issues/149537

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


4 Files Affected:

- (modified) clang/include/clang/Basic/LangOptions.def (+2) 
- (modified) clang/include/clang/Driver/Options.td (+8) 
- (modified) clang/lib/Sema/AnalysisBasedWarnings.cpp (+1-2) 
- (modified) clang/test/Sema/warn-lifetime-safety-dataflow.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 0d546cb3b8471..f5a5d84eefb80 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -496,6 +496,8 @@ LANGOPT(CheckConstexprFunctionBodies, 1, 1, Benign,
 
 LANGOPT(BoundsSafety, 1, 0, NotCompatible, "Bounds safety extension for C")
 
+LANGOPT(EnableLifetimeSafety, 1, 0, NotCompatible, "Experimental lifetime 
safety analysis for C++")
+
 LANGOPT(PreserveVec3Type, 1, 0, NotCompatible, "Preserve 3-component vector 
type")
 
 #undef LANGOPT
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bce29a76f3ac7..18e4ab406ce4e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1917,6 +1917,14 @@ defm bounds_safety : BoolFOption<
   BothFlags<[], [CC1Option],
   " experimental bounds safety extension for C">>;
 
+defm lifetime_safety : BoolFOption<
+  "experimental-lifetime-safety",
+  LangOpts<"EnableLifetimeSafety">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [CC1Option],
+  " experimental lifetime safety for C++">>;
+
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
   PosFlag,
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 85ac3c06ec2c2..ec39bca6039f0 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2891,8 +2891,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
   .setAlwaysAdd(Stmt::UnaryOperatorClass);
   }
 
-  bool EnableLifetimeSafetyAnalysis = !Diags.isIgnored(
-  diag::warn_experimental_lifetime_safety_dummy_warning, D->getBeginLoc());
+  bool EnableLifetimeSafetyAnalysis = S.getLangOpts().EnableLifetimeSafety;
   // Install the logical handler.
   std::optional LEH;
   if (LogicalErrorHandler::hasActiveDiagnostics(Diags, D->getBeginLoc())) {
diff --git a/clang/test/Sema/warn-lifetime-safety-dataflow.cpp 
b/clang/test/Sema/warn-lifetime-safety-dataflow.cpp
index 38dfdb98f08fc..a956386ae9332 100644
--- a/clang/test/Sema/warn-lifetime-safety-dataflow.cpp
+++ b/clang/test/Sema/warn-lifetime-safety-dataflow.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -debug-only=LifetimeFacts,LifetimeDataflow 
-Wexperimental-lifetime-safety %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-lifetime-safety -mllvm 
-debug-only=LifetimeFacts,LifetimeDataflow -Wexperimental-lifetime-safety %s 
2>&1 | FileCheck %s
 // REQUIRES: asserts
 
 struct MyObj {

``




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


[llvm-branch-commits] [clang] [LifetimeSafety] Add language option for experimental lifetime safety… (PR #152027)

2025-08-04 Thread Utkarsh Saxena via llvm-branch-commits

https://github.com/usx95 created 
https://github.com/llvm/llvm-project/pull/152027

… (#149592)

Add a language option flag for experimental lifetime safety analysis in C++.

This change provides a language option to control the experimental lifetime 
safety analysis feature, making it more explicit and easier to enable/disable. 
Previously, the feature was controlled indirectly through a diagnostic warning 
flag, which we do not want to accidentally enable with `-Weverything` (atm)!

- Added a new language option `EnableLifetimeSafety` in `LangOptions.def` for 
experimental lifetime safety analysis in C++
- Added corresponding driver options `-fexperimental-lifetime-safety` and 
`-fno-experimental-lifetime-safety` in `Options.td`
- Modified `AnalysisBasedWarnings.cpp` to use the new language option flag 
instead of checking if a specific diagnostic is ignored
- Updated a test case to use the new flag instead of relying on the warning 
flag alone

(cherry picked from commit 0d0478903474b2e53c874427e3d6eb2ed7567e50)
Fixes: https://github.com/llvm/llvm-project/issues/149537

>From 7d97c041e02f85ac66bd462acf6fa8fb82d6cb48 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 22 Jul 2025 21:31:09 +0200
Subject: [PATCH] [LifetimeSafety] Add language option for experimental
 lifetime safety (#149592)

Add a language option flag for experimental lifetime safety analysis in C++.

This change provides a language option to control the experimental lifetime 
safety analysis feature, making it more explicit and easier to enable/disable. 
Previously, the feature was controlled indirectly through a diagnostic warning 
flag, which we do not want to accidentally enable with `-Weverything` (atm)!

- Added a new language option `EnableLifetimeSafety` in `LangOptions.def` for 
experimental lifetime safety analysis in C++
- Added corresponding driver options `-fexperimental-lifetime-safety` and 
`-fno-experimental-lifetime-safety` in `Options.td`
- Modified `AnalysisBasedWarnings.cpp` to use the new language option flag 
instead of checking if a specific diagnostic is ignored
- Updated a test case to use the new flag instead of relying on the warning 
flag alone

(cherry picked from commit 0d0478903474b2e53c874427e3d6eb2ed7567e50)
---
 clang/include/clang/Basic/LangOptions.def | 2 ++
 clang/include/clang/Driver/Options.td | 8 
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 3 +--
 clang/test/Sema/warn-lifetime-safety-dataflow.cpp | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 0d546cb3b8471..f5a5d84eefb80 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -496,6 +496,8 @@ LANGOPT(CheckConstexprFunctionBodies, 1, 1, Benign,
 
 LANGOPT(BoundsSafety, 1, 0, NotCompatible, "Bounds safety extension for C")
 
+LANGOPT(EnableLifetimeSafety, 1, 0, NotCompatible, "Experimental lifetime 
safety analysis for C++")
+
 LANGOPT(PreserveVec3Type, 1, 0, NotCompatible, "Preserve 3-component vector 
type")
 
 #undef LANGOPT
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bce29a76f3ac7..18e4ab406ce4e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1917,6 +1917,14 @@ defm bounds_safety : BoolFOption<
   BothFlags<[], [CC1Option],
   " experimental bounds safety extension for C">>;
 
+defm lifetime_safety : BoolFOption<
+  "experimental-lifetime-safety",
+  LangOpts<"EnableLifetimeSafety">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [CC1Option],
+  " experimental lifetime safety for C++">>;
+
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
   PosFlag,
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 85ac3c06ec2c2..ec39bca6039f0 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2891,8 +2891,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
   .setAlwaysAdd(Stmt::UnaryOperatorClass);
   }
 
-  bool EnableLifetimeSafetyAnalysis = !Diags.isIgnored(
-  diag::warn_experimental_lifetime_safety_dummy_warning, D->getBeginLoc());
+  bool EnableLifetimeSafetyAnalysis = S.getLangOpts().EnableLifetimeSafety;
   // Install the logical handler.
   std::optional LEH;
   if (LogicalErrorHandler::hasActiveDiagnostics(Diags, D->getBeginLoc())) {
diff --git a/clang/test/Sema/warn-lifetime-safety-dataflow.cpp 
b/clang/test/Sema/warn-lifetime-safety-dataflow.cpp
index 38dfdb98f08fc..a956386ae9332 100644
--- a/clang/test/Sema/warn-lifetime-safety-dataflow.cpp
+++ b/clang/test/Sema/warn-lifetime-safety-dataflow.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -debug-only=LifetimeFacts,LifetimeDataflow 
-Wexperimental-lifetime-safety %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fexper

[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)

2025-08-04 Thread Owen Rodley via llvm-branch-commits

https://github.com/orodley updated 
https://github.com/llvm/llvm-project/pull/139497

>From 7f599c76af7fc371c6f8d54febc90e28a0b7a93c Mon Sep 17 00:00:00 2001
From: Owen Rodley 
Date: Mon, 12 May 2025 15:50:22 +1000
Subject: [PATCH] Add a GUIDLIST table to bitcode

---
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |  3 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++---
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index dc78eb4164acf..9fffa9695d210 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -120,6 +120,9 @@ enum ModuleCodes {
 
   // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
   MODULE_CODE_IFUNC = 18,
+
+  // GUIDLIST: [n x i64]
+  MODULE_CODE_GUIDLIST = 19,
 };
 
 /// PARAMATTR blocks have code for defining a parameter attribute set.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 290d873c632c9..b393fcb99b109 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -984,6 +984,9 @@ class ModuleSummaryIndexBitcodeReader : public 
BitcodeReaderBase {
   /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format.
   std::vector RadixArray;
 
+  // A table which maps ValueID to the GUID for that value.
+  std::vector DefinedGUIDs;
+
 public:
   ModuleSummaryIndexBitcodeReader(
   BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex,
@@ -7177,9 +7180,7 @@ 
ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) {
 void ModuleSummaryIndexBitcodeReader::setValueGUID(
 uint64_t ValueID, StringRef ValueName, GlobalValue::LinkageTypes Linkage,
 StringRef SourceFileName) {
-  std::string GlobalId =
-  GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName);
-  auto ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage(GlobalId);
+  auto ValueGUID = DefinedGUIDs[ValueID];
   auto OriginalNameID = ValueGUID;
   if (GlobalValue::isLocalLinkage(Linkage))
 OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName);
@@ -7402,6 +7403,10 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() {
   // was historically always the start of the regular bitcode header.
   VSTOffset = Record[0] - 1;
   break;
+// MODULE_CODE_GUIDLIST: [i64 x N]
+case bitc::MODULE_CODE_GUIDLIST:
+  llvm::append_range(DefinedGUIDs, Record);
+  break;
 // v1 GLOBALVAR: [pointer type, isconst, initid,   linkage, 
...]
 // v1 FUNCTION:  [type, callingconv, isproto,  linkage, 
...]
 // v1 ALIAS: [alias type,   addrspace,   aliasee val#, linkage, 
...]
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 05680fa5c0f5f..5234deba4ade3 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -250,6 +250,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase {
 
 protected:
   void writePerModuleGlobalValueSummary();
+  void writeGUIDList();
 
 private:
   void writePerModuleFunctionSummaryRecord(
@@ -1591,6 +1592,8 @@ void ModuleBitcodeWriter::writeModuleInfo() {
 Vals.clear();
   }
 
+  writeGUIDList();
+
   // Emit the global variable information.
   for (const GlobalVariable &GV : M.globals()) {
 unsigned AbbrevToUse = 0;
@@ -4896,6 +4899,26 @@ void 
ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
   Stream.ExitBlock();
 }
 
+void ModuleBitcodeWriterBase::writeGUIDList() {
+  std::vector GUIDs;
+  GUIDs.reserve(M.global_size() + M.size() + M.alias_size());
+
+  for (const GlobalValue &GV : M.global_objects()) {
+if (GV.isDeclaration()) {
+  GUIDs.push_back(
+  GlobalValue::getGUIDAssumingExternalLinkage(GV.getName()));
+} else {
+  GUIDs.push_back(GV.getGUID());
+}
+  }
+  for (const GlobalAlias &GA : M.aliases()) {
+// Equivalent to the above loop, as GlobalAliases are always definitions.
+GUIDs.push_back(GA.getGUID());
+  }
+
+  Stream.EmitRecord(bitc::MODULE_CODE_GUIDLIST, GUIDs);
+}
+
 /// Emit the combined summary section into the combined index file.
 void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
   Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4);
@@ -5684,6 +5707,8 @@ void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
 Vals.clear();
   }
 
+  writeGUIDList();
+
   // Emit the global variable information.
   for (const GlobalVariable &GV : M.globals()) {
 // GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage]

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailm

[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)

2025-08-04 Thread Owen Rodley via llvm-branch-commits

https://github.com/orodley updated 
https://github.com/llvm/llvm-project/pull/139497

>From 7f599c76af7fc371c6f8d54febc90e28a0b7a93c Mon Sep 17 00:00:00 2001
From: Owen Rodley 
Date: Mon, 12 May 2025 15:50:22 +1000
Subject: [PATCH] Add a GUIDLIST table to bitcode

---
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |  3 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++---
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index dc78eb4164acf..9fffa9695d210 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -120,6 +120,9 @@ enum ModuleCodes {
 
   // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
   MODULE_CODE_IFUNC = 18,
+
+  // GUIDLIST: [n x i64]
+  MODULE_CODE_GUIDLIST = 19,
 };
 
 /// PARAMATTR blocks have code for defining a parameter attribute set.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 290d873c632c9..b393fcb99b109 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -984,6 +984,9 @@ class ModuleSummaryIndexBitcodeReader : public 
BitcodeReaderBase {
   /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format.
   std::vector RadixArray;
 
+  // A table which maps ValueID to the GUID for that value.
+  std::vector DefinedGUIDs;
+
 public:
   ModuleSummaryIndexBitcodeReader(
   BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex,
@@ -7177,9 +7180,7 @@ 
ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) {
 void ModuleSummaryIndexBitcodeReader::setValueGUID(
 uint64_t ValueID, StringRef ValueName, GlobalValue::LinkageTypes Linkage,
 StringRef SourceFileName) {
-  std::string GlobalId =
-  GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName);
-  auto ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage(GlobalId);
+  auto ValueGUID = DefinedGUIDs[ValueID];
   auto OriginalNameID = ValueGUID;
   if (GlobalValue::isLocalLinkage(Linkage))
 OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName);
@@ -7402,6 +7403,10 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() {
   // was historically always the start of the regular bitcode header.
   VSTOffset = Record[0] - 1;
   break;
+// MODULE_CODE_GUIDLIST: [i64 x N]
+case bitc::MODULE_CODE_GUIDLIST:
+  llvm::append_range(DefinedGUIDs, Record);
+  break;
 // v1 GLOBALVAR: [pointer type, isconst, initid,   linkage, 
...]
 // v1 FUNCTION:  [type, callingconv, isproto,  linkage, 
...]
 // v1 ALIAS: [alias type,   addrspace,   aliasee val#, linkage, 
...]
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 05680fa5c0f5f..5234deba4ade3 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -250,6 +250,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase {
 
 protected:
   void writePerModuleGlobalValueSummary();
+  void writeGUIDList();
 
 private:
   void writePerModuleFunctionSummaryRecord(
@@ -1591,6 +1592,8 @@ void ModuleBitcodeWriter::writeModuleInfo() {
 Vals.clear();
   }
 
+  writeGUIDList();
+
   // Emit the global variable information.
   for (const GlobalVariable &GV : M.globals()) {
 unsigned AbbrevToUse = 0;
@@ -4896,6 +4899,26 @@ void 
ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
   Stream.ExitBlock();
 }
 
+void ModuleBitcodeWriterBase::writeGUIDList() {
+  std::vector GUIDs;
+  GUIDs.reserve(M.global_size() + M.size() + M.alias_size());
+
+  for (const GlobalValue &GV : M.global_objects()) {
+if (GV.isDeclaration()) {
+  GUIDs.push_back(
+  GlobalValue::getGUIDAssumingExternalLinkage(GV.getName()));
+} else {
+  GUIDs.push_back(GV.getGUID());
+}
+  }
+  for (const GlobalAlias &GA : M.aliases()) {
+// Equivalent to the above loop, as GlobalAliases are always definitions.
+GUIDs.push_back(GA.getGUID());
+  }
+
+  Stream.EmitRecord(bitc::MODULE_CODE_GUIDLIST, GUIDs);
+}
+
 /// Emit the combined summary section into the combined index file.
 void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
   Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4);
@@ -5684,6 +5707,8 @@ void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
 Vals.clear();
   }
 
+  writeGUIDList();
+
   // Emit the global variable information.
   for (const GlobalVariable &GV : M.globals()) {
 // GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage]

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailm

[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)

2025-08-04 Thread Lei Wang via llvm-branch-commits


@@ -540,6 +540,22 @@ void ProfileGenerator::generateLineNumBasedProfile() {
   // Fill in boundary sample counts as well as call site samples for calls
   populateBoundarySamplesForAllFunctions(SC.BranchCounter);
 
+  // For each instruction with vtable accesses, get its symbolized inline
+  // stack, and add the vtable counters to the function samples.
+  for (const auto &[IpData, Count] : SC.DataAccessCounter) {
+uint64_t InstAddr = IpData.first;
+const SampleContextFrameVector &FrameVec =
+Binary->getCachedFrameLocationStack(InstAddr, false);
+if (!FrameVec.empty()) {
+  FunctionSamples &FunctionProfile =
+  getLeafProfileAndAddTotalSamples(FrameVec, 0);
+  LineLocation Loc(
+  FrameVec.back().Location.LineOffset,
+  getBaseDiscriminator(FrameVec.back().Location.Discriminator));
+  FunctionProfile.addTypeSamplesAt(Loc, FunctionId(IpData.second), Count);
+}
+  }
+

wlei-llvm wrote:

Maybe move the code into a wrapper function, just to be consistent with other 
populate functions.

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


[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)

2025-08-04 Thread Lei Wang via llvm-branch-commits


@@ -67,6 +67,11 @@ static cl::opt DebugBinPath(
  "from it instead of the executable binary."),
 cl::cat(ProfGenCategory));
 
+static cl::opt DataAccessProfileFilename(
+"data-access-profile", cl::value_desc("data-access-profile"),
+cl::desc("Path to the data access profile to be generated."),
+cl::cat(ProfGenCategory));
+

wlei-llvm wrote:

if I understand correctly, this is the input perf trace not the generated 
output, then how about renaming it to something like `data-access-perftrace` or 
`data-access-perfscript`? In llvm-profgen, the "profile" is usually referred to 
the output of this tool. This also aligns with the parsing 
function("parseDataAccessPerfTraces").

Also, the comment "Path to the data access profile to be generated." made me 
think this refers to the output file, which could be confusing.

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


[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)

2025-08-04 Thread Lei Wang via llvm-branch-commits


@@ -0,0 +1,19 @@
+

wlei-llvm wrote:

Nit: remove the empty leading line. 

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


[llvm-branch-commits] [libcxx] release/21.x: [libc++][hardening] Add a greppable prefix to assertion messages. (#150560) (PR #151921)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:

@var-const What do you think about merging this PR to the release branch?

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


[llvm-branch-commits] [libcxx] release/21.x: [libc++][hardening] Add a greppable prefix to assertion messages. (#150560) (PR #151921)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/151921
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/21.x: [libc++][hardening] Add a greppable prefix to assertion messages. (#150560) (PR #151921)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/151921

Backport 4ef92469ab341ac1bee39a9413ffaa845e307414

Requested by: @var-const

>From 908b0e5893ce79231cb4e613da9c80f76a6ae1ed Mon Sep 17 00:00:00 2001
From: Konstantin Varlamov 
Date: Thu, 31 Jul 2025 02:52:17 -0700
Subject: [PATCH] [libc++][hardening] Add a greppable prefix to assertion
 messages. (#150560)

The current assertion failure messages produced by Hardening are not
very grep-friendly (the common part is rarther generic and requires
wildcards to match). While it's possible to use `__FILE__` for grepping,
it's easier and more straighforward to simply add a libc++-specific
prefix; this is especially important for the planned `observe` mode that
might produce many assertion failure messages over the course of the
program's execution that later need to be filtered and examined.

(cherry picked from commit 4ef92469ab341ac1bee39a9413ffaa845e307414)
---
 libcxx/include/__assert   | 4 ++--
 libcxx/test/support/check_assertion.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libcxx/include/__assert b/libcxx/include/__assert
index 90eaa6023587b..a9451daf47f2f 100644
--- a/libcxx/include/__assert
+++ b/libcxx/include/__assert
@@ -20,8 +20,8 @@
 #define _LIBCPP_ASSERT(expression, message)
\
   (__builtin_expect(static_cast(expression), 1)  
\
? (void)0   
\
-   : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": 
assertion " _LIBCPP_TOSTRING(\
- expression) " failed: " message "\n"))
+   : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(  
\
+ __LINE__) ": libc++ Hardening assertion " 
_LIBCPP_TOSTRING(expression) " failed: " message "\n"))
 
 // WARNING: __builtin_assume can currently inhibit optimizations. Only add 
assumptions with a clear
 // optimization intent. See 
https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a
diff --git a/libcxx/test/support/check_assertion.h 
b/libcxx/test/support/check_assertion.h
index a091043195345..8416de76cfd61 100644
--- a/libcxx/test/support/check_assertion.h
+++ b/libcxx/test/support/check_assertion.h
@@ -52,8 +52,8 @@ MatchResult MatchAssertionMessage(const std::string& text, 
std::string_view expe
   // library.
   std::string assertion_format_string = [&] {
 if (use_marker)
-  return (".*###\\n(.*):(\\d+): assertion (.*) failed: (.*)\\n###");
-return ("(.*):(\\d+): assertion (.*) failed: (.*)\\n");
+  return (".*###\\n(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) 
failed: (.*)\\n###");
+return ("(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) failed: 
(.*)\\n");
   }();
   std::regex assertion_format(assertion_format_string);
 

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


[llvm-branch-commits] [libcxx] release/21.x: [libc++][hardening] Add a greppable prefix to assertion messages. (#150560) (PR #151921)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: None (llvmbot)


Changes

Backport 4ef92469ab341ac1bee39a9413ffaa845e307414

Requested by: @var-const

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


2 Files Affected:

- (modified) libcxx/include/__assert (+2-2) 
- (modified) libcxx/test/support/check_assertion.h (+2-2) 


``diff
diff --git a/libcxx/include/__assert b/libcxx/include/__assert
index 90eaa6023587b..a9451daf47f2f 100644
--- a/libcxx/include/__assert
+++ b/libcxx/include/__assert
@@ -20,8 +20,8 @@
 #define _LIBCPP_ASSERT(expression, message)
\
   (__builtin_expect(static_cast(expression), 1)  
\
? (void)0   
\
-   : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": 
assertion " _LIBCPP_TOSTRING(\
- expression) " failed: " message "\n"))
+   : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(  
\
+ __LINE__) ": libc++ Hardening assertion " 
_LIBCPP_TOSTRING(expression) " failed: " message "\n"))
 
 // WARNING: __builtin_assume can currently inhibit optimizations. Only add 
assumptions with a clear
 // optimization intent. See 
https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a
diff --git a/libcxx/test/support/check_assertion.h 
b/libcxx/test/support/check_assertion.h
index a091043195345..8416de76cfd61 100644
--- a/libcxx/test/support/check_assertion.h
+++ b/libcxx/test/support/check_assertion.h
@@ -52,8 +52,8 @@ MatchResult MatchAssertionMessage(const std::string& text, 
std::string_view expe
   // library.
   std::string assertion_format_string = [&] {
 if (use_marker)
-  return (".*###\\n(.*):(\\d+): assertion (.*) failed: (.*)\\n###");
-return ("(.*):(\\d+): assertion (.*) failed: (.*)\\n");
+  return (".*###\\n(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) 
failed: (.*)\\n###");
+return ("(.*):(\\d+): libc\\+\\+ Hardening assertion (.*) failed: 
(.*)\\n");
   }();
   std::regex assertion_format(assertion_format_string);
 

``




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


[llvm-branch-commits] [llvm] [llvm][docs] Add release note for LLDB MTE changes (PR #151548)

2025-08-04 Thread Omair Javaid via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] [AArch64][ISel] Select constructive SVE2 ext instruction (PR #151730)

2025-08-04 Thread Gaëtan Bossu via llvm-branch-commits


@@ -4069,6 +4069,22 @@ let Predicates = [HasSVE2_or_SME] in {
   let AddedComplexity = 2 in {
 def : Pat<(nxv16i8 (AArch64ext nxv16i8:$zn1, nxv16i8:$zn2, (i32 
imm0_255:$imm))),
   (EXT_ZZI_B (REG_SEQUENCE ZPR2, $zn1, zsub0, $zn2, zsub1), 
imm0_255:$imm)>;
+
+foreach VT = [nxv16i8] in
+  def : Pat<(VT (vector_splice VT:$Z1, VT:$Z2, (i64 (sve_ext_imm_0_255 
i32:$index,
+(EXT_ZZI_B  (REG_SEQUENCE ZPR2, $Z1, zsub0, $Z2, zsub1), 
imm0_255:$index)>;

gbossu wrote:

Right, I guess I'll leave the intrinsic then

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


[llvm-branch-commits] [flang] release/21.x: [Flang][OpenMP][Docs] Update target-related support in Flang docs, NFC (#150443) (PR #151493)

2025-08-04 Thread Kiran Chandramohan via llvm-branch-commits

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

LG. 

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


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/151883

>From 37848d777f74c5052a8332033e51446a3f7a152f Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 3 Aug 2025 22:24:35 +0300
Subject: [PATCH] [libc][math] Refactor cos implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cos.h|  23 +++
 libc/src/__support/math/CMakeLists.txt|  47 +
 libc/src/__support/math/cos.h | 173 ++
 .../math}/range_reduction_double_common.h |  24 ++-
 .../math}/range_reduction_double_fma.h|  18 +-
 .../math}/range_reduction_double_nofma.h  |  16 +-
 .../generic => __support/math}/sincos_eval.h  |   8 +-
 libc/src/math/generic/CMakeLists.txt  |  50 +
 libc/src/math/generic/cos.cpp | 155 +---
 libc/src/math/generic/sin.cpp |  14 +-
 libc/src/math/generic/sincos.cpp  |  14 +-
 libc/src/math/generic/tan.cpp |   7 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel | 101 +-
 16 files changed, 377 insertions(+), 278 deletions(-)
 create mode 100644 libc/shared/math/cos.h
 create mode 100644 libc/src/__support/math/cos.h
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_common.h (97%)
 rename libc/src/{math/generic => __support/math}/range_reduction_double_fma.h 
(97%)
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_nofma.h (97%)
 rename libc/src/{math/generic => __support/math}/sincos_eval.h (98%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos function -*- 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 LLVM_LIBC_SHARED_MATH_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos ---*- C

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/151883

>From 14a8e8add569e7e423cfc57ecf85c722063f0835 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 3 Aug 2025 22:24:35 +0300
Subject: [PATCH] [libc][math] Refactor cos implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cos.h|  23 +++
 libc/src/__support/math/CMakeLists.txt|  47 +
 libc/src/__support/math/cos.h | 173 ++
 .../math}/range_reduction_double_common.h |  24 ++-
 .../math}/range_reduction_double_fma.h|  18 +-
 .../math}/range_reduction_double_nofma.h  |  16 +-
 .../generic => __support/math}/sincos_eval.h  |   8 +-
 libc/src/math/generic/CMakeLists.txt  |  50 +
 libc/src/math/generic/cos.cpp | 155 +---
 libc/src/math/generic/sin.cpp |  14 +-
 libc/src/math/generic/sincos.cpp  |  14 +-
 libc/src/math/generic/tan.cpp |   7 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel | 101 +-
 16 files changed, 377 insertions(+), 278 deletions(-)
 create mode 100644 libc/shared/math/cos.h
 create mode 100644 libc/src/__support/math/cos.h
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_common.h (97%)
 rename libc/src/{math/generic => __support/math}/range_reduction_double_fma.h 
(97%)
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_nofma.h (97%)
 rename libc/src/{math/generic => __support/math}/sincos_eval.h (98%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos function -*- 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 LLVM_LIBC_SHARED_MATH_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos ---*- C

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cosf implementation to header-only in src/__support/math folder. (PR #152069)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/152069

>From 2ff880d6bf304f919b92ae62cac84e4b9789bcf1 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Tue, 5 Aug 2025 06:30:16 +0300
Subject: [PATCH] [libc][math] Refactor cosf implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cosf.h   |  23 +++
 libc/src/__support/math/CMakeLists.txt|  39 +
 libc/src/__support/math/cosf.h| 152 ++
 .../math}/range_reduction.h   |   6 +-
 .../math}/range_reduction_fma.h   |   6 +-
 .../math}/sincosf_utils.h |   6 +-
 libc/src/math/generic/CMakeLists.txt  |  52 ++
 libc/src/math/generic/cosf.cpp| 133 +--
 libc/src/math/generic/cospif.cpp  |   2 +-
 libc/src/math/generic/sincosf.cpp |   2 +-
 libc/src/math/generic/sinf.cpp|   6 +-
 libc/src/math/generic/sinpif.cpp  |   2 +-
 libc/src/math/generic/tanf.cpp|   2 +-
 libc/src/math/generic/tanpif.cpp  |   2 +-
 .../llvm-project-overlay/libc/BUILD.bazel |  84 +-
 16 files changed, 290 insertions(+), 228 deletions(-)
 create mode 100644 libc/shared/math/cosf.h
 create mode 100644 libc/src/__support/math/cosf.h
 rename libc/src/{math/generic => __support/math}/range_reduction.h (95%)
 rename libc/src/{math/generic => __support/math}/range_reduction_fma.h (95%)
 rename libc/src/{math/generic => __support/math}/sincosf_utils.h (97%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index a5581ed4272a3..0c11640101563 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -33,6 +33,7 @@
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
 #include "math/cos.h"
+#include "math/cosf.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cosf.h b/libc/shared/math/cosf.h
new file mode 100644
index 0..06182207a82f2
--- /dev/null
+++ b/libc/shared/math/cosf.h
@@ -0,0 +1,23 @@
+//===-- Shared cosf function *- 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 LLVM_LIBC_SHARED_MATH_COSF_H
+#define LLVM_LIBC_SHARED_MATH_COSF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cosf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cosf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COSF_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 24844063fcd24..450d56acafe53 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -374,6 +374,21 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cosf
+  HDRS
+cosf.h
+  DEPENDS
+.sincosf_utils
+libc.src.errno.errno
+libc.src.__support.FPUtil.basic_operations
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.macros.optimization
+)
 
 add_header_library(
   erff
@@ -649,6 +664,19 @@ add_header_library(
 libc.src.__support.integer_literals
 )
 
+add_header_library(
+  range_reduction
+  HDRS
+range_reduction.h
+range_reduction_fma.h
+  DEPENDS
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+)
+
 add_header_library(
   sincos_eval
   HDRS
@@ -660,3 +688,14 @@ add_header_library(
 libc.src.__support.FPUtil.polyeval
 libc.src.__support.integer_literals
 )
+
+add_header_library(
+  sincosf_utils
+  HDRS
+sincosf_utils.h
+  DEPENDS
+.range_reduction
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.common
+)
diff --git a/libc/src/__support/math/cosf.h b/libc/src/__support/math/cosf.h
new file mode 100644
index 0..074be0b314637
--- /dev/null
+++ b/libc/src/__support/math/cosf.h
@@ -0,0 +1,152 @@
+//===-- Implementation header for cosf --*- 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 LIBC_SRC___SU

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cos implementation to header-only in src/__support/math folder. (PR #151883)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/151883

>From 14a8e8add569e7e423cfc57ecf85c722063f0835 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 3 Aug 2025 22:24:35 +0300
Subject: [PATCH] [libc][math] Refactor cos implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cos.h|  23 +++
 libc/src/__support/math/CMakeLists.txt|  47 +
 libc/src/__support/math/cos.h | 173 ++
 .../math}/range_reduction_double_common.h |  24 ++-
 .../math}/range_reduction_double_fma.h|  18 +-
 .../math}/range_reduction_double_nofma.h  |  16 +-
 .../generic => __support/math}/sincos_eval.h  |   8 +-
 libc/src/math/generic/CMakeLists.txt  |  50 +
 libc/src/math/generic/cos.cpp | 155 +---
 libc/src/math/generic/sin.cpp |  14 +-
 libc/src/math/generic/sincos.cpp  |  14 +-
 libc/src/math/generic/tan.cpp |   7 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel | 101 +-
 16 files changed, 377 insertions(+), 278 deletions(-)
 create mode 100644 libc/shared/math/cos.h
 create mode 100644 libc/src/__support/math/cos.h
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_common.h (97%)
 rename libc/src/{math/generic => __support/math}/range_reduction_double_fma.h 
(97%)
 rename libc/src/{math/generic => 
__support/math}/range_reduction_double_nofma.h (97%)
 rename libc/src/{math/generic => __support/math}/sincos_eval.h (98%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ea645f0afedbc..a5581ed4272a3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,7 @@
 #include "math/atanhf16.h"
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
+#include "math/cos.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cos.h b/libc/shared/math/cos.h
new file mode 100644
index 0..c498550f098b4
--- /dev/null
+++ b/libc/shared/math/cos.h
@@ -0,0 +1,23 @@
+//===-- Shared cos function -*- 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 LLVM_LIBC_SHARED_MATH_COS_H
+#define LLVM_LIBC_SHARED_MATH_COS_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cos.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cos;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COS_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index fe928a8fadd5e..24844063fcd24 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,24 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cos
+  HDRS
+cos.h
+  DEPENDS
+libc.src.__support.math.sincos_eval
+libc.hdr.errno_macros
+libc.src.errno.errno
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.math.range_reduction_double
+libc.src.__support.macros.optimization
+)
+
+
 add_header_library(
   erff
   HDRS
@@ -613,3 +631,32 @@ add_header_library(
 libc.src.__support.macros.optimization
 libc.src.__support.macros.properties.cpu_features
 )
+
+add_header_library(
+  range_reduction_double
+  HDRS
+range_reduction_double_common.h
+range_reduction_double_fma.h
+range_reduction_double_nofma.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+libc.src.__support.integer_literals
+)
+
+add_header_library(
+  sincos_eval
+  HDRS
+sincos_eval.h
+  DEPENDS
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.integer_literals
+)
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
new file mode 100644
index 0..0802f9e4f6e49
--- /dev/null
+++ b/libc/src/__support/math/cos.h
@@ -0,0 +1,173 @@
+//===-- Implementation header for cos ---*- C

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor cosf implementation to header-only in src/__support/math folder. (PR #152069)

2025-08-04 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/152069

>From 2ff880d6bf304f919b92ae62cac84e4b9789bcf1 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Tue, 5 Aug 2025 06:30:16 +0300
Subject: [PATCH] [libc][math] Refactor cosf implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/cosf.h   |  23 +++
 libc/src/__support/math/CMakeLists.txt|  39 +
 libc/src/__support/math/cosf.h| 152 ++
 .../math}/range_reduction.h   |   6 +-
 .../math}/range_reduction_fma.h   |   6 +-
 .../math}/sincosf_utils.h |   6 +-
 libc/src/math/generic/CMakeLists.txt  |  52 ++
 libc/src/math/generic/cosf.cpp| 133 +--
 libc/src/math/generic/cospif.cpp  |   2 +-
 libc/src/math/generic/sincosf.cpp |   2 +-
 libc/src/math/generic/sinf.cpp|   6 +-
 libc/src/math/generic/sinpif.cpp  |   2 +-
 libc/src/math/generic/tanf.cpp|   2 +-
 libc/src/math/generic/tanpif.cpp  |   2 +-
 .../llvm-project-overlay/libc/BUILD.bazel |  84 +-
 16 files changed, 290 insertions(+), 228 deletions(-)
 create mode 100644 libc/shared/math/cosf.h
 create mode 100644 libc/src/__support/math/cosf.h
 rename libc/src/{math/generic => __support/math}/range_reduction.h (95%)
 rename libc/src/{math/generic => __support/math}/range_reduction_fma.h (95%)
 rename libc/src/{math/generic => __support/math}/sincosf_utils.h (97%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index a5581ed4272a3..0c11640101563 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -33,6 +33,7 @@
 #include "math/cbrt.h"
 #include "math/cbrtf.h"
 #include "math/cos.h"
+#include "math/cosf.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/cosf.h b/libc/shared/math/cosf.h
new file mode 100644
index 0..06182207a82f2
--- /dev/null
+++ b/libc/shared/math/cosf.h
@@ -0,0 +1,23 @@
+//===-- Shared cosf function *- 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 LLVM_LIBC_SHARED_MATH_COSF_H
+#define LLVM_LIBC_SHARED_MATH_COSF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/cosf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::cosf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_COSF_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 24844063fcd24..450d56acafe53 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -374,6 +374,21 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  cosf
+  HDRS
+cosf.h
+  DEPENDS
+.sincosf_utils
+libc.src.errno.errno
+libc.src.__support.FPUtil.basic_operations
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.macros.optimization
+)
 
 add_header_library(
   erff
@@ -649,6 +664,19 @@ add_header_library(
 libc.src.__support.integer_literals
 )
 
+add_header_library(
+  range_reduction
+  HDRS
+range_reduction.h
+range_reduction_fma.h
+  DEPENDS
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.fma
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.common
+)
+
 add_header_library(
   sincos_eval
   HDRS
@@ -660,3 +688,14 @@ add_header_library(
 libc.src.__support.FPUtil.polyeval
 libc.src.__support.integer_literals
 )
+
+add_header_library(
+  sincosf_utils
+  HDRS
+sincosf_utils.h
+  DEPENDS
+.range_reduction
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.common
+)
diff --git a/libc/src/__support/math/cosf.h b/libc/src/__support/math/cosf.h
new file mode 100644
index 0..074be0b314637
--- /dev/null
+++ b/libc/src/__support/math/cosf.h
@@ -0,0 +1,152 @@
+//===-- Implementation header for cosf --*- 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 LIBC_SRC___SU