[compiler-rt] [openmp] [libc] [libcxx] [flang] [mlir] [llvm] [clang] [clang-tools-extra] [lld] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Fangrui Song via cfe-commits

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


[clang] [libcxx] [flang] [lld] [clang-tools-extra] [mlir] [openmp] [compiler-rt] [llvm] [libc] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/78835

>From 37b3ff263f2b46bd4541157bee5b5e1bf2639604 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sat, 20 Jan 2024 00:40:53 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 lld/ELF/LTO.cpp| 70 ++
 lld/ELF/LTO.h  |  3 +-
 lld/test/ELF/common-archive-lookup.s   |  7 ++-
 lld/test/ELF/lto/comdat-mixed-archive.test |  4 +-
 lld/test/ELF/lto/emit-asm.ll   | 13 ++--
 lld/test/ELF/lto/exclude-libs-libcall.ll   |  2 +-
 lld/test/ELF/lto/obj-path.ll   |  4 +-
 lld/test/ELF/lto/parallel-internalize.ll   |  2 +-
 lld/test/ELF/lto/parallel.ll   |  2 +-
 lld/test/ELF/lto/pseudo-probe-lto.ll   |  3 +-
 lld/test/ELF/lto/save-temps-eq.ll  | 10 ++--
 lld/test/ELF/lto/thinlto.ll| 48 +++
 12 files changed, 97 insertions(+), 71 deletions(-)

diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 504c12aac6c569..843ee59479eae9 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -12,6 +12,7 @@
 #include "SymbolTable.h"
 #include "Symbols.h"
 #include "lld/Common/Args.h"
+#include "lld/Common/CommonLinkerContext.h"
 #include "lld/Common/ErrorHandler.h"
 #include "lld/Common/Filesystem.h"
 #include "lld/Common/Strings.h"
@@ -26,6 +27,7 @@
 #include "llvm/Support/Caching.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include 
@@ -303,6 +305,7 @@ std::vector BitcodeCompiler::compile() {
   unsigned maxTasks = ltoObj->getMaxTasks();
   buf.resize(maxTasks);
   files.resize(maxTasks);
+  filenames.resize(maxTasks);
 
   // The --thinlto-cache-dir option specifies the path to a directory in which
   // to cache native object files for ThinLTO incremental builds. If a path was
@@ -313,13 +316,15 @@ std::vector BitcodeCompiler::compile() {
  [&](size_t task, const Twine ,
  std::unique_ptr mb) {
files[task] = std::move(mb);
+   filenames[task] = moduleName.str();
  }));
 
   if (!ctx.bitcodeFiles.empty())
 checkError(ltoObj->run(
 [&](size_t task, const Twine ) {
+  buf[task].first = moduleName.str();
   return std::make_unique(
-  std::make_unique(buf[task]));
+  std::make_unique(buf[task].second));
 },
 cache));
 
@@ -338,7 +343,7 @@ std::vector BitcodeCompiler::compile() {
 
   if (config->thinLTOIndexOnly) {
 if (!config->ltoObjPath.empty())
-  saveBuffer(buf[0], config->ltoObjPath);
+  saveBuffer(buf[0].second, config->ltoObjPath);
 
 // ThinLTO with index only option is required to generate only the index
 // files. After that, we exit from linker and ThinLTO backend runs in a
@@ -352,32 +357,49 @@ std::vector BitcodeCompiler::compile() {
 pruneCache(config->thinLTOCacheDir, config->thinLTOCachePolicy, files);
 
   if (!config->ltoObjPath.empty()) {
-saveBuffer(buf[0], config->ltoObjPath);
+saveBuffer(buf[0].second, config->ltoObjPath);
 for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->ltoObjPath + Twine(i));
-  }
-
-  if (config->saveTempsArgs.contains("prelink")) {
-if (!buf[0].empty())
-  saveBuffer(buf[0], config->outputFile + ".lto.o");
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i) + ".lto.o");
-  }
-
-  if (config->ltoEmitAsm) {
-saveBuffer(buf[0], config->outputFile);
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i));
-return {};
+  saveBuffer(buf[i].second, config->ltoObjPath + Twine(i));
   }
 
+  bool savePrelink = config->saveTempsArgs.contains("prelink");
   std::vector ret;
-  for (unsigned i = 0; i != maxTasks; ++i)
-if (!buf[i].empty())
-  ret.push_back(createObjFile(MemoryBufferRef(buf[i], "lto.tmp")));
+  const char *ext = config->ltoEmitAsm ? ".s" : ".o";
+  for (unsigned i = 0; i != maxTasks; ++i) {
+StringRef bitcodeFilePath;
+StringRef objBuf;
+if (files[i]) {
+  objBuf = files[i]->getBuffer();
+  bitcodeFilePath = filenames[i];
+} else {
+  objBuf = buf[i].second;
+  bitcodeFilePath = buf[i].first;
+}
+if (objBuf.empty())
+  continue;
 
-  for (std::unique_ptr  : files)
-if (file)
-  ret.push_back(createObjFile(*file));
+// If the input bitcode file is path/to/a.o and -o specifies a.out, then 
the
+// corresponding lto object file name will look something like:
+// path/to/a.out.lto.a.o.
+

[clang-tools-extra] [libcxx] [llvm] [openmp] [mlir] [compiler-rt] [flang] [clang] [libc] [lld] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Fangrui Song via cfe-commits

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


[llvm] [clang] [RISCV] Add Zicfiss support to the shadow call stack implementation. (PR #68075)

2024-01-23 Thread Jessica Clarke via cfe-commits


@@ -57,11 +57,16 @@ compiled application or the operating system. Integrating 
the runtime into
 the operating system should be preferred since otherwise all thread creation
 and destruction would need to be intercepted by the application.
 
-The instrumentation makes use of the platform register ``x18`` on AArch64 and
-``x3`` (``gp``) on RISC-V. For simplicity we will refer to this as the
-``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is
-designated as a scratch register.  This generally means that any code that may
-run on the same thread as code compiled with ShadowCallStack must either target
+The instrumentation makes use of the platform register ``x18`` on AArch64,
+``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
+hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``

jrtc27 wrote:

(Though you still have the related problem that some older LLVM may not know 
that OS version X supports it, and still default it to off)

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


[llvm] [clang] [RISCV] Add Zicfiss support to the shadow call stack implementation. (PR #68075)

2024-01-23 Thread Jessica Clarke via cfe-commits


@@ -57,11 +57,16 @@ compiled application or the operating system. Integrating 
the runtime into
 the operating system should be preferred since otherwise all thread creation
 and destruction would need to be intercepted by the application.
 
-The instrumentation makes use of the platform register ``x18`` on AArch64 and
-``x3`` (``gp``) on RISC-V. For simplicity we will refer to this as the
-``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is
-designated as a scratch register.  This generally means that any code that may
-run on the same thread as code compiled with ShadowCallStack must either target
+The instrumentation makes use of the platform register ``x18`` on AArch64,
+``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
+hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``

jrtc27 wrote:

I think it's really (non-Android) Linux that's the odd one out due to not 
having a version number in the triple?

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


[clang] [llvm] [CMake][Release] Add option for enabling PGO to release cache file. (PR #78823)

2024-01-23 Thread Tom Stellard via cfe-commits

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


[clang] f6ced35 - [CMake][Release] Add option for enabling PGO to release cache file. (#78823)

2024-01-23 Thread via cfe-commits

Author: Tom Stellard
Date: 2024-01-23T11:32:37-08:00
New Revision: f6ced3579a8c7fe1ef93e25ecf521629afa928dd

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

LOG: [CMake][Release] Add option for enabling PGO to release cache file. 
(#78823)

The option is LLVM_RELEASE_ENABLE_PGO and it's turned on by default.

-

Co-authored-by: Petr Hosek 

Added: 


Modified: 
clang/cmake/caches/Release.cmake
llvm/utils/release/test-release.sh

Removed: 




diff  --git a/clang/cmake/caches/Release.cmake 
b/clang/cmake/caches/Release.cmake
index a7b9a8d0e29f88f..1ca9138b9807311 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -4,27 +4,53 @@
 
 # General Options
 set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
+set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
 
 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 
 # Stage 1 Bootstrap Setup
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
-set(CLANG_BOOTSTRAP_TARGETS
-  clang
-  check-all
-  check-llvm
-  check-clang
-  test-suite
-  stage3
-  stage3-clang
-  stage3-check-all
-  stage3-check-llvm
-  stage3-check-clang
-  stage3-install
-  stage3-test-suite CACHE STRING "")
+if (LLVM_RELEASE_ENABLE_PGO)
+  set(CLANG_BOOTSTRAP_TARGETS
+generate-profdata
+stage2
+stage2-clang
+stage2-distribution
+stage2-install
+stage2-install-distribution
+stage2-install-distribution-toolchain
+stage2-check-all
+stage2-check-llvm
+stage2-check-clang
+stage2-test-suite CACHE STRING "")
+else()
+  set(CLANG_BOOTSTRAP_TARGETS
+clang
+check-all
+check-llvm
+check-clang
+test-suite
+stage3
+stage3-clang
+stage3-check-all
+stage3-check-llvm
+stage3-check-clang
+stage3-install
+stage3-test-suite CACHE STRING "")
+endif()
 
 # Stage 1 Options
-set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+set(STAGE1_PROJECTS "clang")
+set(STAGE1_RUNTIMES "")
+
+if (LLVM_RELEASE_ENABLE_PGO)
+  list(APPEND STAGE1_PROJECTS "lld")
+  list(APPEND STAGE1_RUNTIMES "compiler-rt")
+endif()
+
+set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "")
+set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "")
+
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
 
 # Stage 2 Bootstrap Setup
@@ -37,11 +63,26 @@ set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
 
 # Stage 2 Options
 set(STAGE2_PROJECTS "clang")
-if (LLVM_RELEASE_ENABLE_LTO)
+set(STAGE2_RUNTIMES "")
+
+if (LLVM_RELEASE_ENABLE_LTO OR LLVM_RELEASE_ENABLE_PGO)
  list(APPEND STAGE2_PROJECTS "lld")
 endif()
+
+if (LLVM_RELEASE_ENABLE_PGO)
+  set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED IR CACHE STRING "")
+  list(APPEND STAGE2_RUNTIMES "compiler-rt")
+  set(BOOTSTRAP_LLVM_ENABLE_LTO ${LLVM_RELEASE_ENABLE_LTO})
+  if (LLVM_RELEASE_ENABLE_LTO)
+set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
+  endif()
+endif()
+
 set(BOOTSTRAP_LLVM_ENABLE_PROJECTS ${STAGE2_PROJECTS} CACHE STRING "")
-set(BOOTSTRAP_LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+set(BOOTSTRAP_LLVM_ENABLE_RUNTIMES ${STAGE2_RUNTIMES} CACHE STRING "")
+if (NOT LLVM_RELEASE_ENABLE_PGO)
+  set(BOOTSTRAP_LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+endif()
 
 # Stage 3 Options
 set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")

diff  --git a/llvm/utils/release/test-release.sh 
b/llvm/utils/release/test-release.sh
index 544d4bfdd799ce8..5b1945df47d24a7 100755
--- a/llvm/utils/release/test-release.sh
+++ b/llvm/utils/release/test-release.sh
@@ -359,11 +359,11 @@ function build_with_cmake_cache() {
 $ExtraConfigureFlags
 2>&1 | tee $LogDir/llvm.configure-$Flavor.log
 
-  ${MAKE} $J_ARG $Verbose -C $CMakeBuildDir stage3-check-all \
+  ${MAKE} $J_ARG $Verbose -C $CMakeBuildDir stage2-check-all \
   2>&1 | tee $LogDir/llvm.make-$Flavor.log > $redir
 
   DESTDIR="${InstallDir}" \
-  ${MAKE} -C $CMakeBuildDir stage3-install \
+  ${MAKE} -C $CMakeBuildDir stage2-install \
   2>&1 | tee $LogDir/llvm.install-$Flavor.log > $redir
 
  mkdir -p $BuildDir/Release



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


[llvm] [clang] [RISCV] Add Zicfiss support to the shadow call stack implementation. (PR #68075)

2024-01-23 Thread Paul Kirth via cfe-commits


@@ -57,11 +57,16 @@ compiled application or the operating system. Integrating 
the runtime into
 the operating system should be preferred since otherwise all thread creation
 and destruction would need to be intercepted by the application.
 
-The instrumentation makes use of the platform register ``x18`` on AArch64 and
-``x3`` (``gp``) on RISC-V. For simplicity we will refer to this as the
-``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is
-designated as a scratch register.  This generally means that any code that may
-run on the same thread as code compiled with ShadowCallStack must either target
+The instrumentation makes use of the platform register ``x18`` on AArch64,
+``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
+hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``

ilovepi wrote:


> isn't the problem there that it's unlikely to be a decision that's in the 
> developer's hands? (because the real question is "does the OS support it?", 
> and i think that's the counter-suggestion? "decide based on the whole 
> triple", in effect, since taking Android as an example it's likely to be 
> something like "if android && riscv64 && api level >= where you can assume 
> hardware scs works".)
> 
> (apologies if this isn't what's really being talked about here --- i came in 
> very late to a long conversation :-) )

No, I think your comment is on point.

w.r.t. the diagnostic, my thoughts were that it at least makes sense to point 
out the need for the developer to double check the flags. Maybe i'm being 
overly cautious, though. 

I think using the whole triple is a good approach for platforms like Android 
and Fuchsia, where we can enable/disable certain features based on the target 
OS/SDK version. I don' think we can generalize that to other systems, but  if 
*some* systems can automagically do the right thing its better than nothing.

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


[clang] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-01-23 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/78879

>From 0719f49ecc6dd69ae4698c3e84dbf175a1bf2ed3 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sun, 21 Jan 2024 00:25:47 +
Subject: [PATCH 1/3] [CMake][PGO] Add libunwind to list of stage1 runtimes

This fixes the build since 8f90e6937a1fac80873bb2dab5f382c82ba1ba4e
which made libcxxabi use llvm's libunwind by default.
---
 clang/cmake/caches/PGO.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/cmake/caches/PGO.cmake b/clang/cmake/caches/PGO.cmake
index e1d0585e453f825..15bc755d110d19a 100644
--- a/clang/cmake/caches/PGO.cmake
+++ b/clang/cmake/caches/PGO.cmake
@@ -2,7 +2,7 @@ set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
 
 set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
-set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING 
"")
 
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
 set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED ON CACHE BOOL "")

>From 5c602233ef4e54e850f6c8a17c25968bc706b898 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sat, 6 Jan 2024 07:46:01 +
Subject: [PATCH 2/3] [CMake][PGO] Add option for using an external project to
 generate profile data.

The new CLANG_PGO_TRAINING_DATA_SOURCE_DIR allows users to specify a CMake
project to use for generating the profile data.

For example, to use the llvm-test-suite to generate profile data you
would do:

$ cmake -G Ninja -B build -S llvm -C /clang/cmake/caches/PGO.cmake \
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR= \
-DBOOTSTRAP_CLANG_PERF_TRAINING_DEPS=runtimes
---
 clang/utils/perf-training/CMakeLists.txt | 13 +++--
 clang/utils/perf-training/perf-helper.py | 16 +---
 llvm/docs/AdvancedBuilds.rst | 23 +++
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index c6d51863fb1b5c2..f9d673b2e92e775 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -1,6 +1,10 @@
+include(LLVMExternalProjectUtils)
+
 set(CLANG_PGO_TRAINING_DATA "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH
   "The path to a lit testsuite containing samples for PGO and order file 
generation"
   )
+set(CLANG_PGO_TRAINING_DATA_SOURCE_DIR OFF CACHE STRING "Path to source 
directory containing cmake project with source files to use for generating pgo 
data")
+set(CLANG_PERF_TRAINING_DEPS "" CACHE STRING "Extra dependencies needed to 
build the PGO training data.")
 
 if(LLVM_BUILD_INSTRUMENTED)
   configure_lit_site_cfg(
@@ -15,7 +19,7 @@ if(LLVM_BUILD_INSTRUMENTED)
 )
 
   add_custom_target(clear-profraw
-COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -26,9 +30,14 @@ if(LLVM_BUILD_INSTRUMENTED)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
 add_custom_target(generate-profdata
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR}
+  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
   COMMENT "Merging profdata"
   DEPENDS generate-profraw)
+if (CLANG_PGO_TRAINING_DATA_SOURCE_DIR)
+  llvm_ExternalProject_Add(generate-profraw-external 
${CLANG_PGO_TRAINING_DATA_SOURCE_DIR}
+  USE_TOOLCHAIN EXLUDE_FROM_ALL NO_INSTALL DEPENDS 
generate-profraw)
+  add_dependencies(generate-profdata generate-profraw-external)
+endif()
   endif()
 endif()
 
diff --git a/clang/utils/perf-training/perf-helper.py 
b/clang/utils/perf-training/perf-helper.py
index 99d6ab6ef08..844aa274f049aaa 100644
--- a/clang/utils/perf-training/perf-helper.py
+++ b/clang/utils/perf-training/perf-helper.py
@@ -30,26 +30,28 @@ def findFilesWithExtension(path, extension):
 
 
 def clean(args):
-if len(args) != 2:
+if len(args) < 2:
 print(
-"Usage: %s clean  \n" % __file__
+"Usage: %s clean  \n" % __file__
 + "\tRemoves all files with extension from ."
 )
 return 1
-for filename in findFilesWithExtension(args[0], args[1]):
-os.remove(filename)
+for path in args[1:-1]:
+for filename in findFilesWithExtension(path, args[-1]):
+os.remove(filename)
 return 0
 
 
 def 

[libcxx] [llvm] [openmp] [mlir] [compiler-rt] [clang] [lld] [HEXAGON] Inlining Division (PR #79021)

2024-01-23 Thread via cfe-commits

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

It looks good to me.

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


[clang] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-01-23 Thread Tom Stellard via cfe-commits


@@ -15,7 +19,7 @@ if(LLVM_BUILD_INSTRUMENTED)
 )

tstellar wrote:

@petrhosek CLANG_PERF_TRAINING_DEPS was an existing variable that's used here.  
I think it was meant to be added to cache files, but I added it to 
CMakeLists.txt file here so that it could be passed on the command line without 
modifying the cache files.

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


[libc] [libcxxabi] [clang-tools-extra] [openmp] [mlir] [clang] [flang] [compiler-rt] [libcxx] [llvm] [AArch64] Combine store (trunc X to <3 x i8>) to sequence of ST1.b. (PR #78637)

2024-01-23 Thread Eli Friedman via cfe-commits


@@ -21471,6 +21471,57 @@ bool isHalvingTruncateOfLegalScalableType(EVT SrcVT, 
EVT DstVT) {
  (SrcVT == MVT::nxv2i64 && DstVT == MVT::nxv2i32);
 }
 
+// Combine store (trunc X to <3 x i8>) to sequence of ST1.b.
+static SDValue combineI8TruncStore(StoreSDNode *ST, SelectionDAG ,
+   const AArch64Subtarget *Subtarget) {
+  SDValue Value = ST->getValue();
+  EVT ValueVT = Value.getValueType();
+
+  if (ST->isVolatile() || !Subtarget->isLittleEndian() ||
+  ST->getOriginalAlign() >= 4 || Value.getOpcode() != ISD::TRUNCATE ||

efriedma-quic wrote:

What is `ST->getOriginalAlign() >= 4` protecting against?  Increasing the known 
alignment of the pointer doesn't change the generated code, as far as I can 
tell.



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


[mlir] [flang] [openmp] [libcxxabi] [libcxx] [compiler-rt] [libc] [llvm] [clang] [clang-tools-extra] [AArch64] Combine store (trunc X to <3 x i8>) to sequence of ST1.b. (PR #78637)

2024-01-23 Thread Eli Friedman via cfe-commits


@@ -21471,6 +21471,57 @@ bool isHalvingTruncateOfLegalScalableType(EVT SrcVT, 
EVT DstVT) {
  (SrcVT == MVT::nxv2i64 && DstVT == MVT::nxv2i32);
 }
 
+// Combine store (trunc X to <3 x i8>) to sequence of ST1.b.
+static SDValue combineI8TruncStore(StoreSDNode *ST, SelectionDAG ,
+   const AArch64Subtarget *Subtarget) {
+  SDValue Value = ST->getValue();
+  EVT ValueVT = Value.getValueType();
+
+  if (ST->isVolatile() || !Subtarget->isLittleEndian() ||
+  ST->getOriginalAlign() >= 4 || Value.getOpcode() != ISD::TRUNCATE ||
+  ValueVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3))
+return SDValue();
+
+  assert(ST->getOffset().isUndef() && "undef offset expected");
+  SDLoc DL(ST);
+  auto WideVT = EVT::getVectorVT(
+  *DAG.getContext(),
+  Value->getOperand(0).getValueType().getVectorElementType(), 4);
+  SDValue UndefVector = DAG.getUNDEF(WideVT);
+  SDValue WideTrunc = DAG.getNode(
+  ISD::INSERT_SUBVECTOR, DL, WideVT,
+  {UndefVector, Value->getOperand(0), DAG.getVectorIdxConstant(0, DL)});
+  SDValue Cast = DAG.getNode(
+  ISD::BITCAST, DL, WideVT.getSizeInBits() == 64 ? MVT::v8i8 : MVT::v16i8,
+  WideTrunc);
+
+  unsigned IdxScale = WideVT.getScalarSizeInBits() / 8;

efriedma-quic wrote:

Instead of writing this out, can we just use 
TargetLowering::scalarizeVectorStore?  I think it does roughly the same thing.

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


[libcxxabi] [clang] [openmp] [libc] [clang-tools-extra] [mlir] [flang] [compiler-rt] [libcxx] [llvm] [AArch64] Combine store (trunc X to <3 x i8>) to sequence of ST1.b. (PR #78637)

2024-01-23 Thread Eli Friedman via cfe-commits


@@ -281,23 +279,19 @@ entry:
 define void @store_trunc_add_from_64bits(ptr %src, ptr %dst) {
 ; CHECK-LABEL: store_trunc_add_from_64bits:
 ; CHECK:   ; %bb.0: ; %entry
-; CHECK-NEXT:sub sp, sp, #16
-; CHECK-NEXT:.cfi_def_cfa_offset 16
 ; CHECK-NEXT:ldr s0, [x0]
 ; CHECK-NEXT:add x9, x0, #4
 ; CHECK-NEXT:  Lloh0:
 ; CHECK-NEXT:adrp x8, lCPI7_0@PAGE
 ; CHECK-NEXT:  Lloh1:
 ; CHECK-NEXT:ldr d1, [x8, lCPI7_0@PAGEOFF]
+; CHECK-NEXT:add x8, x1, #1
 ; CHECK-NEXT:ld1.h { v0 }[2], [x9]
+; CHECK-NEXT:add x9, x1, #2
 ; CHECK-NEXT:add.4h v0, v0, v1
-; CHECK-NEXT:xtn.8b v1, v0
-; CHECK-NEXT:umov.h w8, v0[2]
-; CHECK-NEXT:str s1, [sp, #12]
-; CHECK-NEXT:ldrh w9, [sp, #12]

efriedma-quic wrote:

Spent a little time looking at why the default code is so horrible; the primary 
issue is actually the way the legalizer (GenWidenVectorStores) is trying to 
lower the operation into an i16 store followed by an i8 store. It ends up 
generating a bitcast from v4i8 to v2i16, and the default handling for that is 
completely terrible (it doesn't know how to use a shuffle, so it goes through a 
stack temporary).

Maybe worth looking into improving the bitcast situation if you're going to 
continue looking at very narrow vector types.

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


[clang] [llvm] [RISCV] Add Zicfiss support to the shadow call stack implementation. (PR #68075)

2024-01-23 Thread via cfe-commits


@@ -57,11 +57,16 @@ compiled application or the operating system. Integrating 
the runtime into
 the operating system should be preferred since otherwise all thread creation
 and destruction would need to be intercepted by the application.
 
-The instrumentation makes use of the platform register ``x18`` on AArch64 and
-``x3`` (``gp``) on RISC-V. For simplicity we will refer to this as the
-``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is
-designated as a scratch register.  This generally means that any code that may
-run on the same thread as code compiled with ShadowCallStack must either target
+The instrumentation makes use of the platform register ``x18`` on AArch64,
+``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
+hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``

enh-google wrote:

> Related: what are our thoughts about a frontend warning/diagnostic when the 
> mcpu supports the feature, but hasn't been selected?

isn't the problem there that it's unlikely to be a decision that's in the 
developer's hands? (because the real question is "does the OS support it?", and 
i think that's the counter-suggestion? "decide based on the whole triple", in 
effect, since taking Android as an example it's likely to be something like "if 
android && riscv64 && api level >= where you can assume hardware scs works".)

(apologies if this isn't what's really being talked about here --- i came in 
very late to a long conversation :-) )

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


[clang] [compiler-rt] [NFC] Size and element numbers are often swapped when calling calloc (PR #79081)

2024-01-23 Thread Florian Mayer via cfe-commits

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


[clang] 3c20e25 - [NFC] Size and element numbers are often swapped when calling calloc (#79081)

2024-01-23 Thread via cfe-commits

Author: AtariDreams
Date: 2024-01-23T11:13:55-08:00
New Revision: 3c20e25b0c51c67e35d028ba0d1d5f1dd5e206bb

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

LOG: [NFC] Size and element numbers are often swapped when calling calloc 
(#79081)

gcc-14 will now throw a warning if size and elements are swapped.

Added: 


Modified: 
clang/test/Analysis/malloc.mm
clang/test/Analysis/uninit-vals.m
clang/test/CodeGen/alloc-size.c
compiler-rt/lib/profile/InstrProfilingFile.c
compiler-rt/test/tsan/java_finalizer2.cpp

Removed: 




diff  --git a/clang/test/Analysis/malloc.mm b/clang/test/Analysis/malloc.mm
index 9c0f013c4df88a..94a46d731090b3 100644
--- a/clang/test/Analysis/malloc.mm
+++ b/clang/test/Analysis/malloc.mm
@@ -116,17 +116,17 @@ void testUseAfterFree() {
 }
 
 void testNoCopy() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData somethingNoCopy:p]; // no-warning
 }
 
 void testFreeWhenDone() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData something:p freeWhenDone:1]; // no-warning
 }
 
 void testFreeWhenDonePositive() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData something:p freeWhenDone:0]; // 
expected-warning{{leak}}
 }
 

diff  --git a/clang/test/Analysis/uninit-vals.m 
b/clang/test/Analysis/uninit-vals.m
index 9d18f0ef69b927..a6ec4fb74e128f 100644
--- a/clang/test/Analysis/uninit-vals.m
+++ b/clang/test/Analysis/uninit-vals.m
@@ -158,7 +158,7 @@ Point makePoint(float x, float y) {
 }
 
 void PR14765_test(void) {
-  Circle *testObj = calloc(sizeof(Circle), 1);
+  Circle *testObj = calloc(1, sizeof(Circle));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
@@ -207,7 +207,7 @@ IntPoint makeIntPoint(int x, int y) {
 }
 
 void PR14765_test_int(void) {
-  IntCircle *testObj = calloc(sizeof(IntCircle), 1);
+  IntCircle *testObj = calloc(1, sizeof(IntCircle));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
@@ -311,7 +311,7 @@ void testLargeStructsNotCopiedPerField(void) {
 }
 
 void testSmallStructInLargerStruct(void) {
-  IntCircle2D *testObj = calloc(sizeof(IntCircle2D), 1);
+  IntCircle2D *testObj = calloc(1, sizeof(IntCircle2D));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}

diff  --git a/clang/test/CodeGen/alloc-size.c b/clang/test/CodeGen/alloc-size.c
index 370f61058c4937..bbac7965521b6e 100644
--- a/clang/test/CodeGen/alloc-size.c
+++ b/clang/test/CodeGen/alloc-size.c
@@ -137,7 +137,7 @@ void test5(void) {
   // CHECK: store i32 36
   gi = OBJECT_SIZE_BUILTIN(>t[1], 3);
 
-  struct Data *const arr = my_calloc(sizeof(*data), 2);
+  struct Data *const arr = my_calloc(2, sizeof(*data));
   // CHECK: store i32 96
   gi = OBJECT_SIZE_BUILTIN(arr, 0);
   // CHECK: store i32 96
@@ -171,7 +171,7 @@ void test6(void) {
   // CHECK: store i32 11
   gi = OBJECT_SIZE_BUILTIN(data->end, 3);
 
-  struct Data *const arr = my_calloc(sizeof(*arr) + 5, 3);
+  struct Data *const arr = my_calloc(3, sizeof(*arr) + 5);
   // AFAICT, GCC treats malloc and calloc identically. So, we should do the
   // same.
   //

diff  --git a/compiler-rt/lib/profile/InstrProfilingFile.c 
b/compiler-rt/lib/profile/InstrProfilingFile.c
index e72a2ba86f5466..867ae73f0d3b27 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -335,10 +335,10 @@ static void initFileWriter(ProfDataWriter *This, FILE 
*File) {
 COMPILER_RT_VISIBILITY ProfBufferIO *
 lprofCreateBufferIOInternal(void *File, uint32_t BufferSz) {
   FreeHook = 
-  DynamicBufferIOBuffer = (uint8_t *)calloc(BufferSz, 1);
+  DynamicBufferIOBuffer = (uint8_t *)calloc(1, BufferSz);
   VPBufferSize = BufferSz;
   ProfDataWriter *fileWriter =
-  (ProfDataWriter *)calloc(sizeof(ProfDataWriter), 1);
+  (ProfDataWriter *)calloc(1, sizeof(ProfDataWriter));
   initFileWriter(fileWriter, File);
   ProfBufferIO *IO = lprofCreateBufferIO(fileWriter);
   IO->OwnFileWriter = 1;

diff  --git a/compiler-rt/test/tsan/java_finalizer2.cpp 
b/compiler-rt/test/tsan/java_finalizer2.cpp
index 87528900541a84..0d677be2ba1a0b 100644
--- a/compiler-rt/test/tsan/java_finalizer2.cpp
+++ b/compiler-rt/test/tsan/java_finalizer2.cpp
@@ -51,7 +51,7 @@ void *Ballast(void *p) {
 }
 
 int main() {
-  Heap* heap = (Heap*)calloc(sizeof(Heap), 2) + 1;
+  Heap *heap = (Heap *)calloc(2, sizeof(Heap)) + 

[clang] [llvm] Use unaligned atomic load and stores on x86 (PR #79191)

2024-01-23 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/79191

>From c12e481e0a375d58e0d09df0e0e3b80321c2055d Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 13:59:05 -0500
Subject: [PATCH] Use unaligned atomic load and stores on x86

The backend supports it now, so we can use it.
---
 clang/lib/CodeGen/CGObjC.cpp| 5 +++--
 llvm/lib/Target/X86/X86ISelLowering.cpp | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 03fc0ec7ff54e1c..debfc84f49e4848 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -846,8 +846,9 @@ static void emitStructGetterCall(CodeGenFunction , 
ObjCIvarDecl *ivar,
 /// accesses.  They don't have to be fast, just faster than a function
 /// call and a mutex.
 static bool hasUnalignedAtomics(llvm::Triple::ArchType arch) {
-  // FIXME: Allow unaligned atomic load/store on x86.  (It is not
-  // currently supported by the backend.)
+  // x86 is the only one so far that we know support this as of now
+  if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
+return true;
   return false;
 }
 
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index e158312caffdec7..9b5128cc1361147 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -107,6 +107,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine 
,
 setSchedulingPreference(Sched::RegPressure);
   const X86RegisterInfo *RegInfo = Subtarget.getRegisterInfo();
   setStackPointerRegisterToSaveRestore(RegInfo->getStackRegister());
+  setSupportsUnalignedAtomics(true);
 
   // Bypass expensive divides and use cheaper ones.
   if (TM.getOptLevel() >= CodeGenOptLevel::Default) {

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


[clang] [llvm] Use unaligned atomic load and stores on x86 (PR #79191)

2024-01-23 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/79191

>From 4716a62d936ee174b6ffd0a4a7f9f7fbc5f2ae0f Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 13:59:05 -0500
Subject: [PATCH] Use unaligned atomic load and stores on x86

The backend supports it now, so we can use it.
---
 clang/lib/CodeGen/CGObjC.cpp| 5 +++--
 llvm/lib/Target/X86/X86ISelLowering.cpp | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 03fc0ec7ff54e1..debfc84f49e484 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -846,8 +846,9 @@ static void emitStructGetterCall(CodeGenFunction , 
ObjCIvarDecl *ivar,
 /// accesses.  They don't have to be fast, just faster than a function
 /// call and a mutex.
 static bool hasUnalignedAtomics(llvm::Triple::ArchType arch) {
-  // FIXME: Allow unaligned atomic load/store on x86.  (It is not
-  // currently supported by the backend.)
+  // x86 is the only one so far that we know support this as of now
+  if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
+return true;
   return false;
 }
 
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index e158312caffdec..9b5128cc136114 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -107,6 +107,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine 
,
 setSchedulingPreference(Sched::RegPressure);
   const X86RegisterInfo *RegInfo = Subtarget.getRegisterInfo();
   setStackPointerRegisterToSaveRestore(RegInfo->getStackRegister());
+  setSupportsUnalignedAtomics(true);
 
   // Bypass expensive divides and use cheaper ones.
   if (TM.getOptLevel() >= CodeGenOptLevel::Default) {

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


[clang] Use unaligned atomic load and stores on x86 (PR #79191)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)


Changes

The backend supports it now, so we can use it.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGObjC.cpp (+3-2) 


``diff
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 03fc0ec7ff54e1c..debfc84f49e4848 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -846,8 +846,9 @@ static void emitStructGetterCall(CodeGenFunction , 
ObjCIvarDecl *ivar,
 /// accesses.  They don't have to be fast, just faster than a function
 /// call and a mutex.
 static bool hasUnalignedAtomics(llvm::Triple::ArchType arch) {
-  // FIXME: Allow unaligned atomic load/store on x86.  (It is not
-  // currently supported by the backend.)
+  // x86 is the only one so far that we know support this as of now
+  if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
+return true;
   return false;
 }
 

``




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


[clang] Use unaligned atomic load and stores on x86 (PR #79191)

2024-01-23 Thread via cfe-commits

https://github.com/AtariDreams created 
https://github.com/llvm/llvm-project/pull/79191

The backend supports it now, so we can use it.

>From de9497dcfee7c3f49f7729f75bf2714b6059617d Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 13:59:05 -0500
Subject: [PATCH] Use unaligned atomic load and stores on x86

The backend supports it now, so we can use it.
---
 clang/lib/CodeGen/CGObjC.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 03fc0ec7ff54e1..debfc84f49e484 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -846,8 +846,9 @@ static void emitStructGetterCall(CodeGenFunction , 
ObjCIvarDecl *ivar,
 /// accesses.  They don't have to be fast, just faster than a function
 /// call and a mutex.
 static bool hasUnalignedAtomics(llvm::Triple::ArchType arch) {
-  // FIXME: Allow unaligned atomic load/store on x86.  (It is not
-  // currently supported by the backend.)
+  // x86 is the only one so far that we know support this as of now
+  if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
+return true;
   return false;
 }
 

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


[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2024-01-23 Thread David Goldman via cfe-commits


@@ -893,22 +964,36 @@ llvm::Expected buildRenameEdit(llvm::StringRef 
AbsFilePath,
 return LastOffset;
   };
 
-  std::vector> OccurrencesOffsets;
-  for (const auto  : Occurrences) {
-auto StartOffset = Offset(R.start);
-if (!StartOffset)
-  return StartOffset.takeError();
-auto EndOffset = Offset(R.end);
-if (!EndOffset)
-  return EndOffset.takeError();
-OccurrencesOffsets.push_back({*StartOffset, *EndOffset});
+  struct OccurrenceOffset {
+size_t Start;
+size_t End;
+llvm::StringRef NewName;
+
+OccurrenceOffset(size_t Start, size_t End, llvm::StringRef NewName) :
+  Start(Start), End(End), NewName(NewName) {}
+  };
+
+  std::vector OccurrencesOffsets;
+  for (const auto  : Occurrences) {
+for (auto It = SR.Ranges.begin(); It != SR.Ranges.end(); ++It) {

DavidGoldman wrote:

Done

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


[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2024-01-23 Thread David Goldman via cfe-commits

https://github.com/DavidGoldman updated 
https://github.com/llvm/llvm-project/pull/76466

>From 4caf5b3c779bf18236b4b0be5bc7147d10339f2b Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 15:59:01 -0500
Subject: [PATCH 1/4] [clangd][SymbolCollector] Treat ObjC methods as spelled

We'll treat multi-arg methods as spelled once we have full rename
support for them.
---
 .../clangd/index/SymbolCollector.cpp  |  6 ++-
 .../clangd/unittests/SymbolCollectorTests.cpp | 42 +++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 7ef4b15febad22f..336bc3506bb3608 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -174,7 +174,9 @@ bool isSpelled(SourceLocation Loc, const NamedDecl ) {
   auto Name = ND.getDeclName();
   const auto NameKind = Name.getNameKind();
   if (NameKind != DeclarationName::Identifier &&
-  NameKind != DeclarationName::CXXConstructorName)
+  NameKind != DeclarationName::CXXConstructorName &&
+  NameKind != DeclarationName::ObjCZeroArgSelector &&
+  NameKind != DeclarationName::ObjCOneArgSelector)
 return false;
   const auto  = ND.getASTContext();
   const auto  = AST.getSourceManager();
@@ -183,6 +185,8 @@ bool isSpelled(SourceLocation Loc, const NamedDecl ) {
   if (clang::Lexer::getRawToken(Loc, Tok, SM, LO))
 return false;
   auto StrName = Name.getAsString();
+  if (const auto *MD = dyn_cast())
+StrName = MD->getSelector().getNameForSlot(0).str();
   return clang::Lexer::getSpelling(Tok, SM, LO) == StrName;
 }
 } // namespace
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 9cdc57ec01f3276..1d4e1c1d75ea230 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -105,6 +105,9 @@ MATCHER(refRange, "") {
 MATCHER_P2(OverriddenBy, Subject, Object, "") {
   return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID};
 }
+MATCHER(isSpelled, "") {
+  return static_cast(arg.Kind & RefKind::Spelled);
+}
 ::testing::Matcher &>
 haveRanges(const std::vector Ranges) {
   return ::testing::UnorderedPointwise(refRange(), Ranges);
@@ -524,6 +527,45 @@ TEST_F(SymbolCollectorTest, templateArgs) {
  forCodeCompletion(false);
 }
 
+TEST_F(SymbolCollectorTest, ObjCRefs) {
+  Annotations Header(R"(
+  @interface Person
+  - (void)$talk[[talk]];
+  - (void)$say[[say]]:(id)something;
+  @end
+  @interface Person (Category)
+  - (void)categoryMethod;
+  - (void)multiArg:(id)a method:(id)b;
+  @end
+  )");
+  Annotations Main(R"(
+  @implementation Person
+  - (void)$talk[[talk]] {}
+  - (void)$say[[say]]:(id)something {}
+  @end
+
+  void fff(Person *p) {
+[p $talk[[talk]]];
+[p $say[[say]]:0];
+[p categoryMethod];
+[p multiArg:0 method:0];
+  }
+  )");
+  CollectorOpts.RefFilter = RefKind::All;
+  CollectorOpts.CollectMainFileRefs = true;
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header.code(), Main.code(),
+ {"-fblocks", "-xobjective-c++", "-Wno-objc-root-class"});
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::talk").ID,
+  haveRanges(Main.ranges("talk");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
+  haveRanges(Main.ranges("say");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::categoryMethod").ID,
+  ElementsAre(isSpelled();
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::multiArg:method:").ID,
+  ElementsAre(Not(isSpelled());
+}
+
 TEST_F(SymbolCollectorTest, ObjCSymbols) {
   const std::string Header = R"(
 @interface Person

>From 1b6a09464ff5c7b1988fcb479d0a4ff876f696e6 Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 16:12:03 -0500
Subject: [PATCH 2/4] Run clang-format

---
 .../clangd/unittests/SymbolCollectorTests.cpp  | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 1d4e1c1d75ea230..5c20b950e4eac0d 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -560,10 +560,12 @@ TEST_F(SymbolCollectorTest, ObjCRefs) {
   haveRanges(Main.ranges("talk");
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
   haveRanges(Main.ranges("say");
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 

[clang] [llvm] [RISCV] Add Zicfiss support to the shadow call stack implementation. (PR #68075)

2024-01-23 Thread Paul Kirth via cfe-commits


@@ -57,11 +57,16 @@ compiled application or the operating system. Integrating 
the runtime into
 the operating system should be preferred since otherwise all thread creation
 and destruction would need to be intercepted by the application.
 
-The instrumentation makes use of the platform register ``x18`` on AArch64 and
-``x3`` (``gp``) on RISC-V. For simplicity we will refer to this as the
-``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is
-designated as a scratch register.  This generally means that any code that may
-run on the same thread as code compiled with ShadowCallStack must either target
+The instrumentation makes use of the platform register ``x18`` on AArch64,
+``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
+hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``

ilovepi wrote:

I guess I'm in the minority here in thinking that the compiler should pick 
based on the HW capabilities.  I think I'd be surprised if I was compiling w/ 
SCS on HW that supported it and got the software SCS... but at the end of the 
day, as long as we document the usage clearly its probably fine. I acknowledge 
the concern about falling back to a less secure method, but it still feels like 
the wrong tradeoff to me. That said, if there's a consensus that the other way 
makes more sense(which there seems to be), then I'm 100% fine with that. 

Related: what are our thoughts about a frontend warning/diagnostic when the 
mcpu supports the feature, but hasn't been selected?

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


[clang-tools-extra] [include-cleaner] Check emptiness instead of occurences (PR #79154)

2024-01-23 Thread Haojian Wu via cfe-commits

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


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


[clang] [clang-tools-extra] [llvm] Add STACK_SIZES section for MachOS. (PR #77106)

2024-01-23 Thread via cfe-commits

shamithoke wrote:

Ping

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


[flang] [clang] [flang][driver] Rename `flang-new` as `flang` (PR #74377)

2024-01-23 Thread Brad Richardson via cfe-commits

everythingfunctional wrote:

Not that it's the end of the world if this doesn't get in before the this 
release, but @sscalpone , exactly what feedback are we wanting before merging?

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


[clang] [Modules] [HeaderSearch] Don't reenter headers if it is pragma once (PR #76119)

2024-01-23 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

So far the testing shows there are no regressions.

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


[clang-tools-extra] [llvm] [clang] [X86] Use RORX over SHR imm (PR #77964)

2024-01-23 Thread Bryce Wilson via cfe-commits

https://github.com/Bryce-MW updated 
https://github.com/llvm/llvm-project/pull/77964

>From d4c312b9dbf447d0a53dda0e6cdc482bd908430b Mon Sep 17 00:00:00 2001
From: Bryce Wilson 
Date: Fri, 12 Jan 2024 16:01:32 -0600
Subject: [PATCH 01/11] [X86] Use RORX over SHR imm

---
 llvm/lib/Target/X86/X86InstrShiftRotate.td |  78 ++
 llvm/test/CodeGen/X86/atomic-unordered.ll  |   3 +-
 llvm/test/CodeGen/X86/bmi2.ll  |   6 +-
 llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll  |   3 +-
 llvm/test/CodeGen/X86/pr35636.ll   |   4 +-
 llvm/test/CodeGen/X86/vector-trunc-ssat.ll | 116 ++---
 6 files changed, 143 insertions(+), 67 deletions(-)

diff --git a/llvm/lib/Target/X86/X86InstrShiftRotate.td 
b/llvm/lib/Target/X86/X86InstrShiftRotate.td
index f951894db1890cd..238e8e9b6e97f30 100644
--- a/llvm/lib/Target/X86/X86InstrShiftRotate.td
+++ b/llvm/lib/Target/X86/X86InstrShiftRotate.td
@@ -879,6 +879,26 @@ let Predicates = [HasBMI2, HasEGPR, In64BitMode] in {
   defm SHLX64 : bmi_shift<"shlx{q}", GR64, i64mem, "_EVEX">, T8, PD, REX_W, 
EVEX;
 }
 
+
+def immle16_8 : ImmLeaf;
+def immle32_8 : ImmLeaf;
+def immle64_8 : ImmLeaf;
+def immle32_16 : ImmLeaf;
+def immle64_16 : ImmLeaf;
+def immle64_32 : ImmLeaf;
+
 let Predicates = [HasBMI2] in {
   // Prefer RORX which is non-destructive and doesn't update EFLAGS.
   let AddedComplexity = 10 in {
@@ -891,6 +911,64 @@ let Predicates = [HasBMI2] in {
   (RORX32ri GR32:$src, (ROT32L2R_imm8 imm:$shamt))>;
 def : Pat<(rotl GR64:$src, (i8 imm:$shamt)),
   (RORX64ri GR64:$src, (ROT64L2R_imm8 imm:$shamt))>;
+
+// A right shift by less than a smaller register size that is then
+// truncated to that register size can be replaced by RORX to
+// preserve flags with the same execution cost
+
+def : Pat<(i8 (trunc (srl GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc (srl GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+def : Pat<(i32 (trunc (sra GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+
+
+// Can't expand the load
+def : Pat<(i8 (trunc (srl (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc 

[clang-tools-extra] [llvm] [clang] [libc] [libcxx] [compiler-rt] [flang] [clang][FatLTO] Avoid UnifiedLTO until it can support WPD/CFI (PR #79061)

2024-01-23 Thread Paul Kirth via cfe-commits

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

>From 2e0cd6077a756fa28023d907045e6e53c50ec732 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 22 Jan 2024 21:48:16 +
Subject: [PATCH 1/4] =?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.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  9 ++--
 clang/lib/Driver/ToolChains/Clang.cpp |  4 +-
 clang/lib/Frontend/CompilerInvocation.cpp | 14 ---
 clang/test/CodeGen/fat-lto-objects.c  | 42 +--
 clang/test/Driver/fat-lto-objects.c   | 12 --
 llvm/docs/FatLTO.rst  |  4 +-
 llvm/include/llvm/Passes/PassBuilder.h|  3 +-
 .../llvm/Transforms/IPO/EmbedBitcodePass.h| 16 ++-
 llvm/lib/Passes/PassBuilder.cpp   | 20 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 37 +---
 llvm/lib/Passes/PassRegistry.def  |  5 ++-
 llvm/lib/Transforms/IPO/EmbedBitcodePass.cpp  | 12 +-
 llvm/test/CodeGen/X86/fat-lto-section.ll  |  2 +-
 llvm/test/Transforms/EmbedBitcode/embed.ll|  3 ++
 14 files changed, 107 insertions(+), 76 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a6142d99f3b688d..9369c8828231421 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1001,8 +1001,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
 
 if (CodeGenOpts.FatLTO) {
-  assert(CodeGenOpts.UnifiedLTO && "FatLTO requires UnifiedLTO");
-  MPM.addPass(PB.buildFatLTODefaultPipeline(Level));
+  MPM.addPass(PB.buildFatLTODefaultPipeline(
+  Level, PrepareForThinLTO,
+  PrepareForThinLTO || shouldEmitRegularLTOSummary()));
 } else if (PrepareForThinLTO) {
   MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
 } else if (PrepareForLTO) {
@@ -1046,6 +1047,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
 /*EmitLTOSummary=*/true));
   }
+
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
@@ -1073,8 +1075,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
   TheModule->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
uint32_t(CodeGenOpts.EnableSplitLTOUnit));
-// FatLTO always means UnifiedLTO
-if (!TheModule->getModuleFlag("UnifiedLTO"))
+if (CodeGenOpts.UnifiedLTO && !TheModule->getModuleFlag("UnifiedLTO"))
   TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
   }
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2f33943de45c5da..928dca653dabdc1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4854,9 +4854,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   bool UnifiedLTO = false;
   if (IsUsingLTO) {
 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
-  options::OPT_fno_unified_lto, Triple.isPS()) ||
- Args.hasFlag(options::OPT_ffat_lto_objects,
-  options::OPT_fno_fat_lto_objects, false);
+  options::OPT_fno_unified_lto, Triple.isPS());
 if (UnifiedLTO)
   CmdArgs.push_back("-funified-lto");
   }
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 7edea7798af1ef0..feb4de2084b830b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1861,20 +1861,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
, ArgList ,
 if (Args.hasArg(OPT_funified_lto))
   Opts.PrepareForThinLTO = true;
   }
-  if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects,
-   options::OPT_fno_fat_lto_objects)) {
-if (A->getOption().matches(options::OPT_ffat_lto_objects)) {
-  if (Arg *Uni = Args.getLastArg(options::OPT_funified_lto,
- options::OPT_fno_unified_lto)) {
-if (Uni->getOption().matches(options::OPT_fno_unified_lto))
-  Diags.Report(diag::err_drv_incompatible_options)
-  << A->getAsString(Args) << "-fno-unified-lto";
-  } else
-Diags.Report(diag::err_drv_argument_only_allowed_with)
-<< A->getAsString(Args) << "-funified-lto";
-}
-  }
-
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != Language::LLVM_IR)
   Diags.Report(diag::err_drv_argument_only_allowed_with)
diff --git 

[clang] [test] Avoid libc dep in Update warn-unsafe-buffer-usage-warning-data… (PR #79183)

2024-01-23 Thread Augie Fackler via cfe-commits

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


[clang] 5a7d68c - [test] Avoid libc dep in Update warn-unsafe-buffer-usage-warning-data… (#79183)

2024-01-23 Thread via cfe-commits

Author: Danial Klimkin
Date: 2024-01-23T13:14:57-05:00
New Revision: 5a7d68c8c4b13aea9922c860e56f6c6cdc223d87

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

LOG: [test] Avoid libc dep in Update warn-unsafe-buffer-usage-warning-data… 
(#79183)

Avoid libc dep in warn-unsafe-buffer-usage-warning-data-invocation.

To keep the test hermetic. This is in line with other existing
declarations in the file that avoid includes.

Added: 


Modified: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp

Removed: 




diff  --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
index 574afcd0eb6dce3..5c9df12513e521a 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
@@ -7,7 +7,6 @@
 // RUN: %clang_cc1 -std=c++20 -fblocks -include %s %s 2>&1 | FileCheck 
--allow-empty %s
 // CHECK-NOT: [-Wunsafe-buffer-usage]
 
-#include 
 #ifndef INCLUDED
 #define INCLUDED
 #pragma clang system_header
@@ -15,6 +14,8 @@
 // no spanification warnings for system headers
 #else
 
+typedef __INTPTR_TYPE__ intptr_t;
+
 namespace std {
   class type_info;
   class bad_cast;



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


[llvm] [clang] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -1307,6 +1309,13 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zaamo0p1 -x c -E -dM %s \

topperc wrote:

It's not working. It failed the automated testing

```
clang: error: invalid arch name 'rv32i_zaamo0p1', unsupported version number 
0.1 for experimental extension 'zaamo' (this compiler supports 0.2)
```

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

apolloww wrote:

We saw a huge build speed regression from internal codebase when migrating to 
clang-17 triggered by this issue. The search for the same `UsingType` always 
ends up with "not found" and the folding set `UsingTypes` contains lots of 
duplicated notes.  

This is a quick fix I come up with. Feel free to propose a better one because I 
don't work in clang front end often. If it looks good, I'll try to add a test 
case.   

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


[clang] [test] Avoid libc dep in Update warn-unsafe-buffer-usage-warning-data… (PR #79183)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Danial Klimkin (dklimkin)


Changes

Avoid libc dep in warn-unsafe-buffer-usage-warning-data-invocation.

To keep the test hermetic. This is in line with other existing declarations in 
the file that avoid includes.

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


1 Files Affected:

- (modified) 
clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp (+2-1) 


``diff
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
index 574afcd0eb6dce3..5c9df12513e521a 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
@@ -7,7 +7,6 @@
 // RUN: %clang_cc1 -std=c++20 -fblocks -include %s %s 2>&1 | FileCheck 
--allow-empty %s
 // CHECK-NOT: [-Wunsafe-buffer-usage]
 
-#include 
 #ifndef INCLUDED
 #define INCLUDED
 #pragma clang system_header
@@ -15,6 +14,8 @@
 // no spanification warnings for system headers
 #else
 
+typedef __INTPTR_TYPE__ intptr_t;
+
 namespace std {
   class type_info;
   class bad_cast;

``




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


[llvm] [clang] [clang-tools-extra] [X86] Use RORX over SHR imm (PR #77964)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -4212,6 +4213,96 @@ MachineSDNode *X86DAGToDAGISel::emitPCMPESTR(unsigned 
ROpc, unsigned MOpc,
   return CNode;
 }
 
+// When the consumer of a right shift (arithmetic or logical) wouldn't notice
+// the difference if the instruction was a rotate right instead (because the
+// bits shifted in are truncated away), the shift can be replaced by the RORX
+// instruction from BMI2. This doesn't set flags and can output to a different
+// register. However, this increases code size in most cases, and doesn't leave
+// the high bits in a useful state. There may be other situations where this
+// transformation is profitable given those conditions, but currently the
+// transformation is only made when it likely avoids spilling flags.
+bool X86DAGToDAGISel::rightShiftUncloberFlags(SDNode *N) {
+  EVT VT = N->getValueType(0);
+
+  // Target has to have BMI2 for RORX
+  if (!Subtarget->hasBMI2())
+return false;
+
+  // Only handle scalar shifts.
+  if (VT.isVector())
+return false;
+
+  unsigned OpSize;
+  if (VT == MVT::i64)
+OpSize = 64;
+  else if (VT == MVT::i32)
+OpSize = 32;
+  else if (VT == MVT::i16)
+OpSize = 16;
+  else if (VT == MVT::i8)
+return false; // i8 shift can't be truncated.
+  else
+llvm_unreachable("Unexpected shift size");
+
+  unsigned TruncateSize = 0;
+  // This only works when the result is truncated.
+  for (const SDNode *User : N->uses()) {
+auto name = User->getOperationName(CurDAG);
+if (User->getMachineOpcode() != TargetOpcode::EXTRACT_SUBREG)
+  return false;
+EVT TuncateType = User->getValueType(0);
+if (TuncateType == MVT::i32)
+  TruncateSize = std::max(TruncateSize, 32U);
+else if (TuncateType == MVT::i16)
+  TruncateSize = std::max(TruncateSize, 16U);
+else if (TuncateType == MVT::i8)
+  TruncateSize = std::max(TruncateSize, 8U);
+else
+  return false;
+  }
+  if (TruncateSize >= OpSize)
+return false;
+
+  // The shift must be by an immediate that wouldn't expose the zero or sign
+  // extended result.
+  auto *ShiftAmount = dyn_cast(N->getOperand(1));
+  if (!ShiftAmount || ShiftAmount->getZExtValue() > OpSize - TruncateSize)
+return false;
+
+  // Only make the replacement when it avoids clobbering used flags. This is a
+  // similar heuristic as used in the conversion to LEA, namely looking at the
+  // operand for an instruction that creates flags where those flags are used.
+  // This will have both false positives and false negatives. Ideally, both of
+  // these happen later on. Perhaps in copy to flags lowering or in register
+  // allocation.
+  bool MightClobberFlags = false;
+  SDNode *Input = N->getOperand(0).getNode();
+  for (auto Use : Input->uses()) {
+if (Use->getOpcode() == ISD::CopyToReg) {
+  auto RegisterNode =

topperc wrote:

`auto *RegisterSDNode`  to make it clear it's a pointer.

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


[clang] [test] Avoid libc dep in Update warn-unsafe-buffer-usage-warning-data… (PR #79183)

2024-01-23 Thread Danial Klimkin via cfe-commits

https://github.com/dklimkin created 
https://github.com/llvm/llvm-project/pull/79183

Avoid libc dep in warn-unsafe-buffer-usage-warning-data-invocation.

To keep the test hermetic. This is in line with other existing declarations in 
the file that avoid includes.

>From bd284ac0ea8d84b6c7913479063209e21d9180aa Mon Sep 17 00:00:00 2001
From: Danial Klimkin 
Date: Tue, 23 Jan 2024 19:07:42 +0100
Subject: [PATCH] [test] Avoid libc dep in Update
 warn-unsafe-buffer-usage-warning-data-invocation

To keep the test hermetic. This is in line with other existing declarations in 
the file that avoid includes.
---
 .../warn-unsafe-buffer-usage-warning-data-invocation.cpp   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
index 574afcd0eb6dce..5c9df12513e521 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp
@@ -7,7 +7,6 @@
 // RUN: %clang_cc1 -std=c++20 -fblocks -include %s %s 2>&1 | FileCheck 
--allow-empty %s
 // CHECK-NOT: [-Wunsafe-buffer-usage]
 
-#include 
 #ifndef INCLUDED
 #define INCLUDED
 #pragma clang system_header
@@ -15,6 +14,8 @@
 // no spanification warnings for system headers
 #else
 
+typedef __INTPTR_TYPE__ intptr_t;
+
 namespace std {
   class type_info;
   class bad_cast;

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


[flang] [libcxx] [libcxxabi] [libc] [llvm] [clang] [compiler-rt] [clang-tools-extra] [lld] [CSSPGO] Compute and report post-match profile staleness (PR #79090)

2024-01-23 Thread Lei Wang via cfe-commits

https://github.com/wlei-llvm updated 
https://github.com/llvm/llvm-project/pull/79090

>From 54784e26f33178efd21b0289a1f673d66ea26cc3 Mon Sep 17 00:00:00 2001
From: wlei 
Date: Mon, 22 Jan 2024 19:16:26 -0800
Subject: [PATCH] [CSSPGO] Support post-match profile staleness metrics

---
 llvm/lib/Transforms/IPO/SampleProfile.cpp | 440 +++---
 .../Inputs/profile-mismatch.prof  |   7 +-
 .../SampleProfile/profile-mismatch.ll |  12 +-
 .../pseudo-probe-profile-mismatch-thinlto.ll  |   6 +-
 .../pseudo-probe-profile-mismatch.ll  |  76 +--
 5 files changed, 324 insertions(+), 217 deletions(-)

diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp 
b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 2fd8668d15e200f..a7170faa65dc07c 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -433,12 +433,19 @@ using CandidateQueue =
 PriorityQueue,
   CandidateComparer>;
 
+using IRAnchorMap = std::map;
+using ProfileAnchorMap = std::map>;
+
 // Sample profile matching - fuzzy match.
 class SampleProfileMatcher {
   Module 
   SampleProfileReader 
   const PseudoProbeManager *ProbeManager;
   SampleProfileMap FlattenedProfiles;
+
+  std::unordered_map FuncIRAnchors;
+  std::unordered_map FuncProfileAnchors;
+
   // For each function, the matcher generates a map, of which each entry is a
   // mapping from the source location of current build to the source location 
in
   // the profile.
@@ -448,6 +455,8 @@ class SampleProfileMatcher {
   uint64_t TotalProfiledCallsites = 0;
   uint64_t NumMismatchedCallsites = 0;
   uint64_t MismatchedCallsiteSamples = 0;
+  uint64_t PostMatchNumMismatchedCallsites = 0;
+  uint64_t PostMatchMismatchedCallsiteSamples = 0;
   uint64_t TotalCallsiteSamples = 0;
   uint64_t TotalProfiledFunc = 0;
   uint64_t NumMismatchedFuncHash = 0;
@@ -474,24 +483,22 @@ class SampleProfileMatcher {
 return nullptr;
   }
   void runOnFunction(const Function );
-  void findIRAnchors(const Function ,
- std::map );
-  void findProfileAnchors(
+  void findFuncAnchors();
+  void UpdateIRAnchors();
+  void findIRAnchors(const Function , IRAnchorMap );
+  void findProfileAnchors(const FunctionSamples ,
+  ProfileAnchorMap );
+  void countMismatchedHashSamples(const FunctionSamples );
+  void countProfileMismatches(bool IsPreMatch);
+  void countMismatchedHashes(const Function , const FunctionSamples );
+  void countMismatchedCallsites(
+  const Function ,
+  StringMap> ,
+  uint64_t , uint64_t ) 
const;
+  void countMismatchedCallsiteSamples(
   const FunctionSamples ,
-  std::map>
-  );
-  void countMismatchedSamples(const FunctionSamples );
-  void countProfileMismatches(
-  const Function , const FunctionSamples ,
-  const std::map ,
-  const std::map>
-  );
-  void countProfileCallsiteMismatches(
-  const FunctionSamples ,
-  const std::map ,
-  const std::map>
-  ,
-  uint64_t , uint64_t );
+  StringMap> ,
+  uint64_t ) const;
   LocToLocMap (const Function ) {
 auto Ret = FuncMappings.try_emplace(
 FunctionSamples::getCanonicalFnName(F.getName()), LocToLocMap());
@@ -499,11 +506,10 @@ class SampleProfileMatcher {
   }
   void distributeIRToProfileLocationMap();
   void distributeIRToProfileLocationMap(FunctionSamples );
-  void runStaleProfileMatching(
-  const Function , const std::map ,
-  const std::map>
-  ,
-  LocToLocMap );
+  void runStaleProfileMatching();
+  void runStaleProfileMatching(const Function , const IRAnchorMap ,
+   const ProfileAnchorMap ,
+   LocToLocMap );
 };
 
 /// Sample profile pass.
@@ -1129,7 +1135,7 @@ void SampleProfileLoader::findExternalInlineCandidate(
 CalleeSample->getContext().hasAttribute(ContextShouldBeInlined);
 if (!PreInline && CalleeSample->getHeadSamplesEstimate() < Threshold)
   continue;
-
+
 Function *Func = SymbolMap.lookup(CalleeSample->getFunction());
 // Add to the import list only when it's defined out of module.
 if (!Func || Func->isDeclaration())
@@ -2123,8 +2129,8 @@ bool SampleProfileLoader::doInitialization(Module ,
   return true;
 }
 
-void SampleProfileMatcher::findIRAnchors(
-const Function , std::map ) {
+void SampleProfileMatcher::findIRAnchors(const Function ,
+ IRAnchorMap ) {
   // For inlined code, recover the original callsite and callee by finding the
   // top-level inline frame. e.g. For frame stack "main:1 @ foo:2 @ bar:3", the
   // top-level frame is "main:1", the callsite is "1" and the callee is "foo".
@@ -2190,7 +2196,8 @@ void SampleProfileMatcher::findIRAnchors(
   }
 }
 
-void SampleProfileMatcher::countMismatchedSamples(const FunctionSamples ) {
+void SampleProfileMatcher::countMismatchedHashSamples(
+const FunctionSamples 

[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Wei Wang (apolloww)


Changes

When creating a new UsingType, the underlying type may change if it is a 
declaration. This creates an inconsistency between the type searched and type 
created. Move the update before search so that we always use the same type for 
search and creation. 

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


1 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+7-6) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(T, 0);
-
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+return QualType(T, 0);
+  }
+
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

``




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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/79182

When creating a new UsingType, the underlying type may change if it is a 
declaration. This creates an inconsistency between the type searched and type 
created. Move the update before search so that we always use the same type for 
search and creation. 

>From a542d63f472d799eb2d041c82cac402cfb8dec1a Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 10:01:57 -0800
Subject: [PATCH] [clang] Make sure the same UsingType is searched and inserted

---
 clang/lib/AST/ASTContext.cpp | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(T, 0);
-
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+return QualType(T, 0);
+  }
+
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

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


[libcxx] [libc] [lldb] [openmp] [clang] [mlir] [clang-tools-extra] [flang] [lld] [compiler-rt] [llvm] AMDGPU: Do not generate non-temporal hint when Load_Tr intrinsic did not specify it (PR #79104)

2024-01-23 Thread Changpeng Fang via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [X86] Use RORX over SHR imm (PR #77964)

2024-01-23 Thread Bryce Wilson via cfe-commits

https://github.com/Bryce-MW updated 
https://github.com/llvm/llvm-project/pull/77964

>From d4c312b9dbf447d0a53dda0e6cdc482bd908430b Mon Sep 17 00:00:00 2001
From: Bryce Wilson 
Date: Fri, 12 Jan 2024 16:01:32 -0600
Subject: [PATCH 01/10] [X86] Use RORX over SHR imm

---
 llvm/lib/Target/X86/X86InstrShiftRotate.td |  78 ++
 llvm/test/CodeGen/X86/atomic-unordered.ll  |   3 +-
 llvm/test/CodeGen/X86/bmi2.ll  |   6 +-
 llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll  |   3 +-
 llvm/test/CodeGen/X86/pr35636.ll   |   4 +-
 llvm/test/CodeGen/X86/vector-trunc-ssat.ll | 116 ++---
 6 files changed, 143 insertions(+), 67 deletions(-)

diff --git a/llvm/lib/Target/X86/X86InstrShiftRotate.td 
b/llvm/lib/Target/X86/X86InstrShiftRotate.td
index f951894db1890cd..238e8e9b6e97f30 100644
--- a/llvm/lib/Target/X86/X86InstrShiftRotate.td
+++ b/llvm/lib/Target/X86/X86InstrShiftRotate.td
@@ -879,6 +879,26 @@ let Predicates = [HasBMI2, HasEGPR, In64BitMode] in {
   defm SHLX64 : bmi_shift<"shlx{q}", GR64, i64mem, "_EVEX">, T8, PD, REX_W, 
EVEX;
 }
 
+
+def immle16_8 : ImmLeaf;
+def immle32_8 : ImmLeaf;
+def immle64_8 : ImmLeaf;
+def immle32_16 : ImmLeaf;
+def immle64_16 : ImmLeaf;
+def immle64_32 : ImmLeaf;
+
 let Predicates = [HasBMI2] in {
   // Prefer RORX which is non-destructive and doesn't update EFLAGS.
   let AddedComplexity = 10 in {
@@ -891,6 +911,64 @@ let Predicates = [HasBMI2] in {
   (RORX32ri GR32:$src, (ROT32L2R_imm8 imm:$shamt))>;
 def : Pat<(rotl GR64:$src, (i8 imm:$shamt)),
   (RORX64ri GR64:$src, (ROT64L2R_imm8 imm:$shamt))>;
+
+// A right shift by less than a smaller register size that is then
+// truncated to that register size can be replaced by RORX to
+// preserve flags with the same execution cost
+
+def : Pat<(i8 (trunc (srl GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc (srl GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+def : Pat<(i32 (trunc (sra GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+
+
+// Can't expand the load
+def : Pat<(i8 (trunc (srl (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc 

[llvm] [clang] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -176,6 +188,18 @@ def HasStdExtZacas : 
Predicate<"Subtarget->hasStdExtZacas()">,
"'Zacas' (Atomic Compare-And-Swap 
Instructions)">;
 def NoStdExtZacas : Predicate<"!Subtarget->hasStdExtZacas()">;
 
+def FeatureStdExtZalrsc
+: SubtargetFeature<"experimental-zalrsc", "HasStdExtZalrsc", "true",
+   "'Zalrsc' (Load-Reserved/Store-Conditional)">;
+def HasStdExtZalrsc : Predicate<"Subtarget->hasStdExtZalrsc()">,

topperc wrote:

This isn't used

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


[clang] [llvm] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -168,6 +168,18 @@ def FeatureStdExtZa64rs : SubtargetFeature<"za64rs", 
"HasStdExtZa64rs", "true",
 def FeatureStdExtZa128rs : SubtargetFeature<"za128rs", "HasStdExtZa128rs", 
"true",
 "'Za128rs' (Reservation Set Size 
of at Most 128 Bytes)">;
 
+def FeatureStdExtZaamo
+: SubtargetFeature<"experimental-zaamo", "HasStdExtZaamo", "true",
+   "'Zaamo' (Atomic Memory Operations)">;
+def HasStdExtZaamo : Predicate<"Subtarget->hasStdExtZaamo()">,
+   AssemblerPredicate<(all_of FeatureStdExtZaamo),

topperc wrote:

Please reformat this like to have `AssemblerPredicate` start at the same column 
as `Predicate` like 79076

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


[llvm] [clang] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-23 Thread Craig Topper via cfe-commits


@@ -168,6 +168,18 @@ def FeatureStdExtZa64rs : SubtargetFeature<"za64rs", 
"HasStdExtZa64rs", "true",
 def FeatureStdExtZa128rs : SubtargetFeature<"za128rs", "HasStdExtZa128rs", 
"true",
 "'Za128rs' (Reservation Set Size 
of at Most 128 Bytes)">;
 
+def FeatureStdExtZaamo
+: SubtargetFeature<"experimental-zaamo", "HasStdExtZaamo", "true",
+   "'Zaamo' (Atomic Memory Operations)">;
+def HasStdExtZaamo : Predicate<"Subtarget->hasStdExtZaamo()">,

topperc wrote:

This predicate isn't used

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


[libcxx] [libc] [clang] [lld] [clang-tools-extra] [flang] [compiler-rt] [llvm] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Teresa Johnson via cfe-commits

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


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


[clang] Update test intrinsic to support immediates (PR #79174)

2024-01-23 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/79174

>From 6c2774f100b3637126d4da1dffafe0fcd01f2424 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 12:31:49 -0500
Subject: [PATCH] Update test intrinsic to support immediates

---
 clang/lib/CodeGen/CGBuiltin.cpp | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ef764b8e1ac80..4c205be47ff429 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1203,10 +1203,24 @@ static llvm::Value 
*EmitX86BitTestIntrinsic(CodeGenFunction ,
   AsmOS << "bt";
   if (Action)
 AsmOS << Action;
-  AsmOS << SizeSuffix << " $2, ($1)";
 
-  // Build the constraints. FIXME: We should support immediates when possible.
-  std::string Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  // Check if BitPos is a ConstantInt (immediate value)
+  if (llvm::ConstantInt *CI = llvm::dyn_cast(BitPos)) {
+// If it is, use the immediate value in the assembly string
+AsmOS << SizeSuffix << " $" << CI->getZExtValue() << ", ($1)";
+  } else {
+// Otherwise, fall back to the existing behavior
+AsmOS << SizeSuffix << " $2, ($1)";
+  }
+
+  // Build the constraints.
+  std::string Constraints;
+  if (llvm::isa(BitPos)) {
+Constraints = "={@ccc},r,~{cc},~{memory}";
+  } else {
+Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  }
+
   std::string_view MachineClobbers = CGF.getTarget().getClobbers();
   if (!MachineClobbers.empty()) {
 Constraints += ',';

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


[compiler-rt] [clang] [clang-tools-extra] [llvm] [flang] [Bazel][Clang Tidy] Include builtin headers with clang-tidy (PR #67626)

2024-01-23 Thread via cfe-commits

https://github.com/jathu updated https://github.com/llvm/llvm-project/pull/67626

>From 20d9ca99fbf11868a5816df217b2aad09e079fb6 Mon Sep 17 00:00:00 2001
From: jathu 
Date: Wed, 27 Sep 2023 18:01:19 -0700
Subject: [PATCH] [clang-tidy][bazel] Include builtin headers with clang-tidy

---
 .../clang-tools-extra/BUILD.bazel | 21 +++
 .../clang-tools-extra/clang-tidy/BUILD.bazel  |  1 +
 .../clang-tools-extra/defs.bzl| 26 +++
 .../llvm-project-overlay/clang/BUILD.bazel| 12 ++---
 .../bazel/llvm-project-overlay/clang/defs.bzl |  5 
 5 files changed, 61 insertions(+), 4 deletions(-)
 create mode 100644 
utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel
 create mode 100644 utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl
 create mode 100644 utils/bazel/llvm-project-overlay/clang/defs.bzl

diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel
new file mode 100644
index 000..d7559a376698583
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel
@@ -0,0 +1,21 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+load("//:vars.bzl", "LLVM_VERSION_MAJOR")
+load("//clang:defs.bzl", "BUILTIN_HEADERS_GEN_DIR")
+load("defs.bzl", "symlink")
+
+package(
+default_visibility = ["//visibility:public"],
+features = ["layering_check"],
+)
+
+licenses(["notice"])
+
+symlink(
+name = "builtin_headers",
+srcs = ["//clang:builtin_headers_gen"],
+destination = "lib/clang/{0}/include".format(LLVM_VERSION_MAJOR),
+partition = BUILTIN_HEADERS_GEN_DIR,
+)
diff --git 
a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
index bbabc5397e98937..257c9e875d0133b 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
@@ -370,6 +370,7 @@ cc_library(
 cc_binary(
 name = "clang-tidy",
 srcs = ["tool/ClangTidyToolMain.cpp"],
+data = ["//clang-tools-extra:builtin_headers"],
 stamp = 0,
 deps = [":tool"],
 )
diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl 
b/utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl
new file mode 100644
index 000..fd992c052b0f055
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl
@@ -0,0 +1,26 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+load("@bazel_skylib//lib:paths.bzl", "paths")
+
+def _symlink_impl(ctx):
+copied_files = []
+for input_file in ctx.files.srcs:
+(_, _, relative_filename) = 
input_file.path.rpartition(ctx.attr.partition)
+output_file = 
ctx.actions.declare_file(paths.join(ctx.attr.destination, relative_filename))
+ctx.actions.symlink(
+target_file = input_file,
+output = output_file,
+)
+copied_files.append(output_file)
+return DefaultInfo(files = depset(copied_files))
+
+symlink = rule(
+implementation = _symlink_impl,
+attrs = {
+"destination": attr.string(mandatory = True),
+"partition": attr.string(mandatory = True),
+"srcs": attr.label_list(allow_files = True),
+},
+)
diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
index cac8ec120929a37..02f0f6076c6fddd 100644
--- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -14,6 +14,7 @@ load(
 "LLVM_VERSION_MINOR",
 "LLVM_VERSION_PATCH",
 )
+load("defs.bzl", "BUILTIN_HEADERS_GEN_DIR")
 
 package(
 default_visibility = ["//visibility:public"],
@@ -1696,14 +1697,17 @@ builtin_headers = glob(
 genrule(
 name = "builtin_headers_gen",
 srcs = builtin_headers,
-outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in 
builtin_headers],
+outs = [
+header.replace("lib/Headers/", BUILTIN_HEADERS_GEN_DIR)
+for header in builtin_headers
+],
 cmd = """
for src in $(SRCS); do
- relsrc=$${src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}
- target=$(@D)/staging/include/$$relsrc
+ relsrc=$${{src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}}
+ target=$(@D)/{resource_dir}$$relsrc
  mkdir -p $$(dirname $$target)
  cp $$src $$target
-   done""",
+   done""".format(resource_dir = BUILTIN_HEADERS_GEN_DIR),
 output_to_bindir = 1,
 toolchains = [
 ":workspace_root",
diff 

[clang] [clang-tools-extra] [llvm] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-23 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

@felix642, I am not able to reproduce this error on my end. Could you please 
provide steps to reproduce it? Your guidance is highly appreciated. the piece 
of code you mentioned seems to be causing no error when put with current tests.
thank you

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


[clang] [clang-tools-extra] [llvm] [X86] Use RORX over SHR imm (PR #77964)

2024-01-23 Thread Bryce Wilson via cfe-commits

https://github.com/Bryce-MW updated 
https://github.com/llvm/llvm-project/pull/77964

>From d4c312b9dbf447d0a53dda0e6cdc482bd908430b Mon Sep 17 00:00:00 2001
From: Bryce Wilson 
Date: Fri, 12 Jan 2024 16:01:32 -0600
Subject: [PATCH 1/9] [X86] Use RORX over SHR imm

---
 llvm/lib/Target/X86/X86InstrShiftRotate.td |  78 ++
 llvm/test/CodeGen/X86/atomic-unordered.ll  |   3 +-
 llvm/test/CodeGen/X86/bmi2.ll  |   6 +-
 llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll  |   3 +-
 llvm/test/CodeGen/X86/pr35636.ll   |   4 +-
 llvm/test/CodeGen/X86/vector-trunc-ssat.ll | 116 ++---
 6 files changed, 143 insertions(+), 67 deletions(-)

diff --git a/llvm/lib/Target/X86/X86InstrShiftRotate.td 
b/llvm/lib/Target/X86/X86InstrShiftRotate.td
index f951894db1890cd..238e8e9b6e97f30 100644
--- a/llvm/lib/Target/X86/X86InstrShiftRotate.td
+++ b/llvm/lib/Target/X86/X86InstrShiftRotate.td
@@ -879,6 +879,26 @@ let Predicates = [HasBMI2, HasEGPR, In64BitMode] in {
   defm SHLX64 : bmi_shift<"shlx{q}", GR64, i64mem, "_EVEX">, T8, PD, REX_W, 
EVEX;
 }
 
+
+def immle16_8 : ImmLeaf;
+def immle32_8 : ImmLeaf;
+def immle64_8 : ImmLeaf;
+def immle32_16 : ImmLeaf;
+def immle64_16 : ImmLeaf;
+def immle64_32 : ImmLeaf;
+
 let Predicates = [HasBMI2] in {
   // Prefer RORX which is non-destructive and doesn't update EFLAGS.
   let AddedComplexity = 10 in {
@@ -891,6 +911,64 @@ let Predicates = [HasBMI2] in {
   (RORX32ri GR32:$src, (ROT32L2R_imm8 imm:$shamt))>;
 def : Pat<(rotl GR64:$src, (i8 imm:$shamt)),
   (RORX64ri GR64:$src, (ROT64L2R_imm8 imm:$shamt))>;
+
+// A right shift by less than a smaller register size that is then
+// truncated to that register size can be replaced by RORX to
+// preserve flags with the same execution cost
+
+def : Pat<(i8 (trunc (srl GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc (srl GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+def : Pat<(i32 (trunc (sra GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+
+
+// Can't expand the load
+def : Pat<(i8 (trunc (srl (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc 

[compiler-rt] [libc] [clang] [libcxx] [clang-tools-extra] [llvm] [flang] [clang][FatLTO] Avoid UnifiedLTO until it can support WPD/CFI (PR #79061)

2024-01-23 Thread Paul Kirth via cfe-commits

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

>From 2e0cd6077a756fa28023d907045e6e53c50ec732 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 22 Jan 2024 21:48:16 +
Subject: [PATCH 1/3] =?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.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  9 ++--
 clang/lib/Driver/ToolChains/Clang.cpp |  4 +-
 clang/lib/Frontend/CompilerInvocation.cpp | 14 ---
 clang/test/CodeGen/fat-lto-objects.c  | 42 +--
 clang/test/Driver/fat-lto-objects.c   | 12 --
 llvm/docs/FatLTO.rst  |  4 +-
 llvm/include/llvm/Passes/PassBuilder.h|  3 +-
 .../llvm/Transforms/IPO/EmbedBitcodePass.h| 16 ++-
 llvm/lib/Passes/PassBuilder.cpp   | 20 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 37 +---
 llvm/lib/Passes/PassRegistry.def  |  5 ++-
 llvm/lib/Transforms/IPO/EmbedBitcodePass.cpp  | 12 +-
 llvm/test/CodeGen/X86/fat-lto-section.ll  |  2 +-
 llvm/test/Transforms/EmbedBitcode/embed.ll|  3 ++
 14 files changed, 107 insertions(+), 76 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a6142d99f3b688d..9369c8828231421 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1001,8 +1001,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
 
 if (CodeGenOpts.FatLTO) {
-  assert(CodeGenOpts.UnifiedLTO && "FatLTO requires UnifiedLTO");
-  MPM.addPass(PB.buildFatLTODefaultPipeline(Level));
+  MPM.addPass(PB.buildFatLTODefaultPipeline(
+  Level, PrepareForThinLTO,
+  PrepareForThinLTO || shouldEmitRegularLTOSummary()));
 } else if (PrepareForThinLTO) {
   MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
 } else if (PrepareForLTO) {
@@ -1046,6 +1047,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
 /*EmitLTOSummary=*/true));
   }
+
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
@@ -1073,8 +1075,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
   TheModule->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
uint32_t(CodeGenOpts.EnableSplitLTOUnit));
-// FatLTO always means UnifiedLTO
-if (!TheModule->getModuleFlag("UnifiedLTO"))
+if (CodeGenOpts.UnifiedLTO && !TheModule->getModuleFlag("UnifiedLTO"))
   TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
   }
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2f33943de45c5da..928dca653dabdc1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4854,9 +4854,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   bool UnifiedLTO = false;
   if (IsUsingLTO) {
 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
-  options::OPT_fno_unified_lto, Triple.isPS()) ||
- Args.hasFlag(options::OPT_ffat_lto_objects,
-  options::OPT_fno_fat_lto_objects, false);
+  options::OPT_fno_unified_lto, Triple.isPS());
 if (UnifiedLTO)
   CmdArgs.push_back("-funified-lto");
   }
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 7edea7798af1ef0..feb4de2084b830b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1861,20 +1861,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
, ArgList ,
 if (Args.hasArg(OPT_funified_lto))
   Opts.PrepareForThinLTO = true;
   }
-  if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects,
-   options::OPT_fno_fat_lto_objects)) {
-if (A->getOption().matches(options::OPT_ffat_lto_objects)) {
-  if (Arg *Uni = Args.getLastArg(options::OPT_funified_lto,
- options::OPT_fno_unified_lto)) {
-if (Uni->getOption().matches(options::OPT_fno_unified_lto))
-  Diags.Report(diag::err_drv_incompatible_options)
-  << A->getAsString(Args) << "-fno-unified-lto";
-  } else
-Diags.Report(diag::err_drv_argument_only_allowed_with)
-<< A->getAsString(Args) << "-funified-lto";
-}
-  }
-
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != Language::LLVM_IR)
   Diags.Report(diag::err_drv_argument_only_allowed_with)
diff --git 

[clang-tools-extra] [clang] [llvm] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-23 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,151 @@
+//===--- UseStdMinMaxCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdMinMaxCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static const llvm::StringRef AlgorithmHeader("");
+
+static bool MinCondition(const BinaryOperator::Opcode , const Expr *CondLhs,
+ const Expr *CondRhs, const Expr *AssignLhs,
+ const Expr *AssignRhs, const ASTContext ) {
+  if ((Op == BO_LT || Op == BO_LE) &&
+  (tidy::utils::areStatementsIdentical(CondLhs, AssignRhs, Context) &&
+   tidy::utils::areStatementsIdentical(CondRhs, AssignLhs, Context)))
+return true;
+
+  if ((Op == BO_GT || Op == BO_GE) &&
+  (tidy::utils::areStatementsIdentical(CondLhs, AssignLhs, Context) &&
+   tidy::utils::areStatementsIdentical(CondRhs, AssignRhs, Context)))
+return true;
+
+  return false;
+}
+
+static bool MaxCondition(const BinaryOperator::Opcode , const Expr *CondLhs,
+ const Expr *CondRhs, const Expr *AssignLhs,
+ const Expr *AssignRhs, const ASTContext ) {
+  if ((Op == BO_LT || Op == BO_LE) &&
+  (tidy::utils::areStatementsIdentical(CondLhs, AssignLhs, Context) &&
+   tidy::utils::areStatementsIdentical(CondRhs, AssignRhs, Context)))
+return true;
+
+  if ((Op == BO_GT || Op == BO_GE) &&
+  (tidy::utils::areStatementsIdentical(CondLhs, AssignRhs, Context) &&
+   tidy::utils::areStatementsIdentical(CondRhs, AssignLhs, Context)))
+return true;
+
+  return false;
+}
+
+static std::string
+CreateReplacement(const bool UseMax, const BinaryOperator::Opcode ,
+  const Expr *CondLhs, const Expr *CondRhs,
+  const Expr *AssignLhs, const ASTContext ,
+  const SourceManager , const LangOptions ,
+  const StringRef ) {
+  const auto CondLhsStr = Lexer::getSourceText(
+  Source.getExpansionRange(CondLhs->getSourceRange()), Source, LO);
+  const auto CondRhsStr = Lexer::getSourceText(
+  Source.getExpansionRange(CondRhs->getSourceRange()), Source, LO);
+  const auto AssignLhsStr = Lexer::getSourceText(
+  Source.getExpansionRange(AssignLhs->getSourceRange()), Source, LO);
+  return (AssignLhsStr + " = " + FunctionName +
+  ((CondLhs->getType() != CondRhs->getType())
+   ? "<" + AssignLhs->getType().getAsString() + ">("

11happy wrote:

@PiotrZSL Can you please guide me for this as I am not sure how to move 
forward. I am not very good at handling these Implicit casts.

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


[libcxx] [libc] [clang] [lld] [clang-tools-extra] [flang] [compiler-rt] [llvm] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Fangrui Song via cfe-commits


@@ -46,8 +46,9 @@ class BitcodeCompiler {
 
 private:
   std::unique_ptr ltoObj;
-  std::vector> buf;
+  SmallVector>, 0> buf;

MaskRay wrote:

Added a comment

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


[clang] Revert "[clang-repl] Enable native CPU detection by default (#77491)" (PR #79178)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Stefan Gränitz (weliveindetail)


Changes

Reverting because `clang-repl -Xcc -mcpu=arm1176jzf-s` isn't overwriting this 
as I had expected. We need to check whether a specific CPU flag was given by 
the user first.

Reverts llvm/llvm-project#77491

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


1 Files Affected:

- (modified) clang/lib/Interpreter/Interpreter.cpp (-1) 


``diff
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index d1764d07dfd2407..9f97a3c6b0be9e6 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -148,7 +148,6 @@ IncrementalCompilerBuilder::create(std::vector ) {
   // We do C++ by default; append right after argv[0] if no "-x" given
   ClangArgv.insert(ClangArgv.end(), "-Xclang");
   ClangArgv.insert(ClangArgv.end(), "-fincremental-extensions");
-  ClangArgv.insert(ClangArgv.end(), "-mcpu=native");
   ClangArgv.insert(ClangArgv.end(), "-c");
 
   // Put a dummy C++ file on to ensure there's at least one compile job for the

``




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


[compiler-rt] [clang] [libc] [libcxx] [lld] [clang-tools-extra] [llvm] [flang] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Fangrui Song via cfe-commits


@@ -352,32 +357,49 @@ std::vector BitcodeCompiler::compile() {
 pruneCache(config->thinLTOCacheDir, config->thinLTOCachePolicy, files);
 
   if (!config->ltoObjPath.empty()) {
-saveBuffer(buf[0], config->ltoObjPath);
+saveBuffer(buf[0].second, config->ltoObjPath);
 for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->ltoObjPath + Twine(i));
-  }
-
-  if (config->saveTempsArgs.contains("prelink")) {
-if (!buf[0].empty())
-  saveBuffer(buf[0], config->outputFile + ".lto.o");
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i) + ".lto.o");
-  }
-
-  if (config->ltoEmitAsm) {
-saveBuffer(buf[0], config->outputFile);
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i));
-return {};
+  saveBuffer(buf[i].second, config->ltoObjPath + Twine(i));
   }
 
+  bool savePrelink = config->saveTempsArgs.contains("prelink");
   std::vector ret;
-  for (unsigned i = 0; i != maxTasks; ++i)
-if (!buf[i].empty())
-  ret.push_back(createObjFile(MemoryBufferRef(buf[i], "lto.tmp")));
+  const char *ext = config->ltoEmitAsm ? ".s" : ".o";
+  for (unsigned i = 0; i != maxTasks; ++i) {
+StringRef bitcodeFilePath;
+StringRef objBuf;
+if (files[i]) {

MaskRay wrote:

Clarified the comment a bit

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


[compiler-rt] [clang] [libc] [libcxx] [lld] [clang-tools-extra] [llvm] [flang] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/78835

>From 37b3ff263f2b46bd4541157bee5b5e1bf2639604 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sat, 20 Jan 2024 00:40:53 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 lld/ELF/LTO.cpp| 70 ++
 lld/ELF/LTO.h  |  3 +-
 lld/test/ELF/common-archive-lookup.s   |  7 ++-
 lld/test/ELF/lto/comdat-mixed-archive.test |  4 +-
 lld/test/ELF/lto/emit-asm.ll   | 13 ++--
 lld/test/ELF/lto/exclude-libs-libcall.ll   |  2 +-
 lld/test/ELF/lto/obj-path.ll   |  4 +-
 lld/test/ELF/lto/parallel-internalize.ll   |  2 +-
 lld/test/ELF/lto/parallel.ll   |  2 +-
 lld/test/ELF/lto/pseudo-probe-lto.ll   |  3 +-
 lld/test/ELF/lto/save-temps-eq.ll  | 10 ++--
 lld/test/ELF/lto/thinlto.ll| 48 +++
 12 files changed, 97 insertions(+), 71 deletions(-)

diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 504c12aac6c5696..843ee59479eae92 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -12,6 +12,7 @@
 #include "SymbolTable.h"
 #include "Symbols.h"
 #include "lld/Common/Args.h"
+#include "lld/Common/CommonLinkerContext.h"
 #include "lld/Common/ErrorHandler.h"
 #include "lld/Common/Filesystem.h"
 #include "lld/Common/Strings.h"
@@ -26,6 +27,7 @@
 #include "llvm/Support/Caching.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include 
@@ -303,6 +305,7 @@ std::vector BitcodeCompiler::compile() {
   unsigned maxTasks = ltoObj->getMaxTasks();
   buf.resize(maxTasks);
   files.resize(maxTasks);
+  filenames.resize(maxTasks);
 
   // The --thinlto-cache-dir option specifies the path to a directory in which
   // to cache native object files for ThinLTO incremental builds. If a path was
@@ -313,13 +316,15 @@ std::vector BitcodeCompiler::compile() {
  [&](size_t task, const Twine ,
  std::unique_ptr mb) {
files[task] = std::move(mb);
+   filenames[task] = moduleName.str();
  }));
 
   if (!ctx.bitcodeFiles.empty())
 checkError(ltoObj->run(
 [&](size_t task, const Twine ) {
+  buf[task].first = moduleName.str();
   return std::make_unique(
-  std::make_unique(buf[task]));
+  std::make_unique(buf[task].second));
 },
 cache));
 
@@ -338,7 +343,7 @@ std::vector BitcodeCompiler::compile() {
 
   if (config->thinLTOIndexOnly) {
 if (!config->ltoObjPath.empty())
-  saveBuffer(buf[0], config->ltoObjPath);
+  saveBuffer(buf[0].second, config->ltoObjPath);
 
 // ThinLTO with index only option is required to generate only the index
 // files. After that, we exit from linker and ThinLTO backend runs in a
@@ -352,32 +357,49 @@ std::vector BitcodeCompiler::compile() {
 pruneCache(config->thinLTOCacheDir, config->thinLTOCachePolicy, files);
 
   if (!config->ltoObjPath.empty()) {
-saveBuffer(buf[0], config->ltoObjPath);
+saveBuffer(buf[0].second, config->ltoObjPath);
 for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->ltoObjPath + Twine(i));
-  }
-
-  if (config->saveTempsArgs.contains("prelink")) {
-if (!buf[0].empty())
-  saveBuffer(buf[0], config->outputFile + ".lto.o");
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i) + ".lto.o");
-  }
-
-  if (config->ltoEmitAsm) {
-saveBuffer(buf[0], config->outputFile);
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i));
-return {};
+  saveBuffer(buf[i].second, config->ltoObjPath + Twine(i));
   }
 
+  bool savePrelink = config->saveTempsArgs.contains("prelink");
   std::vector ret;
-  for (unsigned i = 0; i != maxTasks; ++i)
-if (!buf[i].empty())
-  ret.push_back(createObjFile(MemoryBufferRef(buf[i], "lto.tmp")));
+  const char *ext = config->ltoEmitAsm ? ".s" : ".o";
+  for (unsigned i = 0; i != maxTasks; ++i) {
+StringRef bitcodeFilePath;
+StringRef objBuf;
+if (files[i]) {
+  objBuf = files[i]->getBuffer();
+  bitcodeFilePath = filenames[i];
+} else {
+  objBuf = buf[i].second;
+  bitcodeFilePath = buf[i].first;
+}
+if (objBuf.empty())
+  continue;
 
-  for (std::unique_ptr  : files)
-if (file)
-  ret.push_back(createObjFile(*file));
+// If the input bitcode file is path/to/a.o and -o specifies a.out, then 
the
+// corresponding lto object file name will look something like:
+// path/to/a.out.lto.a.o.
+  

[clang] Revert "[clang-repl] Enable native CPU detection by default (#77491)" (PR #79178)

2024-01-23 Thread Stefan Gränitz via cfe-commits

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


[clang] 6a7abea - Revert "[clang-repl] Enable native CPU detection by default (#77491)" (#79178)

2024-01-23 Thread via cfe-commits

Author: Stefan Gränitz
Date: 2024-01-23T18:44:07+01:00
New Revision: 6a7abea47418721616c9dd7a16f5cc3e5a67d49c

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

LOG: Revert "[clang-repl] Enable native CPU detection by default (#77491)" 
(#79178)

Reverting because `clang-repl -Xcc -mcpu=arm1176jzf-s` isn't overwriting
this as I had expected. We need to check whether a specific CPU flag was
given by the user first.

Reverts llvm/llvm-project#77491

Added: 


Modified: 
clang/lib/Interpreter/Interpreter.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index d1764d07dfd2407..9f97a3c6b0be9e6 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -148,7 +148,6 @@ IncrementalCompilerBuilder::create(std::vector ) {
   // We do C++ by default; append right after argv[0] if no "-x" given
   ClangArgv.insert(ClangArgv.end(), "-Xclang");
   ClangArgv.insert(ClangArgv.end(), "-fincremental-extensions");
-  ClangArgv.insert(ClangArgv.end(), "-mcpu=native");
   ClangArgv.insert(ClangArgv.end(), "-c");
 
   // Put a dummy C++ file on to ensure there's at least one compile job for the



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


[clang] Revert "[clang-repl] Enable native CPU detection by default (#77491)" (PR #79178)

2024-01-23 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail created 
https://github.com/llvm/llvm-project/pull/79178

Reverting because `clang-repl -Xcc -mcpu=arm1176jzf-s` isn't overwriting this 
as I had expected. We need to check whether a specific CPU flag was given by 
the user first.

Reverts llvm/llvm-project#77491

From c9a439ed53bc6852b913c202749b3aa8833b4207 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Tue, 23 Jan 2024 18:39:57 +0100
Subject: [PATCH] Revert "[clang-repl] Enable native CPU detection by default"

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

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index d1764d07dfd240..9f97a3c6b0be9e 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -148,7 +148,6 @@ IncrementalCompilerBuilder::create(std::vector ) {
   // We do C++ by default; append right after argv[0] if no "-x" given
   ClangArgv.insert(ClangArgv.end(), "-Xclang");
   ClangArgv.insert(ClangArgv.end(), "-fincremental-extensions");
-  ClangArgv.insert(ClangArgv.end(), "-mcpu=native");
   ClangArgv.insert(ClangArgv.end(), "-c");
 
   // Put a dummy C++ file on to ensure there's at least one compile job for the

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


[clang] [llvm] [JITLink][AArch32] Implement Armv5 ldr-pc stubs and use them for all pre-v7 targets (PR #79082)

2024-01-23 Thread via cfe-commits
Stefan =?utf-8?q?Gr=C3=A4nitz?= ,
Stefan =?utf-8?q?Gr=C3=A4nitz?= ,
Stefan =?utf-8?q?Gr=C3=A4nitz?= 
Message-ID:
In-Reply-To: 


https://github.com/lhames commented:

LGTM. I love the detail in the testing here -- thanks @weliveindetail!

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


[lld] [clang-tools-extra] [llvm] [clang] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Fangrui Song via cfe-commits


@@ -53,10 +53,10 @@
 
 ; RUN: rm -fr cache && mkdir cache
 ; RUN: ld.lld --thinlto-cache-dir=cache --save-temps -o out b.bc a.bc -M | 
FileCheck %s --check-prefix=MAP
-; RUN: ls out1.lto.o a.bc.0.preopt.bc b.bc.0.preopt.bc
+; RUN: ls out.lto.a.o a.bc.0.preopt.bc b.bc.0.preopt.bc
 
-; MAP: llvmcache-{{.*}}:(.text)
-; MAP: llvmcache-{{.*}}:(.text)
+; MAP: out.lto.b.o:(.text)

MaskRay wrote:

This is a new test. I noticed the `-Map` difference, so I pre-committed a test 
and changed this PR to demonstrate the difference.

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


[clang] [Clang][Driver] Fix `--save-temps` for OpenCL AoT compilation (PR #78333)

2024-01-23 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/78333

>From 9ae3562ab4a6fb152c2a92f50b72d86711bbad8b Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Tue, 23 Jan 2024 12:35:42 -0500
Subject: [PATCH] [Clang][Driver] Fix `--save-temps` for OpenCL AoT compilation

We can directly call `clang -c -x cl -target amdgcn -mcpu=gfx90a test.cl -o 
test.o`
to compile an OpenCL kernel file. However, when `--save-temps` is enabled, it 
doesn't
work because the preprocessed file (`.i` file)  is taken as C source file when 
it
is fed to the front end, thus causing compilation error because those OpenCL 
keywords
can't be recognized. This patch fixes the issue.
---
 clang/include/clang/Driver/Types.def   |  6 --
 clang/lib/Driver/Types.cpp |  7 ++-
 clang/test/Driver/opencl_aot_save_temps.cl | 19 +++
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/opencl_aot_save_temps.cl

diff --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index b889883125c4c1..f72c27e1ee7019 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -37,8 +37,10 @@
 // C family source language (with and without preprocessing).
 TYPE("cpp-output",   PP_C, INVALID, "i",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("c",C,PP_C,"c",  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
-TYPE("cl",   CL,   PP_C,"cl", 
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
-TYPE("clcpp",CLCXX,PP_CXX,  "clcpp",  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
+TYPE("cl",   CL,   PP_CL,   "cl", 
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
+TYPE("cl-cpp-output",PP_CL,INVALID, "cli",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("clcpp",CLCXX,PP_CLCXX,"clcpp",  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
+TYPE("clcpp-cpp-output", PP_CLCXX, INVALID, "clii",   
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("cuda", CUDA, PP_CUDA, "cu", 
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
 TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu", 
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 08df34ade7b653..a7b6b9000e1d2b 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -133,7 +133,7 @@ bool types::isAcceptedByClang(ID Id) {
 
   case TY_Asm:
   case TY_C: case TY_PP_C:
-  case TY_CL: case TY_CLCXX:
+  case TY_CL: case TY_PP_CL: case TY_CLCXX: case TY_PP_CLCXX:
   case TY_CUDA: case TY_PP_CUDA:
   case TY_CUDA_DEVICE:
   case TY_HIP:
@@ -181,7 +181,9 @@ bool types::isDerivedFromC(ID Id) {
   case TY_PP_C:
   case TY_C:
   case TY_CL:
+  case TY_PP_CL:
   case TY_CLCXX:
+  case TY_PP_CLCXX:
   case TY_PP_CUDA:
   case TY_CUDA:
   case TY_CUDA_DEVICE:
@@ -241,6 +243,7 @@ bool types::isCXX(ID Id) {
   case TY_PP_CXXHeaderUnit:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
   case TY_CXXModule: case TY_PP_CXXModule:
+  case TY_PP_CLCXX:
   case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE:
   case TY_HIP:
   case TY_PP_HIP:
@@ -310,7 +313,9 @@ types::ID types::lookupTypeForExtension(llvm::StringRef 
Ext) {
   .Case("cc", TY_CXX)
   .Case("CC", TY_CXX)
   .Case("cl", TY_CL)
+  .Case("cli", TY_PP_CL)
   .Case("clcpp", TY_CLCXX)
+  .Case("clii", TY_PP_CLCXX)
   .Case("cp", TY_CXX)
   .Case("cu", TY_CUDA)
   .Case("hh", TY_CXXHeader)
diff --git a/clang/test/Driver/opencl_aot_save_temps.cl 
b/clang/test/Driver/opencl_aot_save_temps.cl
new file mode 100644
index 00..b78014ca617b9a
--- /dev/null
+++ b/clang/test/Driver/opencl_aot_save_temps.cl
@@ -0,0 +1,19 @@
+// RUN: %clang -x cl --save-temps -c -### %s 2>&1 | FileCheck %s
+// RUN: %clang -x cl -ccc-print-phases -c %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PHASES
+
+// CHECK: "-o" "[[CLI_NAME:.+]].cli" "-x" "cl"
+// CHECK-NEXT:  "-o" "[[CLI_NAME]].bc" "-x" 
"cl-cpp-output"{{.*}}"[[CLI_NAME:.+]].cli"
+
+// CHECK-PHASES: 0: input, {{.*}}, cl
+// CHECK-PHASES: 1: preprocessor, {0}, cl-cpp-output
+// CHECK-PHASES: 2: compiler, {1}, ir
+// CHECK-PHASES: 3: 

[clang] Update test intrinsic to support immediates (PR #79174)

2024-01-23 Thread via cfe-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 51f9e982ed5c9a1f39c50d0501ab1bcb6ebf5de4 
9ed2a138bd980c1c043e1585cb8e5d82a1592f1e -- clang/lib/CodeGen/CGBuiltin.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e404f92c28..4c205be47f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1220,7 +1220,7 @@ static llvm::Value 
*EmitX86BitTestIntrinsic(CodeGenFunction ,
   } else {
 Constraints = "={@ccc},r,r,~{cc},~{memory}";
   }
-  
+
   std::string_view MachineClobbers = CGF.getTarget().getClobbers();
   if (!MachineClobbers.empty()) {
 Constraints += ',';

``




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


[clang] Update test intrinsic to support immediates (PR #79174)

2024-01-23 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)


Changes



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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+17-3) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ef764b8e1ac80..e404f92c284aaf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1203,10 +1203,24 @@ static llvm::Value 
*EmitX86BitTestIntrinsic(CodeGenFunction ,
   AsmOS << "bt";
   if (Action)
 AsmOS << Action;
-  AsmOS << SizeSuffix << " $2, ($1)";
 
-  // Build the constraints. FIXME: We should support immediates when possible.
-  std::string Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  // Check if BitPos is a ConstantInt (immediate value)
+  if (llvm::ConstantInt *CI = llvm::dyn_cast(BitPos)) {
+// If it is, use the immediate value in the assembly string
+AsmOS << SizeSuffix << " $" << CI->getZExtValue() << ", ($1)";
+  } else {
+// Otherwise, fall back to the existing behavior
+AsmOS << SizeSuffix << " $2, ($1)";
+  }
+
+  // Build the constraints.
+  std::string Constraints;
+  if (llvm::isa(BitPos)) {
+Constraints = "={@ccc},r,~{cc},~{memory}";
+  } else {
+Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  }
+  
   std::string_view MachineClobbers = CGF.getTarget().getClobbers();
   if (!MachineClobbers.empty()) {
 Constraints += ',';

``




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


[clang] Update test intrinsic to support immediates (PR #79174)

2024-01-23 Thread via cfe-commits

https://github.com/AtariDreams created 
https://github.com/llvm/llvm-project/pull/79174

None

>From 9ed2a138bd980c1c043e1585cb8e5d82a1592f1e Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 12:31:49 -0500
Subject: [PATCH] Update test intrinsic to support immediates

---
 clang/lib/CodeGen/CGBuiltin.cpp | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ef764b8e1ac80e..e404f92c284aafc 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1203,10 +1203,24 @@ static llvm::Value 
*EmitX86BitTestIntrinsic(CodeGenFunction ,
   AsmOS << "bt";
   if (Action)
 AsmOS << Action;
-  AsmOS << SizeSuffix << " $2, ($1)";
 
-  // Build the constraints. FIXME: We should support immediates when possible.
-  std::string Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  // Check if BitPos is a ConstantInt (immediate value)
+  if (llvm::ConstantInt *CI = llvm::dyn_cast(BitPos)) {
+// If it is, use the immediate value in the assembly string
+AsmOS << SizeSuffix << " $" << CI->getZExtValue() << ", ($1)";
+  } else {
+// Otherwise, fall back to the existing behavior
+AsmOS << SizeSuffix << " $2, ($1)";
+  }
+
+  // Build the constraints.
+  std::string Constraints;
+  if (llvm::isa(BitPos)) {
+Constraints = "={@ccc},r,~{cc},~{memory}";
+  } else {
+Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  }
+  
   std::string_view MachineClobbers = CGF.getTarget().getClobbers();
   if (!MachineClobbers.empty()) {
 Constraints += ',';

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


[clang] [clang][modules] Fix CodeGen options that can affect the AST. (PR #78816)

2024-01-23 Thread Juergen Ributzka via cfe-commits

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


[clang] c5a33be - [clang][modules] Fix CodeGen options that can affect the AST. (#78816)

2024-01-23 Thread via cfe-commits

Author: Juergen Ributzka
Date: 2024-01-23T09:30:58-08:00
New Revision: c5a33befcc328339a84c35f6899ff3f3309399fc

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

LOG: [clang][modules] Fix CodeGen options that can affect the AST. (#78816)

`OptimizationLevel` and `OptimizeSize` can affect the generated AST. They 
indirectly affect the `Optimize` and `OptimizeSize` frontend options, which in 
turn set predefined macro definitions.

This fixes rdar://121228252.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/lib/Basic/CodeGenOptions.cpp
clang/test/ClangScanDeps/strip-codegen-args.m

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2c4fb6745bc172..2f2e45d5cf63df 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -12,6 +12,9 @@
 // that have enumeration type and VALUE_CODEGENOPT is a code
 // generation option that describes a value rather than a flag.
 //
+// AFFECTING_VALUE_CODEGENOPT is used for code generation options that can
+// affect the AST.
+//
 
//===--===//
 #ifndef CODEGENOPT
 #  error Define the CODEGENOPT macro to handle language options
@@ -27,6 +30,11 @@ CODEGENOPT(Name, Bits, Default)
 CODEGENOPT(Name, Bits, Default)
 #endif
 
+#ifndef AFFECTING_VALUE_CODEGENOPT
+#  define AFFECTING_VALUE_CODEGENOPT(Name, Bits, Default) \
+VALUE_CODEGENOPT(Name, Bits, Default)
+#endif
+
 CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
 CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
 CODEGENOPT(AsmVerbose, 1, 0) ///< -dA, -fverbose-asm.
@@ -193,8 +201,10 @@ ENUM_CODEGENOPT(ObjCDispatchMethod, 
ObjCDispatchMethodKind, 2, Legacy)
 CODEGENOPT(ObjCConvertMessagesToRuntimeCalls , 1, 1)
 CODEGENOPT(ObjCAvoidHeapifyLocalBlocks, 1, 0)
 
-VALUE_CODEGENOPT(OptimizationLevel, 2, 0) ///< The -O[0-3] option specified.
-VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is 
specified.
+
+// The optimization options affect frontend options, whicn in turn do affect 
the AST.
+AFFECTING_VALUE_CODEGENOPT(OptimizationLevel, 2, 0) ///< The -O[0-3] option 
specified.
+AFFECTING_VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) 
is specified.
 
 CODEGENOPT(AtomicProfileUpdate , 1, 0) ///< Set -fprofile-update=atomic
 /// Choose profile instrumenation kind or no instrumentation.
@@ -437,3 +447,4 @@ CODEGENOPT(CtorDtorReturnThis, 1, 0)
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
+#undef AFFECTING_VALUE_CODEGENOPT

diff  --git a/clang/lib/Basic/CodeGenOptions.cpp 
b/clang/lib/Basic/CodeGenOptions.cpp
index 182d0a2fa4d88f..79d715305ef20b 100644
--- a/clang/lib/Basic/CodeGenOptions.cpp
+++ b/clang/lib/Basic/CodeGenOptions.cpp
@@ -27,6 +27,8 @@ void CodeGenOptions::resetNonModularOptions(StringRef 
ModuleFormat) {
 #define ENUM_DEBUGOPT(Name, Type, Bits, Default)
 #define CODEGENOPT(Name, Bits, Default) Name = Default;
 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default);
+// Do not reset AST affecting code generation options.
+#define AFFECTING_VALUE_CODEGENOPT(Name, Bits, Default)
 #include "clang/Basic/CodeGenOptions.def"
 
   // Next reset all debug options that can always be reset, because they never

diff  --git a/clang/test/ClangScanDeps/strip-codegen-args.m 
b/clang/test/ClangScanDeps/strip-codegen-args.m
index bb7e76e86aa2f9..71171f4983386d 100644
--- a/clang/test/ClangScanDeps/strip-codegen-args.m
+++ b/clang/test/ClangScanDeps/strip-codegen-args.m
@@ -5,11 +5,14 @@
 // RUN: clang-scan-deps -compilation-database %t/cdb1.json -format 
experimental-full > %t/result1.txt
 // RUN: FileCheck %s -input-file %t/result1.txt
 
-// This tests that codegen option that do not affect the AST or generation of 
a module are removed. 
+// This tests that codegen option that do not affect the AST or generation of a
+// module are removed. It also tests that the optimization options that affect
+// the AST are not reset to -O0.
 
 // CHECK:"modules": [
 // CHECK-NEXT: {
 // CHECK:"command-line": [
+// CHECK-NOT:  "-O0"
 // CHECK-NOT:  "-flto"
 // CHECK-NOT:  "-fno-autolink"
 // CHECK-NOT:  "-mrelax-relocations=no"
@@ -23,17 +26,17 @@
 [
   {
 "directory": "DIR",
-"command": "clang -Imodules/A -fmodules 
-fmodules-cache-path=DIR/module-cache -fimplicit-modules -flto -fno-autolink 
-Xclang -mrelax-relocations=no -fsyntax-only DIR/t1.m",
+"command": "clang -Imodules/A -fmodules 
-fmodules-cache-path=DIR/module-cache -fimplicit-modules -O2 -flto 
-fno-autolink -Xclang -mrelax-relocations=no 

[clang] [Clang][Driver] Fix `--save-temps` for OpenCL AoT compilation (PR #78333)

2024-01-23 Thread Joseph Huber via cfe-commits

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


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


[clang] 2531a15 - [OpenACC] Implement 'device_type' clause parsing

2024-01-23 Thread via cfe-commits

Author: erichkeane
Date: 2024-01-23T09:23:42-08:00
New Revision: 2531a15dfd4eafda21622e3a828a93fc9a27e3b6

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

LOG: [OpenACC] Implement 'device_type' clause parsing

'device_type' takes either an asterisk or a list of impementation
specific identifiers. This patch implements the parsing for it.
Additionally, 'dtype' is an alias for 'device_type', though we're
implementing it as its own clause kind to improve future diagnostics, as
this will allow us to differentiate the spellings.

Added: 


Modified: 
clang/include/clang/Basic/OpenACCKinds.h
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseOpenACC.cpp
clang/test/ParserOpenACC/parse-clauses.c

Removed: 




diff  --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 872faec0deaebb..6487a95910eddc 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -232,6 +232,12 @@ enum class OpenACCClauseKind {
   DeviceNum,
   /// 'default_async' clause, allowed on 'set' construct.
   DefaultAsync,
+  /// 'device_type' clause, allowed on Constructs, 'data', 'init', 'shutdown',
+  /// 'set', update', 'loop', 'routine', and Combined constructs.
+  DeviceType,
+  /// 'dtype' clause, an alias for 'device_type', stored separately for
+  /// diagnostic purposes.
+  DType,
 
   /// Represents an invalid clause, for the purposes of parsing.
   Invalid,
@@ -348,6 +354,12 @@ inline const StreamingDiagnostic <<(const 
StreamingDiagnostic ,
   case OpenACCClauseKind::DefaultAsync:
 return Out << "default_async";
 
+  case OpenACCClauseKind::DeviceType:
+return Out << "device_type";
+
+  case OpenACCClauseKind::DType:
+return Out << "dtype";
+
   case OpenACCClauseKind::Invalid:
 return Out << "";
   }

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 6bfcd3a0d84129..ffbde370e8f9c6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3587,6 +3587,9 @@ class Parser : public CodeCompletionHandler {
   /// Parses the clause kind of 'int-expr', which can be any integral
   /// expression.
   ExprResult ParseOpenACCIntExpr();
+  /// Parses the 'device-type-list', which is a list of identifiers.
+  bool ParseOpenACCDeviceTypeList();
+
 private:
   
//======//
   // C++ 14: Templates [temp]

diff  --git a/clang/lib/Parse/ParseOpenACC.cpp 
b/clang/lib/Parse/ParseOpenACC.cpp
index 8020c455feecbc..9f7e63ecdc9518 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -104,7 +104,9 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
   .Case("device", OpenACCClauseKind::Device)
   .Case("device_num", OpenACCClauseKind::DeviceNum)
   .Case("device_resident", OpenACCClauseKind::DeviceResident)
+  .Case("device_type", OpenACCClauseKind::DeviceType)
   .Case("deviceptr", OpenACCClauseKind::DevicePtr)
+  .Case("dtype", OpenACCClauseKind::DType)
   .Case("finalize", OpenACCClauseKind::Finalize)
   .Case("firstprivate", OpenACCClauseKind::FirstPrivate)
   .Case("host", OpenACCClauseKind::Host)
@@ -488,6 +490,8 @@ ClauseParensKind getClauseParensKind(OpenACCDirectiveKind 
DirKind,
   case OpenACCClauseKind::NumWorkers:
   case OpenACCClauseKind::DeviceNum:
   case OpenACCClauseKind::DefaultAsync:
+  case OpenACCClauseKind::DeviceType:
+  case OpenACCClauseKind::DType:
 return ClauseParensKind::Required;
 
   case OpenACCClauseKind::Auto:
@@ -580,6 +584,38 @@ bool Parser::ParseOpenACCClauseVarList(OpenACCClauseKind 
Kind) {
   }
   return false;
 }
+
+/// OpenACC 3.3 Section 2.4:
+/// The argument to the device_type clause is a comma-separated list of one or
+/// more device architecture name identifiers, or an asterisk.
+///
+/// The syntax of the device_type clause is
+/// device_type( * )
+/// device_type( device-type-list )
+///
+/// The device_type clause may be abbreviated to dtype.
+bool Parser::ParseOpenACCDeviceTypeList() {
+
+  if (expectIdentifierOrKeyword(*this)) {
+SkipUntil(tok::r_paren, tok::annot_pragma_openacc_end,
+  Parser::StopBeforeMatch);
+return false;
+  }
+  ConsumeToken();
+
+  while (!getCurToken().isOneOf(tok::r_paren, tok::annot_pragma_openacc_end)) {
+ExpectAndConsume(tok::comma);
+
+if (expectIdentifierOrKeyword(*this)) {
+  SkipUntil(tok::r_paren, tok::annot_pragma_openacc_end,
+Parser::StopBeforeMatch);
+  return false;
+}
+ConsumeToken();
+  }
+  return false;
+}
+
 // The OpenACC Clause List is a comma or space-delimited list of clauses (see
 // the comment on ParseOpenACCClauseList). 

[clang] [clang] Add missing streaming attributes to SVE builtins (PR #79134)

2024-01-23 Thread Sam Tebbs via cfe-commits

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


[clang] 42b28c6 - [clang] Add missing streaming attributes to SVE builtins (#79134)

2024-01-23 Thread via cfe-commits

Author: Sam Tebbs
Date: 2024-01-23T17:21:52Z
New Revision: 42b28c694ebc8a4ab09ef0b419308d47fc1e21ba

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

LOG: [clang] Add missing streaming attributes to SVE builtins (#79134)

This patch adds `IsStreamingCompatible` or `IsStreamingOrSVE2p1` to the
SVE builtins that missed them.

Added: 


Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_x2.c

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 4c5c1b5603f181a..6da30e08e7521e7 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -543,13 +543,13 @@ def SVADRD : SInst<"svadrd[_{0}base]_[{2}]index",  "uud", 
"ilUiUl", MergeNone, "
 

 // Scalar to vector
 
-def SVDUPQ_8  : SInst<"svdupq[_n]_{d}", "d",  "cUc", 
MergeNone>;
-def SVDUPQ_16 : SInst<"svdupq[_n]_{d}", "d",  "sUsh", MergeNone>;
+def SVDUPQ_8  : SInst<"svdupq[_n]_{d}", "d",  "cUc", 
MergeNone, "", [IsStreamingCompatible]>;
+def SVDUPQ_16 : SInst<"svdupq[_n]_{d}", "d",  "sUsh", MergeNone, "", 
[IsStreamingCompatible]>;
 let TargetGuard = "sve,bf16" in {
-  def SVDUPQ_BF16 : SInst<"svdupq[_n]_{d}", "d",  "b", MergeNone>;
+  def SVDUPQ_BF16 : SInst<"svdupq[_n]_{d}", "d",  "b", MergeNone, "", 
[IsStreamingCompatible]>;
 }
-def SVDUPQ_32 : SInst<"svdupq[_n]_{d}", "d",  "iUif", MergeNone>;
-def SVDUPQ_64 : SInst<"svdupq[_n]_{d}", "dss",  "lUld", MergeNone>;
+def SVDUPQ_32 : SInst<"svdupq[_n]_{d}", "d",  "iUif", MergeNone, "", 
[IsStreamingCompatible]>;
+def SVDUPQ_64 : SInst<"svdupq[_n]_{d}", "dss",  "lUld", MergeNone, "", 
[IsStreamingCompatible]>;
 
 multiclass svdup_base {
   def NAME : SInst;
@@ -638,8 +638,8 @@ def SVQADD_N_U : SInst<"svqadd[_n_{d}]", "dda",  
"UcUsUiUl", MergeNone, "aarch64
 def SVQSUB_N_S : SInst<"svqsub[_n_{d}]", "dda",  "csil", MergeNone, 
"aarch64_sve_sqsub_x", [IsStreamingCompatible]>;
 def SVQSUB_N_U : SInst<"svqsub[_n_{d}]", "dda",  "UcUsUiUl", MergeNone, 
"aarch64_sve_uqsub_x", [IsStreamingCompatible]>;
 
-def SVDOT_LANE_S : SInst<"svdot_lane[_{d}]",  "ddqqi",  "il",   MergeNone, 
"aarch64_sve_sdot_lane", [], [ImmCheck<3, ImmCheckLaneIndexDot, 2>]>;
-def SVDOT_LANE_U : SInst<"svdot_lane[_{d}]",  "ddqqi",  "UiUl", MergeNone, 
"aarch64_sve_udot_lane", [], [ImmCheck<3, ImmCheckLaneIndexDot, 2>]>;
+def SVDOT_LANE_S : SInst<"svdot_lane[_{d}]",  "ddqqi",  "il",   MergeNone, 
"aarch64_sve_sdot_lane", [IsStreamingCompatible], [ImmCheck<3, 
ImmCheckLaneIndexDot, 2>]>;
+def SVDOT_LANE_U : SInst<"svdot_lane[_{d}]",  "ddqqi",  "UiUl", MergeNone, 
"aarch64_sve_udot_lane", [IsStreamingCompatible], [ImmCheck<3, 
ImmCheckLaneIndexDot, 2>]>;
 
 

 // Logical operations
@@ -835,14 +835,14 @@ def SVSCALE_N_M : SInst<"svscale[_n_{d}]", "dPdK", "hfd", 
MergeOp1,  "aarch64_sv
 def SVSCALE_N_X : SInst<"svscale[_n_{d}]", "dPdK", "hfd", MergeAny,  
"aarch64_sve_fscale", [IsStreamingCompatible]>;
 def SVSCALE_N_Z : SInst<"svscale[_n_{d}]", "dPdK", "hfd", MergeZero, 
"aarch64_sve_fscale", [IsStreamingCompatible]>;
 
-defm SVMAD_F  : SInstZPZZZ<"svmad",  "hfd", "aarch64_sve_fmad",  
"aarch64_sve_fmla_u",  [ReverseMergeAnyAccOp]>;
-defm SVMLA_F  : SInstZPZZZ<"svmla",  "hfd", "aarch64_sve_fmla",  
"aarch64_sve_fmla_u">;
-defm SVMLS_F  : SInstZPZZZ<"svmls",  "hfd", "aarch64_sve_fmls",  
"aarch64_sve_fmls_u">;
-defm SVMSB_F  : SInstZPZZZ<"svmsb",  "hfd", "aarch64_sve_fmsb",  
"aarch64_sve_fmls_u",  [ReverseMergeAnyAccOp]>;
-defm SVNMAD_F : SInstZPZZZ<"svnmad", "hfd", "aarch64_sve_fnmad", 
"aarch64_sve_fnmla_u", [ReverseMergeAnyAccOp]>;
-defm SVNMLA_F : SInstZPZZZ<"svnmla", "hfd", "aarch64_sve_fnmla", 
"aarch64_sve_fnmla_u">;
-defm SVNMLS_F : SInstZPZZZ<"svnmls", "hfd", "aarch64_sve_fnmls", 
"aarch64_sve_fnmls_u">;
-defm SVNMSB_F : SInstZPZZZ<"svnmsb", "hfd", "aarch64_sve_fnmsb", 
"aarch64_sve_fnmls_u", [ReverseMergeAnyAccOp]>;
+defm SVMAD_F  : SInstZPZZZ<"svmad",  "hfd", "aarch64_sve_fmad",  
"aarch64_sve_fmla_u",  [IsStreamingCompatible, ReverseMergeAnyAccOp]>;
+defm SVMLA_F  : SInstZPZZZ<"svmla",  "hfd", "aarch64_sve_fmla",  
"aarch64_sve_fmla_u", [IsStreamingCompatible]>;
+defm SVMLS_F  : SInstZPZZZ<"svmls",  "hfd", "aarch64_sve_fmls",  
"aarch64_sve_fmls_u", [IsStreamingCompatible]>;
+defm SVMSB_F  : SInstZPZZZ<"svmsb",  "hfd", "aarch64_sve_fmsb",  
"aarch64_sve_fmls_u",  [IsStreamingCompatible, ReverseMergeAnyAccOp]>;
+defm SVNMAD_F : SInstZPZZZ<"svnmad", "hfd", "aarch64_sve_fnmad", 
"aarch64_sve_fnmla_u", [IsStreamingCompatible, 

[clang] [openmp] [libcxx] [mlir] [compiler-rt] [lld] [llvm] [HEXAGON] Inlining Division (PR #79021)

2024-01-23 Thread via cfe-commits

iajbar wrote:

It looks good to me. Thanks Abinaya!

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


[flang] [clang] [libc] [clang-tools-extra] [compiler-rt] [llvm] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-23 Thread Yi Wu via cfe-commits


@@ -122,10 +122,22 @@ void RTNAME(ExecuteCommandLine)(const Descriptor 
, bool wait,
 
   if (exitstat) {
 RUNTIME_CHECK(terminator, IsValidIntDescriptor(exitstat));
+auto exitstatKind{exitstat->type().GetCategoryAndKind()->second};
+if (exitstatKind < 4) {

yi-wu-arm wrote:

Sorry I misunderstood your comment.

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


[libc] [llvm] [clang] [clang-tools-extra] [flang] [compiler-rt] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-23 Thread Peter Klausler via cfe-commits

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


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


[libc] [llvm] [clang] [clang-tools-extra] [flang] [compiler-rt] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-23 Thread Yi Wu via cfe-commits

yi-wu-arm wrote:

> Is there another patch that adds integer kind handling for these two 
> arguments to the runtime implementation?

Thanks for mention the kind code in the runtime! I've added kind code check in 
runtime and provide test, an incorrect kind code would result in a 
`terminator.Crash` "exitstat/cmdstat must have an integer kind greater or equal 
to 4/2 but have: %d". The tests also test the terminator printout.

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


[clang-tools-extra] [libc] [clang] [compiler-rt] [llvm] [flang] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-23 Thread Peter Klausler via cfe-commits


@@ -122,10 +122,22 @@ void RTNAME(ExecuteCommandLine)(const Descriptor 
, bool wait,
 
   if (exitstat) {
 RUNTIME_CHECK(terminator, IsValidIntDescriptor(exitstat));
+auto exitstatKind{exitstat->type().GetCategoryAndKind()->second};
+if (exitstatKind < 4) {

klausler wrote:

The runtime code doesn't need to check these descriptors -- that will have been 
done statically when the intrinsic procedure reference was analyzed!

What has to be done in the runtime is using those descriptors to store the 
integer result values properly, and I think that the code already does that.

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


[clang] [flang] [llvm] [libc] [clang-tools-extra] [compiler-rt] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-23 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/78286

>From d56eca56c8e4c64e649febc43e2c48b6e5146680 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Tue, 16 Jan 2024 14:08:00 +
Subject: [PATCH 1/8] change exitstat and cmsstat from AnyInt to DefaultInt

---
 flang/lib/Evaluate/intrinsics.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Evaluate/intrinsics.cpp 
b/flang/lib/Evaluate/intrinsics.cpp
index da6d5970089884..0b9bdac88a78dc 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1314,9 +1314,9 @@ static const IntrinsicInterface intrinsicSubroutine[]{
 {"execute_command_line",
 {{"command", DefaultChar, Rank::scalar},
 {"wait", AnyLogical, Rank::scalar, Optionality::optional},
-{"exitstat", AnyInt, Rank::scalar, Optionality::optional,
+{"exitstat", DefaultInt, Rank::scalar, Optionality::optional,
 common::Intent::InOut},
-{"cmdstat", AnyInt, Rank::scalar, Optionality::optional,
+{"cmdstat", DefaultInt, Rank::scalar, Optionality::optional,
 common::Intent::Out},
 {"cmdmsg", DefaultChar, Rank::scalar, Optionality::optional,
 common::Intent::InOut}},

>From 2741652cae00ca1a94ae7a3310af1f25308e8105 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Tue, 16 Jan 2024 16:54:42 +
Subject: [PATCH 2/8] add KindCode::greaterEqualToKind

Now execute_command_line will accept exitstat kind>=4, cmdstat kind >=2
---
 flang/lib/Evaluate/intrinsics.cpp | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/flang/lib/Evaluate/intrinsics.cpp 
b/flang/lib/Evaluate/intrinsics.cpp
index 0b9bdac88a78dc..947e31967bdf45 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -77,7 +77,7 @@ static constexpr CategorySet AnyType{IntrinsicType | 
DerivedType};
 
 ENUM_CLASS(KindCode, none, defaultIntegerKind,
 defaultRealKind, // is also the default COMPLEX kind
-doublePrecision, defaultCharKind, defaultLogicalKind,
+doublePrecision, defaultCharKind, defaultLogicalKind, 
greaterAndEqualToKind,
 any, // matches any kind value; each instance is independent
 // match any kind, but all "same" kinds must be equal. For characters, also
 // implies that lengths must be equal.
@@ -104,7 +104,8 @@ ENUM_CLASS(KindCode, none, defaultIntegerKind,
 struct TypePattern {
   CategorySet categorySet;
   KindCode kindCode{KindCode::none};
-  int exactKindValue{0}; // for KindCode::exactKind
+  int kindValue{
+  0}; // for KindCode::exactKind and KindCode::greaterAndEqualToKind
   llvm::raw_ostream (llvm::raw_ostream &) const;
 };
 
@@ -1314,10 +1315,12 @@ static const IntrinsicInterface intrinsicSubroutine[]{
 {"execute_command_line",
 {{"command", DefaultChar, Rank::scalar},
 {"wait", AnyLogical, Rank::scalar, Optionality::optional},
-{"exitstat", DefaultInt, Rank::scalar, Optionality::optional,
-common::Intent::InOut},
-{"cmdstat", DefaultInt, Rank::scalar, Optionality::optional,
-common::Intent::Out},
+{"exitstat",
+TypePattern{IntType, KindCode::greaterAndEqualToKind, 4},
+Rank::scalar, Optionality::optional, common::Intent::InOut},
+{"cmdstat",
+TypePattern{IntType, KindCode::greaterAndEqualToKind, 2},
+Rank::scalar, Optionality::optional, common::Intent::Out},
 {"cmdmsg", DefaultChar, Rank::scalar, Optionality::optional,
 common::Intent::InOut}},
 {}, Rank::elemental, IntrinsicClass::impureSubroutine},
@@ -1834,7 +1837,10 @@ std::optional IntrinsicInterface::Match(
   argOk = true;
   break;
 case KindCode::exactKind:
-  argOk = type->kind() == d.typePattern.exactKindValue;
+  argOk = type->kind() == d.typePattern.kindValue;
+  break;
+case KindCode::greaterAndEqualToKind:
+  argOk = type->kind() >= d.typePattern.kindValue;
   break;
 case KindCode::sameAtom:
   if (!sameArg) {
@@ -2177,8 +2183,9 @@ std::optional IntrinsicInterface::Match(
   resultType = DynamicType{
   GetBuiltinDerivedType(builtinsScope, "__builtin_team_type")};
   break;
+case KindCode::greaterAndEqualToKind:
 case KindCode::exactKind:
-  resultType = DynamicType{*category, result.exactKindValue};
+  resultType = DynamicType{*category, result.kindValue};
   break;
 case KindCode::typeless:
 case KindCode::any:

>From cea484080cba83ad32abb5622048b1864e4a49dc Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Tue, 16 Jan 2024 17:25:12 +
Subject: [PATCH 3/8] doc fixes

---
 flang/docs/Intrinsics.md | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index 

[clang] [llvm] [JITLink][AArch32] Implement Armv5 ldr-pc stubs and use them for all pre-v7 targets (PR #79082)

2024-01-23 Thread Stefan Gränitz via cfe-commits

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


[clang] [flang] [llvm] [libc] [clang-tools-extra] [compiler-rt] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-23 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/78286

>From d56eca56c8e4c64e649febc43e2c48b6e5146680 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Tue, 16 Jan 2024 14:08:00 +
Subject: [PATCH 1/8] change exitstat and cmsstat from AnyInt to DefaultInt

---
 flang/lib/Evaluate/intrinsics.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Evaluate/intrinsics.cpp 
b/flang/lib/Evaluate/intrinsics.cpp
index da6d5970089884..0b9bdac88a78dc 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1314,9 +1314,9 @@ static const IntrinsicInterface intrinsicSubroutine[]{
 {"execute_command_line",
 {{"command", DefaultChar, Rank::scalar},
 {"wait", AnyLogical, Rank::scalar, Optionality::optional},
-{"exitstat", AnyInt, Rank::scalar, Optionality::optional,
+{"exitstat", DefaultInt, Rank::scalar, Optionality::optional,
 common::Intent::InOut},
-{"cmdstat", AnyInt, Rank::scalar, Optionality::optional,
+{"cmdstat", DefaultInt, Rank::scalar, Optionality::optional,
 common::Intent::Out},
 {"cmdmsg", DefaultChar, Rank::scalar, Optionality::optional,
 common::Intent::InOut}},

>From 2741652cae00ca1a94ae7a3310af1f25308e8105 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Tue, 16 Jan 2024 16:54:42 +
Subject: [PATCH 2/8] add KindCode::greaterEqualToKind

Now execute_command_line will accept exitstat kind>=4, cmdstat kind >=2
---
 flang/lib/Evaluate/intrinsics.cpp | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/flang/lib/Evaluate/intrinsics.cpp 
b/flang/lib/Evaluate/intrinsics.cpp
index 0b9bdac88a78dc..947e31967bdf45 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -77,7 +77,7 @@ static constexpr CategorySet AnyType{IntrinsicType | 
DerivedType};
 
 ENUM_CLASS(KindCode, none, defaultIntegerKind,
 defaultRealKind, // is also the default COMPLEX kind
-doublePrecision, defaultCharKind, defaultLogicalKind,
+doublePrecision, defaultCharKind, defaultLogicalKind, 
greaterAndEqualToKind,
 any, // matches any kind value; each instance is independent
 // match any kind, but all "same" kinds must be equal. For characters, also
 // implies that lengths must be equal.
@@ -104,7 +104,8 @@ ENUM_CLASS(KindCode, none, defaultIntegerKind,
 struct TypePattern {
   CategorySet categorySet;
   KindCode kindCode{KindCode::none};
-  int exactKindValue{0}; // for KindCode::exactKind
+  int kindValue{
+  0}; // for KindCode::exactKind and KindCode::greaterAndEqualToKind
   llvm::raw_ostream (llvm::raw_ostream &) const;
 };
 
@@ -1314,10 +1315,12 @@ static const IntrinsicInterface intrinsicSubroutine[]{
 {"execute_command_line",
 {{"command", DefaultChar, Rank::scalar},
 {"wait", AnyLogical, Rank::scalar, Optionality::optional},
-{"exitstat", DefaultInt, Rank::scalar, Optionality::optional,
-common::Intent::InOut},
-{"cmdstat", DefaultInt, Rank::scalar, Optionality::optional,
-common::Intent::Out},
+{"exitstat",
+TypePattern{IntType, KindCode::greaterAndEqualToKind, 4},
+Rank::scalar, Optionality::optional, common::Intent::InOut},
+{"cmdstat",
+TypePattern{IntType, KindCode::greaterAndEqualToKind, 2},
+Rank::scalar, Optionality::optional, common::Intent::Out},
 {"cmdmsg", DefaultChar, Rank::scalar, Optionality::optional,
 common::Intent::InOut}},
 {}, Rank::elemental, IntrinsicClass::impureSubroutine},
@@ -1834,7 +1837,10 @@ std::optional IntrinsicInterface::Match(
   argOk = true;
   break;
 case KindCode::exactKind:
-  argOk = type->kind() == d.typePattern.exactKindValue;
+  argOk = type->kind() == d.typePattern.kindValue;
+  break;
+case KindCode::greaterAndEqualToKind:
+  argOk = type->kind() >= d.typePattern.kindValue;
   break;
 case KindCode::sameAtom:
   if (!sameArg) {
@@ -2177,8 +2183,9 @@ std::optional IntrinsicInterface::Match(
   resultType = DynamicType{
   GetBuiltinDerivedType(builtinsScope, "__builtin_team_type")};
   break;
+case KindCode::greaterAndEqualToKind:
 case KindCode::exactKind:
-  resultType = DynamicType{*category, result.exactKindValue};
+  resultType = DynamicType{*category, result.kindValue};
   break;
 case KindCode::typeless:
 case KindCode::any:

>From cea484080cba83ad32abb5622048b1864e4a49dc Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Tue, 16 Jan 2024 17:25:12 +
Subject: [PATCH 3/8] doc fixes

---
 flang/docs/Intrinsics.md | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index 

[clang] [clang] Document the type_visibility attribute (PR #79157)

2024-01-23 Thread Nikolas Klauser via cfe-commits


@@ -5557,6 +5557,21 @@ See :doc:`LTOVisibility`.
   }];
 }
 
+def TypeVisibilityDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+The ``type_visibility`` attribute allows the ELF visibility of a type and its 
vague
+linkage objects (vtable, typeinfo, typeinfo name) to be controlled separately 
from
+the visibility of functions and data members of the type.
+
+For example, this can be used to give default visibility to the typeinfo and 
the vtable
+of a type while still keeping hidden visibility on its member functions and 
static data
+members.
+
+This attribute can only be applied to types and namespaces.

philnik777 wrote:

Maybe we also want to document the behavior of adding both 
`clang::type_visibility` and `gnu::visibility` to a namespace? (I think 
`clang::type_visibility` overrides `gnu::visibility`)

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-23 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

@sdesmalen-arm This appears to be failing on some buildbots: 
https://lab.llvm.org/buildbot/#/builders/176/builds/8232
```
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/utils/lit/lit/TestingConfig.py:152:
 fatal: unable to parse config file 
'/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/runtimes/runtimes-bins/compiler-rt/unittests/lit.common.unit.configured',
 traceback: Traceback (most recent call last):
  File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/utils/lit/lit/TestingConfig.py",
 line 140, in load_from_path
exec(compile(data, path, "exec"), cfg_globals, None)
  File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/runtimes/runtimes-bins/compiler-rt/unittests/lit.common.unit.configured",
 line 23
config.aarch64_sme =
^
SyntaxError: invalid syntax
```

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


[clang] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-01-23 Thread Petr Hosek via cfe-commits


@@ -30,26 +30,28 @@ def findFilesWithExtension(path, extension):
 
 
 def clean(args):
-if len(args) != 2:
+if len(args) < 2:
 print(
-"Usage: %s clean  \n" % __file__
+"Usage: %s clean  \n" % __file__
 + "\tRemoves all files with extension from ."
 )
 return 1
-for filename in findFilesWithExtension(args[0], args[1]):
-os.remove(filename)
+for path in args[1:-1]:
+for filename in findFilesWithExtension(path, args[-1]):
+os.remove(filename)
 return 0
 
 
 def merge(args):
-if len(args) != 3:
+if len(args) < 3:
 print(
-"Usage: %s merge   \n" % __file__
+"Usage: %s merge   \n" % __file__
 + "\tMerges all profraw files from path into output."
 )
 return 1
 cmd = [args[0], "merge", "-o", args[1]]
-cmd.extend(findFilesWithExtension(args[2], "profraw"))
+for i in range(2, len(args)):
+cmd.extend(findFilesWithExtension(args[i], "profraw"))

petrhosek wrote:

```suggestion
for path in args[2:]:
cmd.extend(findFilesWithExtension(path, "profraw"))
```

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


[clang] [llvm] [CMake][PGO] Add option for using an external project to generate profile data (PR #78879)

2024-01-23 Thread Petr Hosek via cfe-commits


@@ -1,6 +1,10 @@
+include(LLVMExternalProjectUtils)
+
 set(CLANG_PGO_TRAINING_DATA "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH
   "The path to a lit testsuite containing samples for PGO and order file 
generation"
   )
+set(CLANG_PGO_TRAINING_DATA_SOURCE_DIR OFF CACHE STRING "Path to source 
directory containing cmake project with source files to use for generating pgo 
data")
+set(CLANG_PERF_TRAINING_DEPS "" CACHE STRING "Extra dependencies needed to 
build the PGO training data.")

petrhosek wrote:

I don't see this variable being used anywhere, should it be added as a 
dependency of `generate-profraw-external`? I'd also consider naming it 
`CLANG_PGO_TRAINING_DEPS` for consistency with other variables in this file.

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


[clang] [mlir] [llvm] [AArch64] Replace LLVM IR function attributes for PSTATE.ZA. (PR #79166)

2024-01-23 Thread via cfe-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 5daf674feba0f57b083113ad7ed486cad433a916 
04c7b856bac07476a3410f1334e703054bd3859d -- clang/lib/CodeGen/CGBuiltin.cpp 
clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CodeGenModule.cpp 
clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c 
clang/test/Modules/aarch64-sme-keywords.cppm llvm/lib/IR/Verifier.cpp 
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp 
llvm/lib/Target/AArch64/SMEABIPass.cpp 
llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp 
llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.h 
llvm/unittests/Target/AArch64/SMEAttributesTest.cpp 
mlir/lib/Target/LLVMIR/ModuleImport.cpp 
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 53d923ced8..b04d39c700 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2155,14 +2155,13 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, 
AttributeList Attrs,
V);
   }
 
-  Check(
-  (Attrs.hasFnAttr("aarch64_new_za") + Attrs.hasFnAttr("aarch64_in_za") +
-   Attrs.hasFnAttr("aarch64_inout_za") +
-   Attrs.hasFnAttr("aarch64_out_za") +
-   Attrs.hasFnAttr("aarch64_preserves_za")) <= 1,
-  "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
-  "'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive",
-  V);
+  Check((Attrs.hasFnAttr("aarch64_new_za") + Attrs.hasFnAttr("aarch64_in_za") +
+ Attrs.hasFnAttr("aarch64_inout_za") +
+ Attrs.hasFnAttr("aarch64_out_za") +
+ Attrs.hasFnAttr("aarch64_preserves_za")) <= 1,
+"Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
+"'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive",
+V);
 
   Check(
   (Attrs.hasFnAttr("aarch64_new_zt0") + Attrs.hasFnAttr("aarch64_in_zt0") +
diff --git a/llvm/lib/Target/AArch64/SMEABIPass.cpp 
b/llvm/lib/Target/AArch64/SMEABIPass.cpp
index bee5d63c5a..23b3cc9ec6 100644
--- a/llvm/lib/Target/AArch64/SMEABIPass.cpp
+++ b/llvm/lib/Target/AArch64/SMEABIPass.cpp
@@ -60,9 +60,8 @@ FunctionPass *llvm::createSMEABIPass() { return new SMEABI(); 
}
 void emitTPIDR2Save(Module *M, IRBuilder<> ) {
   auto *TPIDR2SaveTy =
   FunctionType::get(Builder.getVoidTy(), {}, /*IsVarArgs=*/false);
-  auto Attrs =
-  AttributeList()
-  .addFnAttribute(M->getContext(), "aarch64_pstate_sm_compatible");
+  auto Attrs = AttributeList().addFnAttribute(M->getContext(),
+  "aarch64_pstate_sm_compatible");
   FunctionCallee Callee =
   M->getOrInsertFunction("__arm_tpidr2_save", TPIDR2SaveTy, Attrs);
   CallInst *Call = Builder.CreateCall(Callee);
diff --git a/llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp 
b/llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp
index ac07274a36..d399e0ac07 100644
--- a/llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp
+++ b/llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp
@@ -52,7 +52,7 @@ SMEAttrs::SMEAttrs(StringRef FuncName) : Bitmask(0) {
 Bitmask |= (SMEAttrs::SM_Compatible | SMEAttrs::SME_ABI_Routine);
   if (FuncName == "__arm_tpidr2_restore")
 Bitmask |= SMEAttrs::SM_Compatible | encodeZAState(StateValue::In) |
-SMEAttrs::SME_ABI_Routine;
+   SMEAttrs::SME_ABI_Routine;
 }
 
 SMEAttrs::SMEAttrs(const AttributeList ) {
diff --git a/llvm/unittests/Target/AArch64/SMEAttributesTest.cpp 
b/llvm/unittests/Target/AArch64/SMEAttributesTest.cpp
index 2c1c92dfa6..6036999e34 100644
--- a/llvm/unittests/Target/AArch64/SMEAttributesTest.cpp
+++ b/llvm/unittests/Target/AArch64/SMEAttributesTest.cpp
@@ -38,22 +38,21 @@ TEST(SMEAttributes, Constructors) {
   ->getFunction("foo"))
   .hasStreamingCompatibleInterface());
 
-
   ASSERT_TRUE(
   SA(*parseIR("declare void @foo() \"aarch64_in_za\"")->getFunction("foo"))
   .isInZA());
-  ASSERT_TRUE(SA(*parseIR("declare void @foo() \"aarch64_out_za\"")
-  ->getFunction("foo"))
-  .isOutZA());
+  ASSERT_TRUE(
+  SA(*parseIR("declare void @foo() 
\"aarch64_out_za\"")->getFunction("foo"))
+  .isOutZA());
   ASSERT_TRUE(SA(*parseIR("declare void @foo() \"aarch64_inout_za\"")
   ->getFunction("foo"))
   .isInOutZA());
   ASSERT_TRUE(SA(*parseIR("declare void @foo() \"aarch64_preserves_za\"")
   ->getFunction("foo"))
   .isPreservesZA());
-  ASSERT_TRUE(SA(*parseIR("declare void @foo() \"aarch64_new_za\"")
-  ->getFunction("foo"))
-  .isNewZA());
+  ASSERT_TRUE(

[clang] [llvm] [mlir] [AArch64] Replace LLVM IR function attributes for PSTATE.ZA. (PR #79166)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-llvm

Author: Sander de Smalen (sdesmalen-arm)


Changes

Since https://github.com/ARM-software/acle/pull/276 the ACLE defines attributes 
to better describe the use of a given SME state.

Previously the attributes merely described the possibility of it being 'shared' 
or 'preserved', whereas the new attributes have more semantics and also 
describe how the data flows through the program.

For ZT0 we already had to add new LLVM IR attributes:
* arm_new_zt0
* arm_in_zt0
* arm_out_zt0
* arm_inout_zt0
* arm_preserves_zt0

We have now done the same for ZA, such that we add:
* arm_new_za   (previously `aarch64_pstate_za_new`)
* arm_in_za(more specific variation of `aarch64_pstate_za_shared`)
* arm_out_za   (more specific variation of `aarch64_pstate_za_shared`)
* arm_inout_za (more specific variation of `aarch64_pstate_za_shared`)
* arm_preserves_za (previously `aarch64_pstate_za_shared, 
aarch64_pstate_za_preserved`)

This explicitly removes 'pstate' from the name, because with SME2 and the new 
ACLE attributes there is a difference between "sharing ZA" (sharing the ZA 
matrix register with the caller) and "sharing PSTATE.ZA" (sharing either the ZA 
or ZT0 register, both part of PSTATE.ZA with the caller).

---

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


28 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2-4) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+8-8) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp 
(+9-9) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c (+2-2) 
- (modified) clang/test/Modules/aarch64-sme-keywords.cppm (+5-5) 
- (modified) llvm/docs/AArch64SME.rst (+21-16) 
- (modified) llvm/lib/IR/Verifier.cpp (+8-11) 
- (modified) llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/SMEABIPass.cpp (+4-5) 
- (modified) llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp (+19-13) 
- (modified) llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.h (+24-9) 
- (modified) llvm/test/CodeGen/AArch64/sme-disable-gisel-fisel.ll (+5-5) 
- (modified) llvm/test/CodeGen/AArch64/sme-lazy-save-call-remarks.ll (+3-3) 
- (modified) llvm/test/CodeGen/AArch64/sme-lazy-save-call.ll (+4-4) 
- (modified) llvm/test/CodeGen/AArch64/sme-new-za-function.ll (+4-4) 
- (modified) llvm/test/CodeGen/AArch64/sme-shared-za-interface.ll (+2-2) 
- (modified) llvm/test/CodeGen/AArch64/sme-zt0-state.ll (+11-11) 
- (modified) llvm/test/Transforms/Inline/AArch64/sme-pstateza-attrs.ll (+11-11) 
- (modified) llvm/test/Verifier/sme-attributes.ll (+28-4) 
- (modified) llvm/unittests/Target/AArch64/SMEAttributesTest.cpp (+77-39) 
- (modified) mlir/include/mlir/Dialect/ArmSME/Transforms/Passes.td (+25-10) 
- (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td (+3-1) 
- (modified) mlir/lib/Target/LLVMIR/ModuleImport.cpp (+13-8) 
- (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+8-4) 
- (modified) mlir/test/Dialect/ArmSME/enable-arm-za.mlir (+12-4) 
- (modified) mlir/test/Target/LLVMIR/Import/function-attributes.ll (+19-7) 
- (modified) mlir/test/Target/LLVMIR/llvmir.mlir (+19-5) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ef764b8e1ac80..ce90a36f5ac37f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10676,10 +10676,8 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 llvm::FunctionType::get(StructType::get(CGM.Int64Ty, CGM.Int64Ty), {},
 false),
 "__arm_sme_state"));
-auto Attrs =
-AttributeList()
-.addFnAttribute(getLLVMContext(), "aarch64_pstate_sm_compatible")
-.addFnAttribute(getLLVMContext(), "aarch64_pstate_za_preserved");
+auto Attrs = AttributeList().addFnAttribute(getLLVMContext(),
+
"aarch64_pstate_sm_compatible");
 CI->setAttributes(Attrs);
 CI->setCallingConv(
 llvm::CallingConv::
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 28c211aa631e4d..657666c9bda4ec 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1774,14 +1774,14 @@ static void 
AddAttributesFromFunctionProtoType(ASTContext ,
 FuncAttrs.addAttribute("aarch64_pstate_sm_compatible");
 
   // ZA
-  if (FunctionType::getArmZAState(SMEBits) == FunctionType::ARM_Out ||
-  FunctionType::getArmZAState(SMEBits) == FunctionType::ARM_InOut)
-FuncAttrs.addAttribute("aarch64_pstate_za_shared");
-  if (FunctionType::getArmZAState(SMEBits) == FunctionType::ARM_Preserves ||
-  FunctionType::getArmZAState(SMEBits) == FunctionType::ARM_In) {
-FuncAttrs.addAttribute("aarch64_pstate_za_shared");
-

[clang] [llvm] [mlir] [AArch64] Replace LLVM IR function attributes for PSTATE.ZA. (PR #79166)

2024-01-23 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm created 
https://github.com/llvm/llvm-project/pull/79166

Since https://github.com/ARM-software/acle/pull/276 the ACLE defines attributes 
to better describe the use of a given SME state.

Previously the attributes merely described the possibility of it being 'shared' 
or 'preserved', whereas the new attributes have more semantics and also 
describe how the data flows through the program.

For ZT0 we already had to add new LLVM IR attributes:
* arm_new_zt0
* arm_in_zt0
* arm_out_zt0
* arm_inout_zt0
* arm_preserves_zt0

We have now done the same for ZA, such that we add:
* arm_new_za   (previously `aarch64_pstate_za_new`)
* arm_in_za(more specific variation of `aarch64_pstate_za_shared`)
* arm_out_za   (more specific variation of `aarch64_pstate_za_shared`)
* arm_inout_za (more specific variation of `aarch64_pstate_za_shared`)
* arm_preserves_za (previously `aarch64_pstate_za_shared, 
aarch64_pstate_za_preserved`)

This explicitly removes 'pstate' from the name, because with SME2 and the new 
ACLE attributes there is a difference between "sharing ZA" (sharing the ZA 
matrix register with the caller) and "sharing PSTATE.ZA" (sharing either the ZA 
or ZT0 register, both part of PSTATE.ZA with the caller).

>From 04c7b856bac07476a3410f1334e703054bd3859d Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Mon, 22 Jan 2024 16:50:41 +0100
Subject: [PATCH] [AArch64] Replace LLVM IR function attributes for PSTATE.ZA.

Since https://github.com/ARM-software/acle/pull/276 the ACLE
defines attributes to better describe the use of a given SME state.

Previously the attributes merely described the possibility of it being
'shared' or 'preserved', whereas the new attributes have more semantics
and also describe how the data flows through the program.

For ZT0 we already had to add new LLVM IR attributes:
* arm_new_zt0
* arm_in_zt0
* arm_out_zt0
* arm_inout_zt0
* arm_preserves_zt0

We have now done the same for ZA, such that we add:
* arm_new_za   (previously `aarch64_pstate_za_new`)
* arm_in_za(more specific variation of `aarch64_pstate_za_shared`)
* arm_out_za   (more specific variation of `aarch64_pstate_za_shared`)
* arm_inout_za (more specific variation of `aarch64_pstate_za_shared`)
* arm_preserves_za (previously `aarch64_pstate_za_shared, 
aarch64_pstate_za_preserved`)

This explicitly removes 'pstate' from the name, because with SME2 and
the new ACLE attributes there is a difference between "sharing ZA" (sharing
the ZA matrix register with the caller) and "sharing PSTATE.ZA" (sharing
either the ZA or ZT0 register, both part of PSTATE.ZA with the caller).
---
 clang/lib/CodeGen/CGBuiltin.cpp   |   6 +-
 clang/lib/CodeGen/CGCall.cpp  |  16 +--
 clang/lib/CodeGen/CodeGenModule.cpp   |   2 +-
 .../aarch64-sme-attrs.cpp |  18 +--
 .../aarch64-sme-intrinsics/acle_sme_zero.c|   4 +-
 clang/test/Modules/aarch64-sme-keywords.cppm  |  10 +-
 llvm/docs/AArch64SME.rst  |  37 +++---
 llvm/lib/IR/Verifier.cpp  |  19 ++-
 .../AArch64/AArch64TargetTransformInfo.cpp|   2 +-
 llvm/lib/Target/AArch64/SMEABIPass.cpp|   9 +-
 .../AArch64/Utils/AArch64SMEAttributes.cpp|  32 +++--
 .../AArch64/Utils/AArch64SMEAttributes.h  |  33 +++--
 .../AArch64/sme-disable-gisel-fisel.ll|  10 +-
 .../AArch64/sme-lazy-save-call-remarks.ll |   6 +-
 .../CodeGen/AArch64/sme-lazy-save-call.ll |   8 +-
 .../CodeGen/AArch64/sme-new-za-function.ll|   8 +-
 .../AArch64/sme-shared-za-interface.ll|   4 +-
 llvm/test/CodeGen/AArch64/sme-zt0-state.ll|  22 ++--
 .../Inline/AArch64/sme-pstateza-attrs.ll  |  22 ++--
 llvm/test/Verifier/sme-attributes.ll  |  32 -
 .../Target/AArch64/SMEAttributesTest.cpp  | 116 --
 .../mlir/Dialect/ArmSME/Transforms/Passes.td  |  35 --
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |   4 +-
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  21 ++--
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  12 +-
 mlir/test/Dialect/ArmSME/enable-arm-za.mlir   |  16 ++-
 .../LLVMIR/Import/function-attributes.ll  |  26 ++--
 mlir/test/Target/LLVMIR/llvmir.mlir   |  24 +++-
 28 files changed, 348 insertions(+), 206 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ef764b8e1ac80e..ce90a36f5ac37fb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10676,10 +10676,8 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 llvm::FunctionType::get(StructType::get(CGM.Int64Ty, CGM.Int64Ty), {},
 false),
 "__arm_sme_state"));
-auto Attrs =
-AttributeList()
-.addFnAttribute(getLLVMContext(), "aarch64_pstate_sm_compatible")
-.addFnAttribute(getLLVMContext(), "aarch64_pstate_za_preserved");
+auto 

[clang] [Clang][AArch64] Add diagnostics for builtins that use ZT0. (PR #79140)

2024-01-23 Thread Sander de Smalen via cfe-commits

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


[clang] 1f6f199 - [Clang][AArch64] Add diagnostics for builtins that use ZT0. (#79140)

2024-01-23 Thread via cfe-commits

Author: Sander de Smalen
Date: 2024-01-23T17:41:12+01:00
New Revision: 1f6f19935c1b4512190f1bc94ebf94f3d2b69911

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

LOG: [Clang][AArch64] Add diagnostics for builtins that use ZT0. (#79140)

Similar to what we did for ZA, this patch adds diagnostics to flag when
using a ZT0 builtin in a function that does not have ZT0 state.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/arm_sme.td
clang/include/clang/Basic/arm_sve_sme_incl.td
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_zero_zt.c
clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp
clang/utils/TableGen/SveEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e027e754477fcf4..a1c32abb4dcd880 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3170,6 +3170,9 @@ def warn_attribute_arm_sm_incompat_builtin : Warning<
 def warn_attribute_arm_za_builtin_no_za_state : Warning<
   "builtin call is not valid when calling from a function without active ZA 
state">,
   InGroup>;
+def warn_attribute_arm_zt0_builtin_no_zt0_state : Warning<
+  "builtin call is not valid when calling from a function without active ZT0 
state">,
+  InGroup>;
 def err_sve_vector_in_non_sve_target : Error<
   "SVE vector type %0 cannot be used in a target without sve">;
 def err_attribute_riscv_rvv_bits_unsupported : Error<

diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 4fb50b8e4e4e565..695e1bddf9ffc61 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -636,37 +636,37 @@ let TargetGuard = "sme2,sme-i16i64" in {
 // Spill and fill of ZT0
 //
 let TargetGuard = "sme2" in {
-  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible], [ImmCheck<0, ImmCheck0_0>]>;
-  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible], [ImmCheck<0, ImmCheck0_0>]>;
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsInOutZT0], [ImmCheck<0, 
ImmCheck0_0>]>;
+  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>;
 }
 
 //
 // Zero ZT0
 //
 let TargetGuard = "sme2" in {
-  def SVZERO_ZT : Inst<"svzero_zt", "vi", "", MergeNone, 
"aarch64_sme_zero_zt", [IsOverloadNone, IsStreamingCompatible], [ImmCheck<0, 
ImmCheck0_0>]>;
+  def SVZERO_ZT : Inst<"svzero_zt", "vi", "", MergeNone, 
"aarch64_sme_zero_zt", [IsOverloadNone, IsStreamingCompatible, IsOutZT0], 
[ImmCheck<0, ImmCheck0_0>]>;
 }
 
 //
 // lookup table expand four contiguous registers
 //
 let TargetGuard = "sme2" in {
-  def SVLUTI2_LANE_ZT_X4 : Inst<"svluti2_lane_zt_{d}_x4", "4.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x4", [IsStreaming], 
[ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
-  def SVLUTI4_LANE_ZT_X4 : Inst<"svluti4_lane_zt_{d}_x4", "4.di[i", 
"sUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x4", [IsStreaming], 
[ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_1>]>;
+  def SVLUTI2_LANE_ZT_X4 : Inst<"svluti2_lane_zt_{d}_x4", "4.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x4", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
+  def SVLUTI4_LANE_ZT_X4 : Inst<"svluti4_lane_zt_{d}_x4", "4.di[i", 
"sUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x4", [IsStreaming, IsInZT0], 
[ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_1>]>;
 }
 
 //
 // lookup table expand one register
 //
 let TargetGuard = "sme2" in {
-  def SVLUTI2_LANE_ZT : Inst<"svluti2_lane_zt_{d}", "di[i", "cUcsUsiUibhf", 
MergeNone, "aarch64_sme_luti2_lane_zt", [IsStreaming], [ImmCheck<0, 
ImmCheck0_0>, ImmCheck<2, ImmCheck0_15>]>;
-  def SVLUTI4_LANE_ZT : Inst<"svluti4_lane_zt_{d}", "di[i", "cUcsUsiUibhf", 

[clang] [clang][analyzer] Add missing stream related functions to StdLibraryFunctionsChecker. (PR #76979)

2024-01-23 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/76979

From e4932449fd2407cee888f3f0e5dc00c6ce637221 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 4 Jan 2024 18:16:12 +0100
Subject: [PATCH 1/6] [clang][analyzer] Add missing stream related functions to
 StdCLibraryFunctionsChecker.

Some stream functions were recently added to StreamChecker that were not 
modeled by
StdCLibraryFunctionsChecker. To ensure consistency these functions are added
to the other checker too.
Some of the related tests are re-organized.
---
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  85 --
 clang/test/Analysis/std-c-library-functions.c |   4 +-
 clang/test/Analysis/stream-error.c|  26 -
 clang/test/Analysis/stream-noopen.c   | 110 ++
 clang/test/Analysis/stream.c  |  25 +++-
 5 files changed, 189 insertions(+), 61 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index fcd907a9bb0da0..3f6c5692caef40 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2023,13 +2023,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
{{EOFv, EOFv}, {0, UCharRangeMax}},
"an unsigned char value or EOF")));
 
-  // The getc() family of functions that returns either a char or an EOF.
-  addToFunctionSummaryMap(
-  {"getc", "fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
-  Summary(NoEvalCall)
-  .Case({ReturnValueCondition(WithinRange,
-  {{EOFv, EOFv}, {0, UCharRangeMax}})},
-ErrnoIrrelevant));
   addToFunctionSummaryMap(
   "getchar", Signature(ArgTypes{}, RetType{IntTy}),
   Summary(NoEvalCall)
@@ -2139,7 +2132,17 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 std::move(GetenvSummary));
   }
 
-  if (ModelPOSIX) {
+  if (!ModelPOSIX) {
+// Without POSIX use of 'errno' is not specified (in these cases).
+// Add these functions without 'errno' checks.
+addToFunctionSummaryMap(
+{"getc", "fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange,
+{{EOFv, EOFv}, {0, UCharRangeMax}})},
+  ErrnoIrrelevant)
+.ArgConstraint(NotNull(ArgNo(0;
+  } else {
 const auto ReturnsZeroOrMinusOne =
 ConstraintSet{ReturnValueCondition(WithinRange, Range(-1, 0))};
 const auto ReturnsZero =
@@ -2204,6 +2207,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(1)))
 .ArgConstraint(NotNull(ArgNo(2;
 
+// FILE *fdopen(int fd, const char *mode);
+addToFunctionSummaryMap(
+"fdopen",
+Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fclose(FILE *stream);
 addToFunctionSummaryMap(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
@@ -2212,6 +2225,59 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+std::optional Off_tTy = lookupTy("off_t");
+std::optional Off_tMax = getMaxValue(Off_tTy);
+
+// int fgetc(FILE *stream);
+// 'getc' is the same as 'fgetc' but may be a macro
+addToFunctionSummaryMap(
+{"getc", "fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, UCharRangeMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
+// int fputc(int c, FILE *stream);
+// 'putc' is the same as 'fputc' but may be a macro
+addToFunctionSummaryMap(
+{"putc", "fputc"},
+Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+

[clang] [clang] Add missing streaming attributes to SVE builtins (PR #79134)

2024-01-23 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.


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


[clang] [clang][dataflow] Eliminate two uses of `RecordValue::getLoc()`. (PR #79163)

2024-01-23 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


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


[clang-tools-extra] [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (PR #77246)

2024-01-23 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/77246

>From b2e230f90f97c0fb3385ab05d0217371b72b9a88 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 7 Jan 2024 18:52:05 +
Subject: [PATCH 1/2] [clang-tidy] Add support for lambdas in
 cppcoreguidelines-owning-memory

Implement proper support for lambdas and sub-functions/classes.
Moved from https://reviews.llvm.org/D157285

Fixes: #59389
---
 .../cppcoreguidelines/OwningMemoryCheck.cpp   | 71 --
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +-
 .../cppcoreguidelines/owning-memory.cpp   | 95 +++
 3 files changed, 164 insertions(+), 8 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
index 9215b833573afdd..89450149820f301 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
@@ -19,6 +19,18 @@ using namespace clang::ast_matchers::internal;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+AST_MATCHER_P(LambdaExpr, hasCallOperator,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.getCallOperator(), Finder, Builder);
+}
+
+AST_MATCHER_P(LambdaExpr, hasLambdaBody, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return InnerMatcher.matches(*Node.getBody(), Finder, Builder);
+}
+} // namespace
+
 void OwningMemoryCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "LegacyResourceProducers", LegacyResourceProducers);
   Options.store(Opts, "LegacyResourceConsumers", LegacyResourceConsumers);
@@ -55,6 +67,8 @@ void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) 
{
 CreatesLegacyOwner, LegacyOwnerCast);
 
   const auto ConsideredOwner = eachOf(IsOwnerType, CreatesOwner);
+  const auto ScopeDeclaration = anyOf(translationUnitDecl(), namespaceDecl(),
+  recordDecl(), functionDecl());
 
   // Find delete expressions that delete non-owners.
   Finder->addMatcher(
@@ -147,10 +161,52 @@ void OwningMemoryCheck::registerMatchers(MatchFinder 
*Finder) {
   // Matching on functions, that return an owner/resource, but don't declare
   // their return type as owner.
   Finder->addMatcher(
-  functionDecl(hasDescendant(returnStmt(hasReturnValue(ConsideredOwner))
- .bind("bad_owner_return")),
-   unless(returns(qualType(hasDeclaration(OwnerDecl)
-  .bind("function_decl"),
+  functionDecl(
+  decl().bind("function_decl"),
+  hasBody(stmt(
+  stmt().bind("body"),
+  hasDescendant(
+  returnStmt(hasReturnValue(ConsideredOwner),
+ // Ignore sub-lambda expressions
+ hasAncestor(stmt(anyOf(equalsBoundNode("body"),
+lambdaExpr()))
+ .bind("scope")),
+ hasAncestor(stmt(equalsBoundNode("scope"),
+  equalsBoundNode("body"))),
+ // Ignore sub-functions
+ hasAncestor(functionDecl().bind("context")),
+ hasAncestor(functionDecl(
+ equalsBoundNode("context"),
+ equalsBoundNode("function_decl"
+  .bind("bad_owner_return",
+  returns(qualType(qualType().bind("result"),
+   unless(hasDeclaration(OwnerDecl),
+  this);
+
+  // Matching on lambdas, that return an owner/resource, but don't declare
+  // their return type as owner.
+  Finder->addMatcher(
+  lambdaExpr(
+  hasAncestor(decl(ScopeDeclaration).bind("scope-decl")),
+  hasLambdaBody(stmt(
+  stmt().bind("body"),
+  hasDescendant(
+  returnStmt(
+  hasReturnValue(ConsideredOwner),
+  // Ignore sub-lambdas
+  hasAncestor(
+  stmt(anyOf(equalsBoundNode("body"), lambdaExpr()))
+  .bind("scope")),
+  hasAncestor(stmt(equalsBoundNode("scope"),
+   equalsBoundNode("body"))),
+  // Ignore sub-functions
+  hasAncestor(decl(ScopeDeclaration).bind("context")),
+  hasAncestor(decl(equalsBoundNode("context"),
+   equalsBoundNode("scope-decl"
+  .bind("bad_owner_return",
+  hasCallOperator(returns(qualType(qualType().bind("result"),
+   

[clang-tools-extra] [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (PR #77246)

2024-01-23 Thread Piotr Zegar via cfe-commits


@@ -147,10 +161,52 @@ void OwningMemoryCheck::registerMatchers(MatchFinder 
*Finder) {
   // Matching on functions, that return an owner/resource, but don't declare
   // their return type as owner.
   Finder->addMatcher(
-  functionDecl(hasDescendant(returnStmt(hasReturnValue(ConsideredOwner))
- .bind("bad_owner_return")),
-   unless(returns(qualType(hasDeclaration(OwnerDecl)
-  .bind("function_decl"),
+  functionDecl(
+  decl().bind("function_decl"),
+  hasBody(stmt(
+  stmt().bind("body"),
+  hasDescendant(
+  returnStmt(hasReturnValue(ConsideredOwner),
+ // Ignore sub-lambda expressions
+ hasAncestor(stmt(anyOf(equalsBoundNode("body"),
+lambdaExpr()))
+ .bind("scope")),
+ hasAncestor(stmt(equalsBoundNode("scope"),
+  equalsBoundNode("body"))),
+ // Ignore sub-functions
+ hasAncestor(functionDecl().bind("context")),
+ hasAncestor(functionDecl(
+ equalsBoundNode("context"),
+ equalsBoundNode("function_decl"
+  .bind("bad_owner_return",
+  returns(qualType(qualType().bind("result"),
+   unless(hasDeclaration(OwnerDecl),
+  this);
+
+  // Matching on lambdas, that return an owner/resource, but don't declare
+  // their return type as owner.
+  Finder->addMatcher(
+  lambdaExpr(
+  hasAncestor(decl(ScopeDeclaration).bind("scope-decl")),
+  hasLambdaBody(stmt(
+  stmt().bind("body"),
+  hasDescendant(
+  returnStmt(
+  hasReturnValue(ConsideredOwner),
+  // Ignore sub-lambdas
+  hasAncestor(
+  stmt(anyOf(equalsBoundNode("body"), lambdaExpr()))
+  .bind("scope")),
+  hasAncestor(stmt(equalsBoundNode("scope"),
+   equalsBoundNode("body"))),
+  // Ignore sub-functions
+  hasAncestor(decl(ScopeDeclaration).bind("context")),
+  hasAncestor(decl(equalsBoundNode("context"),
+   equalsBoundNode("scope-decl"
+  .bind("bad_owner_return",
+  hasCallOperator(returns(qualType(qualType().bind("result"),
+   
unless(hasDeclaration(OwnerDecl))

PiotrZSL wrote:

Done

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


[clang-tools-extra] [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (PR #77246)

2024-01-23 Thread Piotr Zegar via cfe-commits


@@ -147,10 +161,52 @@ void OwningMemoryCheck::registerMatchers(MatchFinder 
*Finder) {
   // Matching on functions, that return an owner/resource, but don't declare
   // their return type as owner.
   Finder->addMatcher(
-  functionDecl(hasDescendant(returnStmt(hasReturnValue(ConsideredOwner))
- .bind("bad_owner_return")),
-   unless(returns(qualType(hasDeclaration(OwnerDecl)
-  .bind("function_decl"),
+  functionDecl(
+  decl().bind("function_decl"),
+  hasBody(stmt(
+  stmt().bind("body"),
+  hasDescendant(
+  returnStmt(hasReturnValue(ConsideredOwner),
+ // Ignore sub-lambda expressions
+ hasAncestor(stmt(anyOf(equalsBoundNode("body"),
+lambdaExpr()))
+ .bind("scope")),
+ hasAncestor(stmt(equalsBoundNode("scope"),
+  equalsBoundNode("body"))),
+ // Ignore sub-functions
+ hasAncestor(functionDecl().bind("context")),
+ hasAncestor(functionDecl(
+ equalsBoundNode("context"),
+ equalsBoundNode("function_decl"
+  .bind("bad_owner_return",
+  returns(qualType(qualType().bind("result"),
+   unless(hasDeclaration(OwnerDecl),

PiotrZSL wrote:

Done

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


[lld] [clang-tools-extra] [llvm] [clang] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Teresa Johnson via cfe-commits


@@ -352,32 +357,49 @@ std::vector BitcodeCompiler::compile() {
 pruneCache(config->thinLTOCacheDir, config->thinLTOCachePolicy, files);
 
   if (!config->ltoObjPath.empty()) {
-saveBuffer(buf[0], config->ltoObjPath);
+saveBuffer(buf[0].second, config->ltoObjPath);
 for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->ltoObjPath + Twine(i));
-  }
-
-  if (config->saveTempsArgs.contains("prelink")) {
-if (!buf[0].empty())
-  saveBuffer(buf[0], config->outputFile + ".lto.o");
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i) + ".lto.o");
-  }
-
-  if (config->ltoEmitAsm) {
-saveBuffer(buf[0], config->outputFile);
-for (unsigned i = 1; i != maxTasks; ++i)
-  saveBuffer(buf[i], config->outputFile + Twine(i));
-return {};
+  saveBuffer(buf[i].second, config->ltoObjPath + Twine(i));
   }
 
+  bool savePrelink = config->saveTempsArgs.contains("prelink");
   std::vector ret;
-  for (unsigned i = 0; i != maxTasks; ++i)
-if (!buf[i].empty())
-  ret.push_back(createObjFile(MemoryBufferRef(buf[i], "lto.tmp")));
+  const char *ext = config->ltoEmitAsm ? ".s" : ".o";
+  for (unsigned i = 0; i != maxTasks; ++i) {
+StringRef bitcodeFilePath;
+StringRef objBuf;
+if (files[i]) {

teresajohnson wrote:

Thanks, those are helpful. Can you also add a comment before 373 on meaning of 
files[i] being null vs not - reading through the comments you added it sounds 
like files[i] is non-null when object file was found in the cache?

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


[lld] [clang-tools-extra] [llvm] [clang] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Teresa Johnson via cfe-commits


@@ -53,10 +53,10 @@
 
 ; RUN: rm -fr cache && mkdir cache
 ; RUN: ld.lld --thinlto-cache-dir=cache --save-temps -o out b.bc a.bc -M | 
FileCheck %s --check-prefix=MAP
-; RUN: ls out1.lto.o a.bc.0.preopt.bc b.bc.0.preopt.bc
+; RUN: ls out.lto.a.o a.bc.0.preopt.bc b.bc.0.preopt.bc
 
-; MAP: llvmcache-{{.*}}:(.text)
-; MAP: llvmcache-{{.*}}:(.text)
+; MAP: out.lto.b.o:(.text)

teresajohnson wrote:

Confused about what changed in the latest commit to cause these lines to need 
updating - was this just a missed test update in the prior commit?

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


[llvm] [lld] [clang-tools-extra] [clang] [ELF] --save-temps --lto-emit-asm: derive ELF/asm file names from bitcode file names (PR #78835)

2024-01-23 Thread Teresa Johnson via cfe-commits


@@ -46,8 +46,9 @@ class BitcodeCompiler {
 
 private:
   std::unique_ptr ltoObj;
-  std::vector> buf;
+  SmallVector>, 0> buf;

teresajohnson wrote:

ping on this comment.

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


[clang] [clang][dataflow] Eliminate two uses of `RecordValue::getLoc()`. (PR #79163)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

This is a small step towards eventually eliminating `RecordValue` entirely.


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


1 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+2-2) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 07dc3a9f76ac23b..3567ca41d07c77e 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -412,13 +412,13 @@ void Environment::initialize() {
   QualType ThisPointeeType =
   SurroundingMethodDecl->getFunctionObjectParameterType();
   setThisPointeeStorageLocation(
-  cast(createValue(ThisPointeeType))->getLoc());
+  cast(createObject(ThisPointeeType)));
 }
   }
 } else if (MethodDecl->isImplicitObjectMemberFunction()) {
   QualType ThisPointeeType = MethodDecl->getFunctionObjectParameterType();
   setThisPointeeStorageLocation(
-  cast(createValue(ThisPointeeType))->getLoc());
+  cast(createObject(ThisPointeeType)));
 }
   }
 }

``




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


[clang] [clang][dataflow] Eliminate two uses of `RecordValue::getLoc()`. (PR #79163)

2024-01-23 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/79163

This is a small step towards eventually eliminating `RecordValue` entirely.


>From 8c56bce6b308f316ae8680bb3085e43e05e832a1 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Tue, 23 Jan 2024 16:20:44 +
Subject: [PATCH] [clang][dataflow] Eliminate two uses of
 `RecordValue::getLoc()`.

This is a small step towards eventually eliminating `RecordValue` entirely.
---
 clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 07dc3a9f76ac23b..3567ca41d07c77e 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -412,13 +412,13 @@ void Environment::initialize() {
   QualType ThisPointeeType =
   SurroundingMethodDecl->getFunctionObjectParameterType();
   setThisPointeeStorageLocation(
-  cast(createValue(ThisPointeeType))->getLoc());
+  cast(createObject(ThisPointeeType)));
 }
   }
 } else if (MethodDecl->isImplicitObjectMemberFunction()) {
   QualType ThisPointeeType = MethodDecl->getFunctionObjectParameterType();
   setThisPointeeStorageLocation(
-  cast(createValue(ThisPointeeType))->getLoc());
+  cast(createObject(ThisPointeeType)));
 }
   }
 }

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


[flang] [clang] [compiler-rt] [llvm] [clang-tools-extra] [libc] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-23 Thread Yi Wu via cfe-commits

yi-wu-arm wrote:

> Is there another patch that adds integer kind handling for these two 
> arguments to the runtime implementation?

Not now, sorry, let me add that right now.

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


<    1   2   3   4   5   >