[llvm-branch-commits] [llvm] [BOLT][BAT] Support multi-way split functions (PR #87123)

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


@@ -197,8 +197,10 @@ void BoltAddressTranslation::writeMaps(std::map ,
 ? SecondaryEntryPointsMap[Address].size()
 : 0;
 if (Cold) {
-  size_t HotIndex =
-  std::distance(ColdPartSource.begin(), ColdPartSource.find(Address));
+  // `Maps` is keyed by output addresses.

aaupov wrote:

I'm fine with removing that comment. It's explained in multiple places 
including BAT documentation.

https://github.com/llvm/llvm-project/pull/87123
___
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][BAT] Support multi-way split functions (PR #87123)

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

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

>From d575235e6d61ea73757ec313a26b8b2aedc2c13d Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Fri, 29 Mar 2024 20:14:11 -0700
Subject: [PATCH] Address comment

Created using spr 1.3.4
---
 bolt/lib/Profile/BoltAddressTranslation.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp 
b/bolt/lib/Profile/BoltAddressTranslation.cpp
index 2c00bf6291eb9c..279490170ed446 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -197,7 +197,6 @@ void BoltAddressTranslation::writeMaps(std::map ,
 ? SecondaryEntryPointsMap[Address].size()
 : 0;
 if (Cold) {
-  // `Maps` is keyed by output addresses.
   auto HotEntryIt = Maps.find(ColdPartSource[Address]);
   assert(HotEntryIt != Maps.end());
   size_t HotIndex = std::distance(Maps.begin(), HotEntryIt);

___
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 interfaces in YAMLProfileWriter::convert (PR #86219)

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

aaupov wrote:

> I don't think Test plan in summary is necessary.

`spr` tool complains if there's no test plan, and I tend to agree with it. But 
I'm neutral about removing that.

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] d0c1718 - Revert "Reland "[PassManager] Support MachineFunctionProperties (#83668)" (#8…"

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

Author: paperchalice
Date: 2024-03-30T10:19:10+08:00
New Revision: d0c1718dfbdcaf1ae7629feba3b59a09f550ff5f

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

LOG: Revert "Reland "[PassManager] Support MachineFunctionProperties (#83668)" 
(#8…"

This reverts commit 4f713295cd9b2709e98109d6ce0ef333940c.

Added: 


Modified: 
llvm/include/llvm/CodeGen/MachinePassManager.h
llvm/include/llvm/Passes/MachinePassRegistry.def
llvm/lib/Passes/PassBuilder.cpp

Removed: 
llvm/test/tools/llc/new-pm/machine-function-properties.mir



diff  --git a/llvm/include/llvm/CodeGen/MachinePassManager.h 
b/llvm/include/llvm/CodeGen/MachinePassManager.h
index 085a78f919172d..3faffe5c4cab29 100644
--- a/llvm/include/llvm/CodeGen/MachinePassManager.h
+++ b/llvm/include/llvm/CodeGen/MachinePassManager.h
@@ -16,6 +16,8 @@
 // their respective analysis managers such as ModuleAnalysisManager and
 // FunctionAnalysisManager.
 //
+// TODO: Add MachineFunctionProperties support.
+//
 
//===--===//
 
 #ifndef LLVM_CODEGEN_MACHINEPASSMANAGER_H
@@ -42,67 +44,23 @@ using MachineFunctionAnalysisManager = 
AnalysisManager;
 /// automatically mixes in \c PassInfoMixin.
 template 
 struct MachinePassInfoMixin : public PassInfoMixin {
-protected:
-  class PropertyChanger {
-MachineFunction 
-
-template 
-using has_get_required_properties_t =
-decltype(std::declval().getRequiredProperties());
-
-template 
-using has_get_set_properties_t =
-decltype(std::declval().getSetProperties());
-
-template 
-using has_get_cleared_properties_t =
-decltype(std::declval().getClearedProperties());
-
-  public:
-PropertyChanger(MachineFunction ) : MF(MF) {
-#ifndef NDEBUG
-  if constexpr (is_detected::value) {
-auto  = MF.getProperties();
-auto RequiredProperties = DerivedT::getRequiredProperties();
-if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
-  errs() << "MachineFunctionProperties required by " << 
DerivedT::name()
- << " pass are not met by function " << MF.getName() << ".\n"
- << "Required properties: ";
-  RequiredProperties.print(errs());
-  errs() << "\nCurrent properties: ";
-  MFProps.print(errs());
-  errs() << '\n';
-  report_fatal_error("MachineFunctionProperties check failed");
-}
-  }
-#endif
-}
-
-~PropertyChanger() {
-  if constexpr (is_detected::value)
-MF.getProperties().set(DerivedT::getSetProperties());
-  if constexpr (is_detected::value)
-MF.getProperties().reset(DerivedT::getClearedProperties());
-}
-  };
-
-public:
-  PreservedAnalyses runImpl(MachineFunction ,
-MachineFunctionAnalysisManager ) {
-PropertyChanger PC(MF);
-return static_cast(this)->run(MF, MFAM);
-  }
+  // TODO: Add MachineFunctionProperties support.
 };
 
 namespace detail {
+struct MachinePassConcept
+: PassConcept {
+  virtual MachineFunctionProperties getRequiredProperties() const = 0;
+  virtual MachineFunctionProperties getSetProperties() const = 0;
+  virtual MachineFunctionProperties getClearedProperties() const = 0;
+};
 
-template 
-struct MachinePassModel
-: PassModel {
-  explicit MachinePassModel(PassT &)
-  : PassModel(
-std::move(Pass)) {}
+template  struct MachinePassModel : MachinePassConcept {
+  explicit MachinePassModel(PassT &) : Pass(std::move(Pass)) {}
+  // We have to explicitly define all the special member functions because MSVC
+  // refuses to generate them.
+  MachinePassModel(const MachinePassModel ) : Pass(Arg.Pass) {}
+  MachinePassModel(MachinePassModel &) : Pass(std::move(Arg.Pass)) {}
 
   friend void swap(MachinePassModel , MachinePassModel ) {
 using std::swap;
@@ -117,8 +75,89 @@ struct MachinePassModel
   MachinePassModel =(const MachinePassModel &) = delete;
   PreservedAnalyses run(MachineFunction ,
 MachineFunctionAnalysisManager ) override {
-return this->Pass.runImpl(IR, AM);
+return Pass.run(IR, AM);
+  }
+
+  void printPipeline(
+  raw_ostream ,
+  function_ref MapClassName2PassName) override {
+Pass.printPipeline(OS, MapClassName2PassName);
+  }
+
+  StringRef name() const override { return PassT::name(); }
+
+  template 
+  using has_required_t = decltype(std::declval().isRequired());
+  template 
+  static std::enable_if_t::value, bool>
+  passIsRequiredImpl() {
+return T::isRequired();
   }
+  template 
+  static std::enable_if_t::value, bool>
+  passIsRequiredImpl() {
+return false;
+  }
+  bool isRequired() const override { return passIsRequiredImpl(); }
+
+  template 
+  using 

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

2024-03-29 Thread Alexander Yermolovich via llvm-branch-commits

ayermolo wrote:

I don't think Test plan in summary is necessary.

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][BAT] Support multi-way split functions (PR #87123)

2024-03-29 Thread Davide Italiano via llvm-branch-commits

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

LG with the question answered/addressed.

https://github.com/llvm/llvm-project/pull/87123
___
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][BAT] Support multi-way split functions (PR #87123)

2024-03-29 Thread Davide Italiano via llvm-branch-commits


@@ -197,8 +197,10 @@ void BoltAddressTranslation::writeMaps(std::map ,
 ? SecondaryEntryPointsMap[Address].size()
 : 0;
 if (Cold) {
-  size_t HotIndex =
-  std::distance(ColdPartSource.begin(), ColdPartSource.find(Address));
+  // `Maps` is keyed by output addresses.

dcci wrote:

This comment seems self-explanatory. Maybe remove it?

https://github.com/llvm/llvm-project/pull/87123
___
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] WIP MTE stack record (PR #86356)

2024-03-29 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/86356

>From a64c5d63a4df7f59845291ca0d634466713b1ff8 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 29 Mar 2024 16:53:52 -0700
Subject: [PATCH] update

Created using spr 1.3.4
---
 llvm/lib/Target/AArch64/AArch64StackTagging.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp 
b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
index a6e236386d5baa..6538abea832907 100644
--- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -489,7 +489,6 @@ Instruction *AArch64StackTagging::insertBaseTaggedPointer(
 
 auto *IntptrTy = IRB.getIntPtrTy(M.getDataLayout());
 Value *SlotPtr = memtag::getAndroidSlotPtr(IRB, StackMteSlot);
-SlotPtr->setName("TLS_SLOT_STACK_MTE");
 auto *ThreadLong = IRB.CreateLoad(IntptrTy, SlotPtr);
 Value *TaggedFP = IRB.CreateOr(
 memtag::getFP(IRB),

___
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] WIP MTE stack record (PR #86356)

2024-03-29 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/86356


___
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] WIP MTE stack record (PR #86356)

2024-03-29 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/86356


___
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] [lld] [llvm] [llvm][lld][RISCV] Support x3_reg_usage (PR #84598)

2024-03-29 Thread Paul Kirth via llvm-branch-commits

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

>From 7c9298eea6d8239f9afedc3d6aabb1ec0f71e273 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 11 Mar 2024 15:35:59 -0700
Subject: [PATCH 1/3] Update callsite parameter

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index b2e0ba17e4efe5..5eb2ce3d64513a 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1228,8 +1228,8 @@ mergeAttributesSection(const SmallVector ) {
   if (r.second) {
 firstX3RegUse = sec;
   } else {
-mergeX3RegUse(merged.intAttr, firstX3RegUse, sec,
-  r.first->getSecond(), *i);
+mergeX3RegUse(r.first, firstX3RegUse, sec, r.first->getSecond(),
+  *i);
   }
 }
 continue;

>From c39aca073491f06127eadd8c69cc15e23ea4bc2d Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 22 Mar 2024 12:44:27 -0700
Subject: [PATCH 2/3] Fix typos

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 09db69286c5e9a..173afce454f382 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1139,8 +1139,8 @@ static void mergeX3RegUse(DenseMap::iterator it,
   const InputSectionBase *oldSection,
   const InputSectionBase *newSection,
   unsigned int oldTag, unsigned int newTag) {
-  // X3/GP register usage ar incompatible and cannot be merged, with the
-  // exception of the UNKNOWN or 0 value
+  // X3/GP register usage are incompatible and cannot be merged, with the
+  // exception of the UNKNOWN or 0 value.
   using RISCVAttrs::RISCVX3RegUse::X3RegUsage;
   if (newTag == X3RegUsage::UNKNOWN)
 return;

>From 86bb4a866953c886e586f61da0ec74c9e1129cfa Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 29 Mar 2024 16:15:38 -0700
Subject: [PATCH 3/3] Fix windows test failure

Created using spr 1.3.4
---
 llvm/test/CodeGen/RISCV/attributes.ll | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index eecab162eb31c8..9bd730003f0e72 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -519,7 +519,6 @@
 ; X3SCS: .attribute 16, 2
 ; X3TMP: .attribute 16, 3
 ; X3ERR: LLVM ERROR: Cannot set multiple ABIs for X3/GP
-; X3ERR: error: Aborted
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1

___
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][BAT] Support multi-way split functions (PR #87123)

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

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/87123
___
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][BAT] Support multi-way split functions (PR #87123)

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

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/87123

BAT writeMaps encoded the assumption that functions are only split into
two fragments (hot and cold). However, BOLT supports splitting into
arbitrary number of fragments. Relax that assumption and look up primary
(hot) fragment explicitly.

Test Plan: Updated bolt/test/X86/yaml-secondary-entry-discriminator.s



___
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 interfaces in YAMLProfileWriter::convert (PR #86219)

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

https://github.com/aaupov ready_for_review 
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] [openmp] release/18x: [OpenMP][AIX] Affinity implementation for AIX (#84984) (PR #86695)

2024-03-29 Thread Shilei Tian via llvm-branch-commits

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

Since this feature is needed for the vendor release, we can make exception for 
this patch.

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


[llvm-branch-commits] [clang] release/18.x: Backport PR86914 "Fix a CTAD regression after 42239d2e9" (PR #87084)

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

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

Sounds sensible to me if the release manager is happy w/ it.

https://github.com/llvm/llvm-project/pull/87084
___
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] Move clause/object conversion to happen early, in genOMP (PR #87074)

2024-03-29 Thread Krzysztof Parzyszek via llvm-branch-commits

kparzysz wrote:

Replaced by https://github.com/llvm/llvm-project/pull/87086

https://github.com/llvm/llvm-project/pull/87074
___
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] Move clause/object conversion to happen early, in genOMP (PR #87086)

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

llvmbot wrote:




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

Author: Krzysztof Parzyszek (kparzysz)


Changes

This removes the last use of genOmpObectList2, which has now been removed.

---

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


5 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.h (+2-3) 
- (modified) flang/lib/Lower/OpenMP/DataSharingProcessor.h (+2-3) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+201-223) 
- (modified) flang/lib/Lower/OpenMP/Utils.cpp (+11-19) 
- (modified) flang/lib/Lower/OpenMP/Utils.h (+2-4) 


``diff
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 OpWithBodyGenInfo {
   /// [in] is this an outer operation - prevents privatization.
   bool outerCombined = false;
   /// 

[llvm-branch-commits] [flang] [flang][OpenMP] Move clause/object conversion to happen early, in genOMP (PR #87074)

2024-03-29 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz closed 
https://github.com/llvm/llvm-project/pull/87074
___
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] Move clause/object conversion to happen early, in genOMP (PR #87086)

2024-03-29 Thread Krzysztof Parzyszek via llvm-branch-commits

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

This removes the last use of genOmpObectList2, which has now been removed.

>From f725face892cef4faf9f17d4b549541bdbcd7e08 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Fri, 29 Mar 2024 09:20:41 -0500
Subject: [PATCH] [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 = 

[llvm-branch-commits] [clang] release/18.x: Backport PR86914 "Fix a CTAD regression after 42239d2e9" (PR #87084)

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

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

This fixes a regression that was introduced in 18, which we don't want to carry 
it over to 19 anyways.


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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+21-1) 
- (modified) clang/test/SemaTemplate/concepts-friends.cpp (+26) 
- (modified) clang/test/SemaTemplate/ctad.cpp (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d4401a43c123e7..ebeb47a871e27b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1106,6 +1106,10 @@ Bug Fixes to C++ Support
 - Fix a crash when an unresolved overload set is encountered on the RHS of a 
``.*`` operator.
   (`#53815 `_)
 
+- Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
+  incorrect constraint substitution.
+  (`#86769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index a381d876a54c67..b619f5d729e86b 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1830,7 +1830,27 @@ static TemplateParameterList 
*GetTemplateParameterList(TemplateDecl *TD) {
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
-  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+  Decl *D = TD->getMostRecentDecl();
+  // C++11 [temp.param]p12:
+  // A default template argument shall not be specified in a friend class
+  // template declaration.
+  //
+  // Skip past friend *declarations* because they are not supposed to contain
+  // default template arguments. Moreover, these declarations may introduce
+  // template parameters living in different template depths than the
+  // corresponding template parameters in TD, causing unmatched constraint
+  // substitution.
+  //
+  // FIXME: Diagnose such cases within a class template:
+  //  template 
+  //  struct S {
+  //template  friend struct C;
+  //  };
+  //  template struct S;
+  while (D->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None &&
+ D->getPreviousDecl())
+D = D->getPreviousDecl();
+  return cast(D)->getTemplateParameters();
 }
 
 DeclResult Sema::CheckClassTemplate(
diff --git a/clang/test/SemaTemplate/concepts-friends.cpp 
b/clang/test/SemaTemplate/concepts-friends.cpp
index 255b0858917fb6..0b008811f13621 100644
--- a/clang/test/SemaTemplate/concepts-friends.cpp
+++ b/clang/test/SemaTemplate/concepts-friends.cpp
@@ -478,3 +478,29 @@ template  class Foo {
 };
 
 } // namespace FriendOfFriend
+
+namespace GH86769 {
+
+template 
+concept X = true;
+
+template  struct Y {
+  Y(T) {}
+  template  friend struct Y;
+  template  friend struct Y;
+  template  friend struct Y;
+};
+
+template 
+struct Z {
+  // FIXME: This is ill-formed per C++11 [temp.param]p12:
+  // A default template argument shall not be specified in a friend class
+  // template declaration.
+  template  friend struct Y;
+};
+
+template struct Y;
+template struct Z;
+Y y(1);
+
+}
diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp
index 388ed7d4cced18..ec144d4f44ba8c 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -53,4 +53,4 @@ X x;
 template struct Y { Y(T); };
 template struct Y ;
 Y y(1);
-};
+}

``




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


[llvm-branch-commits] [clang] release/18.x: Backport PR86914 "Fix a CTAD regression after 42239d2e9" (PR #87084)

2024-03-29 Thread Younan Zhang via llvm-branch-commits

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


[llvm-branch-commits] [clang] release/18.x: Backport PR86914 "Fix a CTAD regression after 42239d2e9" (PR #87084)

2024-03-29 Thread Younan Zhang via llvm-branch-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/87084

This fixes a regression that was introduced in 18, which we don't want to carry 
it over to 19 anyways.


>From 997ea41a48a94e92ebe47ac5345428582b32d967 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 29 Mar 2024 23:28:54 +0800
Subject: [PATCH] [clang][Sema] Fix a CTAD regression after 42239d2e9 (#86914)

The most recent declaration of a template as a friend can introduce a
different template parameter depth compared to what we anticipate from a
CTAD guide.

Fixes https://github.com/llvm/llvm-project/issues/86769
---
 clang/docs/ReleaseNotes.rst  |  4 +++
 clang/lib/Sema/SemaTemplate.cpp  | 22 -
 clang/test/SemaTemplate/concepts-friends.cpp | 26 
 clang/test/SemaTemplate/ctad.cpp |  2 +-
 4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d4401a43c123e7..ebeb47a871e27b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1106,6 +1106,10 @@ Bug Fixes to C++ Support
 - Fix a crash when an unresolved overload set is encountered on the RHS of a 
``.*`` operator.
   (`#53815 `_)
 
+- Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
+  incorrect constraint substitution.
+  (`#86769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index a381d876a54c67..b619f5d729e86b 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1830,7 +1830,27 @@ static TemplateParameterList 
*GetTemplateParameterList(TemplateDecl *TD) {
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
-  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+  Decl *D = TD->getMostRecentDecl();
+  // C++11 [temp.param]p12:
+  // A default template argument shall not be specified in a friend class
+  // template declaration.
+  //
+  // Skip past friend *declarations* because they are not supposed to contain
+  // default template arguments. Moreover, these declarations may introduce
+  // template parameters living in different template depths than the
+  // corresponding template parameters in TD, causing unmatched constraint
+  // substitution.
+  //
+  // FIXME: Diagnose such cases within a class template:
+  //  template 
+  //  struct S {
+  //template  friend struct C;
+  //  };
+  //  template struct S;
+  while (D->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None &&
+ D->getPreviousDecl())
+D = D->getPreviousDecl();
+  return cast(D)->getTemplateParameters();
 }
 
 DeclResult Sema::CheckClassTemplate(
diff --git a/clang/test/SemaTemplate/concepts-friends.cpp 
b/clang/test/SemaTemplate/concepts-friends.cpp
index 255b0858917fb6..0b008811f13621 100644
--- a/clang/test/SemaTemplate/concepts-friends.cpp
+++ b/clang/test/SemaTemplate/concepts-friends.cpp
@@ -478,3 +478,29 @@ template  class Foo {
 };
 
 } // namespace FriendOfFriend
+
+namespace GH86769 {
+
+template 
+concept X = true;
+
+template  struct Y {
+  Y(T) {}
+  template  friend struct Y;
+  template  friend struct Y;
+  template  friend struct Y;
+};
+
+template 
+struct Z {
+  // FIXME: This is ill-formed per C++11 [temp.param]p12:
+  // A default template argument shall not be specified in a friend class
+  // template declaration.
+  template  friend struct Y;
+};
+
+template struct Y;
+template struct Z;
+Y y(1);
+
+}
diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp
index 388ed7d4cced18..ec144d4f44ba8c 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -53,4 +53,4 @@ X x;
 template struct Y { Y(T); };
 template struct Y ;
 Y y(1);
-};
+}

___
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][transform] replace original op to loop ops (#83537) (PR #87080)

2024-03-29 Thread Oleksandr Alex Zinenko via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/87080
___
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][transform] replace original op to loop ops (#83537) (PR #87080)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-linalg

Author: None (llvmbot)


Changes

Backport 0597644a6466ae9148b0b41cb8f95d5022e045c2

Requested by: @llvmbot

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


2 Files Affected:

- (modified) mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp (+1) 
- (modified) 
mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir (+1) 


``diff
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp 
b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 140bdd1f2db361..be875297fc93ca 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -2092,6 +2092,7 @@ DiagnosedSilenceableFailure 
transform::ConvertToLoopsOp::applyToOne(
   scf::lowerToLoopsUsingSCFForOp(rewriter, target);
   if (failed(loops))
 return emitDefaultDefiniteFailure(target);
+  rewriter.eraseOp(target);
   return DiagnosedSilenceableFailure::success();
 }
 
diff --git 
a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir 
b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
index 7969de0d456bb6..1b2c553b25ded0 100644
--- a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
+++ b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
@@ -33,6 +33,7 @@ module attributes {transform.with_named_sequence} {
 //   CHECK: %[[MULF:.+]] = arith.mulf %[[LHS]], %[[RHS]]
 //   CHECK: %[[ADDF:.+]] = arith.addf %[[OUT]], %[[MULF]]
 //   CHECK: memref.store %[[ADDF]], %[[ARG2]][%[[IV0]], %[[IV1]]]
+//   CHECK-NOT:   linalg.matmul ins(%arg0, %arg1 : memref, 
memref)
 
 // -
 

``




https://github.com/llvm/llvm-project/pull/87080
___
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][transform] replace original op to loop ops (#83537) (PR #87080)

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

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/87080

>From b277f588061183e88a985cb7037650d22d7aa478 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 5 Mar 2024 03:58:12 +0800
Subject: [PATCH] [mlir][transform] replace original op to loop ops (#83537)

(cherry picked from commit 0597644a6466ae9148b0b41cb8f95d5022e045c2)
---
 mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp  | 1 +
 .../TilingInterface/lower-to-loops-using-interface.mlir  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp 
b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 140bdd1f2db361..be875297fc93ca 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -2092,6 +2092,7 @@ DiagnosedSilenceableFailure 
transform::ConvertToLoopsOp::applyToOne(
   scf::lowerToLoopsUsingSCFForOp(rewriter, target);
   if (failed(loops))
 return emitDefaultDefiniteFailure(target);
+  rewriter.eraseOp(target);
   return DiagnosedSilenceableFailure::success();
 }
 
diff --git 
a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir 
b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
index 7969de0d456bb6..1b2c553b25ded0 100644
--- a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
+++ b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
@@ -33,6 +33,7 @@ module attributes {transform.with_named_sequence} {
 //   CHECK: %[[MULF:.+]] = arith.mulf %[[LHS]], %[[RHS]]
 //   CHECK: %[[ADDF:.+]] = arith.addf %[[OUT]], %[[MULF]]
 //   CHECK: memref.store %[[ADDF]], %[[ARG2]][%[[IV0]], %[[IV1]]]
+//   CHECK-NOT:   linalg.matmul ins(%arg0, %arg1 : memref, 
memref)
 
 // -
 

___
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][transform] replace original op to loop ops (#83537) (PR #87080)

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

llvmbot wrote:

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

https://github.com/llvm/llvm-project/pull/87080
___
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][transform] replace original op to loop ops (#83537) (PR #87080)

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

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

Backport 0597644a6466ae9148b0b41cb8f95d5022e045c2

Requested by: @llvmbot

>From 0c66659ae7dc87a850a266a0592cda7ef85e5a25 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 5 Mar 2024 03:58:12 +0800
Subject: [PATCH] [mlir][transform] replace original op to loop ops (#83537)

(cherry picked from commit 0597644a6466ae9148b0b41cb8f95d5022e045c2)
---
 mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp  | 1 +
 .../TilingInterface/lower-to-loops-using-interface.mlir  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp 
b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 140bdd1f2db361..be875297fc93ca 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -2092,6 +2092,7 @@ DiagnosedSilenceableFailure 
transform::ConvertToLoopsOp::applyToOne(
   scf::lowerToLoopsUsingSCFForOp(rewriter, target);
   if (failed(loops))
 return emitDefaultDefiniteFailure(target);
+  rewriter.eraseOp(target);
   return DiagnosedSilenceableFailure::success();
 }
 
diff --git 
a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir 
b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
index 7969de0d456bb6..1b2c553b25ded0 100644
--- a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
+++ b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
@@ -33,6 +33,7 @@ module attributes {transform.with_named_sequence} {
 //   CHECK: %[[MULF:.+]] = arith.mulf %[[LHS]], %[[RHS]]
 //   CHECK: %[[ADDF:.+]] = arith.addf %[[OUT]], %[[MULF]]
 //   CHECK: memref.store %[[ADDF]], %[[ARG2]][%[[IV0]], %[[IV1]]]
+//   CHECK-NOT:   linalg.matmul ins(%arg0, %arg1 : memref, 
memref)
 
 // -
 

___
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][transform] replace original op to loop ops (#83537) (PR #87080)

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

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/87080
___
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-29 Thread via llvm-branch-commits

lhunloh wrote:

We thought that might bring this transformation more in line with other 
transforms (which give handles to loops). Of course I could cherry-pick only 
the first commit, that would help us already. I'll do that, should this one get 
closed. :)

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] [flang] [Flang][OpenMP][Lower] Refactor lowering of compound constructs (PR #87070)

2024-03-29 Thread Krzysztof Parzyszek via llvm-branch-commits


@@ -710,6 +710,81 @@ genOpenMPReduction(Fortran::lower::AbstractConverter 
,
   }
 }
 
+/// Split a combined directive into an outer leaf directive and the (possibly
+/// combined) rest of the combined directive. Composite directives and
+/// non-compound directives are not split, in which case it will return the
+/// input directive as its first output and an empty value as its second 
output.
+static std::pair>

kparzysz wrote:

Posted: https://github.com/llvm/llvm-project/pull/87076

https://github.com/llvm/llvm-project/pull/87070
___
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] Refactor lowering of compound constructs (PR #87070)

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


@@ -710,6 +710,81 @@ genOpenMPReduction(Fortran::lower::AbstractConverter 
,
   }
 }
 
+/// Split a combined directive into an outer leaf directive and the (possibly
+/// combined) rest of the combined directive. Composite directives and
+/// non-compound directives are not split, in which case it will return the
+/// input directive as its first output and an empty value as its second 
output.
+static std::pair>

skatrak wrote:

> We have llvm::omp::getLeafConstructs that breaks up any combined/composite 
> directive into leafs.

That might be useful here, though if it splits up composite constructs too 
maybe it wouldn't be as straightforward to use in this case. Does it provide a 
relatively clean way to split something like `teams distribute simd` into 
`[teams, distribute simd]` rather than `[teams, distribute, simd]`?

https://github.com/llvm/llvm-project/pull/87070
___
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] Refactor lowering of compound constructs (PR #87070)

2024-03-29 Thread Krzysztof Parzyszek via llvm-branch-commits


@@ -710,6 +710,81 @@ genOpenMPReduction(Fortran::lower::AbstractConverter 
,
   }
 }
 
+/// Split a combined directive into an outer leaf directive and the (possibly
+/// combined) rest of the combined directive. Composite directives and
+/// non-compound directives are not split, in which case it will return the
+/// input directive as its first output and an empty value as its second 
output.
+static std::pair>

kparzysz wrote:

We have llvm::omp::getLeafConstructs that breaks up any combined/composite 
directive into leafs.

I have functions `is[Leaf|Combined|Composite]Construct` in a local commit, I 
can make a PR for it.

https://github.com/llvm/llvm-project/pull/87070
___
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-29 Thread Oleksandr Alex Zinenko via llvm-branch-commits

ftynse wrote:

https://github.com/llvm/llvm-project/commit/0597644a6466ae9148b0b41cb8f95d5022e045c2
 looks like a bugfix, but 
https://github.com/llvm/llvm-project/commit/47bc565ca7990a2de20af4030baf08ac62739aca
 is a arguably a new feature and likely should not be backported. What is the 
reason for backporting the latter? 

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 interfaces in YAMLProfileWriter::convert (PR #86219)

2024-03-29 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] [flang] [flang][OpenMP] Move clause/object conversion to happen early, in genOMP (PR #87074)

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

llvmbot wrote:




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

Author: Krzysztof Parzyszek (kparzysz)


Changes

This removes the last use of genOmpObectList2, which has now been removed.

---

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


5 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.h (+2-3) 
- (modified) flang/lib/Lower/OpenMP/DataSharingProcessor.h (+2-3) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+194-215) 
- (modified) flang/lib/Lower/OpenMP/Utils.cpp (+11-19) 
- (modified) flang/lib/Lower/OpenMP/Utils.h (+2-4) 


``diff
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 692d81f9188be3..77d6c8503f0c34 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()) {
@@ -737,7 +736,7 @@ struct OpWithBodyGenInfo {
 return *this;
   }
 
-  OpWithBodyGenInfo (const Fortran::parser::OmpClauseList *value) {
+  OpWithBodyGenInfo (const List *value) {
 clauses = value;
 return *this;
   }
@@ -773,7 +772,7 @@ struct OpWithBodyGenInfo {
   /// [in] is this an outer operation - prevents privatization.
   bool outerCombined = false;
   /// 

[llvm-branch-commits] [flang] [flang][OpenMP] Move clause/object conversion to happen early, in genOMP (PR #87074)

2024-03-29 Thread Krzysztof Parzyszek via llvm-branch-commits

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

This removes the last use of genOmpObectList2, which has now been removed.

>From 77d870f34c21f1265462adecbeac09f55707bb42 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Fri, 29 Mar 2024 09:20:41 -0500
Subject: [PATCH] [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 | 409 +-
 flang/lib/Lower/OpenMP/Utils.cpp  |  30 +-
 flang/lib/Lower/OpenMP/Utils.h|   6 +-
 5 files changed, 211 insertions(+), 244 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 692d81f9188be3..77d6c8503f0c34 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()) {
@@ -737,7 +736,7 @@ struct OpWithBodyGenInfo {
 return *this;
   }
 
-  OpWithBodyGenInfo (const Fortran::parser::OmpClauseList *value) {
+  OpWithBodyGenInfo (const List *value) {
 clauses = 

[llvm-branch-commits] [llvm] [RISCV] Use larger copies when register tuples are aligned (PR #84455)

2024-03-29 Thread Luke Lau via llvm-branch-commits


@@ -302,102 +302,98 @@ void RISCVInstrInfo::copyPhysRegVector(MachineBasicBlock 
,
RISCVII::VLMUL LMul, unsigned NF) const 
{
   const TargetRegisterInfo *TRI = STI.getRegisterInfo();
 
-  unsigned Opc;
-  unsigned SubRegIdx;
-  unsigned VVOpc, VIOpc;
-  switch (LMul) {
-  default:
-llvm_unreachable("Impossible LMUL for vector register copy.");
-  case RISCVII::LMUL_1:
-Opc = RISCV::VMV1R_V;
-SubRegIdx = RISCV::sub_vrm1_0;
-VVOpc = RISCV::PseudoVMV_V_V_M1;
-VIOpc = RISCV::PseudoVMV_V_I_M1;
-break;
-  case RISCVII::LMUL_2:
-Opc = RISCV::VMV2R_V;
-SubRegIdx = RISCV::sub_vrm2_0;
-VVOpc = RISCV::PseudoVMV_V_V_M2;
-VIOpc = RISCV::PseudoVMV_V_I_M2;
-break;
-  case RISCVII::LMUL_4:
-Opc = RISCV::VMV4R_V;
-SubRegIdx = RISCV::sub_vrm4_0;
-VVOpc = RISCV::PseudoVMV_V_V_M4;
-VIOpc = RISCV::PseudoVMV_V_I_M4;
-break;
-  case RISCVII::LMUL_8:
-assert(NF == 1);
-Opc = RISCV::VMV8R_V;
-SubRegIdx = RISCV::sub_vrm1_0; // There is no sub_vrm8_0.
-VVOpc = RISCV::PseudoVMV_V_V_M8;
-VIOpc = RISCV::PseudoVMV_V_I_M8;
-break;
-  }
-
-  bool UseVMV_V_V = false;
-  bool UseVMV_V_I = false;
-  MachineBasicBlock::const_iterator DefMBBI;
-  if (isConvertibleToVMV_V_V(STI, MBB, MBBI, DefMBBI, LMul)) {
-UseVMV_V_V = true;
-Opc = VVOpc;
-
-if (DefMBBI->getOpcode() == VIOpc) {
-  UseVMV_V_I = true;
-  Opc = VIOpc;
-}
-  }
-
-  if (NF == 1) {
-auto MIB = BuildMI(MBB, MBBI, DL, get(Opc), DstReg);
-if (UseVMV_V_V)
-  MIB.addReg(DstReg, RegState::Undef);
-if (UseVMV_V_I)
-  MIB = MIB.add(DefMBBI->getOperand(2));
-else
-  MIB = MIB.addReg(SrcReg, getKillRegState(KillSrc));
-if (UseVMV_V_V) {
-  const MCInstrDesc  = DefMBBI->getDesc();
-  MIB.add(DefMBBI->getOperand(RISCVII::getVLOpNum(Desc)));  // AVL
-  MIB.add(DefMBBI->getOperand(RISCVII::getSEWOpNum(Desc))); // SEW
-  MIB.addImm(0);// tu, mu
-  MIB.addReg(RISCV::VL, RegState::Implicit);
-  MIB.addReg(RISCV::VTYPE, RegState::Implicit);
-}
-return;
-  }
-
-  int I = 0, End = NF, Incr = 1;
   unsigned SrcEncoding = TRI->getEncodingValue(SrcReg);
   unsigned DstEncoding = TRI->getEncodingValue(DstReg);
   unsigned LMulVal;
   bool Fractional;
   std::tie(LMulVal, Fractional) = RISCVVType::decodeVLMUL(LMul);
   assert(!Fractional && "It is impossible be fractional lmul here.");
-  if (forwardCopyWillClobberTuple(DstEncoding, SrcEncoding, NF * LMulVal)) {
-I = NF - 1;
-End = -1;
-Incr = -1;
-  }
+  unsigned NumRegs = NF * LMulVal;
+  bool ReversedCopy =
+  forwardCopyWillClobberTuple(DstEncoding, SrcEncoding, NumRegs);
+  if (ReversedCopy) {
+// If there exists overlapping, we should copy the registers reversely.
+SrcEncoding += NumRegs - LMulVal;
+DstEncoding += NumRegs - LMulVal;
+  }
+
+  unsigned I = 0;
+  auto GetCopyInfo = [&](uint16_t SrcEncoding, uint16_t DstEncoding)
+  -> std::tuple {
+// If source register encoding and destination register encoding are 
aligned
+// to 8, we can do a LMUL8 copying.
+if (SrcEncoding % 8 == 0 && DstEncoding % 8 == 0 && I + 8 <= NumRegs)
+  return {RISCVII::LMUL_8, RISCV::VRM8RegClass, RISCV::VMV8R_V,
+  RISCV::PseudoVMV_V_V_M8, RISCV::PseudoVMV_V_I_M8};
+// If source register encoding and destination register encoding are 
aligned
+// to 4, we can do a LMUL4 copying.
+if (SrcEncoding % 4 == 0 && DstEncoding % 4 == 0 && I + 4 <= NumRegs)
+  return {RISCVII::LMUL_4, RISCV::VRM4RegClass, RISCV::VMV4R_V,
+  RISCV::PseudoVMV_V_V_M4, RISCV::PseudoVMV_V_I_M4};
+// If source register encoding and destination register encoding are 
aligned
+// to 2, we can do a LMUL2 copying.
+if (SrcEncoding % 2 == 0 && DstEncoding % 2 == 0 && I + 2 <= NumRegs)
+  return {RISCVII::LMUL_2, RISCV::VRM2RegClass, RISCV::VMV2R_V,
+  RISCV::PseudoVMV_V_V_M2, RISCV::PseudoVMV_V_I_M2};
+// Or we should do LMUL1 copying.
+return {RISCVII::LMUL_1, RISCV::VRRegClass, RISCV::VMV1R_V,
+RISCV::PseudoVMV_V_V_M1, RISCV::PseudoVMV_V_I_M1};
+  };
+  auto FindRegWithEncoding = [](const TargetRegisterClass ,
+uint16_t Encoding) {
+ArrayRef Regs = RegClass.getRegisters();
+const auto *FoundReg = llvm::find_if(Regs, [&](MCPhysReg Reg) {
+  return TRI->getEncodingValue(Reg) == Encoding;
+});
+// We should be always able to find one valid register.
+assert(FoundReg != Regs.end());
+return *FoundReg;
+  };

lukel97 wrote:

I presume you don't need to use a subreg index if the register is a VRN8M1 and 
you're trying to do a VRM8 copy? Since the VRM8 reg class should be a subclass 
of VRN8M1 right? (Hope I'm getting the subreg/subclass terminology right btw)

https://github.com/llvm/llvm-project/pull/84455

[llvm-branch-commits] [flang] [Flang][OpenMP][Lower] Refactor lowering of compound constructs (PR #87070)

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

llvmbot wrote:




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

Author: Sergio Afonso (skatrak)


Changes

This patch simplifies the lowering from PFT to MLIR of OpenMP compound 
constructs (i.e. combined and composite).

The new approach consists of iteratively processing the outermost leaf 
construct of the given combined construct until it cannot be split further. 
Both leaf constructs and composite ones have `gen...()` functions that are 
called when appropriate.

This approach enables treating a leaf construct the same way regardless of if 
it appeared as part of a combined construct, and it also enables the lowering 
of composite constructs as a single unit.

Previous corner cases are now handled in a more straightforward way and 
comments pointing to the relevant spec section are added. Directive sets are 
also completed with missing LOOP related constructs.

---

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


2 Files Affected:

- (modified) flang/include/flang/Semantics/openmp-directive-sets.h (+44-13) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+291-141) 


``diff
diff --git a/flang/include/flang/Semantics/openmp-directive-sets.h 
b/flang/include/flang/Semantics/openmp-directive-sets.h
index 91773ae3ea9a3e..842d251b682aa9 100644
--- a/flang/include/flang/Semantics/openmp-directive-sets.h
+++ b/flang/include/flang/Semantics/openmp-directive-sets.h
@@ -32,14 +32,14 @@ static const OmpDirectiveSet topDistributeSet{
 
 static const OmpDirectiveSet allDistributeSet{
 OmpDirectiveSet{
-llvm::omp::OMPD_target_teams_distribute,
-llvm::omp::OMPD_target_teams_distribute_parallel_do,
-llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
-llvm::omp::OMPD_target_teams_distribute_simd,
-llvm::omp::OMPD_teams_distribute,
-llvm::omp::OMPD_teams_distribute_parallel_do,
-llvm::omp::OMPD_teams_distribute_parallel_do_simd,
-llvm::omp::OMPD_teams_distribute_simd,
+Directive::OMPD_target_teams_distribute,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_simd,
+Directive::OMPD_teams_distribute,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_simd,
 } | topDistributeSet,
 };
 
@@ -63,10 +63,24 @@ static const OmpDirectiveSet allDoSet{
 } | topDoSet,
 };
 
+static const OmpDirectiveSet topLoopSet{
+Directive::OMPD_loop,
+};
+
+static const OmpDirectiveSet allLoopSet{
+OmpDirectiveSet{
+Directive::OMPD_parallel_loop,
+Directive::OMPD_target_parallel_loop,
+Directive::OMPD_target_teams_loop,
+Directive::OMPD_teams_loop,
+} | topLoopSet,
+};
+
 static const OmpDirectiveSet topParallelSet{
 Directive::OMPD_parallel,
 Directive::OMPD_parallel_do,
 Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_loop,
 Directive::OMPD_parallel_masked_taskloop,
 Directive::OMPD_parallel_masked_taskloop_simd,
 Directive::OMPD_parallel_master_taskloop,
@@ -82,6 +96,7 @@ static const OmpDirectiveSet allParallelSet{
 Directive::OMPD_target_parallel,
 Directive::OMPD_target_parallel_do,
 Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_parallel_loop,
 Directive::OMPD_target_teams_distribute_parallel_do,
 Directive::OMPD_target_teams_distribute_parallel_do_simd,
 Directive::OMPD_teams_distribute_parallel_do,
@@ -118,12 +133,14 @@ static const OmpDirectiveSet topTargetSet{
 Directive::OMPD_target_parallel,
 Directive::OMPD_target_parallel_do,
 Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_parallel_loop,
 Directive::OMPD_target_simd,
 Directive::OMPD_target_teams,
 Directive::OMPD_target_teams_distribute,
 Directive::OMPD_target_teams_distribute_parallel_do,
 Directive::OMPD_target_teams_distribute_parallel_do_simd,
 Directive::OMPD_target_teams_distribute_simd,
+Directive::OMPD_target_teams_loop,
 };
 
 static const OmpDirectiveSet allTargetSet{topTargetSet};
@@ -156,11 +173,12 @@ static const OmpDirectiveSet topTeamsSet{
 
 static const OmpDirectiveSet allTeamsSet{
 OmpDirectiveSet{
-llvm::omp::OMPD_target_teams,
-llvm::omp::OMPD_target_teams_distribute,
-llvm::omp::OMPD_target_teams_distribute_parallel_do,
-llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
-llvm::omp::OMPD_target_teams_distribute_simd,
+Directive::OMPD_target_teams,
+Directive::OMPD_target_teams_distribute,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_simd,
+  

[llvm-branch-commits] [flang] [Flang][OpenMP][Lower] Refactor lowering of compound constructs (PR #87070)

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

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

This patch simplifies the lowering from PFT to MLIR of OpenMP compound 
constructs (i.e. combined and composite).

The new approach consists of iteratively processing the outermost leaf 
construct of the given combined construct until it cannot be split further. 
Both leaf constructs and composite ones have `gen...()` functions that are 
called when appropriate.

This approach enables treating a leaf construct the same way regardless of if 
it appeared as part of a combined construct, and it also enables the lowering 
of composite constructs as a single unit.

Previous corner cases are now handled in a more straightforward way and 
comments pointing to the relevant spec section are added. Directive sets are 
also completed with missing LOOP related constructs.

>From ec0ed50b0d5f9606f0e9a1a3af601bec310f Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Fri, 29 Mar 2024 13:57:40 +
Subject: [PATCH] [Flang][OpenMP][Lower] Refactor lowering of compound
 constructs

This patch simplifies the lowering from PFT to MLIR of OpenMP compound
constructs (i.e. combined and composite).

The new approach consists of iteratively processing the outermost leaf
construct of the given combined construct until it cannot be split further.
Both leaf constructs and composite ones have `gen...()` functions that are
called when appropriate.

This approach enables treating a leaf construct the same way regardless of if
it appeared as part of a combined construct, and it also enables the lowering
of composite constructs as a single unit.

Previous corner cases are now handled in a more straightforward way and
comments pointing to the relevant spec section are added. Directive sets are
also completed with missing LOOP related constructs.
---
 .../flang/Semantics/openmp-directive-sets.h   |  57 ++-
 flang/lib/Lower/OpenMP/OpenMP.cpp | 432 --
 2 files changed, 335 insertions(+), 154 deletions(-)

diff --git a/flang/include/flang/Semantics/openmp-directive-sets.h 
b/flang/include/flang/Semantics/openmp-directive-sets.h
index 91773ae3ea9a3e..842d251b682aa9 100644
--- a/flang/include/flang/Semantics/openmp-directive-sets.h
+++ b/flang/include/flang/Semantics/openmp-directive-sets.h
@@ -32,14 +32,14 @@ static const OmpDirectiveSet topDistributeSet{
 
 static const OmpDirectiveSet allDistributeSet{
 OmpDirectiveSet{
-llvm::omp::OMPD_target_teams_distribute,
-llvm::omp::OMPD_target_teams_distribute_parallel_do,
-llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
-llvm::omp::OMPD_target_teams_distribute_simd,
-llvm::omp::OMPD_teams_distribute,
-llvm::omp::OMPD_teams_distribute_parallel_do,
-llvm::omp::OMPD_teams_distribute_parallel_do_simd,
-llvm::omp::OMPD_teams_distribute_simd,
+Directive::OMPD_target_teams_distribute,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_simd,
+Directive::OMPD_teams_distribute,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_simd,
 } | topDistributeSet,
 };
 
@@ -63,10 +63,24 @@ static const OmpDirectiveSet allDoSet{
 } | topDoSet,
 };
 
+static const OmpDirectiveSet topLoopSet{
+Directive::OMPD_loop,
+};
+
+static const OmpDirectiveSet allLoopSet{
+OmpDirectiveSet{
+Directive::OMPD_parallel_loop,
+Directive::OMPD_target_parallel_loop,
+Directive::OMPD_target_teams_loop,
+Directive::OMPD_teams_loop,
+} | topLoopSet,
+};
+
 static const OmpDirectiveSet topParallelSet{
 Directive::OMPD_parallel,
 Directive::OMPD_parallel_do,
 Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_loop,
 Directive::OMPD_parallel_masked_taskloop,
 Directive::OMPD_parallel_masked_taskloop_simd,
 Directive::OMPD_parallel_master_taskloop,
@@ -82,6 +96,7 @@ static const OmpDirectiveSet allParallelSet{
 Directive::OMPD_target_parallel,
 Directive::OMPD_target_parallel_do,
 Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_parallel_loop,
 Directive::OMPD_target_teams_distribute_parallel_do,
 Directive::OMPD_target_teams_distribute_parallel_do_simd,
 Directive::OMPD_teams_distribute_parallel_do,
@@ -118,12 +133,14 @@ static const OmpDirectiveSet topTargetSet{
 Directive::OMPD_target_parallel,
 Directive::OMPD_target_parallel_do,
 Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_parallel_loop,
 Directive::OMPD_target_simd,
 Directive::OMPD_target_teams,
 Directive::OMPD_target_teams_distribute,
 Directive::OMPD_target_teams_distribute_parallel_do,
 

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

2024-03-29 Thread Krzysztof Parzyszek via llvm-branch-commits

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

LGTM

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