[llvm-branch-commits] [mlir] release/18.x: [ODS][NFC] Cast range.size() to int32_t in accumulation (#85629) (PR #86677)

2024-03-28 Thread Andrei Golubev via llvm-branch-commits

andrey-golubev wrote:

> Hi @EugeneZelenko (or anyone else). If you would like to add a note about 
> this fix in the release notes (completely optional). Please reply to this 
> comment with a one or two sentence description of the fix.

hi! @tstellar I don't think it's worth it: this is a tiny narrowing conversion 
warnings suppression (by adding explicit static cast), so not worth it to make 
it into release notes.

https://github.com/llvm/llvm-project/pull/86677
___
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: [SystemZ] Fix overflow flag for i128 USUBO (PR #86491)

2024-03-28 Thread Ulrich Weigand via llvm-branch-commits

uweigand wrote:

> Hi @uweigand (or anyone else). If you would like to add a note about this fix 
> in the release notes (completely optional). Please reply to this comment with 
> a one or two sentence description of the fix.

This fix is for a regression that only came in with LLVM 18 due to the rework 
of i128 support (which is already called out in the LLVM 18 release notes).  So 
I don't think there's really any strong need to add another release note.  If 
we did want to call this out specifically, I'd say something like:
- Fix a `llvm.usub.with.overflow.i128` wrong code generation regression that 
was introduced with LLVM 18.1.0.


https://github.com/llvm/llvm-project/pull/86491
___
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: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread via llvm-branch-commits

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

Backport c9db031c

Requested by: @nga888

>From 7a385f860df4319124494ca166a1878af3139440 Mon Sep 17 00:00:00 2001
From: Andrew Ng 
Date: Thu, 28 Mar 2024 11:41:49 +
Subject: [PATCH] [Support] Fix color handling in formatted_raw_ostream
 (#86700)

The color methods in formatted_raw_ostream were forwarding directly to
the underlying stream without considering existing buffered output. This
would cause incorrect colored output for buffered uses of
formatted_raw_ostream.

Fix this issue by applying the color to the formatted_raw_ostream itself
and temporarily disabling scanning of any color related output so as not
to affect the position tracking.

This fix means that workarounds that forced formatted_raw_ostream
buffering to be disabled can be removed. In the case of llvm-objdump,
this can improve disassembly performance when redirecting to a file by
more than an order of magnitude on both Windows and Linux. This
improvement restores the disassembly performance when redirecting to a
file to a level similar to before color support was added.

(cherry picked from commit c9db031c48852af491747dab86ef6f19195eb20d)
---
 llvm/include/llvm/Support/FormattedStream.h | 51 ++---
 llvm/lib/Support/FormattedStream.cpp|  3 ++
 llvm/tools/llvm-mc/llvm-mc.cpp  |  5 --
 llvm/tools/llvm-objdump/llvm-objdump.cpp|  7 ---
 4 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/llvm/include/llvm/Support/FormattedStream.h 
b/llvm/include/llvm/Support/FormattedStream.h
index 5f937cfa798408..850a18dbb94121 100644
--- a/llvm/include/llvm/Support/FormattedStream.h
+++ b/llvm/include/llvm/Support/FormattedStream.h
@@ -52,6 +52,10 @@ class formatted_raw_ostream : public raw_ostream {
   /// have the rest of it.
   SmallString<4> PartialUTF8Char;
 
+  /// DisableScan - Temporarily disable scanning of output. Used to ignore 
color
+  /// codes.
+  bool DisableScan;
+
   void write_impl(const char *Ptr, size_t Size) override;
 
   /// current_pos - Return the current position within the stream,
@@ -89,9 +93,33 @@ class formatted_raw_ostream : public raw_ostream {
   SetUnbuffered();
 TheStream->SetUnbuffered();
 
+enable_colors(TheStream->colors_enabled());
+
 Scanned = nullptr;
   }
 
+  void PreDisableScan() {
+assert(!DisableScan);
+ComputePosition(getBufferStart(), GetNumBytesInBuffer());
+assert(PartialUTF8Char.empty());
+DisableScan = true;
+  }
+
+  void PostDisableScan() {
+assert(DisableScan);
+DisableScan = false;
+Scanned = getBufferStart() + GetNumBytesInBuffer();
+  }
+
+  struct DisableScanScope {
+formatted_raw_ostream *S;
+
+DisableScanScope(formatted_raw_ostream *FRO) : S(FRO) {
+  S->PreDisableScan();
+}
+~DisableScanScope() { S->PostDisableScan(); }
+  };
+
 public:
   /// formatted_raw_ostream - Open the specified file for
   /// writing. If an error occurs, information about the error is
@@ -104,12 +132,12 @@ class formatted_raw_ostream : public raw_ostream {
   /// underneath it.
   ///
   formatted_raw_ostream(raw_ostream &Stream)
-  : TheStream(nullptr), Position(0, 0) {
+  : TheStream(nullptr), Position(0, 0), DisableScan(false) {
 setStream(Stream);
   }
-  explicit formatted_raw_ostream() : TheStream(nullptr), Position(0, 0) {
-Scanned = nullptr;
-  }
+  explicit formatted_raw_ostream()
+  : TheStream(nullptr), Position(0, 0), Scanned(nullptr),
+DisableScan(false) {}
 
   ~formatted_raw_ostream() override {
 flush();
@@ -136,17 +164,26 @@ class formatted_raw_ostream : public raw_ostream {
   }
 
   raw_ostream &resetColor() override {
-TheStream->resetColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::resetColor();
+}
 return *this;
   }
 
   raw_ostream &reverseColor() override {
-TheStream->reverseColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::reverseColor();
+}
 return *this;
   }
 
   raw_ostream &changeColor(enum Colors Color, bool Bold, bool BG) override {
-TheStream->changeColor(Color, Bold, BG);
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::changeColor(Color, Bold, BG);
+}
 return *this;
   }
 
diff --git a/llvm/lib/Support/FormattedStream.cpp 
b/llvm/lib/Support/FormattedStream.cpp
index c0d28435099570..c50530e76efc0a 100644
--- a/llvm/lib/Support/FormattedStream.cpp
+++ b/llvm/lib/Support/FormattedStream.cpp
@@ -94,6 +94,9 @@ void formatted_raw_ostream::UpdatePosition(const char *Ptr, 
size_t Size) {
 /// ComputePosition - Examine the current output and update line and column
 /// counts.
 void formatted_raw_ostream::ComputePosition(const char *Ptr, size_t Size) {
+  if (DisableScan)
+return;
+
   // If our previous scan pointer is inside the buffer, assume we already
   // scanned those bytes. This depends on raw_o

[llvm-branch-commits] [llvm] release/18.x: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/86940
___
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: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread via llvm-branch-commits

llvmbot wrote:

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

https://github.com/llvm/llvm-project/pull/86940
___
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: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: None (llvmbot)


Changes

Backport c9db031c

Requested by: @nga888

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


4 Files Affected:

- (modified) llvm/include/llvm/Support/FormattedStream.h (+44-7) 
- (modified) llvm/lib/Support/FormattedStream.cpp (+3) 
- (modified) llvm/tools/llvm-mc/llvm-mc.cpp (-5) 
- (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (-7) 


``diff
diff --git a/llvm/include/llvm/Support/FormattedStream.h 
b/llvm/include/llvm/Support/FormattedStream.h
index 5f937cfa798408..850a18dbb94121 100644
--- a/llvm/include/llvm/Support/FormattedStream.h
+++ b/llvm/include/llvm/Support/FormattedStream.h
@@ -52,6 +52,10 @@ class formatted_raw_ostream : public raw_ostream {
   /// have the rest of it.
   SmallString<4> PartialUTF8Char;
 
+  /// DisableScan - Temporarily disable scanning of output. Used to ignore 
color
+  /// codes.
+  bool DisableScan;
+
   void write_impl(const char *Ptr, size_t Size) override;
 
   /// current_pos - Return the current position within the stream,
@@ -89,9 +93,33 @@ class formatted_raw_ostream : public raw_ostream {
   SetUnbuffered();
 TheStream->SetUnbuffered();
 
+enable_colors(TheStream->colors_enabled());
+
 Scanned = nullptr;
   }
 
+  void PreDisableScan() {
+assert(!DisableScan);
+ComputePosition(getBufferStart(), GetNumBytesInBuffer());
+assert(PartialUTF8Char.empty());
+DisableScan = true;
+  }
+
+  void PostDisableScan() {
+assert(DisableScan);
+DisableScan = false;
+Scanned = getBufferStart() + GetNumBytesInBuffer();
+  }
+
+  struct DisableScanScope {
+formatted_raw_ostream *S;
+
+DisableScanScope(formatted_raw_ostream *FRO) : S(FRO) {
+  S->PreDisableScan();
+}
+~DisableScanScope() { S->PostDisableScan(); }
+  };
+
 public:
   /// formatted_raw_ostream - Open the specified file for
   /// writing. If an error occurs, information about the error is
@@ -104,12 +132,12 @@ class formatted_raw_ostream : public raw_ostream {
   /// underneath it.
   ///
   formatted_raw_ostream(raw_ostream &Stream)
-  : TheStream(nullptr), Position(0, 0) {
+  : TheStream(nullptr), Position(0, 0), DisableScan(false) {
 setStream(Stream);
   }
-  explicit formatted_raw_ostream() : TheStream(nullptr), Position(0, 0) {
-Scanned = nullptr;
-  }
+  explicit formatted_raw_ostream()
+  : TheStream(nullptr), Position(0, 0), Scanned(nullptr),
+DisableScan(false) {}
 
   ~formatted_raw_ostream() override {
 flush();
@@ -136,17 +164,26 @@ class formatted_raw_ostream : public raw_ostream {
   }
 
   raw_ostream &resetColor() override {
-TheStream->resetColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::resetColor();
+}
 return *this;
   }
 
   raw_ostream &reverseColor() override {
-TheStream->reverseColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::reverseColor();
+}
 return *this;
   }
 
   raw_ostream &changeColor(enum Colors Color, bool Bold, bool BG) override {
-TheStream->changeColor(Color, Bold, BG);
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::changeColor(Color, Bold, BG);
+}
 return *this;
   }
 
diff --git a/llvm/lib/Support/FormattedStream.cpp 
b/llvm/lib/Support/FormattedStream.cpp
index c0d28435099570..c50530e76efc0a 100644
--- a/llvm/lib/Support/FormattedStream.cpp
+++ b/llvm/lib/Support/FormattedStream.cpp
@@ -94,6 +94,9 @@ void formatted_raw_ostream::UpdatePosition(const char *Ptr, 
size_t Size) {
 /// ComputePosition - Examine the current output and update line and column
 /// counts.
 void formatted_raw_ostream::ComputePosition(const char *Ptr, size_t Size) {
+  if (DisableScan)
+return;
+
   // If our previous scan pointer is inside the buffer, assume we already
   // scanned those bytes. This depends on raw_ostream to not change our buffer
   // in unexpected ways.
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index cf6aaa1f06981f..2754d49645595d 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -547,11 +547,6 @@ int main(int argc, char **argv) {
 std::unique_ptr MAB(
 TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
 auto FOut = std::make_unique(*OS);
-// FIXME: Workaround for bug in formatted_raw_ostream. Color escape codes
-// are (incorrectly) written directly to the unbuffered raw_ostream wrapped
-// by the formatted_raw_ostream.
-if (Action == AC_CDisassemble)
-  FOut->SetUnbuffered();
 Str.reset(
 TheTarget->createAsmStreamer(Ctx, std::move(FOut), /*asmverbose*/ true,
  /*useDwarfDirectory*/ true, IP,
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp 
b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 22b427f57658e1..7ecdd60313d065 100644
--- a/llvm/tools/llvm-o

[llvm-branch-commits] [clang] release/18.x: backport PR84230 (PR #86106)

2024-03-28 Thread Aaron Ballman via llvm-branch-commits

AaronBallman wrote:

> Hi @antoniofrighetto (or anyone else). If you would like to add a note about 
> this fix in the release notes (completely optional). Please reply to this 
> comment with a one or two sentence description of the fix.

How about we go with something along the lines of:

Fixed a Clang 18.x regression which increased binary size and stack usage with 
`-ftrivial-auto-var-init`. Fixes #GH84178.

https://github.com/llvm/llvm-project/pull/86106
___
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] 0f8a379 - Revert "[compiler-rt] Allow building builtins.a without a libc (#86737)"

2024-03-28 Thread via llvm-branch-commits

Author: Leandro Lupori
Date: 2024-03-28T09:54:27-03:00
New Revision: 0f8a3797da1b35c3a5029d4b1ed2e1cb41909f82

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

LOG: Revert "[compiler-rt] Allow building builtins.a without a libc (#86737)"

This reverts commit 86692258637549ed9f863c3d2ba47b49f61bbc1f.

Added: 


Modified: 
compiler-rt/cmake/config-ix.cmake

Removed: 




diff  --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index 911f48fa13816c..46a6fdf8728ff8 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -235,9 +235,9 @@ set(COMPILER_RT_SUPPORTED_ARCH)
 # Try to compile a very simple source file to ensure we can target the given
 # platform. We use the results of these tests to build only the various target
 # runtime libraries supported by our current compilers cross-compiling
-# abilities. Avoids using libc as that may not be available yet.
+# abilities.
 set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
-file(WRITE ${SIMPLE_SOURCE} "int main(void) { return 0; }\n")
+file(WRITE ${SIMPLE_SOURCE} "#include \n#include \nint 
main(void) { printf(\"hello, world\"); }\n")
 
 # Detect whether the current target platform is 32-bit or 64-bit, and setup
 # the correct commandline flags needed to attempt to target 32-bit and 64-bit.



___
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] [mlir] release/18.x: [ODS][NFC] Cast range.size() to int32_t in accumulation (#85629) (PR #86677)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@andrey-golubev OK, no problem. I don't expect a release note entry for every 
change.

https://github.com/llvm/llvm-project/pull/86677
___
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][Lower] Split MLIR codegen for clauses and constructs (PR #86963)

2024-03-28 Thread via llvm-branch-commits

llvmbot wrote:




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

Author: Sergio Afonso (skatrak)


Changes

This patch performs several cleanups with the main purpose of normalizing the 
code patterns used to trigger codegen for MLIR OpenMP operations and making the 
processing of clauses and constructs independent. The following changes are 
made:

- Clean up unused `directive` argument to `ClauseProcessor::processMap()`.
- Move general helper functions in OpenMP.cpp to the appropriate section of the 
file.
- Create `genClauses()` functions containing the clause 
processing code specific for the associated OpenMP construct.
- Update `genOp()` functions to call the corresponding 
`genClauses()` function.
- Sort calls to `ClauseProcessor::process()` alphabetically, 
to avoid inadvertently relying on some arbitrary order. Update some tests that 
broke due to the order change.
- Normalize `genOMP()` functions so they all delegate the generation of MLIR to 
`genOp()` functions following the same pattern.
- Only process `nowait` clause on `TARGET` constructs if not compiling for the 
target device.

A later patch can move the calls to `genClauses()` out of 
`genOp()` functions and passing completed clause structures 
instead, in preparation to supporting composite constructs. That will make it 
possible to reuse clause processing for a given leaf construct when appearing 
alone or in a combined or composite construct, while controlling where the 
associated code is produced.

---

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


6 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+2-2) 
- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.h (+1-2) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+1166-924) 
- (modified) flang/test/Lower/OpenMP/FIR/target.f90 (+1-1) 
- (modified) flang/test/Lower/OpenMP/target.f90 (+1-1) 
- (modified) flang/test/Lower/OpenMP/use-device-ptr-to-use-device-addr.f90 
(+2-2) 


``diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index ee1f6c2fbc7e89..e2b26b3025049f 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -804,8 +804,8 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location 
loc,
 }
 
 bool ClauseProcessor::processMap(
-mlir::Location currentLocation, const llvm::omp::Directive &directive,
-Fortran::lower::StatementContext &stmtCtx, mlir::omp::MapClauseOps &result,
+mlir::Location currentLocation, Fortran::lower::StatementContext &stmtCtx,
+mlir::omp::MapClauseOps &result,
 llvm::SmallVectorImpl *mapSyms,
 llvm::SmallVectorImpl *mapSymLocs,
 llvm::SmallVectorImpl *mapSymTypes) const {
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h 
b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index d933e0a913d2bc..9e59d754280ef4 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -102,8 +102,7 @@ class ClauseProcessor {
   // They may be used later on to create the block_arguments for some of the
   // target directives that require it.
   bool processMap(
-  mlir::Location currentLocation, const llvm::omp::Directive &directive,
-  Fortran::lower::StatementContext &stmtCtx,
+  mlir::Location currentLocation, Fortran::lower::StatementContext 
&stmtCtx,
   mlir::omp::MapClauseOps &result,
   llvm::SmallVectorImpl *mapSyms =
   nullptr,
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index d67060d1cce72b..b6de2079a973f5 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -237,6 +237,276 @@ 
createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   return storeOp;
 }
 
+// This helper function implements the functionality of "promoting"
+// non-CPTR arguments of use_device_ptr to use_device_addr
+// arguments (automagic conversion of use_device_ptr ->
+// use_device_addr in these cases). The way we do so currently is
+// through the shuffling of operands from the devicePtrOperands to
+// deviceAddrOperands where neccesary and re-organizing the types,
+// locations and symbols to maintain the correct ordering of ptr/addr
+// input -> BlockArg.
+//
+// This effectively implements some deprecated OpenMP functionality
+// that some legacy applications unfortunately depend on
+// (deprecated in specification version 5.2):
+//
+// "If a list item in a use_device_ptr clause is not of type C_PTR,
+//  the behavior is as if the list item appeared in a use_device_addr
+//  clause. Support for such list items in a use_device_ptr clause
+//  is deprecated."
+static void promoteNonCPtrUseDevicePtrArgsToUseDeviceAddr(
+mlir::omp::UseDeviceClauseOps &clauseOps,
+llvm::SmallVectorImpl &useDeviceTypes,
+llvm::SmallVectorImpl

[llvm-branch-commits] [flang] [Flang][OpenMP][Lower] Use clause operand structures (PR #86802)

2024-03-28 Thread Sergio Afonso via llvm-branch-commits

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

>From 7af7e9d13fc2134e76bb532bfa4313aa3df17924 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 26 Mar 2024 16:46:56 +
Subject: [PATCH] [Flang][OpenMP][Lower] Use clause operand structures

This patch updates Flang lowering to use the new set of OpenMP clause operand
structures and their groupings into directive-specific sets of clause operands.

It simplifies the passing of information from the clause processor and the
creation of operations.

The `DataSharingProcessor` is slightly modified to not hold delayed
privatization state. Instead, optional arguments are added to `processStep1`
which are only passed when delayed privatization is used. This enables using
the clause operand structure for `private` and removes the need for the ad-hoc
`DelayedPrivatizationInfo` structure.

The processing of the `schedule` clause is updated to process the `chunk`
modifier rather than requiring two separate calls to the `ClauseProcessor`.

Lowering of a block-associated `ordered` construct is updated to emit a TODO
error if the `simd` clause is specified, since it is not currently supported by
the `ClauseProcessor` or later compilation stages.

Removed processing of `schedule` from `omp.simdloop`, as it doesn't apply to
`simd` constructs.
---
 flang/lib/Lower/OpenMP/ClauseProcessor.cpp| 261 +
 flang/lib/Lower/OpenMP/ClauseProcessor.h  | 105 ++--
 .../lib/Lower/OpenMP/DataSharingProcessor.cpp |  38 +-
 flang/lib/Lower/OpenMP/DataSharingProcessor.h |  45 +-
 flang/lib/Lower/OpenMP/OpenMP.cpp | 517 +++---
 5 files changed, 428 insertions(+), 538 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 0a57a1496289f4..ee1f6c2fbc7e89 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -162,14 +162,13 @@ getIfClauseOperand(Fortran::lower::AbstractConverter 
&converter,
 ifVal);
 }
 
-static void
-addUseDeviceClause(Fortran::lower::AbstractConverter &converter,
-   const omp::ObjectList &objects,
-   llvm::SmallVectorImpl &operands,
-   llvm::SmallVectorImpl &useDeviceTypes,
-   llvm::SmallVectorImpl &useDeviceLocs,
-   llvm::SmallVectorImpl
-   &useDeviceSymbols) {
+static void addUseDeviceClause(
+Fortran::lower::AbstractConverter &converter,
+const omp::ObjectList &objects,
+llvm::SmallVectorImpl &operands,
+llvm::SmallVectorImpl &useDeviceTypes,
+llvm::SmallVectorImpl &useDeviceLocs,
+llvm::SmallVectorImpl &useDeviceSyms) {
   genObjectList(objects, converter, operands);
   for (mlir::Value &operand : operands) {
 checkMapType(operand.getLoc(), operand.getType());
@@ -177,25 +176,24 @@ addUseDeviceClause(Fortran::lower::AbstractConverter 
&converter,
 useDeviceLocs.push_back(operand.getLoc());
   }
   for (const omp::Object &object : objects)
-useDeviceSymbols.push_back(object.id());
+useDeviceSyms.push_back(object.id());
 }
 
 static void convertLoopBounds(Fortran::lower::AbstractConverter &converter,
   mlir::Location loc,
-  llvm::SmallVectorImpl &lowerBound,
-  llvm::SmallVectorImpl &upperBound,
-  llvm::SmallVectorImpl &step,
+  mlir::omp::CollapseClauseOps &result,
   std::size_t loopVarTypeSize) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
   // The types of lower bound, upper bound, and step are converted into the
   // type of the loop variable if necessary.
   mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
-  for (unsigned it = 0; it < (unsigned)lowerBound.size(); it++) {
-lowerBound[it] =
-firOpBuilder.createConvert(loc, loopVarType, lowerBound[it]);
-upperBound[it] =
-firOpBuilder.createConvert(loc, loopVarType, upperBound[it]);
-step[it] = firOpBuilder.createConvert(loc, loopVarType, step[it]);
+  for (unsigned it = 0; it < (unsigned)result.loopLBVar.size(); it++) {
+result.loopLBVar[it] =
+firOpBuilder.createConvert(loc, loopVarType, result.loopLBVar[it]);
+result.loopUBVar[it] =
+firOpBuilder.createConvert(loc, loopVarType, result.loopUBVar[it]);
+result.loopStepVar[it] =
+firOpBuilder.createConvert(loc, loopVarType, result.loopStepVar[it]);
   }
 }
 
@@ -205,9 +203,7 @@ static void 
convertLoopBounds(Fortran::lower::AbstractConverter &converter,
 
 bool ClauseProcessor::processCollapse(
 mlir::Location currentLocation, Fortran::lower::pft::Evaluation &eval,
-llvm::SmallVectorImpl &lowerBound,
-llvm::SmallVectorImpl &upperBound,
-llvm::SmallVectorImpl &step,
+mlir::omp::CollapseClauseOps &r

[llvm-branch-commits] [mlir] [mlir][OpenMP] map argument to reduction initialization region (PR #86979)

2024-03-28 Thread Tom Eccles via llvm-branch-commits

https://github.com/tblah created https://github.com/llvm/llvm-project/pull/86979

The argument to the initialization region of reduction declarations was never 
mapped. This meant that if this argument was accessed inside the initialization 
region, that mlir operation would be translated to an llvm operation with a 
null argument (failing verification).

Adding the mapping ensures that the right LLVM value can be found when inlining 
and converting the initialization region.

We have to separately establish and clean up these mappings for each use of the 
reduction declaration because repeated usage of the same declaration will 
inline it using a different concrete value for the block argument.

>From aa5f843292a941dc976bd445d1dce4916cfb7438 Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Mon, 25 Mar 2024 16:36:02 +
Subject: [PATCH] [mlir][OpenMP] map argument to reduction initialization
 region

The argument to the initialization region of reduction declarations was
never mapped. This meant that if this argument was accessed inside the
initialization region, that mlir operation would be translated to an
llvm operation with a null argument (failing verification).

Adding the mapping ensures that the right LLVM value can be found when
inlining and converting the initialization region.

We have to separately establish and clean up these mappings for each use
of the reduction declaration because repeated usage of the same
declaration will inline it using a different concrete value for the
block argument.
---
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  |  35 +
 .../LLVMIR/openmp-reduction-init-arg.mlir | 147 ++
 2 files changed, 182 insertions(+)
 create mode 100644 mlir/test/Target/LLVMIR/openmp-reduction-init-arg.mlir

diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index cacf2c37e38d1c..c4bf6a20ebe71c 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -825,6 +825,25 @@ static void allocByValReductionVars(
   }
 }
 
+/// Map input argument to all reduction initialization regions
+template 
+static void
+mapInitializationArg(T loop, LLVM::ModuleTranslation &moduleTranslation,
+ SmallVectorImpl &reductionDecls,
+ unsigned i) {
+  // map input argument to the initialization region
+  mlir::omp::DeclareReductionOp &reduction = reductionDecls[i];
+  Region &initializerRegion = reduction.getInitializerRegion();
+  Block &entry = initializerRegion.front();
+  assert(entry.getNumArguments() == 1 &&
+ "the initialization region has one argument");
+
+  mlir::Value mlirSource = loop.getReductionVars()[i];
+  llvm::Value *llvmSource = moduleTranslation.lookupValue(mlirSource);
+  assert(llvmSource && "lookup reduction var");
+  moduleTranslation.mapValue(entry.getArgument(0), llvmSource);
+}
+
 /// Collect reduction info
 template 
 static void collectReductionInfo(
@@ -902,6 +921,10 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase 
&builder,
   loop.getRegion().getArguments().take_back(loop.getNumReductionVars());
   for (unsigned i = 0; i < loop.getNumReductionVars(); ++i) {
 SmallVector phis;
+
+// map block argument to initializer region
+mapInitializationArg(loop, moduleTranslation, reductionDecls, i);
+
 if 
(failed(inlineConvertOmpRegions(reductionDecls[i].getInitializerRegion(),
"omp.reduction.neutral", builder,
moduleTranslation, &phis)))
@@ -925,6 +948,11 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase 
&builder,
   builder.CreateStore(phis[0], privateReductionVariables[i]);
   // the rest was handled in allocByValReductionVars
 }
+
+// forget the mapping for the initializer region because we might need a
+// different mapping if this reduction declaration is re-used for a
+// different variable
+moduleTranslation.forgetMapping(reductionDecls[i].getInitializerRegion());
   }
 
   // Store the mapping between reduction variables and their private copies on
@@ -1118,6 +1146,9 @@ convertOmpParallel(omp::ParallelOp opInst, 
llvm::IRBuilderBase &builder,
 opInst.getNumReductionVars());
 for (unsigned i = 0; i < opInst.getNumReductionVars(); ++i) {
   SmallVector phis;
+
+  // map the block argument
+  mapInitializationArg(opInst, moduleTranslation, reductionDecls, i);
   if (failed(inlineConvertOmpRegions(
   reductionDecls[i].getInitializerRegion(), 
"omp.reduction.neutral",
   builder, moduleTranslation, &phis)))
@@ -1144,6 +1175,10 @@ convertOmpParallel(omp::ParallelOp opInst, 
llvm::IRBuilderBase &builder,
 builder.CreateStore(phis[0], privateReductionVariables[i]);
 // the rest is done in allocByValReduc

[llvm-branch-commits] [mlir] [mlir][OpenMP] map argument to reduction initialization region (PR #86979)

2024-03-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Tom Eccles (tblah)


Changes

The argument to the initialization region of reduction declarations was never 
mapped. This meant that if this argument was accessed inside the initialization 
region, that mlir operation would be translated to an llvm operation with a 
null argument (failing verification).

Adding the mapping ensures that the right LLVM value can be found when inlining 
and converting the initialization region.

We have to separately establish and clean up these mappings for each use of the 
reduction declaration because repeated usage of the same declaration will 
inline it using a different concrete value for the block argument.

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


2 Files Affected:

- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+35) 
- (added) mlir/test/Target/LLVMIR/openmp-reduction-init-arg.mlir (+147) 


``diff
diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index cacf2c37e38d1c..c4bf6a20ebe71c 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -825,6 +825,25 @@ static void allocByValReductionVars(
   }
 }
 
+/// Map input argument to all reduction initialization regions
+template 
+static void
+mapInitializationArg(T loop, LLVM::ModuleTranslation &moduleTranslation,
+ SmallVectorImpl &reductionDecls,
+ unsigned i) {
+  // map input argument to the initialization region
+  mlir::omp::DeclareReductionOp &reduction = reductionDecls[i];
+  Region &initializerRegion = reduction.getInitializerRegion();
+  Block &entry = initializerRegion.front();
+  assert(entry.getNumArguments() == 1 &&
+ "the initialization region has one argument");
+
+  mlir::Value mlirSource = loop.getReductionVars()[i];
+  llvm::Value *llvmSource = moduleTranslation.lookupValue(mlirSource);
+  assert(llvmSource && "lookup reduction var");
+  moduleTranslation.mapValue(entry.getArgument(0), llvmSource);
+}
+
 /// Collect reduction info
 template 
 static void collectReductionInfo(
@@ -902,6 +921,10 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase 
&builder,
   loop.getRegion().getArguments().take_back(loop.getNumReductionVars());
   for (unsigned i = 0; i < loop.getNumReductionVars(); ++i) {
 SmallVector phis;
+
+// map block argument to initializer region
+mapInitializationArg(loop, moduleTranslation, reductionDecls, i);
+
 if 
(failed(inlineConvertOmpRegions(reductionDecls[i].getInitializerRegion(),
"omp.reduction.neutral", builder,
moduleTranslation, &phis)))
@@ -925,6 +948,11 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase 
&builder,
   builder.CreateStore(phis[0], privateReductionVariables[i]);
   // the rest was handled in allocByValReductionVars
 }
+
+// forget the mapping for the initializer region because we might need a
+// different mapping if this reduction declaration is re-used for a
+// different variable
+moduleTranslation.forgetMapping(reductionDecls[i].getInitializerRegion());
   }
 
   // Store the mapping between reduction variables and their private copies on
@@ -1118,6 +1146,9 @@ convertOmpParallel(omp::ParallelOp opInst, 
llvm::IRBuilderBase &builder,
 opInst.getNumReductionVars());
 for (unsigned i = 0; i < opInst.getNumReductionVars(); ++i) {
   SmallVector phis;
+
+  // map the block argument
+  mapInitializationArg(opInst, moduleTranslation, reductionDecls, i);
   if (failed(inlineConvertOmpRegions(
   reductionDecls[i].getInitializerRegion(), 
"omp.reduction.neutral",
   builder, moduleTranslation, &phis)))
@@ -1144,6 +1175,10 @@ convertOmpParallel(omp::ParallelOp opInst, 
llvm::IRBuilderBase &builder,
 builder.CreateStore(phis[0], privateReductionVariables[i]);
 // the rest is done in allocByValReductionVars
   }
+
+  // clear block argument mapping in case it needs to be re-created with a
+  // different source for another use of the same reduction decl
+  
moduleTranslation.forgetMapping(reductionDecls[i].getInitializerRegion());
 }
 
 // Store the mapping between reduction variables and their private copies 
on
diff --git a/mlir/test/Target/LLVMIR/openmp-reduction-init-arg.mlir 
b/mlir/test/Target/LLVMIR/openmp-reduction-init-arg.mlir
new file mode 100644
index 00..b3cbb8aeebef6a
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/openmp-reduction-init-arg.mlir
@@ -0,0 +1,147 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// Test that the block argument to the initialization region of
+// omp.declare_reduction gets mapped properly when trans

[llvm-branch-commits] [mlir] [mlir][OpenMP] map argument to reduction initialization region (PR #86979)

2024-03-28 Thread Tom Eccles via llvm-branch-commits

https://github.com/tblah edited https://github.com/llvm/llvm-project/pull/86979
___
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] [BOLT] Use BAT callbacks in YAMLProfileWriter::convert (PR #86219)

2024-03-28 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/86219


___
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] [BOLT] Use BAT callbacks in YAMLProfileWriter::convert (PR #86219)

2024-03-28 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/86219


___
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] [BOLT] Use BAT callbacks in YAMLProfileWriter::convert (PR #86219)

2024-03-28 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/86219
___
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] [BOLT] Use BAT callbacks in YAMLProfileWriter::convert (PR #86219)

2024-03-28 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/86219

>From 685d3f5fa6ae75d6c3e22873a52ea8347e170c1e Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 28 Mar 2024 10:16:15 -0700
Subject: [PATCH] Get rid of std::map::at

Created using spr 1.3.4
---
 bolt/lib/Profile/BoltAddressTranslation.cpp | 5 -
 bolt/lib/Profile/YAMLProfileWriter.cpp  | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp 
b/bolt/lib/Profile/BoltAddressTranslation.cpp
index 6d3f83efbe5f5a..7c54ba1971cbac 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -600,7 +600,10 @@ BoltAddressTranslation::getBFBranches(uint64_t 
OutputAddress) const {
 unsigned
 BoltAddressTranslation::getSecondaryEntryPointId(uint64_t Address,
  uint32_t Offset) const {
-  const std::vector &Offsets = SecondaryEntryPointsMap.at(Address);
+  auto FunctionIt = SecondaryEntryPointsMap.find(Address);
+  if (FunctionIt == SecondaryEntryPointsMap.end())
+return UINT_MAX;
+  const std::vector &Offsets = FunctionIt->second;
   auto OffsetIt = std::find(Offsets.begin(), Offsets.end(), Offset);
   if (OffsetIt == Offsets.end())
 return UINT_MAX;
diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp 
b/bolt/lib/Profile/YAMLProfileWriter.cpp
index 78fb1e8539d477..bacee136de3f87 100644
--- a/bolt/lib/Profile/YAMLProfileWriter.cpp
+++ b/bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -48,7 +48,8 @@ setCSIDestination(const BinaryContext &BC, 
yaml::bolt::CallSiteInfo &CSI,
 if (SymbolValue.getError())
   return Callee;
 if (uint32_t Offset = SymbolValue.get() - Callee->getAddress())
-  EntryID = (*GetBATSecondaryEntryPointId)(Callee->getAddress(), Offset);
+  EntryID =
+  (*GetBATSecondaryEntryPointId)(Callee->getAddress(), Offset) + 1;
   } else {
 BC.getFunctionForSymbol(Symbol, &EntryID);
   }

___
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: Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (#86020) (PR #86197)

2024-03-28 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> @mordante Is the test failure legitimate?

I've checked and the test failure is unrelated to this patch.

https://github.com/llvm/llvm-project/pull/86197
___
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] lower reductions of assumed shape arrays (PR #86982)

2024-03-28 Thread Tom Eccles via llvm-branch-commits

https://github.com/tblah created https://github.com/llvm/llvm-project/pull/86982

Patch 1: https://github.com/llvm/llvm-project/pull/86978
Patch 2: https://github.com/llvm/llvm-project/pull/86979

>From 9f68c844b6f4c4a52002cd9d90cd158b10e64bf2 Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Tue, 19 Mar 2024 15:41:59 +
Subject: [PATCH] [flang][OpenMP] lower reductions of assumed shape arrays

---
 flang/lib/Lower/OpenMP/ReductionProcessor.cpp | 25 +-
 .../wsloop-reduction-array-assumed-shape.f90  | 90 +++
 2 files changed, 112 insertions(+), 3 deletions(-)
 create mode 100644 
flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90

diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp 
b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
index 0d05ca5aee658b..afb1a6e7107641 100644
--- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
@@ -522,11 +522,16 @@ void ReductionProcessor::addDeclareReduction(
 if (reductionSymbols)
   reductionSymbols->push_back(symbol);
 mlir::Value symVal = converter.getSymbolAddress(*symbol);
-auto redType = mlir::cast(symVal.getType());
+mlir::Type eleType;
+auto refType = 
mlir::dyn_cast_or_null(symVal.getType());
+if (refType)
+  eleType = refType.getEleTy();
+else
+  eleType = symVal.getType();
 
 // all arrays must be boxed so that we have convenient access to all the
 // information needed to iterate over the array
-if (mlir::isa(redType.getEleTy())) {
+if (mlir::isa(eleType)) {
   hlfir::Entity entity{symVal};
   entity = genVariableBox(currentLocation, builder, entity);
   mlir::Value box = entity.getBase();
@@ -538,11 +543,25 @@ void ReductionProcessor::addDeclareReduction(
   builder.create(currentLocation, box, alloca);
 
   symVal = alloca;
-  redType = mlir::cast(symVal.getType());
+} else if (mlir::isa(symVal.getType())) {
+  // boxed arrays are passed as values not by reference. Unfortunately,
+  // we can't pass a box by value to omp.redution_declare, so turn it
+  // into a reference
+
+  auto alloca =
+  builder.create(currentLocation, symVal.getType());
+  builder.create(currentLocation, symVal, alloca);
+  symVal = alloca;
 } else if (auto declOp = symVal.getDefiningOp()) {
   symVal = declOp.getBase();
 }
 
+// this isn't the same as the by-val and by-ref passing later in the
+// pipeline. Both styles assume that the variable is a reference at
+// this point
+assert(mlir::isa(symVal.getType()) &&
+   "reduction input var is a reference");
+
 reductionVars.push_back(symVal);
   }
   const bool isByRef = doReductionByRef(reductionVars);
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90 
b/flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90
new file mode 100644
index 00..a1f339faea5cd5
--- /dev/null
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90
@@ -0,0 +1,90 @@
+! RUN: bbc -emit-hlfir -fopenmp -o - %s | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s | FileCheck %s
+
+program reduce_assumed_shape
+real(8), dimension(2) :: r
+r = 0
+call reduce(r)
+print *, r
+
+contains
+subroutine reduce(r)
+  implicit none
+  real(8),intent(inout) :: r(:)
+  integer :: i = 0
+
+  !$omp parallel do reduction(+:r)
+  do i=0,10
+r(1) = i
+r(2) = 1
+  enddo
+  !$omp end parallel do
+end subroutine
+end program
+
+! CHECK-LABEL:   omp.declare_reduction @add_reduction_byref_box_Uxf64 : 
!fir.ref>> init {
+! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref>>):
+! CHECK:   %[[VAL_1:.*]] = arith.constant 0.00e+00 : f64
+! CHECK:   %[[VAL_2:.*]] = fir.load %[[VAL_0]] : 
!fir.ref>>
+! CHECK:   %[[VAL_3:.*]] = arith.constant 0 : index
+! CHECK:   %[[VAL_4:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_3]] : 
(!fir.box>, index) -> (index, index, index)
+! CHECK:   %[[VAL_5:.*]] = fir.shape %[[VAL_4]]#1 : (index) -> 
!fir.shape<1>
+! CHECK:   %[[VAL_6:.*]] = fir.alloca !fir.array, %[[VAL_4]]#1 
{bindc_name = ".tmp"}
+! CHECK:   %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_5]]) 
{uniq_name = ".tmp"} : (!fir.ref>, !fir.shape<1>) -> 
(!fir.box>, !fir.ref>)
+! CHECK:   hlfir.assign %[[VAL_1]] to %[[VAL_7]]#0 : f64, 
!fir.box>
+! CHECK:   %[[VAL_8:.*]] = fir.alloca !fir.box>
+! CHECK:   fir.store %[[VAL_7]]#0 to %[[VAL_8]] : 
!fir.ref>>
+! CHECK:   omp.yield(%[[VAL_8]] : 
!fir.ref>>)
+
+! CHECK-LABEL:   } combiner {
+! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref>>, 
%[[VAL_1:.*]]: !fir.ref>>):
+! CHECK:   %[[VAL_2:.*]] = fir.load %[[VAL_0]] : 
!fir.ref>>
+! CHECK:   %[[VAL_3:.*]] = fir.load %[[VAL_1]] : 
!fir.ref>>
+! CHECK:   %[[VAL_4:.*]] = arith.constant 0 : index
+! CHECK:   %[[VAL_5:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_4]] : 
(!fir.box>

[llvm-branch-commits] [flang] [flang][OpenMP] lower reductions of assumed shape arrays (PR #86982)

2024-03-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Tom Eccles (tblah)


Changes

Patch 1: https://github.com/llvm/llvm-project/pull/86978
Patch 2: https://github.com/llvm/llvm-project/pull/86979

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


2 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ReductionProcessor.cpp (+22-3) 
- (added) flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90 
(+90) 


``diff
diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp 
b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
index 0d05ca5aee658b..afb1a6e7107641 100644
--- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
@@ -522,11 +522,16 @@ void ReductionProcessor::addDeclareReduction(
 if (reductionSymbols)
   reductionSymbols->push_back(symbol);
 mlir::Value symVal = converter.getSymbolAddress(*symbol);
-auto redType = mlir::cast(symVal.getType());
+mlir::Type eleType;
+auto refType = 
mlir::dyn_cast_or_null(symVal.getType());
+if (refType)
+  eleType = refType.getEleTy();
+else
+  eleType = symVal.getType();
 
 // all arrays must be boxed so that we have convenient access to all the
 // information needed to iterate over the array
-if (mlir::isa(redType.getEleTy())) {
+if (mlir::isa(eleType)) {
   hlfir::Entity entity{symVal};
   entity = genVariableBox(currentLocation, builder, entity);
   mlir::Value box = entity.getBase();
@@ -538,11 +543,25 @@ void ReductionProcessor::addDeclareReduction(
   builder.create(currentLocation, box, alloca);
 
   symVal = alloca;
-  redType = mlir::cast(symVal.getType());
+} else if (mlir::isa(symVal.getType())) {
+  // boxed arrays are passed as values not by reference. Unfortunately,
+  // we can't pass a box by value to omp.redution_declare, so turn it
+  // into a reference
+
+  auto alloca =
+  builder.create(currentLocation, symVal.getType());
+  builder.create(currentLocation, symVal, alloca);
+  symVal = alloca;
 } else if (auto declOp = symVal.getDefiningOp()) {
   symVal = declOp.getBase();
 }
 
+// this isn't the same as the by-val and by-ref passing later in the
+// pipeline. Both styles assume that the variable is a reference at
+// this point
+assert(mlir::isa(symVal.getType()) &&
+   "reduction input var is a reference");
+
 reductionVars.push_back(symVal);
   }
   const bool isByRef = doReductionByRef(reductionVars);
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90 
b/flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90
new file mode 100644
index 00..a1f339faea5cd5
--- /dev/null
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-array-assumed-shape.f90
@@ -0,0 +1,90 @@
+! RUN: bbc -emit-hlfir -fopenmp -o - %s | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s | FileCheck %s
+
+program reduce_assumed_shape
+real(8), dimension(2) :: r
+r = 0
+call reduce(r)
+print *, r
+
+contains
+subroutine reduce(r)
+  implicit none
+  real(8),intent(inout) :: r(:)
+  integer :: i = 0
+
+  !$omp parallel do reduction(+:r)
+  do i=0,10
+r(1) = i
+r(2) = 1
+  enddo
+  !$omp end parallel do
+end subroutine
+end program
+
+! CHECK-LABEL:   omp.declare_reduction @add_reduction_byref_box_Uxf64 : 
!fir.ref>> init {
+! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref>>):
+! CHECK:   %[[VAL_1:.*]] = arith.constant 0.00e+00 : f64
+! CHECK:   %[[VAL_2:.*]] = fir.load %[[VAL_0]] : 
!fir.ref>>
+! CHECK:   %[[VAL_3:.*]] = arith.constant 0 : index
+! CHECK:   %[[VAL_4:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_3]] : 
(!fir.box>, index) -> (index, index, index)
+! CHECK:   %[[VAL_5:.*]] = fir.shape %[[VAL_4]]#1 : (index) -> 
!fir.shape<1>
+! CHECK:   %[[VAL_6:.*]] = fir.alloca !fir.array, %[[VAL_4]]#1 
{bindc_name = ".tmp"}
+! CHECK:   %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_5]]) 
{uniq_name = ".tmp"} : (!fir.ref>, !fir.shape<1>) -> 
(!fir.box>, !fir.ref>)
+! CHECK:   hlfir.assign %[[VAL_1]] to %[[VAL_7]]#0 : f64, 
!fir.box>
+! CHECK:   %[[VAL_8:.*]] = fir.alloca !fir.box>
+! CHECK:   fir.store %[[VAL_7]]#0 to %[[VAL_8]] : 
!fir.ref>>
+! CHECK:   omp.yield(%[[VAL_8]] : 
!fir.ref>>)
+
+! CHECK-LABEL:   } combiner {
+! CHECK: ^bb0(%[[VAL_0:.*]]: !fir.ref>>, 
%[[VAL_1:.*]]: !fir.ref>>):
+! CHECK:   %[[VAL_2:.*]] = fir.load %[[VAL_0]] : 
!fir.ref>>
+! CHECK:   %[[VAL_3:.*]] = fir.load %[[VAL_1]] : 
!fir.ref>>
+! CHECK:   %[[VAL_4:.*]] = arith.constant 0 : index
+! CHECK:   %[[VAL_5:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_4]] : 
(!fir.box>, index) -> (index, index, index)
+! CHECK:   %[[VAL_6:.*]] = fir.shape_shift %[[VAL_5]]#0, %[[VAL_5]]#1 
: (index, index) -> !fir.shapeshift<1>
+! CHECK:   %[[VAL_7:.*]] = arith.constant 1 : in

[llvm-branch-commits] [llvm] [BOLT] Use BAT callbacks in YAMLProfileWriter::convert (PR #86219)

2024-03-28 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov converted_to_draft 
https://github.com/llvm/llvm-project/pull/86219
___
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: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread Jonas Devlieghere via llvm-branch-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/86940
___
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: Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (#86020) (PR #86197)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

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

>From 0cd4babe0342c994d28916ecbbb7cd2b91023b9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Thu, 21 Mar 2024 17:29:15 +0200
Subject: [PATCH] Reapply [libcxx] [modules] Fix relative paths with absolute
 LIBCXX_INSTALL_MODULES_DIR (#86020)

This reapplies 272d1b44efdedb68c194970a610f0ca1b7b769c5 (from #85756),
which was reverted in
407937036fa7640f61f225474b1ea6623a40dbdd.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by
quoting them, in d209d1340b99d4fbd325dffb5e13b757ab8264ea. That made the
calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that
weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by constructing a non-empty base directory variable
to use for calculating the relative path.

(cherry picked from commit 50801f1095d33e712c3a51fdeef82569bd09007f)
---
 libcxx/modules/CMakeLists.txt | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 0dea8cfca94ac3..d47d19a4755317 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -206,9 +206,20 @@ add_custom_target(generate-cxx-modules
 # Configure the modules manifest.
 # Use the relative path between the installation and the module in the json
 # file. This allows moving the entire installation to a different location.
+if("${CMAKE_INSTALL_PREFIX}" STREQUAL "")
+  set(BASE_DIRECTORY "/")
+else()
+  set(BASE_DIRECTORY ${CMAKE_INSTALL_PREFIX})
+endif()
+cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_LIBRARY_DIR
+  BASE_DIRECTORY ${BASE_DIRECTORY}
+  OUTPUT_VARIABLE ABS_LIBRARY_DIR)
+cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_MODULES_DIR
+  BASE_DIRECTORY ${BASE_DIRECTORY}
+  OUTPUT_VARIABLE ABS_MODULES_DIR)
 file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
-  ${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
-  ${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULES_DIR})
+  ${ABS_LIBRARY_DIR}
+  ${ABS_MODULES_DIR})
 configure_file(
   "modules.json.in"
   "${LIBCXX_LIBRARY_DIR}/libc++.modules.json"

___
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] 0cd4bab - Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (#86020)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

Author: Martin Storsjö
Date: 2024-03-28T14:18:41-07:00
New Revision: 0cd4babe0342c994d28916ecbbb7cd2b91023b9b

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

LOG: Reapply [libcxx] [modules] Fix relative paths with absolute 
LIBCXX_INSTALL_MODULES_DIR (#86020)

This reapplies 272d1b44efdedb68c194970a610f0ca1b7b769c5 (from #85756),
which was reverted in
407937036fa7640f61f225474b1ea6623a40dbdd.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by
quoting them, in d209d1340b99d4fbd325dffb5e13b757ab8264ea. That made the
calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that
weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by constructing a non-empty base directory variable
to use for calculating the relative path.

(cherry picked from commit 50801f1095d33e712c3a51fdeef82569bd09007f)

Added: 


Modified: 
libcxx/modules/CMakeLists.txt

Removed: 




diff  --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 0dea8cfca94ac3..d47d19a4755317 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -206,9 +206,20 @@ add_custom_target(generate-cxx-modules
 # Configure the modules manifest.
 # Use the relative path between the installation and the module in the json
 # file. This allows moving the entire installation to a 
diff erent location.
+if("${CMAKE_INSTALL_PREFIX}" STREQUAL "")
+  set(BASE_DIRECTORY "/")
+else()
+  set(BASE_DIRECTORY ${CMAKE_INSTALL_PREFIX})
+endif()
+cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_LIBRARY_DIR
+  BASE_DIRECTORY ${BASE_DIRECTORY}
+  OUTPUT_VARIABLE ABS_LIBRARY_DIR)
+cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_MODULES_DIR
+  BASE_DIRECTORY ${BASE_DIRECTORY}
+  OUTPUT_VARIABLE ABS_MODULES_DIR)
 file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
-  ${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
-  ${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULES_DIR})
+  ${ABS_LIBRARY_DIR}
+  ${ABS_MODULES_DIR})
 configure_file(
   "modules.json.in"
   "${LIBCXX_LIBRARY_DIR}/libc++.modules.json"



___
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: Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (#86020) (PR #86197)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/86197
___
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: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

Hi @nga888 (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.

https://github.com/llvm/llvm-project/pull/86940
___
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: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

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

>From a385a917da93a65ffabe1982f5b101db6d15a125 Mon Sep 17 00:00:00 2001
From: Andrew Ng 
Date: Thu, 28 Mar 2024 11:41:49 +
Subject: [PATCH] [Support] Fix color handling in formatted_raw_ostream
 (#86700)

The color methods in formatted_raw_ostream were forwarding directly to
the underlying stream without considering existing buffered output. This
would cause incorrect colored output for buffered uses of
formatted_raw_ostream.

Fix this issue by applying the color to the formatted_raw_ostream itself
and temporarily disabling scanning of any color related output so as not
to affect the position tracking.

This fix means that workarounds that forced formatted_raw_ostream
buffering to be disabled can be removed. In the case of llvm-objdump,
this can improve disassembly performance when redirecting to a file by
more than an order of magnitude on both Windows and Linux. This
improvement restores the disassembly performance when redirecting to a
file to a level similar to before color support was added.

(cherry picked from commit c9db031c48852af491747dab86ef6f19195eb20d)
---
 llvm/include/llvm/Support/FormattedStream.h | 51 ++---
 llvm/lib/Support/FormattedStream.cpp|  3 ++
 llvm/tools/llvm-mc/llvm-mc.cpp  |  5 --
 llvm/tools/llvm-objdump/llvm-objdump.cpp|  7 ---
 4 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/llvm/include/llvm/Support/FormattedStream.h 
b/llvm/include/llvm/Support/FormattedStream.h
index 5f937cfa798408..850a18dbb94121 100644
--- a/llvm/include/llvm/Support/FormattedStream.h
+++ b/llvm/include/llvm/Support/FormattedStream.h
@@ -52,6 +52,10 @@ class formatted_raw_ostream : public raw_ostream {
   /// have the rest of it.
   SmallString<4> PartialUTF8Char;
 
+  /// DisableScan - Temporarily disable scanning of output. Used to ignore 
color
+  /// codes.
+  bool DisableScan;
+
   void write_impl(const char *Ptr, size_t Size) override;
 
   /// current_pos - Return the current position within the stream,
@@ -89,9 +93,33 @@ class formatted_raw_ostream : public raw_ostream {
   SetUnbuffered();
 TheStream->SetUnbuffered();
 
+enable_colors(TheStream->colors_enabled());
+
 Scanned = nullptr;
   }
 
+  void PreDisableScan() {
+assert(!DisableScan);
+ComputePosition(getBufferStart(), GetNumBytesInBuffer());
+assert(PartialUTF8Char.empty());
+DisableScan = true;
+  }
+
+  void PostDisableScan() {
+assert(DisableScan);
+DisableScan = false;
+Scanned = getBufferStart() + GetNumBytesInBuffer();
+  }
+
+  struct DisableScanScope {
+formatted_raw_ostream *S;
+
+DisableScanScope(formatted_raw_ostream *FRO) : S(FRO) {
+  S->PreDisableScan();
+}
+~DisableScanScope() { S->PostDisableScan(); }
+  };
+
 public:
   /// formatted_raw_ostream - Open the specified file for
   /// writing. If an error occurs, information about the error is
@@ -104,12 +132,12 @@ class formatted_raw_ostream : public raw_ostream {
   /// underneath it.
   ///
   formatted_raw_ostream(raw_ostream &Stream)
-  : TheStream(nullptr), Position(0, 0) {
+  : TheStream(nullptr), Position(0, 0), DisableScan(false) {
 setStream(Stream);
   }
-  explicit formatted_raw_ostream() : TheStream(nullptr), Position(0, 0) {
-Scanned = nullptr;
-  }
+  explicit formatted_raw_ostream()
+  : TheStream(nullptr), Position(0, 0), Scanned(nullptr),
+DisableScan(false) {}
 
   ~formatted_raw_ostream() override {
 flush();
@@ -136,17 +164,26 @@ class formatted_raw_ostream : public raw_ostream {
   }
 
   raw_ostream &resetColor() override {
-TheStream->resetColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::resetColor();
+}
 return *this;
   }
 
   raw_ostream &reverseColor() override {
-TheStream->reverseColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::reverseColor();
+}
 return *this;
   }
 
   raw_ostream &changeColor(enum Colors Color, bool Bold, bool BG) override {
-TheStream->changeColor(Color, Bold, BG);
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::changeColor(Color, Bold, BG);
+}
 return *this;
   }
 
diff --git a/llvm/lib/Support/FormattedStream.cpp 
b/llvm/lib/Support/FormattedStream.cpp
index c0d28435099570..c50530e76efc0a 100644
--- a/llvm/lib/Support/FormattedStream.cpp
+++ b/llvm/lib/Support/FormattedStream.cpp
@@ -94,6 +94,9 @@ void formatted_raw_ostream::UpdatePosition(const char *Ptr, 
size_t Size) {
 /// ComputePosition - Examine the current output and update line and column
 /// counts.
 void formatted_raw_ostream::ComputePosition(const char *Ptr, size_t Size) {
+  if (DisableScan)
+return;
+
   // If our previous scan pointer is inside the buffer, assume we already
   // scanned those bytes. This depends on raw_ostream to not change our buffer
   // in 

[llvm-branch-commits] [llvm] a385a91 - [Support] Fix color handling in formatted_raw_ostream (#86700)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

Author: Andrew Ng
Date: 2024-03-28T14:23:36-07:00
New Revision: a385a917da93a65ffabe1982f5b101db6d15a125

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

LOG: [Support] Fix color handling in formatted_raw_ostream (#86700)

The color methods in formatted_raw_ostream were forwarding directly to
the underlying stream without considering existing buffered output. This
would cause incorrect colored output for buffered uses of
formatted_raw_ostream.

Fix this issue by applying the color to the formatted_raw_ostream itself
and temporarily disabling scanning of any color related output so as not
to affect the position tracking.

This fix means that workarounds that forced formatted_raw_ostream
buffering to be disabled can be removed. In the case of llvm-objdump,
this can improve disassembly performance when redirecting to a file by
more than an order of magnitude on both Windows and Linux. This
improvement restores the disassembly performance when redirecting to a
file to a level similar to before color support was added.

(cherry picked from commit c9db031c48852af491747dab86ef6f19195eb20d)

Added: 


Modified: 
llvm/include/llvm/Support/FormattedStream.h
llvm/lib/Support/FormattedStream.cpp
llvm/tools/llvm-mc/llvm-mc.cpp
llvm/tools/llvm-objdump/llvm-objdump.cpp

Removed: 




diff  --git a/llvm/include/llvm/Support/FormattedStream.h 
b/llvm/include/llvm/Support/FormattedStream.h
index 5f937cfa798408..850a18dbb94121 100644
--- a/llvm/include/llvm/Support/FormattedStream.h
+++ b/llvm/include/llvm/Support/FormattedStream.h
@@ -52,6 +52,10 @@ class formatted_raw_ostream : public raw_ostream {
   /// have the rest of it.
   SmallString<4> PartialUTF8Char;
 
+  /// DisableScan - Temporarily disable scanning of output. Used to ignore 
color
+  /// codes.
+  bool DisableScan;
+
   void write_impl(const char *Ptr, size_t Size) override;
 
   /// current_pos - Return the current position within the stream,
@@ -89,9 +93,33 @@ class formatted_raw_ostream : public raw_ostream {
   SetUnbuffered();
 TheStream->SetUnbuffered();
 
+enable_colors(TheStream->colors_enabled());
+
 Scanned = nullptr;
   }
 
+  void PreDisableScan() {
+assert(!DisableScan);
+ComputePosition(getBufferStart(), GetNumBytesInBuffer());
+assert(PartialUTF8Char.empty());
+DisableScan = true;
+  }
+
+  void PostDisableScan() {
+assert(DisableScan);
+DisableScan = false;
+Scanned = getBufferStart() + GetNumBytesInBuffer();
+  }
+
+  struct DisableScanScope {
+formatted_raw_ostream *S;
+
+DisableScanScope(formatted_raw_ostream *FRO) : S(FRO) {
+  S->PreDisableScan();
+}
+~DisableScanScope() { S->PostDisableScan(); }
+  };
+
 public:
   /// formatted_raw_ostream - Open the specified file for
   /// writing. If an error occurs, information about the error is
@@ -104,12 +132,12 @@ class formatted_raw_ostream : public raw_ostream {
   /// underneath it.
   ///
   formatted_raw_ostream(raw_ostream &Stream)
-  : TheStream(nullptr), Position(0, 0) {
+  : TheStream(nullptr), Position(0, 0), DisableScan(false) {
 setStream(Stream);
   }
-  explicit formatted_raw_ostream() : TheStream(nullptr), Position(0, 0) {
-Scanned = nullptr;
-  }
+  explicit formatted_raw_ostream()
+  : TheStream(nullptr), Position(0, 0), Scanned(nullptr),
+DisableScan(false) {}
 
   ~formatted_raw_ostream() override {
 flush();
@@ -136,17 +164,26 @@ class formatted_raw_ostream : public raw_ostream {
   }
 
   raw_ostream &resetColor() override {
-TheStream->resetColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::resetColor();
+}
 return *this;
   }
 
   raw_ostream &reverseColor() override {
-TheStream->reverseColor();
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::reverseColor();
+}
 return *this;
   }
 
   raw_ostream &changeColor(enum Colors Color, bool Bold, bool BG) override {
-TheStream->changeColor(Color, Bold, BG);
+if (colors_enabled()) {
+  DisableScanScope S(this);
+  raw_ostream::changeColor(Color, Bold, BG);
+}
 return *this;
   }
 

diff  --git a/llvm/lib/Support/FormattedStream.cpp 
b/llvm/lib/Support/FormattedStream.cpp
index c0d28435099570..c50530e76efc0a 100644
--- a/llvm/lib/Support/FormattedStream.cpp
+++ b/llvm/lib/Support/FormattedStream.cpp
@@ -94,6 +94,9 @@ void formatted_raw_ostream::UpdatePosition(const char *Ptr, 
size_t Size) {
 /// ComputePosition - Examine the current output and update line and column
 /// counts.
 void formatted_raw_ostream::ComputePosition(const char *Ptr, size_t Size) {
+  if (DisableScan)
+return;
+
   // If our previous scan pointer is inside the buffer, assume we already
   // scanne

[llvm-branch-commits] [llvm] release/18.x: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)

2024-03-28 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/86940
___
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] [mlir] release/18.x: [MLIR] [Transforms] Let `transform.structured.convert_to_loops` return handles to loops (#83984) (PR #85942)

2024-03-28 Thread via llvm-branch-commits

MaheshRavishankar wrote:

> Pinging @MaheshRavishankar as I don't have permission to add reviewers and 
> it's been a week. I'm relatively new to contributing, so if I am doing 
> something wrong or have to do something else, I'd appreciate a pointer. :)

Sorry for the delay. I dont know very much about transform dialect. Adding 
folks who might know better.

https://github.com/llvm/llvm-project/pull/85942
___
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] [BOLT] Use BAT callbacks in YAMLProfileWriter::convert (PR #86219)

2024-03-28 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/86219

>From 685d3f5fa6ae75d6c3e22873a52ea8347e170c1e Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 28 Mar 2024 10:16:15 -0700
Subject: [PATCH 1/2] Get rid of std::map::at

Created using spr 1.3.4
---
 bolt/lib/Profile/BoltAddressTranslation.cpp | 5 -
 bolt/lib/Profile/YAMLProfileWriter.cpp  | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp 
b/bolt/lib/Profile/BoltAddressTranslation.cpp
index 6d3f83efbe5f5a..7c54ba1971cbac 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -600,7 +600,10 @@ BoltAddressTranslation::getBFBranches(uint64_t 
OutputAddress) const {
 unsigned
 BoltAddressTranslation::getSecondaryEntryPointId(uint64_t Address,
  uint32_t Offset) const {
-  const std::vector &Offsets = SecondaryEntryPointsMap.at(Address);
+  auto FunctionIt = SecondaryEntryPointsMap.find(Address);
+  if (FunctionIt == SecondaryEntryPointsMap.end())
+return UINT_MAX;
+  const std::vector &Offsets = FunctionIt->second;
   auto OffsetIt = std::find(Offsets.begin(), Offsets.end(), Offset);
   if (OffsetIt == Offsets.end())
 return UINT_MAX;
diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp 
b/bolt/lib/Profile/YAMLProfileWriter.cpp
index 78fb1e8539d477..bacee136de3f87 100644
--- a/bolt/lib/Profile/YAMLProfileWriter.cpp
+++ b/bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -48,7 +48,8 @@ setCSIDestination(const BinaryContext &BC, 
yaml::bolt::CallSiteInfo &CSI,
 if (SymbolValue.getError())
   return Callee;
 if (uint32_t Offset = SymbolValue.get() - Callee->getAddress())
-  EntryID = (*GetBATSecondaryEntryPointId)(Callee->getAddress(), Offset);
+  EntryID =
+  (*GetBATSecondaryEntryPointId)(Callee->getAddress(), Offset) + 1;
   } else {
 BC.getFunctionForSymbol(Symbol, &EntryID);
   }

>From 03520283ff38a47bc44cfa395534837d8da66934 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 28 Mar 2024 22:37:24 -0700
Subject: [PATCH 2/2] Fixed setting of BAT secondary entry point, updated test

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/YAMLProfileWriter.h | 11 +--
 bolt/lib/Profile/DataAggregator.cpp   | 11 +--
 bolt/lib/Profile/YAMLProfileWriter.cpp| 71 ---
 .../X86/yaml-secondary-entry-discriminator.s  | 52 +-
 4 files changed, 97 insertions(+), 48 deletions(-)

diff --git a/bolt/include/bolt/Profile/YAMLProfileWriter.h 
b/bolt/include/bolt/Profile/YAMLProfileWriter.h
index 7db581652a5b73..0db2e3fd90f9f1 100644
--- a/bolt/include/bolt/Profile/YAMLProfileWriter.h
+++ b/bolt/include/bolt/Profile/YAMLProfileWriter.h
@@ -15,6 +15,7 @@
 
 namespace llvm {
 namespace bolt {
+class BoltAddressTranslation;
 class RewriteInstance;
 
 class YAMLProfileWriter {
@@ -31,17 +32,9 @@ class YAMLProfileWriter {
   /// Save execution profile for that instance.
   std::error_code writeProfile(const RewriteInstance &RI);
 
-  /// Callback to determine if a function is covered by BAT.
-  using IsBATCallbackTy = std::optional>;
-  /// Callback to get secondary entry point id for a given function and offset.
-  using GetBATSecondaryEntryPointIdCallbackTy =
-  std::optional>;
-
   static yaml::bolt::BinaryFunctionProfile
   convert(const BinaryFunction &BF, bool UseDFS,
-  IsBATCallbackTy IsBATFunction = std::nullopt,
-  GetBATSecondaryEntryPointIdCallbackTy GetBATSecondaryEntryPointId =
-  std::nullopt);
+  const BoltAddressTranslation *BAT = nullptr);
 };
 
 } // namespace bolt
diff --git a/bolt/lib/Profile/DataAggregator.cpp 
b/bolt/lib/Profile/DataAggregator.cpp
index 5b5ce5532ffdb9..71824e2cc0e97a 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -2324,13 +2324,6 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
   BP.Header.Flags = opts::BasicAggregation ? BinaryFunction::PF_SAMPLE
: BinaryFunction::PF_LBR;
 
-  auto IsBATFunction = [&](uint64_t Address) {
-return BAT->isBATFunction(Address);
-  };
-  auto GetSecondaryEntryPointId = [&](uint64_t Address, uint32_t Offset) {
-return BAT->getSecondaryEntryPointId(Address, Offset);
-  };
-
   if (!opts::BasicAggregation) {
 // Convert profile for functions not covered by BAT
 for (auto &BFI : BC.getBinaryFunctions()) {
@@ -2339,8 +2332,8 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 continue;
   if (BAT->isBATFunction(Function.getAddress()))
 continue;
-  BP.Functions.emplace_back(YAMLProfileWriter::convert(
-  Function, /*UseDFS=*/false, IsBATFunction, 
GetSecondaryEntryPointId));
+  BP.Functions.emplace_back(
+  YAMLProfileWriter::convert(Function, /*UseDFS=*/false, BAT));
 }
 
 for (const auto &KV : Names