[llvm-branch-commits] [clang] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

2024-04-17 Thread Fangrui Song via llvm-branch-commits


@@ -2876,6 +2876,15 @@ def flax_vector_conversions : Flag<["-"], 
"flax-vector-conversions">, Group, Group,
   HelpText<"Force linking the clang builtins runtime library">;
+
+/// ClangIR-specific options - BEGIN
+def fclangir_enable : Flag<["-"], "fclangir-enable">, Visibility<[ClangOption, 
CC1Option]>,

MaskRay wrote:

+1 to -fclangir and -fno-clangir.

You can use `BoolFOption` to define two options at one time. Ensure that only 
the positive form gets a `CC1Option` (so that `clang -cc1 -fno-clangir` is 
invalid`)

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


[llvm-branch-commits] [llvm] release/18.x: [X86] Always use 64-bit relocations in no-PIC large code model (#89101) (PR #89124)

2024-04-17 Thread Fangrui Song via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Mehdi Amini via llvm-branch-commits


@@ -0,0 +1,44 @@
+//===- CIRDialect.td - CIR dialect -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file declares the CIR dialect.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+
+include "mlir/IR/OpBase.td"
+
+def CIR_Dialect : Dialect {
+  let name = "cir";
+
+  // A short one-line summary of our dialect.
+  let summary = "A high-level dialect for analyzing and optimizing Clang "
+"supported languages";
+
+  let cppNamespace = "::mlir::cir";
+
+  let useDefaultAttributePrinterParser = 0;
+  let useDefaultTypePrinterParser = 0;
+
+  let extraClassDeclaration = [{
+void registerAttributes();
+void registerTypes();
+
+Type parseType(DialectAsmParser ) const override;

joker-eph wrote:

I think I mentioned it elsewhere, but worth keeping in mind: MLIR didn't intend 
to diverge from LLVM, it started about at the time where there was this plan to 
adopt a new style for LLVM: https://llvm.org/docs/Proposals/VariableNames.html
So we thought we were just adopting the "new coding style" to limit churn, and 
unfortunately this didn't pan out for the whole codebase (I think lldb and lld 
are also using this style now)

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


[llvm-branch-commits] [compiler-rt] b207702 - Revert "CompilerRT: Normalize COMPILER_RT_DEFAULT_TARGET_TRIPLE (#88835)"

2024-04-17 Thread via llvm-branch-commits

Author: ZijunZhaoCCK
Date: 2024-04-17T15:09:37-07:00
New Revision: b207702dbbfa6a4ec65cf983080b13235bb854c0

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

LOG: Revert "CompilerRT: Normalize COMPILER_RT_DEFAULT_TARGET_TRIPLE (#88835)"

This reverts commit 16f188761da1df6ba5e6627b8742aacfec8e9ec5.

Added: 


Modified: 
compiler-rt/cmake/Modules/CompilerRTUtils.cmake

Removed: 




diff  --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake 
b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index 6d413f6753bc0c..e8e5f612d5b03c 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -368,12 +368,6 @@ macro(construct_compiler_rt_default_triple)
   "Default triple for which compiler-rt runtimes will be built.")
   endif()
 
-  if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
-execute_process(COMMAND ${CMAKE_C_COMPILER} 
--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} -print-effective-triple
-OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE
-OUTPUT_STRIP_TRAILING_WHITESPACE)
-  endif()
-
   string(REPLACE "-" ";" LLVM_TARGET_TRIPLE_LIST 
${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
   list(GET LLVM_TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH)
 



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


[llvm-branch-commits] [llvm] ReleaseNote: Mention SpecialCaseList change (PR #89141)

2024-04-17 Thread Paul T Robinson via llvm-branch-commits

pogo59 wrote:

@tstellar The PR was committed in December, so this is a change from LLVM17 to 
LLVM18. It is a behavior change that is tripping up some people, and I asked 
@MaskRay for a release note.

If it's too late for that, I can propagate his release note to our downstream 
release.

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


[llvm-branch-commits] [llvm] ReleaseNote: Mention SpecialCaseList change (PR #89141)

2024-04-17 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

Is this a change from LLVM 17 to LLVM 18 or from LLVM 18.0.3 to 18.0.4 ?

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


[llvm-branch-commits] [llvm] ReleaseNote: Mention SpecialCaseList change (PR #89141)

2024-04-17 Thread Fangrui Song via llvm-branch-commits

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

>From a562fa55380991c37b0ec3ace83a98715795517a Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 17 Apr 2024 13:51:25 -0700
Subject: [PATCH] ReleaseNote: Mention SpecialCaseList change

---
 llvm/docs/ReleaseNotes.rst | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index ecfcd2c983ce5e..453abc63397764 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -435,6 +435,12 @@ Changes to Sanitizers
 -
 * HWASan now defaults to detecting use-after-scope bugs.
 
+* ``SpecialCaseList`` used by sanitizer ignore lists (e.g. ``*_ignorelist.txt``
+  in the Clang resource directory) now uses glob patterns instead of a variant
+  of POSIX Extended Regular Expression (where ``*`` is translated to ``.*``) by
+  default. Search for ``|`` to find patterns that may have different meanings
+  now.
+
 Changes to the Profile Runtime
 --
 

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


[llvm-branch-commits] [llvm] ReleaseNote: Mention SpecialCaseList change (PR #89141)

2024-04-17 Thread Fangrui Song via llvm-branch-commits

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


[llvm-branch-commits] [llvm] ReleaseNote: Mention SpecialCaseList change (PR #89141)

2024-04-17 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/89141

None

>From 34afd4aa3c44d65f66edfc9e568890fd16d81a59 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 17 Apr 2024 13:51:25 -0700
Subject: [PATCH] ReleaseNote: Mention SpecialCaseList change

---
 llvm/docs/ReleaseNotes.rst | 5 +
 1 file changed, 5 insertions(+)

diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index ecfcd2c983ce5e..e049689adc703c 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -435,6 +435,11 @@ Changes to Sanitizers
 -
 * HWASan now defaults to detecting use-after-scope bugs.
 
+* ``SpecialCaseList`` used by sanitizer ignore lists now uses glob patterns
+  instead of a variant of POSIX Extended Regular Expression (where ``*`` is
+  translated to ``.*``) by default. Search for ``|`` to find patterns that may
+  have different meanings now.
+
 Changes to the Profile Runtime
 --
 

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread John Ericson via llvm-branch-commits

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread John Ericson via llvm-branch-commits


@@ -0,0 +1,6 @@
+set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --includedir
+set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)

Ericson2314 wrote:

We should keep the standalone build in mind, where a standalone build of Clang 
(with CIR enabled) should be able to use a prebuilt LLVM and MLIR alike.

CC @pca006132 

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread John Ericson via llvm-branch-commits


@@ -0,0 +1,4 @@
+include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
+include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)

Ericson2314 wrote:

I think something like `target_include_directories` is generally preferred, 
because it is less of a sledgehammer effecting many targets at once.

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Erich Keane via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] release/18.x: [X86] Always use 64-bit relocations in no-PIC large code model (#89101) (PR #89124)

2024-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: None (llvmbot)


Changes

Backport 6cea7c491f4c4c68aa0494a9b18f36ff40c22c81

Requested by: @aeubanks

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


2 Files Affected:

- (modified) llvm/lib/Target/X86/X86ISelDAGToDAG.cpp (+3-4) 
- (modified) llvm/test/CodeGen/X86/code-model-elf.ll (+2-2) 


``diff
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp 
b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index 833f058253d880..553d338b77904a 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -2923,11 +2923,10 @@ bool X86DAGToDAGISel::selectAddr(SDNode *Parent, 
SDValue N, SDValue ,
 }
 
 bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue ) {
-  // Cannot use 32 bit constants to reference objects in kernel code model.
-  // Cannot use 32 bit constants to reference objects in large PIC mode since
-  // GOTOFF is 64 bits.
+  // Cannot use 32 bit constants to reference objects in kernel/large code
+  // model.
   if (TM.getCodeModel() == CodeModel::Kernel ||
-  (TM.getCodeModel() == CodeModel::Large && TM.isPositionIndependent()))
+  TM.getCodeModel() == CodeModel::Large)
 return false;
 
   // In static codegen with small code model, we can get the address of a label
diff --git a/llvm/test/CodeGen/X86/code-model-elf.ll 
b/llvm/test/CodeGen/X86/code-model-elf.ll
index afcffb3a7adeda..b6634403dc1d05 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -346,7 +346,7 @@ define dso_local ptr @lea_forced_small_data() #0 {
 ;
 ; LARGE-STATIC-LABEL: lea_forced_small_data:
 ; LARGE-STATIC:   # %bb.0:
-; LARGE-STATIC-NEXT:movl $forced_small_data, %eax
+; LARGE-STATIC-NEXT:movabsq $forced_small_data, %rax
 ; LARGE-STATIC-NEXT:retq
 ;
 ; SMALL-PIC-LABEL: lea_forced_small_data:
@@ -399,7 +399,7 @@ define dso_local i32 @load_forced_small_data() #0 {
 ;
 ; LARGE-STATIC-LABEL: load_forced_small_data:
 ; LARGE-STATIC:   # %bb.0:
-; LARGE-STATIC-NEXT:movl $forced_small_data+8, %eax
+; LARGE-STATIC-NEXT:movabsq $forced_small_data+8, %rax
 ; LARGE-STATIC-NEXT:movl (%rax), %eax
 ; LARGE-STATIC-NEXT:retq
 ;

``




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


[llvm-branch-commits] [llvm] release/18.x: [X86] Always use 64-bit relocations in no-PIC large code model (#89101) (PR #89124)

2024-04-17 Thread via llvm-branch-commits

llvmbot wrote:

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

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


[llvm-branch-commits] [llvm] release/18.x: [X86] Always use 64-bit relocations in no-PIC large code model (#89101) (PR #89124)

2024-04-17 Thread via llvm-branch-commits

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

Backport 6cea7c491f4c4c68aa0494a9b18f36ff40c22c81

Requested by: @aeubanks

>From 62da265640d070cb6c7e67de94202089a44b6e5c Mon Sep 17 00:00:00 2001
From: Arthur Eubanks 
Date: Wed, 17 Apr 2024 12:04:18 -0700
Subject: [PATCH] [X86] Always use 64-bit relocations in no-PIC large code
 model (#89101)

This matches other types of relocations, e.g. to constant pool. And
makes things more consistent with PIC large code model.

Some users of the large code model may not place small data in the lower
2GB of the address space (e.g.
https://github.com/ClangBuiltLinux/linux/issues/2016), so just
unconditionally use 64-bit relocations in the large code model.

So now functions in a section not marked large will use 64-bit
relocations to reference everything when using the large code model.

This also fixes some lldb tests broken by #88172
(https://lab.llvm.org/buildbot/#/builders/68/builds/72458).

(cherry picked from commit 6cea7c491f4c4c68aa0494a9b18f36ff40c22c81)
---
 llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | 7 +++
 llvm/test/CodeGen/X86/code-model-elf.ll | 4 ++--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp 
b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index 833f058253d880..553d338b77904a 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -2923,11 +2923,10 @@ bool X86DAGToDAGISel::selectAddr(SDNode *Parent, 
SDValue N, SDValue ,
 }
 
 bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue ) {
-  // Cannot use 32 bit constants to reference objects in kernel code model.
-  // Cannot use 32 bit constants to reference objects in large PIC mode since
-  // GOTOFF is 64 bits.
+  // Cannot use 32 bit constants to reference objects in kernel/large code
+  // model.
   if (TM.getCodeModel() == CodeModel::Kernel ||
-  (TM.getCodeModel() == CodeModel::Large && TM.isPositionIndependent()))
+  TM.getCodeModel() == CodeModel::Large)
 return false;
 
   // In static codegen with small code model, we can get the address of a label
diff --git a/llvm/test/CodeGen/X86/code-model-elf.ll 
b/llvm/test/CodeGen/X86/code-model-elf.ll
index afcffb3a7adeda..b6634403dc1d05 100644
--- a/llvm/test/CodeGen/X86/code-model-elf.ll
+++ b/llvm/test/CodeGen/X86/code-model-elf.ll
@@ -346,7 +346,7 @@ define dso_local ptr @lea_forced_small_data() #0 {
 ;
 ; LARGE-STATIC-LABEL: lea_forced_small_data:
 ; LARGE-STATIC:   # %bb.0:
-; LARGE-STATIC-NEXT:movl $forced_small_data, %eax
+; LARGE-STATIC-NEXT:movabsq $forced_small_data, %rax
 ; LARGE-STATIC-NEXT:retq
 ;
 ; SMALL-PIC-LABEL: lea_forced_small_data:
@@ -399,7 +399,7 @@ define dso_local i32 @load_forced_small_data() #0 {
 ;
 ; LARGE-STATIC-LABEL: load_forced_small_data:
 ; LARGE-STATIC:   # %bb.0:
-; LARGE-STATIC-NEXT:movl $forced_small_data+8, %eax
+; LARGE-STATIC-NEXT:movabsq $forced_small_data+8, %rax
 ; LARGE-STATIC-NEXT:movl (%rax), %eax
 ; LARGE-STATIC-NEXT:retq
 ;

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


[llvm-branch-commits] [llvm] release/18.x: [X86] Always use 64-bit relocations in no-PIC large code model (#89101) (PR #89124)

2024-04-17 Thread via llvm-branch-commits

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Aaron Ballman via llvm-branch-commits

AaronBallman wrote:

> > LGTM, though it would be nice if @petrhosek or @Ericson2314 could validate 
> > the cmake changes (they look sensible to me, but I never know if there's a 
> > better way to do things in CMake).
> 
> We already did that above. Petr left a comment and it was fixed :p

Ah, I missed that entirely because the conversations were resolved. Phew, then 
yeah, LGTM!

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Nathan Lanza via llvm-branch-commits

lanza wrote:

> LGTM, though it would be nice if @petrhosek or @Ericson2314 could validate 
> the cmake changes (they look sensible to me, but I never know if there's a 
> better way to do things in CMake).

We already did that above. Petr left a comment and it was fixed :p 

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Nathan Lanza via llvm-branch-commits

https://github.com/lanza updated https://github.com/llvm/llvm-project/pull/86080

>From 435869501bb0788d8b22d847c3a870dbfbf94126 Mon Sep 17 00:00:00 2001
From: Nathan Lanza 
Date: Thu, 21 Mar 2024 04:57:16 +
Subject: [PATCH 1/3] fix MLIRCIROpsIncGen

Created using spr 1.3.5
---
 .../clang/CIR/Dialect/IR/CIRDialect.td| 46 +++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 18 
 2 files changed, 64 insertions(+)
 create mode 100644 clang/include/clang/CIR/Dialect/IR/CIRDialect.td

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td 
b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
new file mode 100644
index 00..8f756fa422e5f3
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
@@ -0,0 +1,46 @@
+//===- CIRTypes.td - CIR dialect types -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file declares the CIR dialect.
+//
+//===--===//
+
+#ifndef MLIR_CIR_DIALECT_CIR
+#define MLIR_CIR_DIALECT_CIR
+
+include "mlir/IR/OpBase.td"
+
+def CIR_Dialect : Dialect {
+  let name = "cir";
+
+  // A short one-line summary of our dialect.
+  let summary = "A high-level dialect for analyzing and optimizing Clang "
+"supported languages";
+
+  let cppNamespace = "::mlir::cir";
+
+  let useDefaultAttributePrinterParser = 0;
+  let useDefaultTypePrinterParser = 0;
+
+  let extraClassDeclaration = [{
+void registerAttributes();
+void registerTypes();
+
+::mlir::Type parseType(::mlir::DialectAsmParser ) const override;
+void printType(::mlir::Type type,
+   ::mlir::DialectAsmPrinter ) const override;
+
+::mlir::Attribute parseAttribute(::mlir::DialectAsmParser ,
+ ::mlir::Type type) const override;
+
+void printAttribute(::mlir::Attribute attr,
+::mlir::DialectAsmPrinter ) const override;
+  }];
+}
+
+#endif // MLIR_CIR_DIALECT_CIR
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index e69de29bb2d1d6..cfc62986b0b9d1 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -0,0 +1,18 @@
+//===-- CIROps.td - CIR dialect definition -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+///
+/// \file
+/// Definition of the CIR dialect
+///
+//===--===//
+
+#ifndef MLIR_CIR_DIALECT_CIR_OPS
+#define MLIR_CIR_DIALECT_CIR_OPS
+
+include "clang/CIR/Dialect/IR/CIRDialect.td"
+#endif // MLIR_CIR_DIALECT_CIR_OPS

>From fe44284534be0752d95634251289a5c74c06afe7 Mon Sep 17 00:00:00 2001
From: Nathan Lanza 
Date: Thu, 21 Mar 2024 05:12:26 +
Subject: [PATCH 2/3] add some guts to CIRDialect.cpp and MLIRCIR lib

Created using spr 1.3.5
---
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 11 +++
 clang/lib/CIR/Dialect/IR/CMakeLists.txt |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index e69de29bb2d1d6..8abf39119e04f7 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -0,0 +1,11 @@
+//===- CIRDialect.cpp - MLIR CIR ops implementation 
---===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the CIR dialect and its operations.
+//
+//===--===//
diff --git a/clang/lib/CIR/Dialect/IR/CMakeLists.txt 
b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
index e69de29bb2d1d6..0d7476b555705d 100644
--- a/clang/lib/CIR/Dialect/IR/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_clang_library(MLIRCIR
+  CIRDialect.cpp
+  )

>From 0e195548f24fb3748e22141739f914676b1d56d5 Mon Sep 17 00:00:00 2001
From: Nathan Lanza 
Date: Wed, 17 Apr 2024 18:59:53 +
Subject: [PATCH 3/3] include dialect and add include guards

Created using spr 1.3.5
---
 clang/include/clang/CIR/Dialect/IR/CIRDialect.h | 5 +
 

[llvm-branch-commits] [llvm] 5f2c198 - Revert "[RISCV] Support Zama16b1p0 (#88474)"

2024-04-17 Thread via llvm-branch-commits

Author: ZijunZhaoCCK
Date: 2024-04-17T11:44:16-07:00
New Revision: 5f2c198dea46ecce30f09d894dafdc12142fbe4c

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

LOG: Revert "[RISCV] Support Zama16b1p0 (#88474)"

This reverts commit b090569685699abe4a8031ad442a0f81e373146b.

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s
llvm/unittests/Support/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 646043681fe330..ec7764bb538189 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -79,7 +79,6 @@
 // CHECK-NOT: __riscv_za128rs {{.*$}}
 // CHECK-NOT: __riscv_za64rs {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
-// CHECK-NOT: __riscv_zama16b {{.*$}}
 // CHECK-NOT: __riscv_zawrs {{.*$}}
 // CHECK-NOT: __riscv_zba {{.*$}}
 // CHECK-NOT: __riscv_zbb {{.*$}}
@@ -705,12 +704,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
 // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
 
-// RUN: %clang --target=riscv32 -march=rv32izama16b -x c -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s
-// RUN: %clang --target=riscv64 -march=rv64izama16b  -x c -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s
-// CHECK-ZAMA16B-EXT: __riscv_zama16b  100{{$}}
-
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32izawrs -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAWRS-EXT %s

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index a4cf17a8398a82..6f5eba263def43 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -119,7 +119,6 @@ on support follow.
  ``Za128rs``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Za64rs``Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Zacas`` Supported (`See note <#riscv-zacas-note>`__)
- ``Zama16b``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Zawrs`` Assembly Support
  ``Zba``   Supported
  ``Zbb``   Supported
@@ -238,7 +237,7 @@ Supported
 
 .. _riscv-profiles-extensions-note:
 
-``Za128rs``, ``Za64rs``, ``Zama16b``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, 
``Zicclsm``, ``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, 
``Shvsatpa``, ``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscounterenw``, 
``Ssstateen``, ``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, 
``Svbare``
+``Za128rs``, ``Za64rs``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, ``Zicclsm``, 
``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, ``Shvsatpa``, 
``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscounterenw``, ``Ssstateen``, 
``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, ``Svbare``
   These extensions are defined as part of the `RISC-V Profiles specification 
`__.  They do not 
introduce any new features themselves, but instead describe existing hardware 
features.
 
   .. _riscv-zacas-note:

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index fa967403ea449c..cbdc64bc7a97be 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -119,7 +119,6 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 {"za128rs", {1, 0}},
 {"za64rs", {1, 0}},
 {"zacas", {1, 0}},
-{"zama16b", {1, 0}},
 {"zawrs", {1, 0}},
 
 {"zba", {1, 0}},

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index f830ead5dd692a..561187c39a4a04 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -208,13 +208,6 @@ def HasStdExtAOrZalrsc
  "'A' (Atomic Instructions) or "
  "'Zalrsc' (Load-Reserved/Store-Conditional)">;
 
-def FeatureStdExtZama16b
-: SubtargetFeature<"zama16b", "HasStdExtZama16b", "true",
-   "'Zama16b' (Atomic 16-byte misaligned loads, stores and 
AMOs)">;
-def HasStdExtZama16b : Predicate<"Subtarget->hasStdExtZama16b()">,
-   AssemblerPredicate<(all_of FeatureStdExtZama16b),
-   "'Zama16b' (Atomic 16-byte misaligned loads, stores 
and AMOs)">;
-
 def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true",
   "'Zawrs' (Wait on 

[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Aaron Ballman via llvm-branch-commits

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Aaron Ballman via llvm-branch-commits


@@ -0,0 +1,44 @@
+//===- CIRDialect.td - CIR dialect -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file declares the CIR dialect.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+
+include "mlir/IR/OpBase.td"
+
+def CIR_Dialect : Dialect {
+  let name = "cir";
+
+  // A short one-line summary of our dialect.
+  let summary = "A high-level dialect for analyzing and optimizing Clang "
+"supported languages";
+
+  let cppNamespace = "::mlir::cir";
+
+  let useDefaultAttributePrinterParser = 0;
+  let useDefaultTypePrinterParser = 0;
+
+  let extraClassDeclaration = [{
+void registerAttributes();
+void registerTypes();
+
+Type parseType(DialectAsmParser ) const override;

AaronBallman wrote:

> This will be added to generated class which have lower-case starting APIs: 
> consistency within the class seems to prevail to me.

Ah, then yeah, I agree. Thank you!

> You should really expect that all the MLIR code will follow this convention, 
> because it'll be intertwined closely with the MLIR framework.

MLIR isn't old enough to really get "grandfathered" in with their own style, so 
that's pretty surprising. That said, I *fully support* letting projects have 
project-specific policies including coding style, so I see no reason for MLIR 
to change either. Interfacing closely with MLIR does make this a bit awkward 
however, because it's also intertwined with the Clang code base. On balance, I 
think it's fine to follow the MLIR convention because I think there will be 
more surface area in common between CIR + MLIR than CIR + Clang (and Clang has 
plenty of inconsistency with coding style already so this is not really novel).

tl;dr: nothing needs to change here.

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Aaron Ballman via llvm-branch-commits

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

LGTM, though it would be nice if @petrhosek or @Ericson2314 could validate the 
cmake changes (they look sensible to me, but I never know if there's a better 
way to do things in CMake).

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Erich Keane via llvm-branch-commits




erichkeane wrote:

I see this is irrelevant now, but noticed I had a pair of pending comments and 
wanted the other one.

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Erich Keane via llvm-branch-commits


@@ -0,0 +1,11 @@
+//===- CIRDialect.cpp - MLIR CIR ops implementation 
---===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the CIR dialect and its operations.
+//
+//===--===//

erichkeane wrote:

As a nit, it would be nice to #include the .h file for this.

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Erich Keane via llvm-branch-commits




erichkeane wrote:

we should probably still create this file with the comment header and include 
guards at this point.

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Mehdi Amini via llvm-branch-commits


@@ -0,0 +1,44 @@
+//===- CIRDialect.td - CIR dialect -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file declares the CIR dialect.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+
+include "mlir/IR/OpBase.td"
+
+def CIR_Dialect : Dialect {
+  let name = "cir";
+
+  // A short one-line summary of our dialect.
+  let summary = "A high-level dialect for analyzing and optimizing Clang "
+"supported languages";
+
+  let cppNamespace = "::mlir::cir";
+
+  let useDefaultAttributePrinterParser = 0;
+  let useDefaultTypePrinterParser = 0;
+
+  let extraClassDeclaration = [{
+void registerAttributes();
+void registerTypes();
+
+Type parseType(DialectAsmParser ) const override;

joker-eph wrote:

This will be added to generated class which have lower-case starting APIs: 
consistency within the class seems to prevail to me.
You should really expect that all the MLIR code will follow this convention, 
because it'll be intertwined closely with the MLIR framework.

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


[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Aaron Ballman via llvm-branch-commits


@@ -0,0 +1,44 @@
+//===- CIRDialect.td - CIR dialect -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file declares the CIR dialect.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
+
+include "mlir/IR/OpBase.td"
+
+def CIR_Dialect : Dialect {
+  let name = "cir";
+
+  // A short one-line summary of our dialect.
+  let summary = "A high-level dialect for analyzing and optimizing Clang "
+"supported languages";
+
+  let cppNamespace = "::mlir::cir";
+
+  let useDefaultAttributePrinterParser = 0;
+  let useDefaultTypePrinterParser = 0;
+
+  let extraClassDeclaration = [{
+void registerAttributes();
+void registerTypes();
+
+Type parseType(DialectAsmParser ) const override;

AaronBallman wrote:

Because this is new code, the parameter names should match the usual coding 
style for naming (start with a capital letter) for consistency with the rest of 
the code base.

Where do the definitions for these come from?

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


[llvm-branch-commits] [llvm] [LLVM][OpenMP] Implement getLeafOrCompositeConstructs (PR #89104)

2024-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

This function will break up a construct into constituent leaf and composite 
constructs, e.g. if OMPD_c_d_e and OMPD_d_e are composite constructs, then 
OMPD_a_b_c_d_e will be broken up into the list {OMPD_a, OMPD_b, OMPD_c_d_e}.

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


3 Files Affected:

- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.h (+6) 
- (modified) llvm/lib/Frontend/OpenMP/OMP.cpp (+75-13) 
- (modified) llvm/unittests/Frontend/OpenMPCompositionTest.cpp (+32) 


``diff
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h 
b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index ec8ae68f1c2ca0..6f7a39acac1d31 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -16,9 +16,15 @@
 #include "llvm/Frontend/OpenMP/OMP.h.inc"
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
 
 namespace llvm::omp {
 ArrayRef getLeafConstructs(Directive D);
+ArrayRef getLeafConstructsOrSelf(Directive D);
+
+ArrayRef
+getLeafOrCompositeConstructs(Directive D, SmallVectorImpl );
+
 Directive getCompoundConstruct(ArrayRef Parts);
 
 bool isLeafConstruct(Directive D);
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 4b9b7037ee4ad5..2ebadf5216a084 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -25,6 +25,43 @@ using namespace llvm::omp;
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
 
+static iterator_range::iterator>
+getFirstCompositeRange(iterator_range::iterator> Leafs) {
+  // OpenMP Spec 5.2: [17.3, 8-9]
+  // If directive-name-A and directive-name-B both correspond to loop-
+  // associated constructs then directive-name is a composite construct
+  // otherwise directive-name is a combined construct.
+  //
+  // In the list of leaf constructs, find the first loop-associated construct,
+  // this is the beginning of the range. Then, starting from the immediately
+  // following leaf construct, find the first sequence of adjacent loop-
+  // -associated constructs. The last of those is the last one of the range.
+
+  auto firstLoopAssociated =
+  [](iterator_range::iterator> List) {
+for (auto It = List.begin(), End = List.end(); It != End; ++It) {
+  if (getDirectiveAssociation(*It) == Association::Loop)
+return It;
+}
+return List.end();
+  };
+
+  auto Begin = firstLoopAssociated(Leafs);
+  if (Begin == Leafs.end())
+return llvm::make_range(Leafs.end(), Leafs.end());
+
+  auto End =
+  firstLoopAssociated(llvm::make_range(std::next(Begin), Leafs.end()));
+  if (End == Leafs.end())
+return llvm::make_range(Begin, std::next(Begin));
+
+  for (; End != Leafs.end(); ++End) {
+if (getDirectiveAssociation(*End) != Association::Loop)
+  break;
+  }
+  return llvm::make_range(Begin, End);
+}
+
 namespace llvm::omp {
 ArrayRef getLeafConstructs(Directive D) {
   auto Idx = static_cast(D);
@@ -34,6 +71,40 @@ ArrayRef getLeafConstructs(Directive D) {
   return ArrayRef([2], [2] + static_cast(Row[1]));
 }
 
+ArrayRef getLeafConstructsOrSelf(Directive D) {
+  if (auto Leafs = getLeafConstructs(D); !Leafs.empty())
+return Leafs;
+  auto Idx = static_cast(D);
+  assert(Idx < Directive_enumSize && "Invalid directive");
+  const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
+  // The first entry in the row is the directive itself.
+  return ArrayRef([0], [0] + 1);
+}
+
+ArrayRef
+getLeafOrCompositeConstructs(Directive D, SmallVectorImpl ) {
+  using ArrayTy = ArrayRef;
+  using IteratorTy = ArrayTy::iterator;
+  ArrayRef Leafs = getLeafConstructsOrSelf(D);
+
+  IteratorTy Iter = Leafs.begin();
+  do {
+auto Range = getFirstCompositeRange(llvm::make_range(Iter, Leafs.end()));
+// All directives before the range are leaf constructs.
+for (; Iter != Range.begin(); ++Iter)
+  Output.push_back(*Iter);
+if (!Range.empty()) {
+  Directive Comp =
+  getCompoundConstruct(ArrayTy(Range.begin(), Range.end()));
+  assert(Comp != OMPD_unknown);
+  Output.push_back(Comp);
+}
+Iter = Range.end();
+  } while (Iter != Leafs.end());
+
+  return Output;
+}
+
 Directive getCompoundConstruct(ArrayRef Parts) {
   if (Parts.empty())
 return OMPD_unknown;
@@ -88,20 +159,11 @@ Directive getCompoundConstruct(ArrayRef Parts) {
 bool isLeafConstruct(Directive D) { return getLeafConstructs(D).empty(); }
 
 bool isCompositeConstruct(Directive D) {
-  // OpenMP Spec 5.2: [17.3, 8-9]
-  // If directive-name-A and directive-name-B both correspond to loop-
-  // associated constructs then directive-name is a composite construct
-  llvm::ArrayRef Leafs{getLeafConstructs(D)};
-  if (Leafs.empty())
-return false;
-  if (getDirectiveAssociation(Leafs.front()) != Association::Loop)
+  ArrayRef Leafs = 

[llvm-branch-commits] [llvm] [LLVM][OpenMP] Implement getLeafOrCompositeConstructs (PR #89104)

2024-04-17 Thread Krzysztof Parzyszek via llvm-branch-commits

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

This function will break up a construct into constituent leaf and composite 
constructs, e.g. if OMPD_c_d_e and OMPD_d_e are composite constructs, then 
OMPD_a_b_c_d_e will be broken up into the list {OMPD_a, OMPD_b, OMPD_c_d_e}.

>From 4593582b2a480dfffd2dceb4611cc0dec9cd7de5 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 11 Apr 2024 10:33:44 -0500
Subject: [PATCH] [LLVM][OpenMP] Implement getLeafOrCompositeConstructs

This function will break up a construct into constituent leaf and
composite constructs, e.g. if OMPD_c_d_e and OMPD_d_e are composite
constructs, then OMPD_a_b_c_d_e will be broken up into the list
{OMPD_a, OMPD_b, OMPD_c_d_e}.
---
 llvm/include/llvm/Frontend/OpenMP/OMP.h   |  6 ++
 llvm/lib/Frontend/OpenMP/OMP.cpp  | 88 ---
 .../Frontend/OpenMPCompositionTest.cpp| 32 +++
 3 files changed, 113 insertions(+), 13 deletions(-)

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h 
b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index ec8ae68f1c2ca0..6f7a39acac1d31 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -16,9 +16,15 @@
 #include "llvm/Frontend/OpenMP/OMP.h.inc"
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
 
 namespace llvm::omp {
 ArrayRef getLeafConstructs(Directive D);
+ArrayRef getLeafConstructsOrSelf(Directive D);
+
+ArrayRef
+getLeafOrCompositeConstructs(Directive D, SmallVectorImpl );
+
 Directive getCompoundConstruct(ArrayRef Parts);
 
 bool isLeafConstruct(Directive D);
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 4b9b7037ee4ad5..2ebadf5216a084 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -25,6 +25,43 @@ using namespace llvm::omp;
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
 
+static iterator_range::iterator>
+getFirstCompositeRange(iterator_range::iterator> Leafs) {
+  // OpenMP Spec 5.2: [17.3, 8-9]
+  // If directive-name-A and directive-name-B both correspond to loop-
+  // associated constructs then directive-name is a composite construct
+  // otherwise directive-name is a combined construct.
+  //
+  // In the list of leaf constructs, find the first loop-associated construct,
+  // this is the beginning of the range. Then, starting from the immediately
+  // following leaf construct, find the first sequence of adjacent loop-
+  // -associated constructs. The last of those is the last one of the range.
+
+  auto firstLoopAssociated =
+  [](iterator_range::iterator> List) {
+for (auto It = List.begin(), End = List.end(); It != End; ++It) {
+  if (getDirectiveAssociation(*It) == Association::Loop)
+return It;
+}
+return List.end();
+  };
+
+  auto Begin = firstLoopAssociated(Leafs);
+  if (Begin == Leafs.end())
+return llvm::make_range(Leafs.end(), Leafs.end());
+
+  auto End =
+  firstLoopAssociated(llvm::make_range(std::next(Begin), Leafs.end()));
+  if (End == Leafs.end())
+return llvm::make_range(Begin, std::next(Begin));
+
+  for (; End != Leafs.end(); ++End) {
+if (getDirectiveAssociation(*End) != Association::Loop)
+  break;
+  }
+  return llvm::make_range(Begin, End);
+}
+
 namespace llvm::omp {
 ArrayRef getLeafConstructs(Directive D) {
   auto Idx = static_cast(D);
@@ -34,6 +71,40 @@ ArrayRef getLeafConstructs(Directive D) {
   return ArrayRef([2], [2] + static_cast(Row[1]));
 }
 
+ArrayRef getLeafConstructsOrSelf(Directive D) {
+  if (auto Leafs = getLeafConstructs(D); !Leafs.empty())
+return Leafs;
+  auto Idx = static_cast(D);
+  assert(Idx < Directive_enumSize && "Invalid directive");
+  const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
+  // The first entry in the row is the directive itself.
+  return ArrayRef([0], [0] + 1);
+}
+
+ArrayRef
+getLeafOrCompositeConstructs(Directive D, SmallVectorImpl ) {
+  using ArrayTy = ArrayRef;
+  using IteratorTy = ArrayTy::iterator;
+  ArrayRef Leafs = getLeafConstructsOrSelf(D);
+
+  IteratorTy Iter = Leafs.begin();
+  do {
+auto Range = getFirstCompositeRange(llvm::make_range(Iter, Leafs.end()));
+// All directives before the range are leaf constructs.
+for (; Iter != Range.begin(); ++Iter)
+  Output.push_back(*Iter);
+if (!Range.empty()) {
+  Directive Comp =
+  getCompoundConstruct(ArrayTy(Range.begin(), Range.end()));
+  assert(Comp != OMPD_unknown);
+  Output.push_back(Comp);
+}
+Iter = Range.end();
+  } while (Iter != Leafs.end());
+
+  return Output;
+}
+
 Directive getCompoundConstruct(ArrayRef Parts) {
   if (Parts.empty())
 return OMPD_unknown;
@@ -88,20 +159,11 @@ Directive getCompoundConstruct(ArrayRef Parts) {
 bool isLeafConstruct(Directive D) { return getLeafConstructs(D).empty(); }
 
 bool isCompositeConstruct(Directive D) {
-  // 

[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

2024-04-17 Thread Bruno Cardoso Lopes via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] [Frontend][OpenMP] Add functions for checking construct type (PR #87258)

2024-04-17 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From a889f3074fc8c4ae5c6d9480308be0501217b9ff Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 11 Mar 2024 12:55:38 -0500
Subject: [PATCH 1/3] [Frontend][OpenMP] Add functions for checking construct
 type

Implement helper functions to identify leaf, composite, and combined
constructs.
---
 llvm/include/llvm/Frontend/OpenMP/OMP.h   |  4 +++
 llvm/lib/Frontend/OpenMP/OMP.cpp  | 25 ++
 llvm/unittests/Frontend/OpenMPComposeTest.cpp | 26 +++
 3 files changed, 55 insertions(+)

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h 
b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index 4ed47f15dfe59e..ec8ae68f1c2ca0 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -20,6 +20,10 @@
 namespace llvm::omp {
 ArrayRef getLeafConstructs(Directive D);
 Directive getCompoundConstruct(ArrayRef Parts);
+
+bool isLeafConstruct(Directive D);
+bool isCompositeConstruct(Directive D);
+bool isCombinedConstruct(Directive D);
 } // namespace llvm::omp
 
 #endif // LLVM_FRONTEND_OPENMP_OMP_H
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index dd99d3d074fd1e..98d7c63bb8537e 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -78,4 +78,29 @@ Directive getCompoundConstruct(ArrayRef Parts) {
 return Found;
   return OMPD_unknown;
 }
+
+bool isLeafConstruct(Directive D) { return getLeafConstructs(D).empty(); }
+
+bool isCompositeConstruct(Directive D) {
+  // OpenMP Spec 5.2: [17.3, 8-9]
+  // If directive-name-A and directive-name-B both correspond to loop-
+  // associated constructs then directive-name is a composite construct
+  llvm::ArrayRef Leafs{getLeafConstructs(D)};
+  if (Leafs.empty())
+return false;
+  if (getDirectiveAssociation(Leafs.front()) != Association::Loop)
+return false;
+
+  size_t numLoopConstructs =
+  llvm::count_if(Leafs.drop_front(), [](Directive L) {
+return getDirectiveAssociation(L) == Association::Loop;
+  });
+  return numLoopConstructs != 0;
+}
+
+bool isCombinedConstruct(Directive D) {
+  // OpenMP Spec 5.2: [17.3, 9-10]
+  // Otherwise directive-name is a combined construct.
+  return !getLeafConstructs(D).empty() && !isCompositeConstruct(D);
+}
 } // namespace llvm::omp
diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp 
b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
index 29b1be4eb3432c..cc02af8bf67c26 100644
--- a/llvm/unittests/Frontend/OpenMPComposeTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
@@ -39,3 +39,29 @@ TEST(Composition, GetCompoundConstruct) {
   Directive C7 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd});
   ASSERT_EQ(C7, OMPD_parallel_for_simd);
 }
+
+TEST(Composition, IsLeafConstruct) {
+  ASSERT_TRUE(isLeafConstruct(OMPD_loop));
+  ASSERT_TRUE(isLeafConstruct(OMPD_teams));
+  ASSERT_FALSE(isLeafConstruct(OMPD_for_simd));
+  ASSERT_FALSE(isLeafConstruct(OMPD_distribute_simd));
+}
+
+TEST(Composition, IsCompositeConstruct) {
+  ASSERT_TRUE(isCompositeConstruct(OMPD_distribute_simd));
+  ASSERT_FALSE(isCompositeConstruct(OMPD_for));
+  ASSERT_TRUE(isCompositeConstruct(OMPD_for_simd));
+  // directive-name-A = "parallel", directive-name-B = "for simd",
+  // only directive-name-A is loop-associated, so this is not a
+  // composite construct, even though "for simd" is.
+  ASSERT_FALSE(isCompositeConstruct(OMPD_parallel_for_simd));
+}
+
+TEST(Composition, IsCombinedConstruct) {
+  // "parallel for simd" is a combined construct, see comment in
+  // IsCompositeConstruct.
+  ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for_simd));
+  ASSERT_FALSE(isCombinedConstruct(OMPD_for_simd));
+  ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for));
+  ASSERT_FALSE(isCombinedConstruct(OMPD_parallel));
+}

>From cb7c0f8c1d929939bccbd2565cd11132c18a9687 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Wed, 17 Apr 2024 11:42:32 -0500
Subject: [PATCH 2/3] Rename test

---
 .../Frontend/{OpenMPComposeTest.cpp => OpenMPCompositionTest.cpp} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename llvm/unittests/Frontend/{OpenMPComposeTest.cpp => 
OpenMPCompositionTest.cpp} (100%)

diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp 
b/llvm/unittests/Frontend/OpenMPCompositionTest.cpp
similarity index 100%
rename from llvm/unittests/Frontend/OpenMPComposeTest.cpp
rename to llvm/unittests/Frontend/OpenMPCompositionTest.cpp

>From 8f935fbcd7ee8a572e0a5242d1b6ad5c5a70975d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Wed, 17 Apr 2024 11:46:48 -0500
Subject: [PATCH 3/3] Finish the renaming

---
 llvm/unittests/Frontend/CMakeLists.txt| 2 +-
 llvm/unittests/Frontend/OpenMPCompositionTest.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/unittests/Frontend/CMakeLists.txt 
b/llvm/unittests/Frontend/CMakeLists.txt
index 

[llvm-branch-commits] [llvm] [Frontend][OpenMP] Add functions for checking construct type (PR #87258)

2024-04-17 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From a889f3074fc8c4ae5c6d9480308be0501217b9ff Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 11 Mar 2024 12:55:38 -0500
Subject: [PATCH 1/2] [Frontend][OpenMP] Add functions for checking construct
 type

Implement helper functions to identify leaf, composite, and combined
constructs.
---
 llvm/include/llvm/Frontend/OpenMP/OMP.h   |  4 +++
 llvm/lib/Frontend/OpenMP/OMP.cpp  | 25 ++
 llvm/unittests/Frontend/OpenMPComposeTest.cpp | 26 +++
 3 files changed, 55 insertions(+)

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h 
b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index 4ed47f15dfe59e..ec8ae68f1c2ca0 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -20,6 +20,10 @@
 namespace llvm::omp {
 ArrayRef getLeafConstructs(Directive D);
 Directive getCompoundConstruct(ArrayRef Parts);
+
+bool isLeafConstruct(Directive D);
+bool isCompositeConstruct(Directive D);
+bool isCombinedConstruct(Directive D);
 } // namespace llvm::omp
 
 #endif // LLVM_FRONTEND_OPENMP_OMP_H
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index dd99d3d074fd1e..98d7c63bb8537e 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -78,4 +78,29 @@ Directive getCompoundConstruct(ArrayRef Parts) {
 return Found;
   return OMPD_unknown;
 }
+
+bool isLeafConstruct(Directive D) { return getLeafConstructs(D).empty(); }
+
+bool isCompositeConstruct(Directive D) {
+  // OpenMP Spec 5.2: [17.3, 8-9]
+  // If directive-name-A and directive-name-B both correspond to loop-
+  // associated constructs then directive-name is a composite construct
+  llvm::ArrayRef Leafs{getLeafConstructs(D)};
+  if (Leafs.empty())
+return false;
+  if (getDirectiveAssociation(Leafs.front()) != Association::Loop)
+return false;
+
+  size_t numLoopConstructs =
+  llvm::count_if(Leafs.drop_front(), [](Directive L) {
+return getDirectiveAssociation(L) == Association::Loop;
+  });
+  return numLoopConstructs != 0;
+}
+
+bool isCombinedConstruct(Directive D) {
+  // OpenMP Spec 5.2: [17.3, 9-10]
+  // Otherwise directive-name is a combined construct.
+  return !getLeafConstructs(D).empty() && !isCompositeConstruct(D);
+}
 } // namespace llvm::omp
diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp 
b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
index 29b1be4eb3432c..cc02af8bf67c26 100644
--- a/llvm/unittests/Frontend/OpenMPComposeTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
@@ -39,3 +39,29 @@ TEST(Composition, GetCompoundConstruct) {
   Directive C7 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd});
   ASSERT_EQ(C7, OMPD_parallel_for_simd);
 }
+
+TEST(Composition, IsLeafConstruct) {
+  ASSERT_TRUE(isLeafConstruct(OMPD_loop));
+  ASSERT_TRUE(isLeafConstruct(OMPD_teams));
+  ASSERT_FALSE(isLeafConstruct(OMPD_for_simd));
+  ASSERT_FALSE(isLeafConstruct(OMPD_distribute_simd));
+}
+
+TEST(Composition, IsCompositeConstruct) {
+  ASSERT_TRUE(isCompositeConstruct(OMPD_distribute_simd));
+  ASSERT_FALSE(isCompositeConstruct(OMPD_for));
+  ASSERT_TRUE(isCompositeConstruct(OMPD_for_simd));
+  // directive-name-A = "parallel", directive-name-B = "for simd",
+  // only directive-name-A is loop-associated, so this is not a
+  // composite construct, even though "for simd" is.
+  ASSERT_FALSE(isCompositeConstruct(OMPD_parallel_for_simd));
+}
+
+TEST(Composition, IsCombinedConstruct) {
+  // "parallel for simd" is a combined construct, see comment in
+  // IsCompositeConstruct.
+  ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for_simd));
+  ASSERT_FALSE(isCombinedConstruct(OMPD_for_simd));
+  ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for));
+  ASSERT_FALSE(isCombinedConstruct(OMPD_parallel));
+}

>From cb7c0f8c1d929939bccbd2565cd11132c18a9687 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Wed, 17 Apr 2024 11:42:32 -0500
Subject: [PATCH 2/2] Rename test

---
 .../Frontend/{OpenMPComposeTest.cpp => OpenMPCompositionTest.cpp} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename llvm/unittests/Frontend/{OpenMPComposeTest.cpp => 
OpenMPCompositionTest.cpp} (100%)

diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp 
b/llvm/unittests/Frontend/OpenMPCompositionTest.cpp
similarity index 100%
rename from llvm/unittests/Frontend/OpenMPComposeTest.cpp
rename to llvm/unittests/Frontend/OpenMPCompositionTest.cpp

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


[llvm-branch-commits] [flang] [flang][OpenMP] Concatenate begin and end clauses into single list (PR #89090)

2024-04-17 Thread via llvm-branch-commits

llvmbot wrote:




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

Author: Krzysztof Parzyszek (kparzysz)


Changes

This will remove the distinction between begin clauses and end clauses,
and process all of them together.

---

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+99-123) 


``diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 4424788e0132e2..304bef72534805 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1121,16 +1121,14 @@ static void 
genSimdClauses(Fortran::lower::AbstractConverter ,
 
 static void genSingleClauses(Fortran::lower::AbstractConverter ,
  Fortran::semantics::SemanticsContext ,
- const List ,
- const List , mlir::Location 
loc,
+ const List , mlir::Location loc,
  mlir::omp::SingleClauseOps ) {
-  ClauseProcessor bcp(converter, semaCtx, beginClauses);
-  bcp.processAllocate(clauseOps);
+  ClauseProcessor cp(converter, semaCtx, clauses);
+  cp.processAllocate(clauseOps);
   // TODO Support delayed privatization.
 
-  ClauseProcessor ecp(converter, semaCtx, endClauses);
-  ecp.processCopyprivate(loc, clauseOps);
-  ecp.processNowait(clauseOps);
+  cp.processCopyprivate(loc, clauseOps);
+  cp.processNowait(clauseOps);
 }
 
 static void genTargetClauses(
@@ -1280,30 +1278,26 @@ static void genWsloopClauses(
 Fortran::lower::AbstractConverter ,
 Fortran::semantics::SemanticsContext ,
 Fortran::lower::StatementContext ,
-Fortran::lower::pft::Evaluation , const List ,
-const List , mlir::Location loc,
-mlir::omp::WsloopClauseOps ,
+Fortran::lower::pft::Evaluation , const List ,
+mlir::Location loc, mlir::omp::WsloopClauseOps ,
 llvm::SmallVectorImpl ,
 llvm::SmallVectorImpl ,
 llvm::SmallVectorImpl ) {
   fir::FirOpBuilder  = converter.getFirOpBuilder();
-  ClauseProcessor bcp(converter, semaCtx, beginClauses);
-  bcp.processCollapse(loc, eval, clauseOps, iv);
-  bcp.processOrdered(clauseOps);
-  bcp.processReduction(loc, clauseOps, , );
-  bcp.processSchedule(stmtCtx, clauseOps);
+  ClauseProcessor cp(converter, semaCtx, clauses);
+  cp.processCollapse(loc, eval, clauseOps, iv);
+  cp.processOrdered(clauseOps);
+  cp.processReduction(loc, clauseOps, , );
+  cp.processSchedule(stmtCtx, clauseOps);
   clauseOps.loopInclusiveAttr = firOpBuilder.getUnitAttr();
   // TODO Support delayed privatization.
 
   if (ReductionProcessor::doReductionByRef(clauseOps.reductionVars))
 clauseOps.reductionByRefAttr = firOpBuilder.getUnitAttr();
 
-  if (!endClauses.empty()) {
-ClauseProcessor ecp(converter, semaCtx, endClauses);
-ecp.processNowait(clauseOps);
-  }
+  cp.processNowait(clauseOps);
 
-  bcp.processTODO(
+  cp.processTODO(
   loc, llvm::omp::Directive::OMPD_do);
 }
 
@@ -1557,17 +1551,15 @@ static mlir::omp::SingleOp
 genSingleOp(Fortran::lower::AbstractConverter ,
 Fortran::semantics::SemanticsContext ,
 Fortran::lower::pft::Evaluation , bool genNested,
-mlir::Location loc, const List ,
-const List ) {
+mlir::Location loc, const List ) {
   mlir::omp::SingleClauseOps clauseOps;
-  genSingleClauses(converter, semaCtx, beginClauses, endClauses, loc,
-   clauseOps);
+  genSingleClauses(converter, semaCtx, clauses, loc, clauseOps);
 
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, loc, eval,
 llvm::omp::Directive::OMPD_single)
   .setGenNested(genNested)
-  .setClauses(),
+  .setClauses(),
   clauseOps);
 }
 
@@ -1816,8 +1808,8 @@ static mlir::omp::WsloopOp
 genWsloopOp(Fortran::lower::AbstractConverter ,
 Fortran::semantics::SemanticsContext ,
 Fortran::lower::pft::Evaluation , mlir::Location loc,
-const List , const List ) {
-  DataSharingProcessor dsp(converter, semaCtx, beginClauses, eval);
+const List ) {
+  DataSharingProcessor dsp(converter, semaCtx, clauses, eval);
   dsp.processStep1();
 
   Fortran::lower::StatementContext stmtCtx;
@@ -1825,10 +1817,10 @@ genWsloopOp(Fortran::lower::AbstractConverter 
,
   llvm::SmallVector iv;
   llvm::SmallVector reductionTypes;
   llvm::SmallVector reductionSyms;
-  genWsloopClauses(converter, semaCtx, stmtCtx, eval, beginClauses, endClauses,
-   loc, clauseOps, iv, reductionTypes, reductionSyms);
+  genWsloopClauses(converter, semaCtx, stmtCtx, eval, clauses, loc, clauseOps,
+   iv, reductionTypes, reductionSyms);
 
-  auto *nestedEval = getCollapsedLoopEval(eval, 
getCollapseValue(beginClauses));
+  auto *nestedEval = getCollapsedLoopEval(eval, getCollapseValue(clauses));
 
   auto ivCallback = 

[llvm-branch-commits] [flang] [flang][OpenMP] Concatenate begin and end clauses into single list (PR #89090)

2024-04-17 Thread Krzysztof Parzyszek via llvm-branch-commits

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

This will remove the distinction between begin clauses and end clauses,
and process all of them together.

>From cbfb3685f970cbd82d3b17d4341c389b32459447 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 1 Apr 2024 12:38:07 -0500
Subject: [PATCH] [flang][OpenMP] Concatenate begin and end clauses into single
 list

---
 flang/lib/Lower/OpenMP/OpenMP.cpp | 222 +-
 1 file changed, 99 insertions(+), 123 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 4424788e0132e2..304bef72534805 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1121,16 +1121,14 @@ static void 
genSimdClauses(Fortran::lower::AbstractConverter ,
 
 static void genSingleClauses(Fortran::lower::AbstractConverter ,
  Fortran::semantics::SemanticsContext ,
- const List ,
- const List , mlir::Location 
loc,
+ const List , mlir::Location loc,
  mlir::omp::SingleClauseOps ) {
-  ClauseProcessor bcp(converter, semaCtx, beginClauses);
-  bcp.processAllocate(clauseOps);
+  ClauseProcessor cp(converter, semaCtx, clauses);
+  cp.processAllocate(clauseOps);
   // TODO Support delayed privatization.
 
-  ClauseProcessor ecp(converter, semaCtx, endClauses);
-  ecp.processCopyprivate(loc, clauseOps);
-  ecp.processNowait(clauseOps);
+  cp.processCopyprivate(loc, clauseOps);
+  cp.processNowait(clauseOps);
 }
 
 static void genTargetClauses(
@@ -1280,30 +1278,26 @@ static void genWsloopClauses(
 Fortran::lower::AbstractConverter ,
 Fortran::semantics::SemanticsContext ,
 Fortran::lower::StatementContext ,
-Fortran::lower::pft::Evaluation , const List ,
-const List , mlir::Location loc,
-mlir::omp::WsloopClauseOps ,
+Fortran::lower::pft::Evaluation , const List ,
+mlir::Location loc, mlir::omp::WsloopClauseOps ,
 llvm::SmallVectorImpl ,
 llvm::SmallVectorImpl ,
 llvm::SmallVectorImpl ) {
   fir::FirOpBuilder  = converter.getFirOpBuilder();
-  ClauseProcessor bcp(converter, semaCtx, beginClauses);
-  bcp.processCollapse(loc, eval, clauseOps, iv);
-  bcp.processOrdered(clauseOps);
-  bcp.processReduction(loc, clauseOps, , );
-  bcp.processSchedule(stmtCtx, clauseOps);
+  ClauseProcessor cp(converter, semaCtx, clauses);
+  cp.processCollapse(loc, eval, clauseOps, iv);
+  cp.processOrdered(clauseOps);
+  cp.processReduction(loc, clauseOps, , );
+  cp.processSchedule(stmtCtx, clauseOps);
   clauseOps.loopInclusiveAttr = firOpBuilder.getUnitAttr();
   // TODO Support delayed privatization.
 
   if (ReductionProcessor::doReductionByRef(clauseOps.reductionVars))
 clauseOps.reductionByRefAttr = firOpBuilder.getUnitAttr();
 
-  if (!endClauses.empty()) {
-ClauseProcessor ecp(converter, semaCtx, endClauses);
-ecp.processNowait(clauseOps);
-  }
+  cp.processNowait(clauseOps);
 
-  bcp.processTODO(
+  cp.processTODO(
   loc, llvm::omp::Directive::OMPD_do);
 }
 
@@ -1557,17 +1551,15 @@ static mlir::omp::SingleOp
 genSingleOp(Fortran::lower::AbstractConverter ,
 Fortran::semantics::SemanticsContext ,
 Fortran::lower::pft::Evaluation , bool genNested,
-mlir::Location loc, const List ,
-const List ) {
+mlir::Location loc, const List ) {
   mlir::omp::SingleClauseOps clauseOps;
-  genSingleClauses(converter, semaCtx, beginClauses, endClauses, loc,
-   clauseOps);
+  genSingleClauses(converter, semaCtx, clauses, loc, clauseOps);
 
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, loc, eval,
 llvm::omp::Directive::OMPD_single)
   .setGenNested(genNested)
-  .setClauses(),
+  .setClauses(),
   clauseOps);
 }
 
@@ -1816,8 +1808,8 @@ static mlir::omp::WsloopOp
 genWsloopOp(Fortran::lower::AbstractConverter ,
 Fortran::semantics::SemanticsContext ,
 Fortran::lower::pft::Evaluation , mlir::Location loc,
-const List , const List ) {
-  DataSharingProcessor dsp(converter, semaCtx, beginClauses, eval);
+const List ) {
+  DataSharingProcessor dsp(converter, semaCtx, clauses, eval);
   dsp.processStep1();
 
   Fortran::lower::StatementContext stmtCtx;
@@ -1825,10 +1817,10 @@ genWsloopOp(Fortran::lower::AbstractConverter 
,
   llvm::SmallVector iv;
   llvm::SmallVector reductionTypes;
   llvm::SmallVector reductionSyms;
-  genWsloopClauses(converter, semaCtx, stmtCtx, eval, beginClauses, endClauses,
-   loc, clauseOps, iv, reductionTypes, reductionSyms);
+  genWsloopClauses(converter, semaCtx, stmtCtx, eval, clauses, loc, clauseOps,
+   iv, reductionTypes, reductionSyms);
 
-  auto *nestedEval = getCollapsedLoopEval(eval, 

[llvm-branch-commits] [flang] [llvm] [Frontend][OpenMP] Refactor getLeafConstructs, add getCompoundConstruct (PR #87247)

2024-04-17 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From f725face892cef4faf9f17d4b549541bdbcd7e08 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Fri, 29 Mar 2024 09:20:41 -0500
Subject: [PATCH 1/3] [flang][OpenMP] Move clause/object conversion to happen
 early, in genOMP

This removes the last use of genOmpObectList2, which has now been removed.
---
 flang/lib/Lower/OpenMP/ClauseProcessor.h  |   5 +-
 flang/lib/Lower/OpenMP/DataSharingProcessor.h |   5 +-
 flang/lib/Lower/OpenMP/OpenMP.cpp | 424 +-
 flang/lib/Lower/OpenMP/Utils.cpp  |  30 +-
 flang/lib/Lower/OpenMP/Utils.h|   6 +-
 5 files changed, 218 insertions(+), 252 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h 
b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index db7a1b8335f818..f4d659b70cfee7 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -49,9 +49,8 @@ class ClauseProcessor {
 public:
   ClauseProcessor(Fortran::lower::AbstractConverter ,
   Fortran::semantics::SemanticsContext ,
-  const Fortran::parser::OmpClauseList )
-  : converter(converter), semaCtx(semaCtx),
-clauses(makeClauses(clauses, semaCtx)) {}
+  const List )
+  : converter(converter), semaCtx(semaCtx), clauses(clauses) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
   bool processCollapse(
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.h 
b/flang/lib/Lower/OpenMP/DataSharingProcessor.h
index c11ee299c5d085..ef7b14327278e3 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.h
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.h
@@ -78,13 +78,12 @@ class DataSharingProcessor {
 public:
   DataSharingProcessor(Fortran::lower::AbstractConverter ,
Fortran::semantics::SemanticsContext ,
-   const Fortran::parser::OmpClauseList ,
+   const List ,
Fortran::lower::pft::Evaluation ,
bool useDelayedPrivatization = false,
Fortran::lower::SymMap *symTable = nullptr)
   : hasLastPrivateOp(false), converter(converter),
-firOpBuilder(converter.getFirOpBuilder()),
-clauses(omp::makeClauses(opClauseList, semaCtx)), eval(eval),
+firOpBuilder(converter.getFirOpBuilder()), clauses(clauses), 
eval(eval),
 useDelayedPrivatization(useDelayedPrivatization), symTable(symTable) {}
 
   // Privatisation is split into two steps.
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index edae453972d3d9..23dc25ac1ae9a1 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -17,6 +17,7 @@
 #include "DataSharingProcessor.h"
 #include "DirectivesCommon.h"
 #include "ReductionProcessor.h"
+#include "Utils.h"
 #include "flang/Common/idioms.h"
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/ConvertExpr.h"
@@ -310,14 +311,15 @@ static void getDeclareTargetInfo(
   } else if (const auto *clauseList{
  Fortran::parser::Unwrap(
  spec.u)}) {
-if (clauseList->v.empty()) {
+List clauses = makeClauses(*clauseList, semaCtx);
+if (clauses.empty()) {
   // Case: declare target, implicit capture of function
   symbolAndClause.emplace_back(
   mlir::omp::DeclareTargetCaptureClause::to,
   eval.getOwningProcedure()->getSubprogramSymbol());
 }
 
-ClauseProcessor cp(converter, semaCtx, *clauseList);
+ClauseProcessor cp(converter, semaCtx, clauses);
 cp.processDeviceType(clauseOps);
 cp.processEnter(symbolAndClause);
 cp.processLink(symbolAndClause);
@@ -597,14 +599,11 @@ static void removeStoreOp(mlir::Operation *reductionOp, 
mlir::Value symVal) {
 // TODO: Generate the reduction operation during lowering instead of creating
 // and removing operations since this is not a robust approach. Also, removing
 // ops in the builder (instead of a rewriter) is probably not the best 
approach.
-static void
-genOpenMPReduction(Fortran::lower::AbstractConverter ,
-   Fortran::semantics::SemanticsContext ,
-   const Fortran::parser::OmpClauseList ) {
+static void genOpenMPReduction(Fortran::lower::AbstractConverter ,
+   Fortran::semantics::SemanticsContext ,
+   const List ) {
   fir::FirOpBuilder  = converter.getFirOpBuilder();
 
-  List clauses{makeClauses(clauseList, semaCtx)};
-
   for (const Clause  : clauses) {
 if (const auto  =
 std::get_if()) {
@@ -812,7 +811,7 @@ struct OpWithBodyGenInfo {
 return *this;
   }
 
-  OpWithBodyGenInfo (const Fortran::parser::OmpClauseList *value) {
+  OpWithBodyGenInfo (const List *value) {
 clauses = value;
 return *this;
   }
@@ -848,7 +847,7 @@ struct 

[llvm-branch-commits] [libcxx] release/18.x: [libcxx] coerce formatter precision to int (#87738) (PR #87801)

2024-04-17 Thread Brian Cain via llvm-branch-commits

androm3da wrote:

I think omitting this from the release notes makes sense. 

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


[llvm-branch-commits] [llvm] [RISCV] Don't use V0 directly in patterns (PR #88496)

2024-04-17 Thread Pengcheng Wang via llvm-branch-commits

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


[llvm-branch-commits] [llvm] [RISCV] Don't use V0 directly in patterns (PR #88496)

2024-04-17 Thread Pengcheng Wang via llvm-branch-commits

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


[llvm-branch-commits] [clang] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

2024-04-17 Thread Erich Keane via llvm-branch-commits


@@ -590,7 +596,7 @@ class FrontendOptions {
 EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
 EmitSymbolGraphSymbolLabelsForTesting(false),
 EmitPrettySymbolGraphs(false), GenReducedBMI(false),
-TimeTraceGranularity(500) {}
+UseClangIRPipeline(), TimeTraceGranularity(500) {}

erichkeane wrote:

Why isn't this initializing this to a value? I would expect it to have  'false' 
here.
```suggestion
UseClangIRPipeline(false), TimeTraceGranularity(500) {}
```

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


[llvm-branch-commits] [clang] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

2024-04-17 Thread Erich Keane via llvm-branch-commits


@@ -2876,6 +2876,15 @@ def flax_vector_conversions : Flag<["-"], 
"flax-vector-conversions">, Group, Group,
   HelpText<"Force linking the clang builtins runtime library">;
+
+/// ClangIR-specific options - BEGIN
+def fclangir_enable : Flag<["-"], "fclangir-enable">, Visibility<[ClangOption, 
CC1Option]>,
+  Group, HelpText<"Use ClangIR pipeline to compile">,
+  MarshallingInfoFlag>;
+def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
+  Group, HelpText<"Build ASTs and then lower to ClangIR, emit 
the .cir file">;

erichkeane wrote:

The 'help' text says this outputs to a file: Does this actually, or does it 
work more like -emit-llvm, which outputs to whatever the 'out' file is?

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


[llvm-branch-commits] [libcxx] release/18.x: [libc++] Fix -Wgnu-include-next in stddef.h (#88214) (PR #88419)

2024-04-17 Thread Louis Dionne via llvm-branch-commits

ldionne wrote:

I don't think a release note is necessary here because we introduced the "bug" 
and fixed it in the same point-release. So from the user's perspective there 
was no issue introduced.

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


[llvm-branch-commits] [llvm] Revert "[Mips] Fix missing sign extension in expansion of sub-word atomic max (#77072)" (PR #88818)

2024-04-17 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

Given that this change has already caused two distinct bugs, I don't think we 
will accept a backport for it anyway, so don't worry about the release branch.

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


[llvm-branch-commits] [llvm] Revert "[Mips] Fix missing sign extension in expansion of sub-word atomic max (#77072)" (PR #88818)

2024-04-17 Thread Quentin Dian via llvm-branch-commits

DianQK wrote:

> > @yingopq The patches are not reverted in main, so you can base your fix on 
> > top of the existing changes (or revert them as part of your PR, if that's 
> > easier?)
> 
> Should it be consistent with the release branch, so that it is more 
> convenient to merge into the release branch?

Maybe you can revert them in your new PR, then we can use rebase and push to 
merge your PR.
We can also revert this PR (#88818) and cherry-pick your new patch in 
`release/18.x`.

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


[llvm-branch-commits] [llvm] Revert "[Mips] Fix missing sign extension in expansion of sub-word atomic max (#77072)" (PR #88818)

2024-04-17 Thread via llvm-branch-commits

yingopq wrote:

> @yingopq The patches are not reverted in main, so you can base your fix on 
> top of the existing changes (or revert them as part of your PR, if that's 
> easier?)

Should it be consistent with the release branch, so that it is more convenient 
to merge into the release branch?

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


[llvm-branch-commits] [llvm] Revert "[Mips] Fix missing sign extension in expansion of sub-word atomic max (#77072)" (PR #88818)

2024-04-17 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

@yingopq The patches are not reverted in main, so you can base your fix on top 
of the existing changes (or revert them as part of your PR, if that's easier?)

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


[llvm-branch-commits] [llvm] Revert "[Mips] Fix missing sign extension in expansion of sub-word atomic max (#77072)" (PR #88818)

2024-04-17 Thread via llvm-branch-commits

yingopq wrote:

@nikic Hi, have you not reverted those two patches yet? I plan to submit new 
patch which has addressed this issue.

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


[llvm-branch-commits] [clang] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

2024-04-17 Thread Nathan Lanza via llvm-branch-commits

https://github.com/lanza updated https://github.com/llvm/llvm-project/pull/89030

>From 21d80d2c5e2d67d54bfb450eb53b1fa73ffb635a Mon Sep 17 00:00:00 2001
From: Nathan Lanza 
Date: Wed, 17 Apr 2024 07:26:49 +
Subject: [PATCH] fix options.td

Created using spr 1.3.5
---
 clang/include/clang/Driver/Options.td | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 659650baf218f8..3c64ad45c1f86a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2876,18 +2876,21 @@ def flax_vector_conversions : Flag<["-"], 
"flax-vector-conversions">, Group, Group,
   HelpText<"Force linking the clang builtins runtime library">;
-def flto_EQ : Joined<["-"], "flto=">,
-  Visibility<[ClangOption, CLOption, CC1Option, FC1Option, FlangOption]>,
-  Group,
-  HelpText<"Set LTO mode">, Values<"thin,full">;
-def flto_EQ_jobserver : Flag<["-"], "flto=jobserver">, 
Visibility<[ClangOption, FlangOption]>, Group,
-  Alias, AliasArgs<["full"]>, HelpText<"Enable LTO in 'full' mode">;
+
 /// ClangIR-specific options - BEGIN
 def fclangir_enable : Flag<["-"], "fclangir-enable">, Visibility<[ClangOption, 
CC1Option]>,
   Group, HelpText<"Use ClangIR pipeline to compile">,
   MarshallingInfoFlag>;
 def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
   Group, HelpText<"Build ASTs and then lower to ClangIR, emit 
the .cir file">;
+/// ClangIR-specific options - END
+
+def flto_EQ : Joined<["-"], "flto=">,
+  Visibility<[ClangOption, CLOption, CC1Option, FC1Option, FlangOption]>,
+  Group,
+  HelpText<"Set LTO mode">, Values<"thin,full">;
+def flto_EQ_jobserver : Flag<["-"], "flto=jobserver">, 
Visibility<[ClangOption, FlangOption]>, Group,
+  Alias, AliasArgs<["full"]>, HelpText<"Enable LTO in 'full' mode">;
 def flto_EQ_auto : Flag<["-"], "flto=auto">, Visibility<[ClangOption, 
FlangOption]>, Group,
   Alias, AliasArgs<["full"]>, HelpText<"Enable LTO in 'full' mode">;
 def flto : Flag<["-"], "flto">,

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


[llvm-branch-commits] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

2024-04-17 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Nathan Lanza (lanza)


Changes

Introduce just the option definitions and support for their existance at
a few different points in the frontend. This will be followed soon by
functionality that uses it.


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


5 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+6) 
- (modified) clang/include/clang/Frontend/FrontendOptions.h (+7-1) 
- (modified) clang/lib/Driver/Driver.cpp (+3) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+4) 
- (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+2) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e24626913add76..659650baf218f8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2882,6 +2882,12 @@ def flto_EQ : Joined<["-"], "flto=">,
   HelpText<"Set LTO mode">, Values<"thin,full">;
 def flto_EQ_jobserver : Flag<["-"], "flto=jobserver">, 
Visibility<[ClangOption, FlangOption]>, Group,
   Alias, AliasArgs<["full"]>, HelpText<"Enable LTO in 'full' mode">;
+/// ClangIR-specific options - BEGIN
+def fclangir_enable : Flag<["-"], "fclangir-enable">, Visibility<[ClangOption, 
CC1Option]>,
+  Group, HelpText<"Use ClangIR pipeline to compile">,
+  MarshallingInfoFlag>;
+def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
+  Group, HelpText<"Build ASTs and then lower to ClangIR, emit 
the .cir file">;
 def flto_EQ_auto : Flag<["-"], "flto=auto">, Visibility<[ClangOption, 
FlangOption]>, Group,
   Alias, AliasArgs<["full"]>, HelpText<"Enable LTO in 'full' mode">;
 def flto : Flag<["-"], "flto">,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index a738c1f3757682..236345b2143670 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -65,6 +65,9 @@ enum ActionKind {
   /// Translate input source into HTML.
   EmitHTML,
 
+  /// Emit a .cir file
+  EmitCIR,
+
   /// Emit a .ll file.
   EmitLLVM,
 
@@ -408,6 +411,9 @@ class FrontendOptions {
   LLVM_PREFERRED_TYPE(bool)
   unsigned GenReducedBMI : 1;
 
+  /// Use Clang IR pipeline to emit code
+  unsigned UseClangIRPipeline : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
@@ -590,7 +596,7 @@ class FrontendOptions {
 EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
 EmitSymbolGraphSymbolLabelsForTesting(false),
 EmitPrettySymbolGraphs(false), GenReducedBMI(false),
-TimeTraceGranularity(500) {}
+UseClangIRPipeline(), TimeTraceGranularity(500) {}
 
   /// getInputKindForExtension - Return the appropriate input kind for a file
   /// extension. For example, "c" would return Language::C.
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..d8ada220e6bd4a 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -361,6 +361,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList ,
  (PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
  (PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
  (PhaseArg = DAL.getLastArg(options::OPT__analyze)) ||
+ (PhaseArg = DAL.getLastArg(options::OPT_emit_cir)) ||
  (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
 FinalPhase = phases::Compile;
 
@@ -4799,6 +4800,8 @@ Action *Driver::ConstructPhaseAction(
   return C.MakeAction(Input, types::TY_Remap);
 if (Args.hasArg(options::OPT_emit_ast))
   return C.MakeAction(Input, types::TY_AST);
+if (Args.hasArg(options::OPT_emit_cir))
+  return C.MakeAction(Input, types::TY_CIR);
 if (Args.hasArg(options::OPT_module_file_info))
   return C.MakeAction(Input, types::TY_ModuleFile);
 if (Args.hasArg(options::OPT_verify_pch))
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1f1f5440ddd75f..27b75086029436 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2544,6 +2544,7 @@ static const auto () {
   {frontend::DumpTokens, OPT_dump_tokens},
   {frontend::EmitAssembly, OPT_S},
   {frontend::EmitBC, OPT_emit_llvm_bc},
+  {frontend::EmitCIR, OPT_emit_cir},
   {frontend::EmitHTML, OPT_emit_html},
   {frontend::EmitLLVM, OPT_emit_llvm},
   {frontend::EmitLLVMOnly, OPT_emit_llvm_only},
@@ -2886,6 +2887,8 @@ static bool ParseFrontendArgs(FrontendOptions , 
ArgList ,
   if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
 Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
<< "-emit-module";
+  if 

[llvm-branch-commits] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

2024-04-17 Thread Nathan Lanza via llvm-branch-commits

https://github.com/lanza created https://github.com/llvm/llvm-project/pull/89030

Introduce just the option definitions and support for their existance at
a few different points in the frontend. This will be followed soon by
functionality that uses it.



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


[llvm-branch-commits] [llvm] release/18x:[X86] Fix typo: QWORD alignment is greater than or equal to 8, not greater than 8 (#87819) (PR #88394)

2024-04-17 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

This looks like an optimization improvement, not a bug fix, to me, and as such 
should not be backported.

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


[llvm-branch-commits] [openmp] 62305b2 - Revert "[Libomptarget] Rework Record & Replay to be a plugin member (#88928)"

2024-04-17 Thread via llvm-branch-commits

Author: Jan Patrick Lehr
Date: 2024-04-17T08:54:04+02:00
New Revision: 62305b2e66879cefebf25af1720963f81903ca01

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

LOG: Revert "[Libomptarget] Rework Record & Replay to be a plugin member 
(#88928)"

This reverts commit 9a0a28f8384b2cb534953df33bf124f01f0e0d0e.

Added: 


Modified: 
openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp

Removed: 




diff  --git 
a/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h 
b/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
index 7f05464f36c1f3..79e8464bfda5c1 100644
--- a/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
+++ b/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
@@ -45,8 +45,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
 
-struct RecordReplayTy;
-
 namespace llvm {
 namespace omp {
 namespace target {
@@ -1033,12 +1031,6 @@ struct GenericPluginTy {
 return *RPCServer;
   }
 
-  /// Get a reference to the R interface for this plugin.
-  RecordReplayTy () const {
-assert(RecordReplay && "R not initialized");
-return *RecordReplay;
-  }
-
   /// Get the OpenMP requires flags set for this plugin.
   int64_t getRequiresFlags() const { return RequiresFlags; }
 
@@ -1228,9 +1220,6 @@ struct GenericPluginTy {
 
   /// The interface between the plugin and the GPU for host services.
   RPCServerTy *RPCServer;
-
-  /// The interface into the record-and-replay functionality.
-  RecordReplayTy *RecordReplay;
 };
 
 namespace Plugin {

diff  --git 
a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp 
b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
index 6df9798f12e3d0..b5f3c45c835fdb 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
@@ -362,6 +362,8 @@ struct RecordReplayTy {
   }
 };
 
+static RecordReplayTy RecordReplay;
+
 // Extract the mapping of host function pointers to device function pointers
 // from the entry table. Functions marked as 'indirect' in OpenMP will have
 // offloading entries generated for them which map the host's function pointer
@@ -471,8 +473,7 @@ GenericKernelTy::getKernelLaunchEnvironment(
   // Ctor/Dtor have no arguments, replaying uses the original kernel launch
   // environment. Older versions of the compiler do not generate a kernel
   // launch environment.
-  if (isCtorOrDtor() ||
-  GenericDevice.Plugin.getRecordAndReplay().isReplaying() ||
+  if (isCtorOrDtor() || RecordReplay.isReplaying() ||
   Version < OMP_KERNEL_ARG_MIN_VERSION_WITH_DYN_PTR)
 return nullptr;
 
@@ -561,7 +562,6 @@ Error GenericKernelTy::launch(GenericDeviceTy 
, void **ArgPtrs,
 
   // Record the kernel description after we modified the argument count and num
   // blocks/threads.
-  RecordReplayTy  = GenericDevice.Plugin.getRecordAndReplay();
   if (RecordReplay.isRecording()) {
 RecordReplay.saveImage(getName(), getImage());
 RecordReplay.saveKernelInput(getName(), getImage());
@@ -839,6 +839,9 @@ Error GenericDeviceTy::deinit(GenericPluginTy ) {
 delete MemoryManager;
   MemoryManager = nullptr;
 
+  if (RecordReplay.isRecordingOrReplaying())
+RecordReplay.deinit();
+
   if (RPCServer)
 if (auto Err = RPCServer->deinitDevice(*this))
   return Err;
@@ -855,7 +858,6 @@ Error GenericDeviceTy::deinit(GenericPluginTy ) {
 
   return deinitImpl();
 }
-
 Expected
 GenericDeviceTy::loadBinary(GenericPluginTy ,
 const __tgt_device_image *InputTgtImage) {
@@ -890,8 +892,7 @@ GenericDeviceTy::loadBinary(GenericPluginTy ,
 return std::move(Err);
 
   // Setup the global device memory pool if needed.
-  if (!Plugin.getRecordAndReplay().isReplaying() &&
-  shouldSetupDeviceMemoryPool()) {
+  if (!RecordReplay.isReplaying() && shouldSetupDeviceMemoryPool()) {
 uint64_t HeapSize;
 auto SizeOrErr = getDeviceHeapSize(HeapSize);
 if (SizeOrErr) {
@@ -1306,8 +1307,8 @@ Expected GenericDeviceTy::dataAlloc(int64_t Size, 
void *HostPtr,
 TargetAllocTy Kind) {
   void *Alloc = nullptr;
 
-  if (Plugin.getRecordAndReplay().isRecordingOrReplaying())
-return Plugin.getRecordAndReplay().alloc(Size);
+  if (RecordReplay.isRecordingOrReplaying())
+return RecordReplay.alloc(Size);
 
   switch (Kind) {
   case TARGET_ALLOC_DEFAULT:
@@ -1343,7 +1344,7 @@ Expected GenericDeviceTy::dataAlloc(int64_t Size, 
void *HostPtr,
 
 Error GenericDeviceTy::dataDelete(void *TgtPtr, TargetAllocTy Kind) {
   // Free is a noop when recording or 

[llvm-branch-commits] [llvm] release/18x:[X86] Fix typo: QWORD alignment is greater than or equal to 8, not greater than 8 (#87819) (PR #88394)

2024-04-17 Thread Nikita Popov via llvm-branch-commits

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


[llvm-branch-commits] [llvm] [nfc][ThinLTO] Generate import status in per-module combined summary (PR #88024)

2024-04-17 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/88024

>From cfb63d775d43a28b560d938346f1dd4b2dddc765 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Thu, 4 Apr 2024 11:54:17 -0700
Subject: [PATCH 1/3] function import changes

---
 llvm/include/llvm/IR/ModuleSummaryIndex.h |  24 
 .../llvm/Transforms/IPO/FunctionImport.h  |  18 ++-
 llvm/lib/LTO/LTO.cpp  |  13 +-
 llvm/lib/LTO/LTOBackend.cpp   |   5 +-
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp |   9 +-
 llvm/lib/Transforms/IPO/FunctionImport.cpp| 130 --
 llvm/tools/llvm-link/llvm-link.cpp|   2 +-
 7 files changed, 146 insertions(+), 55 deletions(-)

diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h 
b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 286b51bda0e2c1..259fe56ce5f63e 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -296,6 +296,30 @@ template <> struct DenseMapInfo {
   static unsigned getHashValue(ValueInfo I) { return (uintptr_t)I.getRef(); }
 };
 
+struct SummaryImportInfo {
+  enum class ImportType : uint8_t {
+NotImported = 0,
+Declaration = 1,
+Definition = 2,
+  };
+  unsigned Type : 3;
+  SummaryImportInfo() : Type(static_cast(ImportType::NotImported)) {}
+  SummaryImportInfo(ImportType Type) : Type(static_cast(Type)) {}
+
+  // FIXME: delete the first two set* helper function.
+  void updateType(ImportType InputType) {
+Type = std::max(Type, static_cast(InputType));
+  }
+
+  bool isDefinition() const {
+return static_cast(Type) == ImportType::Definition;
+  }
+
+  bool isDeclaration() const {
+return static_cast(Type) == ImportType::Declaration;
+  }
+};
+
 /// Summary of memprof callsite metadata.
 struct CallsiteInfo {
   // Actual callee function.
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h 
b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
index c4d19e8641eca2..9adc0c31eed439 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
@@ -33,7 +33,14 @@ class FunctionImporter {
 public:
   /// Set of functions to import from a source module. Each entry is a set
   /// containing all the GUIDs of all functions to import for a source module.
-  using FunctionsToImportTy = std::unordered_set;
+  using FunctionsToImportTy = DenseMap;
+
+  // FIXME: Remove this.
+  enum ImportStatus {
+NotImported,
+ImportDeclaration,
+ImportDefinition,
+  };
 
   /// The different reasons selectCallee will chose not to import a
   /// candidate.
@@ -99,8 +106,10 @@ class FunctionImporter {
   /// index's module path string table).
   using ImportMapTy = DenseMap;
 
-  /// The set contains an entry for every global value the module exports.
-  using ExportSetTy = DenseSet;
+  /// The map contains an entry for every global value the module exports, the
+  /// key being the value info, and the value is the summary-based import info.
+  /// FIXME: Does this set need to be a map?
+  using ExportSetTy = DenseMap;
 
   /// A function of this type is used to load modules referenced by the index.
   using ModuleLoaderTy =
@@ -211,7 +220,8 @@ void gatherImportedSummariesForModule(
 StringRef ModulePath,
 const DenseMap ,
 const FunctionImporter::ImportMapTy ,
-std::map );
+std::map ,
+ModuleToGVSummaryPtrSet );
 
 /// Emit into \p OutputFilename the files module \p ModulePath will import 
from.
 std::error_code EmitImportsFiles(
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 53060df7f503e0..ace533fe28c92f 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -159,7 +159,7 @@ void llvm::computeLTOCacheKey(
   std::vector ExportsGUID;
   ExportsGUID.reserve(ExportList.size());
   for (const auto  : ExportList) {
-auto GUID = VI.getGUID();
+auto GUID = VI.first.getGUID();
 ExportsGUID.push_back(GUID);
   }
 
@@ -205,7 +205,7 @@ void llvm::computeLTOCacheKey(
 
 AddUint64(Entry.getFunctions().size());
 for (auto  : Entry.getFunctions())
-  AddUint64(Fn);
+  AddUint64(Fn.first);
   }
 
   // Include the hash for the resolved ODR.
@@ -277,7 +277,7 @@ void llvm::computeLTOCacheKey(
   for (const ImportModule  : ImportModulesVector)
 for (auto  : ImpM.getFunctions()) {
   GlobalValueSummary *S =
-  Index.findSummaryInModule(ImpF, ImpM.getIdentifier());
+  Index.findSummaryInModule(ImpF.first, ImpM.getIdentifier());
   AddUsedThings(S);
   // If this is an alias, we also care about any types/etc. that the 
aliasee
   // may reference.
@@ -1389,15 +1389,18 @@ class lto::ThinBackendProc {
   llvm::StringRef ModulePath,
   const std::string ) {
 std::map ModuleToSummariesForIndex;
+ModuleToGVSummaryPtrSet ModuleToDeclarationSummaries;
 std::error_code EC;
 gatherImportedSummariesForModule(ModulePath, 

[llvm-branch-commits] [clang] Backport fix for crash reported in #88181 (PR #89022)

2024-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)


Changes

Fixes #88181

(cherry picked from commit e096c144921daba59963f15e89d2ca6fb32d3a78)

The user requested the backport 
[here](https://github.com/llvm/llvm-project/pull/88536#issuecomment-2052237181).

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
(+5-1) 
- (added) clang/test/Analysis/invalid-ptr-checker.cpp (+10) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce7e615d878944..1e88b58725bd95 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1474,6 +1474,10 @@ Crash and bug fixes
 - Fix false positive in mutation check when using pointer to member function.
   (`#66204 `_)
 
+- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
+  matched user-defined ``strerror`` and similar library functions.
+  (`#88181 `_)
+
 Improvements
 
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index e5dd907c660d8e..b2947f590c4ec1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -205,8 +205,12 @@ void InvalidPtrChecker::postPreviousReturnInvalidatingCall(
   CE, LCtx, CE->getType(), C.blockCount());
   State = State->BindExpr(CE, LCtx, RetVal);
 
+  const auto *SymRegOfRetVal =
+  dyn_cast_or_null(RetVal.getAsRegion());
+  if (!SymRegOfRetVal)
+return;
+
   // Remember to this region.
-  const auto *SymRegOfRetVal = cast(RetVal.getAsRegion());
   const MemRegion *MR = SymRegOfRetVal->getBaseRegion();
   State = State->set(FD, MR);
 
diff --git a/clang/test/Analysis/invalid-ptr-checker.cpp 
b/clang/test/Analysis/invalid-ptr-checker.cpp
new file mode 100644
index 00..58bb45e0fb8421
--- /dev/null
+++ b/clang/test/Analysis/invalid-ptr-checker.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,security.cert.env.InvalidPtr 
-verify %s
+
+// expected-no-diagnostics
+
+namespace other {
+int strerror(int errnum); // custom strerror
+void no_crash_on_custom_strerror() {
+  (void)strerror(0); // no-crash
+}
+} // namespace other

``




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


[llvm-branch-commits] [clang] Backport fix for crash reported in #88181 (PR #89022)

2024-04-17 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/89022

Fixes #88181

(cherry picked from commit e096c144921daba59963f15e89d2ca6fb32d3a78)

The user requested the backport 
[here](https://github.com/llvm/llvm-project/pull/88536#issuecomment-2052237181).

>From ebe4abe49354d8f42fe403b8d0e6487f0febcf50 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Wed, 17 Apr 2024 08:02:49 +0200
Subject: [PATCH] [analyzer] Fix a security.cert.env.InvalidPtr crash

Fixes #88181

(cherry picked from commit e096c144921daba59963f15e89d2ca6fb32d3a78)
---
 clang/docs/ReleaseNotes.rst|  4 
 .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp |  6 +-
 clang/test/Analysis/invalid-ptr-checker.cpp| 10 ++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Analysis/invalid-ptr-checker.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce7e615d878944..1e88b58725bd95 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1474,6 +1474,10 @@ Crash and bug fixes
 - Fix false positive in mutation check when using pointer to member function.
   (`#66204 `_)
 
+- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
+  matched user-defined ``strerror`` and similar library functions.
+  (`#88181 `_)
+
 Improvements
 
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index e5dd907c660d8e..b2947f590c4ec1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -205,8 +205,12 @@ void InvalidPtrChecker::postPreviousReturnInvalidatingCall(
   CE, LCtx, CE->getType(), C.blockCount());
   State = State->BindExpr(CE, LCtx, RetVal);
 
+  const auto *SymRegOfRetVal =
+  dyn_cast_or_null(RetVal.getAsRegion());
+  if (!SymRegOfRetVal)
+return;
+
   // Remember to this region.
-  const auto *SymRegOfRetVal = cast(RetVal.getAsRegion());
   const MemRegion *MR = SymRegOfRetVal->getBaseRegion();
   State = State->set(FD, MR);
 
diff --git a/clang/test/Analysis/invalid-ptr-checker.cpp 
b/clang/test/Analysis/invalid-ptr-checker.cpp
new file mode 100644
index 00..58bb45e0fb8421
--- /dev/null
+++ b/clang/test/Analysis/invalid-ptr-checker.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,security.cert.env.InvalidPtr 
-verify %s
+
+// expected-no-diagnostics
+
+namespace other {
+int strerror(int errnum); // custom strerror
+void no_crash_on_custom_strerror() {
+  (void)strerror(0); // no-crash
+}
+} // namespace other

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


[llvm-branch-commits] [clang] Backport fix for crash reported in #88181 (PR #89022)

2024-04-17 Thread Balazs Benics via llvm-branch-commits

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