[llvm-branch-commits] [mlir] release/18.x: [mlir][transform] replace original op to loop ops (#83537) (PR #87080)

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

lhunloh wrote:

> @lhunloh (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.

"`transform.structured.convert_to_loops` now properly deletes its target op."

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] [llvm] [RISCV] Use larger copies when register tuples are aligned (PR #84455)

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

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/84455

>From 35d0ea085b43a67c092e6263e6ec9d34e66e1453 Mon Sep 17 00:00:00 2001
From: Wang Pengcheng 
Date: Tue, 12 Mar 2024 17:31:47 +0800
Subject: [PATCH 1/6] Reduce copies

Created using spr 1.3.4
---
 llvm/lib/Target/RISCV/RISCVInstrInfo.cpp |  89 +-
 llvm/test/CodeGen/RISCV/rvv/vmv-copy.mir |  30 +---
 llvm/test/CodeGen/RISCV/rvv/zvlsseg-copy.mir | 175 +++
 3 files changed, 106 insertions(+), 188 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp 
b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index 7895e87702c711..9fe5666d6a81f4 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -302,58 +302,38 @@ void RISCVInstrInfo::copyPhysRegVector(MachineBasicBlock 
&MBB,
RISCVII::VLMUL LMul, unsigned NF) const 
{
   const TargetRegisterInfo *TRI = STI.getRegisterInfo();
 
-  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);
 
-  for (; I != End; I += Incr) {
+  unsigned I = 0;
+  while (I != NumRegs) {
 auto GetCopyInfo =
-[](RISCVII::VLMUL LMul,unsigned NF) -> std::tuple {
-  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;
-  }
-  return {SubRegIdx, Opc, VVOpc, VIOpc};
+[&](unsigned SrcReg,
+unsigned DstReg) -> std::tuple {
+  unsigned SrcEncoding = TRI->getEncodingValue(SrcReg);
+  unsigned DstEncoding = TRI->getEncodingValue(DstReg);
+  if (!(SrcEncoding & 0b111) && !(DstEncoding & 0b111) && I + 8 <= NumRegs)
+return {8, RISCV::VRM8RegClass, RISCV::VMV8R_V, 
RISCV::PseudoVMV_V_V_M8,
+RISCV::PseudoVMV_V_I_M8};
+  if (!(SrcEncoding & 0b11) && !(DstEncoding & 0b11) && I + 4 <= NumRegs)
+return {4, RISCV::VRM4RegClass, RISCV::VMV4R_V, 
RISCV::PseudoVMV_V_V_M4,
+RISCV::PseudoVMV_V_I_M4};
+  if (!(SrcEncoding & 0b1) && !(DstEncoding & 0b1) && I + 2 <= NumRegs)
+return {2, RISCV::VRM2RegClass, RISCV::VMV2R_V, 
RISCV::PseudoVMV_V_V_M2,
+RISCV::PseudoVMV_V_I_M2};
+  return {1, RISCV::VRRegClass, RISCV::VMV1R_V, RISCV::PseudoVMV_V_V_M1,
+  RISCV::PseudoVMV_V_I_M1};
 };
 
-auto [SubRegIdx, Opc, VVOpc, VIOpc] = GetCopyInfo(LMul, NF);
+auto [NumCopied, RegClass, Opc, VVOpc, VIOpc] = GetCopyInfo(SrcReg, 
DstReg);
 
 MachineBasicBlock::const_iterator DefMBBI;
 if (isConvertibleToVMV_V_V(STI, MBB, MBBI, DefMBBI, LMul)) {
@@ -364,6 +344,20 @@ void RISCVInstrInfo::copyPhysRegVector(MachineBasicBlock 
&MBB,
   }
 }
 
+for (MCPhysReg Reg : RegClass.getRegisters()) {
+  if (TRI->getEncodingValue(Reg) == TRI->getEncodingValue(SrcReg)) {
+SrcReg = Reg;
+break;
+  }
+}
+
+for (MCPhysReg Reg : RegClass.getRegisters()) {
+  if (TRI->getEncodingValue(Reg) == TRI->getEncodingValue(DstReg)) {
+DstReg = Reg;
+break;
+  }
+}
+
 auto EmitCopy = [&](MCRegister SrcReg, MCRegister DstReg, unsigned Opcode) 
{
   auto MIB = BuildMI(MBB, MBBI, DL, get(Opcode), DstReg);
   bool UseVMV_V_I = RISCV::getRVVMCOpcode(Opcode) == RISCV::VMV_V_I;
@@ -385,13 +379,10 @@ void RISCVInstrInfo::copyPhysRegVector(MachineBasicBlock 
&MBB,
   }
 };
 
-if (NF == 1) {
-  EmitCopy(SrcReg, DstReg, Opc);
-  return;
-}
-
-EmitCopy(TRI->getSubReg(SrcReg, SubRegIdx + I),
- TR

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

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


@@ -212,19 +185,13 @@ body: |
 ; CHECK-NEXT: $v7 = VMV1R_V $v14
 ; CHECK-NEXT: $v8 = VMV1R_V $v15
 ; CHECK-NEXT: $v9 = VMV1R_V $v16
-; CHECK-NEXT: $v4 = VMV1R_V $v10
-; CHECK-NEXT: $v5 = VMV1R_V $v11
-; CHECK-NEXT: $v6 = VMV1R_V $v12
-; CHECK-NEXT: $v7 = VMV1R_V $v13
-; CHECK-NEXT: $v8 = VMV1R_V $v14
-; CHECK-NEXT: $v9 = VMV1R_V $v15
+; CHECK-NEXT: $v4m2 = VMV2R_V $v10m2
+; CHECK-NEXT: $v6m2 = VMV2R_V $v12m2
+; CHECK-NEXT: $v8m2 = VMV2R_V $v14m2
 ; CHECK-NEXT: $v10 = VMV1R_V $v16
-; CHECK-NEXT: $v22 = VMV1R_V $v16
-; CHECK-NEXT: $v21 = VMV1R_V $v15
-; CHECK-NEXT: $v20 = VMV1R_V $v14
-; CHECK-NEXT: $v19 = VMV1R_V $v13
-; CHECK-NEXT: $v18 = VMV1R_V $v12
-; CHECK-NEXT: $v17 = VMV1R_V $v11
+; CHECK-NEXT: $v22m2 = VMV2R_V $v16m2

wangpc-pp wrote:

Thanks for catching this! Fixed.
I haved added more tests and checked the result, I think it should be robust 
now.

https://github.com/llvm/llvm-project/pull/84455
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Michael Kruse via llvm-branch-commits


@@ -1730,9 +1730,28 @@ LogicalResult LoopNestOp::verify() {
  << "range argument type does not match corresponding IV type";
   }
 
+  auto wrapper =
+  llvm::dyn_cast_if_present((*this)->getParentOp());
+
+  if (!wrapper || !wrapper.isWrapper())
+return emitOpError() << "expects parent op to be a valid loop wrapper";
+
   return success();
 }
 
+SmallVector LoopNestOp::getWrappers() {

Meinersbur wrote:

```suggestion
void LoopNestOp::findSurroundingWrappers(SmallVectorImpl 
&list) {
```
Instead of returning a list, LLVM often uses this pattern that fill's a 
caller's list. This may have been done because `SmallVector` has a SmallSize 
argument that should not be hardcoded in a public API, but with it being 
optional I don't know how relevant this still is. Another reason is to avoid 
the impression that this is a simple getter. Also, it allows hoisting the 
declaration of the list outside a loop. See 
https://llvm.org/docs/ProgrammersManual.html#vector and the note in 
https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h

https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Michael Kruse via llvm-branch-commits


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);
+if (!r.hasOneBlock())
+  return false;
+
+if (std::distance(r.op_begin(), r.op_end()) != 2)

Meinersbur wrote:

```suggestion
if (llvm::range_size(r.getOps()) != 2)
```

https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Michael Kruse via llvm-branch-commits


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);
+if (!r.hasOneBlock())
+  return false;
+
+if (std::distance(r.op_begin(), r.op_end()) != 2)
+  return false;
+
+::mlir::Operation &firstOp = *r.op_begin();
+::mlir::Operation &secondOp = *(++r.op_begin());

Meinersbur wrote:

[serious]
```suggestion
::mlir::Operation &secondOp = *(std::next(r.op_begin()));
```
`++` would potentially modify the underlying iterator. I think it's a temporary 
here, but there is also no reason to modify a temporary.

Also, why not `r.op_begin()[0]` and `r.op_begin()[1]`?

https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Michael Kruse via llvm-branch-commits


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);

Meinersbur wrote:

[style]
```suggestion
Region &r = $_op->getRegion(0);
```
Since this is emitted into the `mlir::omp` namespace, declaring the namespace 
for each type seems unnecessary. Or use `auto`?


https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Make omp.taskloop into a loop wrapper (PR #87253)

2024-04-02 Thread Michael Kruse via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/87253
___
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] [MLIR][OpenMP] Make omp.distribute into a loop wrapper (PR #87239)

2024-04-02 Thread Michael Kruse via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/87239
___
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-04-02 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak edited 
https://github.com/llvm/llvm-project/pull/87086
___
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-04-02 Thread Sergio Afonso via llvm-branch-commits

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

Thank you Krzysztof, LGTM. I have a couple of suggestions, but this should be 
ready if you don't agree with them.

https://github.com/llvm/llvm-project/pull/87086
___
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-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -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 &converter,
-   Fortran::semantics::SemanticsContext &semaCtx,
-   const Fortran::parser::OmpClauseList &clauseList) {
+static void genOpenMPReduction(Fortran::lower::AbstractConverter &converter,
+   Fortran::semantics::SemanticsContext &semaCtx,
+   const List &clauses) {

skatrak wrote:

Nit: I'm generally in favor of using `ArrayRef` in place of `const 
Container &` for function arguments in all `gen...` functions here and the 
constructor for `ClauseProcessor`, but if you don't agree I don't think it's a 
reason to withhold approval either.

https://github.com/llvm/llvm-project/pull/87086
___
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-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -58,17 +58,15 @@ void gatherFuncAndVarSyms(
 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
 llvm::SmallVectorImpl &symbolAndClause);
 
+int64_t getCollapseValue(const List &clauses);

skatrak wrote:

It looks like this function is only used within OpenMP.cpp, is it expected to 
be used elsewhere later? Otherwise it may make more sense to make it internal 
(`static`) to that compilation unit instead.

https://github.com/llvm/llvm-project/pull/87086
___
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-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -2357,44 +2332,44 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   converter.genLocation(beginBlockDirective.source);
   const auto origDirective =
   std::get(beginBlockDirective.t).v;
-  const auto &beginClauseList =
-  std::get(beginBlockDirective.t);
-  const auto &endClauseList =
-  std::get(endBlockDirective.t);
+  List beginClauses = makeClauses(
+  std::get(beginBlockDirective.t), 
semaCtx);
+  List endClauses = makeClauses(
+  std::get(endBlockDirective.t), semaCtx);
 
   assert(llvm::omp::blockConstructSet.test(origDirective) &&
  "Expected block construct");
 
-  for (const Fortran::parser::OmpClause &clause : beginClauseList.v) {
+  for (const Clause &clause : beginClauses) {
 mlir::Location clauseLocation = converter.genLocation(clause.source);
-if (!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u) &&
-!std::get_if(&clause.u)) {
+if (!std::get_if(&clause.u) &&

skatrak wrote:

Nit: I'd suggest taking the opportunity of already updating all these lines to 
sort them alphabetically and possibly replace `std::get_if` with 
`std::holds_alternative`, but feel free to ignore (same thing below for 
`endClauses`).

https://github.com/llvm/llvm-project/pull/87086
___
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-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -49,9 +49,8 @@ class ClauseProcessor {
 public:
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
-  const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx),
-clauses(makeClauses(clauses, semaCtx)) {}
+  const List &clauses)
+  : converter(converter), semaCtx(semaCtx), clauses(clauses) {}

skatrak wrote:

Could we make the `clauses` field an `ArrayRef`? In the regular use 
pattern of this class the clause list of the caller does not go out of scope 
before the `ClauseProcessor` instance does. Maybe we can document this and 
avoid creating a local copy.

In any case this is a discussion to consider creating another patch for, not 
something to be addressed here.

https://github.com/llvm/llvm-project/pull/87086
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

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


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);

joker-eph wrote:

It depends if anyone outside of this dialect could also implement this 
interface? (if not then why is it in the public header directory though?)

Another dialect implementing this interface could be in another namespace and 
see this kind of code injected potentially.

https://github.com/llvm/llvm-project/pull/87232
___
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] [mlir][Transforms][NFC] Make `rewriterImpl` private in `IRRewrite` (PR #84865)

2024-04-02 Thread Nicolas Vasilache via llvm-branch-commits

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


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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -8,12 +8,74 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
 
+#include 
+#include 
+#include 
+
 using namespace llvm;
-using namespace omp;
+using namespace llvm::omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D) {
+  auto Idx = static_cast(D);
+  if (Idx < 0 || Idx >= static_cast(Directive_enumSize))
+return {};
+  const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
+  return ArrayRef(&Row[2], &Row[2] + static_cast(Row[1]));
+}
+
+Directive getCompoundConstruct(ArrayRef Parts) {
+  if (Parts.empty())
+return OMPD_unknown;
+
+  // Parts don't have to be leafs, so expand them into leafs first.
+  // Store the expanded leafs in the same format as rows in the leaf
+  // table (generated by tablegen).
+  SmallVector RawLeafs(2);
+  for (Directive P : Parts) {
+ArrayRef Ls = getLeafConstructs(P);
+if (!Ls.empty())
+  RawLeafs.append(Ls.begin(), Ls.end());
+else
+  RawLeafs.push_back(P);
+  }
+
+  auto GivenLeafs{ArrayRef(RawLeafs).drop_front(2)};

skatrak wrote:

Can you add a comment to describe why this is done? I'm having trouble 
understanding it.

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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -8,12 +8,74 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
 
+#include 
+#include 
+#include 
+
 using namespace llvm;
-using namespace omp;
+using namespace llvm::omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D) {
+  auto Idx = static_cast(D);
+  if (Idx < 0 || Idx >= static_cast(Directive_enumSize))

skatrak wrote:

Nit: `Directive_enumSize` seems to be of `std::size_t` type, so maybe this can 
be simplified a bit:
```suggestion
  auto Idx = static_cast(D);
  if (Idx >= Directive_enumSize)
```

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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -0,0 +1,41 @@
+//===- llvm/unittests/Frontend/OpenMPComposeTest.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Frontend/OpenMP/OMP.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::omp;
+
+TEST(Composition, GetLeafConstructs) {
+  ArrayRef L1 = getLeafConstructs(OMPD_loop);
+  ASSERT_EQ(L1, (ArrayRef{}));
+  ArrayRef L2 = getLeafConstructs(OMPD_parallel_for);
+  ASSERT_EQ(L2, (ArrayRef{OMPD_parallel, OMPD_for}));
+  ArrayRef L3 = getLeafConstructs(OMPD_parallel_for_simd);
+  ASSERT_EQ(L3, (ArrayRef{OMPD_parallel, OMPD_for, OMPD_simd}));
+}
+
+TEST(Composition, GetCompoundConstruct) {
+  Directive C1 =
+  getCompoundConstruct({OMPD_target, OMPD_teams, OMPD_distribute});
+  ASSERT_EQ(C1, OMPD_target_teams_distribute);
+  Directive C2 = getCompoundConstruct({OMPD_target});
+  ASSERT_EQ(C2, OMPD_target);
+  Directive C3 = getCompoundConstruct({OMPD_target, OMPD_masked});
+  ASSERT_EQ(C3, OMPD_unknown);
+  Directive C4 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute});
+  ASSERT_EQ(C4, OMPD_target_teams_distribute);
+  Directive C5 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute});
+  ASSERT_EQ(C5, OMPD_target_teams_distribute);

skatrak wrote:

Same test as before?

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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak commented:

I think this looks reasonable if we want to both split a construct into leaf 
constructs and also merge multiple constructs into a single compound one, if it 
exists. I'm just wondering if we need that much flexibility (and complexity 
associated with it).

It looks to me that there are mainly a couple of things that we want to be able 
to do:
- Split any compound directive into a list of leaves, so that clauses can be 
appropriately assigned to each.
- Split combined directives while preserving composite constructs as a unit, 
useful during lowering.

This approach works well for the first case and the second case can be made to 
work by first processing composite and standalone constructs, then splitting 
combined directives into the first leaf and the rest, which we would combine. 
Then processing that "rest of the construct" by processing it the same way and 
splitting it iteratively until everything has been processed. This has the 
disadvantage of being costly in comparison, since combining leaf constructs 
involves a binary search within the leaf table.

I'm wondering if there's a better abstraction we could use in tablegen that 
would work for both. Specifically, I'm thinking whether this makes sense to do:
- Non-compound constructs remain as they are.
- Rename the `leafConstructs` list of records to `composite`, and only use it 
for composite constructs.
- Add an optional `combined` pair of records that defines exclusively for 
combined constructs what the outer/parent construct is and what the "rest" is.
- A directive cannot define both `composite` and `combined` simultaneously.

An example of how that would look in tablegen could be:
```tablegen
def OMP_DoSimd : Directive<"do simd"> {
  let allowedClauses = [...];
  // 2+ elements: both leaf constructs.
  let composite = [OMP_Do, OMP_Simd];
}
def OMP_ParallelDoSimd : Directive<"parallel do simd"> {
  let allowedClauses = [...];
  // Always 2 elements: the first is a leaf and the second can be compound.
  let combined = [OMP_Parallel, OMP_DoSimd];
}
def OMP_TargetParallelDoSimd : Directive<"target parallel do simd"> {
  let allowedClauses = [...];
  // Always 2 elements: the first is a leaf and the second can be compound.
  let combined = [OMP_Target, OMP_ParallelDoSimd];
}
```

Based on that alternative representation, I think it should be easier to 
implement both types of splitting without having to allow re-combining leaf 
constructs back into compound ones. Another advantage is that the 
representation is explicit in the separation between combined and composite 
directives. However, it doesn't make it any less cumbersome to add the proposed 
list of new combined constructs.

This is just an idea, which may have some big disadvantages I haven't thought 
about. I won't block the current proposal, but I prefer if others more involved 
in the definition of the OMP.td format gave this a look before merging as well.

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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

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

Thank you, based on the current proposal in #87247 this LGTM. If that changes, 
this will need another review.

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


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

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

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


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

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

https://github.com/kparzysz commented:

I have considered putting more information in the .td file, but I decided 
against it.  The main reason was that TableGen would need to have a lot more 
knowledge about OMP directives than it does now:
- It would need to be aware of OpenMP's definitions of "composite" vs. 
"combined" directives.  This information would need to be encoded in the 
directive emitter (as a part of TableGen), plus it would also be in the OMP.cpp 
file (as a part of the compiler).  In my view, the .td file should be easy to 
update (or in other words hard to make a mistake in).
- The directive emitter is shared between OpenMP and OpenACC, and this change 
would mean that we need to distinguish these two targets in the emitters.

Even if there was 1000 directives to search through, the search is binary, 
requiring in the worst case ~10 steps.

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


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

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


@@ -8,12 +8,74 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
 
+#include 
+#include 
+#include 
+
 using namespace llvm;
-using namespace omp;
+using namespace llvm::omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D) {
+  auto Idx = static_cast(D);
+  if (Idx < 0 || Idx >= static_cast(Directive_enumSize))

kparzysz wrote:

The underlying type of `Directive` is int, that's why I used int, but your 
suggestion is ok as well.

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


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

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


@@ -8,12 +8,74 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
 
+#include 
+#include 
+#include 
+
 using namespace llvm;
-using namespace omp;
+using namespace llvm::omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D) {
+  auto Idx = static_cast(D);
+  if (Idx < 0 || Idx >= static_cast(Directive_enumSize))
+return {};
+  const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
+  return ArrayRef(&Row[2], &Row[2] + static_cast(Row[1]));
+}
+
+Directive getCompoundConstruct(ArrayRef Parts) {
+  if (Parts.empty())
+return OMPD_unknown;
+
+  // Parts don't have to be leafs, so expand them into leafs first.
+  // Store the expanded leafs in the same format as rows in the leaf
+  // table (generated by tablegen).
+  SmallVector RawLeafs(2);
+  for (Directive P : Parts) {
+ArrayRef Ls = getLeafConstructs(P);
+if (!Ls.empty())
+  RawLeafs.append(Ls.begin(), Ls.end());
+else
+  RawLeafs.push_back(P);
+  }
+
+  auto GivenLeafs{ArrayRef(RawLeafs).drop_front(2)};

kparzysz wrote:

Done

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


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

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


@@ -0,0 +1,41 @@
+//===- llvm/unittests/Frontend/OpenMPComposeTest.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Frontend/OpenMP/OMP.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::omp;
+
+TEST(Composition, GetLeafConstructs) {
+  ArrayRef L1 = getLeafConstructs(OMPD_loop);
+  ASSERT_EQ(L1, (ArrayRef{}));
+  ArrayRef L2 = getLeafConstructs(OMPD_parallel_for);
+  ASSERT_EQ(L2, (ArrayRef{OMPD_parallel, OMPD_for}));
+  ArrayRef L3 = getLeafConstructs(OMPD_parallel_for_simd);
+  ASSERT_EQ(L3, (ArrayRef{OMPD_parallel, OMPD_for, OMPD_simd}));
+}
+
+TEST(Composition, GetCompoundConstruct) {
+  Directive C1 =
+  getCompoundConstruct({OMPD_target, OMPD_teams, OMPD_distribute});
+  ASSERT_EQ(C1, OMPD_target_teams_distribute);
+  Directive C2 = getCompoundConstruct({OMPD_target});
+  ASSERT_EQ(C2, OMPD_target);
+  Directive C3 = getCompoundConstruct({OMPD_target, OMPD_masked});
+  ASSERT_EQ(C3, OMPD_unknown);
+  Directive C4 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute});
+  ASSERT_EQ(C4, OMPD_target_teams_distribute);
+  Directive C5 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute});
+  ASSERT_EQ(C5, OMPD_target_teams_distribute);

kparzysz wrote:

Indeed.  Removed.

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


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

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

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

>From 291dc48d5e0b7e0ee39681a1276bd1d63f456b01 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 1 Apr 2024 10:07:45 -0500
Subject: [PATCH 1/2] [Frontend][OpenMP] Refactor getLeafConstructs, add
 getCompoundConstruct

Emit a special leaf constuct table in DirectiveEmitter.cpp, which will
allow both decomposition of a construct into leafs, and composition of
constituent constructs into a single compound construct (is possible).
---
 llvm/include/llvm/Frontend/OpenMP/OMP.h   |   7 +
 llvm/lib/Frontend/OpenMP/OMP.cpp  |  64 +-
 llvm/test/TableGen/directive1.td  |  19 +-
 llvm/test/TableGen/directive2.td  |  19 +-
 llvm/unittests/Frontend/CMakeLists.txt|   1 +
 llvm/unittests/Frontend/OpenMPComposeTest.cpp |  41 
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 194 +++---
 7 files changed, 258 insertions(+), 87 deletions(-)
 create mode 100644 llvm/unittests/Frontend/OpenMPComposeTest.cpp

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h 
b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index a85cd9d344c6d7..4ed47f15dfe59e 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -15,4 +15,11 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h.inc"
 
+#include "llvm/ADT/ArrayRef.h"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D);
+Directive getCompoundConstruct(ArrayRef Parts);
+} // namespace llvm::omp
+
 #endif // LLVM_FRONTEND_OPENMP_OMP_H
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 4f2f95392648b3..dd99d3d074fd1e 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -8,12 +8,74 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
 
+#include 
+#include 
+#include 
+
 using namespace llvm;
-using namespace omp;
+using namespace llvm::omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D) {
+  auto Idx = static_cast(D);
+  if (Idx < 0 || Idx >= static_cast(Directive_enumSize))
+return {};
+  const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
+  return ArrayRef(&Row[2], &Row[2] + static_cast(Row[1]));
+}
+
+Directive getCompoundConstruct(ArrayRef Parts) {
+  if (Parts.empty())
+return OMPD_unknown;
+
+  // Parts don't have to be leafs, so expand them into leafs first.
+  // Store the expanded leafs in the same format as rows in the leaf
+  // table (generated by tablegen).
+  SmallVector RawLeafs(2);
+  for (Directive P : Parts) {
+ArrayRef Ls = getLeafConstructs(P);
+if (!Ls.empty())
+  RawLeafs.append(Ls.begin(), Ls.end());
+else
+  RawLeafs.push_back(P);
+  }
+
+  auto GivenLeafs{ArrayRef(RawLeafs).drop_front(2)};
+  if (GivenLeafs.size() == 1)
+return GivenLeafs.front();
+  RawLeafs[1] = static_cast(GivenLeafs.size());
+
+  auto Iter = llvm::lower_bound(
+  LeafConstructTable,
+  
static_cast>(RawLeafs.data()),
+  [](const auto *RowA, const auto *RowB) {
+const auto *BeginA = &RowA[2];
+const auto *EndA = BeginA + static_cast(RowA[1]);
+const auto *BeginB = &RowB[2];
+const auto *EndB = BeginB + static_cast(RowB[1]);
+if (BeginA == EndA && BeginB == EndB)
+  return static_cast(RowA[0]) < static_cast(RowB[0]);
+return std::lexicographical_compare(BeginA, EndA, BeginB, EndB);
+  });
+
+  if (Iter == std::end(LeafConstructTable))
+return OMPD_unknown;
+
+  // Verify that we got a match.
+  Directive Found = (*Iter)[0];
+  ArrayRef FoundLeafs = getLeafConstructs(Found);
+  if (FoundLeafs == GivenLeafs)
+return Found;
+  return OMPD_unknown;
+}
+} // namespace llvm::omp
diff --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index 3184f625ead928..e6150210e7e9a4 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -52,6 +52,7 @@ def TDL_DirA : Directive<"dira"> {
 // CHECK-EMPTY:
 // CHECK-NEXT:  #include "llvm/ADT/ArrayRef.h"
 // CHECK-NEXT:  #include "llvm/ADT/BitmaskEnum.h"
+// CHECK-NEXT:  #include 
 // CHECK-EMPTY:
 // CHECK-NEXT:  namespace llvm {
 // CHECK-NEXT:  class StringRef;
@@ -112,7 +113,7 @@ def TDL_DirA : Directive<"dira"> {
 // CHECK-NEXT:  /// Return true if \p C is a valid clause for \p D in version 
\p Version.
 // CHECK-NEXT:  bool isAllowedClauseForDirective(Directive D, Clause C, 
unsigned Version);
 // CHECK-EMPTY:
-// CHECK-NEXT:  llvm::ArrayRef getLeafConstructs(Directive D);
+// CHECK-NEXT:  constexpr std::size_t getMaxLeafCount() { return 0; }
 // CHECK-NEXT:  Association getDirectiveAssociation(Directive D);
 // CHECK-NE

[llvm-branch-commits] [openmp] release/18x: [OpenMP][AIX] Affinity implementation for AIX (#84984) (PR #86695)

2024-04-02 Thread Xing Xue via llvm-branch-commits

xingxue-ibm wrote:

> Hi @xingxue-ibm (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.

Thank you very much, @tstellar! We don't have anything specific to add to the 
release notes at this point.

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] [mlir] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);

skatrak wrote:

@joker-eph Thanks for the comment, it is indeed not intended for this interface 
to be used outside of the OpenMP dialect. I chose to define it here because it 
looks like every other interface for the dialect is also in the same place 
(most of them look to be intended for just the OpenMP dialect as well). What 
would be a more suitable location for these internal interfaces?

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


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

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

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/87247
___
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-04-02 Thread Krzysztof Parzyszek via llvm-branch-commits

kparzysz wrote:

We can switch to ArrayRef in another PR.

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


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

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

skatrak wrote:

Thank you @kparzysz for sharing your thoughts. I think it's a reasonable 
solution, so it's fine by me. I'll leave it to someone more familiar with the 
directive emitter to approve the PR though.

https://github.com/llvm/llvm-project/pull/87247
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

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

>From 2452bc75a7f2efb67a0522bbe8b0e7ba5bc3365b Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Mon, 1 Apr 2024 13:04:14 +0100
Subject: [PATCH 1/2] [MLIR][OpenMP] Introduce the LoopWrapperInterface

This patch defines a common interface to be shared by all OpenMP loop wrapper
operations. The main restrictions these operations must meet in order to be
considered a wrapper are:

- They contain a single region.
- Their region contains a single block.
- Their block only contains another loop wrapper or `omp.loop_nest` and a
terminator.

The new interface is attached to the `omp.parallel`, `omp.wsloop`,
`omp.simdloop`, `omp.distribute` and `omp.taskloop` operations. It is not
currently enforced that these operations meet the wrapper restrictions, which
would break existing OpenMP loop-generating code. Rather, this will be
introduced progressively in subsequent patches.
---
 .../mlir/Dialect/OpenMP/OpenMPInterfaces.h|  3 +
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 16 +++--
 .../Dialect/OpenMP/OpenMPOpsInterfaces.td | 68 +++
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 19 ++
 mlir/test/Dialect/OpenMP/invalid.mlir | 16 -
 5 files changed, 117 insertions(+), 5 deletions(-)

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h
index b3184db8852161..787c48b05c5c5c 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h
@@ -21,6 +21,9 @@
 #include "mlir/Interfaces/ControlFlowInterfaces.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
 
+#define GET_OP_FWD_DEFINES
+#include "mlir/Dialect/OpenMP/OpenMPOps.h.inc"
+
 #include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.h.inc"
 
 namespace mlir::omp {
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index ffd00948915153..a7bf93deae2fb3 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -236,6 +236,7 @@ def PrivateClauseOp : OpenMP_Op<"private", 
[IsolatedFromAbove]> {
 
 def ParallelOp : OpenMP_Op<"parallel", [
  AutomaticAllocationScope, AttrSizedOperandSegments,
+ DeclareOpInterfaceMethods,
  DeclareOpInterfaceMethods,
  RecursiveMemoryEffects, ReductionClauseInterface]> {
   let summary = "parallel construct";
@@ -517,8 +518,6 @@ def SingleOp : OpenMP_Op<"single", 
[AttrSizedOperandSegments]> {
 
 def LoopNestOp : OpenMP_Op<"loop_nest", [SameVariadicOperandSize,
 AllTypesMatch<["lowerBound", "upperBound", "step"]>,
-ParentOneOf<["DistributeOp", "SimdLoopOp", 
"TaskloopOp",
- "WsloopOp"]>,
 RecursiveMemoryEffects]> {
   let summary = "rectangular loop nest";
   let description = [{
@@ -568,6 +567,10 @@ def LoopNestOp : OpenMP_Op<"loop_nest", 
[SameVariadicOperandSize,
 
 /// Returns the induction variables of the loop nest.
 ArrayRef getIVs() { return getRegion().getArguments(); }
+
+/// Returns the list of wrapper operations around this loop nest. Wrappers
+/// in the resulting vector will be sorted from innermost to outermost.
+SmallVector getWrappers();
   }];
 
   let hasCustomAssemblyFormat = 1;
@@ -580,6 +583,7 @@ def LoopNestOp : OpenMP_Op<"loop_nest", 
[SameVariadicOperandSize,
 
 def WsloopOp : OpenMP_Op<"wsloop", [AttrSizedOperandSegments,
  AllTypesMatch<["lowerBound", "upperBound", "step"]>,
+ DeclareOpInterfaceMethods,
  RecursiveMemoryEffects, ReductionClauseInterface]> {
   let summary = "worksharing-loop construct";
   let description = [{
@@ -700,7 +704,9 @@ def WsloopOp : OpenMP_Op<"wsloop", 
[AttrSizedOperandSegments,
 
//===--===//
 
 def SimdLoopOp : OpenMP_Op<"simdloop", [AttrSizedOperandSegments,
- AllTypesMatch<["lowerBound", "upperBound", "step"]>]> 
{
+ AllTypesMatch<["lowerBound", "upperBound", "step"]>,
+ DeclareOpInterfaceMethods,
+ RecursiveMemoryEffects]> {
  let summary = "simd loop construct";
   let description = [{
 The simd construct can be applied to a loop to indicate that the loop can 
be
@@ -809,7 +815,8 @@ def YieldOp : OpenMP_Op<"yield",
 // Distribute construct [2.9.4.1]
 
//===--===//
 def DistributeOp : OpenMP_Op<"distribute", [AttrSizedOperandSegments,
-  MemoryEffects<[MemWrite]>]> {
+ DeclareOpInterfaceMethods,
+ RecursiveMemoryEffects]> {
   let summary = "dis

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);
+if (!r.hasOneBlock())
+  return false;
+
+if (std::distance(r.op_begin(), r.op_end()) != 2)

skatrak wrote:

Done

https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);

skatrak wrote:

@Meinersbur I just removed the redundant `::mlir[::omp]::` uses from the 
interface definition.

https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -1730,9 +1730,28 @@ LogicalResult LoopNestOp::verify() {
  << "range argument type does not match corresponding IV type";
   }
 
+  auto wrapper =
+  llvm::dyn_cast_if_present((*this)->getParentOp());
+
+  if (!wrapper || !wrapper.isWrapper())
+return emitOpError() << "expects parent op to be a valid loop wrapper";
+
   return success();
 }
 
+SmallVector LoopNestOp::getWrappers() {

skatrak wrote:

Done.

https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits


@@ -69,6 +69,74 @@ def ReductionClauseInterface : 
OpInterface<"ReductionClauseInterface"> {
   ];
 }
 
+def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
+  let description = [{
+OpenMP operations that can wrap a single loop nest. When taking a wrapper
+role, these operations must only contain a single region with a single 
block
+in which there's a single operation and a terminator. That nested operation
+must be another loop wrapper or an `omp.loop_nest`.
+  }];
+
+  let cppNamespace = "::mlir::omp";
+
+  let methods = [
+InterfaceMethod<
+  /*description=*/[{
+Tell whether the operation could be taking the role of a loop wrapper.
+That is, it has a single region with a single block in which there are
+two operations: another wrapper or `omp.loop_nest` operation and a
+terminator.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isWrapper",
+  (ins ), [{}], [{
+if ($_op->getNumRegions() != 1)
+  return false;
+
+::mlir::Region &r = $_op->getRegion(0);
+if (!r.hasOneBlock())
+  return false;
+
+if (std::distance(r.op_begin(), r.op_end()) != 2)
+  return false;
+
+::mlir::Operation &firstOp = *r.op_begin();
+::mlir::Operation &secondOp = *(++r.op_begin());

skatrak wrote:

Done. I wasn't able to index directly because it's not a random access 
iterator, but I was able to use `std::next` to address your concerns.

https://github.com/llvm/llvm-project/pull/87232
___
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] [MLIR][OpenMP] Make omp.distribute into a loop wrapper (PR #87239)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

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

>From 4537071171506b17de3727800e3754e412c9a967 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Mon, 1 Apr 2024 14:08:33 +0100
Subject: [PATCH] [MLIR][OpenMP] Make omp.distribute into a loop wrapper

This patch updates the definition of `omp.distribute` to enforce the
restrictions of a wrapper operation.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 22 +--
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 11 ++
 mlir/test/Dialect/OpenMP/invalid.mlir | 34 -
 mlir/test/Dialect/OpenMP/ops.mlir | 38 +++
 4 files changed, 93 insertions(+), 12 deletions(-)

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index a7bf93deae2fb3..8dbfe447616e11 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -816,7 +816,8 @@ def YieldOp : OpenMP_Op<"yield",
 
//===--===//
 def DistributeOp : OpenMP_Op<"distribute", [AttrSizedOperandSegments,
  DeclareOpInterfaceMethods,
- RecursiveMemoryEffects]> {
+ RecursiveMemoryEffects,
+ SingleBlockImplicitTerminator<"TerminatorOp">]> {
   let summary = "distribute construct";
   let description = [{
 The distribute construct specifies that the iterations of one or more loops
@@ -831,15 +832,28 @@ def DistributeOp : OpenMP_Op<"distribute", 
[AttrSizedOperandSegments,
 The distribute loop construct specifies that the iterations of the loop(s)
 will be executed in parallel by threads in the current context. These
 iterations are spread across threads that already exist in the enclosing
-region. The lower and upper bounds specify a half-open range: the
-range includes the lower bound but does not include the upper bound. If the
-`inclusive` attribute is specified then the upper bound is also included.
+region.
+
+The body region can contain a single block which must contain a single
+operation and a terminator. The operation must be another compatible loop
+wrapper or an `omp.loop_nest`.
 
 The `dist_schedule_static` attribute specifies the  schedule for this
 loop, determining how the loop is distributed across the parallel threads.
 The optional `schedule_chunk` associated with this determines further
 controls this distribution.
 
+```mlir
+omp.distribute  {
+  omp.loop_nest (%i1, %i2) : index = (%c0, %c0) to (%c10, %c10) step (%c1, 
%c1) {
+%a = load %arrA[%i1, %i2] : memref
+%b = load %arrB[%i1, %i2] : memref
+%sum = arith.addf %a, %b : f32
+store %sum, %arrC[%i1, %i2] : memref
+omp.yield
+  }
+}
+```
 // TODO: private_var, firstprivate_var, lastprivate_var, collapse
   }];
   let arguments = (ins
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 564c23201db4fd..b407d27ef53e39 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1516,6 +1516,17 @@ LogicalResult DistributeOp::verify() {
 return emitError(
 "expected equal sizes for allocate and allocator variables");
 
+  if (!isWrapper())
+return emitOpError() << "must be a loop wrapper";
+
+  if (LoopWrapperInterface nested = getNestedWrapper()) {
+// Check for the allowed leaf constructs that may appear in a composite
+// construct directly after DISTRIBUTE.
+if (!isa(nested))
+  return emitError() << "only supported nested wrappers are 'omp.parallel' 
"
+"and 'omp.simdloop'";
+  }
+
   return success();
 }
 
diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir 
b/mlir/test/Dialect/OpenMP/invalid.mlir
index 8f4103dabee5df..35f5d24deb5d17 100644
--- a/mlir/test/Dialect/OpenMP/invalid.mlir
+++ b/mlir/test/Dialect/OpenMP/invalid.mlir
@@ -1847,7 +1847,16 @@ func.func @omp_target_depend(%data_var: memref) {
 
 // -
 
-func.func @omp_distribute(%data_var : memref) -> () {
+func.func @omp_distribute_schedule(%chunk_size : i32) -> () {
+  // expected-error @below {{op chunk size set without dist_schedule_static 
being present}}
+  "omp.distribute"(%chunk_size) <{operandSegmentSizes = array}> 
({
+  "omp.terminator"() : () -> ()
+}) : (i32) -> ()
+}
+
+// -
+
+func.func @omp_distribute_allocate(%data_var : memref) -> () {
   // expected-error @below {{expected equal sizes for allocate and allocator 
variables}}
   "omp.distribute"(%data_var) <{operandSegmentSizes = array}> ({
   "omp.terminator"() : () -> ()
@@ -1856,6 +1865,29 @@ func.func @omp_distribute(%data_var : memref) -> () 
{
 
 // -
 
+func.func @omp_distribute_wrapper() -> () {
+  // expected-error @bel

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Make omp.taskloop into a loop wrapper (PR #87253)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

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

>From daaf4f7fec79aeebf37b4a1d83d89d19904fb417 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Mon, 1 Apr 2024 17:05:38 +0100
Subject: [PATCH] [MLIR][OpenMP] Make omp.taskloop into a loop wrapper

This patch updates the definition of `omp.taskloop` to enforce the restrictions
of a wrapper operation.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td |  39 ++-
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  |  10 +
 mlir/test/Dialect/OpenMP/invalid.mlir |  92 +---
 mlir/test/Dialect/OpenMP/ops.mlir | 222 ++
 4 files changed, 212 insertions(+), 151 deletions(-)

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index a7bf93deae2fb3..b7660d6cd0ea5d 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -985,10 +985,10 @@ def TaskOp : OpenMP_Op<"task", [AttrSizedOperandSegments,
 }
 
 def TaskloopOp : OpenMP_Op<"taskloop", [AttrSizedOperandSegments,
-   AutomaticAllocationScope, RecursiveMemoryEffects,
-   AllTypesMatch<["lowerBound", "upperBound", "step"]>,
+   AutomaticAllocationScope,
DeclareOpInterfaceMethods,
-   ReductionClauseInterface]> {
+   RecursiveMemoryEffects, ReductionClauseInterface,
+   SingleBlockImplicitTerminator<"TerminatorOp">]> {
   let summary = "taskloop construct";
   let description = [{
 The taskloop construct specifies that the iterations of one or more
@@ -996,21 +996,19 @@ def TaskloopOp : OpenMP_Op<"taskloop", 
[AttrSizedOperandSegments,
 iterations are distributed across tasks generated by the construct and
 scheduled to be executed.
 
-The `lowerBound` and `upperBound` specify a half-open range: the range
-includes the lower bound but does not include the upper bound. If the
-`inclusive` attribute is specified then the upper bound is also included.
-The `step` specifies the loop step.
-
-The body region can contain any number of blocks.
+The body region can contain a single block which must contain a single
+operation and a terminator. The operation must be another compatible loop
+wrapper or an `omp.loop_nest`.
 
 ```
-omp.taskloop 
-for (%i1, %i2) : index = (%c0, %c0) to (%c10, %c10) step (%c1, %c1) {
-  %a = load %arrA[%i1, %i2] : memref
-  %b = load %arrB[%i1, %i2] : memref
-  %sum = arith.addf %a, %b : f32
-  store %sum, %arrC[%i1, %i2] : memref
-  omp.terminator
+omp.taskloop  {
+  omp.loop_nest (%i1, %i2) : index = (%c0, %c0) to (%c10, %c10) step (%c1, 
%c1) {
+%a = load %arrA[%i1, %i2] : memref
+%b = load %arrB[%i1, %i2] : memref
+%sum = arith.addf %a, %b : f32
+store %sum, %arrC[%i1, %i2] : memref
+omp.yield
+  }
 }
 ```
 
@@ -1087,11 +1085,7 @@ def TaskloopOp : OpenMP_Op<"taskloop", 
[AttrSizedOperandSegments,
 created.
   }];
 
-  let arguments = (ins Variadic:$lowerBound,
-   Variadic:$upperBound,
-   Variadic:$step,
-   UnitAttr:$inclusive,
-   Optional:$if_expr,
+  let arguments = (ins Optional:$if_expr,
Optional:$final_expr,
UnitAttr:$untied,
UnitAttr:$mergeable,
@@ -1130,8 +1124,7 @@ def TaskloopOp : OpenMP_Op<"taskloop", 
[AttrSizedOperandSegments,
   |`grain_size` `(` $grain_size `:` type($grain_size) `)`
   |`num_tasks` `(` $num_tasks `:` type($num_tasks) `)`
   |`nogroup` $nogroup
-) `for` custom($region, $lowerBound, $upperBound, $step,
-  type($step), $inclusive) attr-dict
+) $region attr-dict
   }];
 
   let extraClassDeclaration = [{
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 564c23201db4fd..c92e593c20dc45 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1659,6 +1659,16 @@ LogicalResult TaskloopOp::verify() {
 "the grainsize clause and num_tasks clause are mutually exclusive and "
 "may not appear on the same taskloop directive");
   }
+
+  if (!isWrapper())
+return emitOpError() << "must be a loop wrapper";
+
+  if (LoopWrapperInterface nested = getNestedWrapper()) {
+// Check for the allowed leaf constructs that may appear in a composite
+// construct directly after TASKLOOP.
+if (!isa(nested))
+  return emitError() << "only supported nested wrapper is 'omp.simdloop'";
+  }
   return success();
 }
 
diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir 
b/mlir/test/Dialect/OpenMP/invalid.mlir
index 8f4103dabee5df..4e9f3b0cff064d 

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

2024-04-02 Thread Andrew Ng via llvm-branch-commits

nga888 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.

Fix color handling for buffered formatted_raw_ostream which allows the 
unbuffered workaround in llvm-objdump to be removed, restoring the performance 
of llvm-objdump disassembly when the output is redirected.

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] [flang] [mlir] [MLIR][OpenMP] Make omp.simdloop into a loop wrapper (PR #87365)

2024-04-02 Thread Sergio Afonso via llvm-branch-commits

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

This patch updates the definition of `omp.simdloop` to enforce the restrictions 
of a wrapper operation. It has been renamed to `omp.simd`, to better reflect 
the naming used in the spec.

Some changes to Flang lowering and OpenMP to LLVM IR translation are introduced 
in order for this patch to be able to compile and run. The eventual long term 
solution might be different.

This is a WIP posted early for visibility. Related unit tests need updating and 
there might still be some bugs due to lack of testing.

>From 0326e2d10e34f63cb7f32b767a611de108bddb0f Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 2 Apr 2024 17:20:37 +0100
Subject: [PATCH] [MLIR][OpenMP] Make omp.simdloop into a loop wrapper

This patch updates the definition of `omp.simdloop` to enforce the restrictions
of a wrapper operation. It has been renamed to `omp.simd`, to better reflect
the naming used in the spec.

Some changes to Flang lowering and OpenMP to LLVM IR translation are introduced
in order for this patch to be able to compile and run. The eventual long term
solution might be different.

This is a WIP posted early for visibility. Related unit tests need updating and
there might still be some bugs due to lack of testing.
---
 flang/lib/Lower/OpenMP/OpenMP.cpp | 70 +++
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 56 ++-
 .../Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp  | 22 +++---
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 12 ++--
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  | 40 ++-
 5 files changed, 101 insertions(+), 99 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 340921c867246c..a3da92ba339fd9 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -521,7 +521,7 @@ struct OpWithBodyGenInfo {
 /// \param [in]   op - the operation the body belongs to.
 /// \param [in] info - options controlling code-gen for the construction.
 template 
-static void createBodyOfOp(Op &op, OpWithBodyGenInfo &info) {
+static void createBodyOfOp(mlir::Operation &op, OpWithBodyGenInfo &info) {
   fir::FirOpBuilder &firOpBuilder = info.converter.getFirOpBuilder();
 
   auto insertMarker = [](fir::FirOpBuilder &builder) {
@@ -537,10 +537,10 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo 
&info) {
   auto regionArgs =
   [&]() -> llvm::SmallVector {
 if (info.genRegionEntryCB != nullptr) {
-  return info.genRegionEntryCB(op);
+  return info.genRegionEntryCB(&op);
 }
 
-firOpBuilder.createBlock(&op.getRegion());
+firOpBuilder.createBlock(&op.getRegion(0));
 return {};
   }();
   // Mark the earliest insertion point.
@@ -556,7 +556,7 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo &info) 
{
   // Start with privatization, so that the lowering of the nested
   // code will use the right symbols.
   constexpr bool isLoop = std::is_same_v ||
-  std::is_same_v;
+  std::is_same_v;
   bool privatize = info.clauses && !info.outerCombined;
 
   firOpBuilder.setInsertionPoint(marker);
@@ -582,9 +582,9 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo &info) 
{
 // a lot of complications for our approach if the terminator generation
 // is delayed past this point. Insert a temporary terminator here, then
 // delete it.
-firOpBuilder.setInsertionPointToEnd(&op.getRegion().back());
-auto *temp = Fortran::lower::genOpenMPTerminator(
-firOpBuilder, op.getOperation(), info.loc);
+firOpBuilder.setInsertionPointToEnd(&op.getRegion(0).back());
+auto *temp =
+Fortran::lower::genOpenMPTerminator(firOpBuilder, &op, info.loc);
 firOpBuilder.setInsertionPointAfter(marker);
 genNestedEvaluations(info.converter, info.eval);
 temp->erase();
@@ -626,10 +626,10 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo 
&info) {
 return exit;
   };
 
-  if (auto *exitBlock = getUniqueExit(op.getRegion())) {
+  if (auto *exitBlock = getUniqueExit(op.getRegion(0))) {
 firOpBuilder.setInsertionPointToEnd(exitBlock);
-auto *term = Fortran::lower::genOpenMPTerminator(
-firOpBuilder, op.getOperation(), info.loc);
+auto *term =
+Fortran::lower::genOpenMPTerminator(firOpBuilder, &op, info.loc);
 // Only insert lastprivate code when there actually is an exit block.
 // Such a block may not exist if the nested code produced an infinite
 // loop (this may not make sense in production code, but a user could
@@ -638,11 +638,11 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo 
&info) {
 if (privatize) {
   if (!info.dsp) {
 assert(tempDsp.has_value());
-tempDsp->processStep2(op, isLoop);
+tempDsp->processStep2(&op, isLoop);
   } else {
 if (isLoop && regionArgs.size() > 0)
   info.dsp->setLoopIV(info.

[llvm-branch-commits] [libcxx] release/18.x: [libc++] Simplify the implementation of (#86843) (PR #87374)

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

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


[llvm-branch-commits] [libcxx] release/18.x: [libc++] Simplify the implementation of (#86843) (PR #87374)

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

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

Backport 2950283dddab03c183c1be2d7de9d4999cc86131

Requested by: @ian-twilightcoder

>From 20cb23caea75d1d94e930ce0593eb92770f3c94d Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Tue, 2 Apr 2024 08:14:04 -0400
Subject: [PATCH] [libc++] Simplify the implementation of  (#86843)

Libc++'s own  is complicated by the need to handle various
platform-specific macros and to support duplicate inclusion. In reality,
we only need to add a declaration of nullptr_t to it, so we can simply
include the underlying  outside of our guards to let it handle
re-inclusion itself.

(cherry picked from commit 2950283dddab03c183c1be2d7de9d4999cc86131)
---
 libcxx/include/stddef.h | 25 -
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/libcxx/include/stddef.h b/libcxx/include/stddef.h
index 887776b150e49d..470b5408336c6d 100644
--- a/libcxx/include/stddef.h
+++ b/libcxx/include/stddef.h
@@ -7,18 +7,6 @@
 //
 
//===--===//
 
-#if defined(__need_ptrdiff_t) || defined(__need_size_t) || 
defined(__need_wchar_t) || defined(__need_NULL) ||  \
-defined(__need_wint_t)
-
-#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#  endif
-
-#  include_next 
-
-#elif !defined(_LIBCPP_STDDEF_H)
-#  define _LIBCPP_STDDEF_H
-
 /*
 stddef.h synopsis
 
@@ -36,16 +24,19 @@
 
 */
 
-#  include <__config>
+#include <__config>
+
+// Note: This include is outside of header guards because we sometimes get 
included multiple times
+//   with different defines and the underlying  will know how to 
deal with that.
+#include_next 
+
+#ifndef _LIBCPP_STDDEF_H
+#  define _LIBCPP_STDDEF_H
 
 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #  endif
 
-#  if __has_include_next()
-#include_next 
-#  endif
-
 #  ifdef __cplusplus
 typedef decltype(nullptr) nullptr_t;
 #  endif

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


[llvm-branch-commits] [compiler-rt] f249092 - [tsan] Refine fstat{, 64} interceptors (#86625)

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

Author: Fangrui Song
Date: 2024-04-01T22:10:23Z
New Revision: f249092ef26d6fe9627b0158c7c15dee241226db

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

LOG: [tsan] Refine fstat{,64} interceptors (#86625)

In glibc versions before 2.33. `libc_nonshared.a` defines
`__fxstat/__fxstat64` but there is no `fstat/fstat64`. glibc 2.33 added
`fstat/fstat64` and obsoleted `__fxstat/__fxstat64`. Ports added after
2.33 do not provide `__fxstat/__fxstat64`, so our `fstat/fstat64`
interceptors using `__fxstat/__fxstat64` interceptors would lead to
runtime failures on such ports (LoongArch and certain RISC-V ports).

Similar to https://reviews.llvm.org/D118423, refine the conditions that
we define fstat{,64} interceptors. `fstat` is supported by musl/*BSD
while `fstat64` is glibc only.

(cherry picked from commit d5224b73ccd09a6759759791f58426b6acd4a2e2)

Added: 


Modified: 
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Removed: 




diff  --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index a9f6673ac44e90..d0282c27043125 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -14,6 +14,7 @@
 
 #include "sanitizer_common/sanitizer_atomic.h"
 #include "sanitizer_common/sanitizer_errno.h"
+#include "sanitizer_common/sanitizer_glibc_version.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_linux.h"
 #include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
@@ -1613,47 +1614,40 @@ TSAN_INTERCEPTOR(int, __fxstat, int version, int fd, 
void *buf) {
 FdAccess(thr, pc, fd);
   return REAL(__fxstat)(version, fd, buf);
 }
-#define TSAN_MAYBE_INTERCEPT___FXSTAT TSAN_INTERCEPT(__fxstat)
+
+TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
+  SCOPED_TSAN_INTERCEPTOR(__fxstat64, version, fd, buf);
+  if (fd > 0)
+FdAccess(thr, pc, fd);
+  return REAL(__fxstat64)(version, fd, buf);
+}
+#define TSAN_MAYBE_INTERCEPT___FXSTAT TSAN_INTERCEPT(__fxstat); 
TSAN_INTERCEPT(__fxstat64)
 #else
 #define TSAN_MAYBE_INTERCEPT___FXSTAT
 #endif
 
+#if !SANITIZER_GLIBC || __GLIBC_PREREQ(2, 33)
 TSAN_INTERCEPTOR(int, fstat, int fd, void *buf) {
-#if SANITIZER_GLIBC
-  SCOPED_TSAN_INTERCEPTOR(__fxstat, 0, fd, buf);
-  if (fd > 0)
-FdAccess(thr, pc, fd);
-  return REAL(__fxstat)(0, fd, buf);
-#else
   SCOPED_TSAN_INTERCEPTOR(fstat, fd, buf);
   if (fd > 0)
 FdAccess(thr, pc, fd);
   return REAL(fstat)(fd, buf);
-#endif
-}
-
-#if SANITIZER_GLIBC
-TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
-  SCOPED_TSAN_INTERCEPTOR(__fxstat64, version, fd, buf);
-  if (fd > 0)
-FdAccess(thr, pc, fd);
-  return REAL(__fxstat64)(version, fd, buf);
 }
-#define TSAN_MAYBE_INTERCEPT___FXSTAT64 TSAN_INTERCEPT(__fxstat64)
+#  define TSAN_MAYBE_INTERCEPT_FSTAT TSAN_INTERCEPT(fstat)
 #else
-#define TSAN_MAYBE_INTERCEPT___FXSTAT64
+#  define TSAN_MAYBE_INTERCEPT_FSTAT
 #endif
 
-#if SANITIZER_GLIBC
+#if __GLIBC_PREREQ(2, 33)
 TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) {
-  SCOPED_TSAN_INTERCEPTOR(__fxstat64, 0, fd, buf);
+  SCOPED_TSAN_INTERCEPTOR(fstat64, fd, buf);
   if (fd > 0)
 FdAccess(thr, pc, fd);
-  return REAL(__fxstat64)(0, fd, buf);
+  return REAL(fstat64)(fd, buf);
 }
-#define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
+#  define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
 #else
-#define TSAN_MAYBE_INTERCEPT_FSTAT64
+#  define TSAN_MAYBE_INTERCEPT_FSTAT64
 #endif
 
 TSAN_INTERCEPTOR(int, open, const char *name, int oflag, ...) {
@@ -2950,10 +2944,9 @@ void InitializeInterceptors() {
 
   TSAN_INTERCEPT(pthread_once);
 
-  TSAN_INTERCEPT(fstat);
   TSAN_MAYBE_INTERCEPT___FXSTAT;
+  TSAN_MAYBE_INTERCEPT_FSTAT;
   TSAN_MAYBE_INTERCEPT_FSTAT64;
-  TSAN_MAYBE_INTERCEPT___FXSTAT64;
   TSAN_INTERCEPT(open);
   TSAN_MAYBE_INTERCEPT_OPEN64;
   TSAN_INTERCEPT(creat);



___
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] c13b748 - [clang] Avoid -Wshadow warning when init-capture named same as class field (#74512)

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

Author: Mariya Podchishchaeva
Date: 2024-04-02T15:10:59-07:00
New Revision: c13b7485b87909fcf739f62cfa382b55407433c0

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

LOG: [clang] Avoid -Wshadow warning when init-capture named same as class field 
(#74512)

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/ScopeInfo.h
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ebeb47a871e27b..ce7e615d878944 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -899,6 +899,9 @@ Bug Fixes in This Version
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
   Fixes (`#64356 `_).
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field unless the lambda can capture this.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/Sema/ScopeInfo.h 
b/clang/include/clang/Sema/ScopeInfo.h
index 6eaa74382685ba..06e47eed4e93b6 100644
--- a/clang/include/clang/Sema/ScopeInfo.h
+++ b/clang/include/clang/Sema/ScopeInfo.h
@@ -925,8 +925,8 @@ class LambdaScopeInfo final :
   /// that were defined in parent contexts. Used to avoid warnings when the
   /// shadowed variables are uncaptured by this lambda.
   struct ShadowedOuterDecl {
-const VarDecl *VD;
-const VarDecl *ShadowedDecl;
+const NamedDecl *VD;
+const NamedDecl *ShadowedDecl;
   };
   llvm::SmallVector ShadowingDecls;
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a300badc6d0260..f5bb3e0b42e26c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8396,28 +8396,40 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
-if (RD->getLambdaCaptureDefault() == LCD_None) {
-  // Try to avoid warnings for lambdas with an explicit capture list.
+if (const auto *VD = dyn_cast(ShadowedDecl)) {
   const auto *LSI = cast(getCurFunction());
-  // Warn only when the lambda captures the shadowed decl explicitly.
-  CaptureLoc = getCaptureLocation(LSI, cast(ShadowedDecl));
-  if (CaptureLoc.isInvalid())
-WarningDiag = diag::warn_decl_shadow_uncaptured_local;
-} else {
-  // Remember that this was shadowed so we can avoid the warning if the
-  // shadowed decl isn't captured and the warning settings allow it.
+  if (RD->getLambdaCaptureDefault() == LCD_None) {
+// Try to avoid warnings for lambdas with an explicit capture
+// list. Warn only when the lambda captures the shadowed decl
+// explicitly.
+CaptureLoc = getCaptureLocation(LSI, VD);
+if (CaptureLoc.isInvalid())
+  WarningDiag = diag::warn_decl_shadow_uncaptured_local;
+  } else {
+// Remember that this was shadowed so we can avoid the warning if
+// the shadowed decl isn't captured and the warning settings allow
+// it.
+cast(getCurFunction())
+->ShadowingDecls.push_back({D, VD});
+return;
+  }
+}
+if (isa(ShadowedDecl)) {
+  // If lambda can capture this, then emit default shadowing warning,
+  // Otherwise it is not really a shadowing case since field is not
+  // available in lambda's body.
+  // At this point we don't know that lambda can capture this, so
+  // remember that this was shadowed and delay until we know.
   cast(getCurFunction())
-  ->ShadowingDecls.push_back(
-  {cast(D), cast(ShadowedDecl)});
+  ->ShadowingDecls.push_back({D, ShadowedDecl});
   return;
 }
   }
-
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // 

[llvm-branch-commits] [llvm] fa3df67 - Revert "[PAC][llvm-readobj][AArch64][ELF] Support `GNU_PROPERTY_AARCH64_FEATU…"

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

Author: Daniil Kovalev
Date: 2024-04-03T03:11:37+03:00
New Revision: fa3df6749e2752ce70d1aa1054be1349a86e2dc9

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

LOG: Revert "[PAC][llvm-readobj][AArch64][ELF] Support 
`GNU_PROPERTY_AARCH64_FEATU…"

This reverts commit 5029949952f4dc745dcb7799c7449a02fe8309c3.

Added: 


Modified: 
llvm/include/llvm/BinaryFormat/ELF.h
llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-note-gnu-property.s
llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 




diff  --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index ed267c100b76eb..877f3f7862c8ba 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1712,6 +1712,11 @@ enum {
   NT_ANDROID_TYPE_MEMTAG = 4,
 };
 
+// ARM note types.
+enum {
+  NT_ARM_TYPE_PAUTH_ABI_TAG = 1,
+};
+
 // Memory tagging values used in NT_ANDROID_TYPE_MEMTAG notes.
 enum {
   // Enumeration to determine the tagging mode. In Android-land, 'SYNC' means
@@ -1735,7 +1740,6 @@ enum : unsigned {
   GNU_PROPERTY_STACK_SIZE = 1,
   GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
   GNU_PROPERTY_AARCH64_FEATURE_1_AND = 0xc000,
-  GNU_PROPERTY_AARCH64_FEATURE_PAUTH = 0xc001,
   GNU_PROPERTY_X86_FEATURE_1_AND = 0xc002,
 
   GNU_PROPERTY_X86_UINT32_OR_LO = 0xc0008000,
@@ -1754,26 +1758,6 @@ enum : unsigned {
   GNU_PROPERTY_AARCH64_FEATURE_1_GCS = 1 << 2,
 };
 
-// aarch64 PAuth platforms.
-enum : unsigned {
-  AARCH64_PAUTH_PLATFORM_INVALID = 0x0,
-  AARCH64_PAUTH_PLATFORM_BAREMETAL = 0x1,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX = 0x1002,
-};
-
-// Bit positions of version flags for AARCH64_PAUTH_PLATFORM_LLVM_LINUX.
-enum : unsigned {
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INTRINSICS = 0,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_CALLS = 1,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_RETURNS = 2,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_AUTHTRAPS = 3,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_VPTRADDRDISCR = 4,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_VPTRTYPEDISCR = 5,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI = 6,
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST =
-  AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI,
-};
-
 // x86 processor feature bits.
 enum : unsigned {
   GNU_PROPERTY_X86_FEATURE_1_IBT = 1 << 0,

diff  --git a/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s 
b/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
index 24918e883d9bfe..f28d92eae85754 100644
--- a/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
+++ b/llvm/test/tools/llvm-readobj/ELF/AArch64/aarch64-feature-pauth.s
@@ -1,211 +1,98 @@
 # RUN: rm -rf %t && split-file %s %t && cd %t
 
-#--- gnu-42-1.s
-
-.section ".note.gnu.property", "a"
-  .long 4   // Name length is always 4 ("GNU")
-  .long end - begin // Data length
-  .long 5   // Type: NT_GNU_PROPERTY_TYPE_0
-  .asciz "GNU"  // Name
-  .p2align 3
-begin:
-  # PAuth ABI property note
-  .long 0xc001  // Type: GNU_PROPERTY_AARCH64_FEATURE_PAUTH
-  .long 16  // Data size
-  .quad 42  // PAuth ABI platform
-  .quad 1   // PAuth ABI version
-  .p2align 3// Align to 8 byte for 64 bit
-end:
-
-# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnu gnu-42-1.s -o gnu-42-1.o
-# RUN: llvm-readelf --notes gnu-42-1.o | \
-# RUN:   FileCheck --check-prefix=ELF -DPLATFORM="0x2a (unknown)" 
-DVERSION=0x1 %s
-# RUN: llvm-readobj --notes gnu-42-1.o | \
-# RUN:   FileCheck --check-prefix=OBJ -DPLATFORM="0x2a (unknown)" 
-DVERSION=0x1 %s
-
-# ELF: Displaying notes found in: .note.gnu.property
-# ELF-NEXT:   Owner Data size  Description
-# ELF-NEXT:   GNU   0x0018 NT_GNU_PROPERTY_TYPE_0 
(property note)
-# ELF-NEXT:   AArch64 PAuth ABI core info: platform [[PLATFORM]], version 
[[VERSION]]
-
-# OBJ:  Notes [
-# OBJ-NEXT:   NoteSection {
-# OBJ-NEXT: Name: .note.gnu.property
-# OBJ-NEXT: Offset: 0x40
-# OBJ-NEXT: Size: 0x28
-# OBJ-NEXT: Note {
-# OBJ-NEXT:   Owner: GNU
-# OBJ-NEXT:   Data size: 0x18
-# OBJ-NEXT:   Type: NT_GNU_PROPERTY_TYPE_0 (property note)
-# OBJ-NEXT:   Property [
-# OBJ-NEXT: AArch64 PAuth ABI core info: platform [[PLATFORM]], 
version [[VERSION]]
-# OBJ-NEXT:   ]
-# OBJ-NEXT: }
-# OBJ-NEXT:   }
-# OBJ-NEXT: ]
-
-#--- gnu-0-0.s
-
-.section ".note.gnu.property", "a"
-  .long 4   // Name length is always 4 ("GNU")
-  .long end - begin // Data length
-  .long 5   // Type: NT_GNU_PROPERTY_TYPE_0
-  .asciz "GNU"  // Name
-  .p2align 3
-begin:
-  # PAuth ABI property note
-  .long 0xc001  // Type