[llvm-branch-commits] [flang] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

Introduce `genNestedEvaluations` that will lower all evaluations nested in the 
given, accouting for a potential COLLAPSE directive.

Recursive lowering [2/5]

>From fd51d9b3ad850579787cb31a5423498e09d51f0c Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 9 Jan 2024 12:22:06 -0600
Subject: [PATCH] [Flang][OpenMP] Push genEval calls to individual operations,
 NFC

Introduce `genNestedEvaluations` that will lower all evaluations
nested in the given, accouting for a potential COLLAPSE directive.

Recursive lowering [2/5]
---
 flang/lib/Lower/OpenMP.cpp | 128 +++--
 1 file changed, 66 insertions(+), 62 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 99690b03eca1d3..496b4ba27a0533 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -110,6 +110,32 @@ static void gatherFuncAndVarSyms(
   }
 }
 
+static Fortran::lower::pft::Evaluation *
+getEvalPastCollapse(Fortran::lower::pft::Evaluation &eval, int collapseValue) {
+  if (collapseValue == 0)
+return &eval;
+
+  Fortran::lower::pft::Evaluation *curEval = &eval.getFirstNestedEvaluation();
+  for (int i = 1; i < collapseValue; i++) {
+// The nested evaluations should be DoConstructs (i.e. they should form
+// a loop nest). Each DoConstruct is a tuple .
+assert(curEval->isA());
+curEval = &*std::next(curEval->getNestedEvaluations().begin());
+  }
+  return curEval;
+}
+
+static void genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ int collapseValue = 0) {
+  Fortran::lower::pft::Evaluation *curEval =
+  getEvalPastCollapse(eval, collapseValue);
+
+  for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations())
+converter.genEval(e);
+}
+
 
//===--===//
 // DataSharingProcessor
 
//===--===//
@@ -2944,7 +2970,7 @@ genOmpFlush(Fortran::lower::AbstractConverter &converter,
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) {
   std::visit(
@@ -3025,15 +3051,17 @@ createSimdLoop(Fortran::lower::AbstractConverter 
&converter,
   createBodyOfOp(simdLoopOp, converter, loc, eval,
 &loopOpClauseList, iv,
 /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(loopOpClauseList));
 }
 
-static void
-createWsLoop(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- llvm::omp::Directive ompDirective,
- const Fortran::parser::OmpClauseList &beginClauseList,
- const Fortran::parser::OmpClauseList *endClauseList,
- mlir::Location loc) {
+static void createWsLoop(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ llvm::omp::Directive ompDirective,
+ const Fortran::parser::OmpClauseList &beginClauseList,
+ const Fortran::parser::OmpClauseList *endClauseList,
+ mlir::Location loc) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
   DataSharingProcessor dsp(converter, beginClauseList, eval);
   dsp.processStep1();
@@ -3107,9 +3135,13 @@ createWsLoop(Fortran::lower::AbstractConverter 
&converter,
   createBodyOfOp(wsLoopOp, converter, loc, eval,
   &beginClauseList, iv,
   /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(beginClauseList));
 }
 
 static void genOMP(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
@@ -3179,11 +3211,12 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 createWsLoop(converter, eval, ompDirective, loopOpClauseList, 
endClauseList,
  currentLocation);
   }
+  genOpenMPReduction(converter, loopOpClauseList);
 }
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   

[llvm-branch-commits] [flang] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-11 Thread via llvm-branch-commits

llvmbot wrote:




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

Author: Krzysztof Parzyszek (kparzysz)


Changes

Introduce `genNestedEvaluations` that will lower all evaluations nested in the 
given, accouting for a potential COLLAPSE directive.

Recursive lowering [2/5]

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP.cpp (+66-62) 


``diff
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 99690b03eca1d3..496b4ba27a0533 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -110,6 +110,32 @@ static void gatherFuncAndVarSyms(
   }
 }
 
+static Fortran::lower::pft::Evaluation *
+getEvalPastCollapse(Fortran::lower::pft::Evaluation &eval, int collapseValue) {
+  if (collapseValue == 0)
+return &eval;
+
+  Fortran::lower::pft::Evaluation *curEval = &eval.getFirstNestedEvaluation();
+  for (int i = 1; i < collapseValue; i++) {
+// The nested evaluations should be DoConstructs (i.e. they should form
+// a loop nest). Each DoConstruct is a tuple .
+assert(curEval->isA());
+curEval = &*std::next(curEval->getNestedEvaluations().begin());
+  }
+  return curEval;
+}
+
+static void genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ int collapseValue = 0) {
+  Fortran::lower::pft::Evaluation *curEval =
+  getEvalPastCollapse(eval, collapseValue);
+
+  for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations())
+converter.genEval(e);
+}
+
 
//===--===//
 // DataSharingProcessor
 
//===--===//
@@ -2944,7 +2970,7 @@ genOmpFlush(Fortran::lower::AbstractConverter &converter,
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) {
   std::visit(
@@ -3025,15 +3051,17 @@ createSimdLoop(Fortran::lower::AbstractConverter 
&converter,
   createBodyOfOp(simdLoopOp, converter, loc, eval,
 &loopOpClauseList, iv,
 /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(loopOpClauseList));
 }
 
-static void
-createWsLoop(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- llvm::omp::Directive ompDirective,
- const Fortran::parser::OmpClauseList &beginClauseList,
- const Fortran::parser::OmpClauseList *endClauseList,
- mlir::Location loc) {
+static void createWsLoop(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ llvm::omp::Directive ompDirective,
+ const Fortran::parser::OmpClauseList &beginClauseList,
+ const Fortran::parser::OmpClauseList *endClauseList,
+ mlir::Location loc) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
   DataSharingProcessor dsp(converter, beginClauseList, eval);
   dsp.processStep1();
@@ -3107,9 +3135,13 @@ createWsLoop(Fortran::lower::AbstractConverter 
&converter,
   createBodyOfOp(wsLoopOp, converter, loc, eval,
   &beginClauseList, iv,
   /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(beginClauseList));
 }
 
 static void genOMP(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
@@ -3179,11 +3211,12 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 createWsLoop(converter, eval, ompDirective, loopOpClauseList, 
endClauseList,
  currentLocation);
   }
+  genOpenMPReduction(converter, loopOpClauseList);
 }
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPBlockConstruct &blockConstruct) {
   const auto &beginBlockDirective =
@@ -3298,11 +3331,14 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   

[llvm-branch-commits] [flang] [Flang][OpenMP] Handle SECTION construct from within SECTIONS (PR #77759)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

Introduce `createSectionOp`, invoke it from the SECTIONS construct for each 
nested SECTION construct. This makes it unnecessary to embed 
OpenMPSectionConstruct inside of OpenMPSectionConstruct anymore.

Recursive lowering [3/5]

>From a503d366249dd2c549abbdb614ac4a84a7be3af1 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 9 Jan 2024 12:25:10 -0600
Subject: [PATCH] [Flang][OpenMP] Handle SECTION construct from within SECTIONS

Introduce `createSectionOp`, invoke it from the SECTIONS construct for
each nested SECTION construct. This makes it unnecessary to embed
OpenMPSectionConstruct inside of OpenMPSectionConstruct anymore.

Recursive lowering [3/5]
---
 flang/lib/Lower/OpenMP.cpp | 57 +-
 1 file changed, 26 insertions(+), 31 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 496b4ba27a0533..aa315d7ab280e2 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2379,6 +2379,18 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
   procBindKindAttr);
 }
 
+static mlir::omp::SectionOp
+genSectionOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ mlir::Location currentLocation,
+ const Fortran::parser::OmpClauseList §ionsClauseList) {
+  // Currently only private/firstprivate clause is handled, and
+  // all privatization is done within `omp.section` operations.
+  return genOpWithBody(converter, eval, currentLocation,
+ /*outerCombined=*/false,
+ §ionsClauseList);
+}
+
 static mlir::omp::SingleOp
 genSingleOp(Fortran::lower::AbstractConverter &converter,
 Fortran::lower::pft::Evaluation &eval,
@@ -3375,35 +3387,6 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   genNestedEvaluations(converter, eval);
 }
 
-static void
-genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
-   const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
-  mlir::Location currentLocation = converter.getCurrentLocation();
-  const Fortran::parser::OpenMPConstruct *parentOmpConstruct =
-  eval.parentConstruct->getIf();
-  assert(parentOmpConstruct &&
- "No enclosing parent OpenMPConstruct on SECTION construct");
-  const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct =
-  std::get_if(
-  &parentOmpConstruct->u);
-  assert(sectionsConstruct && "SECTION construct must have parent"
-  "SECTIONS construct");
-  const Fortran::parser::OmpClauseList §ionsClauseList =
-  std::get(
-  std::get(
-  sectionsConstruct->t)
-  .t);
-  // Currently only private/firstprivate clause is handled, and
-  // all privatization is done within `omp.section` operations.
-  symTable.pushScope();
-  genOpWithBody(converter, eval, currentLocation,
-  /*outerCombined=*/false,
-  §ionsClauseList);
-  genNestedEvaluations(converter, eval);
-  symTable.popScope();
-}
-
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
@@ -3447,7 +3430,18 @@ genOMP(Fortran::lower::AbstractConverter &converter,
/*reductions=*/nullptr, 
allocateOperands,
allocatorOperands, nowaitClauseOperand);
 
-  genNestedEvaluations(converter, eval);
+  const auto §ionBlocks =
+  std::get(sectionsConstruct.t);
+  auto &firOpBuilder = converter.getFirOpBuilder();
+  auto ip = firOpBuilder.saveInsertionPoint();
+  for (const auto &[nblock, neval] :
+   llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) {
+symTable.pushScope();
+genSectionOp(converter, neval, currentLocation, sectionsClauseList);
+genNestedEvaluations(converter, neval);
+symTable.popScope();
+firOpBuilder.restoreInsertionPoint(ip);
+  }
 }
 
 static void
@@ -3562,7 +3556,8 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 genOMP(converter, symTable, eval, sectionsConstruct);
   },
   [&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) 
{
-genOMP(converter, symTable, eval, sectionConstruct);
+// SECTION constructs are handled as a part of SECTIONS.
+llvm_unreachable("Unexpected standalone OMP SECTION");
   },
   [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
 genOMP(converter, symTable, eval, semanticsContext, loopConstruct);

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.l

[llvm-branch-commits] [flang] [Flang][OpenMP] Handle SECTION construct from within SECTIONS (PR #77759)

2024-01-11 Thread via llvm-branch-commits

llvmbot wrote:




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

Author: Krzysztof Parzyszek (kparzysz)


Changes

Introduce `createSectionOp`, invoke it from the SECTIONS construct for each 
nested SECTION construct. This makes it unnecessary to embed 
OpenMPSectionConstruct inside of OpenMPSectionConstruct anymore.

Recursive lowering [3/5]

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP.cpp (+26-31) 


``diff
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 496b4ba27a0533..aa315d7ab280e2 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2379,6 +2379,18 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
   procBindKindAttr);
 }
 
+static mlir::omp::SectionOp
+genSectionOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ mlir::Location currentLocation,
+ const Fortran::parser::OmpClauseList §ionsClauseList) {
+  // Currently only private/firstprivate clause is handled, and
+  // all privatization is done within `omp.section` operations.
+  return genOpWithBody(converter, eval, currentLocation,
+ /*outerCombined=*/false,
+ §ionsClauseList);
+}
+
 static mlir::omp::SingleOp
 genSingleOp(Fortran::lower::AbstractConverter &converter,
 Fortran::lower::pft::Evaluation &eval,
@@ -3375,35 +3387,6 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   genNestedEvaluations(converter, eval);
 }
 
-static void
-genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
-   const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
-  mlir::Location currentLocation = converter.getCurrentLocation();
-  const Fortran::parser::OpenMPConstruct *parentOmpConstruct =
-  eval.parentConstruct->getIf();
-  assert(parentOmpConstruct &&
- "No enclosing parent OpenMPConstruct on SECTION construct");
-  const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct =
-  std::get_if(
-  &parentOmpConstruct->u);
-  assert(sectionsConstruct && "SECTION construct must have parent"
-  "SECTIONS construct");
-  const Fortran::parser::OmpClauseList §ionsClauseList =
-  std::get(
-  std::get(
-  sectionsConstruct->t)
-  .t);
-  // Currently only private/firstprivate clause is handled, and
-  // all privatization is done within `omp.section` operations.
-  symTable.pushScope();
-  genOpWithBody(converter, eval, currentLocation,
-  /*outerCombined=*/false,
-  §ionsClauseList);
-  genNestedEvaluations(converter, eval);
-  symTable.popScope();
-}
-
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
@@ -3447,7 +3430,18 @@ genOMP(Fortran::lower::AbstractConverter &converter,
/*reductions=*/nullptr, 
allocateOperands,
allocatorOperands, nowaitClauseOperand);
 
-  genNestedEvaluations(converter, eval);
+  const auto §ionBlocks =
+  std::get(sectionsConstruct.t);
+  auto &firOpBuilder = converter.getFirOpBuilder();
+  auto ip = firOpBuilder.saveInsertionPoint();
+  for (const auto &[nblock, neval] :
+   llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) {
+symTable.pushScope();
+genSectionOp(converter, neval, currentLocation, sectionsClauseList);
+genNestedEvaluations(converter, neval);
+symTable.popScope();
+firOpBuilder.restoreInsertionPoint(ip);
+  }
 }
 
 static void
@@ -3562,7 +3556,8 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 genOMP(converter, symTable, eval, sectionsConstruct);
   },
   [&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) 
{
-genOMP(converter, symTable, eval, sectionConstruct);
+// SECTION constructs are handled as a part of SECTIONS.
+llvm_unreachable("Unexpected standalone OMP SECTION");
   },
   [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
 genOMP(converter, symTable, eval, semanticsContext, loopConstruct);

``




https://github.com/llvm/llvm-project/pull/77759
___
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] Push genEval closer to leaf lowering functions (PR #77760)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

Recursive lowering [4/5]

>From 0205beb4b6c6c828fb654866ed4e97c0485e00c4 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH] [Flang][OpenMP] Push genEval closer to leaf lowering
 functions

Recursive lowering [4/5]
---
 flang/lib/Lower/OpenMP.cpp | 233 +
 1 file changed, 135 insertions(+), 98 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index aa315d7ab280e2..c0f5619344c605 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2178,7 +2178,7 @@ 
createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
 template 
 static void createBodyOfOp(
 Op &op, Fortran::lower::AbstractConverter &converter, mlir::Location &loc,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 const Fortran::parser::OmpClauseList *clauses = nullptr,
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
@@ -2248,11 +2248,15 @@ static void createBodyOfOp(
 if (clauses)
   ClauseProcessor(converter, *clauses).processCopyin();
   }
+
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 static void genBodyOfTargetDataOp(
 Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval, mlir::omp::DataOp &dataOp,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
+mlir::omp::DataOp &dataOp,
 const llvm::SmallVector &useDeviceTypes,
 const llvm::SmallVector &useDeviceLocs,
 const llvm::SmallVector
@@ -2310,43 +2314,48 @@ static void genBodyOfTargetDataOp(
 
   // Set the insertion point after the marker.
   firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp());
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 template 
 static OpTy genOpWithBody(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool 
genNested,
   mlir::Location currentLocation, bool outerCombined,
   const Fortran::parser::OmpClauseList *clauseList,
   Args &&...args) {
   auto op = converter.getFirOpBuilder().create(
   currentLocation, std::forward(args)...);
-  createBodyOfOp(op, converter, currentLocation, eval, clauseList,
+  createBodyOfOp(op, converter, currentLocation, eval, genNested,
+   clauseList,
/*args=*/{}, outerCombined);
   return op;
 }
 
 static mlir::omp::MasterOp
 genMasterOp(Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location currentLocation) {
-  return genOpWithBody(converter, eval, currentLocation,
-/*outerCombined=*/false,
-/*clauseList=*/nullptr,
-/*resultTypes=*/mlir::TypeRange());
+  return genOpWithBody(
+  converter, eval, genNested, currentLocation,
+  /*outerCombined=*/false,
+  /*clauseList=*/nullptr,
+  /*resultTypes=*/mlir::TypeRange());
 }
 
 static mlir::omp::OrderedRegionOp
 genOrderedRegionOp(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation) {
   return genOpWithBody(
-  converter, eval, currentLocation, /*outerCombined=*/false,
+  converter, eval, genNested, currentLocation,
+  /*outerCombined=*/false,
   /*clauseList=*/nullptr, /*simd=*/false);
 }
 
 static mlir::omp::ParallelOp
 genParallelOp(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::Location currentLocation,
   const Fortran::parser::OmpClauseList &clauseList,
   bool outerCombined = false) {
@@ -2368,8 +2377,8 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
 
   return genOpWithBody(
-  converter, eval, currentLocation, outerCombined, &clauseList,
-  /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
+  converter, eval, genNested, currentLocation, outerCombined,
+  &clauseList, /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
   numThreadsClauseOperand, allocateOperands, allocatorOperands,
   reductionVars,
   reductionDeclSymbols.empty()
@@ -2381,19 +2390,20 @@ genParallelOp(Fortran::low

[llvm-branch-commits] [flang] [Flang][OpenMP] Push genEval closer to leaf lowering functions (PR #77760)

2024-01-11 Thread via llvm-branch-commits

llvmbot wrote:



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

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

Recursive lowering [4/5]

---

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP.cpp (+135-98) 


``diff
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index aa315d7ab280e2..c0f5619344c605 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2178,7 +2178,7 @@ 
createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
 template 
 static void createBodyOfOp(
 Op &op, Fortran::lower::AbstractConverter &converter, mlir::Location &loc,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 const Fortran::parser::OmpClauseList *clauses = nullptr,
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
@@ -2248,11 +2248,15 @@ static void createBodyOfOp(
 if (clauses)
   ClauseProcessor(converter, *clauses).processCopyin();
   }
+
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 static void genBodyOfTargetDataOp(
 Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval, mlir::omp::DataOp &dataOp,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
+mlir::omp::DataOp &dataOp,
 const llvm::SmallVector &useDeviceTypes,
 const llvm::SmallVector &useDeviceLocs,
 const llvm::SmallVector
@@ -2310,43 +2314,48 @@ static void genBodyOfTargetDataOp(
 
   // Set the insertion point after the marker.
   firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp());
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 template 
 static OpTy genOpWithBody(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool 
genNested,
   mlir::Location currentLocation, bool outerCombined,
   const Fortran::parser::OmpClauseList *clauseList,
   Args &&...args) {
   auto op = converter.getFirOpBuilder().create(
   currentLocation, std::forward(args)...);
-  createBodyOfOp(op, converter, currentLocation, eval, clauseList,
+  createBodyOfOp(op, converter, currentLocation, eval, genNested,
+   clauseList,
/*args=*/{}, outerCombined);
   return op;
 }
 
 static mlir::omp::MasterOp
 genMasterOp(Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location currentLocation) {
-  return genOpWithBody(converter, eval, currentLocation,
-/*outerCombined=*/false,
-/*clauseList=*/nullptr,
-/*resultTypes=*/mlir::TypeRange());
+  return genOpWithBody(
+  converter, eval, genNested, currentLocation,
+  /*outerCombined=*/false,
+  /*clauseList=*/nullptr,
+  /*resultTypes=*/mlir::TypeRange());
 }
 
 static mlir::omp::OrderedRegionOp
 genOrderedRegionOp(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation) {
   return genOpWithBody(
-  converter, eval, currentLocation, /*outerCombined=*/false,
+  converter, eval, genNested, currentLocation,
+  /*outerCombined=*/false,
   /*clauseList=*/nullptr, /*simd=*/false);
 }
 
 static mlir::omp::ParallelOp
 genParallelOp(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::Location currentLocation,
   const Fortran::parser::OmpClauseList &clauseList,
   bool outerCombined = false) {
@@ -2368,8 +2377,8 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
 
   return genOpWithBody(
-  converter, eval, currentLocation, outerCombined, &clauseList,
-  /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
+  converter, eval, genNested, currentLocation, outerCombined,
+  &clauseList, /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
   numThreadsClauseOperand, allocateOperands, allocatorOperands,
   reductionVars,
   reductionDeclSymbols.empty()
@@ -2381,19 +2390,20 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::SectionOp
 genSectionOp(Fortran::lower::AbstractC

[llvm-branch-commits] [flang] [Flang][OpenMP] Push genEval closer to leaf lowering functions (PR #77760)

2024-01-11 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff a503d366249dd2c549abbdb614ac4a84a7be3af1 
0205beb4b6c6c828fb654866ed4e97c0485e00c4 -- flang/lib/Lower/OpenMP.cpp
``





View the diff from clang-format here.


``diff
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index c0f5619344..6e93387fbf 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2336,11 +2336,11 @@ static mlir::omp::MasterOp
 genMasterOp(Fortran::lower::AbstractConverter &converter,
 Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location currentLocation) {
-  return genOpWithBody(
-  converter, eval, genNested, currentLocation,
-  /*outerCombined=*/false,
-  /*clauseList=*/nullptr,
-  /*resultTypes=*/mlir::TypeRange());
+  return genOpWithBody(converter, eval, genNested,
+currentLocation,
+/*outerCombined=*/false,
+/*clauseList=*/nullptr,
+/*resultTypes=*/mlir::TypeRange());
 }
 
 static mlir::omp::OrderedRegionOp
@@ -2377,8 +2377,8 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
 
   return genOpWithBody(
-  converter, eval, genNested, currentLocation, outerCombined,
-  &clauseList, /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
+  converter, eval, genNested, currentLocation, outerCombined, &clauseList,
+  /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
   numThreadsClauseOperand, allocateOperands, allocatorOperands,
   reductionVars,
   reductionDeclSymbols.empty()
@@ -2395,10 +2395,9 @@ genSectionOp(Fortran::lower::AbstractConverter 
&converter,
  const Fortran::parser::OmpClauseList §ionsClauseList) {
   // Currently only private/firstprivate clause is handled, and
   // all privatization is done within `omp.section` operations.
-  return genOpWithBody(converter, eval, genNested,
- currentLocation,
- /*outerCombined=*/false,
- §ionsClauseList);
+  return genOpWithBody(
+  converter, eval, genNested, currentLocation,
+  /*outerCombined=*/false, §ionsClauseList);
 }
 
 static mlir::omp::SingleOp
@@ -2508,9 +2507,8 @@ genDataOp(Fortran::lower::AbstractConverter &converter,
   auto dataOp = converter.getFirOpBuilder().create(
   currentLocation, ifClauseOperand, deviceOperand, devicePtrOperands,
   deviceAddrOperands, mapOperands);
-  genBodyOfTargetDataOp(converter, eval, genNested, dataOp,
-useDeviceTypes, useDeviceLocs, useDeviceSymbols,
-currentLocation);
+  genBodyOfTargetDataOp(converter, eval, genNested, dataOp, useDeviceTypes,
+useDeviceLocs, useDeviceSymbols, currentLocation);
   return dataOp;
 }
 
@@ -2820,8 +2818,8 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
   currentLocation, ifClauseOperand, deviceOperand, threadLimitOperand,
   nowaitAttr, mapOperands);
 
-  genBodyOfTargetOp(converter, eval, genNested, targetOp,
-mapSymTypes, mapSymLocs, mapSymbols, currentLocation);
+  genBodyOfTargetOp(converter, eval, genNested, targetOp, mapSymTypes,
+mapSymLocs, mapSymbols, currentLocation);
 
   return targetOp;
 }
@@ -2849,8 +2847,7 @@ genTeamsOp(Fortran::lower::AbstractConverter &converter,
   currentLocation, llvm::omp::Directive::OMPD_teams);
 
   return genOpWithBody(
-  converter, eval, genNested, currentLocation, outerCombined,
-  &clauseList,
+  converter, eval, genNested, currentLocation, outerCombined, &clauseList,
   /*num_teams_lower=*/nullptr, numTeamsClauseOperand, ifClauseOperand,
   threadLimitClauseOperand, allocateOperands, allocatorOperands,
   reductionVars,
@@ -2962,8 +2959,8 @@ genOmpSimpleStandalone(Fortran::lower::AbstractConverter 
&converter,
 firOpBuilder.create(currentLocation);
 break;
   case llvm::omp::Directive::OMPD_target_data:
-genDataOp(converter, eval, semanticsContext, genNested,
-  currentLocation, opClauseList);
+genDataOp(converter, eval, semanticsContext, genNested, currentLocation,
+  opClauseList);
 break;
   case llvm::omp::Directive::OMPD_target_enter_data:
 genEnterExitUpdateDataOp(

``




https://github.com/llvm/llvm-project/pull/77760
___
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] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

This brings `createBodyOfOp` to its final intended form. First, input 
privatization is performed, then the recursive lowering takes place, and 
finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an OpenMP 
region, and the fix is included in this patch.

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

Recursive lowering [5/5]

>From 923b4a996e92c448c289548eadca3fbaf7462aab Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH] [Flang][OpenMP] Restructure recursive lowering in
 `createBodyOfOp`

This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place,
and finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

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

Recursive lowering [5/5]
---
 flang/include/flang/Lower/OpenMP.h|   4 +-
 flang/lib/Lower/OpenMP.cpp| 133 --
 flang/test/Lower/OpenMP/FIR/sections.f90  |   6 +-
 .../OpenMP/infinite-loop-in-construct.f90 |  19 +++
 flang/test/Lower/OpenMP/sections.f90  |   6 +-
 5 files changed, 119 insertions(+), 49 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/infinite-loop-in-construct.f90

diff --git a/flang/include/flang/Lower/OpenMP.h 
b/flang/include/flang/Lower/OpenMP.h
index 6e772c43d8c46e..477d3e7d9da3a8 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -50,8 +50,8 @@ struct Variable;
 } // namespace pft
 
 // Generate the OpenMP terminator for Operation at Location.
-void genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
- mlir::Location);
+mlir::Operation *genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
+ mlir::Location);
 
 void genOpenMPConstruct(AbstractConverter &, Fortran::lower::SymMap &,
 semantics::SemanticsContext &, pft::Evaluation &,
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index c0f5619344c605..f795007f8504f3 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -383,7 +383,8 @@ void 
DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
 // construct
 mlir::OpBuilder::InsertPoint unstructuredSectionsIP =
 firOpBuilder.saveInsertionPoint();
-firOpBuilder.setInsertionPointToStart(&op->getRegion(0).back());
+mlir::Operation *lastOper = 
op->getRegion(0).back().getTerminator();
+firOpBuilder.setInsertionPoint(lastOper);
 lastPrivIP = firOpBuilder.saveInsertionPoint();
 firOpBuilder.restoreInsertionPoint(unstructuredSectionsIP);
   }
@@ -2133,15 +2134,6 @@ static mlir::Type 
getLoopVarType(Fortran::lower::AbstractConverter &converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
-static void resetBeforeTerminator(fir::FirOpBuilder &firOpBuilder,
-  mlir::Operation *storeOp,
-  mlir::Block &block) {
-  if (storeOp)
-firOpBuilder.setInsertionPointAfter(storeOp);
-  else
-firOpBuilder.setInsertionPointToStart(&block);
-}
-
 static mlir::Operation *
 createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   mlir::Location loc, mlir::Value indexVal,
@@ -2183,11 +2175,43 @@ static void createBodyOfOp(
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+  auto insertMarker = [](fir::FirOpBuilder &builder) {
+mlir::Value undef = builder.create(builder.getUnknownLoc(),
+ builder.getIndexType());
+return undef.getDefiningOp();
+  };
+
+  // Find the block where the OMP terminator should go. In simple cases
+  // it is the single block in the operation's region. When the region
+  // is more complicated, especially with unstructured control flow, there
+  // may be multiple blocks, and some of them may have non-OMP terminators
+  // resulting from lowering of the code contained within the operation.
+  // By OpenMP rules, there should be a single exit point from the region:
+  // here exit means transfering control to the code following the operation.
+  // STOP statement is allowed and does not count as exit for the purpose of
+  // inserting terminators.
+  auto findExitBlock = [&](mlir::Region ®ion) -> mlir::Block * {
+auto isTerminated = [](mlir::Block &block) -> bool {
+  if (block.empty())
+

[llvm-branch-commits] [flang] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-11 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-openmp

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

Author: Krzysztof Parzyszek (kparzysz)


Changes

This brings `createBodyOfOp` to its final intended form. First, input 
privatization is performed, then the recursive lowering takes place, and 
finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an OpenMP 
region, and the fix is included in this patch.

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

Recursive lowering [5/5]

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


5 Files Affected:

- (modified) flang/include/flang/Lower/OpenMP.h (+2-2) 
- (modified) flang/lib/Lower/OpenMP.cpp (+92-41) 
- (modified) flang/test/Lower/OpenMP/FIR/sections.f90 (+3-3) 
- (added) flang/test/Lower/OpenMP/infinite-loop-in-construct.f90 (+19) 
- (modified) flang/test/Lower/OpenMP/sections.f90 (+3-3) 


``diff
diff --git a/flang/include/flang/Lower/OpenMP.h 
b/flang/include/flang/Lower/OpenMP.h
index 6e772c43d8c46e..477d3e7d9da3a8 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -50,8 +50,8 @@ struct Variable;
 } // namespace pft
 
 // Generate the OpenMP terminator for Operation at Location.
-void genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
- mlir::Location);
+mlir::Operation *genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
+ mlir::Location);
 
 void genOpenMPConstruct(AbstractConverter &, Fortran::lower::SymMap &,
 semantics::SemanticsContext &, pft::Evaluation &,
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index c0f5619344c605..f795007f8504f3 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -383,7 +383,8 @@ void 
DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
 // construct
 mlir::OpBuilder::InsertPoint unstructuredSectionsIP =
 firOpBuilder.saveInsertionPoint();
-firOpBuilder.setInsertionPointToStart(&op->getRegion(0).back());
+mlir::Operation *lastOper = 
op->getRegion(0).back().getTerminator();
+firOpBuilder.setInsertionPoint(lastOper);
 lastPrivIP = firOpBuilder.saveInsertionPoint();
 firOpBuilder.restoreInsertionPoint(unstructuredSectionsIP);
   }
@@ -2133,15 +2134,6 @@ static mlir::Type 
getLoopVarType(Fortran::lower::AbstractConverter &converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
-static void resetBeforeTerminator(fir::FirOpBuilder &firOpBuilder,
-  mlir::Operation *storeOp,
-  mlir::Block &block) {
-  if (storeOp)
-firOpBuilder.setInsertionPointAfter(storeOp);
-  else
-firOpBuilder.setInsertionPointToStart(&block);
-}
-
 static mlir::Operation *
 createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   mlir::Location loc, mlir::Value indexVal,
@@ -2183,11 +2175,43 @@ static void createBodyOfOp(
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+  auto insertMarker = [](fir::FirOpBuilder &builder) {
+mlir::Value undef = builder.create(builder.getUnknownLoc(),
+ builder.getIndexType());
+return undef.getDefiningOp();
+  };
+
+  // Find the block where the OMP terminator should go. In simple cases
+  // it is the single block in the operation's region. When the region
+  // is more complicated, especially with unstructured control flow, there
+  // may be multiple blocks, and some of them may have non-OMP terminators
+  // resulting from lowering of the code contained within the operation.
+  // By OpenMP rules, there should be a single exit point from the region:
+  // here exit means transfering control to the code following the operation.
+  // STOP statement is allowed and does not count as exit for the purpose of
+  // inserting terminators.
+  auto findExitBlock = [&](mlir::Region ®ion) -> mlir::Block * {
+auto isTerminated = [](mlir::Block &block) -> bool {
+  if (block.empty())
+return false;
+  return block.back().hasTrait();
+};
+
+mlir::Block *exit = nullptr;
+for (auto &block : region) {
+  if (!isTerminated(block)) {
+assert(exit == nullptr && "Multiple exit block in OpenMP region");
+exit = █
+  }
+}
+return exit;
+  };
+
   // If an argument for the region is provided then create the block with that
   // argument. Also update the symbol's address with the mlir argument value.
   // e.g. For loops the argument is the induction variable. And all further
   // uses of the induction variable should use this mlir va

[llvm-branch-commits] [flang] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 1b5524ae8874e389d373a55417919afa56beb2b5 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH] [Flang][OpenMP] Restructure recursive lowering in
 `createBodyOfOp`

This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place,
and finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

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

Recursive lowering [5/5]
---
 flang/include/flang/Lower/OpenMP.h|   4 +-
 flang/lib/Lower/OpenMP.cpp| 133 --
 flang/test/Lower/OpenMP/FIR/sections.f90  |   6 +-
 .../OpenMP/infinite-loop-in-construct.f90 |  19 +++
 flang/test/Lower/OpenMP/sections.f90  |   6 +-
 5 files changed, 119 insertions(+), 49 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/infinite-loop-in-construct.f90

diff --git a/flang/include/flang/Lower/OpenMP.h 
b/flang/include/flang/Lower/OpenMP.h
index 6e772c43d8c46e..477d3e7d9da3a8 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -50,8 +50,8 @@ struct Variable;
 } // namespace pft
 
 // Generate the OpenMP terminator for Operation at Location.
-void genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
- mlir::Location);
+mlir::Operation *genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
+ mlir::Location);
 
 void genOpenMPConstruct(AbstractConverter &, Fortran::lower::SymMap &,
 semantics::SemanticsContext &, pft::Evaluation &,
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 6e93387fbff7cc..bb92fdce4ac56e 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -383,7 +383,8 @@ void 
DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
 // construct
 mlir::OpBuilder::InsertPoint unstructuredSectionsIP =
 firOpBuilder.saveInsertionPoint();
-firOpBuilder.setInsertionPointToStart(&op->getRegion(0).back());
+mlir::Operation *lastOper = 
op->getRegion(0).back().getTerminator();
+firOpBuilder.setInsertionPoint(lastOper);
 lastPrivIP = firOpBuilder.saveInsertionPoint();
 firOpBuilder.restoreInsertionPoint(unstructuredSectionsIP);
   }
@@ -2133,15 +2134,6 @@ static mlir::Type 
getLoopVarType(Fortran::lower::AbstractConverter &converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
-static void resetBeforeTerminator(fir::FirOpBuilder &firOpBuilder,
-  mlir::Operation *storeOp,
-  mlir::Block &block) {
-  if (storeOp)
-firOpBuilder.setInsertionPointAfter(storeOp);
-  else
-firOpBuilder.setInsertionPointToStart(&block);
-}
-
 static mlir::Operation *
 createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   mlir::Location loc, mlir::Value indexVal,
@@ -2183,11 +2175,43 @@ static void createBodyOfOp(
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+  auto insertMarker = [](fir::FirOpBuilder &builder) {
+mlir::Value undef = builder.create(builder.getUnknownLoc(),
+ builder.getIndexType());
+return undef.getDefiningOp();
+  };
+
+  // Find the block where the OMP terminator should go. In simple cases
+  // it is the single block in the operation's region. When the region
+  // is more complicated, especially with unstructured control flow, there
+  // may be multiple blocks, and some of them may have non-OMP terminators
+  // resulting from lowering of the code contained within the operation.
+  // By OpenMP rules, there should be a single exit point from the region:
+  // here exit means transfering control to the code following the operation.
+  // STOP statement is allowed and does not count as exit for the purpose of
+  // inserting terminators.
+  auto findExitBlock = [&](mlir::Region ®ion) -> mlir::Block * {
+auto isTerminated = [](mlir::Block &block) -> bool {
+  if (block.empty())
+return false;
+  return block.back().hasTrait();
+};
+
+mlir::Block *exit = nullptr;
+for (auto &block : region) {
+  if (!isTerminated(block)) {
+assert(exit == nullptr && "Multiple exit block in OpenMP region");
+exit = █
+  }
+}
+return exit;
+  };
+
   // If an argument for the region is provided then create the block with that
   // argument. Also update

[llvm-branch-commits] [flang] [Flang][OpenMP] Handle SECTION construct from within SECTIONS (PR #77759)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 67ea0e5df3c4919030c963c969d8f9cda0b5996b Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 9 Jan 2024 12:25:10 -0600
Subject: [PATCH] [Flang][OpenMP] Handle SECTION construct from within SECTIONS

Introduce `createSectionOp`, invoke it from the SECTIONS construct for
each nested SECTION construct. This makes it unnecessary to embed
OpenMPSectionConstruct inside of OpenMPSectionConstruct anymore.

Recursive lowering [3/5]
---
 flang/lib/Lower/OpenMP.cpp | 57 +-
 1 file changed, 26 insertions(+), 31 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 496b4ba27a0533..aa315d7ab280e2 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2379,6 +2379,18 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
   procBindKindAttr);
 }
 
+static mlir::omp::SectionOp
+genSectionOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ mlir::Location currentLocation,
+ const Fortran::parser::OmpClauseList §ionsClauseList) {
+  // Currently only private/firstprivate clause is handled, and
+  // all privatization is done within `omp.section` operations.
+  return genOpWithBody(converter, eval, currentLocation,
+ /*outerCombined=*/false,
+ §ionsClauseList);
+}
+
 static mlir::omp::SingleOp
 genSingleOp(Fortran::lower::AbstractConverter &converter,
 Fortran::lower::pft::Evaluation &eval,
@@ -3375,35 +3387,6 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   genNestedEvaluations(converter, eval);
 }
 
-static void
-genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
-   const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
-  mlir::Location currentLocation = converter.getCurrentLocation();
-  const Fortran::parser::OpenMPConstruct *parentOmpConstruct =
-  eval.parentConstruct->getIf();
-  assert(parentOmpConstruct &&
- "No enclosing parent OpenMPConstruct on SECTION construct");
-  const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct =
-  std::get_if(
-  &parentOmpConstruct->u);
-  assert(sectionsConstruct && "SECTION construct must have parent"
-  "SECTIONS construct");
-  const Fortran::parser::OmpClauseList §ionsClauseList =
-  std::get(
-  std::get(
-  sectionsConstruct->t)
-  .t);
-  // Currently only private/firstprivate clause is handled, and
-  // all privatization is done within `omp.section` operations.
-  symTable.pushScope();
-  genOpWithBody(converter, eval, currentLocation,
-  /*outerCombined=*/false,
-  §ionsClauseList);
-  genNestedEvaluations(converter, eval);
-  symTable.popScope();
-}
-
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
@@ -3447,7 +3430,18 @@ genOMP(Fortran::lower::AbstractConverter &converter,
/*reductions=*/nullptr, 
allocateOperands,
allocatorOperands, nowaitClauseOperand);
 
-  genNestedEvaluations(converter, eval);
+  const auto §ionBlocks =
+  std::get(sectionsConstruct.t);
+  auto &firOpBuilder = converter.getFirOpBuilder();
+  auto ip = firOpBuilder.saveInsertionPoint();
+  for (const auto &[nblock, neval] :
+   llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) {
+symTable.pushScope();
+genSectionOp(converter, neval, currentLocation, sectionsClauseList);
+genNestedEvaluations(converter, neval);
+symTable.popScope();
+firOpBuilder.restoreInsertionPoint(ip);
+  }
 }
 
 static void
@@ -3562,7 +3556,8 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 genOMP(converter, symTable, eval, sectionsConstruct);
   },
   [&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) 
{
-genOMP(converter, symTable, eval, sectionConstruct);
+// SECTION constructs are handled as a part of SECTIONS.
+llvm_unreachable("Unexpected standalone OMP SECTION");
   },
   [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
 genOMP(converter, symTable, eval, semanticsContext, loopConstruct);

___
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] Push genEval closer to leaf lowering functions (PR #77760)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 883afd9e93c34ffb05fb54cab6cf7ca0cb3379b6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH] [Flang][OpenMP] Push genEval closer to leaf lowering
 functions

Recursive lowering [4/5]
---
 flang/lib/Lower/OpenMP.cpp | 226 +
 1 file changed, 130 insertions(+), 96 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index aa315d7ab280e2..6e93387fbff7cc 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2178,7 +2178,7 @@ 
createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
 template 
 static void createBodyOfOp(
 Op &op, Fortran::lower::AbstractConverter &converter, mlir::Location &loc,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 const Fortran::parser::OmpClauseList *clauses = nullptr,
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
@@ -2248,11 +2248,15 @@ static void createBodyOfOp(
 if (clauses)
   ClauseProcessor(converter, *clauses).processCopyin();
   }
+
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 static void genBodyOfTargetDataOp(
 Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval, mlir::omp::DataOp &dataOp,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
+mlir::omp::DataOp &dataOp,
 const llvm::SmallVector &useDeviceTypes,
 const llvm::SmallVector &useDeviceLocs,
 const llvm::SmallVector
@@ -2310,26 +2314,30 @@ static void genBodyOfTargetDataOp(
 
   // Set the insertion point after the marker.
   firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp());
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 template 
 static OpTy genOpWithBody(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool 
genNested,
   mlir::Location currentLocation, bool outerCombined,
   const Fortran::parser::OmpClauseList *clauseList,
   Args &&...args) {
   auto op = converter.getFirOpBuilder().create(
   currentLocation, std::forward(args)...);
-  createBodyOfOp(op, converter, currentLocation, eval, clauseList,
+  createBodyOfOp(op, converter, currentLocation, eval, genNested,
+   clauseList,
/*args=*/{}, outerCombined);
   return op;
 }
 
 static mlir::omp::MasterOp
 genMasterOp(Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location currentLocation) {
-  return genOpWithBody(converter, eval, currentLocation,
+  return genOpWithBody(converter, eval, genNested,
+currentLocation,
 /*outerCombined=*/false,
 /*clauseList=*/nullptr,
 /*resultTypes=*/mlir::TypeRange());
@@ -2337,16 +2345,17 @@ genMasterOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::OrderedRegionOp
 genOrderedRegionOp(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation) {
   return genOpWithBody(
-  converter, eval, currentLocation, /*outerCombined=*/false,
+  converter, eval, genNested, currentLocation,
+  /*outerCombined=*/false,
   /*clauseList=*/nullptr, /*simd=*/false);
 }
 
 static mlir::omp::ParallelOp
 genParallelOp(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::Location currentLocation,
   const Fortran::parser::OmpClauseList &clauseList,
   bool outerCombined = false) {
@@ -2368,7 +2377,7 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
 
   return genOpWithBody(
-  converter, eval, currentLocation, outerCombined, &clauseList,
+  converter, eval, genNested, currentLocation, outerCombined, &clauseList,
   /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
   numThreadsClauseOperand, allocateOperands, allocatorOperands,
   reductionVars,
@@ -2381,19 +2390,19 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::SectionOp
 genSectionOp(Fortran::lower::AbstractConver

[llvm-branch-commits] [flang] [Flang][OpenMP] Handle SECTION construct from within SECTIONS (PR #77759)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 67ea0e5df3c4919030c963c969d8f9cda0b5996b Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 9 Jan 2024 12:25:10 -0600
Subject: [PATCH] [Flang][OpenMP] Handle SECTION construct from within SECTIONS

Introduce `createSectionOp`, invoke it from the SECTIONS construct for
each nested SECTION construct. This makes it unnecessary to embed
OpenMPSectionConstruct inside of OpenMPSectionConstruct anymore.

Recursive lowering [3/5]
---
 flang/lib/Lower/OpenMP.cpp | 57 +-
 1 file changed, 26 insertions(+), 31 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 496b4ba27a0533..aa315d7ab280e2 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2379,6 +2379,18 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
   procBindKindAttr);
 }
 
+static mlir::omp::SectionOp
+genSectionOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ mlir::Location currentLocation,
+ const Fortran::parser::OmpClauseList §ionsClauseList) {
+  // Currently only private/firstprivate clause is handled, and
+  // all privatization is done within `omp.section` operations.
+  return genOpWithBody(converter, eval, currentLocation,
+ /*outerCombined=*/false,
+ §ionsClauseList);
+}
+
 static mlir::omp::SingleOp
 genSingleOp(Fortran::lower::AbstractConverter &converter,
 Fortran::lower::pft::Evaluation &eval,
@@ -3375,35 +3387,6 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   genNestedEvaluations(converter, eval);
 }
 
-static void
-genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
-   const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
-  mlir::Location currentLocation = converter.getCurrentLocation();
-  const Fortran::parser::OpenMPConstruct *parentOmpConstruct =
-  eval.parentConstruct->getIf();
-  assert(parentOmpConstruct &&
- "No enclosing parent OpenMPConstruct on SECTION construct");
-  const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct =
-  std::get_if(
-  &parentOmpConstruct->u);
-  assert(sectionsConstruct && "SECTION construct must have parent"
-  "SECTIONS construct");
-  const Fortran::parser::OmpClauseList §ionsClauseList =
-  std::get(
-  std::get(
-  sectionsConstruct->t)
-  .t);
-  // Currently only private/firstprivate clause is handled, and
-  // all privatization is done within `omp.section` operations.
-  symTable.pushScope();
-  genOpWithBody(converter, eval, currentLocation,
-  /*outerCombined=*/false,
-  §ionsClauseList);
-  genNestedEvaluations(converter, eval);
-  symTable.popScope();
-}
-
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
@@ -3447,7 +3430,18 @@ genOMP(Fortran::lower::AbstractConverter &converter,
/*reductions=*/nullptr, 
allocateOperands,
allocatorOperands, nowaitClauseOperand);
 
-  genNestedEvaluations(converter, eval);
+  const auto §ionBlocks =
+  std::get(sectionsConstruct.t);
+  auto &firOpBuilder = converter.getFirOpBuilder();
+  auto ip = firOpBuilder.saveInsertionPoint();
+  for (const auto &[nblock, neval] :
+   llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) {
+symTable.pushScope();
+genSectionOp(converter, neval, currentLocation, sectionsClauseList);
+genNestedEvaluations(converter, neval);
+symTable.popScope();
+firOpBuilder.restoreInsertionPoint(ip);
+  }
 }
 
 static void
@@ -3562,7 +3556,8 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 genOMP(converter, symTable, eval, sectionsConstruct);
   },
   [&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) 
{
-genOMP(converter, symTable, eval, sectionConstruct);
+// SECTION constructs are handled as a part of SECTIONS.
+llvm_unreachable("Unexpected standalone OMP SECTION");
   },
   [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
 genOMP(converter, symTable, eval, semanticsContext, loopConstruct);

___
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] Push genEval closer to leaf lowering functions (PR #77760)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 883afd9e93c34ffb05fb54cab6cf7ca0cb3379b6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH] [Flang][OpenMP] Push genEval closer to leaf lowering
 functions

Recursive lowering [4/5]
---
 flang/lib/Lower/OpenMP.cpp | 226 +
 1 file changed, 130 insertions(+), 96 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index aa315d7ab280e2..6e93387fbff7cc 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2178,7 +2178,7 @@ 
createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
 template 
 static void createBodyOfOp(
 Op &op, Fortran::lower::AbstractConverter &converter, mlir::Location &loc,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 const Fortran::parser::OmpClauseList *clauses = nullptr,
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
@@ -2248,11 +2248,15 @@ static void createBodyOfOp(
 if (clauses)
   ClauseProcessor(converter, *clauses).processCopyin();
   }
+
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 static void genBodyOfTargetDataOp(
 Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval, mlir::omp::DataOp &dataOp,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
+mlir::omp::DataOp &dataOp,
 const llvm::SmallVector &useDeviceTypes,
 const llvm::SmallVector &useDeviceLocs,
 const llvm::SmallVector
@@ -2310,26 +2314,30 @@ static void genBodyOfTargetDataOp(
 
   // Set the insertion point after the marker.
   firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp());
+  if (genNested)
+genNestedEvaluations(converter, eval);
 }
 
 template 
 static OpTy genOpWithBody(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool 
genNested,
   mlir::Location currentLocation, bool outerCombined,
   const Fortran::parser::OmpClauseList *clauseList,
   Args &&...args) {
   auto op = converter.getFirOpBuilder().create(
   currentLocation, std::forward(args)...);
-  createBodyOfOp(op, converter, currentLocation, eval, clauseList,
+  createBodyOfOp(op, converter, currentLocation, eval, genNested,
+   clauseList,
/*args=*/{}, outerCombined);
   return op;
 }
 
 static mlir::omp::MasterOp
 genMasterOp(Fortran::lower::AbstractConverter &converter,
-Fortran::lower::pft::Evaluation &eval,
+Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location currentLocation) {
-  return genOpWithBody(converter, eval, currentLocation,
+  return genOpWithBody(converter, eval, genNested,
+currentLocation,
 /*outerCombined=*/false,
 /*clauseList=*/nullptr,
 /*resultTypes=*/mlir::TypeRange());
@@ -2337,16 +2345,17 @@ genMasterOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::OrderedRegionOp
 genOrderedRegionOp(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation) {
   return genOpWithBody(
-  converter, eval, currentLocation, /*outerCombined=*/false,
+  converter, eval, genNested, currentLocation,
+  /*outerCombined=*/false,
   /*clauseList=*/nullptr, /*simd=*/false);
 }
 
 static mlir::omp::ParallelOp
 genParallelOp(Fortran::lower::AbstractConverter &converter,
-  Fortran::lower::pft::Evaluation &eval,
+  Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::Location currentLocation,
   const Fortran::parser::OmpClauseList &clauseList,
   bool outerCombined = false) {
@@ -2368,7 +2377,7 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
 
   return genOpWithBody(
-  converter, eval, currentLocation, outerCombined, &clauseList,
+  converter, eval, genNested, currentLocation, outerCombined, &clauseList,
   /*resultTypes=*/mlir::TypeRange(), ifClauseOperand,
   numThreadsClauseOperand, allocateOperands, allocatorOperands,
   reductionVars,
@@ -2381,19 +2390,19 @@ genParallelOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::SectionOp
 genSectionOp(Fortran::lower::AbstractConver

[llvm-branch-commits] [flang] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 1b5524ae8874e389d373a55417919afa56beb2b5 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH] [Flang][OpenMP] Restructure recursive lowering in
 `createBodyOfOp`

This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place,
and finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

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

Recursive lowering [5/5]
---
 flang/include/flang/Lower/OpenMP.h|   4 +-
 flang/lib/Lower/OpenMP.cpp| 133 --
 flang/test/Lower/OpenMP/FIR/sections.f90  |   6 +-
 .../OpenMP/infinite-loop-in-construct.f90 |  19 +++
 flang/test/Lower/OpenMP/sections.f90  |   6 +-
 5 files changed, 119 insertions(+), 49 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/infinite-loop-in-construct.f90

diff --git a/flang/include/flang/Lower/OpenMP.h 
b/flang/include/flang/Lower/OpenMP.h
index 6e772c43d8c46e..477d3e7d9da3a8 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -50,8 +50,8 @@ struct Variable;
 } // namespace pft
 
 // Generate the OpenMP terminator for Operation at Location.
-void genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
- mlir::Location);
+mlir::Operation *genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
+ mlir::Location);
 
 void genOpenMPConstruct(AbstractConverter &, Fortran::lower::SymMap &,
 semantics::SemanticsContext &, pft::Evaluation &,
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 6e93387fbff7cc..bb92fdce4ac56e 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -383,7 +383,8 @@ void 
DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
 // construct
 mlir::OpBuilder::InsertPoint unstructuredSectionsIP =
 firOpBuilder.saveInsertionPoint();
-firOpBuilder.setInsertionPointToStart(&op->getRegion(0).back());
+mlir::Operation *lastOper = 
op->getRegion(0).back().getTerminator();
+firOpBuilder.setInsertionPoint(lastOper);
 lastPrivIP = firOpBuilder.saveInsertionPoint();
 firOpBuilder.restoreInsertionPoint(unstructuredSectionsIP);
   }
@@ -2133,15 +2134,6 @@ static mlir::Type 
getLoopVarType(Fortran::lower::AbstractConverter &converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
-static void resetBeforeTerminator(fir::FirOpBuilder &firOpBuilder,
-  mlir::Operation *storeOp,
-  mlir::Block &block) {
-  if (storeOp)
-firOpBuilder.setInsertionPointAfter(storeOp);
-  else
-firOpBuilder.setInsertionPointToStart(&block);
-}
-
 static mlir::Operation *
 createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   mlir::Location loc, mlir::Value indexVal,
@@ -2183,11 +2175,43 @@ static void createBodyOfOp(
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+  auto insertMarker = [](fir::FirOpBuilder &builder) {
+mlir::Value undef = builder.create(builder.getUnknownLoc(),
+ builder.getIndexType());
+return undef.getDefiningOp();
+  };
+
+  // Find the block where the OMP terminator should go. In simple cases
+  // it is the single block in the operation's region. When the region
+  // is more complicated, especially with unstructured control flow, there
+  // may be multiple blocks, and some of them may have non-OMP terminators
+  // resulting from lowering of the code contained within the operation.
+  // By OpenMP rules, there should be a single exit point from the region:
+  // here exit means transfering control to the code following the operation.
+  // STOP statement is allowed and does not count as exit for the purpose of
+  // inserting terminators.
+  auto findExitBlock = [&](mlir::Region ®ion) -> mlir::Block * {
+auto isTerminated = [](mlir::Block &block) -> bool {
+  if (block.empty())
+return false;
+  return block.back().hasTrait();
+};
+
+mlir::Block *exit = nullptr;
+for (auto &block : region) {
+  if (!isTerminated(block)) {
+assert(exit == nullptr && "Multiple exit block in OpenMP region");
+exit = █
+  }
+}
+return exit;
+  };
+
   // If an argument for the region is provided then create the block with that
   // argument. Also update

[llvm-branch-commits] [flang] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 841ae5f68c36628bf209b220595fcb6e81bad18d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 9 Jan 2024 12:22:06 -0600
Subject: [PATCH] [Flang][OpenMP] Push genEval calls to individual operations,
 NFC

Introduce `genNestedEvaluations` that will lower all evaluations
nested in the given, accouting for a potential COLLAPSE directive.

Recursive lowering [2/5]
---
 flang/lib/Lower/OpenMP.cpp | 115 +++--
 1 file changed, 60 insertions(+), 55 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 350cb29121da93..496b4ba27a0533 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -110,6 +110,32 @@ static void gatherFuncAndVarSyms(
   }
 }
 
+static Fortran::lower::pft::Evaluation *
+getEvalPastCollapse(Fortran::lower::pft::Evaluation &eval, int collapseValue) {
+  if (collapseValue == 0)
+return &eval;
+
+  Fortran::lower::pft::Evaluation *curEval = &eval.getFirstNestedEvaluation();
+  for (int i = 1; i < collapseValue; i++) {
+// The nested evaluations should be DoConstructs (i.e. they should form
+// a loop nest). Each DoConstruct is a tuple .
+assert(curEval->isA());
+curEval = &*std::next(curEval->getNestedEvaluations().begin());
+  }
+  return curEval;
+}
+
+static void genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ int collapseValue = 0) {
+  Fortran::lower::pft::Evaluation *curEval =
+  getEvalPastCollapse(eval, collapseValue);
+
+  for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations())
+converter.genEval(e);
+}
+
 
//===--===//
 // DataSharingProcessor
 
//===--===//
@@ -2944,7 +2970,7 @@ genOmpFlush(Fortran::lower::AbstractConverter &converter,
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) {
   std::visit(
@@ -3025,6 +3051,9 @@ createSimdLoop(Fortran::lower::AbstractConverter 
&converter,
   createBodyOfOp(simdLoopOp, converter, loc, eval,
 &loopOpClauseList, iv,
 /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(loopOpClauseList));
 }
 
 static void createWsLoop(Fortran::lower::AbstractConverter &converter,
@@ -3106,9 +3135,13 @@ static void 
createWsLoop(Fortran::lower::AbstractConverter &converter,
   createBodyOfOp(wsLoopOp, converter, loc, eval,
   &beginClauseList, iv,
   /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(beginClauseList));
 }
 
 static void genOMP(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
@@ -3178,11 +3211,12 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 createWsLoop(converter, eval, ompDirective, loopOpClauseList, 
endClauseList,
  currentLocation);
   }
+  genOpenMPReduction(converter, loopOpClauseList);
 }
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPBlockConstruct &blockConstruct) {
   const auto &beginBlockDirective =
@@ -3297,11 +3331,14 @@ genOMP(Fortran::lower::AbstractConverter &converter,
 break;
   }
   }
+
+  genNestedEvaluations(converter, eval);
+  genOpenMPReduction(converter, beginClauseList);
 }
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
const Fortran::parser::OpenMPCriticalConstruct &criticalConstruct) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
   mlir::Location currentLocation = converter.getCurrentLocation();
@@ -3335,11 +3372,12 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   }();
   createBodyOfOp(criticalOp, converter, cur

[llvm-branch-commits] [flang] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-11 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 841ae5f68c36628bf209b220595fcb6e81bad18d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 9 Jan 2024 12:22:06 -0600
Subject: [PATCH] [Flang][OpenMP] Push genEval calls to individual operations,
 NFC

Introduce `genNestedEvaluations` that will lower all evaluations
nested in the given, accouting for a potential COLLAPSE directive.

Recursive lowering [2/5]
---
 flang/lib/Lower/OpenMP.cpp | 115 +++--
 1 file changed, 60 insertions(+), 55 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 350cb29121da93..496b4ba27a0533 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -110,6 +110,32 @@ static void gatherFuncAndVarSyms(
   }
 }
 
+static Fortran::lower::pft::Evaluation *
+getEvalPastCollapse(Fortran::lower::pft::Evaluation &eval, int collapseValue) {
+  if (collapseValue == 0)
+return &eval;
+
+  Fortran::lower::pft::Evaluation *curEval = &eval.getFirstNestedEvaluation();
+  for (int i = 1; i < collapseValue; i++) {
+// The nested evaluations should be DoConstructs (i.e. they should form
+// a loop nest). Each DoConstruct is a tuple .
+assert(curEval->isA());
+curEval = &*std::next(curEval->getNestedEvaluations().begin());
+  }
+  return curEval;
+}
+
+static void genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ int collapseValue = 0) {
+  Fortran::lower::pft::Evaluation *curEval =
+  getEvalPastCollapse(eval, collapseValue);
+
+  for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations())
+converter.genEval(e);
+}
+
 
//===--===//
 // DataSharingProcessor
 
//===--===//
@@ -2944,7 +2970,7 @@ genOmpFlush(Fortran::lower::AbstractConverter &converter,
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) {
   std::visit(
@@ -3025,6 +3051,9 @@ createSimdLoop(Fortran::lower::AbstractConverter 
&converter,
   createBodyOfOp(simdLoopOp, converter, loc, eval,
 &loopOpClauseList, iv,
 /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(loopOpClauseList));
 }
 
 static void createWsLoop(Fortran::lower::AbstractConverter &converter,
@@ -3106,9 +3135,13 @@ static void 
createWsLoop(Fortran::lower::AbstractConverter &converter,
   createBodyOfOp(wsLoopOp, converter, loc, eval,
   &beginClauseList, iv,
   /*outer=*/false, &dsp);
+
+  genNestedEvaluations(converter, eval,
+   Fortran::lower::getCollapseValue(beginClauseList));
 }
 
 static void genOMP(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
@@ -3178,11 +3211,12 @@ static void genOMP(Fortran::lower::AbstractConverter 
&converter,
 createWsLoop(converter, eval, ompDirective, loopOpClauseList, 
endClauseList,
  currentLocation);
   }
+  genOpenMPReduction(converter, loopOpClauseList);
 }
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
Fortran::semantics::SemanticsContext &semanticsContext,
const Fortran::parser::OpenMPBlockConstruct &blockConstruct) {
   const auto &beginBlockDirective =
@@ -3297,11 +3331,14 @@ genOMP(Fortran::lower::AbstractConverter &converter,
 break;
   }
   }
+
+  genNestedEvaluations(converter, eval);
+  genOpenMPReduction(converter, beginClauseList);
 }
 
 static void
 genOMP(Fortran::lower::AbstractConverter &converter,
-   Fortran::lower::pft::Evaluation &eval,
+   Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
const Fortran::parser::OpenMPCriticalConstruct &criticalConstruct) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
   mlir::Location currentLocation = converter.getCurrentLocation();
@@ -3335,11 +3372,12 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   }();
   createBodyOfOp(criticalOp, converter, cur

[llvm-branch-commits] [clang-tools-extra] [clang] [compiler-rt] [llvm] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 


https://github.com/avillega updated 
https://github.com/llvm/llvm-project/pull/77702

>From a3220262a3236115d55235e4cc34acc8202268f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Wed, 10 Jan 2024 23:56:45 +
Subject: [PATCH 1/2] Fix typo.

Created using spr 1.3.5
---
 .../test/asan/TestCases/use-after-free-symbolizer-markup.cpp| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 548ae57b5c3797..323de4ec7a36ed 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
-// COM: to do offline symbolization we only check that the current module 
correctly is correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized  
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12

>From 29abe012394c582239b257a6a51b833b974743f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Thu, 11 Jan 2024 17:25:29 +
Subject: [PATCH 2/2] run git clang-format

Created using spr 1.3.5
---
 .../asan/TestCases/use-after-free-symbolizer-markup.cpp  | 9 -
 compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp | 6 ++
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 323de4ec7a36ed..8d818217eb5b63 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
-// COM: to do offline symbolization we only check that the current module is 
correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
@@ -9,9 +9,8 @@
 
 #include 
 
-[[gnu::noinline]]
-char *alloc() {
-  char *x = (char*)malloc(10 * sizeof(char));
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
   return x;
 }
 int main() {
@@ -26,7 +25,7 @@ int main() {
 // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
 // CHECK: {{freed by thread T0 here:}}
 // CHECK: {{#1 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-9]]
-// CHECK: {{previously allocated by thread T0 here:}} 
+// CHECK: {{previously allocated by thread T0 here:}}
 // CHECK: {{#1 0x.* alloc\(\) 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-16]]
 // CHECK: {{#2 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-13]]
 // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} 
application bytes):
diff --git a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp 
b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
index 5798986d73839e..a4f5e0e9d9fe46 100644
--- a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
+++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: linux
-// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main 
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
 // RUN: cp %t.main %t/.build-id/12/345678.debug
 // RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
@@ -9,9 +9,7 @@
 
 int Global;
 
-void __attribute__((noinline)) foo1() {
-  Global = 42;
-}
+void __attribute__((noinline)) foo1() { Global = 42; }
 
 void __attribute__((noinline)) bar1() {
   volatile int tmp = 42;

___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Valentin Clement バレンタイン クレメン via llvm-branch-commits

https://github.com/clementval created 
https://github.com/llvm/llvm-project/pull/77804

- Move the DeviceType enumeratoon to `Fortran::common` so it can be used 
outside of parser only. 
- Store the device_type dependent information on the symbol and reproduce them 
in the module file. 

>From d417332a130814e34fcc2448430d71b0fd5376b5 Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Wed, 10 Jan 2024 21:26:53 -0800
Subject: [PATCH] [flang][openacc] Carry device dependent info for routine in
 the module file

---
 flang/include/flang/Common/Fortran.h |  4 ++
 flang/include/flang/Parser/dump-parse-tree.h |  3 +-
 flang/include/flang/Parser/parse-tree.h  |  4 +-
 flang/include/flang/Semantics/symbol.h   | 29 +--
 flang/lib/Lower/OpenACC.cpp  | 16 +++---
 flang/lib/Parser/openacc-parsers.cpp | 14 ++---
 flang/lib/Semantics/mod-file.cpp | 54 ++--
 flang/lib/Semantics/resolve-directives.cpp   | 50 +++---
 flang/test/Semantics/OpenACC/acc-module.f90  | 13 +
 9 files changed, 142 insertions(+), 45 deletions(-)

diff --git a/flang/include/flang/Common/Fortran.h 
b/flang/include/flang/Common/Fortran.h
index 4007bfc7994f98..1d3a85e2500733 100644
--- a/flang/include/flang/Common/Fortran.h
+++ b/flang/include/flang/Common/Fortran.h
@@ -87,6 +87,10 @@ ENUM_CLASS(CUDASubprogramAttrs, Host, Device, HostDevice, 
Global, Grid_Global)
 // CUDA data attributes; mutually exclusive
 ENUM_CLASS(CUDADataAttr, Constant, Device, Managed, Pinned, Shared, Texture)
 
+// OpenACC device types
+ENUM_CLASS(
+OpenACCDeviceType, Star, Default, Nvidia, Radeon, Host, Multicore, None)
+
 // OpenMP atomic_default_mem_order clause allowed values
 ENUM_CLASS(OmpAtomicDefaultMemOrderType, SeqCst, AcqRel, Relaxed)
 
diff --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index 1defbf132327c4..d067a7273540f0 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -48,6 +48,7 @@ class ParseTreeDumper {
   NODE(std, uint64_t)
   NODE_ENUM(common, CUDADataAttr)
   NODE_ENUM(common, CUDASubprogramAttrs)
+  NODE_ENUM(common, OpenACCDeviceType)
   NODE(format, ControlEditDesc)
   NODE(format::ControlEditDesc, Kind)
   NODE(format, DerivedTypeDataEditDesc)
@@ -101,7 +102,7 @@ class ParseTreeDumper {
   NODE(parser, AccSelfClause)
   NODE(parser, AccStandaloneDirective)
   NODE(parser, AccDeviceTypeExpr)
-  NODE_ENUM(parser::AccDeviceTypeExpr, Device)
+
   NODE(parser, AccDeviceTypeExprList)
   NODE(parser, AccTileExpr)
   NODE(parser, AccTileExprList)
diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 71195f2bb9ddc4..e9bfb728a2bef6 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4072,8 +4072,8 @@ struct AccWaitArgument {
 };
 
 struct AccDeviceTypeExpr {
-  ENUM_CLASS(Device, Star, Default, Nvidia, Radeon, Host, Multicore)
-  WRAPPER_CLASS_BOILERPLATE(AccDeviceTypeExpr, Device);
+  WRAPPER_CLASS_BOILERPLATE(
+  AccDeviceTypeExpr, Fortran::common::OpenACCDeviceType);
   CharBlock source;
 };
 
diff --git a/flang/include/flang/Semantics/symbol.h 
b/flang/include/flang/Semantics/symbol.h
index f6f195b6bb95b2..2b6b18e40e6528 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -112,7 +112,8 @@ class WithBindName {
   bool isExplicitBindName_{false};
 };
 
-class OpenACCRoutineInfo {
+// Device type specific OpenACC routine information
+class OpenACCRoutineDeviceTypeInfo {
 public:
   bool isSeq() const { return isSeq_; }
   void set_isSeq(bool value = true) { isSeq_ = value; }
@@ -124,12 +125,12 @@ class OpenACCRoutineInfo {
   void set_isGang(bool value = true) { isGang_ = value; }
   unsigned gangDim() const { return gangDim_; }
   void set_gangDim(unsigned value) { gangDim_ = value; }
-  bool isNohost() const { return isNohost_; }
-  void set_isNohost(bool value = true) { isNohost_ = value; }
   const std::string *bindName() const {
 return bindName_ ? &*bindName_ : nullptr;
   }
   void set_bindName(std::string &&name) { bindName_ = std::move(name); }
+  void set_dType(Fortran::common::OpenACCDeviceType dType) { dType_ = dType; }
+  Fortran::common::OpenACCDeviceType dType() const { return dType_; }
 
 private:
   bool isSeq_{false};
@@ -137,8 +138,28 @@ class OpenACCRoutineInfo {
   bool isWorker_{false};
   bool isGang_{false};
   unsigned gangDim_{0};
-  bool isNohost_{false};
   std::optional bindName_;
+  Fortran::common::OpenACCDeviceType dType_{
+  Fortran::common::OpenACCDeviceType::None};
+};
+
+// OpenACC routine information. Device independent info are stored on the
+// OpenACCRoutineInfo instance while device dependent info are stored
+// in as objects in the OpenACCRoutineDeviceTypeInfo list.
+class OpenACCRoutineInfo : public OpenACCRoutineDeviceTypeInfo {
+public:
+  bool isN

[llvm-branch-commits] [flang] [flang][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)


Changes

- Move the DeviceType enumeratoon to `Fortran::common` so it can be used 
outside of parser only. 
- Store the device_type dependent information on the symbol and reproduce them 
in the module file. 

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


9 Files Affected:

- (modified) flang/include/flang/Common/Fortran.h (+4) 
- (modified) flang/include/flang/Parser/dump-parse-tree.h (+2-1) 
- (modified) flang/include/flang/Parser/parse-tree.h (+2-2) 
- (modified) flang/include/flang/Semantics/symbol.h (+25-4) 
- (modified) flang/lib/Lower/OpenACC.cpp (+9-7) 
- (modified) flang/lib/Parser/openacc-parsers.cpp (+7-7) 
- (modified) flang/lib/Semantics/mod-file.cpp (+37-17) 
- (modified) flang/lib/Semantics/resolve-directives.cpp (+43-7) 
- (modified) flang/test/Semantics/OpenACC/acc-module.f90 (+13) 


``diff
diff --git a/flang/include/flang/Common/Fortran.h 
b/flang/include/flang/Common/Fortran.h
index 4007bfc7994f98..1d3a85e2500733 100644
--- a/flang/include/flang/Common/Fortran.h
+++ b/flang/include/flang/Common/Fortran.h
@@ -87,6 +87,10 @@ ENUM_CLASS(CUDASubprogramAttrs, Host, Device, HostDevice, 
Global, Grid_Global)
 // CUDA data attributes; mutually exclusive
 ENUM_CLASS(CUDADataAttr, Constant, Device, Managed, Pinned, Shared, Texture)
 
+// OpenACC device types
+ENUM_CLASS(
+OpenACCDeviceType, Star, Default, Nvidia, Radeon, Host, Multicore, None)
+
 // OpenMP atomic_default_mem_order clause allowed values
 ENUM_CLASS(OmpAtomicDefaultMemOrderType, SeqCst, AcqRel, Relaxed)
 
diff --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index 1defbf132327c4..d067a7273540f0 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -48,6 +48,7 @@ class ParseTreeDumper {
   NODE(std, uint64_t)
   NODE_ENUM(common, CUDADataAttr)
   NODE_ENUM(common, CUDASubprogramAttrs)
+  NODE_ENUM(common, OpenACCDeviceType)
   NODE(format, ControlEditDesc)
   NODE(format::ControlEditDesc, Kind)
   NODE(format, DerivedTypeDataEditDesc)
@@ -101,7 +102,7 @@ class ParseTreeDumper {
   NODE(parser, AccSelfClause)
   NODE(parser, AccStandaloneDirective)
   NODE(parser, AccDeviceTypeExpr)
-  NODE_ENUM(parser::AccDeviceTypeExpr, Device)
+
   NODE(parser, AccDeviceTypeExprList)
   NODE(parser, AccTileExpr)
   NODE(parser, AccTileExprList)
diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 71195f2bb9ddc4..e9bfb728a2bef6 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4072,8 +4072,8 @@ struct AccWaitArgument {
 };
 
 struct AccDeviceTypeExpr {
-  ENUM_CLASS(Device, Star, Default, Nvidia, Radeon, Host, Multicore)
-  WRAPPER_CLASS_BOILERPLATE(AccDeviceTypeExpr, Device);
+  WRAPPER_CLASS_BOILERPLATE(
+  AccDeviceTypeExpr, Fortran::common::OpenACCDeviceType);
   CharBlock source;
 };
 
diff --git a/flang/include/flang/Semantics/symbol.h 
b/flang/include/flang/Semantics/symbol.h
index f6f195b6bb95b2..2b6b18e40e6528 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -112,7 +112,8 @@ class WithBindName {
   bool isExplicitBindName_{false};
 };
 
-class OpenACCRoutineInfo {
+// Device type specific OpenACC routine information
+class OpenACCRoutineDeviceTypeInfo {
 public:
   bool isSeq() const { return isSeq_; }
   void set_isSeq(bool value = true) { isSeq_ = value; }
@@ -124,12 +125,12 @@ class OpenACCRoutineInfo {
   void set_isGang(bool value = true) { isGang_ = value; }
   unsigned gangDim() const { return gangDim_; }
   void set_gangDim(unsigned value) { gangDim_ = value; }
-  bool isNohost() const { return isNohost_; }
-  void set_isNohost(bool value = true) { isNohost_ = value; }
   const std::string *bindName() const {
 return bindName_ ? &*bindName_ : nullptr;
   }
   void set_bindName(std::string &&name) { bindName_ = std::move(name); }
+  void set_dType(Fortran::common::OpenACCDeviceType dType) { dType_ = dType; }
+  Fortran::common::OpenACCDeviceType dType() const { return dType_; }
 
 private:
   bool isSeq_{false};
@@ -137,8 +138,28 @@ class OpenACCRoutineInfo {
   bool isWorker_{false};
   bool isGang_{false};
   unsigned gangDim_{0};
-  bool isNohost_{false};
   std::optional bindName_;
+  Fortran::common::OpenACCDeviceType dType_{
+  Fortran::common::OpenACCDeviceType::None};
+};
+
+// OpenACC routine information. Device independent info are stored on the
+// OpenACCRoutineInfo instance while device dependent info are stored
+// in as objects in the OpenACCRoutineDeviceTypeInfo list.
+class OpenACCRoutineInfo : public OpenACCRoutineDeviceTypeInfo {
+public:
+  bool isNohost() const { return isNohost_; }
+  void set_isNohost(bool value = true) { isNohost_ = value; }
+  std::list &deviceTypeInfos() {
+return deviceT

[llvm-branch-commits] [clang-tools-extra] [llvm] [clang] [compiler-rt] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info

ilovepi wrote:

`COM:` I assume is for comment? I don't recall seeing this in `lit` tests 
anywhere, and I don't see it in the documentation 
(https://llvm.org/docs/TestingGuide.html). This can be confused w/ a test 
prefix, so I think its more idiomatic to use: `///` or `;;;` to differentiate 
comments vs. checks.

https://github.com/llvm/llvm-project/pull/77702
___
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-tools-extra] [clang] [llvm] [compiler-rt] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+// CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}

ilovepi wrote:

If you expect these to be in order, `CHECK-NEXT:` or `CHECK-DAG:` are probably 
better.

https://github.com/llvm/llvm-project/pull/77702
___
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] [compiler-rt] [clang-tools-extra] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux

ilovepi wrote:

Is this intended to change? If so, a comment/TODO may be appropriate.

https://github.com/llvm/llvm-project/pull/77702
___
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] [compiler-rt] [clang] [clang-tools-extra] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,57 @@
+// REQUIRES: linux
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s --dump-input=always

ilovepi wrote:

See above.

https://github.com/llvm/llvm-project/pull/77702
___
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] [compiler-rt] [clang-tools-extra] [llvm] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}

ilovepi wrote:

I don't think most of these need to be regexes, do they? The following should 
work fine.

```suggestion
// CHECK: ERROR: AddressSanitizer: heap-use-after-free on address
```

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang-tools-extra] [llvm] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12

ilovepi wrote:

```suggestion
// RUN: rm -rf %t
// RUN: mkdir -p %t/.build-id/12
// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t/main
```
Its normal to remove the old test dir before doing trying to make a new one or 
add to it. It also makes sense to put any artifacts into the temp dir you're 
going to remove, so each run is self contained.

You'll need to adjust the other commands to match.

https://github.com/llvm/llvm-project/pull/77702
___
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-tools-extra] [compiler-rt] [llvm] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+// CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
+// CHECK: {{READ of size 1 at 0x.* thread T0}}
+// CHECK: {{#0 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-5]]

ilovepi wrote:

No need to match whitespace.

There are other ways to match numbers that you don't want to check exactly in 
FileCheck. see 
https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-numeric-substitution-blocks

https://github.com/llvm/llvm-project/pull/77702
___
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] [llvm] [clang] [clang-tools-extra] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,57 @@
+// REQUIRES: linux
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s --dump-input=always
+
+#include "test.h"
+
+int Global;
+
+void __attribute__((noinline)) foo1() { Global = 42; }

ilovepi wrote:

why mix `[[gnu::noinline]]` and `__attribute__((noinline))`? I expect these are 
copied from existing test files, but I think you should be consistent in this 
patch. I think we prefer cpp style attributes when possible.

https://github.com/llvm/llvm-project/pull/77702
___
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-tools-extra] [llvm] [compiler-rt] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+// CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
+// CHECK: {{READ of size 1 at 0x.* thread T0}}
+// CHECK: {{#0 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-5]]
+// CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
+// CHECK: {{freed by thread T0 here:}}
+// CHECK: {{#1 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-9]]
+// CHECK: {{previously allocated by thread T0 here:}}
+// CHECK: {{#1 0x.* alloc\(\) 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-16]]

ilovepi wrote:

```suggestion
// CHECK: {{#1 0x.* alloc\(\) 
.*use-after-free-symbolizer-markup.cpp:}}[[#@LINE-16]]
```
Note: `[[@LINE]]` is deprecated. Use `[[#@LINE]]`.

https://github.com/llvm/llvm-project/pull/77702
___
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-tools-extra] [clang] [llvm] [compiler-rt] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info

ilovepi wrote:

oh, nevermind I missed 
https://llvm.org/docs/CommandGuide/FileCheck.html#cmdoption-FileCheck-comment-prefixes

https://github.com/llvm/llvm-project/pull/77702
___
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] [llvm] [clang] [clang-tools-extra] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info

avillega wrote:

Yes, COM is for comments 
(https://llvm.org/docs/CommandGuide/FileCheck.html#the-com-directive) I am 
probably being too cautious here and not using COM maight be fine since the 
comment doesn't have anything like look like a directive.

https://github.com/llvm/llvm-project/pull/77702
___
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] [compiler-rt] [clang-tools-extra] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Paul Kirth via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info

ilovepi wrote:

The current use is fine. It just isn't something I've seen much(TBH, not at 
all). Grepping through llvm tests shows that it's mostly in the AArch64 backend 
tests, from a quick look. So, no need to change this if its a supported feature.

https://github.com/llvm/llvm-project/pull/77702
___
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] [compiler-rt] [clang-tools-extra] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,57 @@
+// REQUIRES: linux
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s --dump-input=always
+
+#include "test.h"
+
+int Global;
+
+void __attribute__((noinline)) foo1() { Global = 42; }

avillega wrote:

Yes, I copied another test and modified it. My assumption was that it would be 
better to keep each test as an analogous to the original, so I tried to keep it 
as close to the original as possible. but I totally agree with your comment.

https://github.com/llvm/llvm-project/pull/77702
___
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] [mlir] [lldb] [clang] [libcxx] [clang-tools-extra] [libc] [BOLT] Add BOLT Address Translation documentation (PR #76898)

2024-01-11 Thread Rafael Auler via llvm-branch-commits

https://github.com/rafaelauler edited 
https://github.com/llvm/llvm-project/pull/76898
___
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] [libc] [mlir] [libcxx] [clang-tools-extra] [lldb] [clang] [BOLT] Add BOLT Address Translation documentation (PR #76898)

2024-01-11 Thread Rafael Auler via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/76898
___
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] [libc] [clang-tools-extra] [llvm] [lldb] [clang] [mlir] [BOLT] Add BOLT Address Translation documentation (PR #76898)

2024-01-11 Thread Rafael Auler via llvm-branch-commits


@@ -0,0 +1,97 @@
+# BOLT Address Translation (BAT)
+# Purpose
+A regular profile collection for BOLT involves collecting samples from
+unoptimized binary. BOLT Address Translation allows collecting profile
+from BOLT-optimized binary and using it for optimizing the input (pre-BOLT)
+binary.
+
+# Overview
+BOLT Address Translation is an extra section (`.note.bolt_bat`) inserted by 
BOLT
+into the output binary containing translation tables and split functions 
linkage
+information. This information enables mapping the profile back from optimized
+binary onto the original binary.
+
+# Usage
+`--enable-bat` flag controls the generation of BAT section. Sampled profile
+needs to be passed along with the optimized binary containing BAT section to
+`perf2bolt` which reads BAT section and produces fdata profile for the original
+binary. Note that YAML profile generation is not supported since BAT doesn't
+contain the metadata for input functions.
+
+# Internals
+## Section contents
+The section is organized as follows:
+- Functions table
+  - Address translation tables
+- Fragment linkage table
+
+## Construction and parsing
+BAT section is created from `BoltAddressTranslation` class which captures
+address translation information provided by BOLT linker. It is then encoded as 
a
+note section in the output binary.
+
+During profile conversion when BAT-enabled binary is passed to perf2bolt,
+`BoltAddressTranslation` class is populated from BAT section. The class is then
+queried by `DataAggregator` during sample processing to reconstruct addresses/
+offsets in the input binary.
+
+## Encoding format
+The encoding is specified in
+[BoltAddressTranslation.h](/bolt/include/bolt/Profile/BoltAddressTranslation.h)
+and [BoltAddressTranslation.cpp](/bolt/lib/Profile/BoltAddressTranslation.cpp).
+
+### Layout
+The general layout is as follows:
+```
+Functions table header
+|--|
+|  Function entry  |
+| |--| |
+| | OutOff InOff | |
+| |--| |
+
+
+Fragment linkage header
+|--|
+| ColdAddr HotAddr |
+
+```
+
+### Functions table
+Header:
+| Entry  | Width | Description |
+| -- | - | --- |
+| `NumFuncs` | 4b | Number of functions in the functions table |

rafaelauler wrote:

Minor suggestion:
4b -> 4B

I usually see Bytes capitalized, but that's up to you

https://github.com/llvm/llvm-project/pull/76898
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Valentin Clement バレンタイン クレメン via llvm-branch-commits


@@ -124,21 +125,41 @@ class OpenACCRoutineInfo {
   void set_isGang(bool value = true) { isGang_ = value; }
   unsigned gangDim() const { return gangDim_; }
   void set_gangDim(unsigned value) { gangDim_ = value; }
-  bool isNohost() const { return isNohost_; }
-  void set_isNohost(bool value = true) { isNohost_ = value; }
   const std::string *bindName() const {
 return bindName_ ? &*bindName_ : nullptr;
   }
   void set_bindName(std::string &&name) { bindName_ = std::move(name); }
+  void set_dType(Fortran::common::OpenACCDeviceType dType) { dType_ = dType; }
+  Fortran::common::OpenACCDeviceType dType() const { return dType_; }
 
 private:
   bool isSeq_{false};
   bool isVector_{false};
   bool isWorker_{false};
   bool isGang_{false};
   unsigned gangDim_{0};
-  bool isNohost_{false};
   std::optional bindName_;
+  Fortran::common::OpenACCDeviceType dType_{
+  Fortran::common::OpenACCDeviceType::None};
+};
+
+// OpenACC routine information. Device independent info are stored on the
+// OpenACCRoutineInfo instance while device dependent info are stored
+// in as objects in the OpenACCRoutineDeviceTypeInfo list.

clementval wrote:

```suggestion
// OpenACCRoutineInfo instance while device dependent info are stored
// as objects in the OpenACCRoutineDeviceTypeInfo list.
```

https://github.com/llvm/llvm-project/pull/77804
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Valentin Clement バレンタイン クレメン via llvm-branch-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?Message-ID:
In-Reply-To: 


https://github.com/clementval updated 
https://github.com/llvm/llvm-project/pull/77804

>From d417332a130814e34fcc2448430d71b0fd5376b5 Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Wed, 10 Jan 2024 21:26:53 -0800
Subject: [PATCH 1/2] [flang][openacc] Carry device dependent info for routine
 in the module file

---
 flang/include/flang/Common/Fortran.h |  4 ++
 flang/include/flang/Parser/dump-parse-tree.h |  3 +-
 flang/include/flang/Parser/parse-tree.h  |  4 +-
 flang/include/flang/Semantics/symbol.h   | 29 +--
 flang/lib/Lower/OpenACC.cpp  | 16 +++---
 flang/lib/Parser/openacc-parsers.cpp | 14 ++---
 flang/lib/Semantics/mod-file.cpp | 54 ++--
 flang/lib/Semantics/resolve-directives.cpp   | 50 +++---
 flang/test/Semantics/OpenACC/acc-module.f90  | 13 +
 9 files changed, 142 insertions(+), 45 deletions(-)

diff --git a/flang/include/flang/Common/Fortran.h 
b/flang/include/flang/Common/Fortran.h
index 4007bfc7994f98..1d3a85e2500733 100644
--- a/flang/include/flang/Common/Fortran.h
+++ b/flang/include/flang/Common/Fortran.h
@@ -87,6 +87,10 @@ ENUM_CLASS(CUDASubprogramAttrs, Host, Device, HostDevice, 
Global, Grid_Global)
 // CUDA data attributes; mutually exclusive
 ENUM_CLASS(CUDADataAttr, Constant, Device, Managed, Pinned, Shared, Texture)
 
+// OpenACC device types
+ENUM_CLASS(
+OpenACCDeviceType, Star, Default, Nvidia, Radeon, Host, Multicore, None)
+
 // OpenMP atomic_default_mem_order clause allowed values
 ENUM_CLASS(OmpAtomicDefaultMemOrderType, SeqCst, AcqRel, Relaxed)
 
diff --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index 1defbf132327c4..d067a7273540f0 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -48,6 +48,7 @@ class ParseTreeDumper {
   NODE(std, uint64_t)
   NODE_ENUM(common, CUDADataAttr)
   NODE_ENUM(common, CUDASubprogramAttrs)
+  NODE_ENUM(common, OpenACCDeviceType)
   NODE(format, ControlEditDesc)
   NODE(format::ControlEditDesc, Kind)
   NODE(format, DerivedTypeDataEditDesc)
@@ -101,7 +102,7 @@ class ParseTreeDumper {
   NODE(parser, AccSelfClause)
   NODE(parser, AccStandaloneDirective)
   NODE(parser, AccDeviceTypeExpr)
-  NODE_ENUM(parser::AccDeviceTypeExpr, Device)
+
   NODE(parser, AccDeviceTypeExprList)
   NODE(parser, AccTileExpr)
   NODE(parser, AccTileExprList)
diff --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 71195f2bb9ddc4..e9bfb728a2bef6 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4072,8 +4072,8 @@ struct AccWaitArgument {
 };
 
 struct AccDeviceTypeExpr {
-  ENUM_CLASS(Device, Star, Default, Nvidia, Radeon, Host, Multicore)
-  WRAPPER_CLASS_BOILERPLATE(AccDeviceTypeExpr, Device);
+  WRAPPER_CLASS_BOILERPLATE(
+  AccDeviceTypeExpr, Fortran::common::OpenACCDeviceType);
   CharBlock source;
 };
 
diff --git a/flang/include/flang/Semantics/symbol.h 
b/flang/include/flang/Semantics/symbol.h
index f6f195b6bb95b2..2b6b18e40e6528 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -112,7 +112,8 @@ class WithBindName {
   bool isExplicitBindName_{false};
 };
 
-class OpenACCRoutineInfo {
+// Device type specific OpenACC routine information
+class OpenACCRoutineDeviceTypeInfo {
 public:
   bool isSeq() const { return isSeq_; }
   void set_isSeq(bool value = true) { isSeq_ = value; }
@@ -124,12 +125,12 @@ class OpenACCRoutineInfo {
   void set_isGang(bool value = true) { isGang_ = value; }
   unsigned gangDim() const { return gangDim_; }
   void set_gangDim(unsigned value) { gangDim_ = value; }
-  bool isNohost() const { return isNohost_; }
-  void set_isNohost(bool value = true) { isNohost_ = value; }
   const std::string *bindName() const {
 return bindName_ ? &*bindName_ : nullptr;
   }
   void set_bindName(std::string &&name) { bindName_ = std::move(name); }
+  void set_dType(Fortran::common::OpenACCDeviceType dType) { dType_ = dType; }
+  Fortran::common::OpenACCDeviceType dType() const { return dType_; }
 
 private:
   bool isSeq_{false};
@@ -137,8 +138,28 @@ class OpenACCRoutineInfo {
   bool isWorker_{false};
   bool isGang_{false};
   unsigned gangDim_{0};
-  bool isNohost_{false};
   std::optional bindName_;
+  Fortran::common::OpenACCDeviceType dType_{
+  Fortran::common::OpenACCDeviceType::None};
+};
+
+// OpenACC routine information. Device independent info are stored on the
+// OpenACCRoutineInfo instance while device dependent info are stored
+// in as objects in the OpenACCRoutineDeviceTypeInfo list.
+class OpenACCRoutineInfo : public OpenACCRoutineDeviceTypeInfo {
+public:
+  bool isNohost() const { return isNohost_; }
+  void set_isNohost(bool value = true) { isNohost_ = value; }
+  std::list &deviceTypeInfo

[llvm-branch-commits] [libcxx] [libc++][modules] Adds module testing. (PR #76246)

2024-01-11 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76246

>From 196cedd36534b02a7c55cf4a1746b34f87ead467 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 20 Dec 2023 20:43:38 +0100
Subject: [PATCH 1/3] [libc++][modules] Adds module testing.

This adds a new module test infrastructure. This requires tagging tests
using modules. The test runner uses this information to determine the
compiler flags needed to build and use the module.

Currently modules are build per test, which allows testing them for
tests with ADDITIONAL_COMPILE_FLAGS. At the moment only 4 tests use
modules. Therefore the performance penalty is not measurable. If in the
future more tests use modules it would be good to measure the overhead
and determine whether it's acceptable.
---
 libcxx/test/libcxx/module_std.gen.py  |  3 +-
 libcxx/test/libcxx/module_std_compat.gen.py   |  3 +-
 .../libcxx/selftest/modules/no-modules.sh.cpp | 12 +++
 .../modules/std-and-std.compat-module.sh.cpp  | 23 ++
 .../libcxx/selftest/modules/std-module.sh.cpp | 25 ++
 .../selftest/modules/std.compat-module.sh.cpp | 25 ++
 .../modules/unknown-module.compile.pass.cpp   | 13 
 libcxx/test/std/modules/std.compat.pass.cpp   |  5 +-
 libcxx/test/std/modules/std.pass.cpp  |  5 +-
 libcxx/utils/libcxx/test/features.py  | 12 +++
 libcxx/utils/libcxx/test/format.py| 76 +--
 libcxx/utils/libcxx/test/modules.py   |  5 +-
 12 files changed, 196 insertions(+), 11 deletions(-)
 create mode 100644 libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std.compat-module.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/unknown-module.compile.pass.cpp

diff --git a/libcxx/test/libcxx/module_std.gen.py 
b/libcxx/test/libcxx/module_std.gen.py
index 8e03d6e5b5b523..3ad2aff9d085f4 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -29,7 +29,8 @@
 "%{clang-tidy}",
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
-"%{flags} %{compile_flags}",
+"%{flags} %{compile_flags} %{module_flags}",
+"std",
 )
 
 
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index c4792db3d71e62..63fdd8188937e1 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -29,7 +29,8 @@
 "%{clang-tidy}",
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
-"%{flags} %{compile_flags}",
+"%{flags} %{compile_flags} %{module_flags}",
+"std.compat",
 )
 
 
diff --git a/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp 
b/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
new file mode 100644
index 00..86d0afc13e3c40
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
@@ -0,0 +1,12 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// Make sure that the module flags are empty when no module is supplied.
+
+// MODULES:
+// RUN: echo "%{module_flags}"  | grep "^$"
diff --git 
a/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp 
b/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
new file mode 100644
index 00..da9497f2dbb768
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
@@ -0,0 +1,23 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// UNSUPPORTED: clang-modules-build
+// UNSUPPORTED: gcc
+
+// XFAIL: has-no-module-support
+
+// Make sure that the module flags contain the expected elements.
+// The tests only look for the expected components and not the exact flags.
+// Otherwise changing the location of the module breaks this test.
+
+// MODULES: std std.compat
+//
+// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
+// RUN: echo "%{module_flags}" | grep "std.pcm"
+// RUN: echo "%{module_flags}" | grep "std.compat.pcm"
diff --git a/libcxx/test/libcxx/selftest/modules/std-module.sh.cpp 
b/libcxx/test/libcxx/s

[llvm-branch-commits] [libcxx] [libc++][modules] Adds module testing. (PR #76246)

2024-01-11 Thread Mark de Wever via llvm-branch-commits


@@ -131,13 +138,65 @@ def parseScript(test, preamble):
 script += preamble
 script += scriptInTest
 
+has_std_module = False
+has_std_compat_module = False
+for module in modules:
+if module == "std":
+has_std_module = True
+elif module == "std.compat":
+has_std_compat_module = True
+else:
+script.insert(
+0,
+f"echo \"The module '{module}' is not valid, use 'std' or 
'std.compat'\"",
+)
+script.insert(1, "false")
+return script
+
+if modules:
+# This flag is needed for both modules.
+moduleCompileFlags.append("-fprebuilt-module-path=%T")

mordante wrote:

I've tested this locally and added it to this patch.

https://github.com/llvm/llvm-project/pull/76246
___
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-tools-extra] [mlir] [lldb] [llvm] [libc] [clang] [libcxx] [BOLT] Add BOLT Address Translation documentation (PR #76898)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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

>From 5a55a403683003bfa937a563092f45cc4fbfb578 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 4 Jan 2024 07:22:58 -0800
Subject: [PATCH] Fix table rendering

Created using spr 1.3.4
---
 bolt/docs/BAT.md | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/bolt/docs/BAT.md b/bolt/docs/BAT.md
index 17845b906afe76..22986f7db2b17f 100644
--- a/bolt/docs/BAT.md
+++ b/bolt/docs/BAT.md
@@ -12,7 +12,7 @@ information. This information enables mapping the profile 
back from optimized
 binary onto the original binary.
 
 # Usage
-`--enable-bat` flag controls the generation of BAT section. Sampled profile 
+`--enable-bat` flag controls the generation of BAT section. Sampled profile
 needs to be passed along with the optimized binary containing BAT section to
 `perf2bolt` which reads BAT section and produces fdata profile for the original
 binary. Note that YAML profile generation is not supported since BAT doesn't
@@ -30,14 +30,15 @@ BAT section is created from `BoltAddressTranslation` class 
which captures
 address translation information provided by BOLT linker. It is then encoded as 
a
 note section in the output binary.
 
-During profile conversion when BAT-enabled binary is passed to perf2bolt, 
+During profile conversion when BAT-enabled binary is passed to perf2bolt,
 `BoltAddressTranslation` class is populated from BAT section. The class is then
 queried by `DataAggregator` during sample processing to reconstruct addresses/
 offsets in the input binary.
 
 ## Encoding format
-The encoding is specified in bolt/include/bolt/Profile/BoltAddressTranslation.h
-and bolt/lib/Profile/BoltAddressTranslation.cpp.
+The encoding is specified in
+[BoltAddressTranslation.h](/bolt/include/bolt/Profile/BoltAddressTranslation.h)
+and [BoltAddressTranslation.cpp](/bolt/lib/Profile/BoltAddressTranslation.cpp).
 
 ### Layout
 The general layout is as follows:
@@ -67,6 +68,7 @@ The header is followed by Functions table with `NumFuncs` 
entries.
 | -- | --| --- |
 | `Address` | 8b | Function address in the output binary |
 | `NumEntries` | 4b | Number of address translation entries for a function |
+
 Function header is followed by `NumEntries` pairs of offsets for current
 function.
 

___
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] [libc] [lldb] [mlir] [clang] [llvm] [clang-tools-extra] [libcxx] [BOLT] Add BOLT Address Translation documentation (PR #76898)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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

>From 5a55a403683003bfa937a563092f45cc4fbfb578 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 4 Jan 2024 07:22:58 -0800
Subject: [PATCH] Fix table rendering

Created using spr 1.3.4
---
 bolt/docs/BAT.md | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/bolt/docs/BAT.md b/bolt/docs/BAT.md
index 17845b906afe76..22986f7db2b17f 100644
--- a/bolt/docs/BAT.md
+++ b/bolt/docs/BAT.md
@@ -12,7 +12,7 @@ information. This information enables mapping the profile 
back from optimized
 binary onto the original binary.
 
 # Usage
-`--enable-bat` flag controls the generation of BAT section. Sampled profile 
+`--enable-bat` flag controls the generation of BAT section. Sampled profile
 needs to be passed along with the optimized binary containing BAT section to
 `perf2bolt` which reads BAT section and produces fdata profile for the original
 binary. Note that YAML profile generation is not supported since BAT doesn't
@@ -30,14 +30,15 @@ BAT section is created from `BoltAddressTranslation` class 
which captures
 address translation information provided by BOLT linker. It is then encoded as 
a
 note section in the output binary.
 
-During profile conversion when BAT-enabled binary is passed to perf2bolt, 
+During profile conversion when BAT-enabled binary is passed to perf2bolt,
 `BoltAddressTranslation` class is populated from BAT section. The class is then
 queried by `DataAggregator` during sample processing to reconstruct addresses/
 offsets in the input binary.
 
 ## Encoding format
-The encoding is specified in bolt/include/bolt/Profile/BoltAddressTranslation.h
-and bolt/lib/Profile/BoltAddressTranslation.cpp.
+The encoding is specified in
+[BoltAddressTranslation.h](/bolt/include/bolt/Profile/BoltAddressTranslation.h)
+and [BoltAddressTranslation.cpp](/bolt/lib/Profile/BoltAddressTranslation.cpp).
 
 ### Layout
 The general layout is as follows:
@@ -67,6 +68,7 @@ The header is followed by Functions table with `NumFuncs` 
entries.
 | -- | --| --- |
 | `Address` | 8b | Function address in the output binary |
 | `NumEntries` | 4b | Number of address translation entries for a function |
+
 Function header is followed by `NumEntries` pairs of offsets for current
 function.
 

___
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] [mlir] [clang-tools-extra] [libc] [libcxx] [clang] [lldb] [BOLT] Encode BAT using ULEB128 (PR #76899)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [libcxx] [clang] [llvm] [clang-tools-extra] [lldb] [mlir] [BOLT] Encode BAT using ULEB128 (PR #76899)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [lldb] [mlir] [clang] [llvm] [clang-tools-extra] [libcxx] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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-tools-extra] [mlir] [lldb] [llvm] [libc] [clang] [libcxx] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [libcxx] [clang] [llvm] [clang-tools-extra] [lldb] [mlir] [BOLT] Delta-encode function start addresses in BAT (PR #76902)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [llvm] [libc] [clang] [lldb] [mlir] [clang-tools-extra] [BOLT] Embed cold mapping info into function entry in BAT (PR #76903)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [mlir] [clang-tools-extra] [lldb] [libcxx] [llvm] [BOLT] Embed cold mapping info into function entry in BAT (PR #76903)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [lldb] [mlir] [clang] [llvm] [clang-tools-extra] [libcxx] [BOLT] Use continuous output addresses in delta encoding in BAT (PR #76904)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [mlir] [clang-tools-extra] [libc] [libcxx] [clang] [lldb] [BOLT] Delta-encode function start addresses in BAT (PR #76902)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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-tools-extra] [mlir] [lldb] [llvm] [libc] [clang] [libcxx] [BOLT] Use continuous output addresses in delta encoding in BAT (PR #76904)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [mlir] [clang-tools-extra] [libc] [libcxx] [clang] [lldb] [BOLT] Deduplicate equal offsets in BAT (PR #76905)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [libcxx] [clang] [llvm] [clang-tools-extra] [lldb] [mlir] [BOLT] Deduplicate equal offsets in BAT (PR #76905)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [mlir] [clang-tools-extra] [lldb] [libcxx] [llvm] [BOLT][NFC] Pass BF/BB hashes to BAT (PR #76906)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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-tools-extra] [libcxx] [mlir] [lldb] [libc] [clang] [llvm] [BOLT][NFC] Pass BF/BB hashes to BAT (PR #76906)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [lldb] [mlir] [clang] [llvm] [clang-tools-extra] [libcxx] [BOLT] Write and parse BF/BB hashes in BAT (PR #76907)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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-tools-extra] [mlir] [lldb] [llvm] [libc] [clang] [libcxx] [BOLT] Write and parse BF/BB hashes in BAT (PR #76907)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [mlir] [clang-tools-extra] [libc] [libcxx] [clang] [lldb] [BOLT][NFC] Const-ify DataAggregator::getLocationName (PR #76908)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [libcxx] [clang] [llvm] [clang-tools-extra] [lldb] [mlir] [BOLT][NFC] Const-ify DataAggregator::getLocationName (PR #76908)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [mlir] [clang-tools-extra] [lldb] [libcxx] [llvm] [BOLT][NFC] Expose YAMLProfileWriter::convert function (PR #76909)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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-tools-extra] [libcxx] [mlir] [lldb] [libc] [clang] [llvm] [BOLT][NFC] Expose YAMLProfileWriter::convert function (PR #76909)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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-tools-extra] [mlir] [lldb] [llvm] [libc] [clang] [libcxx] [BOLT] Output YAML profile in BAT mode (PR #76910)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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

>From b9173e3769ce2fefe846b0b65cef61631af94008 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 4 Jan 2024 09:52:26 -0800
Subject: [PATCH] Fix SaveProfile definition issue

Created using spr 1.3.4
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 4 +---
 bolt/lib/Utils/CommandLineOpts.cpp   | 4 
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index c6f38db17f093d..06f28195bb08dd 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -199,9 +199,7 @@ static cl::opt RelocationMode(
 "relocs", cl::desc("use relocations in the binary (default=autodetect)"),
 cl::cat(BoltCategory));
 
-cl::opt SaveProfile("w",
- cl::desc("save recorded profile to a file"),
- cl::cat(BoltOutputCategory));
+extern cl::opt SaveProfile;
 
 static cl::list
 SkipFunctionNames("skip-funcs",
diff --git a/bolt/lib/Utils/CommandLineOpts.cpp 
b/bolt/lib/Utils/CommandLineOpts.cpp
index a1df5de2623402..4a980a67fca378 100644
--- a/bolt/lib/Utils/CommandLineOpts.cpp
+++ b/bolt/lib/Utils/CommandLineOpts.cpp
@@ -163,6 +163,10 @@ cl::opt ProfileFormat(
clEnumValN(PF_YAML, "yaml", "dense YAML representation")),
 cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
 
+cl::opt SaveProfile("w",
+ cl::desc("save recorded profile to a file"),
+ cl::cat(BoltOutputCategory));
+
 cl::opt SplitEH("split-eh", cl::desc("split C++ exception handling 
code"),
   cl::Hidden, cl::cat(BoltOptCategory));
 

___
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] [llvm] [libc] [clang] [lldb] [mlir] [clang-tools-extra] [BOLT] Output YAML profile in BAT mode (PR #76910)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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

>From b9173e3769ce2fefe846b0b65cef61631af94008 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 4 Jan 2024 09:52:26 -0800
Subject: [PATCH] Fix SaveProfile definition issue

Created using spr 1.3.4
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 4 +---
 bolt/lib/Utils/CommandLineOpts.cpp   | 4 
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index c6f38db17f093d..06f28195bb08dd 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -199,9 +199,7 @@ static cl::opt RelocationMode(
 "relocs", cl::desc("use relocations in the binary (default=autodetect)"),
 cl::cat(BoltCategory));
 
-cl::opt SaveProfile("w",
- cl::desc("save recorded profile to a file"),
- cl::cat(BoltOutputCategory));
+extern cl::opt SaveProfile;
 
 static cl::list
 SkipFunctionNames("skip-funcs",
diff --git a/bolt/lib/Utils/CommandLineOpts.cpp 
b/bolt/lib/Utils/CommandLineOpts.cpp
index a1df5de2623402..4a980a67fca378 100644
--- a/bolt/lib/Utils/CommandLineOpts.cpp
+++ b/bolt/lib/Utils/CommandLineOpts.cpp
@@ -163,6 +163,10 @@ cl::opt ProfileFormat(
clEnumValN(PF_YAML, "yaml", "dense YAML representation")),
 cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
 
+cl::opt SaveProfile("w",
+ cl::desc("save recorded profile to a file"),
+ cl::cat(BoltOutputCategory));
+
 cl::opt SplitEH("split-eh", cl::desc("split C++ exception handling 
code"),
   cl::Hidden, cl::cat(BoltOptCategory));
 

___
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] [libc] [libcxx] [clang] [llvm] [clang-tools-extra] [lldb] [mlir] [BOLT] Emit intra-function control flow in YAMLBAT (PR #76911)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [mlir] [clang-tools-extra] [libc] [libcxx] [clang] [lldb] [BOLT] Emit intra-function control flow in YAMLBAT (PR #76911)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [mlir] [clang-tools-extra] [lldb] [libcxx] [llvm] [BOLT] Add CallSiteInfo entries in YAMLBAT (PR #76896)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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

>From 3362e9990ee0334ab7073943b4b682764f52bc8f Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 4 Jan 2024 10:40:04 -0800
Subject: [PATCH] Assert that a function exists

Created using spr 1.3.4
---
 bolt/lib/Profile/BoltAddressTranslation.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp 
b/bolt/lib/Profile/BoltAddressTranslation.cpp
index dbc9e1702a3016..62f8b777ee91b4 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -521,8 +521,7 @@ std::unordered_map>
 BoltAddressTranslation::getBFBranches(uint64_t OutputAddress) const {
   std::unordered_map> Branches;
   auto FuncIt = Maps.find(OutputAddress);
-  if (FuncIt == Maps.end())
-return Branches;
+  assert(FuncIt != Maps.end());
   std::vector InputOffsets;
   for (const auto &KV : FuncIt->second)
 InputOffsets.emplace_back(KV.second);

___
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-tools-extra] [libcxx] [mlir] [lldb] [libc] [clang] [llvm] [BOLT] Add CallSiteInfo entries in YAMLBAT (PR #76896)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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

>From 3362e9990ee0334ab7073943b4b682764f52bc8f Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 4 Jan 2024 10:40:04 -0800
Subject: [PATCH] Assert that a function exists

Created using spr 1.3.4
---
 bolt/lib/Profile/BoltAddressTranslation.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp 
b/bolt/lib/Profile/BoltAddressTranslation.cpp
index dbc9e1702a3016..62f8b777ee91b4 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -521,8 +521,7 @@ std::unordered_map>
 BoltAddressTranslation::getBFBranches(uint64_t OutputAddress) const {
   std::unordered_map> Branches;
   auto FuncIt = Maps.find(OutputAddress);
-  if (FuncIt == Maps.end())
-return Branches;
+  assert(FuncIt != Maps.end());
   std::vector InputOffsets;
   for (const auto &KV : FuncIt->second)
 InputOffsets.emplace_back(KV.second);

___
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] [libc] [mlir] [clang-tools-extra] [lldb] [libcxx] [llvm] [BOLT] Add BOLT Address Translation documentation (PR #76898)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/76898
___
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] [mlir] [clang-tools-extra] [libc] [libcxx] [clang] [lldb] [BOLT] Encode BAT using ULEB128 (PR #76899)

2024-01-11 Thread Rafael Auler via llvm-branch-commits

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

Great!

https://github.com/llvm/llvm-project/pull/76899
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Peter Klausler via llvm-branch-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw==?=
Message-ID:
In-Reply-To: 


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


https://github.com/llvm/llvm-project/pull/77804
___
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] [mlir] [clang-tools-extra] [libc] [libcxx] [clang] [lldb] [BOLT] Encode BAT using ULEB128 (PR #76899)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/76899
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread via llvm-branch-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw==?=
Message-ID:
In-Reply-To: 


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


https://github.com/llvm/llvm-project/pull/77804
___
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] [lldb] [llvm] [clang-tools-extra] [libcxx] [libc] [mlir] [clang] [BOLT] Encode BAT using ULEB128 (PR #76899)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

aaupov wrote:

Merged into wrong branch... spr workflow is tough.

https://github.com/llvm/llvm-project/pull/76899
___
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] [clang-tools-extra] [clang] [compiler-rt] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux

avillega wrote:

I don't think it is intended to change, at least no for now.

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang-tools-extra] [clang] [llvm] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12

avillega wrote:

Done

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang-tools-extra] [llvm] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}

avillega wrote:

Done

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang-tools-extra] [llvm] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 


https://github.com/avillega updated 
https://github.com/llvm/llvm-project/pull/77702

>From a3220262a3236115d55235e4cc34acc8202268f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Wed, 10 Jan 2024 23:56:45 +
Subject: [PATCH 1/3] Fix typo.

Created using spr 1.3.5
---
 .../test/asan/TestCases/use-after-free-symbolizer-markup.cpp| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 548ae57b5c3797..323de4ec7a36ed 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
-// COM: to do offline symbolization we only check that the current module 
correctly is correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized  
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12

>From 29abe012394c582239b257a6a51b833b974743f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Thu, 11 Jan 2024 17:25:29 +
Subject: [PATCH 2/3] run git clang-format

Created using spr 1.3.5
---
 .../asan/TestCases/use-after-free-symbolizer-markup.cpp  | 9 -
 compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp | 6 ++
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 323de4ec7a36ed..8d818217eb5b63 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
-// COM: to do offline symbolization we only check that the current module is 
correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
@@ -9,9 +9,8 @@
 
 #include 
 
-[[gnu::noinline]]
-char *alloc() {
-  char *x = (char*)malloc(10 * sizeof(char));
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
   return x;
 }
 int main() {
@@ -26,7 +25,7 @@ int main() {
 // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
 // CHECK: {{freed by thread T0 here:}}
 // CHECK: {{#1 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-9]]
-// CHECK: {{previously allocated by thread T0 here:}} 
+// CHECK: {{previously allocated by thread T0 here:}}
 // CHECK: {{#1 0x.* alloc\(\) 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-16]]
 // CHECK: {{#2 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-13]]
 // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} 
application bytes):
diff --git a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp 
b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
index 5798986d73839e..a4f5e0e9d9fe46 100644
--- a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
+++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: linux
-// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main 
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
 // RUN: cp %t.main %t/.build-id/12/345678.debug
 // RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
@@ -9,9 +9,7 @@
 
 int Global;
 
-void __attribute__((noinline)) foo1() {
-  Global = 42;
-}
+void __attribute__((noinline)) foo1() { Global = 42; }
 
 void __attribute__((noinline)) bar1() {
   volatile int tmp = 42;

>From 2f11f65aadc8411c544f60bd3af29529625bc177 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Thu, 11 Jan 2024 20:21:04 +
Subject: [PATCH 3/3] Fix review comments

Created using spr 1.3.5
---
 .../use-after-free-symbolizer-markup.cpp  | 32 ++-
 .../tsan/simple_stack_symbolizer_markup.cpp   | 29 +
 2 files changed, 32 insertions(+), 29 deletions(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 8d818217eb5b63..2da07892daf6c5 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,10 +1,12 @@
-// COM: End to end test for the sanitiz

[llvm-branch-commits] [compiler-rt] [clang-tools-extra] [llvm] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+// CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}

avillega wrote:

Added CHECK-NEXT and CHECK-DAG in some places. because of how the symvolizer 
markup context elements currently work, it is possible to get a line containing 
module information in the middle of two lines that might be expected to be NEXT 
to each other. I think it is something we might want to review.

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang] [llvm] [clang-tools-extra] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+// CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
+// CHECK: {{READ of size 1 at 0x.* thread T0}}
+// CHECK: {{#0 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-5]]

avillega wrote:

Done

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang-tools-extra] [clang] [llvm] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 
2>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s
+
+#include 
+
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
+  return x;
+}
+int main() {
+  char *x = alloc();
+  free(x);
+  return x[5];
+}
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+// CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
+// CHECK: {{READ of size 1 at 0x.* thread T0}}
+// CHECK: {{#0 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-5]]
+// CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
+// CHECK: {{freed by thread T0 here:}}
+// CHECK: {{#1 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-9]]
+// CHECK: {{previously allocated by thread T0 here:}}
+// CHECK: {{#1 0x.* alloc\(\) 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-16]]

avillega wrote:

Done

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang-tools-extra] [clang] [llvm] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,57 @@
+// REQUIRES: linux
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s --dump-input=always

avillega wrote:

Done

https://github.com/llvm/llvm-project/pull/77702
___
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] [clang] [llvm] [clang-tools-extra] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,57 @@
+// REQUIRES: linux
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < 
%t/sanitizer.out | FileCheck %s --dump-input=always
+
+#include "test.h"
+
+int Global;
+
+void __attribute__((noinline)) foo1() { Global = 42; }

avillega wrote:

Done

https://github.com/llvm/llvm-project/pull/77702
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Razvan Lupusoru via llvm-branch-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?Message-ID:
In-Reply-To: 



@@ -124,21 +125,41 @@ class OpenACCRoutineInfo {
   void set_isGang(bool value = true) { isGang_ = value; }
   unsigned gangDim() const { return gangDim_; }
   void set_gangDim(unsigned value) { gangDim_ = value; }
-  bool isNohost() const { return isNohost_; }
-  void set_isNohost(bool value = true) { isNohost_ = value; }
   const std::string *bindName() const {
 return bindName_ ? &*bindName_ : nullptr;
   }
   void set_bindName(std::string &&name) { bindName_ = std::move(name); }
+  void set_dType(Fortran::common::OpenACCDeviceType dType) { dType_ = dType; }
+  Fortran::common::OpenACCDeviceType dType() const { return dType_; }
 
 private:
   bool isSeq_{false};
   bool isVector_{false};
   bool isWorker_{false};
   bool isGang_{false};
   unsigned gangDim_{0};
-  bool isNohost_{false};
   std::optional bindName_;
+  Fortran::common::OpenACCDeviceType dType_{

razvanlupusoru wrote:

nit: Can you name it deviceType_ instead of dType_? Although the name "dtype" 
is specifically noted as acceptable abbreviation in OpenACC spec, I personally 
find it confusing.

https://github.com/llvm/llvm-project/pull/77804
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Razvan Lupusoru via llvm-branch-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw==?=
Message-ID:
In-Reply-To: 


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

Nice work! Glad you realized this info was missing in the module file.

https://github.com/llvm/llvm-project/pull/77804
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Valentin Clement バレンタイン クレメン via llvm-branch-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?Message-ID:
In-Reply-To: 


https://github.com/clementval closed 
https://github.com/llvm/llvm-project/pull/77804
___
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][openacc] Carry device dependent info for acc routine in the module file (PR #77804)

2024-01-11 Thread Valentin Clement バレンタイン クレメン via llvm-branch-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?Message-ID:
In-Reply-To: 


clementval wrote:

For some reason this PR has been closed when I merged the parent PR. I'll apply 
the suggestion and push the commit manually. 

https://github.com/llvm/llvm-project/pull/77804
___
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-tools-extra] [mlir] [lldb] [libcxx] [llvm] [libc] [clang] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Rafael Auler via llvm-branch-commits

https://github.com/rafaelauler edited 
https://github.com/llvm/llvm-project/pull/76900
___
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] [clang-tools-extra] [lldb] [clang] [libc] [libcxx] [mlir] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Rafael Auler via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/76900
___
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] [mlir] [libc] [lldb] [clang-tools-extra] [llvm] [libcxx] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Rafael Auler via llvm-branch-commits


@@ -114,9 +114,12 @@ void BoltAddressTranslation::write(const BinaryContext 
&BC, raw_ostream &OS) {
   << Twine::utohexstr(Address) << ".\n");
 encodeULEB128(Address, OS);
 encodeULEB128(NumEntries, OS);
+uint64_t InOffset = 0, OutOffset = 0;

rafaelauler wrote:

It's not an offset, right? Maybe a better name would be PrevIn, PrevOut? (as in 
"Previous Input Address")

https://github.com/llvm/llvm-project/pull/76900
___
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-tools-extra] [clang] [libcxx] [mlir] [llvm] [libc] [lldb] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Rafael Auler via llvm-branch-commits


@@ -164,12 +167,16 @@ std::error_code BoltAddressTranslation::parse(StringRef 
Buf) {
 
 LLVM_DEBUG(dbgs() << "Parsing " << NumEntries << " entries for 0x"
   << Twine::utohexstr(Address) << "\n");
+uint64_t InputOffset = 0, OutputOffset = 0;

rafaelauler wrote:

Maybe I'm missing something, but I don't understand why are we naming this as 
Offset. Even in BAT.md it is listed as 'address' instead of offset. 

https://github.com/llvm/llvm-project/pull/76900
___
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] [clang-tools-extra] [lldb] [clang] [libc] [libcxx] [mlir] [BOLT] Delta-encode function start addresses in BAT (PR #76902)

2024-01-11 Thread Rafael Auler via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/76902
___
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] [clang] [clang-tools-extra] [compiler-rt] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

2024-01-11 Thread Andres Villegas via llvm-branch-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 


https://github.com/avillega updated 
https://github.com/llvm/llvm-project/pull/77702

>From a3220262a3236115d55235e4cc34acc8202268f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Wed, 10 Jan 2024 23:56:45 +
Subject: [PATCH 1/4] Fix typo.

Created using spr 1.3.5
---
 .../test/asan/TestCases/use-after-free-symbolizer-markup.cpp| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 548ae57b5c3797..323de4ec7a36ed 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
-// COM: to do offline symbolization we only check that the current module 
correctly is correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized  
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12

>From 29abe012394c582239b257a6a51b833b974743f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Thu, 11 Jan 2024 17:25:29 +
Subject: [PATCH 2/4] run git clang-format

Created using spr 1.3.5
---
 .../asan/TestCases/use-after-free-symbolizer-markup.cpp  | 9 -
 compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp | 6 ++
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 323de4ec7a36ed..8d818217eb5b63 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses 
debug info
-// COM: to do offline symbolization we only check that the current module is 
correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is 
correctly symbolized
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
@@ -9,9 +9,8 @@
 
 #include 
 
-[[gnu::noinline]]
-char *alloc() {
-  char *x = (char*)malloc(10 * sizeof(char));
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
   return x;
 }
 int main() {
@@ -26,7 +25,7 @@ int main() {
 // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
 // CHECK: {{freed by thread T0 here:}}
 // CHECK: {{#1 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-9]]
-// CHECK: {{previously allocated by thread T0 here:}} 
+// CHECK: {{previously allocated by thread T0 here:}}
 // CHECK: {{#1 0x.* alloc\(\) 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-16]]
 // CHECK: {{#2 0x.* main 
.*use-after-free-symbolizer-markup.cpp:}}[[@LINE-13]]
 // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} 
application bytes):
diff --git a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp 
b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
index 5798986d73839e..a4f5e0e9d9fe46 100644
--- a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
+++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: linux
-// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main 
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
 // RUN: cp %t.main %t/.build-id/12/345678.debug
 // RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main 
>%t/sanitizer.out
@@ -9,9 +9,7 @@
 
 int Global;
 
-void __attribute__((noinline)) foo1() {
-  Global = 42;
-}
+void __attribute__((noinline)) foo1() { Global = 42; }
 
 void __attribute__((noinline)) bar1() {
   volatile int tmp = 42;

>From 2f11f65aadc8411c544f60bd3af29529625bc177 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= 
Date: Thu, 11 Jan 2024 20:21:04 +
Subject: [PATCH 3/4] Fix review comments

Created using spr 1.3.5
---
 .../use-after-free-symbolizer-markup.cpp  | 32 ++-
 .../tsan/simple_stack_symbolizer_markup.cpp   | 29 +
 2 files changed, 32 insertions(+), 29 deletions(-)

diff --git 
a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp 
b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 8d818217eb5b63..2da07892daf6c5 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,10 +1,12 @@
-// COM: E

[llvm-branch-commits] [llvm] [clang-tools-extra] [lldb] [clang] [libc] [libcxx] [mlir] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits


@@ -114,9 +114,12 @@ void BoltAddressTranslation::write(const BinaryContext 
&BC, raw_ostream &OS) {
   << Twine::utohexstr(Address) << ".\n");
 encodeULEB128(Address, OS);
 encodeULEB128(NumEntries, OS);
+uint64_t InOffset = 0, OutOffset = 0;

aaupov wrote:

No, these are offsets, BAT.md is incorrect here

https://github.com/llvm/llvm-project/pull/76900
___
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] [clang-tools-extra] [lldb] [clang] [libc] [libcxx] [mlir] [flang] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [lldb] [libc] [flang] [llvm] [libcxx] [mlir] [clang] [clang-tools-extra] [BOLT] Delta-encode offsets in BAT (PR #76900)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [clang-tools-extra] [libc] [clang] [libcxx] [llvm] [lldb] [flang] [BOLT] Delta-encode function start addresses in BAT (PR #76902)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [libc] [libcxx] [lldb] [mlir] [clang-tools-extra] [llvm] [flang] [BOLT] Delta-encode function start addresses in BAT (PR #76902)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [clang] [libcxx] [mlir] [libc] [clang-tools-extra] [flang] [lldb] [BOLT] Embed cold mapping info into function entry in BAT (PR #76903)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


___
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] [lldb] [clang] [flang] [libc] [llvm] [clang-tools-extra] [libcxx] [BOLT] Embed cold mapping info into function entry in BAT (PR #76903)

2024-01-11 Thread Amir Ayupov via llvm-branch-commits

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


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


  1   2   >