[llvm-branch-commits] [ubsan] Pass fsanitize-skip-hot-cutoff into -fsanitize=bounds (PR #122576)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122576


___
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] [ubsan] Pass fsanitize-skip-hot-cutoff into -fsanitize=bounds (PR #122576)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122576


___
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] [ubsan] Pass fsanitize-skip-hot-cutoff into -fsanitize=bounds (PR #122576)

2025-01-10 Thread Thurston Dang via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/122576
___
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] [nfc][ubsan] Add local-bounds test (PR #122415)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122415


___
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] [nfc][ubsan] Add local-bounds test (PR #122415)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122415


___
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] [Flang-RT] Build libflang_rt.so (PR #121782)

2025-01-10 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/121782

>From a3037ab5557dcc4a4deb5bb40f801ca9770e3854 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Mon, 6 Jan 2025 16:44:08 +0100
Subject: [PATCH 1/5] Add FLANG_RT_ENABLE_STATIC and FLANG_RT_ENABLE_SHARED

---
 flang-rt/CMakeLists.txt   |  30 ++
 flang-rt/cmake/modules/AddFlangRT.cmake   | 291 --
 .../cmake/modules/AddFlangRTOffload.cmake |   8 +-
 flang-rt/cmake/modules/GetToolchainDirs.cmake | 254 +++
 flang-rt/lib/flang_rt/CMakeLists.txt  |  20 +-
 flang-rt/test/CMakeLists.txt  |   2 +-
 flang-rt/test/lit.cfg.py  |   2 +-
 7 files changed, 366 insertions(+), 241 deletions(-)

diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index 7b3d22e454a108..7effa6012a078f 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -113,6 +113,15 @@ cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR)
 cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH)
 
 # Determine subdirectories for build output and install destinations.
+# FIXME: For the libflang_rt.so, the toolchain resource lib dir is not a good
+#destination because it is not a ld.so default search path.
+#The machine where the executable is eventually executed may not be the
+#machine where the Flang compiler and its resource dir is installed, so
+#setting RPath by the driver is not an solution. It should belong into
+#/usr/lib//libflang_rt.so, like e.g. libgcc_s.so.
+#But the linker as invoked by the Flang driver also requires
+#libflang_rt.so to be found when linking and the resource lib dir is
+#the only reliable location.
 get_toolchain_library_subdir(toolchain_lib_subdir)
 extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" 
"${toolchain_lib_subdir}")
 extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH 
"${FLANG_RT_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
@@ -130,6 +139,27 @@ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
 option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit 
and regression-tests." "${LLVM_INCLUDE_TESTS}")
 
 
+option(FLANG_RT_ENABLE_STATIC "Build Flang-RT as a static library." ON)
+if (WIN32)
+  # Windows DLL currently not implemented.
+  set(FLANG_RT_ENABLE_SHARED OFF)
+else ()
+  # TODO: Enable by default to increase test coverage, and which version of the
+  #   library should be the user's choice anyway.
+  #   Currently, the Flang driver adds `-L"libdir" -lflang_rt` as linker
+  #   argument, which leaves the choice which library to use to the linker.
+  #   Since most linkers prefer the shared library, this would constitute a
+  #   breaking change unless the driver is changed.
+  option(FLANG_RT_ENABLE_SHARED "Build Flang-RT as a shared library." OFF)
+endif ()
+if (NOT FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
+  message(FATAL_ERROR "
+  Must build at least one type of library
+  (FLANG_RT_ENABLE_STATIC=ON, FLANG_RT_ENABLE_SHARED=ON, or both)
+")
+endif ()
+
+
 set(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT "" CACHE STRING "Compile Flang-RT 
with GPU support (CUDA or OpenMP)")
 set_property(CACHE FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT PROPERTY STRINGS
 ""
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake 
b/flang-rt/cmake/modules/AddFlangRT.cmake
index 1f8b5111433825..5f493a80c35f20 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -16,7 +16,8 @@
 #   STATIC
 # Build a static (.a/.lib) library
 #   OBJECT
-# Create only object files without static/dynamic library
+# Always create an object library.
+# Without SHARED/STATIC, build only the object library.
 #   INSTALL_WITH_TOOLCHAIN
 # Install library into Clang's resource directory so it can be found by the
 # Flang driver during compilation, including tests
@@ -44,17 +45,73 @@ function (add_flangrt_library name)
   ")
   endif ()
 
-  # Forward libtype to add_library
-  set(extra_args "")
-  if (ARG_SHARED)
-list(APPEND extra_args SHARED)
+  # Internal names of libraries. If called with just single type option, use
+  # the default name for it. Name of targets must only depend on function
+  # arguments to be predictable for callers.
+  set(name_static "${name}.static")
+  set(name_shared "${name}.shared")
+  set(name_object "obj.${name}")
+  if (ARG_STATIC AND NOT ARG_SHARED)
+set(name_static "${name}")
+  elseif (NOT ARG_STATIC AND ARG_SHARED)
+set(name_shared "${name}")
+  elseif (NOT ARG_STATIC AND NOT ARG_SHARED AND ARG_OBJECT)
+set(name_object "${name}")
+  elseif (NOT ARG_STATIC AND NOT ARG_SHARED AND NOT ARG_OBJECT)
+# Only one of them will actually be built.
+set(name_static "${name}")
+set(name_shared "${name}")
+  endif ()
+
+  # Determine what to build. If not explicitly

[llvm-branch-commits] [ubsan] Pass fsanitize-skip-hot-cutoff into -fsanitize=bounds (PR #122576)

2025-01-10 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vitaly Buka (vitalybuka)


Changes



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


3 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+7) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+3-1) 
- (modified) clang/test/CodeGen/allow-ubsan-check.c (+22-16) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 2863887fd4d2f9..bb73f4a5dbde19 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -118,6 +118,9 @@ static cl::opt ClPGOColdFuncAttr(
 
 extern cl::opt ProfileCorrelate;
 } // namespace llvm
+namespace clang {
+extern llvm::cl::opt ClSanitizeGuardChecks;
+}
 
 namespace {
 
@@ -1025,6 +1028,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   PB.registerScalarOptimizerLateEPCallback([this](FunctionPassManager &FPM,
   OptimizationLevel Level) 
{
 BoundsCheckingPass::Options Options;
+if (CodeGenOpts.SanitizeSkipHotCutoffs[SanitizerKind::SO_LocalBounds] 
||
+ClSanitizeGuardChecks) {
+  Options.GuardKind = SanitizerKind::SO_LocalBounds;
+}
 Options.Merge =
 CodeGenOpts.SanitizeMergeHandlers.has(SanitizerKind::LocalBounds);
 if (!CodeGenOpts.SanitizeTrap.has(SanitizerKind::LocalBounds)) {
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 060d02b7f14873..6e5a21c8f01e78 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -52,11 +52,13 @@
 using namespace clang;
 using namespace CodeGen;
 
+namespace clang {
 // TODO: Introduce frontend options to enabled per sanitizers, similar to
 // `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeGuardChecks(
+llvm::cl::opt ClSanitizeGuardChecks(
 "ubsan-guard-checks", llvm::cl::Optional,
 llvm::cl::desc("Guard UBSAN checks with `llvm.allow.ubsan.check()`."));
+} // namespace clang
 
 //======//
 //Defines for metadata
diff --git a/clang/test/CodeGen/allow-ubsan-check.c 
b/clang/test/CodeGen/allow-ubsan-check.c
index fb264ce32ab996..38b4848c1edc14 100644
--- a/clang/test/CodeGen/allow-ubsan-check.c
+++ b/clang/test/CodeGen/allow-ubsan-check.c
@@ -174,12 +174,14 @@ void use(double*);
 // CHECK-NEXT:[[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
 // CHECK-NEXT:call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR7:[0-9]+]]
 // CHECK-NEXT:[[IDXPROM:%.*]] = sext i32 [[I]] to i64
-// CHECK-NEXT:[[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
-// CHECK-NEXT:br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
-// CHECK:   [[BB1]]:
+// CHECK-NEXT:[[TMP1:%.*]] = icmp ule i64 [[TMP0]], [[IDXPROM]]
+// CHECK-NEXT:[[TMP2:%.*]] = call i1 @llvm.allow.ubsan.check(i8 71), 
!nosanitize [[META2]]
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 [[TMP1]], [[TMP2]], !nosanitize 
[[META2]]
+// CHECK-NEXT:br i1 [[TMP3]], label %[[TRAP:.*]], label %[[BB4:.*]]
+// CHECK:   [[BB4]]:
 // CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr 
[[VLA]], i64 [[IDXPROM]]
-// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA8:![0-9]+]]
-// CHECK-NEXT:ret double [[TMP2]]
+// CHECK-NEXT:[[TMP5:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA8:![0-9]+]]
+// CHECK-NEXT:ret double [[TMP5]]
 // CHECK:   [[TRAP]]:
 // CHECK-NEXT:call void @__ubsan_handle_local_out_of_bounds_abort() 
#[[ATTR6]], !nosanitize [[META2]]
 // CHECK-NEXT:unreachable, !nosanitize [[META2]]
@@ -191,12 +193,14 @@ void use(double*);
 // TR-NEXT:[[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
 // TR-NEXT:call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR6:[0-9]+]]
 // TR-NEXT:[[IDXPROM:%.*]] = sext i32 [[I]] to i64
-// TR-NEXT:[[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
-// TR-NEXT:br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
-// TR:   [[BB1]]:
+// TR-NEXT:[[TMP1:%.*]] = icmp ule i64 [[TMP0]], [[IDXPROM]]
+// TR-NEXT:[[TMP2:%.*]] = call i1 @llvm.allow.ubsan.check(i8 71), 
!nosanitize [[META2]]
+// TR-NEXT:[[TMP3:%.*]] = and i1 [[TMP1]], [[TMP2]], !nosanitize [[META2]]
+// TR-NEXT:br i1 [[TMP3]], label %[[TRAP:.*]], label %[[BB4:.*]]
+// TR:   [[BB4]]:
 // TR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], 
i64 [[IDXPROM]]
-// TR-NEXT:[[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA7:![0-9]+]]
-// TR-NEXT:ret double [[TMP2]]
+// TR-NEXT:[[TMP5:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA7:![0-9]+]]
+// TR-NEXT:ret double [[TMP5]]
 // TR:   [[TRAP]]:
 // TR-NEXT:call void @llvm.ubsantrap(i8 3) #[[ATTR5]], !nosanitize 
[[META2]]
 // TR-NEXT:unreachable, !nosanitize [[META2]]
@@ -208,15 +212,17

[llvm-branch-commits] [ubsan] Pass fsanitize-skip-hot-cutoff into -fsanitize=bounds (PR #122576)

2025-01-10 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Vitaly Buka (vitalybuka)


Changes



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


3 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+7) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+3-1) 
- (modified) clang/test/CodeGen/allow-ubsan-check.c (+22-16) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 2863887fd4d2f9..bb73f4a5dbde19 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -118,6 +118,9 @@ static cl::opt ClPGOColdFuncAttr(
 
 extern cl::opt ProfileCorrelate;
 } // namespace llvm
+namespace clang {
+extern llvm::cl::opt ClSanitizeGuardChecks;
+}
 
 namespace {
 
@@ -1025,6 +1028,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   PB.registerScalarOptimizerLateEPCallback([this](FunctionPassManager &FPM,
   OptimizationLevel Level) 
{
 BoundsCheckingPass::Options Options;
+if (CodeGenOpts.SanitizeSkipHotCutoffs[SanitizerKind::SO_LocalBounds] 
||
+ClSanitizeGuardChecks) {
+  Options.GuardKind = SanitizerKind::SO_LocalBounds;
+}
 Options.Merge =
 CodeGenOpts.SanitizeMergeHandlers.has(SanitizerKind::LocalBounds);
 if (!CodeGenOpts.SanitizeTrap.has(SanitizerKind::LocalBounds)) {
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 060d02b7f14873..6e5a21c8f01e78 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -52,11 +52,13 @@
 using namespace clang;
 using namespace CodeGen;
 
+namespace clang {
 // TODO: Introduce frontend options to enabled per sanitizers, similar to
 // `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeGuardChecks(
+llvm::cl::opt ClSanitizeGuardChecks(
 "ubsan-guard-checks", llvm::cl::Optional,
 llvm::cl::desc("Guard UBSAN checks with `llvm.allow.ubsan.check()`."));
+} // namespace clang
 
 //======//
 //Defines for metadata
diff --git a/clang/test/CodeGen/allow-ubsan-check.c 
b/clang/test/CodeGen/allow-ubsan-check.c
index fb264ce32ab996..38b4848c1edc14 100644
--- a/clang/test/CodeGen/allow-ubsan-check.c
+++ b/clang/test/CodeGen/allow-ubsan-check.c
@@ -174,12 +174,14 @@ void use(double*);
 // CHECK-NEXT:[[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
 // CHECK-NEXT:call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR7:[0-9]+]]
 // CHECK-NEXT:[[IDXPROM:%.*]] = sext i32 [[I]] to i64
-// CHECK-NEXT:[[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
-// CHECK-NEXT:br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
-// CHECK:   [[BB1]]:
+// CHECK-NEXT:[[TMP1:%.*]] = icmp ule i64 [[TMP0]], [[IDXPROM]]
+// CHECK-NEXT:[[TMP2:%.*]] = call i1 @llvm.allow.ubsan.check(i8 71), 
!nosanitize [[META2]]
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 [[TMP1]], [[TMP2]], !nosanitize 
[[META2]]
+// CHECK-NEXT:br i1 [[TMP3]], label %[[TRAP:.*]], label %[[BB4:.*]]
+// CHECK:   [[BB4]]:
 // CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr 
[[VLA]], i64 [[IDXPROM]]
-// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA8:![0-9]+]]
-// CHECK-NEXT:ret double [[TMP2]]
+// CHECK-NEXT:[[TMP5:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA8:![0-9]+]]
+// CHECK-NEXT:ret double [[TMP5]]
 // CHECK:   [[TRAP]]:
 // CHECK-NEXT:call void @__ubsan_handle_local_out_of_bounds_abort() 
#[[ATTR6]], !nosanitize [[META2]]
 // CHECK-NEXT:unreachable, !nosanitize [[META2]]
@@ -191,12 +193,14 @@ void use(double*);
 // TR-NEXT:[[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
 // TR-NEXT:call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR6:[0-9]+]]
 // TR-NEXT:[[IDXPROM:%.*]] = sext i32 [[I]] to i64
-// TR-NEXT:[[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
-// TR-NEXT:br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
-// TR:   [[BB1]]:
+// TR-NEXT:[[TMP1:%.*]] = icmp ule i64 [[TMP0]], [[IDXPROM]]
+// TR-NEXT:[[TMP2:%.*]] = call i1 @llvm.allow.ubsan.check(i8 71), 
!nosanitize [[META2]]
+// TR-NEXT:[[TMP3:%.*]] = and i1 [[TMP1]], [[TMP2]], !nosanitize [[META2]]
+// TR-NEXT:br i1 [[TMP3]], label %[[TRAP:.*]], label %[[BB4:.*]]
+// TR:   [[BB4]]:
 // TR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], 
i64 [[IDXPROM]]
-// TR-NEXT:[[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA7:![0-9]+]]
-// TR-NEXT:ret double [[TMP2]]
+// TR-NEXT:[[TMP5:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[TBAA7:![0-9]+]]
+// TR-NEXT:ret double [[TMP5]]
 // TR:   [[TRAP]]:
 // TR-NEXT:call void @llvm.ubsantrap(i8 3) #[[ATTR5]], !nosanitize 
[[META2]]
 // TR-NEXT:unreachable, !nosanitize [[META2]]
@@ -208,15

[llvm-branch-commits] [llvm] [ctxprof] Move test serialization to yaml (PR #122545)

2025-01-10 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin edited 
https://github.com/llvm/llvm-project/pull/122545
___
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] [ctxprof] Move test serialization to yaml (PR #122545)

2025-01-10 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin ready_for_review 
https://github.com/llvm/llvm-project/pull/122545
___
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-cov: [MCDC] Merge and recalculate independence pairs on template instantiations. (PR #121196)

2025-01-10 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/121196

>From dc0ef8f682f704422ec52b484248cdfee1a6e804 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 27 Dec 2024 16:19:01 +0900
Subject: [PATCH] llvm-cov: [MCDC] Merge and recalculate independence pairs on
 template instantiations.

---
 .../ProfileData/Coverage/CoverageMapping.h| 16 --
 .../ProfileData/Coverage/CoverageMapping.cpp  | 57 ---
 .../llvm-cov/Inputs/mcdc-templates-merge.cpp  |  4 +-
 .../tools/llvm-cov/mcdc-templates-merge.test  |  2 +-
 4 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index cfaee395655295..5d7d555a10bd3a 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -471,6 +471,7 @@ struct MCDCRecord {
 }
   };
 
+  using BitmapByCondTy = std::array;
   using TestVectors = llvm::SmallVector>;
   using BoolVector = std::array;
   using TVRowPair = std::pair;
@@ -481,6 +482,7 @@ struct MCDCRecord {
 private:
   CounterMappingRegion Region;
   TestVectors TV;
+  BitmapByCondTy BitmapByCond;
   std::optional IndependencePairs;
   BoolVector Folded;
   CondIDMap PosToID;
@@ -488,8 +490,10 @@ struct MCDCRecord {
 
 public:
   MCDCRecord(const CounterMappingRegion &Region, TestVectors &&TV,
- BoolVector &&Folded, CondIDMap &&PosToID, LineColPairMap 
&&CondLoc)
-  : Region(Region), TV(std::move(TV)), Folded(std::move(Folded)),
+ BitmapByCondTy &&BitmapByCond, BoolVector &&Folded,
+ CondIDMap &&PosToID, LineColPairMap &&CondLoc)
+  : Region(Region), TV(std::move(TV)),
+BitmapByCond(std::move(BitmapByCond)), Folded(std::move(Folded)),
 PosToID(std::move(PosToID)), CondLoc(std::move(CondLoc)) {
 findIndependencePairs();
   }
@@ -497,8 +501,9 @@ struct MCDCRecord {
   inline LineColPair viewLoc() const { return Region.endLoc(); }
 
   bool isMergeable(const MCDCRecord &RHS) const {
-return (this->viewLoc() == RHS.viewLoc() && this->PosToID == RHS.PosToID &&
-this->CondLoc == RHS.CondLoc);
+return (this->viewLoc() == RHS.viewLoc() &&
+this->BitmapByCond[false].size() == RHS.BitmapByCond[true].size() 
&&
+this->PosToID == RHS.PosToID && this->CondLoc == RHS.CondLoc);
   }
 
   // This may invalidate IndependencePairs
@@ -577,7 +582,8 @@ struct MCDCRecord {
 auto [Covered, Folded] = getCoveredCount();
 auto NumTVs = getNumTestVectors();
 switch (Strategy) {
-case MergeStrategy::Merge:
+default:
+  llvm_unreachable("Not supported");
 case MergeStrategy::Any:
   return {
   Covered, // The largest covered number
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 76aa008886291e..8dd354f5122253 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -260,17 +260,55 @@ void CountedRegion::merge(const CountedRegion &RHS, 
MergeStrategy Strategy) {
 }
 
 void MCDCRecord::merge(MCDCRecord &&RHS, MergeStrategy Strategy) {
+  assert(this->TV.size() ==
+ this->BitmapByCond[false].count() + this->BitmapByCond[true].count());
+  assert(RHS.TV.size() ==
+ RHS.BitmapByCond[false].count() + RHS.BitmapByCond[true].count());
   assert(this->PosToID == RHS.PosToID);
   assert(this->CondLoc == RHS.CondLoc);
 
   switch (Strategy) {
   case MergeStrategy::Merge:
+break;
   case MergeStrategy::Any:
   case MergeStrategy::All:
 if (this->getMergeRank(Strategy) < RHS.getMergeRank(Strategy))
   *this = std::move(RHS);
 return;
   }
+
+  std::array LHSTV;
+  auto LHSI = this->TV.begin();
+  auto RHSI = RHS.TV.begin();
+  bool Merged = false;
+  for (auto MCDCCond : {MCDCRecord::MCDC_False, MCDCRecord::MCDC_True}) {
+auto &LHSBitmap = this->BitmapByCond[MCDCCond];
+auto &RHSBitmap = RHS.BitmapByCond[MCDCCond];
+for (unsigned I = 0, E = LHSBitmap.size(); I != E; ++I) {
+  if (LHSBitmap[I]) {
+if (RHSBitmap[I])
+  ++RHSI;
+LHSTV[LHSI->second].push_back(std::move(*LHSI++));
+  } else if (RHSBitmap[I]) {
+LHSTV[RHSI->second].push_back(std::move(*RHSI++));
+LHSBitmap[I] = true;
+Merged = true;
+  }
+}
+
+this->Folded[MCDCCond] &= RHS.Folded[MCDCCond];
+  }
+
+  if (Merged)
+IndependencePairs.reset();
+
+  assert(LHSI == this->TV.end());
+  assert(RHSI == RHS.TV.end());
+  this->TV = std::move(LHSTV[false]);
+  this->TV.append(std::make_move_iterator(LHSTV[true].begin()),
+  std::make_move_iterator(LHSTV[true].end()));
+  assert(this->TV.size() ==
+ this->BitmapByCond[false].count() + this->BitmapByCond[true].count());
 }
 
 // Find an independence pair for each condition:
@@ -284,13 +3

[llvm-branch-commits] [llvm] [ctxprof] Move test serialization to yaml (PR #122545)

2025-01-10 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lto

Author: Mircea Trofin (mtrofin)


Changes

We have a textual representation of contextual profiles for test scenarios, 
mainly. This patch moves that to YAML instead of JSON. YAML is more succinct 
and readable (some of the .ll tests should be illustrative). In addition, JSON 
is parse-able by the YAML reader.

A subsequent patch will address deserialization.

---

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


31 Files Affected:

- (modified) llvm/include/llvm/ProfileData/PGOCtxProfWriter.h (+9-1) 
- (modified) llvm/lib/ProfileData/PGOCtxProfWriter.cpp (+25-32) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-and-annotate.ll 
(+10-22) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll (+12-9) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-icp.ll (+16-9) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-zero-path.ll (+4-3) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/full-cycle.ll (+16-50) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/handle-select.ll (+10-3) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/inline.ll (+16-17) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/load-unapplicable.ll (+11-33) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/load.ll (+11-33) 
- (modified) llvm/test/ThinLTO/X86/ctxprof.ll (+2-2) 
- (modified) 
llvm/test/Transforms/EliminateAvailableExternally/transform-to-local.ll (+2-2) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/bad.json (-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/bad.yaml (+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/empty.json (-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/empty.yaml () 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-bad-subctx.json 
(-8) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-bad-subctx.yaml (+4) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-counters.json 
(-5) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-counters.yaml 
(+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-ctx.json (-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-ctx.yaml (+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-vector.json 
(-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-vector.yaml (+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/valid.json (-47) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/valid.yaml (+13) 
- (modified) llvm/test/tools/llvm-ctxprof-util/llvm-ctxprof-util-negative.test 
(+18-18) 
- (modified) llvm/test/tools/llvm-ctxprof-util/llvm-ctxprof-util.test (+4-4) 
- (modified) llvm/tools/llvm-ctxprof-util/llvm-ctxprof-util.cpp (+7-7) 
- (modified) llvm/unittests/Transforms/Utils/CallPromotionUtilsTest.cpp (+1-1) 


``diff
diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h 
b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
index b370fdd9ba5a1c..f6158609c12855 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
@@ -81,6 +81,14 @@ class PGOCtxProfileWriter final {
   static constexpr StringRef ContainerMagic = "CTXP";
 };
 
-Error createCtxProfFromJSON(StringRef Profile, raw_ostream &Out);
+/// Representation of the context node suitable for yaml / json serialization /
+/// deserialization.
+struct SerializableCtxRepresentation {
+  ctx_profile::GUID Guid = 0;
+  std::vector Counters;
+  std::vector> Callsites;
+};
+
+Error createCtxProfFromYAML(StringRef Profile, raw_ostream &Out);
 } // namespace llvm
 #endif
diff --git a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp 
b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
index 4c0f3d459988b1..d22aadd6bd7eb0 100644
--- a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
@@ -13,7 +13,11 @@
 #include "llvm/ProfileData/PGOCtxProfWriter.h"
 #include "llvm/Bitstream/BitCodeEnums.h"
 #include "llvm/ProfileData/CtxInstrContextNode.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 using namespace llvm::ctx_profile;
@@ -85,22 +89,15 @@ void PGOCtxProfileWriter::write(const ContextNode 
&RootNode) {
 }
 
 namespace {
-// A structural representation of the JSON input.
-struct DeserializableCtx {
-  ctx_profile::GUID Guid = 0;
-  std::vector Counters;
-  std::vector> Callsites;
-};
-
 ctx_profile::ContextNode *
 createNode(std::vector> &Nodes,
-   const std::vector &DCList);
+   const std::vector &DCList);
 
 // Convert a DeserializableCtx into a ContextNode, potentially linking it to
 // its sibling (e.g. callee at same callsite) "Next".
 ctx_profile::ContextNode *
 createNode(std::vector> &Nodes,
-   const DeserializableCtx &DC,
+   const Serial

[llvm-branch-commits] [llvm] [ctxprof] Move test serialization to yaml (PR #122545)

2025-01-10 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Mircea Trofin (mtrofin)


Changes

We have a textual representation of contextual profiles for test scenarios, 
mainly. This patch moves that to YAML instead of JSON. YAML is more succinct 
and readable (some of the .ll tests should be illustrative). In addition, JSON 
is parse-able by the YAML reader.

A subsequent patch will address deserialization.

---

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


31 Files Affected:

- (modified) llvm/include/llvm/ProfileData/PGOCtxProfWriter.h (+9-1) 
- (modified) llvm/lib/ProfileData/PGOCtxProfWriter.cpp (+25-32) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-and-annotate.ll 
(+10-22) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll (+12-9) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-icp.ll (+16-9) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-zero-path.ll (+4-3) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/full-cycle.ll (+16-50) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/handle-select.ll (+10-3) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/inline.ll (+16-17) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/load-unapplicable.ll (+11-33) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/load.ll (+11-33) 
- (modified) llvm/test/ThinLTO/X86/ctxprof.ll (+2-2) 
- (modified) 
llvm/test/Transforms/EliminateAvailableExternally/transform-to-local.ll (+2-2) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/bad.json (-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/bad.yaml (+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/empty.json (-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/empty.yaml () 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-bad-subctx.json 
(-8) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-bad-subctx.yaml (+4) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-counters.json 
(-5) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-counters.yaml 
(+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-ctx.json (-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-ctx.yaml (+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-vector.json 
(-1) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-vector.yaml (+1) 
- (removed) llvm/test/tools/llvm-ctxprof-util/Inputs/valid.json (-47) 
- (added) llvm/test/tools/llvm-ctxprof-util/Inputs/valid.yaml (+13) 
- (modified) llvm/test/tools/llvm-ctxprof-util/llvm-ctxprof-util-negative.test 
(+18-18) 
- (modified) llvm/test/tools/llvm-ctxprof-util/llvm-ctxprof-util.test (+4-4) 
- (modified) llvm/tools/llvm-ctxprof-util/llvm-ctxprof-util.cpp (+7-7) 
- (modified) llvm/unittests/Transforms/Utils/CallPromotionUtilsTest.cpp (+1-1) 


``diff
diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h 
b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
index b370fdd9ba5a1c..f6158609c12855 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
@@ -81,6 +81,14 @@ class PGOCtxProfileWriter final {
   static constexpr StringRef ContainerMagic = "CTXP";
 };
 
-Error createCtxProfFromJSON(StringRef Profile, raw_ostream &Out);
+/// Representation of the context node suitable for yaml / json serialization /
+/// deserialization.
+struct SerializableCtxRepresentation {
+  ctx_profile::GUID Guid = 0;
+  std::vector Counters;
+  std::vector> Callsites;
+};
+
+Error createCtxProfFromYAML(StringRef Profile, raw_ostream &Out);
 } // namespace llvm
 #endif
diff --git a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp 
b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
index 4c0f3d459988b1..d22aadd6bd7eb0 100644
--- a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
@@ -13,7 +13,11 @@
 #include "llvm/ProfileData/PGOCtxProfWriter.h"
 #include "llvm/Bitstream/BitCodeEnums.h"
 #include "llvm/ProfileData/CtxInstrContextNode.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 using namespace llvm::ctx_profile;
@@ -85,22 +89,15 @@ void PGOCtxProfileWriter::write(const ContextNode 
&RootNode) {
 }
 
 namespace {
-// A structural representation of the JSON input.
-struct DeserializableCtx {
-  ctx_profile::GUID Guid = 0;
-  std::vector Counters;
-  std::vector> Callsites;
-};
-
 ctx_profile::ContextNode *
 createNode(std::vector> &Nodes,
-   const std::vector &DCList);
+   const std::vector &DCList);
 
 // Convert a DeserializableCtx into a ContextNode, potentially linking it to
 // its sibling (e.g. callee at same callsite) "Next".
 ctx_profile::ContextNode *
 createNode(std::vector> &Nodes,
-   const DeserializableCtx &DC,
+   co

[llvm-branch-commits] [llvm] [ctxprof] Move test serialization to yaml (PR #122545)

2025-01-10 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin edited 
https://github.com/llvm/llvm-project/pull/122545
___
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] [NFCI][BoundsChecking] Apply nosanitize on local-bounds instrumentation (PR #122416)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122416


___
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] [NFCI][BoundsChecking] Apply nosanitize on local-bounds instrumentation (PR #122416)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122416


___
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] [NFCI][BoundsChecking] Apply nosanitize on local-bounds instrumentation (PR #122416)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122416


___
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] [ubsan] Pass fsanitize-skip-hot-cutoff into -fsanitize=bounds (PR #122576)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/122576

None


___
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] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)

2025-01-10 Thread Pengcheng Wang via llvm-branch-commits

wangpc-pp wrote:

> > Do you know what caused the X86 changes? I don't see any uses of 
> > getRegPressureSetLimit in the X86 directory.
> 
> Just checked line by line, I have no idea why X86 has some changes...

The reason may be mentally absorbing (and costed me a lot of time on 
debugging...): For some `RegisterClass`s, `getRawAllocationOrder` may return 
different orders by `OrderFunc` (which is set by `AltOrderSelect` in TableGen). 
We calculate the number of reserved registers first, and then calculate the 
number of allocatable registers. This results in higher allocatable registers, 
bacause the alternative allocation orders may have less registers.
We change to calculate the number of allocatable registers directly and 
calculate the number of reserved registers from it, the problem can be solved.

https://github.com/llvm/llvm-project/pull/118787
___
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] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)

2025-01-10 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp edited 
https://github.com/llvm/llvm-project/pull/118787
___
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] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)

2025-01-10 Thread Pengcheng Wang via llvm-branch-commits


@@ -16,6 +16,6 @@ body: |
 $f1 = COPY %2
 BLR8 implicit $lr8, implicit undef $rm, implicit $x3, implicit $f1
 ...
-# CHECK-DAG: AllocationOrder(VFRC) = [ $vf2 $vf3 $vf4 $vf5 $vf0 $vf1 $vf6 $vf7 
$vf8 $vf9 $vf10 $vf11 $vf12 $vf13 $vf14 $vf15 $vf16 $vf17 $vf18 $vf19 $vf31 
$vf30 $vf29 $vf28 $vf27 $vf26 $vf25 $vf24 $vf23 $vf22 $vf21 $vf20 ]
 # CHECK-DAG: AllocationOrder(G8RC_and_G8RC_NOX0) = [ $x3 $x4 $x5 $x6 $x7 $x8 
$x9 $x10 $x11 $x12 $x2 $x31 $x30 $x29 $x28 $x27 $x26 $x25 $x24 $x23 $x22 $x21 
$x20 $x19 $x18 $x17 $x16 $x15 $x14 ]
+# CHECK-DAG: AllocationOrder(G8RC) = [ $x3 $x4 $x5 $x6 $x7 $x8 $x9 $x10 $x11 
$x12 $x0 $x2 $x31 $x30 $x29 $x28 $x27 $x26 $x25 $x24 $x23 $x22 $x21 $x20 $x19 
$x18 $x17 $x16 $x15 $x14 ]

wangpc-pp wrote:

For these PPC changes, it is just because we have different code path now and 
the dumps are different.

https://github.com/llvm/llvm-project/pull/118787
___
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] release/19.x: [Matrix] Skip already fused instructions before trying to fuse multiply. (PR #118020)

2025-01-10 Thread Florian Hahn via llvm-branch-commits

https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/118020
___
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] 8f22647 - Revert "[ADT] Fix specialization of ValueIsPresent for PointerUnion (#121847)"

2025-01-10 Thread via llvm-branch-commits

Author: Sergei Barannikov
Date: 2025-01-11T03:29:02+03:00
New Revision: 8f22647c877002892f029415b0ec0dade69f758e

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

LOG: Revert "[ADT] Fix specialization of ValueIsPresent for PointerUnion 
(#121847)"

This reverts commit 7b0536794349734c8862fc140808e4e5a2ab8f8d.

Added: 


Modified: 
llvm/include/llvm/Support/Casting.h
llvm/lib/CodeGen/RegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
llvm/unittests/ADT/PointerUnionTest.cpp

Removed: 




diff  --git a/llvm/include/llvm/Support/Casting.h 
b/llvm/include/llvm/Support/Casting.h
index 2ce70e732e2ecb..66fdcb44ea2c00 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -614,12 +614,12 @@ template  struct 
ValueIsPresent> {
   static inline decltype(auto) unwrapValue(std::optional &t) { return *t; }
 };
 
-// If something is "nullable" then we just cast it to bool to see if it exists.
+// If something is "nullable" then we just compare it to nullptr to see if it
+// exists.
 template 
-struct ValueIsPresent<
-T, std::enable_if_t && std::is_constructible_v>> {
+struct ValueIsPresent>> {
   using UnwrappedType = T;
-  static inline bool isPresent(const T &t) { return static_cast(t); }
+  static inline bool isPresent(const T &t) { return t != T(nullptr); }
   static inline decltype(auto) unwrapValue(T &t) { return t; }
 };
 

diff  --git a/llvm/lib/CodeGen/RegisterBankInfo.cpp 
b/llvm/lib/CodeGen/RegisterBankInfo.cpp
index 5a8cf13ad11fd5..e1720b038e2361 100644
--- a/llvm/lib/CodeGen/RegisterBankInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterBankInfo.cpp
@@ -134,10 +134,10 @@ const TargetRegisterClass 
*RegisterBankInfo::constrainGenericRegister(
 
   // If the register already has a class, fallback to MRI::constrainRegClass.
   auto &RegClassOrBank = MRI.getRegClassOrRegBank(Reg);
-  if (isa_and_present(RegClassOrBank))
+  if (isa(RegClassOrBank))
 return MRI.constrainRegClass(Reg, &RC);
 
-  const auto *RB = dyn_cast_if_present(RegClassOrBank);
+  const RegisterBank *RB = cast(RegClassOrBank);
   // Otherwise, all we can do is ensure the bank covers the class, and set it.
   if (RB && !RB->covers(RC))
 return nullptr;

diff  --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp 
b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
index 8fa656c77e90ed..704435dad65d7b 100644
--- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
@@ -3708,10 +3708,10 @@ const TargetRegisterClass *
 SIRegisterInfo::getConstrainedRegClassForOperand(const MachineOperand &MO,
  const MachineRegisterInfo &MRI) const 
{
   const RegClassOrRegBank &RCOrRB = MRI.getRegClassOrRegBank(MO.getReg());
-  if (const auto *RB = dyn_cast_if_present(RCOrRB))
+  if (const RegisterBank *RB = dyn_cast(RCOrRB))
 return getRegClassForTypeOnBank(MRI.getType(MO.getReg()), *RB);
 
-  if (const auto *RC = dyn_cast_if_present(RCOrRB))
+  if (const auto *RC = dyn_cast(RCOrRB))
 return getAllocatableClass(RC);
 
   return nullptr;

diff  --git a/llvm/unittests/ADT/PointerUnionTest.cpp 
b/llvm/unittests/ADT/PointerUnionTest.cpp
index a28d532865cbc1..acddb789601494 100644
--- a/llvm/unittests/ADT/PointerUnionTest.cpp
+++ b/llvm/unittests/ADT/PointerUnionTest.cpp
@@ -208,11 +208,6 @@ TEST_F(PointerUnionTest, NewCastInfra) {
   EXPECT_FALSE(isa(d4null));
   EXPECT_FALSE(isa(d4null));
 
-  EXPECT_FALSE(isa_and_present(i4null));
-  EXPECT_FALSE(isa_and_present(f4null));
-  EXPECT_FALSE(isa_and_present(l4null));
-  EXPECT_FALSE(isa_and_present(d4null));
-
   // test cast<>
   EXPECT_EQ(cast(a), &f);
   EXPECT_EQ(cast(b), &i);



___
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] [NFCI][BoundsChecking] Apply nosanitize on local-bounds instrumentation (PR #122416)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122416


___
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] [AsmPrinter][TargetLowering]Place a hot jump table into a hot-suffixed section (PR #122215)

2025-01-10 Thread Mingming Liu via llvm-branch-commits

https://github.com/mingmingl-llvm updated 
https://github.com/llvm/llvm-project/pull/122215

>From dd748277dff2b30ed02bfa466eeca7102aa93eb4 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Fri, 10 Jan 2025 13:53:08 -0800
Subject: [PATCH 1/2] rely to upstream

---
 llvm/include/llvm/CodeGen/MachineFunction.h   |   2 +-
 .../llvm/CodeGen/MachineJumpTableInfo.h   |   9 +-
 llvm/include/llvm/CodeGen/Passes.h|   2 +-
 llvm/lib/CodeGen/MachineFunction.cpp  |  12 +-
 llvm/lib/CodeGen/StaticDataSplitter.cpp   |  87 +++---
 llvm/test/CodeGen/X86/jump-table-partition.ll | 251 +++---
 6 files changed, 223 insertions(+), 140 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h 
b/llvm/include/llvm/CodeGen/MachineFunction.h
index c0f983d1c6787b..dcdbcaec168d22 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -91,7 +91,7 @@ template <> struct ilist_callback_traits {
 // The hotness of static data tracked by a MachineFunction and not represented
 // as a global object in the module IR / MIR. Typical examples are
 // MachineJumpTableInfo and MachineConstantPool.
-enum class DataHotness {
+enum class MachineFunctionDataHotness {
   Unknown,
   Cold,
   Hot,
diff --git a/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h 
b/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
index cc1f54a81b9bb4..e3675d6489b350 100644
--- a/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
@@ -28,7 +28,7 @@ namespace llvm {
 class MachineBasicBlock;
 class DataLayout;
 class raw_ostream;
-enum class DataHotness;
+enum class MachineFunctionDataHotness;
 
 /// MachineJumpTableEntry - One jump table in the jump table info.
 ///
@@ -36,7 +36,7 @@ struct MachineJumpTableEntry {
   /// MBBs - The vector of basic blocks from which to create the jump table.
   std::vector MBBs;
 
-  DataHotness Hotness;
+  MachineFunctionDataHotness Hotness;
 
   explicit MachineJumpTableEntry(const std::vector &M);
 };
@@ -109,7 +109,10 @@ class MachineJumpTableInfo {
 return JumpTables;
   }
 
-  void updateJumpTableHotness(size_t JTI, DataHotness Hotness);
+  // Update machine jump table entry's hotness. Return true if the hotness is
+  // updated.
+  bool updateJumpTableEntryHotness(size_t JTI,
+   MachineFunctionDataHotness Hotness);
 
   /// RemoveJumpTable - Mark the specific index as being dead.  This will
   /// prevent it from being emitted.
diff --git a/llvm/include/llvm/CodeGen/Passes.h 
b/llvm/include/llvm/CodeGen/Passes.h
index 16423d03ff7018..b5d2a7e6bf035b 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -71,7 +71,7 @@ namespace llvm {
   /// using profile information.
   MachineFunctionPass *createMachineFunctionSplitterPass();
 
-  /// createStaticDataSplitterPass - This pass partions static data sections
+  /// createStaticDataSplitterPass - This pass partitions a static data section
   /// into a hot and cold section using profile information.
   MachineFunctionPass *createStaticDataSplitterPass();
 
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp 
b/llvm/lib/CodeGen/MachineFunction.cpp
index b5a89f3bcf42f1..d09e93d79aae6c 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -1293,7 +1293,7 @@ const unsigned MachineFunction::DebugOperandMemNumber = 
100;
 
 MachineJumpTableEntry::MachineJumpTableEntry(
 const std::vector &MBBs)
-: MBBs(MBBs), Hotness(DataHotness::Unknown) {}
+: MBBs(MBBs), Hotness(MachineFunctionDataHotness::Unknown) {}
 
 /// Return the size of each entry in the jump table.
 unsigned MachineJumpTableInfo::getEntrySize(const DataLayout &TD) const {
@@ -1344,13 +1344,17 @@ unsigned MachineJumpTableInfo::createJumpTableIndex(
   return JumpTables.size()-1;
 }
 
-void MachineJumpTableInfo::updateJumpTableHotness(size_t JTI,
-  DataHotness Hotness) {
+bool MachineJumpTableInfo::updateJumpTableEntryHotness(
+size_t JTI, MachineFunctionDataHotness Hotness) {
   assert(JTI < JumpTables.size() && "Invalid JTI!");
   // Note record the largest hotness is important for mergable data (constant
   // pools). Even if jump table instances are not merged, record the largest
   // value seen fwiw.
-  JumpTables[JTI].Hotness = std::max(JumpTables[JTI].Hotness, Hotness);
+  if (Hotness <= JumpTables[JTI].Hotness)
+return false;
+
+  JumpTables[JTI].Hotness = Hotness;
+  return true;
 }
 
 /// If Old is the target of any jump tables, update the jump tables to branch
diff --git a/llvm/lib/CodeGen/StaticDataSplitter.cpp 
b/llvm/lib/CodeGen/StaticDataSplitter.cpp
index 482a61027cf985..9e2cfe18256e35 100644
--- a/llvm/lib/CodeGen/StaticDataSplitter.cpp
+++ b/llvm/lib/CodeGen/StaticDataSplitter.cpp
@@ -6,13 +6,16 @@
 //
 
//===-

[llvm-branch-commits] [NFCI][BoundsChecking] Apply nosanitize on local-bounds instrumentation (PR #122416)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122416


___
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] [AsmPrinter][TargetLowering]Place a hot jump table into a hot-suffixed section (PR #122215)

2025-01-10 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 34b6b9b45564d994844cc9610edddf026a0e49cc 
8d3a985df083bf766d28e089ce3f7dcab2b53b00 --extensions h,cpp -- 
llvm/include/llvm/CodeGen/AsmPrinter.h 
llvm/include/llvm/CodeGen/MachineFunction.h 
llvm/include/llvm/CodeGen/MachineJumpTableInfo.h 
llvm/include/llvm/CodeGen/Passes.h 
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h 
llvm/include/llvm/Target/TargetLoweringObjectFile.h 
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/CodeGen/MachineFunction.cpp 
llvm/lib/CodeGen/StaticDataSplitter.cpp 
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp 
llvm/lib/CodeGen/TargetPassConfig.cpp 
llvm/lib/Target/TargetLoweringObjectFile.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 208c812ac4..a0fd99387b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2911,12 +2911,12 @@ void AsmPrinter::emitJumpTableInfo() {
 // Retain the relative orders of original jump tables.
 for (int L = NextHotJumpTableIndex, R = JT.size() - 1; L < R; ++L, --R)
   std::swap(JumpTableIndices[L], JumpTableIndices[R]);
-  
-emitJumpTables(
-ArrayRef(JumpTableIndices)
-.take_back(JT.size() - NextHotJumpTableIndex),
-TLOF.getSectionForJumpTable(F, TM, 
&JT[JumpTableIndices[NextHotJumpTableIndex]]),
-JTInDiffSection, *MJTI);
+
+emitJumpTables(ArrayRef(JumpTableIndices)
+   .take_back(JT.size() - NextHotJumpTableIndex),
+   TLOF.getSectionForJumpTable(
+   F, TM, &JT[JumpTableIndices[NextHotJumpTableIndex]]),
+   JTInDiffSection, *MJTI);
   }
 
   return;

``




https://github.com/llvm/llvm-project/pull/122215
___
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] [ctxprof] Move test serialization to yaml (PR #122545)

2025-01-10 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin created 
https://github.com/llvm/llvm-project/pull/122545

None

>From 26f606aed7fd6016f9defc2be9d0206e136d0ced Mon Sep 17 00:00:00 2001
From: Mircea Trofin 
Date: Fri, 10 Jan 2025 14:53:22 -0800
Subject: [PATCH] [ctxprof] Move test serialization to yaml

---
 .../llvm/ProfileData/PGOCtxProfWriter.h   | 10 ++-
 llvm/lib/ProfileData/PGOCtxProfWriter.cpp | 57 +++-
 .../CtxProfAnalysis/flatten-and-annotate.ll   | 32 +++--
 .../CtxProfAnalysis/flatten-check-path.ll | 21 +++---
 .../Analysis/CtxProfAnalysis/flatten-icp.ll   | 25 ---
 .../CtxProfAnalysis/flatten-zero-path.ll  |  7 +-
 .../Analysis/CtxProfAnalysis/full-cycle.ll| 66 +--
 .../Analysis/CtxProfAnalysis/handle-select.ll | 13 +++-
 llvm/test/Analysis/CtxProfAnalysis/inline.ll  | 33 +-
 .../CtxProfAnalysis/load-unapplicable.ll  | 44 -
 llvm/test/Analysis/CtxProfAnalysis/load.ll| 44 -
 llvm/test/ThinLTO/X86/ctxprof.ll  |  4 +-
 .../transform-to-local.ll |  4 +-
 .../tools/llvm-ctxprof-util/Inputs/bad.json   |  1 -
 .../tools/llvm-ctxprof-util/Inputs/bad.yaml   |  1 +
 .../tools/llvm-ctxprof-util/Inputs/empty.json |  1 -
 .../tools/llvm-ctxprof-util/Inputs/empty.yaml |  0
 .../Inputs/invalid-bad-subctx.json|  8 ---
 .../Inputs/invalid-bad-subctx.yaml|  4 ++
 .../Inputs/invalid-no-counters.json   |  5 --
 .../Inputs/invalid-no-counters.yaml   |  1 +
 .../Inputs/invalid-no-ctx.json|  1 -
 .../Inputs/invalid-no-ctx.yaml|  1 +
 .../Inputs/invalid-no-vector.json |  1 -
 .../Inputs/invalid-no-vector.yaml |  1 +
 .../tools/llvm-ctxprof-util/Inputs/valid.json | 47 -
 .../tools/llvm-ctxprof-util/Inputs/valid.yaml | 13 
 .../llvm-ctxprof-util-negative.test   | 36 +-
 .../llvm-ctxprof-util/llvm-ctxprof-util.test  |  8 +--
 .../llvm-ctxprof-util/llvm-ctxprof-util.cpp   | 14 ++--
 .../Utils/CallPromotionUtilsTest.cpp  |  2 +-
 31 files changed, 195 insertions(+), 310 deletions(-)
 delete mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/bad.json
 create mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/bad.yaml
 delete mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/empty.json
 create mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/empty.yaml
 delete mode 100644 
llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-bad-subctx.json
 create mode 100644 
llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-bad-subctx.yaml
 delete mode 100644 
llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-counters.json
 create mode 100644 
llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-counters.yaml
 delete mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-ctx.json
 create mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-ctx.yaml
 delete mode 100644 
llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-vector.json
 create mode 100644 
llvm/test/tools/llvm-ctxprof-util/Inputs/invalid-no-vector.yaml
 delete mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/valid.json
 create mode 100644 llvm/test/tools/llvm-ctxprof-util/Inputs/valid.yaml

diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h 
b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
index b370fdd9ba5a1c..f6158609c12855 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
@@ -81,6 +81,14 @@ class PGOCtxProfileWriter final {
   static constexpr StringRef ContainerMagic = "CTXP";
 };
 
-Error createCtxProfFromJSON(StringRef Profile, raw_ostream &Out);
+/// Representation of the context node suitable for yaml / json serialization /
+/// deserialization.
+struct SerializableCtxRepresentation {
+  ctx_profile::GUID Guid = 0;
+  std::vector Counters;
+  std::vector> Callsites;
+};
+
+Error createCtxProfFromYAML(StringRef Profile, raw_ostream &Out);
 } // namespace llvm
 #endif
diff --git a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp 
b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
index 4c0f3d459988b1..d22aadd6bd7eb0 100644
--- a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
@@ -13,7 +13,11 @@
 #include "llvm/ProfileData/PGOCtxProfWriter.h"
 #include "llvm/Bitstream/BitCodeEnums.h"
 #include "llvm/ProfileData/CtxInstrContextNode.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 using namespace llvm::ctx_profile;
@@ -85,22 +89,15 @@ void PGOCtxProfileWriter::write(const ContextNode 
&RootNode) {
 }
 
 namespace {
-// A structural representation of the JSON input.
-struct DeserializableCtx {
-  ctx_profile::GUID Guid = 0;
-  std::vector Counters;
-  std::vector> Callsites;
-};
-
 ctx_profile::ContextNode *
 createNode(std::vector> &Nodes,

[llvm-branch-commits] [llvm] [ctxprof] Move test serialization to yaml (PR #122545)

2025-01-10 Thread Mircea Trofin via llvm-branch-commits

mtrofin wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/122545?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#122545** https://app.graphite.dev/github/pr/llvm/llvm-project/122545?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/122545?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#122544** https://app.graphite.dev/github/pr/llvm/llvm-project/122544?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/122545
___
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] [NFCI][BoundsChecking] Apply nosanitize on local-bounds instrumentation (PR #122416)

2025-01-10 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/122416


___
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-tools-extra] [clang-doc] Make `--repository` change the HTML output (PR #122566)

2025-01-10 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Paul Kirth (ilovepi)


Changes

The current check in writeFileDefinition() is incorrect, and prevents us
from ever emitting the URL from the clang-doc tool. The unit tests do
test this, but call the API directly circumventing the check.

This is the first step towards addressing #59814.

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


4 Files Affected:

- (modified) clang-tools-extra/clang-doc/HTMLGenerator.cpp (+1-1) 
- (modified) 
clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp (+2-1) 
- (modified) clang-tools-extra/test/clang-doc/basic-project.test (+174-121) 
- (modified) clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp (+6-1) 


``diff
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index e3532559a32fcc..a400d2e9cbd184 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -494,7 +494,7 @@ genReferencesBlock(const std::vector &References,
 static std::unique_ptr
 writeFileDefinition(const Location &L,
 std::optional RepositoryUrl = std::nullopt) {
-  if (!L.IsFileInRootDir || !RepositoryUrl)
+  if (!L.IsFileInRootDir && !RepositoryUrl)
 return std::make_unique(
 HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
 " of file " + L.Filename);
diff --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
index 823384a4d97e86..3ddb2fd9ff563e 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
@@ -8,4 +8,5 @@ double Circle::area() const {
 
 double Circle::perimeter() const {
 return 3.141 * radius_;
-}
\ No newline at end of file
+}
+
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index b6b43bb82bb15d..1f5ba8bdc0703d 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -54,130 +54,183 @@
 // JSON-INDEX-NEXT: };
 // JSON-INDEX-NEXT: }
 
-// HTML-SHAPE: class Shape
-// HTML-SHAPE: Defined at line 8 of file {{.*}}Shape.h
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Abstract base class for shapes.
-// HTML-SHAPE:  Provides a common interface for different types of 
shapes.
-// HTML-SHAPE: Functions
-// HTML-SHAPE: area
-// HTML-SHAPE: public double area()
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Calculates the area of the shape.
-// HTML-SHAPE: perimeter
-// HTML-SHAPE: public double perimeter()
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Calculates the perimeter of the shape.
-// HTML-SHAPE: return
-// HTML-SHAPE:  double The perimeter of the shape.
-// HTML-SHAPE: ~Shape
-// HTML-SHAPE: public void ~Shape()
-// HTML-SHAPE: Defined at line 13 of file {{.*}}Shape.h
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Virtual destructor.
+//  HTML-SHAPE: class Shape
+// HTML-SHAPE-NEXT: 
+// HTML-SHAPE-NEXT: Defined at line
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h#8";>8
+// HTML-SHAPE-NEXT: of file
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h";>Shape.h
+// HTML-SHAPE-NEXT: 
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Abstract base class for shapes.
+//  HTML-SHAPE:  Provides a common interface for different types of 
shapes.
+//  HTML-SHAPE: Functions
+//  HTML-SHAPE: area
+//  HTML-SHAPE: public double area()
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Calculates the area of the shape.
+//  HTML-SHAPE: perimeter
+//  HTML-SHAPE: public double perimeter()
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Calculates the perimeter of the shape.
+//  HTML-SHAPE: return
+//  HTML-SHAPE:  double The perimeter of the shape.
+//  HTML-SHAPE: ~Shape
+//  HTML-SHAPE: public void ~Shape()
+//  HTML-SHAPE: Defined at line 
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h#13";>13
+// HTML-SHAPE-NEXT: of file 
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h";>Shape.h
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Virtual destructor.
 
-// HTML-CALC: class Calculator
-// HTML-CALC: Defined at line 8 of file {{.*}}Calculator.h
-// HTML-CALC: brief
-// HTML-CALC:  A simple calculator class.
-// HTML-CALC:  Provides basic arithmetic operations.
-// HTML-CALC: Functions
-// HTML-CALC: add
-// HTML-CALC: public int add(int a, int b)
-// HTML-CALC: Defined at line 3 of file {{.*}}Calculator.cpp
-// HTML-CALC: brief
-// HTML-CALC:  Adds two integers.
-// HTML-CALC: return
-// HTML-CALC:  int The sum of a and b.
-// HTML-CALC: subtract
-// HTML-CALC: public int subtract(int a, int b)
-// HTML-CALC: Defined at line 7 of file {{.*}}Calculator.cpp
-// HTML-CALC: brief
-// HTML-C

[llvm-branch-commits] [clang-tools-extra] [clang-doc] Make `--repository` change the HTML output (PR #122566)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi ready_for_review 
https://github.com/llvm/llvm-project/pull/122566
___
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-tools-extra] [clang-doc] Make `--repository` change the HTML output (PR #122566)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/122566

The current check in writeFileDefinition() is incorrect, and prevents us
from ever emitting the URL from the clang-doc tool. The unit tests do
test this, but call the API directly circumventing the check.

This is the first step towards addressing #59814.

>From ee3c4b40e18b1bba41db14ff72c689d16e2e075c Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Sat, 11 Jan 2025 01:21:54 +
Subject: [PATCH] [clang-doc] Make `--repository` change the HTML output

The current check in writeFileDefinition() is incorrect, and prevents us
from ever emitting the URL from the clang-doc tool. The unit tests do
test this, but call the API directly circumventing the check.

This is the first step towards addressing #59814.
---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp |   2 +-
 .../Inputs/basic-project/src/Circle.cpp   |   3 +-
 .../test/clang-doc/basic-project.test | 295 +++---
 .../unittests/clang-doc/HTMLGeneratorTest.cpp |   7 +-
 4 files changed, 183 insertions(+), 124 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index e3532559a32fcc..a400d2e9cbd184 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -494,7 +494,7 @@ genReferencesBlock(const std::vector &References,
 static std::unique_ptr
 writeFileDefinition(const Location &L,
 std::optional RepositoryUrl = std::nullopt) {
-  if (!L.IsFileInRootDir || !RepositoryUrl)
+  if (!L.IsFileInRootDir && !RepositoryUrl)
 return std::make_unique(
 HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
 " of file " + L.Filename);
diff --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
index 823384a4d97e86..3ddb2fd9ff563e 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
@@ -8,4 +8,5 @@ double Circle::area() const {
 
 double Circle::perimeter() const {
 return 3.141 * radius_;
-}
\ No newline at end of file
+}
+
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index b6b43bb82bb15d..1f5ba8bdc0703d 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -54,130 +54,183 @@
 // JSON-INDEX-NEXT: };
 // JSON-INDEX-NEXT: }
 
-// HTML-SHAPE: class Shape
-// HTML-SHAPE: Defined at line 8 of file {{.*}}Shape.h
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Abstract base class for shapes.
-// HTML-SHAPE:  Provides a common interface for different types of 
shapes.
-// HTML-SHAPE: Functions
-// HTML-SHAPE: area
-// HTML-SHAPE: public double area()
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Calculates the area of the shape.
-// HTML-SHAPE: perimeter
-// HTML-SHAPE: public double perimeter()
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Calculates the perimeter of the shape.
-// HTML-SHAPE: return
-// HTML-SHAPE:  double The perimeter of the shape.
-// HTML-SHAPE: ~Shape
-// HTML-SHAPE: public void ~Shape()
-// HTML-SHAPE: Defined at line 13 of file {{.*}}Shape.h
-// HTML-SHAPE: brief
-// HTML-SHAPE:  Virtual destructor.
+//  HTML-SHAPE: class Shape
+// HTML-SHAPE-NEXT: 
+// HTML-SHAPE-NEXT: Defined at line
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h#8";>8
+// HTML-SHAPE-NEXT: of file
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h";>Shape.h
+// HTML-SHAPE-NEXT: 
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Abstract base class for shapes.
+//  HTML-SHAPE:  Provides a common interface for different types of 
shapes.
+//  HTML-SHAPE: Functions
+//  HTML-SHAPE: area
+//  HTML-SHAPE: public double area()
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Calculates the area of the shape.
+//  HTML-SHAPE: perimeter
+//  HTML-SHAPE: public double perimeter()
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Calculates the perimeter of the shape.
+//  HTML-SHAPE: return
+//  HTML-SHAPE:  double The perimeter of the shape.
+//  HTML-SHAPE: ~Shape
+//  HTML-SHAPE: public void ~Shape()
+//  HTML-SHAPE: Defined at line 
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h#13";>13
+// HTML-SHAPE-NEXT: of file 
+// HTML-SHAPE-NEXT: https://repository.com/./include/Shape.h";>Shape.h
+//  HTML-SHAPE: brief
+//  HTML-SHAPE:  Virtual destructor.
 
-// HTML-CALC: class Calculator
-// HTML-CALC: Defined at line 8 of file {{.*}}Calculator.h
-// HTML-CALC: brief
-// HTML-CALC:  A simple calculator class.
-// HTML-CALC:  Provides basic arithmetic operations.
-// HTML-CALC: Functions
-// HTML-CALC: add
-// HTML-CALC: public int add(int a, int b)
-// HTML-CALC: Defined at 

[llvm-branch-commits] [clang-tools-extra] [clang-doc] Make `--repository` change the HTML output (PR #122566)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

ilovepi wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/122566?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#122566** https://app.graphite.dev/github/pr/llvm/llvm-project/122566?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/122566?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#122565** https://app.graphite.dev/github/pr/llvm/llvm-project/122565?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/122566
___
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] [ubsan] Pass fsanitize-skip-hot-cutoff into -fsanitize=bounds (PR #122576)

2025-01-10 Thread Thurston Dang via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/122576
___
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] [mlir] [OMPIRBuilder] Support runtime number of teams and threads, and SPMD mode (PR #116051)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits

skatrak wrote:

The PR stack should be almost ready to be merged in the next few days (buildbot 
failures are unrelated). If there are any remaining blockers from your side, 
let me know @jdoerfert.

https://github.com/llvm/llvm-project/pull/116051
___
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] AMDGPU: Implement isExtractVecEltCheap (PR #122460)

2025-01-10 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/122460

Once again we have excessive TLI hooks with bad defaults. Permit this
for 32-bit element vectors, which are just use-different-register.
We should permit 16-bit vectors as cheap with legal packed instructions,
but I see some mixed improvements and regressions that need investigation.

>From df2fcf7d00d79b1a7d8a209a66cb32e7712d5918 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Fri, 10 Jan 2025 14:57:24 +0700
Subject: [PATCH] AMDGPU: Implement isExtractVecEltCheap

Once again we have excessive TLI hooks with bad defaults. Permit this
for 32-bit element vectors, which are just use-different-register.
We should permit 16-bit vectors as cheap with legal packed instructions,
but I see some mixed improvements and regressions that need investigation.
---
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  7 +
 llvm/lib/Target/AMDGPU/SIISelLowering.h   |  1 +
 llvm/test/CodeGen/AMDGPU/mad-mix.ll   | 12 -
 llvm/test/CodeGen/AMDGPU/packed-fp32.ll   | 32 +++
 llvm/test/CodeGen/AMDGPU/trunc-combine.ll |  9 ---
 5 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 529d9ba17d4f60..3fa7add8c6f268 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -1949,6 +1949,13 @@ bool SITargetLowering::isExtractSubvectorCheap(EVT 
ResVT, EVT SrcVT,
   return Index == 0;
 }
 
+bool SITargetLowering::isExtractVecEltCheap(EVT VT, unsigned Index) const {
+  // TODO: This should be more aggressive, particular for 16-bit element
+  // vectors. However there are some mixed improvements and regressions.
+  EVT EltTy = VT.getVectorElementType();
+  return EltTy.getSizeInBits() % 32 == 0;
+}
+
 bool SITargetLowering::isTypeDesirableForOp(unsigned Op, EVT VT) const {
   if (Subtarget->has16BitInsts() && VT == MVT::i16) {
 switch (Op) {
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.h 
b/llvm/lib/Target/AMDGPU/SIISelLowering.h
index 5c215f76552d9c..bbb96d9115a0a9 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.h
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.h
@@ -365,6 +365,7 @@ class SITargetLowering final : public AMDGPUTargetLowering {
 
   bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
unsigned Index) const override;
+  bool isExtractVecEltCheap(EVT VT, unsigned Index) const override;
 
   bool isTypeDesirableForOp(unsigned Op, EVT VT) const override;
 
diff --git a/llvm/test/CodeGen/AMDGPU/mad-mix.ll 
b/llvm/test/CodeGen/AMDGPU/mad-mix.ll
index b520dd1060ec8c..30e3bc3ba5da85 100644
--- a/llvm/test/CodeGen/AMDGPU/mad-mix.ll
+++ b/llvm/test/CodeGen/AMDGPU/mad-mix.ll
@@ -385,17 +385,15 @@ define <2 x float> @v_mad_mix_v2f32_shuffle(<2 x half> 
%src0, <2 x half> %src1,
 ; SDAG-CI:   ; %bb.0:
 ; SDAG-CI-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
 ; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v3, v3
-; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v4, v5
 ; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v2, v2
-; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v5, v1
+; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v1, v1
 ; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v0, v0
 ; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v3, v3
-; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v1, v4
 ; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v2, v2
-; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v4, v5
-; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v5, v0
-; SDAG-CI-NEXT:v_mad_f32 v0, v4, v2, v1
-; SDAG-CI-NEXT:v_mac_f32_e32 v1, v5, v3
+; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v1, v1
+; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v4, v0
+; SDAG-CI-NEXT:v_mad_f32 v0, v1, v2, v5
+; SDAG-CI-NEXT:v_mad_f32 v1, v4, v3, v5
 ; SDAG-CI-NEXT:s_setpc_b64 s[30:31]
 ;
 ; GISEL-CI-LABEL: v_mad_mix_v2f32_shuffle:
diff --git a/llvm/test/CodeGen/AMDGPU/packed-fp32.ll 
b/llvm/test/CodeGen/AMDGPU/packed-fp32.ll
index 6b7eff316fe95b..0833dada43e4d5 100644
--- a/llvm/test/CodeGen/AMDGPU/packed-fp32.ll
+++ b/llvm/test/CodeGen/AMDGPU/packed-fp32.ll
@@ -549,17 +549,19 @@ bb:
   ret void
 }
 
-; GCN-LABEL: {{^}}fadd_fadd_fsub:
+; GCN-LABEL: {{^}}fadd_fadd_fsub_0:
 ; GFX900:   v_add_f32_e64 v{{[0-9]+}}, s{{[0-9]+}}, 0
 ; GFX900:   v_add_f32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}
-; PACKED-SDAG:  v_pk_add_f32 v[{{[0-9:]+}}], s[{{[0-9:]+}}], 0 
op_sel_hi:[1,0]{{$}}
-; PACKED-SDAG:  v_pk_add_f32 v[{{[0-9:]+}}], v[{{[0-9:]+}}], 0 
op_sel_hi:[1,0]{{$}}
+
+; PACKED-SDAG: v_add_f32_e64 v{{[0-9]+}}, s{{[0-9]+}}, 0
+; PACKED-SDAG: v_add_f32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}
+
 ; PACKED-GISEL: v_pk_add_f32 v[{{[0-9:]+}}], s[{{[0-9:]+}}], 
v[{{[0-9:]+}}]{{$}}
 ; PACKED-GISEL: v_pk_add_f32 v[{{[0-9:]+}}], v[{{[0-9:]+}}], 
s[{{[0-9:]+}}]{{$}}
-define amdgpu_kernel void @fadd_fadd_fsub(<2 x float> %arg) {
+define amdgpu_kernel void @fadd_fadd_fsub_0(<2 x float> %arg) {
 bb:
   %i12 = fadd <2 x float> zeroinitializer, %arg
-  %shift8 = shufflevector <2 x float> %i12, <2

[llvm-branch-commits] [llvm] AMDGPU: Implement isExtractVecEltCheap (PR #122460)

2025-01-10 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/122460?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#122460** https://app.graphite.dev/github/pr/llvm/llvm-project/122460?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/122460?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#122459** https://app.graphite.dev/github/pr/llvm/llvm-project/122459?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/122460
___
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] AMDGPU: Implement isExtractVecEltCheap (PR #122460)

2025-01-10 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)


Changes

Once again we have excessive TLI hooks with bad defaults. Permit this
for 32-bit element vectors, which are just use-different-register.
We should permit 16-bit vectors as cheap with legal packed instructions,
but I see some mixed improvements and regressions that need investigation.

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


5 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+7) 
- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.h (+1) 
- (modified) llvm/test/CodeGen/AMDGPU/mad-mix.ll (+5-7) 
- (modified) llvm/test/CodeGen/AMDGPU/packed-fp32.ll (+27-5) 
- (modified) llvm/test/CodeGen/AMDGPU/trunc-combine.ll (+5-4) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 529d9ba17d4f60..3fa7add8c6f268 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -1949,6 +1949,13 @@ bool SITargetLowering::isExtractSubvectorCheap(EVT 
ResVT, EVT SrcVT,
   return Index == 0;
 }
 
+bool SITargetLowering::isExtractVecEltCheap(EVT VT, unsigned Index) const {
+  // TODO: This should be more aggressive, particular for 16-bit element
+  // vectors. However there are some mixed improvements and regressions.
+  EVT EltTy = VT.getVectorElementType();
+  return EltTy.getSizeInBits() % 32 == 0;
+}
+
 bool SITargetLowering::isTypeDesirableForOp(unsigned Op, EVT VT) const {
   if (Subtarget->has16BitInsts() && VT == MVT::i16) {
 switch (Op) {
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.h 
b/llvm/lib/Target/AMDGPU/SIISelLowering.h
index 5c215f76552d9c..bbb96d9115a0a9 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.h
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.h
@@ -365,6 +365,7 @@ class SITargetLowering final : public AMDGPUTargetLowering {
 
   bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
unsigned Index) const override;
+  bool isExtractVecEltCheap(EVT VT, unsigned Index) const override;
 
   bool isTypeDesirableForOp(unsigned Op, EVT VT) const override;
 
diff --git a/llvm/test/CodeGen/AMDGPU/mad-mix.ll 
b/llvm/test/CodeGen/AMDGPU/mad-mix.ll
index b520dd1060ec8c..30e3bc3ba5da85 100644
--- a/llvm/test/CodeGen/AMDGPU/mad-mix.ll
+++ b/llvm/test/CodeGen/AMDGPU/mad-mix.ll
@@ -385,17 +385,15 @@ define <2 x float> @v_mad_mix_v2f32_shuffle(<2 x half> 
%src0, <2 x half> %src1,
 ; SDAG-CI:   ; %bb.0:
 ; SDAG-CI-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
 ; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v3, v3
-; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v4, v5
 ; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v2, v2
-; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v5, v1
+; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v1, v1
 ; SDAG-CI-NEXT:v_cvt_f16_f32_e32 v0, v0
 ; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v3, v3
-; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v1, v4
 ; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v2, v2
-; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v4, v5
-; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v5, v0
-; SDAG-CI-NEXT:v_mad_f32 v0, v4, v2, v1
-; SDAG-CI-NEXT:v_mac_f32_e32 v1, v5, v3
+; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v1, v1
+; SDAG-CI-NEXT:v_cvt_f32_f16_e32 v4, v0
+; SDAG-CI-NEXT:v_mad_f32 v0, v1, v2, v5
+; SDAG-CI-NEXT:v_mad_f32 v1, v4, v3, v5
 ; SDAG-CI-NEXT:s_setpc_b64 s[30:31]
 ;
 ; GISEL-CI-LABEL: v_mad_mix_v2f32_shuffle:
diff --git a/llvm/test/CodeGen/AMDGPU/packed-fp32.ll 
b/llvm/test/CodeGen/AMDGPU/packed-fp32.ll
index 6b7eff316fe95b..0833dada43e4d5 100644
--- a/llvm/test/CodeGen/AMDGPU/packed-fp32.ll
+++ b/llvm/test/CodeGen/AMDGPU/packed-fp32.ll
@@ -549,17 +549,19 @@ bb:
   ret void
 }
 
-; GCN-LABEL: {{^}}fadd_fadd_fsub:
+; GCN-LABEL: {{^}}fadd_fadd_fsub_0:
 ; GFX900:   v_add_f32_e64 v{{[0-9]+}}, s{{[0-9]+}}, 0
 ; GFX900:   v_add_f32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}
-; PACKED-SDAG:  v_pk_add_f32 v[{{[0-9:]+}}], s[{{[0-9:]+}}], 0 
op_sel_hi:[1,0]{{$}}
-; PACKED-SDAG:  v_pk_add_f32 v[{{[0-9:]+}}], v[{{[0-9:]+}}], 0 
op_sel_hi:[1,0]{{$}}
+
+; PACKED-SDAG: v_add_f32_e64 v{{[0-9]+}}, s{{[0-9]+}}, 0
+; PACKED-SDAG: v_add_f32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}
+
 ; PACKED-GISEL: v_pk_add_f32 v[{{[0-9:]+}}], s[{{[0-9:]+}}], 
v[{{[0-9:]+}}]{{$}}
 ; PACKED-GISEL: v_pk_add_f32 v[{{[0-9:]+}}], v[{{[0-9:]+}}], 
s[{{[0-9:]+}}]{{$}}
-define amdgpu_kernel void @fadd_fadd_fsub(<2 x float> %arg) {
+define amdgpu_kernel void @fadd_fadd_fsub_0(<2 x float> %arg) {
 bb:
   %i12 = fadd <2 x float> zeroinitializer, %arg
-  %shift8 = shufflevector <2 x float> %i12, <2 x float> undef, <2 x i32> 
+  %shift8 = shufflevector <2 x float> %i12, <2 x float> poison, <2 x i32> 
   %i13 = fadd <2 x float> zeroinitializer, %shift8
   %i14 = shufflevector <2 x float> %arg, <2 x float> %i13, <2 x i32> 
   %i15 = fsub <2 x float> %i14, zeroinitializer
@@ -567,6 +569,26 @@ bb:
   ret void
 }
 
+; GCN-LABEL: {{^}}fadd_fadd_fsub:
+; GFX900:   v_add_f32_e32 v{{[0-9]+}}, s

[llvm-branch-commits] [llvm] AMDGPU: Implement isExtractVecEltCheap (PR #122460)

2025-01-10 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/122460
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Krzysztof Parzyszek via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);
+};
+
+// trait-property-extension ->
+//trait-property-name (trait-property-value, ...)
+// trait-property-value ->
+//trait-property-name |
+//scalar-integer-expression |
+//trait-property-extension
+//
+// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
+// version (but equivalent) that doesn't have ambiguities.
+// The ambiguity is in
+//   trait-property:
+//  trait-property-name  <- (a)
+//  trait-property-clause
+//  trait-property-expression<- (b)
+//  trait-property-extension <- this conflicts with (a) and (b)
+//   trait-property-extension:
+//  trait-property-name  <- conflict with (a)
+//  identifier(trait-property-extension[, trait-property-extension[, ...]])
+//  constant integer expression  <- conflict with (b)
+//
+struct OmpTraitPropertyExtension {
+  CharBlock source;
+  TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension);
+  struct ExtensionValue {
+CharBlock source;
+UNION_CLASS_BOILERPLATE(ExtensionValue);
+std::variant>
+u;
+  };
+  using ExtensionList = std::list;
+  std::tuple t;
+};
+
+// trait-property ->
+//trait-property-name | OmpClause |
+//trait-property-expression | trait-property-extension
+// trait-property-expression ->
+//scalar-logical-expression | scalar-integer-expression
+//
+// The parser for a logical expression will accept an integer expression,
+// and if it's not logical, it will flag an error later. The same thing
+// will happen if the scalar integer expression sees a logical expresion.
+// To avoid this, parse all expressions as scalar expressions.
+struct OmpTraitProperty {
+  CharBlock source;
+  UNION_CLASS_BOILERPLATE(OmpTraitProperty);
+  std::variant,
+  ScalarExpr, // trait-property-expresion
+  OmpTraitPropertyExtension>
+  u;
+};
+
+// trait-selector-name ->
+//KIND |  DT   // name-list (host, nohost, +/add-def-doc)
+//ISA |   DT   // name-list (isa_name, ... /impl-defined)
+//ARCH |  DT   // name-list (arch_name, ... /impl-defined)
+//directive-name |C// no properties
+//SIMD |  C// clause-list (from declare_simd)
+// // (at least simdlen, inbranch/notinbranch)
+//DEVICE_NUM |T// device-number
+//UID |   T// unique-string-id /impl-defined
+//VENDOR |I// name-list (vendor-id /add-def-doc)
+//EXTENSION | I// name-list (ext_name /impl-defined)
+//ATOMIC_DEFAULT_MEM_ORDER I | // value of admo
+//REQUIRES |  I// clause-list (from requires)
+//CONDITION   U// logical-expr
+//
+// Trait-set-selectors:
+//[D]evice, [T]arget_device, [C]onstruct, [I]mplementation, [U]ser.
+struct OmpTraitSelectorName {
+  CharBlock source;
+  UNION_CLASS_BOILERPLATE(OmpTraitSelectorName);
+  ENUM_CLASS(Value, Arch, Atomic_Default_Mem_Order, Condition, Device_Num,

kparzysz wrote:

Yes, see BindAttr at lines 1130-1131, or ImageSelectorSpec at lines 1687 and 
1689.  Additionally, this spelling (ignoring upper/lower case) follows the 
spelling to be used in source code.

https://github.com/llvm/llvm-project/pull/121815
___
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] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits


@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, 
llvm::Argument &arg,
   return builder.saveIP();
 }
 
+/// Follow uses of `host_eval`-defined block arguments of the given 
`omp.target`
+/// operation and populate output variables with their corresponding host value
+/// (i.e. operand evaluated outside of the target region), based on their uses
+/// inside of the target region.
+///
+/// Loop bounds and steps are only optionally populated, if output vectors are
+/// provided.
+static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads,
+   Value &numTeamsLower, Value &numTeamsUpper,
+   Value &threadLimit) {
+  auto blockArgIface = llvm::cast(*targetOp);
+  for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(),
+   blockArgIface.getHostEvalBlockArgs())) {
+Value hostEvalVar = std::get<0>(item), blockArg = std::get<1>(item);
+
+for (Operation *user : blockArg.getUsers()) {
+  llvm::TypeSwitch(user)
+  .Case([&](omp::TeamsOp teamsOp) {
+if (teamsOp.getNumTeamsLower() == blockArg)
+  numTeamsLower = hostEvalVar;
+else if (teamsOp.getNumTeamsUpper() == blockArg)
+  numTeamsUpper = hostEvalVar;
+else if (teamsOp.getThreadLimit() == blockArg)
+  threadLimit = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::ParallelOp parallelOp) {
+if (parallelOp.getNumThreads() == blockArg)
+  numThreads = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::LoopNestOp loopOp) {
+// TODO: Extract bounds and step values.
+  })
+  .Default([](Operation *) {
+llvm_unreachable("unsupported host_eval use");
+  });
+}
+  }
+}
+
+/// If \p op is of the given type parameter, return it casted to that type.
+/// Otherwise, if its immediate parent operation (or some other higher-level
+/// parent, if \p immediateParent is false) is of that type, return that parent
+/// casted to the given type.
+///
+/// If \p op is \c null or neither it or its parent(s) are of the specified
+/// type, return a \c null operation.
+template 
+static OpTy castOrGetParentOfType(Operation *op, bool immediateParent = false) 
{
+  if (!op)
+return OpTy();
+
+  if (OpTy casted = dyn_cast(op))
+return casted;
+
+  if (immediateParent)
+return dyn_cast_if_present(op->getParentOp());
+
+  return op->getParentOfType();
+}
+
+/// Populate default `MinTeams`, `MaxTeams` and `MaxThreads` to their default
+/// values as stated by the corresponding clauses, if constant.
+///
+/// These default values must be set before the creation of the outlined LLVM
+/// function for the target region, so that they can be used to initialize the
+/// corresponding global `ConfigurationEnvironmentTy` structure.
+static void
+initTargetDefaultAttrs(omp::TargetOp targetOp,
+   llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &attrs,
+   bool isTargetDevice) {
+  // TODO: Handle constant 'if' clauses.
+  Operation *capturedOp = targetOp.getInnermostCapturedOmpOp();
+
+  Value numThreads, numTeamsLower, numTeamsUpper, threadLimit;
+  if (!isTargetDevice) {
+extractHostEvalClauses(targetOp, numThreads, numTeamsLower, numTeamsUpper,
+   threadLimit);
+  } else {
+// In the target device, values for these clauses are not passed as
+// host_eval, but instead evaluated prior to entry to the region. This
+// ensures values are mapped and available inside of the target region.
+if (auto teamsOp = castOrGetParentOfType(capturedOp)) {
+  numTeamsLower = teamsOp.getNumTeamsLower();
+  numTeamsUpper = teamsOp.getNumTeamsUpper();
+  threadLimit = teamsOp.getThreadLimit();
+}
+
+if (auto parallelOp = castOrGetParentOfType(capturedOp))
+  numThreads = parallelOp.getNumThreads();
+  }
+
+  auto extractConstInteger = [](Value value) -> std::optional {
+if (auto constOp =
+dyn_cast_if_present(value.getDefiningOp()))
+  if (auto constAttr = dyn_cast(constOp.getValue()))
+return constAttr.getInt();
+
+return std::nullopt;
+  };
+
+  // Handle clauses impacting the number of teams.
+
+  int32_t minTeamsVal = 1, maxTeamsVal = -1;
+  if (castOrGetParentOfType(capturedOp)) {
+// TODO: Use `hostNumTeamsLower` to initialize `minTeamsVal`. For now, 
match
+// clang and set min and max to the same value.
+if (numTeamsUpper) {
+  if (auto val = extractConstInteger(numTeamsUpper))
+minTeamsVal = maxTeamsVal = *val;

skatrak wrote:

It's not a dumb question, this code tries to replicate the logic in 
`CGOpenMPRuntime::getNumTeamsExprForTargetDi

[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits


@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, 
llvm::Argument &arg,
   return builder.saveIP();
 }
 
+/// Follow uses of `host_eval`-defined block arguments of the given 
`omp.target`
+/// operation and populate output variables with their corresponding host value
+/// (i.e. operand evaluated outside of the target region), based on their uses
+/// inside of the target region.
+///
+/// Loop bounds and steps are only optionally populated, if output vectors are
+/// provided.
+static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads,
+   Value &numTeamsLower, Value &numTeamsUpper,
+   Value &threadLimit) {
+  auto blockArgIface = llvm::cast(*targetOp);
+  for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(),

skatrak wrote:

Doing a decomposition declaration for `hostEvalVar` and `blockArg`, and then 
capturing these values in the `TypeSwitch` lambdas below apparently triggers a 
[weird corner in the C++ 
standard](https://stackoverflow.com/questions/46114214/lambda-implicit-capture-fails-with-variable-declared-from-structured-binding)
 that was disallowed at one point. So, apparently we can only do this if 
compiling for C++20 or later.

https://github.com/llvm/llvm-project/pull/116052
___
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] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits


@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, 
llvm::Argument &arg,
   return builder.saveIP();
 }
 
+/// Follow uses of `host_eval`-defined block arguments of the given 
`omp.target`
+/// operation and populate output variables with their corresponding host value
+/// (i.e. operand evaluated outside of the target region), based on their uses
+/// inside of the target region.
+///
+/// Loop bounds and steps are only optionally populated, if output vectors are
+/// provided.
+static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads,
+   Value &numTeamsLower, Value &numTeamsUpper,
+   Value &threadLimit) {
+  auto blockArgIface = llvm::cast(*targetOp);
+  for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(),
+   blockArgIface.getHostEvalBlockArgs())) {
+Value hostEvalVar = std::get<0>(item), blockArg = std::get<1>(item);
+
+for (Operation *user : blockArg.getUsers()) {
+  llvm::TypeSwitch(user)
+  .Case([&](omp::TeamsOp teamsOp) {
+if (teamsOp.getNumTeamsLower() == blockArg)
+  numTeamsLower = hostEvalVar;
+else if (teamsOp.getNumTeamsUpper() == blockArg)
+  numTeamsUpper = hostEvalVar;
+else if (teamsOp.getThreadLimit() == blockArg)
+  threadLimit = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::ParallelOp parallelOp) {
+if (parallelOp.getNumThreads() == blockArg)
+  numThreads = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::LoopNestOp loopOp) {
+// TODO: Extract bounds and step values.

skatrak wrote:

> Shame there isn't a TODO warning as opposed to hard failure for cases where 
> it won't generate wrong code, but unoptimized/ignored requests

Whenever we need to do that, we can just `emitWarning` instead of `emitError` 
and just avoid returning a `failure` value. For example, we do that in 
`convertIgnoredWrapper`. We just don't want to do that in this case because 
it's actually a compilation-stopping error, it's just reported elsewhere.

https://github.com/llvm/llvm-project/pull/116052
___
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] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits


@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, 
llvm::Argument &arg,
   return builder.saveIP();
 }
 
+/// Follow uses of `host_eval`-defined block arguments of the given 
`omp.target`
+/// operation and populate output variables with their corresponding host value
+/// (i.e. operand evaluated outside of the target region), based on their uses
+/// inside of the target region.
+///
+/// Loop bounds and steps are only optionally populated, if output vectors are
+/// provided.
+static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads,
+   Value &numTeamsLower, Value &numTeamsUpper,
+   Value &threadLimit) {
+  auto blockArgIface = llvm::cast(*targetOp);
+  for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(),
+   blockArgIface.getHostEvalBlockArgs())) {
+Value hostEvalVar = std::get<0>(item), blockArg = std::get<1>(item);
+
+for (Operation *user : blockArg.getUsers()) {
+  llvm::TypeSwitch(user)
+  .Case([&](omp::TeamsOp teamsOp) {
+if (teamsOp.getNumTeamsLower() == blockArg)
+  numTeamsLower = hostEvalVar;
+else if (teamsOp.getNumTeamsUpper() == blockArg)
+  numTeamsUpper = hostEvalVar;
+else if (teamsOp.getThreadLimit() == blockArg)
+  threadLimit = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::ParallelOp parallelOp) {
+if (parallelOp.getNumThreads() == blockArg)
+  numThreads = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::LoopNestOp loopOp) {
+// TODO: Extract bounds and step values.
+  })
+  .Default([](Operation *) {
+llvm_unreachable("unsupported host_eval use");
+  });
+}
+  }
+}
+
+/// If \p op is of the given type parameter, return it casted to that type.
+/// Otherwise, if its immediate parent operation (or some other higher-level
+/// parent, if \p immediateParent is false) is of that type, return that parent
+/// casted to the given type.
+///
+/// If \p op is \c null or neither it or its parent(s) are of the specified
+/// type, return a \c null operation.
+template 
+static OpTy castOrGetParentOfType(Operation *op, bool immediateParent = false) 
{
+  if (!op)
+return OpTy();
+
+  if (OpTy casted = dyn_cast(op))
+return casted;
+
+  if (immediateParent)
+return dyn_cast_if_present(op->getParentOp());
+
+  return op->getParentOfType();
+}
+
+/// Populate default `MinTeams`, `MaxTeams` and `MaxThreads` to their default
+/// values as stated by the corresponding clauses, if constant.
+///
+/// These default values must be set before the creation of the outlined LLVM
+/// function for the target region, so that they can be used to initialize the
+/// corresponding global `ConfigurationEnvironmentTy` structure.
+static void
+initTargetDefaultAttrs(omp::TargetOp targetOp,
+   llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &attrs,
+   bool isTargetDevice) {
+  // TODO: Handle constant 'if' clauses.
+  Operation *capturedOp = targetOp.getInnermostCapturedOmpOp();
+
+  Value numThreads, numTeamsLower, numTeamsUpper, threadLimit;
+  if (!isTargetDevice) {
+extractHostEvalClauses(targetOp, numThreads, numTeamsLower, numTeamsUpper,
+   threadLimit);
+  } else {
+// In the target device, values for these clauses are not passed as
+// host_eval, but instead evaluated prior to entry to the region. This
+// ensures values are mapped and available inside of the target region.
+if (auto teamsOp = castOrGetParentOfType(capturedOp)) {
+  numTeamsLower = teamsOp.getNumTeamsLower();
+  numTeamsUpper = teamsOp.getNumTeamsUpper();
+  threadLimit = teamsOp.getThreadLimit();
+}
+
+if (auto parallelOp = castOrGetParentOfType(capturedOp))
+  numThreads = parallelOp.getNumThreads();
+  }
+
+  auto extractConstInteger = [](Value value) -> std::optional {

skatrak wrote:

Good idea, done.

https://github.com/llvm/llvm-project/pull/116052
___
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] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits


@@ -289,7 +281,16 @@ static LogicalResult checkImplementationStatus(Operation 
&op) {
 checkBare(op, result);
 checkDevice(op, result);
 checkHasDeviceAddr(op, result);
-checkHostEval(op, result);
+
+// Host evaluated clauses are supported, except for target SPMD loop

skatrak wrote:

Actually, initially I wasn't sure between doing what you suggest and what I 
ended up doing. Since other `check` helpers only tested that the 
clause exists at all, and special cases so far were handled within the switch 
(i.e. firstprivate in target) to allow these functions still be reused by other 
operations, I decided to do the latter even though that clause cannot appear in 
any other operation.

But I agree that it makes things simpler, so I'm following your suggestion. In 
fact, I'm moving type-specific checks to the associated lambda as well and get 
things straightened out.

https://github.com/llvm/llvm-project/pull/116052
___
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] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak updated 
https://github.com/llvm/llvm-project/pull/116052

>From 9cf700147b302de9bb9fc5ec1453aa660ecb8411 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 12 Nov 2024 10:49:28 +
Subject: [PATCH 1/2] [MLIR][OpenMP] LLVM IR translation of host_eval

This patch adds support for processing the `host_eval` clause of `omp.target`
to populate default and runtime kernel launch attributes. Specifically, these
related to the `num_teams`, `thread_limit` and `num_threads` clauses attached
to operations nested inside of `omp.target`. As a result, the `thread_limit`
clause of `omp.target` is also supported.

The implementation of `initTargetDefaultAttrs()` is intended to reflect clang's
own processing of multiple constructs and clauses in order to define a default
number of teams and threads to be used as kernel attributes and to populate
global variables in the target device module.

One side effect of this change is that it is no longer possible to translate to
LLVM IR target device MLIR modules unless they have a supported target triple.
This is because the local `getGridValue()` function in the `OpenMPIRBuilder`
only works for certain architectures, and it is called whenever the maximum
number of threads has not been explicitly defined. This limitation also matches
clang.

Evaluating the collapsed loop trip count of target SPMD kernels remains
unsupported.
---
 .../Integration/OpenMP/target-filtering.f90   |   2 +-
 .../Lower/OpenMP/function-filtering-2.f90 |   6 +-
 .../Lower/OpenMP/function-filtering-3.f90 |   6 +-
 .../test/Lower/OpenMP/function-filtering.f90  |   6 +-
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  | 262 --
 ...target-byref-bycopy-generation-device.mlir |   4 +-
 .../omptarget-constant-alloca-raise.mlir  |   4 +-
 ...arget-constant-indexing-device-region.mlir |   4 +-
 mlir/test/Target/LLVMIR/omptarget-debug.mlir  |   2 +-
 .../omptarget-declare-target-llvm-device.mlir |   2 +-
 .../LLVMIR/omptarget-parallel-llvm.mlir   |   4 +-
 .../LLVMIR/omptarget-region-device-llvm.mlir  |   6 +-
 .../LLVMIR/omptarget-target-inside-task.mlir  |   4 +-
 ...ptarget-threadprivate-device-lowering.mlir |   4 +-
 .../LLVMIR/openmp-target-launch-device.mlir   |  45 +++
 .../LLVMIR/openmp-target-launch-host.mlir |  31 +++
 .../openmp-target-use-device-nested.mlir  |   4 +-
 .../LLVMIR/openmp-task-target-device.mlir |   2 +-
 mlir/test/Target/LLVMIR/openmp-todo.mlir  |  27 +-
 19 files changed, 362 insertions(+), 63 deletions(-)
 create mode 100644 mlir/test/Target/LLVMIR/openmp-target-launch-device.mlir
 create mode 100644 mlir/test/Target/LLVMIR/openmp-target-launch-host.mlir

diff --git a/flang/test/Integration/OpenMP/target-filtering.f90 
b/flang/test/Integration/OpenMP/target-filtering.f90
index d1ab1b47e580d4..699c1040d91f9c 100644
--- a/flang/test/Integration/OpenMP/target-filtering.f90
+++ b/flang/test/Integration/OpenMP/target-filtering.f90
@@ -7,7 +7,7 @@
 !===--===!
 
 !RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s --check-prefixes 
HOST,ALL
-!RUN: %flang_fc1 -emit-llvm -fopenmp -fopenmp-is-target-device %s -o - | 
FileCheck %s --check-prefixes DEVICE,ALL
+!RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-llvm -fopenmp 
-fopenmp-is-target-device %s -o - | FileCheck %s --check-prefixes DEVICE,ALL
 
 !HOST: define {{.*}}@{{.*}}before{{.*}}(
 !DEVICE-NOT: define {{.*}}@before{{.*}}(
diff --git a/flang/test/Lower/OpenMP/function-filtering-2.f90 
b/flang/test/Lower/OpenMP/function-filtering-2.f90
index 0c02aa223820e7..a2c5e29cfdcbf6 100644
--- a/flang/test/Lower/OpenMP/function-filtering-2.f90
+++ b/flang/test/Lower/OpenMP/function-filtering-2.f90
@@ -1,9 +1,9 @@
 ! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -flang-experimental-hlfir 
-emit-llvm %s -o - | FileCheck --check-prefixes=LLVM,LLVM-HOST %s
 ! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -emit-hlfir %s -o - | FileCheck 
--check-prefix=MLIR %s
-! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -fopenmp-is-target-device 
-flang-experimental-hlfir -emit-llvm %s -o - | FileCheck 
--check-prefixes=LLVM,LLVM-DEVICE %s
-! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -fopenmp-is-target-device 
-emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s
+! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 
-fopenmp-is-target-device -flang-experimental-hlfir -emit-llvm %s -o - | 
FileCheck --check-prefixes=LLVM,LLVM-DEVICE %s
+! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 
-fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s
 ! RUN: bbc -fopenmp -fopenmp-version=52 -emit-hlfir %s -o - | FileCheck 
--check-prefixes=MLIR-HOST,MLIR-ALL %s
-! RUN: bbc -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir 
%s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s
+! RUN: bbc -target amdgcn-amd-amdhsa -fopenmp -fopenmp-

[llvm-branch-commits] [flang] [mlir] [Flang][OpenMP] Lowering of host-evaluated clauses (PR #116219)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits


@@ -55,6 +55,149 @@ static void genOMPDispatch(lower::AbstractConverter 
&converter,
const ConstructQueue &queue,
ConstructQueue::const_iterator item);
 
+static void processHostEvalClauses(lower::AbstractConverter &converter,
+   semantics::SemanticsContext &semaCtx,
+   lower::StatementContext &stmtCtx,
+   lower::pft::Evaluation &eval,
+   mlir::Location loc);
+
+namespace {
+/// Structure holding information that is needed to pass host-evaluated
+/// information to later lowering stages.
+class HostEvalInfo {
+public:
+  // Allow this function access to private members in order to initialize them.
+  friend void ::processHostEvalClauses(lower::AbstractConverter &,
+   semantics::SemanticsContext &,
+   lower::StatementContext &,
+   lower::pft::Evaluation &,
+   mlir::Location);
+
+  /// Fill \c vars with values stored in \c ops.
+  ///
+  /// The order in which values are stored matches the one expected by \see
+  /// bindOperands().
+  void collectValues(llvm::SmallVectorImpl &vars) const {
+vars.append(ops.loopLowerBounds);
+vars.append(ops.loopUpperBounds);
+vars.append(ops.loopSteps);
+
+if (ops.numTeamsLower)
+  vars.push_back(ops.numTeamsLower);
+
+if (ops.numTeamsUpper)
+  vars.push_back(ops.numTeamsUpper);
+
+if (ops.numThreads)
+  vars.push_back(ops.numThreads);
+
+if (ops.threadLimit)
+  vars.push_back(ops.threadLimit);
+  }
+
+  /// Update \c ops, replacing all values with the corresponding block argument
+  /// in \c args.
+  ///
+  /// The order in which values are stored in \c args is the same as the one
+  /// used by \see collectValues().
+  void bindOperands(llvm::ArrayRef args) {
+assert(args.size() ==
+   ops.loopLowerBounds.size() + ops.loopUpperBounds.size() +
+   ops.loopSteps.size() + (ops.numTeamsLower ? 1 : 0) +
+   (ops.numTeamsUpper ? 1 : 0) + (ops.numThreads ? 1 : 0) +
+   (ops.threadLimit ? 1 : 0) &&
+   "invalid block argument list");
+int argIndex = 0;
+for (size_t i = 0; i < ops.loopLowerBounds.size(); ++i)
+  ops.loopLowerBounds[i] = args[argIndex++];
+
+for (size_t i = 0; i < ops.loopUpperBounds.size(); ++i)
+  ops.loopUpperBounds[i] = args[argIndex++];
+
+for (size_t i = 0; i < ops.loopSteps.size(); ++i)
+  ops.loopSteps[i] = args[argIndex++];
+
+if (ops.numTeamsLower)
+  ops.numTeamsLower = args[argIndex++];
+
+if (ops.numTeamsUpper)
+  ops.numTeamsUpper = args[argIndex++];
+
+if (ops.numThreads)
+  ops.numThreads = args[argIndex++];
+
+if (ops.threadLimit)
+  ops.threadLimit = args[argIndex++];
+  }
+
+  /// Update \p clauseOps and \p ivOut with the corresponding host-evaluated
+  /// values and Fortran symbols, respectively, if they have already been
+  /// initialized but not yet applied.
+  ///
+  /// \returns whether an update was performed. If not, these clauses were not
+  ///  evaluated in the host device.
+  bool apply(mlir::omp::LoopNestOperands &clauseOps,
+ llvm::SmallVectorImpl &ivOut) {
+if (iv.empty() || loopNestApplied) {
+  loopNestApplied = true;
+  return false;
+}
+
+loopNestApplied = true;
+clauseOps.loopLowerBounds = ops.loopLowerBounds;
+clauseOps.loopUpperBounds = ops.loopUpperBounds;
+clauseOps.loopSteps = ops.loopSteps;
+ivOut.append(iv);
+return true;
+  }
+
+  /// Update \p clauseOps with the corresponding host-evaluated values if they
+  /// have already been initialized but not yet applied.
+  ///
+  /// \returns whether an update was performed. If not, these clauses were not
+  ///  evaluated in the host device.
+  bool apply(mlir::omp::ParallelOperands &clauseOps) {
+if (!ops.numThreads || parallelApplied) {
+  parallelApplied = true;
+  return false;
+}
+
+parallelApplied = true;
+clauseOps.numThreads = ops.numThreads;
+return true;
+  }
+
+  /// Update \p clauseOps with the corresponding host-evaluated values if they
+  /// have already been initialized.
+  ///
+  /// \returns whether an update was performed. If not, these clauses were not
+  ///  evaluated in the host device.
+  bool apply(mlir::omp::TeamsOperands &clauseOps) {

skatrak wrote:

This is because there can't be multiple `teams` in a single `target` region, 
basically. And the only legal way for a `teams` construct be somewhere nested 
inside another `teams` construct would be in a reverse-offload situation. In 
that case, executing this function for the inner `teams` would still not 
overwrite any of the previously applied values because 

[llvm-branch-commits] [flang] [Flang] Introduce FortranSupport (PR #122069)

2025-01-10 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur ready_for_review 
https://github.com/llvm/llvm-project/pull/122069
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Krzysztof Parzyszek via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);
+};
+
+// trait-property-extension ->
+//trait-property-name (trait-property-value, ...)
+// trait-property-value ->
+//trait-property-name |
+//scalar-integer-expression |
+//trait-property-extension
+//
+// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
+// version (but equivalent) that doesn't have ambiguities.

kparzysz wrote:

To the OpenMP ARB?  No.  I think their grammar is there to show the syntax to 
the user (just like the in-text grammar for the compound constructs).  I'll 
mention it to @mjklemm and let him weigh in on what we should do with this.

https://github.com/llvm/llvm-project/pull/121815
___
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-cov: Introduce `--merge-instantiations=` (PR #121194)

2025-01-10 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/121194

>From 273eea73c158acbf7140bd599554b2ba02d88097 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 27 Dec 2024 16:14:24 +0900
Subject: [PATCH 1/2] llvm-cov: Introduce
 `--merge-instantiations=`

---
 .../ProfileData/Coverage/CoverageMapping.h|  82 -
 .../ProfileData/Coverage/CoverageMapping.cpp  | 170 --
 .../llvm-cov/Inputs/branch-templates.cpp  |   6 +-
 .../llvm-cov/Inputs/mcdc-templates-merge.cpp  |  54 ++
 .../Inputs/mcdc-templates-merge.proftext  |  73 
 .../llvm-cov/Inputs/mcdc-templates-merge.yaml | 105 +++
 .../tools/llvm-cov/branch-export-json.test|   2 +-
 .../tools/llvm-cov/branch-export-lcov.test|   4 +-
 llvm/test/tools/llvm-cov/branch-macros.test   |   9 +
 .../test/tools/llvm-cov/branch-templates.test |   4 +-
 .../tools/llvm-cov/mcdc-templates-merge.test  |  41 +
 llvm/tools/llvm-cov/CodeCoverage.cpp  |  12 +-
 llvm/tools/llvm-cov/CoverageReport.cpp|   4 +-
 llvm/tools/llvm-cov/CoverageViewOptions.h |   2 +
 llvm/tools/llvm-cov/SourceCoverageView.cpp|   4 +-
 15 files changed, 540 insertions(+), 32 deletions(-)
 create mode 100644 llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.cpp
 create mode 100644 
llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.proftext
 create mode 100644 llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.yaml
 create mode 100644 llvm/test/tools/llvm-cov/mcdc-templates-merge.test

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index 64416fdba1b247..d6df8403a2cd1c 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -59,6 +59,12 @@ namespace coverage {
 class CoverageMappingReader;
 struct CoverageMappingRecord;
 
+enum class MergeStrategy {
+  Merge,
+  Any,
+  All,
+};
+
 enum class coveragemap_error {
   success = 0,
   eof,
@@ -375,6 +381,32 @@ struct CountedRegion : public CounterMappingRegion {
   : CounterMappingRegion(R), ExecutionCount(ExecutionCount),
 FalseExecutionCount(FalseExecutionCount), TrueFolded(false),
 FalseFolded(false) {}
+
+  LineColPair viewLoc() const { return startLoc(); }
+
+  bool isMergeable(const CountedRegion &RHS) const {
+return (this->viewLoc() == RHS.viewLoc());
+  }
+
+  void merge(const CountedRegion &RHS, MergeStrategy Strategy);
+
+  /// Returns comparable rank value in selecting a better Record for merging.
+  auto getMergeRank(MergeStrategy Strategy) const {
+assert(isBranch() && "Dedicated to Branch");
+assert(Strategy == MergeStrategy::Any && "Dedicated to Any");
+unsigned m = 0;
+// Prefer both Counts have values.
+m = (m << 1) | (ExecutionCount != 0 && FalseExecutionCount != 0);
+// Prefer both are unfolded.
+m = (m << 1) | (!TrueFolded && !FalseFolded);
+// Prefer either Count has value.
+m = (m << 1) | (ExecutionCount != 0 || FalseExecutionCount != 0);
+// Prefer either is unfolded.
+m = (m << 1) | (!TrueFolded || !FalseFolded);
+return std::make_pair(m, ExecutionCount + FalseExecutionCount);
+  }
+
+  void commit() const {}
 };
 
 /// MCDC Record grouping all information together.
@@ -462,6 +494,19 @@ struct MCDCRecord {
 findIndependencePairs();
   }
 
+  inline LineColPair viewLoc() const { return Region.endLoc(); }
+
+  bool isMergeable(const MCDCRecord &RHS) const {
+return (this->viewLoc() == RHS.viewLoc() && this->PosToID == RHS.PosToID &&
+this->CondLoc == RHS.CondLoc);
+  }
+
+  // This may invalidate IndependencePairs
+  // MCDCRecord &operator+=(const MCDCRecord &RHS);
+  void merge(MCDCRecord &&RHS, MergeStrategy Strategy);
+
+  void commit() { findIndependencePairs(); }
+
   // Compare executed test vectors against each other to find an independence
   // pairs for each condition.  This processing takes the most time.
   void findIndependencePairs();
@@ -512,15 +557,42 @@ struct MCDCRecord {
 return (*IndependencePairs)[PosToID[Condition]];
   }
 
-  float getPercentCovered() const {
-unsigned Folded = 0;
+  std::pair getCoveredCount() const {
 unsigned Covered = 0;
+unsigned Folded = 0;
 for (unsigned C = 0; C < getNumConditions(); C++) {
   if (isCondFolded(C))
 Folded++;
   else if (isConditionIndependencePairCovered(C))
 Covered++;
 }
+return {Covered, Folded};
+  }
+
+  /// Returns comparable rank value in selecting a better Record for merging.
+  std::tuple
+  getMergeRank(MergeStrategy Strategy) const {
+auto [Covered, Folded] = getCoveredCount();
+auto NumTVs = getNumTestVectors();
+switch (Strategy) {
+case MergeStrategy::Merge:
+case MergeStrategy::Any:
+  return {
+  Covered, // The largest covered number
+  ~Folded, // Less folded is better
+  NumTVs,

[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);

kiranchandramohan wrote:

Sure. Thanks for the explanation. Can you add this explanation to the 
representation?

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits

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

LGTM.

https://github.com/llvm/llvm-project/pull/121815
___
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] 8876f16 - Revert "Fix a cmake error when using the Xcode generator. (#119403)"

2025-01-10 Thread via llvm-branch-commits

Author: Aaron Ballman
Date: 2025-01-10T08:48:34-05:00
New Revision: 8876f169829dd3c8dfebcfe9652fb1059ce75325

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

LOG: Revert "Fix a cmake error when using the Xcode generator. (#119403)"

This reverts commit 1842a3d833d934793012c717e98b10d51193fd0d.

Added: 


Modified: 
clang/cmake/modules/AddClang.cmake

Removed: 




diff  --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index cdc8bd5cd503b4..091aec98e93ca3 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -109,14 +109,13 @@ macro(add_clang_library name)
   llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(MSVC AND NOT CLANG_LINK_CLANG_DYLIB)
-# Make sure all consumers also turn off visibility macros so they're not
-# trying to dllimport symbols.
+# Make sure all consumers also turn off visibility macros so there not 
trying to dllimport symbols.
 target_compile_definitions(${name} PUBLIC CLANG_BUILD_STATIC)
 if(TARGET "obj.${name}")
   target_compile_definitions("obj.${name}" PUBLIC CLANG_BUILD_STATIC)
 endif()
-  elseif(TARGET "obj.${name}" AND NOT ARG_SHARED AND NOT ARG_STATIC)
-# Clang component libraries linked to clang-cpp are declared without 
SHARED or STATIC
+  elseif(NOT ARG_SHARED AND NOT ARG_STATIC)
+# Clang component libraries linked in to clang-cpp are declared without 
SHARED or STATIC
 target_compile_definitions("obj.${name}" PUBLIC CLANG_EXPORTS)
   endif()
 



___
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] Introduce FortranSupport (PR #122069)

2025-01-10 Thread Joseph Huber via llvm-branch-commits

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

Seems reasonable to me

https://github.com/llvm/llvm-project/pull/122069
___
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] [mlir] [Flang][OpenMP] Lowering of host-evaluated clauses (PR #116219)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak updated 
https://github.com/llvm/llvm-project/pull/116219

>From 3490effe3ecabfa805c3cd9d9c02b644e35ce3f0 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Thu, 14 Nov 2024 12:24:15 +
Subject: [PATCH] [Flang][OpenMP] Lowering of host-evaluated clauses

This patch adds support for lowering OpenMP clauses and expressions attached to
constructs nested inside of a target region that need to be evaluated in the
host device. This is done through the use of the `OpenMP_HostEvalClause`
`omp.target` set of operands and entry block arguments.

When lowering clauses for a target construct, a more involved
`processHostEvalClauses()` function is called, which looks at the current and
potentially other nested constructs in order to find and lower clauses that
need to be processed outside of the `omp.target` operation under construction.
This populates an instance of a global structure with the resulting MLIR
values.

The resulting list of host-evaluated values is used to initialize the
`host_eval` operands when constructing the `omp.target` operation, and then
replaced with the corresponding block arguments after creating that operation's
region.

Afterwards, while lowering nested operations, those that might potentially be
evaluated in the host (e.g. `num_teams`, `thread_limit`, `num_threads` and
`collapse`) check first whether there is an active global host-evaluated
information structure and whether it holds values referring to these clauses.
If that is the case, the stored values (referring to `omp.target` entry block
arguments at that stage) are used instead of lowering clauses again.
---
 flang/include/flang/Common/OpenMP-utils.h |  20 +-
 flang/lib/Common/OpenMP-utils.cpp |   9 +-
 flang/lib/Lower/OpenMP/OpenMP.cpp | 449 +-
 flang/test/Lower/OpenMP/host-eval.f90 | 157 ++
 flang/test/Lower/OpenMP/target-spmd.f90   | 191 
 .../Dialect/OpenMP/OpenMPClauseOperands.h |   6 +
 6 files changed, 805 insertions(+), 27 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/host-eval.f90
 create mode 100644 flang/test/Lower/OpenMP/target-spmd.f90

diff --git a/flang/include/flang/Common/OpenMP-utils.h 
b/flang/include/flang/Common/OpenMP-utils.h
index e6a3f1bac1c605..a65629834c6ff9 100644
--- a/flang/include/flang/Common/OpenMP-utils.h
+++ b/flang/include/flang/Common/OpenMP-utils.h
@@ -34,6 +34,7 @@ struct EntryBlockArgsEntry {
 /// Structure holding the information needed to create and bind entry block
 /// arguments associated to all clauses that can define them.
 struct EntryBlockArgs {
+  llvm::ArrayRef hostEvalVars;
   EntryBlockArgsEntry inReduction;
   EntryBlockArgsEntry map;
   EntryBlockArgsEntry priv;
@@ -49,18 +50,25 @@ struct EntryBlockArgs {
   }
 
   auto getSyms() const {
-return llvm::concat(
-inReduction.syms, map.syms, priv.syms, reduction.syms,
-taskReduction.syms, useDeviceAddr.syms, useDevicePtr.syms);
+return llvm::concat(inReduction.syms,
+map.syms, priv.syms, reduction.syms, taskReduction.syms,
+useDeviceAddr.syms, useDevicePtr.syms);
   }
 
   auto getVars() const {
-return llvm::concat(inReduction.vars, map.vars,
-priv.vars, reduction.vars, taskReduction.vars, useDeviceAddr.vars,
-useDevicePtr.vars);
+return llvm::concat(hostEvalVars, inReduction.vars,
+map.vars, priv.vars, reduction.vars, taskReduction.vars,
+useDeviceAddr.vars, useDevicePtr.vars);
   }
 };
 
+/// Create an entry block for the given region, including the clause-defined
+/// arguments specified.
+///
+/// \param [in] builder - MLIR operation builder.
+/// \param [in] rgs - entry block arguments information for the given
+/// operation.
+/// \param [in]  region - Empty region in which to create the entry block.
 mlir::Block *genEntryBlock(
 mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region 
®ion);
 } // namespace Fortran::common::openmp
diff --git a/flang/lib/Common/OpenMP-utils.cpp 
b/flang/lib/Common/OpenMP-utils.cpp
index f5115f475d6a19..47e89fe6dd1ee9 100644
--- a/flang/lib/Common/OpenMP-utils.cpp
+++ b/flang/lib/Common/OpenMP-utils.cpp
@@ -18,10 +18,10 @@ mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const 
EntryBlockArgs &args,
 
   llvm::SmallVector types;
   llvm::SmallVector locs;
-  unsigned numVars = args.inReduction.vars.size() + args.map.vars.size() +
-  args.priv.vars.size() + args.reduction.vars.size() +
-  args.taskReduction.vars.size() + args.useDeviceAddr.vars.size() +
-  args.useDevicePtr.vars.size();
+  unsigned numVars = args.hostEvalVars.size() + args.inReduction.vars.size() +
+  args.map.vars.size() + args.priv.vars.size() +
+  args.reduction.vars.size() + args.taskReduction.vars.size() +
+  args.useDeviceAddr.vars.size() + args.useDevicePtr.vars.size();
   types.reserve(numVars);
   locs.reserve(numVars);
 
@@ -34,6 +34,7 @@ mlir::Block *genEnt

[llvm-branch-commits] [llvm] d211d65 - Revert "MachineVerifier: Check stack protector is top-most in frame (#121481)"

2025-01-10 Thread via llvm-branch-commits

Author: Simon Pilgrim
Date: 2025-01-10T12:09:29Z
New Revision: d211d6502646a0b2bf88c265586c937aafacb53e

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

LOG: Revert "MachineVerifier: Check stack protector is top-most in frame 
(#121481)"

This reverts commit 86b1b0671cafd462c0aa681e2d320ce597300f69.

Added: 


Modified: 
llvm/lib/CodeGen/MachineVerifier.cpp

Removed: 
llvm/test/MachineVerifier/stack-protector-offset.mir



diff  --git a/llvm/lib/CodeGen/MachineVerifier.cpp 
b/llvm/lib/CodeGen/MachineVerifier.cpp
index 2558799c19f4d8..bec36b728ae328 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -353,8 +353,6 @@ struct MachineVerifier {
LaneBitmask LaneMask = LaneBitmask::getNone());
 
   void verifyStackFrame();
-  // Check that the stack protector is the top-most object in the stack.
-  void verifyStackProtector();
 
   void verifySlotIndexes() const;
   void verifyProperties(const MachineFunction &MF);
@@ -711,10 +709,8 @@ void MachineVerifier::visitMachineFunctionBefore() {
   // Check that the register use lists are sane.
   MRI->verifyUseLists();
 
-  if (!MF->empty()) {
+  if (!MF->empty())
 verifyStackFrame();
-verifyStackProtector();
-  }
 }
 
 void
@@ -4042,49 +4038,3 @@ void MachineVerifier::verifyStackFrame() {
 }
   }
 }
-
-void MachineVerifier::verifyStackProtector() {
-  const MachineFrameInfo &MFI = MF->getFrameInfo();
-  if (!MFI.hasStackProtectorIndex())
-return;
-  // Only applicable when the offsets of frame objects have been determined,
-  // which is indicated by a non-zero stack size.
-  if (!MFI.getStackSize())
-return;
-  const TargetFrameLowering &TFI = *MF->getSubtarget().getFrameLowering();
-  bool StackGrowsDown =
-  TFI.getStackGrowthDirection() == TargetFrameLowering::StackGrowsDown;
-  // Collect the frame indices of the callee-saved registers which are spilled
-  // to the stack. These are the registers that are stored above the stack
-  // protector.
-  SmallSet CalleeSavedFrameIndices;
-  if (MFI.isCalleeSavedInfoValid()) {
-for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) {
-  if (!Info.isSpilledToReg())
-CalleeSavedFrameIndices.insert(Info.getFrameIdx());
-}
-  }
-  unsigned FI = MFI.getStackProtectorIndex();
-  int64_t SPStart = MFI.getObjectOffset(FI);
-  int64_t SPEnd = SPStart + MFI.getObjectSize(FI);
-  for (unsigned I = 0, E = MFI.getObjectIndexEnd(); I != E; ++I) {
-if (I == FI)
-  continue;
-// Variable-sized objects do not have a fixed offset.
-if (MFI.isVariableSizedObjectIndex(I))
-  continue;
-if (CalleeSavedFrameIndices.contains(I))
-  continue;
-int64_t ObjStart = MFI.getObjectOffset(I);
-int64_t ObjEnd = ObjStart + MFI.getObjectSize(I);
-if (SPStart < ObjEnd && ObjStart < SPEnd) {
-  report("Stack protector overlaps with another stack object", MF);
-  break;
-}
-if ((StackGrowsDown && SPStart <= ObjStart) ||
-(!StackGrowsDown && SPStart >= ObjStart)) {
-  report("Stack protector is not the top-most object on the stack", MF);
-  break;
-}
-  }
-}

diff  --git a/llvm/test/MachineVerifier/stack-protector-offset.mir 
b/llvm/test/MachineVerifier/stack-protector-offset.mir
deleted file mode 100644
index 47008e1b123546..00
--- a/llvm/test/MachineVerifier/stack-protector-offset.mir
+++ /dev/null
@@ -1,63 +0,0 @@
-# REQUIRES: aarch64-registered-target, amdgpu-registered-target
-
-# RUN: split-file %s %t
-
-# RUN: llc -mtriple=aarch64 -run-pass=none -o - %t/valid.mir
-# RUN: not --crash llc -mtriple=aarch64 -run-pass=none -o - %t/lower.mir 2>&1 
| FileCheck %t/lower.mir
-# RUN: not --crash llc -mtriple=aarch64 -run-pass=none -o - %t/overlap.mir 
2>&1 | FileCheck %t/overlap.mir
-# RUN: not --crash llc -mtriple=amdgcn -run-pass=none -o - %t/higher.mir 2>&1 
| FileCheck %t/higher.mir
-
-;--- valid.mir

-name:valid
-frameInfo:
-  stackSize:   16
-  stackProtector:  '%stack.1'
-stack:
-  - { id: 0, offset: -24, size: 8, alignment: 8, stack-id: default }
-  - { id: 1, offset: -16, size: 8, alignment: 8, stack-id: default }
-body: |
-  bb.0:
-...
-
-;--- lower.mir
-# CHECK: *** Bad machine code: Stack protector is not the top-most object on 
the stack ***

-name:lower
-frameInfo:
-  stackSize:   16
-  stackProtector:  '%stack.1'
-stack:
-  - { id: 0, offset: -16, size: 8, alignment: 8, stack-id: default }
-  - { id: 1, offset: -24, size: 8, alignment: 8, stack-id: default }
-body: |
-  bb.0:
-...
-
-;--- overlap.mir
-# CHECK: *** Bad machine code: Stack protector overlaps with another stack 
object ***

-name:overlap
-frameInfo:
-  stackSize:   16

[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits


@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, 
llvm::Argument &arg,
   return builder.saveIP();
 }
 
+/// Follow uses of `host_eval`-defined block arguments of the given 
`omp.target`
+/// operation and populate output variables with their corresponding host value
+/// (i.e. operand evaluated outside of the target region), based on their uses
+/// inside of the target region.
+///
+/// Loop bounds and steps are only optionally populated, if output vectors are
+/// provided.
+static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads,
+   Value &numTeamsLower, Value &numTeamsUpper,
+   Value &threadLimit) {
+  auto blockArgIface = llvm::cast(*targetOp);
+  for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(),
+   blockArgIface.getHostEvalBlockArgs())) {
+Value hostEvalVar = std::get<0>(item), blockArg = std::get<1>(item);
+
+for (Operation *user : blockArg.getUsers()) {
+  llvm::TypeSwitch(user)
+  .Case([&](omp::TeamsOp teamsOp) {
+if (teamsOp.getNumTeamsLower() == blockArg)
+  numTeamsLower = hostEvalVar;
+else if (teamsOp.getNumTeamsUpper() == blockArg)
+  numTeamsUpper = hostEvalVar;
+else if (teamsOp.getThreadLimit() == blockArg)
+  threadLimit = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::ParallelOp parallelOp) {
+if (parallelOp.getNumThreads() == blockArg)
+  numThreads = hostEvalVar;
+else
+  llvm_unreachable("unsupported host_eval use");
+  })
+  .Case([&](omp::LoopNestOp loopOp) {
+// TODO: Extract bounds and step values.

skatrak wrote:

This case must have already been checked and reported by the 
`checkImplementationStatus` of the `omp.target` operation, stopping the 
translation process. So, an `llvm_unreachable` makes sense to add here, thanks 
for the suggestion. I also added that explanation to the comment above.

https://github.com/llvm/llvm-project/pull/116052
___
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] [mlir] [Flang][OpenMP] Lowering of host-evaluated clauses (PR #116219)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak updated 
https://github.com/llvm/llvm-project/pull/116219

>From d2b7ffef6e2a1cce81f47e7d1886551aef677ed8 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Thu, 14 Nov 2024 12:24:15 +
Subject: [PATCH] [Flang][OpenMP] Lowering of host-evaluated clauses

This patch adds support for lowering OpenMP clauses and expressions attached to
constructs nested inside of a target region that need to be evaluated in the
host device. This is done through the use of the `OpenMP_HostEvalClause`
`omp.target` set of operands and entry block arguments.

When lowering clauses for a target construct, a more involved
`processHostEvalClauses()` function is called, which looks at the current and
potentially other nested constructs in order to find and lower clauses that
need to be processed outside of the `omp.target` operation under construction.
This populates an instance of a global structure with the resulting MLIR
values.

The resulting list of host-evaluated values is used to initialize the
`host_eval` operands when constructing the `omp.target` operation, and then
replaced with the corresponding block arguments after creating that operation's
region.

Afterwards, while lowering nested operations, those that might potentially be
evaluated in the host (e.g. `num_teams`, `thread_limit`, `num_threads` and
`collapse`) check first whether there is an active global host-evaluated
information structure and whether it holds values referring to these clauses.
If that is the case, the stored values (referring to `omp.target` entry block
arguments at that stage) are used instead of lowering clauses again.
---
 flang/include/flang/Common/OpenMP-utils.h |  20 +-
 flang/lib/Common/OpenMP-utils.cpp |   9 +-
 flang/lib/Lower/OpenMP/OpenMP.cpp | 449 +-
 flang/test/Lower/OpenMP/host-eval.f90 | 157 ++
 flang/test/Lower/OpenMP/target-spmd.f90   | 191 
 .../Dialect/OpenMP/OpenMPClauseOperands.h |   6 +
 6 files changed, 805 insertions(+), 27 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/host-eval.f90
 create mode 100644 flang/test/Lower/OpenMP/target-spmd.f90

diff --git a/flang/include/flang/Common/OpenMP-utils.h 
b/flang/include/flang/Common/OpenMP-utils.h
index e6a3f1bac1c605..827f13bc4758e2 100644
--- a/flang/include/flang/Common/OpenMP-utils.h
+++ b/flang/include/flang/Common/OpenMP-utils.h
@@ -34,6 +34,7 @@ struct EntryBlockArgsEntry {
 /// Structure holding the information needed to create and bind entry block
 /// arguments associated to all clauses that can define them.
 struct EntryBlockArgs {
+  llvm::ArrayRef hostEvalVars;
   EntryBlockArgsEntry inReduction;
   EntryBlockArgsEntry map;
   EntryBlockArgsEntry priv;
@@ -49,18 +50,25 @@ struct EntryBlockArgs {
   }
 
   auto getSyms() const {
-return llvm::concat(
-inReduction.syms, map.syms, priv.syms, reduction.syms,
-taskReduction.syms, useDeviceAddr.syms, useDevicePtr.syms);
+return llvm::concat(inReduction.syms,
+map.syms, priv.syms, reduction.syms, taskReduction.syms,
+useDeviceAddr.syms, useDevicePtr.syms);
   }
 
   auto getVars() const {
-return llvm::concat(inReduction.vars, map.vars,
-priv.vars, reduction.vars, taskReduction.vars, useDeviceAddr.vars,
-useDevicePtr.vars);
+return llvm::concat(hostEvalVars, inReduction.vars,
+map.vars, priv.vars, reduction.vars, taskReduction.vars,
+useDeviceAddr.vars, useDevicePtr.vars);
   }
 };
 
+/// Create an entry block for the given region, including the clause-defined
+/// arguments specified.
+///
+/// \param [in] builder - MLIR operation builder.
+/// \param [in]args - entry block arguments information for the given
+///   operation.
+/// \param [in]  region - Empty region in which to create the entry block.
 mlir::Block *genEntryBlock(
 mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region 
®ion);
 } // namespace Fortran::common::openmp
diff --git a/flang/lib/Common/OpenMP-utils.cpp 
b/flang/lib/Common/OpenMP-utils.cpp
index f5115f475d6a19..47e89fe6dd1ee9 100644
--- a/flang/lib/Common/OpenMP-utils.cpp
+++ b/flang/lib/Common/OpenMP-utils.cpp
@@ -18,10 +18,10 @@ mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const 
EntryBlockArgs &args,
 
   llvm::SmallVector types;
   llvm::SmallVector locs;
-  unsigned numVars = args.inReduction.vars.size() + args.map.vars.size() +
-  args.priv.vars.size() + args.reduction.vars.size() +
-  args.taskReduction.vars.size() + args.useDeviceAddr.vars.size() +
-  args.useDevicePtr.vars.size();
+  unsigned numVars = args.hostEvalVars.size() + args.inReduction.vars.size() +
+  args.map.vars.size() + args.priv.vars.size() +
+  args.reduction.vars.size() + args.taskReduction.vars.size() +
+  args.useDeviceAddr.vars.size() + args.useDevicePtr.vars.size();
   types.reserve(numVars);
   locs.reserve(numVars);
 
@@ -34,6 +34,7 @@ mlir::Block *genEntry

[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Krzysztof Parzyszek via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);

kparzysz wrote:

I wanted to be able to print a meaningful message (in semantic checks) when 
it's not a constant expression.  Otherwise, the user would just get a syntax 
error.

https://github.com/llvm/llvm-project/pull/121815
___
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] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-10 Thread Sam Elliott via llvm-branch-commits


@@ -92,12 +93,141 @@ MultilibSet &MultilibSet::FilterOut(FilterCallback F) {
 
 void MultilibSet::push_back(const Multilib &M) { Multilibs.push_back(M); }
 
-bool MultilibSet::select(const Driver &D, const Multilib::flags_list &Flags,
- llvm::SmallVectorImpl &Selected) const {
-  llvm::StringSet<> FlagSet(expandFlags(Flags));
+static void DiagnoseUnclaimedMultilibCustomFlags(
+const Driver &D, const SmallVector &UnclaimedCustomFlagValues,
+const SmallVector &CustomFlagDecls) {
+  struct EditDistanceInfo {
+StringRef FlagValue;
+unsigned EditDistance;
+  };
+  const unsigned MaxEditDistance = 5;
+
+  for (StringRef Unclaimed : UnclaimedCustomFlagValues) {
+std::optional BestCandidate;
+for (const auto &Decl : CustomFlagDecls) {
+  for (const auto &Value : Decl->ValueList) {
+const std::string &FlagValueName = Value.Name;
+unsigned EditDistance =
+Unclaimed.edit_distance(FlagValueName, /*AllowReplacements=*/true,
+/*MaxEditDistance=*/MaxEditDistance);
+if (!BestCandidate || (EditDistance <= MaxEditDistance &&
+   EditDistance < BestCandidate->EditDistance)) {
+  BestCandidate = {FlagValueName, EditDistance};
+}
+  }
+}
+if (!BestCandidate)
+  D.Diag(clang::diag::err_drv_unsupported_opt)
+  << (custom_flag::Prefix + Unclaimed).str();
+else
+  D.Diag(clang::diag::err_drv_unsupported_opt_with_suggestion)
+  << (custom_flag::Prefix + Unclaimed).str()
+  << (custom_flag::Prefix + BestCandidate->FlagValue).str();
+  }
+}
+
+namespace clang::driver::custom_flag {
+// Map implemented using linear searches as the expected size is too small for
+// the overhead of a search tree or a hash table.
+class ValueNameToDetailMap {
+  SmallVector> Mapping;
+
+public:
+  template 
+  ValueNameToDetailMap(It FlagDeclsBegin, It FlagDeclsEnd) {
+for (auto DeclIt = FlagDeclsBegin; DeclIt != FlagDeclsEnd; ++DeclIt) {
+  const DeclarationPtr &Decl = *DeclIt;
+  for (const auto &Value : Decl->ValueList)
+Mapping.emplace_back(Value.Name, &Value);
+}
+  }
+
+  const ValueDetail *get(StringRef Key) const {
+auto Iter = llvm::find_if(
+Mapping, [&](const auto &Pair) { return Pair.first == Key; });
+return Iter != Mapping.end() ? Iter->second : nullptr;
+  }
+};
+} // namespace clang::driver::custom_flag
+
+std::pair>
+MultilibSet::processCustomFlags(const Driver &D,
+const Multilib::flags_list &Flags) const {
+  Multilib::flags_list Result;
+  SmallVector MacroDefines;
+
+  // Custom flag values detected in the flags list
+  SmallVector ClaimedCustomFlagValues;
+
+  // Arguments to -fmultilib-flag= that don't correspond to any valid
+  // custom flag value. An error will be printed out for each of these.
+  SmallVector UnclaimedCustomFlagValueStrs;
+
+  const auto ValueNameToValueDetail = custom_flag::ValueNameToDetailMap(
+  CustomFlagDecls.begin(), CustomFlagDecls.end());
+
+  for (StringRef Flag : Flags) {
+if (!Flag.starts_with(custom_flag::Prefix)) {
+  Result.push_back(Flag.str());
+  continue;
+}
+
+StringRef CustomFlagValueStr = Flag.substr(custom_flag::Prefix.size());
+const custom_flag::ValueDetail *Detail =
+ValueNameToValueDetail.get(CustomFlagValueStr);
+if (Detail)
+  ClaimedCustomFlagValues.push_back(Detail);
+else
+  UnclaimedCustomFlagValueStrs.push_back(CustomFlagValueStr);
+  }
+
+  // Set of custom flag declarations for which a value was passed in the flags
+  // list. This is used to, firstly, detect multiple values for the same flag
+  // declaration (in this case, the last one wins), and secondly, to detect
+  // which declarations had no value passed in (in this case, the default value
+  // is selected).
+  llvm::SmallSet TriggeredCustomFlagDecls;
+
+  // Detect multiple values for the same flag declaration. Last one wins.
+  for (auto *CustomFlagValue : llvm::reverse(ClaimedCustomFlagValues)) {
+if (!TriggeredCustomFlagDecls.insert(CustomFlagValue->Decl).second)
+  continue;
+Result.push_back(std::string(custom_flag::Prefix) + CustomFlagValue->Name);
+if (CustomFlagValue->MacroDefines)
+  MacroDefines.append(CustomFlagValue->MacroDefines->begin(),
+  CustomFlagValue->MacroDefines->end());
+  }
+
+  // Detect flag declarations with no value passed in. Select default value.
+  for (const auto &Decl : CustomFlagDecls) {
+if (TriggeredCustomFlagDecls.contains(Decl))
+  continue;
+custom_flag::ValueDetail &CustomFlagValue =
+Decl->ValueList[*Decl->DefaultValueIdx];
+Result.push_back(std::string(custom_flag::Prefix) + CustomFlagValue.Name);
+if (CustomFlagValue.MacroDefines)
+  MacroDefines.append(CustomFlagValue.MacroDefines->begin(),
+  CustomFlagValue.MacroDefines->

[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Krzysztof Parzyszek via llvm-branch-commits


@@ -153,6 +153,81 @@ static TypeDeclarationStmt 
makeIterSpecDecl(std::list &&names) {
   makeEntityList(std::move(names)));
 }
 
+// --- Parsers for context traits -
+
+TYPE_PARSER(sourced(construct( //
+(space >> charLiteralConstantWithoutKind) ||
+applyMem(&Name::ToString, Parser{}
+
+TYPE_PARSER(sourced(construct( //
+"SCORE" >> parenthesized(scalarIntExpr
+
+TYPE_PARSER(sourced(construct(
+// Parse nested extension first.
+construct(
+indirect(Parser{})) ||
+construct(
+Parser{}) ||
+construct(scalarExpr
+
+TYPE_PARSER(sourced(construct( //
+Parser{},
+parenthesized(nonemptySeparated(
+Parser{}, ","_tok)
+
+TYPE_PARSER(sourced(construct(
+// Try clause first, then extension before OmpTraitPropertyName.
+construct(indirect(Parser{})) ||
+construct(Parser{}) ||
+construct(Parser{}) ||
+construct(scalarExpr
+
+TYPE_PARSER(construct(
+"ARCH" >> pure(OmpTraitSelectorName::Value::Arch) ||
+"ATOMIC_DEFAULT_MEM_ORDER" >>
+pure(OmpTraitSelectorName::Value::Atomic_Default_Mem_Order) ||
+"CONDITION" >> pure(OmpTraitSelectorName::Value::Condition) ||
+"DEVICE_NUM" >> pure(OmpTraitSelectorName::Value::Device_Num) ||
+"EXTENSION" >> pure(OmpTraitSelectorName::Value::Extension) ||
+"ISA" >> pure(OmpTraitSelectorName::Value::Isa) ||
+"KIND" >> pure(OmpTraitSelectorName::Value::Kind) ||
+"REQUIRES" >> pure(OmpTraitSelectorName::Value::Requires) ||
+"SIMD" >> pure(OmpTraitSelectorName::Value::Simd) ||
+"UID" >> pure(OmpTraitSelectorName::Value::Uid) ||
+"VENDOR" >> pure(OmpTraitSelectorName::Value::Vendor)))
+
+TYPE_PARSER(sourced(construct(
+// Parse predefined names first (because of SIMD).
+construct(Parser{}) ||
+construct(OmpDirectiveNameParser{}
+
+TYPE_PARSER(construct(
+maybe(Parser{} / ":"_tok),
+nonemptySeparated(Parser{}, ","_tok)))
+
+TYPE_PARSER(sourced(construct( //
+Parser{}, //
+maybe(parenthesized(Parser{})
+
+TYPE_PARSER(construct(
+"CONSTRUCT" >> pure(OmpTraitSetSelectorName::Value::Construct) ||
+"DEVICE" >> pure(OmpTraitSetSelectorName::Value::Device) ||
+"IMPLEMENTATION" >> pure(OmpTraitSetSelectorName::Value::Implementation) ||
+"TARGET_DEVICE" >> pure(OmpTraitSetSelectorName::Value::Target_Device) ||
+"USER" >> pure(OmpTraitSetSelectorName::Value::User)))
+
+TYPE_PARSER(sourced(construct(
+Parser{})))
+
+TYPE_PARSER(sourced(construct( //
+Parser{},
+"=" >> braced(nonemptySeparated(Parser{}, ","_tok)
+
+TYPE_PARSER(sourced(construct(
+nonemptySeparated(Parser{}, ","_tok
+
+// Parser == 
Parser

kparzysz wrote:

This is a section with parsers for all modifiers.  You'd expect to find the 
parser for OmpContextSelector here as well, but it's the same as the parser for 
the OmpContextSelectorSpecification.  To avoid confusion why it's not here, I 
added a comment that's intended to explain it.

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 215c7e6133bf07d005ac7483b8faf797e319a1fa Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 12 Dec 2024 15:26:26 -0600
Subject: [PATCH 1/7] [flang][OpenMP] Parsing context selectors for
 METADIRECTIVE

This is just adding parsers for context selectors. There are no tests
because there is no way to execute these parsers yet.
---
 flang/include/flang/Parser/characters.h  |   2 +
 flang/include/flang/Parser/dump-parse-tree.h |  14 ++
 flang/include/flang/Parser/parse-tree.h  | 136 +++
 flang/lib/Parser/openmp-parsers.cpp  |  78 +++
 flang/lib/Parser/token-parsers.h |   4 +
 flang/lib/Parser/unparse.cpp |  38 ++
 flang/lib/Semantics/check-omp-structure.cpp  |   8 ++
 flang/lib/Semantics/check-omp-structure.h|   3 +
 flang/lib/Semantics/resolve-directives.cpp   |   6 +
 9 files changed, 289 insertions(+)

diff --git a/flang/include/flang/Parser/characters.h 
b/flang/include/flang/Parser/characters.h
index df188d674b9eeb..dbdc058c44995a 100644
--- a/flang/include/flang/Parser/characters.h
+++ b/flang/include/flang/Parser/characters.h
@@ -180,6 +180,8 @@ inline constexpr bool IsValidFortranTokenCharacter(char ch) 
{
   case '>':
   case '[':
   case ']':
+  case '{': // Used in OpenMP context selector specification
+  case '}': //
 return true;
   default:
 return IsLegalIdentifierStart(ch) || IsDecimalDigit(ch);
diff --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index 3331520922bc63..a61d7973dd5c36 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -476,6 +476,20 @@ class ParseTreeDumper {
   NODE(parser, NullInit)
   NODE(parser, ObjectDecl)
   NODE(parser, OldParameterStmt)
+  NODE(parser, OmpDirectiveSpecification)
+  NODE(parser, OmpTraitPropertyName)
+  NODE(parser, OmpTraitScore)
+  NODE(parser, OmpTraitPropertyExtension)
+  NODE(OmpTraitPropertyExtension, ExtensionValue)
+  NODE(parser, OmpTraitProperty)
+  NODE(parser, OmpTraitSelectorName)
+  NODE_ENUM(OmpTraitSelectorName, Value)
+  NODE(parser, OmpTraitSelector)
+  NODE(OmpTraitSelector, Properties)
+  NODE(parser, OmpTraitSetSelectorName)
+  NODE_ENUM(OmpTraitSetSelectorName, Value)
+  NODE(parser, OmpTraitSetSelector)
+  NODE(parser, OmpContextSelectorSpecification)
   NODE(parser, OmpMapper)
   NODE(parser, OmpMapType)
   NODE_ENUM(OmpMapType, Value)
diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 941d70d3876291..697bddfaf16150 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3453,6 +3453,17 @@ WRAPPER_CLASS(PauseStmt, std::optional);
 
 // --- Common definitions
 
+struct OmpClause;
+struct OmpClauseList;
+
+struct OmpDirectiveSpecification {
+  TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification);
+  std::tuple>>
+  t;
+  CharBlock source;
+};
+
 // 2.1 Directives or clauses may accept a list or extended-list.
 // A list item is a variable, array section or common block name (enclosed
 // in slashes). An extended list item is a list item or a procedure Name.
@@ -3474,6 +3485,128 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);
+};
+
+// trait-property-extension ->
+//trait-property-name (trait-property-value, ...)
+// trait-property-value ->
+//trait-property-name |
+//scalar-integer-expression |
+//trait-property-extension
+//
+// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
+// version (but equivalent) that doesn't have ambiguities.
+// The ambiguity is in
+//   trait-property:
+//  trait-property-name  <- (a)
+//  trait-property-clause
+//  trait-property-expression<- (b)
+//  trait-property-extension <- this conflicts with (a) and (b)
+//   trait-property-extension:
+//  trait-property-name  <- conflict with (a)
+//  identifier(trait-property-extension[, trait-property-extension[, ...]])
+//  constant integer expression  <- conflict with (b)
+//
+struct OmpTraitPropertyExtension {
+  TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension);
+  struct ExtensionValue {
+UNION_CLASS_BOILERPLATE(ExtensionValue);
+std::variant>
+u;
+  };
+  using ExtensionList = std::list;
+  std::tuple t;
+};
+
+// trait-property ->
+//trait-property-name | OmpClause |
+//trait-property-expression | trait-property-extension
+// trait-property-expression ->
+//

[llvm-branch-commits] [llvm] [mlir] [OMPIRBuilder][MLIR] Add support for target 'if' clause (PR #122478)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak created 
https://github.com/llvm/llvm-project/pull/122478

This patch implements support for handling the 'if' clause of OpenMP 'target' 
constructs in the OMPIRBuilder and updates MLIR to LLVM IR translation of the 
`omp.target` MLIR operation to make use of this new feature.

>From 3aea11b2d7857784d442d97925561ea54a5a8095 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Fri, 10 Jan 2025 15:40:05 +
Subject: [PATCH] [OMPIRBuilder][MLIR] Add support for target 'if' clause

This patch implements support for handling the 'if' clause of OpenMP 'target'
constructs in the OMPIRBuilder and updates MLIR to LLVM IR translation of the
`omp.target` MLIR operation to make use of this new feature.
---
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   |  26 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 130 +++---
 .../Frontend/OpenMPIRBuilderTest.cpp  |  11 +-
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  |   9 +-
 mlir/test/Target/LLVMIR/omptarget-if.mlir |  68 +
 mlir/test/Target/LLVMIR/openmp-todo.mlir  |  11 --
 6 files changed, 172 insertions(+), 83 deletions(-)
 create mode 100644 mlir/test/Target/LLVMIR/omptarget-if.mlir

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 4ce47b1c05d9b0..b1a23996c7bdd2 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2965,21 +2965,25 @@ class OpenMPIRBuilder {
   /// \param NumThreads Number of teams specified in the thread_limit clause.
   /// \param Inputs The input values to the region that will be passed.
   /// as arguments to the outlined function.
+  /// \param IfCond value of the `if` clause.
   /// \param BodyGenCB Callback that will generate the region code.
   /// \param ArgAccessorFuncCB Callback that will generate accessors
   /// instructions for passed in target arguments where neccessary
   /// \param Dependencies A vector of DependData objects that carry
-  // dependency information as passed in the depend clause
-  // \param HasNowait Whether the target construct has a `nowait` clause or 
not.
-  InsertPointOrErrorTy createTarget(
-  const LocationDescription &Loc, bool IsOffloadEntry,
-  OpenMPIRBuilder::InsertPointTy AllocaIP,
-  OpenMPIRBuilder::InsertPointTy CodeGenIP,
-  TargetRegionEntryInfo &EntryInfo, ArrayRef NumTeams,
-  ArrayRef NumThreads, SmallVectorImpl &Inputs,
-  GenMapInfoCallbackTy GenMapInfoCB, TargetBodyGenCallbackTy BodyGenCB,
-  TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
-  SmallVector Dependencies = {}, bool HasNowait = false);
+  /// dependency information as passed in the depend clause
+  /// \param HasNowait Whether the target construct has a `nowait` clause or
+  /// not.
+  InsertPointOrErrorTy
+  createTarget(const LocationDescription &Loc, bool IsOffloadEntry,
+   OpenMPIRBuilder::InsertPointTy AllocaIP,
+   OpenMPIRBuilder::InsertPointTy CodeGenIP,
+   TargetRegionEntryInfo &EntryInfo, ArrayRef NumTeams,
+   ArrayRef NumThreads, SmallVectorImpl &Inputs,
+   Value *IfCond, GenMapInfoCallbackTy GenMapInfoCB,
+   TargetBodyGenCallbackTy BodyGenCB,
+   TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
+   SmallVector Dependencies = {},
+   bool HasNowait = false);
 
   /// Returns __kmpc_for_static_init_* runtime function for the specified
   /// size \a IVSize and sign \a IVSigned. Will create a distribute call
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index db77c6a5869764..0e190f4c64a8b3 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7310,6 +7310,7 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase 
&Builder,
OpenMPIRBuilder::InsertPointTy AllocaIP, Function *OutlinedFn,
Constant *OutlinedFnID, ArrayRef NumTeams,
ArrayRef NumThreads, SmallVectorImpl &Args,
+   Value *IfCond,
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
SmallVector Dependencies = 
{},
bool HasNoWait = false) {
@@ -7354,9 +7355,9 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase 
&Builder,
 return Error::success();
   };
 
-  // If we don't have an ID for the target region, it means an offload entry
-  // wasn't created. In this case we just run the host fallback directly.
-  if (!OutlinedFnID) {
+  auto &&EmitTargetCallElse =
+  [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
+  OpenMPIRBuilder::InsertPointTy CodeGenIP) -> Error {
 // Assume no error was returned because EmitTargetCallFallbackCB doesn't
 // produce any.
 OpenMPIRBuilder::InsertPointTy AfterIP = cantFail([&]() {
@@ -7372,65 +7373,87 @@ emitTargetCall(OpenMPIRBuilder &O

[llvm-branch-commits] [flang] [Flang] Introduce FortranSupport (PR #122069)

2025-01-10 Thread Peter Klausler via llvm-branch-commits

klausler wrote:

There's an implicit assumption here that either future runtime work won't 
occur, or won't need anything from Common that you're moving away into the new 
compiler-only directory.

Is this change required for your work that restructures the runtime builds?

https://github.com/llvm/llvm-project/pull/122069
___
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] [mlir] [OMPIRBuilder][MLIR] Add support for target 'if' clause (PR #122478)

2025-01-10 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-flang-openmp

Author: Sergio Afonso (skatrak)


Changes

This patch implements support for handling the 'if' clause of OpenMP 'target' 
constructs in the OMPIRBuilder and updates MLIR to LLVM IR translation of the 
`omp.target` MLIR operation to make use of this new feature.

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


6 Files Affected:

- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+15-11) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+77-53) 
- (modified) llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp (+6-5) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+6-3) 
- (added) mlir/test/Target/LLVMIR/omptarget-if.mlir (+68) 
- (modified) mlir/test/Target/LLVMIR/openmp-todo.mlir (-11) 


``diff
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 4ce47b1c05d9b0..b1a23996c7bdd2 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2965,21 +2965,25 @@ class OpenMPIRBuilder {
   /// \param NumThreads Number of teams specified in the thread_limit clause.
   /// \param Inputs The input values to the region that will be passed.
   /// as arguments to the outlined function.
+  /// \param IfCond value of the `if` clause.
   /// \param BodyGenCB Callback that will generate the region code.
   /// \param ArgAccessorFuncCB Callback that will generate accessors
   /// instructions for passed in target arguments where neccessary
   /// \param Dependencies A vector of DependData objects that carry
-  // dependency information as passed in the depend clause
-  // \param HasNowait Whether the target construct has a `nowait` clause or 
not.
-  InsertPointOrErrorTy createTarget(
-  const LocationDescription &Loc, bool IsOffloadEntry,
-  OpenMPIRBuilder::InsertPointTy AllocaIP,
-  OpenMPIRBuilder::InsertPointTy CodeGenIP,
-  TargetRegionEntryInfo &EntryInfo, ArrayRef NumTeams,
-  ArrayRef NumThreads, SmallVectorImpl &Inputs,
-  GenMapInfoCallbackTy GenMapInfoCB, TargetBodyGenCallbackTy BodyGenCB,
-  TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
-  SmallVector Dependencies = {}, bool HasNowait = false);
+  /// dependency information as passed in the depend clause
+  /// \param HasNowait Whether the target construct has a `nowait` clause or
+  /// not.
+  InsertPointOrErrorTy
+  createTarget(const LocationDescription &Loc, bool IsOffloadEntry,
+   OpenMPIRBuilder::InsertPointTy AllocaIP,
+   OpenMPIRBuilder::InsertPointTy CodeGenIP,
+   TargetRegionEntryInfo &EntryInfo, ArrayRef NumTeams,
+   ArrayRef NumThreads, SmallVectorImpl &Inputs,
+   Value *IfCond, GenMapInfoCallbackTy GenMapInfoCB,
+   TargetBodyGenCallbackTy BodyGenCB,
+   TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
+   SmallVector Dependencies = {},
+   bool HasNowait = false);
 
   /// Returns __kmpc_for_static_init_* runtime function for the specified
   /// size \a IVSize and sign \a IVSigned. Will create a distribute call
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index db77c6a5869764..0e190f4c64a8b3 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7310,6 +7310,7 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase 
&Builder,
OpenMPIRBuilder::InsertPointTy AllocaIP, Function *OutlinedFn,
Constant *OutlinedFnID, ArrayRef NumTeams,
ArrayRef NumThreads, SmallVectorImpl &Args,
+   Value *IfCond,
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
SmallVector Dependencies = 
{},
bool HasNoWait = false) {
@@ -7354,9 +7355,9 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase 
&Builder,
 return Error::success();
   };
 
-  // If we don't have an ID for the target region, it means an offload entry
-  // wasn't created. In this case we just run the host fallback directly.
-  if (!OutlinedFnID) {
+  auto &&EmitTargetCallElse =
+  [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
+  OpenMPIRBuilder::InsertPointTy CodeGenIP) -> Error {
 // Assume no error was returned because EmitTargetCallFallbackCB doesn't
 // produce any.
 OpenMPIRBuilder::InsertPointTy AfterIP = cantFail([&]() {
@@ -7372,65 +7373,87 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, 
IRBuilderBase &Builder,
 }());
 
 Builder.restoreIP(AfterIP);
-return;
-  }
+return Error::success();
+  };
+
+  auto &&EmitTargetCallThen =
+  [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
+  OpenMPIRBuilder::InsertPointTy CodeGenIP) -> Error {
+OpenMPIRBuilder::TargetDataInfo Info(
+/*Requ

[llvm-branch-commits] [llvm] [mlir] [OMPIRBuilder][MLIR] Add support for target 'if' clause (PR #122478)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits

skatrak wrote:

PR stack:
- #122477
- #122478

https://github.com/llvm/llvm-project/pull/122478
___
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] [Driver][RISCV] Integrate RISCV target in baremetal toolchain object and deprecate RISCVToolchain object.(3/3) (PR #121831)

2025-01-10 Thread Garvit Gupta via llvm-branch-commits

https://github.com/quic-garvgupt edited 
https://github.com/llvm/llvm-project/pull/121831
___
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] [Driver] Change linker job in Baremetal toolchain object accomodate GCCInstallation.(2/3) (PR #121830)

2025-01-10 Thread Garvit Gupta via llvm-branch-commits

https://github.com/quic-garvgupt edited 
https://github.com/llvm/llvm-project/pull/121830
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 215c7e6133bf07d005ac7483b8faf797e319a1fa Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 12 Dec 2024 15:26:26 -0600
Subject: [PATCH 1/6] [flang][OpenMP] Parsing context selectors for
 METADIRECTIVE

This is just adding parsers for context selectors. There are no tests
because there is no way to execute these parsers yet.
---
 flang/include/flang/Parser/characters.h  |   2 +
 flang/include/flang/Parser/dump-parse-tree.h |  14 ++
 flang/include/flang/Parser/parse-tree.h  | 136 +++
 flang/lib/Parser/openmp-parsers.cpp  |  78 +++
 flang/lib/Parser/token-parsers.h |   4 +
 flang/lib/Parser/unparse.cpp |  38 ++
 flang/lib/Semantics/check-omp-structure.cpp  |   8 ++
 flang/lib/Semantics/check-omp-structure.h|   3 +
 flang/lib/Semantics/resolve-directives.cpp   |   6 +
 9 files changed, 289 insertions(+)

diff --git a/flang/include/flang/Parser/characters.h 
b/flang/include/flang/Parser/characters.h
index df188d674b9eeb..dbdc058c44995a 100644
--- a/flang/include/flang/Parser/characters.h
+++ b/flang/include/flang/Parser/characters.h
@@ -180,6 +180,8 @@ inline constexpr bool IsValidFortranTokenCharacter(char ch) 
{
   case '>':
   case '[':
   case ']':
+  case '{': // Used in OpenMP context selector specification
+  case '}': //
 return true;
   default:
 return IsLegalIdentifierStart(ch) || IsDecimalDigit(ch);
diff --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index 3331520922bc63..a61d7973dd5c36 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -476,6 +476,20 @@ class ParseTreeDumper {
   NODE(parser, NullInit)
   NODE(parser, ObjectDecl)
   NODE(parser, OldParameterStmt)
+  NODE(parser, OmpDirectiveSpecification)
+  NODE(parser, OmpTraitPropertyName)
+  NODE(parser, OmpTraitScore)
+  NODE(parser, OmpTraitPropertyExtension)
+  NODE(OmpTraitPropertyExtension, ExtensionValue)
+  NODE(parser, OmpTraitProperty)
+  NODE(parser, OmpTraitSelectorName)
+  NODE_ENUM(OmpTraitSelectorName, Value)
+  NODE(parser, OmpTraitSelector)
+  NODE(OmpTraitSelector, Properties)
+  NODE(parser, OmpTraitSetSelectorName)
+  NODE_ENUM(OmpTraitSetSelectorName, Value)
+  NODE(parser, OmpTraitSetSelector)
+  NODE(parser, OmpContextSelectorSpecification)
   NODE(parser, OmpMapper)
   NODE(parser, OmpMapType)
   NODE_ENUM(OmpMapType, Value)
diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 941d70d3876291..697bddfaf16150 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3453,6 +3453,17 @@ WRAPPER_CLASS(PauseStmt, std::optional);
 
 // --- Common definitions
 
+struct OmpClause;
+struct OmpClauseList;
+
+struct OmpDirectiveSpecification {
+  TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification);
+  std::tuple>>
+  t;
+  CharBlock source;
+};
+
 // 2.1 Directives or clauses may accept a list or extended-list.
 // A list item is a variable, array section or common block name (enclosed
 // in slashes). An extended list item is a list item or a procedure Name.
@@ -3474,6 +3485,128 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);
+};
+
+// trait-property-extension ->
+//trait-property-name (trait-property-value, ...)
+// trait-property-value ->
+//trait-property-name |
+//scalar-integer-expression |
+//trait-property-extension
+//
+// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
+// version (but equivalent) that doesn't have ambiguities.
+// The ambiguity is in
+//   trait-property:
+//  trait-property-name  <- (a)
+//  trait-property-clause
+//  trait-property-expression<- (b)
+//  trait-property-extension <- this conflicts with (a) and (b)
+//   trait-property-extension:
+//  trait-property-name  <- conflict with (a)
+//  identifier(trait-property-extension[, trait-property-extension[, ...]])
+//  constant integer expression  <- conflict with (b)
+//
+struct OmpTraitPropertyExtension {
+  TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension);
+  struct ExtensionValue {
+UNION_CLASS_BOILERPLATE(ExtensionValue);
+std::variant>
+u;
+  };
+  using ExtensionList = std::list;
+  std::tuple t;
+};
+
+// trait-property ->
+//trait-property-name | OmpClause |
+//trait-property-expression | trait-property-extension
+// trait-property-expression ->
+//

[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -1000,6 +1000,7 @@ def MapInfoOp : OpenMP_Op<"map.info", 
[AttrSizedOperandSegments]> {
OptionalAttr:$members_index,
Variadic:$bounds, /* rank-0 to 
rank-{n-1} */
OptionalAttr:$map_type,
+   OptionalAttr:$mapper_id,

kiranchandramohan wrote:

If it can only be the name of a declare mapper then it might be good to add 
that to the verifier.

https://github.com/llvm/llvm-project/pull/120994
___
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] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -1000,6 +1000,7 @@ def MapInfoOp : OpenMP_Op<"map.info", 
[AttrSizedOperandSegments]> {
OptionalAttr:$members_index,
Variadic:$bounds, /* rank-0 to 
rank-{n-1} */
OptionalAttr:$map_type,
+   OptionalAttr:$mapper_id,

kiranchandramohan wrote:

Please add a description for this argument.

https://github.com/llvm/llvm-project/pull/120994
___
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] [mlir] [OMPIRBuilder][MLIR] Add support for target 'if' clause (PR #122478)

2025-01-10 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak updated 
https://github.com/llvm/llvm-project/pull/122478

>From 83c1d7917c863026b30310ea7a1a42ea9467fd55 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Fri, 10 Jan 2025 15:40:05 +
Subject: [PATCH] [OMPIRBuilder][MLIR] Add support for target 'if' clause

This patch implements support for handling the 'if' clause of OpenMP 'target'
constructs in the OMPIRBuilder and updates MLIR to LLVM IR translation of the
`omp.target` MLIR operation to make use of this new feature.
---
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   |  26 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 130 +++---
 .../Frontend/OpenMPIRBuilderTest.cpp  |  11 +-
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  |  13 +-
 mlir/test/Target/LLVMIR/omptarget-if.mlir |  68 +
 mlir/test/Target/LLVMIR/openmp-todo.mlir  |  11 --
 6 files changed, 172 insertions(+), 87 deletions(-)
 create mode 100644 mlir/test/Target/LLVMIR/omptarget-if.mlir

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 4ce47b1c05d9b0..b1a23996c7bdd2 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2965,21 +2965,25 @@ class OpenMPIRBuilder {
   /// \param NumThreads Number of teams specified in the thread_limit clause.
   /// \param Inputs The input values to the region that will be passed.
   /// as arguments to the outlined function.
+  /// \param IfCond value of the `if` clause.
   /// \param BodyGenCB Callback that will generate the region code.
   /// \param ArgAccessorFuncCB Callback that will generate accessors
   /// instructions for passed in target arguments where neccessary
   /// \param Dependencies A vector of DependData objects that carry
-  // dependency information as passed in the depend clause
-  // \param HasNowait Whether the target construct has a `nowait` clause or 
not.
-  InsertPointOrErrorTy createTarget(
-  const LocationDescription &Loc, bool IsOffloadEntry,
-  OpenMPIRBuilder::InsertPointTy AllocaIP,
-  OpenMPIRBuilder::InsertPointTy CodeGenIP,
-  TargetRegionEntryInfo &EntryInfo, ArrayRef NumTeams,
-  ArrayRef NumThreads, SmallVectorImpl &Inputs,
-  GenMapInfoCallbackTy GenMapInfoCB, TargetBodyGenCallbackTy BodyGenCB,
-  TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
-  SmallVector Dependencies = {}, bool HasNowait = false);
+  /// dependency information as passed in the depend clause
+  /// \param HasNowait Whether the target construct has a `nowait` clause or
+  /// not.
+  InsertPointOrErrorTy
+  createTarget(const LocationDescription &Loc, bool IsOffloadEntry,
+   OpenMPIRBuilder::InsertPointTy AllocaIP,
+   OpenMPIRBuilder::InsertPointTy CodeGenIP,
+   TargetRegionEntryInfo &EntryInfo, ArrayRef NumTeams,
+   ArrayRef NumThreads, SmallVectorImpl &Inputs,
+   Value *IfCond, GenMapInfoCallbackTy GenMapInfoCB,
+   TargetBodyGenCallbackTy BodyGenCB,
+   TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
+   SmallVector Dependencies = {},
+   bool HasNowait = false);
 
   /// Returns __kmpc_for_static_init_* runtime function for the specified
   /// size \a IVSize and sign \a IVSigned. Will create a distribute call
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index db77c6a5869764..0e190f4c64a8b3 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7310,6 +7310,7 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase 
&Builder,
OpenMPIRBuilder::InsertPointTy AllocaIP, Function *OutlinedFn,
Constant *OutlinedFnID, ArrayRef NumTeams,
ArrayRef NumThreads, SmallVectorImpl &Args,
+   Value *IfCond,
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
SmallVector Dependencies = 
{},
bool HasNoWait = false) {
@@ -7354,9 +7355,9 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase 
&Builder,
 return Error::success();
   };
 
-  // If we don't have an ID for the target region, it means an offload entry
-  // wasn't created. In this case we just run the host fallback directly.
-  if (!OutlinedFnID) {
+  auto &&EmitTargetCallElse =
+  [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
+  OpenMPIRBuilder::InsertPointTy CodeGenIP) -> Error {
 // Assume no error was returned because EmitTargetCallFallbackCB doesn't
 // produce any.
 OpenMPIRBuilder::InsertPointTy AfterIP = cantFail([&]() {
@@ -7372,65 +7373,87 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, 
IRBuilderBase &Builder,
 }());
 
 Builder.restoreIP(AfterIP);
-return;
-  }
+return Error::success();
+  };
+
+  auto &&EmitTargetCallThen =
+  [&](OpenMPIRBuilder::InsertPointTy AllocaIP,

[llvm-branch-commits] [clang] [llvm] [IR] Add FPOperation intrinsic property (PR #122313)

2025-01-10 Thread Eli Friedman via llvm-branch-commits

efriedma-quic wrote:

Should this be part of the "memory" attribute, instead of an independent thing?

In my head, the model I have is the following: the current fp state is a bit of 
thread-local state, and transforms that use generic reasoning about memory 
reads/writes should be able to conservatively handle fp state without knowing 
anything about it.  Then we have some additional markings that allow fp-aware 
transforms to be more precise: they can see if the operation reads the status 
flags, or whether the rounding mode is known.

I don't think attributes specific to intrinsics make sense in this context; 
anything that makes sense to assert about an intrinsic call, equally makes 
sense to assert about a non-intrinsic call.

https://github.com/llvm/llvm-project/pull/122313
___
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-cov: Introduce `--merge-instantiations=` (PR #121194)

2025-01-10 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/121194

>From 273eea73c158acbf7140bd599554b2ba02d88097 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 27 Dec 2024 16:14:24 +0900
Subject: [PATCH] llvm-cov: Introduce `--merge-instantiations=`

---
 .../ProfileData/Coverage/CoverageMapping.h|  82 -
 .../ProfileData/Coverage/CoverageMapping.cpp  | 170 --
 .../llvm-cov/Inputs/branch-templates.cpp  |   6 +-
 .../llvm-cov/Inputs/mcdc-templates-merge.cpp  |  54 ++
 .../Inputs/mcdc-templates-merge.proftext  |  73 
 .../llvm-cov/Inputs/mcdc-templates-merge.yaml | 105 +++
 .../tools/llvm-cov/branch-export-json.test|   2 +-
 .../tools/llvm-cov/branch-export-lcov.test|   4 +-
 llvm/test/tools/llvm-cov/branch-macros.test   |   9 +
 .../test/tools/llvm-cov/branch-templates.test |   4 +-
 .../tools/llvm-cov/mcdc-templates-merge.test  |  41 +
 llvm/tools/llvm-cov/CodeCoverage.cpp  |  12 +-
 llvm/tools/llvm-cov/CoverageReport.cpp|   4 +-
 llvm/tools/llvm-cov/CoverageViewOptions.h |   2 +
 llvm/tools/llvm-cov/SourceCoverageView.cpp|   4 +-
 15 files changed, 540 insertions(+), 32 deletions(-)
 create mode 100644 llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.cpp
 create mode 100644 
llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.proftext
 create mode 100644 llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.yaml
 create mode 100644 llvm/test/tools/llvm-cov/mcdc-templates-merge.test

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index 64416fdba1b247..d6df8403a2cd1c 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -59,6 +59,12 @@ namespace coverage {
 class CoverageMappingReader;
 struct CoverageMappingRecord;
 
+enum class MergeStrategy {
+  Merge,
+  Any,
+  All,
+};
+
 enum class coveragemap_error {
   success = 0,
   eof,
@@ -375,6 +381,32 @@ struct CountedRegion : public CounterMappingRegion {
   : CounterMappingRegion(R), ExecutionCount(ExecutionCount),
 FalseExecutionCount(FalseExecutionCount), TrueFolded(false),
 FalseFolded(false) {}
+
+  LineColPair viewLoc() const { return startLoc(); }
+
+  bool isMergeable(const CountedRegion &RHS) const {
+return (this->viewLoc() == RHS.viewLoc());
+  }
+
+  void merge(const CountedRegion &RHS, MergeStrategy Strategy);
+
+  /// Returns comparable rank value in selecting a better Record for merging.
+  auto getMergeRank(MergeStrategy Strategy) const {
+assert(isBranch() && "Dedicated to Branch");
+assert(Strategy == MergeStrategy::Any && "Dedicated to Any");
+unsigned m = 0;
+// Prefer both Counts have values.
+m = (m << 1) | (ExecutionCount != 0 && FalseExecutionCount != 0);
+// Prefer both are unfolded.
+m = (m << 1) | (!TrueFolded && !FalseFolded);
+// Prefer either Count has value.
+m = (m << 1) | (ExecutionCount != 0 || FalseExecutionCount != 0);
+// Prefer either is unfolded.
+m = (m << 1) | (!TrueFolded || !FalseFolded);
+return std::make_pair(m, ExecutionCount + FalseExecutionCount);
+  }
+
+  void commit() const {}
 };
 
 /// MCDC Record grouping all information together.
@@ -462,6 +494,19 @@ struct MCDCRecord {
 findIndependencePairs();
   }
 
+  inline LineColPair viewLoc() const { return Region.endLoc(); }
+
+  bool isMergeable(const MCDCRecord &RHS) const {
+return (this->viewLoc() == RHS.viewLoc() && this->PosToID == RHS.PosToID &&
+this->CondLoc == RHS.CondLoc);
+  }
+
+  // This may invalidate IndependencePairs
+  // MCDCRecord &operator+=(const MCDCRecord &RHS);
+  void merge(MCDCRecord &&RHS, MergeStrategy Strategy);
+
+  void commit() { findIndependencePairs(); }
+
   // Compare executed test vectors against each other to find an independence
   // pairs for each condition.  This processing takes the most time.
   void findIndependencePairs();
@@ -512,15 +557,42 @@ struct MCDCRecord {
 return (*IndependencePairs)[PosToID[Condition]];
   }
 
-  float getPercentCovered() const {
-unsigned Folded = 0;
+  std::pair getCoveredCount() const {
 unsigned Covered = 0;
+unsigned Folded = 0;
 for (unsigned C = 0; C < getNumConditions(); C++) {
   if (isCondFolded(C))
 Folded++;
   else if (isConditionIndependencePairCovered(C))
 Covered++;
 }
+return {Covered, Folded};
+  }
+
+  /// Returns comparable rank value in selecting a better Record for merging.
+  std::tuple
+  getMergeRank(MergeStrategy Strategy) const {
+auto [Covered, Folded] = getCoveredCount();
+auto NumTVs = getNumTestVectors();
+switch (Strategy) {
+case MergeStrategy::Merge:
+case MergeStrategy::Any:
+  return {
+  Covered, // The largest covered number
+  ~Folded, // Less folded is better
+  NumTVs,  // 

[llvm-branch-commits] [llvm] llvm-cov: Introduce `--merge-instantiations=` (PR #121194)

2025-01-10 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/121194

>From 273eea73c158acbf7140bd599554b2ba02d88097 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 27 Dec 2024 16:14:24 +0900
Subject: [PATCH] llvm-cov: Introduce `--merge-instantiations=`

---
 .../ProfileData/Coverage/CoverageMapping.h|  82 -
 .../ProfileData/Coverage/CoverageMapping.cpp  | 170 --
 .../llvm-cov/Inputs/branch-templates.cpp  |   6 +-
 .../llvm-cov/Inputs/mcdc-templates-merge.cpp  |  54 ++
 .../Inputs/mcdc-templates-merge.proftext  |  73 
 .../llvm-cov/Inputs/mcdc-templates-merge.yaml | 105 +++
 .../tools/llvm-cov/branch-export-json.test|   2 +-
 .../tools/llvm-cov/branch-export-lcov.test|   4 +-
 llvm/test/tools/llvm-cov/branch-macros.test   |   9 +
 .../test/tools/llvm-cov/branch-templates.test |   4 +-
 .../tools/llvm-cov/mcdc-templates-merge.test  |  41 +
 llvm/tools/llvm-cov/CodeCoverage.cpp  |  12 +-
 llvm/tools/llvm-cov/CoverageReport.cpp|   4 +-
 llvm/tools/llvm-cov/CoverageViewOptions.h |   2 +
 llvm/tools/llvm-cov/SourceCoverageView.cpp|   4 +-
 15 files changed, 540 insertions(+), 32 deletions(-)
 create mode 100644 llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.cpp
 create mode 100644 
llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.proftext
 create mode 100644 llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.yaml
 create mode 100644 llvm/test/tools/llvm-cov/mcdc-templates-merge.test

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index 64416fdba1b247..d6df8403a2cd1c 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -59,6 +59,12 @@ namespace coverage {
 class CoverageMappingReader;
 struct CoverageMappingRecord;
 
+enum class MergeStrategy {
+  Merge,
+  Any,
+  All,
+};
+
 enum class coveragemap_error {
   success = 0,
   eof,
@@ -375,6 +381,32 @@ struct CountedRegion : public CounterMappingRegion {
   : CounterMappingRegion(R), ExecutionCount(ExecutionCount),
 FalseExecutionCount(FalseExecutionCount), TrueFolded(false),
 FalseFolded(false) {}
+
+  LineColPair viewLoc() const { return startLoc(); }
+
+  bool isMergeable(const CountedRegion &RHS) const {
+return (this->viewLoc() == RHS.viewLoc());
+  }
+
+  void merge(const CountedRegion &RHS, MergeStrategy Strategy);
+
+  /// Returns comparable rank value in selecting a better Record for merging.
+  auto getMergeRank(MergeStrategy Strategy) const {
+assert(isBranch() && "Dedicated to Branch");
+assert(Strategy == MergeStrategy::Any && "Dedicated to Any");
+unsigned m = 0;
+// Prefer both Counts have values.
+m = (m << 1) | (ExecutionCount != 0 && FalseExecutionCount != 0);
+// Prefer both are unfolded.
+m = (m << 1) | (!TrueFolded && !FalseFolded);
+// Prefer either Count has value.
+m = (m << 1) | (ExecutionCount != 0 || FalseExecutionCount != 0);
+// Prefer either is unfolded.
+m = (m << 1) | (!TrueFolded || !FalseFolded);
+return std::make_pair(m, ExecutionCount + FalseExecutionCount);
+  }
+
+  void commit() const {}
 };
 
 /// MCDC Record grouping all information together.
@@ -462,6 +494,19 @@ struct MCDCRecord {
 findIndependencePairs();
   }
 
+  inline LineColPair viewLoc() const { return Region.endLoc(); }
+
+  bool isMergeable(const MCDCRecord &RHS) const {
+return (this->viewLoc() == RHS.viewLoc() && this->PosToID == RHS.PosToID &&
+this->CondLoc == RHS.CondLoc);
+  }
+
+  // This may invalidate IndependencePairs
+  // MCDCRecord &operator+=(const MCDCRecord &RHS);
+  void merge(MCDCRecord &&RHS, MergeStrategy Strategy);
+
+  void commit() { findIndependencePairs(); }
+
   // Compare executed test vectors against each other to find an independence
   // pairs for each condition.  This processing takes the most time.
   void findIndependencePairs();
@@ -512,15 +557,42 @@ struct MCDCRecord {
 return (*IndependencePairs)[PosToID[Condition]];
   }
 
-  float getPercentCovered() const {
-unsigned Folded = 0;
+  std::pair getCoveredCount() const {
 unsigned Covered = 0;
+unsigned Folded = 0;
 for (unsigned C = 0; C < getNumConditions(); C++) {
   if (isCondFolded(C))
 Folded++;
   else if (isConditionIndependencePairCovered(C))
 Covered++;
 }
+return {Covered, Folded};
+  }
+
+  /// Returns comparable rank value in selecting a better Record for merging.
+  std::tuple
+  getMergeRank(MergeStrategy Strategy) const {
+auto [Covered, Folded] = getCoveredCount();
+auto NumTVs = getNumTestVectors();
+switch (Strategy) {
+case MergeStrategy::Merge:
+case MergeStrategy::Any:
+  return {
+  Covered, // The largest covered number
+  ~Folded, // Less folded is better
+  NumTVs,  // 

[llvm-branch-commits] [llvm] llvm-cov: Show `FileCoverageSummary` with `getCoverageForFile()` (PR #121192)

2025-01-10 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/121192

>From c1678ea160892c7b0912d9521866073a6b2ff839 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 27 Dec 2024 16:11:10 +0900
Subject: [PATCH 1/3] llvm-cov: Use `getCoverageForFile()`

---
 .../ProfileData/Coverage/CoverageMapping.h|  4 +-
 .../ProfileData/Coverage/CoverageMapping.cpp  |  6 ++-
 .../test/tools/llvm-cov/branch-templates.test |  4 +-
 .../tools/llvm-cov/coverage_watermark.test| 22 
 llvm/test/tools/llvm-cov/zeroFunctionFile.c   |  3 +-
 llvm/tools/llvm-cov/CoverageReport.cpp| 42 +++
 llvm/tools/llvm-cov/CoverageSummaryInfo.cpp   | 26 --
 llvm/tools/llvm-cov/CoverageSummaryInfo.h | 51 +--
 .../tools/llvm-cov/SourceCoverageViewHTML.cpp | 16 --
 9 files changed, 79 insertions(+), 95 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index c51733b46a1894..64416fdba1b247 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -1012,7 +1012,9 @@ class CoverageMapping {
   /// The given filename must be the name as recorded in the coverage
   /// information. That is, only names returned from getUniqueSourceFiles will
   /// yield a result.
-  CoverageData getCoverageForFile(StringRef Filename) const;
+  CoverageData getCoverageForFile(
+  StringRef Filename,
+  const DenseSet &FilteredOutFunctions = {}) const;
 
   /// Get the coverage for a particular function.
   CoverageData getCoverageForFunction(const FunctionRecord &Function) const;
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index feededcd7d1eb5..e7780b465186df 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -1422,7 +1422,9 @@ static bool isExpansion(const CountedRegion &R, unsigned 
FileID) {
   return R.Kind == CounterMappingRegion::ExpansionRegion && R.FileID == FileID;
 }
 
-CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
+CoverageData CoverageMapping::getCoverageForFile(
+StringRef Filename,
+const DenseSet &FilteredOutFunctions) const {
   assert(SingleByteCoverage);
   MergeableCoverageData FileCoverage(*SingleByteCoverage, Filename);
 
@@ -1432,6 +1434,8 @@ CoverageData 
CoverageMapping::getCoverageForFile(StringRef Filename) const {
   getImpreciseRecordIndicesForFilename(Filename);
   for (unsigned RecordIndex : RecordIndices) {
 const FunctionRecord &Function = Functions[RecordIndex];
+if (FilteredOutFunctions.count(&Function))
+  continue;
 auto MainFileID = findMainViewFileID(Filename, Function);
 auto FileIDs = gatherFileIDs(Filename, Function);
 FileCoverage.addFunctionRegions(
diff --git a/llvm/test/tools/llvm-cov/branch-templates.test 
b/llvm/test/tools/llvm-cov/branch-templates.test
index d5535022239f5f..594a3ca533678b 100644
--- a/llvm/test/tools/llvm-cov/branch-templates.test
+++ b/llvm/test/tools/llvm-cov/branch-templates.test
@@ -26,6 +26,6 @@
 
 // REPORTFILE:  Filename RegionsMissed Regions 
Cover   Functions  Missed Functions  Executed   Lines  Missed Lines 
CoverBranches   Missed Branches Cover
 // REPORTFILE-NEXT: ---
-// REPORTFILE-NEXT: branch-templates.cpp  12 3
75.00%   2 0   100.00%  17 4
76.47%   8 450.00%
+// REPORTFILE-NEXT: branch-templates.cpp  12 2
83.33%   2 0   100.00%  17 3
82.35%  12 650.00%
 // REPORTFILE-NEXT: ---
-// REPORTFILE-NEXT: TOTAL 12 3
75.00%   2 0   100.00%  17 4
76.47%   8 450.00%
+// REPORTFILE-NEXT: TOTAL 12 2
83.33%   2 0   100.00%  17 3
82.35%  12 650.00%
diff --git a/llvm/test/tools/llvm-cov/coverage_watermark.test 
b/llvm/test/tools/llvm-cov/coverage_watermark.test
index 5c48b4f0fb4bf4..818baa470bc38d 100644
--- a/llvm/test/tools/llvm-cov/coverage_watermark.test
+++ b/llvm/test/tools/llvm-cov/coverage_watermark.test
@@ -18,15 +18,15 @@ ORIGIN: 
 ORIGIN: 100.00% (2/2)
 ORIGIN: 
 ORIGIN: 100.00% (3/3)
-ORIGIN: 
-ORIGIN: 75.00% (9/12)
-ORIGIN: 
-ORIGIN: 66.67% (4/6)
+ORIGIN: 
+ORIGIN: 83.33% (10/12)
+ORIGIN: 
+ORIGIN: 83.33% (5/6)
 ORIGIN: 
 ORIGIN: - (0/0)
 ORIGIN: 
 
-RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile 
%S/Inputs/templateInstantiations.profdata -format html -show-region-summary 
-show-instanti

[llvm-branch-commits] [llvm] llvm-cov: Show `FileCoverageSummary` with `getCoverageForFile()` (PR #121192)

2025-01-10 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/121192

>From c1678ea160892c7b0912d9521866073a6b2ff839 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 27 Dec 2024 16:11:10 +0900
Subject: [PATCH 1/3] llvm-cov: Use `getCoverageForFile()`

---
 .../ProfileData/Coverage/CoverageMapping.h|  4 +-
 .../ProfileData/Coverage/CoverageMapping.cpp  |  6 ++-
 .../test/tools/llvm-cov/branch-templates.test |  4 +-
 .../tools/llvm-cov/coverage_watermark.test| 22 
 llvm/test/tools/llvm-cov/zeroFunctionFile.c   |  3 +-
 llvm/tools/llvm-cov/CoverageReport.cpp| 42 +++
 llvm/tools/llvm-cov/CoverageSummaryInfo.cpp   | 26 --
 llvm/tools/llvm-cov/CoverageSummaryInfo.h | 51 +--
 .../tools/llvm-cov/SourceCoverageViewHTML.cpp | 16 --
 9 files changed, 79 insertions(+), 95 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index c51733b46a1894..64416fdba1b247 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -1012,7 +1012,9 @@ class CoverageMapping {
   /// The given filename must be the name as recorded in the coverage
   /// information. That is, only names returned from getUniqueSourceFiles will
   /// yield a result.
-  CoverageData getCoverageForFile(StringRef Filename) const;
+  CoverageData getCoverageForFile(
+  StringRef Filename,
+  const DenseSet &FilteredOutFunctions = {}) const;
 
   /// Get the coverage for a particular function.
   CoverageData getCoverageForFunction(const FunctionRecord &Function) const;
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index feededcd7d1eb5..e7780b465186df 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -1422,7 +1422,9 @@ static bool isExpansion(const CountedRegion &R, unsigned 
FileID) {
   return R.Kind == CounterMappingRegion::ExpansionRegion && R.FileID == FileID;
 }
 
-CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
+CoverageData CoverageMapping::getCoverageForFile(
+StringRef Filename,
+const DenseSet &FilteredOutFunctions) const {
   assert(SingleByteCoverage);
   MergeableCoverageData FileCoverage(*SingleByteCoverage, Filename);
 
@@ -1432,6 +1434,8 @@ CoverageData 
CoverageMapping::getCoverageForFile(StringRef Filename) const {
   getImpreciseRecordIndicesForFilename(Filename);
   for (unsigned RecordIndex : RecordIndices) {
 const FunctionRecord &Function = Functions[RecordIndex];
+if (FilteredOutFunctions.count(&Function))
+  continue;
 auto MainFileID = findMainViewFileID(Filename, Function);
 auto FileIDs = gatherFileIDs(Filename, Function);
 FileCoverage.addFunctionRegions(
diff --git a/llvm/test/tools/llvm-cov/branch-templates.test 
b/llvm/test/tools/llvm-cov/branch-templates.test
index d5535022239f5f..594a3ca533678b 100644
--- a/llvm/test/tools/llvm-cov/branch-templates.test
+++ b/llvm/test/tools/llvm-cov/branch-templates.test
@@ -26,6 +26,6 @@
 
 // REPORTFILE:  Filename RegionsMissed Regions 
Cover   Functions  Missed Functions  Executed   Lines  Missed Lines 
CoverBranches   Missed Branches Cover
 // REPORTFILE-NEXT: ---
-// REPORTFILE-NEXT: branch-templates.cpp  12 3
75.00%   2 0   100.00%  17 4
76.47%   8 450.00%
+// REPORTFILE-NEXT: branch-templates.cpp  12 2
83.33%   2 0   100.00%  17 3
82.35%  12 650.00%
 // REPORTFILE-NEXT: ---
-// REPORTFILE-NEXT: TOTAL 12 3
75.00%   2 0   100.00%  17 4
76.47%   8 450.00%
+// REPORTFILE-NEXT: TOTAL 12 2
83.33%   2 0   100.00%  17 3
82.35%  12 650.00%
diff --git a/llvm/test/tools/llvm-cov/coverage_watermark.test 
b/llvm/test/tools/llvm-cov/coverage_watermark.test
index 5c48b4f0fb4bf4..818baa470bc38d 100644
--- a/llvm/test/tools/llvm-cov/coverage_watermark.test
+++ b/llvm/test/tools/llvm-cov/coverage_watermark.test
@@ -18,15 +18,15 @@ ORIGIN: 
 ORIGIN: 100.00% (2/2)
 ORIGIN: 
 ORIGIN: 100.00% (3/3)
-ORIGIN: 
-ORIGIN: 75.00% (9/12)
-ORIGIN: 
-ORIGIN: 66.67% (4/6)
+ORIGIN: 
+ORIGIN: 83.33% (10/12)
+ORIGIN: 
+ORIGIN: 83.33% (5/6)
 ORIGIN: 
 ORIGIN: - (0/0)
 ORIGIN: 
 
-RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile 
%S/Inputs/templateInstantiations.profdata -format html -show-region-summary 
-show-instanti

[llvm-branch-commits] [llvm] llvm-cov: [MCDC] Merge and recalculate independence pairs on template instantiations. (PR #121196)

2025-01-10 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/121196

>From dc0ef8f682f704422ec52b484248cdfee1a6e804 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 27 Dec 2024 16:19:01 +0900
Subject: [PATCH] llvm-cov: [MCDC] Merge and recalculate independence pairs on
 template instantiations.

---
 .../ProfileData/Coverage/CoverageMapping.h| 16 --
 .../ProfileData/Coverage/CoverageMapping.cpp  | 57 ---
 .../llvm-cov/Inputs/mcdc-templates-merge.cpp  |  4 +-
 .../tools/llvm-cov/mcdc-templates-merge.test  |  2 +-
 4 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index cfaee395655295..5d7d555a10bd3a 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -471,6 +471,7 @@ struct MCDCRecord {
 }
   };
 
+  using BitmapByCondTy = std::array;
   using TestVectors = llvm::SmallVector>;
   using BoolVector = std::array;
   using TVRowPair = std::pair;
@@ -481,6 +482,7 @@ struct MCDCRecord {
 private:
   CounterMappingRegion Region;
   TestVectors TV;
+  BitmapByCondTy BitmapByCond;
   std::optional IndependencePairs;
   BoolVector Folded;
   CondIDMap PosToID;
@@ -488,8 +490,10 @@ struct MCDCRecord {
 
 public:
   MCDCRecord(const CounterMappingRegion &Region, TestVectors &&TV,
- BoolVector &&Folded, CondIDMap &&PosToID, LineColPairMap 
&&CondLoc)
-  : Region(Region), TV(std::move(TV)), Folded(std::move(Folded)),
+ BitmapByCondTy &&BitmapByCond, BoolVector &&Folded,
+ CondIDMap &&PosToID, LineColPairMap &&CondLoc)
+  : Region(Region), TV(std::move(TV)),
+BitmapByCond(std::move(BitmapByCond)), Folded(std::move(Folded)),
 PosToID(std::move(PosToID)), CondLoc(std::move(CondLoc)) {
 findIndependencePairs();
   }
@@ -497,8 +501,9 @@ struct MCDCRecord {
   inline LineColPair viewLoc() const { return Region.endLoc(); }
 
   bool isMergeable(const MCDCRecord &RHS) const {
-return (this->viewLoc() == RHS.viewLoc() && this->PosToID == RHS.PosToID &&
-this->CondLoc == RHS.CondLoc);
+return (this->viewLoc() == RHS.viewLoc() &&
+this->BitmapByCond[false].size() == RHS.BitmapByCond[true].size() 
&&
+this->PosToID == RHS.PosToID && this->CondLoc == RHS.CondLoc);
   }
 
   // This may invalidate IndependencePairs
@@ -577,7 +582,8 @@ struct MCDCRecord {
 auto [Covered, Folded] = getCoveredCount();
 auto NumTVs = getNumTestVectors();
 switch (Strategy) {
-case MergeStrategy::Merge:
+default:
+  llvm_unreachable("Not supported");
 case MergeStrategy::Any:
   return {
   Covered, // The largest covered number
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 76aa008886291e..8dd354f5122253 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -260,17 +260,55 @@ void CountedRegion::merge(const CountedRegion &RHS, 
MergeStrategy Strategy) {
 }
 
 void MCDCRecord::merge(MCDCRecord &&RHS, MergeStrategy Strategy) {
+  assert(this->TV.size() ==
+ this->BitmapByCond[false].count() + this->BitmapByCond[true].count());
+  assert(RHS.TV.size() ==
+ RHS.BitmapByCond[false].count() + RHS.BitmapByCond[true].count());
   assert(this->PosToID == RHS.PosToID);
   assert(this->CondLoc == RHS.CondLoc);
 
   switch (Strategy) {
   case MergeStrategy::Merge:
+break;
   case MergeStrategy::Any:
   case MergeStrategy::All:
 if (this->getMergeRank(Strategy) < RHS.getMergeRank(Strategy))
   *this = std::move(RHS);
 return;
   }
+
+  std::array LHSTV;
+  auto LHSI = this->TV.begin();
+  auto RHSI = RHS.TV.begin();
+  bool Merged = false;
+  for (auto MCDCCond : {MCDCRecord::MCDC_False, MCDCRecord::MCDC_True}) {
+auto &LHSBitmap = this->BitmapByCond[MCDCCond];
+auto &RHSBitmap = RHS.BitmapByCond[MCDCCond];
+for (unsigned I = 0, E = LHSBitmap.size(); I != E; ++I) {
+  if (LHSBitmap[I]) {
+if (RHSBitmap[I])
+  ++RHSI;
+LHSTV[LHSI->second].push_back(std::move(*LHSI++));
+  } else if (RHSBitmap[I]) {
+LHSTV[RHSI->second].push_back(std::move(*RHSI++));
+LHSBitmap[I] = true;
+Merged = true;
+  }
+}
+
+this->Folded[MCDCCond] &= RHS.Folded[MCDCCond];
+  }
+
+  if (Merged)
+IndependencePairs.reset();
+
+  assert(LHSI == this->TV.end());
+  assert(RHSI == RHS.TV.end());
+  this->TV = std::move(LHSTV[false]);
+  this->TV.append(std::make_move_iterator(LHSTV[true].begin()),
+  std::make_move_iterator(LHSTV[true].end()));
+  assert(this->TV.size() ==
+ this->BitmapByCond[false].count() + this->BitmapByCond[true].count());
 }
 
 // Find an independence pair for each condition:
@@ -284,13 +3

[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits

https://github.com/kiranchandramohan edited 
https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -153,6 +153,81 @@ static TypeDeclarationStmt 
makeIterSpecDecl(std::list &&names) {
   makeEntityList(std::move(names)));
 }
 
+// --- Parsers for context traits -
+
+TYPE_PARSER(sourced(construct( //
+(space >> charLiteralConstantWithoutKind) ||
+applyMem(&Name::ToString, Parser{}
+
+TYPE_PARSER(sourced(construct( //
+"SCORE" >> parenthesized(scalarIntExpr
+
+TYPE_PARSER(sourced(construct(
+// Parse nested extension first.
+construct(
+indirect(Parser{})) ||
+construct(
+Parser{}) ||
+construct(scalarExpr
+
+TYPE_PARSER(sourced(construct( //
+Parser{},
+parenthesized(nonemptySeparated(
+Parser{}, ","_tok)
+
+TYPE_PARSER(sourced(construct(
+// Try clause first, then extension before OmpTraitPropertyName.
+construct(indirect(Parser{})) ||
+construct(Parser{}) ||
+construct(Parser{}) ||
+construct(scalarExpr
+
+TYPE_PARSER(construct(
+"ARCH" >> pure(OmpTraitSelectorName::Value::Arch) ||
+"ATOMIC_DEFAULT_MEM_ORDER" >>
+pure(OmpTraitSelectorName::Value::Atomic_Default_Mem_Order) ||
+"CONDITION" >> pure(OmpTraitSelectorName::Value::Condition) ||
+"DEVICE_NUM" >> pure(OmpTraitSelectorName::Value::Device_Num) ||
+"EXTENSION" >> pure(OmpTraitSelectorName::Value::Extension) ||
+"ISA" >> pure(OmpTraitSelectorName::Value::Isa) ||
+"KIND" >> pure(OmpTraitSelectorName::Value::Kind) ||
+"REQUIRES" >> pure(OmpTraitSelectorName::Value::Requires) ||
+"SIMD" >> pure(OmpTraitSelectorName::Value::Simd) ||
+"UID" >> pure(OmpTraitSelectorName::Value::Uid) ||
+"VENDOR" >> pure(OmpTraitSelectorName::Value::Vendor)))
+
+TYPE_PARSER(sourced(construct(
+// Parse predefined names first (because of SIMD).
+construct(Parser{}) ||
+construct(OmpDirectiveNameParser{}
+
+TYPE_PARSER(construct(
+maybe(Parser{} / ":"_tok),
+nonemptySeparated(Parser{}, ","_tok)))
+
+TYPE_PARSER(sourced(construct( //
+Parser{}, //
+maybe(parenthesized(Parser{})
+
+TYPE_PARSER(construct(
+"CONSTRUCT" >> pure(OmpTraitSetSelectorName::Value::Construct) ||
+"DEVICE" >> pure(OmpTraitSetSelectorName::Value::Device) ||
+"IMPLEMENTATION" >> pure(OmpTraitSetSelectorName::Value::Implementation) ||
+"TARGET_DEVICE" >> pure(OmpTraitSetSelectorName::Value::Target_Device) ||
+"USER" >> pure(OmpTraitSetSelectorName::Value::User)))
+
+TYPE_PARSER(sourced(construct(
+Parser{})))
+
+TYPE_PARSER(sourced(construct( //
+Parser{},
+"=" >> braced(nonemptySeparated(Parser{}, ","_tok)
+
+TYPE_PARSER(sourced(construct(
+nonemptySeparated(Parser{}, ","_tok
+
+// Parser == 
Parser

kiranchandramohan wrote:

Commented code?

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);
+};
+
+// trait-property-extension ->
+//trait-property-name (trait-property-value, ...)
+// trait-property-value ->
+//trait-property-name |
+//scalar-integer-expression |
+//trait-property-extension
+//
+// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
+// version (but equivalent) that doesn't have ambiguities.
+// The ambiguity is in
+//   trait-property:
+//  trait-property-name  <- (a)
+//  trait-property-clause
+//  trait-property-expression<- (b)
+//  trait-property-extension <- this conflicts with (a) and (b)
+//   trait-property-extension:
+//  trait-property-name  <- conflict with (a)
+//  identifier(trait-property-extension[, trait-property-extension[, ...]])
+//  constant integer expression  <- conflict with (b)
+//
+struct OmpTraitPropertyExtension {
+  CharBlock source;
+  TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension);
+  struct ExtensionValue {
+CharBlock source;
+UNION_CLASS_BOILERPLATE(ExtensionValue);
+std::variant>
+u;
+  };
+  using ExtensionList = std::list;
+  std::tuple t;
+};
+
+// trait-property ->
+//trait-property-name | OmpClause |
+//trait-property-expression | trait-property-extension
+// trait-property-expression ->
+//scalar-logical-expression | scalar-integer-expression
+//
+// The parser for a logical expression will accept an integer expression,
+// and if it's not logical, it will flag an error later. The same thing
+// will happen if the scalar integer expression sees a logical expresion.
+// To avoid this, parse all expressions as scalar expressions.
+struct OmpTraitProperty {
+  CharBlock source;
+  UNION_CLASS_BOILERPLATE(OmpTraitProperty);
+  std::variant,
+  ScalarExpr, // trait-property-expresion
+  OmpTraitPropertyExtension>
+  u;
+};
+
+// trait-selector-name ->
+//KIND |  DT   // name-list (host, nohost, +/add-def-doc)
+//ISA |   DT   // name-list (isa_name, ... /impl-defined)
+//ARCH |  DT   // name-list (arch_name, ... /impl-defined)
+//directive-name |C// no properties
+//SIMD |  C// clause-list (from declare_simd)
+// // (at least simdlen, inbranch/notinbranch)
+//DEVICE_NUM |T// device-number
+//UID |   T// unique-string-id /impl-defined
+//VENDOR |I// name-list (vendor-id /add-def-doc)
+//EXTENSION | I// name-list (ext_name /impl-defined)
+//ATOMIC_DEFAULT_MEM_ORDER I | // value of admo
+//REQUIRES |  I// clause-list (from requires)
+//CONDITION   U// logical-expr
+//
+// Trait-set-selectors:
+//[D]evice, [T]arget_device, [C]onstruct, [I]mplementation, [U]ser.
+struct OmpTraitSelectorName {
+  CharBlock source;
+  UNION_CLASS_BOILERPLATE(OmpTraitSelectorName);
+  ENUM_CLASS(Value, Arch, Atomic_Default_Mem_Order, Condition, Device_Num,
+  Extension, Isa, Kind, Requires, Simd, Uid, Vendor)
+  std::variant u;
+};
+
+// trait-selector ->
+//trait-selector-name |
+//trait-selector-name ([trait-score:] trait-property, ...)
+struct OmpTraitSelector {
+  CharBlock source;
+  TUPLE_CLASS_BOILERPLATE(OmpTraitSelector);
+  struct Properties {
+TUPLE_CLASS_BOILERPLATE(Properties);
+std::tuple, std::list> t;
+  };
+  std::tuple> t;
+};
+
+// trait-set-selector-name ->
+//CONSTRUCT | DEVICE | IMPLEMENTATION | USER |  // since 5.0
+//TARGET_DEVICE // since 5.1
+struct OmpTraitSetSelectorName {
+  CharBlock source;
+  ENUM_CLASS(Value, Construct, Device, Implementation, Target_Device, User)

kiranchandramohan wrote:

Same question as above.

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);
+};
+
+// trait-property-extension ->
+//trait-property-name (trait-property-value, ...)
+// trait-property-value ->
+//trait-property-name |
+//scalar-integer-expression |
+//trait-property-extension
+//
+// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
+// version (but equivalent) that doesn't have ambiguities.
+// The ambiguity is in
+//   trait-property:
+//  trait-property-name  <- (a)
+//  trait-property-clause
+//  trait-property-expression<- (b)
+//  trait-property-extension <- this conflicts with (a) and (b)
+//   trait-property-extension:
+//  trait-property-name  <- conflict with (a)
+//  identifier(trait-property-extension[, trait-property-extension[, ...]])
+//  constant integer expression  <- conflict with (b)
+//
+struct OmpTraitPropertyExtension {
+  CharBlock source;
+  TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension);
+  struct ExtensionValue {
+CharBlock source;
+UNION_CLASS_BOILERPLATE(ExtensionValue);
+std::variant>
+u;
+  };
+  using ExtensionList = std::list;
+  std::tuple t;
+};
+
+// trait-property ->
+//trait-property-name | OmpClause |
+//trait-property-expression | trait-property-extension
+// trait-property-expression ->
+//scalar-logical-expression | scalar-integer-expression
+//
+// The parser for a logical expression will accept an integer expression,
+// and if it's not logical, it will flag an error later. The same thing
+// will happen if the scalar integer expression sees a logical expresion.
+// To avoid this, parse all expressions as scalar expressions.
+struct OmpTraitProperty {
+  CharBlock source;
+  UNION_CLASS_BOILERPLATE(OmpTraitProperty);
+  std::variant,
+  ScalarExpr, // trait-property-expresion
+  OmpTraitPropertyExtension>
+  u;
+};
+
+// trait-selector-name ->
+//KIND |  DT   // name-list (host, nohost, +/add-def-doc)
+//ISA |   DT   // name-list (isa_name, ... /impl-defined)
+//ARCH |  DT   // name-list (arch_name, ... /impl-defined)
+//directive-name |C// no properties
+//SIMD |  C// clause-list (from declare_simd)
+// // (at least simdlen, inbranch/notinbranch)
+//DEVICE_NUM |T// device-number
+//UID |   T// unique-string-id /impl-defined
+//VENDOR |I// name-list (vendor-id /add-def-doc)
+//EXTENSION | I// name-list (ext_name /impl-defined)
+//ATOMIC_DEFAULT_MEM_ORDER I | // value of admo
+//REQUIRES |  I// clause-list (from requires)
+//CONDITION   U// logical-expr
+//
+// Trait-set-selectors:
+//[D]evice, [T]arget_device, [C]onstruct, [I]mplementation, [U]ser.
+struct OmpTraitSelectorName {
+  CharBlock source;
+  UNION_CLASS_BOILERPLATE(OmpTraitSelectorName);
+  ENUM_CLASS(Value, Arch, Atomic_Default_Mem_Order, Condition, Device_Num,

kiranchandramohan wrote:

Are underscores generally used in this file?

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);

kiranchandramohan wrote:

Did we miss the identifier part, ie `Name`?
```
trait-property-name: identifier | string-literal
```

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);

kiranchandramohan wrote:

Should this be `ScalarIntConstantExpr` ?

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits


@@ -3474,6 +3477,138 @@ WRAPPER_CLASS(OmpObjectList, std::list);
 
 #define MODIFIERS() std::optional>
 
+inline namespace traits {
+// trait-property-name ->
+//identifier | string-literal
+struct OmpTraitPropertyName {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string);
+};
+
+// trait-score ->
+//SCORE(non-negative-const-integer-expression)
+struct OmpTraitScore {
+  CharBlock source;
+  WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr);
+};
+
+// trait-property-extension ->
+//trait-property-name (trait-property-value, ...)
+// trait-property-value ->
+//trait-property-name |
+//scalar-integer-expression |
+//trait-property-extension
+//
+// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
+// version (but equivalent) that doesn't have ambiguities.

kiranchandramohan wrote:

Is this reported?

https://github.com/llvm/llvm-project/pull/121815
___
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] Parsing context selectors for METADIRECTIVE (PR #121815)

2025-01-10 Thread Kiran Chandramohan via llvm-branch-commits

https://github.com/kiranchandramohan commented:

Nice work.

A few minor comments.

https://github.com/llvm/llvm-project/pull/121815
___
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] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121819

>From 9f952de3cb3e973f17121c057089a28bf4c6e5e0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 6 Jan 2025 11:15:35 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S

>From 71603241c3e377a5b74c308367f066f3f9e760ae Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 7 Jan 2025 14:59:24 -0800
Subject: [PATCH 2/2] Update commit message and add comment

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 72dd3f5bca9960..602c99fe237b8e 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,6 +20,11 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
+  # We need to set `-fexceptions` here so that key
+  # unwinding functions, like
+  # _UNWIND_RaiseExcpetion, are not marked as
+  # `nounwind`, which breaks LTO builds of
+  # libunwind.  See #56825 and #120657 for context.
   COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES

___
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] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi edited 
https://github.com/llvm/llvm-project/pull/121819
___
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] Reapply "[Fuchsia][cmake] Allow using FatLTO when building runtimes" (#119252) (PR #121820)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121820


___
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] Reapply "[Fuchsia][cmake] Allow using FatLTO when building runtimes" (#119252) (PR #121820)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121820


___
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] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121819

>From 9f952de3cb3e973f17121c057089a28bf4c6e5e0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 6 Jan 2025 11:15:35 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S

>From 71603241c3e377a5b74c308367f066f3f9e760ae Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 7 Jan 2025 14:59:24 -0800
Subject: [PATCH 2/2] Update commit message and add comment

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 72dd3f5bca9960..602c99fe237b8e 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,6 +20,11 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
+  # We need to set `-fexceptions` here so that key
+  # unwinding functions, like
+  # _UNWIND_RaiseExcpetion, are not marked as
+  # `nounwind`, which breaks LTO builds of
+  # libunwind.  See #56825 and #120657 for context.
   COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES

___
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] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi edited 
https://github.com/llvm/llvm-project/pull/121819
___
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] Reapply "[Fuchsia][cmake] Allow using FatLTO when building runtimes" (#119252) (PR #121820)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121820


___
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] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121819

>From 9f952de3cb3e973f17121c057089a28bf4c6e5e0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 6 Jan 2025 11:15:35 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S

>From 71603241c3e377a5b74c308367f066f3f9e760ae Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 7 Jan 2025 14:59:24 -0800
Subject: [PATCH 2/2] Update commit message and add comment

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 72dd3f5bca9960..602c99fe237b8e 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,6 +20,11 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
+  # We need to set `-fexceptions` here so that key
+  # unwinding functions, like
+  # _UNWIND_RaiseExcpetion, are not marked as
+  # `nounwind`, which breaks LTO builds of
+  # libunwind.  See #56825 and #120657 for context.
   COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES

___
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] Reapply "[Fuchsia][cmake] Allow using FatLTO when building runtimes" (#119252) (PR #121820)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121820


___
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] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121819

>From 9f952de3cb3e973f17121c057089a28bf4c6e5e0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 6 Jan 2025 11:15:35 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S

>From 71603241c3e377a5b74c308367f066f3f9e760ae Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 7 Jan 2025 14:59:24 -0800
Subject: [PATCH 2/2] Update commit message and add comment

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 72dd3f5bca9960..602c99fe237b8e 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,6 +20,11 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
+  # We need to set `-fexceptions` here so that key
+  # unwinding functions, like
+  # _UNWIND_RaiseExcpetion, are not marked as
+  # `nounwind`, which breaks LTO builds of
+  # libunwind.  See #56825 and #120657 for context.
   COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES

___
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] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121819

>From 9f952de3cb3e973f17121c057089a28bf4c6e5e0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 6 Jan 2025 11:15:35 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S

>From 71603241c3e377a5b74c308367f066f3f9e760ae Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 7 Jan 2025 14:59:24 -0800
Subject: [PATCH 2/2] Update commit message and add comment

Created using spr 1.3.6-beta.1
---
 libunwind/src/CMakeLists.txt | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 72dd3f5bca9960..602c99fe237b8e 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,6 +20,11 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
+  # We need to set `-fexceptions` here so that key
+  # unwinding functions, like
+  # _UNWIND_RaiseExcpetion, are not marked as
+  # `nounwind`, which breaks LTO builds of
+  # libunwind.  See #56825 and #120657 for context.
   COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES

___
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] Reapply "[Fuchsia][cmake] Allow using FatLTO when building runtimes" (#119252) (PR #121820)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121820


___
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] Reapply "[Fuchsia][cmake] Allow using FatLTO when building runtimes" (#119252) (PR #121820)

2025-01-10 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/121820


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


  1   2   >