[llvm-branch-commits] [clang] [Serialization] Code cleanups and polish 83233 (PR #83237)

2024-04-01 Thread Vassil Vassilev via llvm-branch-commits

vgvassilev wrote:

> Btw, if I don't respond timely to these requests and you need an urgent 
> reaction, feel free to ping me via email at 
> [ibiryu...@google.com](mailto:ibiryu...@google.com). We heavily use Clang 
> header modules internally at Google and we are really interested in helping 
> to discover and prevent the module bugs as early as possible. And we also 
> really appreciate your work on improving and optimizing the modules 
> implementation!

@ilya-biryukov, I was wondering if you have had a chance to test this PR?

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


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

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

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

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

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

The new interface is attached to the `omp.parallel`, `omp.wsloop`, 
`omp.simdloop`, `omp.distribute` and `omp.taskloop` operations. It is not 
currently enforced that these operations meet the wrapper restrictions, which 
would break existing OpenMP loop-generating code. Rather, this will be 
introduced progressively in subsequent patches.

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

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

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

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

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

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

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

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Sergio Afonso (skatrak)


Changes

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

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

The new interface is attached to the `omp.parallel`, `omp.wsloop`, 
`omp.simdloop`, `omp.distribute` and `omp.taskloop` operations. It is not 
currently enforced that these operations meet the wrapper restrictions, which 
would break existing OpenMP loop-generating code. Rather, this will be 
introduced progressively in subsequent patches.

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h (+3) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+12-4) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+68) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+19) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+15-1) 


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

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

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

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

This patch updates the definition of `omp.distribute` to enforce the 
restrictions of a wrapper operation.

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

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

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

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

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

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Sergio Afonso (skatrak)


Changes

This patch updates the definition of `omp.distribute` to enforce the 
restrictions of a wrapper operation.

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+18-4) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+11) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+33-1) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+31-7) 


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

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

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

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

Emit a special leaf constuct table in DirectiveEmitter.cpp, which will allow 
both decomposition of a construct into leafs, and composition of constituent 
constructs into a single compound construct (is possible).

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

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

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h 
b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index a85cd9d344c6d7..4ed47f15dfe59e 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -15,4 +15,11 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h.inc"
 
+#include "llvm/ADT/ArrayRef.h"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D);
+Directive getCompoundConstruct(ArrayRef Parts);
+} // namespace llvm::omp
+
 #endif // LLVM_FRONTEND_OPENMP_OMP_H
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 4f2f95392648b3..dd99d3d074fd1e 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -8,12 +8,74 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
 
+#include 
+#include 
+#include 
+
 using namespace llvm;
-using namespace omp;
+using namespace llvm::omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D) {
+  auto Idx = static_cast(D);
+  if (Idx < 0 || Idx >= static_cast(Directive_enumSize))
+return {};
+  const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
+  return ArrayRef(&Row[2], &Row[2] + static_cast(Row[1]));
+}
+
+Directive getCompoundConstruct(ArrayRef Parts) {
+  if (Parts.empty())
+return OMPD_unknown;
+
+  // Parts don't have to be leafs, so expand them into leafs first.
+  // Store the expanded leafs in the same format as rows in the leaf
+  // table (generated by tablegen).
+  SmallVector RawLeafs(2);
+  for (Directive P : Parts) {
+ArrayRef Ls = getLeafConstructs(P);
+if (!Ls.empty())
+  RawLeafs.append(Ls.begin(), Ls.end());
+else
+  RawLeafs.push_back(P);
+  }
+
+  auto GivenLeafs{ArrayRef(RawLeafs).drop_front(2)};
+  if (GivenLeafs.size() == 1)
+return GivenLeafs.front();
+  RawLeafs[1] = static_cast(GivenLeafs.size());
+
+  auto Iter = llvm::lower_bound(
+  LeafConstructTable,
+  
static_cast>(RawLeafs.data()),
+  [](const auto *RowA, const auto *RowB) {
+const auto *BeginA = &RowA[2];
+const auto *EndA = BeginA + static_cast(RowA[1]);
+const auto *BeginB = &RowB[2];
+const auto *EndB = BeginB + static_cast(RowB[1]);
+if (BeginA == EndA && BeginB == EndB)
+  return static_cast(RowA[0]) < static_cast(RowB[0]);
+return std::lexicographical_compare(BeginA, EndA, BeginB, EndB);
+  });
+
+  if (Iter == std::end(LeafConstructTable))
+return OMPD_unknown;
+
+  // Verify that we got a match.
+  Directive Found = (*Iter)[0];
+  ArrayRef FoundLeafs = getLeafConstructs(Found);
+  if (FoundLeafs == GivenLeafs)
+return Found;
+  return OMPD_unknown;
+}
+} // namespace llvm::omp
diff --git a/llvm/unittests/Frontend/CMakeLists.txt 
b/llvm/unittests/Frontend/CMakeLists.txt
index c6f60142d6276a..ddb6a16cbb984e 100644
--- a/llvm/unittests/Frontend/CMakeLists.txt
+++ b/llvm/unittests/Frontend/CMakeLists.txt
@@ -14,6 +14,7 @@ add_llvm_unittest(LLVMFrontendTests
   OpenMPContextTest.cpp
   OpenMPIRBuilderTest.cpp
   OpenMPParsingTest.cpp
+  OpenMPComposeTest.cpp
 
   DEPENDS
   acc_gen
diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp 
b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
new file mode 100644
index 00..2dc35aca8842e9
--- /dev/null
+++ b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
@@ -0,0 +1,40 @@
+//===- llvm/unittests/Frontend/OpenMPComposeTest.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LIC

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

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

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

Emit a special leaf constuct table in DirectiveEmitter.cpp, which will allow 
both decomposition of a construct into leafs, and composition of constituent 
constructs into a single compound construct (is possible).

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


5 Files Affected:

- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.h (+7) 
- (modified) llvm/lib/Frontend/OpenMP/OMP.cpp (+63-1) 
- (modified) llvm/unittests/Frontend/CMakeLists.txt (+1) 
- (added) llvm/unittests/Frontend/OpenMPComposeTest.cpp (+40) 
- (modified) llvm/utils/TableGen/DirectiveEmitter.cpp (+124-70) 


``diff
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h 
b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index a85cd9d344c6d7..4ed47f15dfe59e 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -15,4 +15,11 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h.inc"
 
+#include "llvm/ADT/ArrayRef.h"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D);
+Directive getCompoundConstruct(ArrayRef Parts);
+} // namespace llvm::omp
+
 #endif // LLVM_FRONTEND_OPENMP_OMP_H
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 4f2f95392648b3..dd99d3d074fd1e 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -8,12 +8,74 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
 
+#include 
+#include 
+#include 
+
 using namespace llvm;
-using namespace omp;
+using namespace llvm::omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+ArrayRef getLeafConstructs(Directive D) {
+  auto Idx = static_cast(D);
+  if (Idx < 0 || Idx >= static_cast(Directive_enumSize))
+return {};
+  const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
+  return ArrayRef(&Row[2], &Row[2] + static_cast(Row[1]));
+}
+
+Directive getCompoundConstruct(ArrayRef Parts) {
+  if (Parts.empty())
+return OMPD_unknown;
+
+  // Parts don't have to be leafs, so expand them into leafs first.
+  // Store the expanded leafs in the same format as rows in the leaf
+  // table (generated by tablegen).
+  SmallVector RawLeafs(2);
+  for (Directive P : Parts) {
+ArrayRef Ls = getLeafConstructs(P);
+if (!Ls.empty())
+  RawLeafs.append(Ls.begin(), Ls.end());
+else
+  RawLeafs.push_back(P);
+  }
+
+  auto GivenLeafs{ArrayRef(RawLeafs).drop_front(2)};
+  if (GivenLeafs.size() == 1)
+return GivenLeafs.front();
+  RawLeafs[1] = static_cast(GivenLeafs.size());
+
+  auto Iter = llvm::lower_bound(
+  LeafConstructTable,
+  
static_cast>(RawLeafs.data()),
+  [](const auto *RowA, const auto *RowB) {
+const auto *BeginA = &RowA[2];
+const auto *EndA = BeginA + static_cast(RowA[1]);
+const auto *BeginB = &RowB[2];
+const auto *EndB = BeginB + static_cast(RowB[1]);
+if (BeginA == EndA && BeginB == EndB)
+  return static_cast(RowA[0]) < static_cast(RowB[0]);
+return std::lexicographical_compare(BeginA, EndA, BeginB, EndB);
+  });
+
+  if (Iter == std::end(LeafConstructTable))
+return OMPD_unknown;
+
+  // Verify that we got a match.
+  Directive Found = (*Iter)[0];
+  ArrayRef FoundLeafs = getLeafConstructs(Found);
+  if (FoundLeafs == GivenLeafs)
+return Found;
+  return OMPD_unknown;
+}
+} // namespace llvm::omp
diff --git a/llvm/unittests/Frontend/CMakeLists.txt 
b/llvm/unittests/Frontend/CMakeLists.txt
index c6f60142d6276a..ddb6a16cbb984e 100644
--- a/llvm/unittests/Frontend/CMakeLists.txt
+++ b/llvm/unittests/Frontend/CMakeLists.txt
@@ -14,6 +14,7 @@ add_llvm_unittest(LLVMFrontendTests
   OpenMPContextTest.cpp
   OpenMPIRBuilderTest.cpp
   OpenMPParsingTest.cpp
+  OpenMPComposeTest.cpp
 
   DEPENDS
   acc_gen
diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp 
b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
new file mode 100644
index 00..2dc35aca8842e9
--- /dev/null
+++ b/llvm/unittests/Frontend/OpenMPComposeTest.cpp
@@ -0,0 +1,40 @@
+//===- llvm/unittests/Frontend/OpenMPComposeTest.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Frontend/OpenMP/OMP.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::omp;
+
+TEST(Composition, GetLeafConstructs) {
+  ArrayRef L1 = getLeafConstructs(OMPD_loop);
+  ASSERT_EQ(L1, (A

[llvm-branch-commits] [libcxx] [libc++][chrono] Completes the tzdb class. (PR #82157)

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

EricWF wrote:

Which of this change and D82113 would you like to move? They seem to overlap 
substantially? 

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


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

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

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

This patch updates the definition of `omp.taskloop` to enforce the restrictions 
of a wrapper operation.

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

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

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

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

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

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Sergio Afonso (skatrak)


Changes

This patch updates the definition of `omp.taskloop` to enforce the restrictions 
of a wrapper operation.

---

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+16-23) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+10) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+62-30) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+124-98) 


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

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

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

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

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

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

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

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

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

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

Implement helper functions to identify leaf, composite, and combined constructs.

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

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

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

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


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

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

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

Implement helper functions to identify leaf, composite, and combined constructs.

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


3 Files Affected:

- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.h (+4) 
- (modified) llvm/lib/Frontend/OpenMP/OMP.cpp (+25) 
- (modified) llvm/unittests/Frontend/OpenMPComposeTest.cpp (+26) 


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

``




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


[llvm-branch-commits] [libcxx] [libc++][chrono] Completes the tzdb class. (PR #82157)

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

h-vetinari wrote:

If you look at the branch targets you'll see that they're stacked on top of 
each other (poor man's stacked reviews on GitHub using multiple branches).

https://github.com/llvm/llvm-project/pull/82157
___
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] [clang-tools-extra] [compiler-rt] [flang] [libc] [lld] [llvm] [mlir] [openmp] [ThinLTO][TypeProf] Implement vtable def import (PR #79381)

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

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

error: too big or took too long to generate
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18x: [clang] Avoid -Wshadow warning when init-capture named same as class … (PR #84912)

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

erichkeane wrote:

Just got back from WG21, so sorry for the delay.  While we don't USUALLY do 
backports like this that fix something that was present in the last release, I 
think this ends up being reasonably low risk, we haven't seen any bugs 
regarding this SINCE, and worst-case it breaks `-Wshadow`.  So I am OK with 
this, so approve.

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


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

2024-04-01 Thread Leandro Lupori via llvm-branch-commits

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

LGTM

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


[llvm-branch-commits] [clang][ubsan] Switch UBSAN optimization to `llvm.allow.{runtime, ubsan}.check()` (PR #84858)

2024-04-01 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/84858
___
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][ubsan] Switch UBSAN optimization to `llvm.allow.{runtime, ubsan}.check()` (PR #84858)

2024-04-01 Thread Vitaly Buka via llvm-branch-commits

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


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

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

tstellar wrote:

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

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


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

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

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


[llvm-branch-commits] [openmp] 47aac49 - [OpenMP][AIX] Affinity implementation for AIX (#84984)

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

Author: Xing Xue
Date: 2024-03-30T09:57:06-04:00
New Revision: 47aac495c89554bb61ee13a3a32823feec4bf5b4

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

LOG: [OpenMP][AIX] Affinity implementation for AIX (#84984)

This patch implements `affinity` for AIX, which is quite different from
platforms such as Linux.
- Setting CPU affinity through masks and related functions are not
supported. System call `bindprocessor()` is used to bind a thread to one
CPU per call.
- There are no system routines to get the affinity info of a thread. The
implementation of `get_system_affinity()` for AIX gets the mask of all
available CPUs, to be used as the full mask only.
- Topology is not available from the file system. It is obtained through
system SRAD (Scheduler Resource Allocation Domain).

This patch has run through the libomp LIT tests successfully with
`affinity` enabled.

(cherry picked from commit d394f3a162b871668d0c8e8bf6a94922fa8698ae)

Added: 


Modified: 
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_affinity.cpp
openmp/runtime/src/kmp_affinity.h
openmp/runtime/src/kmp_os.h
openmp/runtime/src/z_Linux_util.cpp
openmp/runtime/test/lit.cfg

Removed: 




diff  --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index e3a1e20731bbe0..46ee4c9fba7109 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -818,6 +818,7 @@ class KMPAffinity {
 typedef KMPAffinity::Mask kmp_affin_mask_t;
 extern KMPAffinity *__kmp_affinity_dispatch;
 
+#ifndef KMP_OS_AIX
 class kmp_affinity_raii_t {
   kmp_affin_mask_t *mask;
   bool restored;
@@ -842,6 +843,7 @@ class kmp_affinity_raii_t {
   }
   ~kmp_affinity_raii_t() { restore(); }
 };
+#endif // !KMP_OS_AIX
 
 // Declare local char buffers with this size for printing debug and info
 // messages, using __kmp_affinity_print_mask().
@@ -3911,7 +3913,7 @@ extern void __kmp_balanced_affinity(kmp_info_t *th, int 
team_size);
 #if KMP_WEIGHTED_ITERATIONS_SUPPORTED
 extern int __kmp_get_first_osid_with_ecore(void);
 #endif
-#if KMP_OS_LINUX || KMP_OS_FREEBSD
+#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_AIX
 extern int kmp_set_thread_affinity_mask_initial(void);
 #endif
 static inline void __kmp_assign_root_init_mask() {

diff  --git a/openmp/runtime/src/kmp_affinity.cpp 
b/openmp/runtime/src/kmp_affinity.cpp
index 6a41d34b023729..1ac541fbcaa707 100644
--- a/openmp/runtime/src/kmp_affinity.cpp
+++ b/openmp/runtime/src/kmp_affinity.cpp
@@ -2906,12 +2906,17 @@ static inline const char *__kmp_cpuinfo_get_envvar() {
 }
 
 // Parse /proc/cpuinfo (or an alternate file in the same format) to obtain the
-// affinity map.
+// affinity map. On AIX, the map is obtained through system SRAD (Scheduler
+// Resource Allocation Domain).
 static bool __kmp_affinity_create_cpuinfo_map(int *line,
   kmp_i18n_id_t *const msg_id) {
+  *msg_id = kmp_i18n_null;
+
+#if KMP_OS_AIX
+  unsigned num_records = __kmp_xproc;
+#else
   const char *filename = __kmp_cpuinfo_get_filename();
   const char *envvar = __kmp_cpuinfo_get_envvar();
-  *msg_id = kmp_i18n_null;
 
   if (__kmp_affinity.flags.verbose) {
 KMP_INFORM(AffParseFilename, "KMP_AFFINITY", filename);
@@ -2970,6 +2975,7 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
 *msg_id = kmp_i18n_str_CantRewindCpuinfo;
 return false;
   }
+#endif // KMP_OS_AIX
 
   // Allocate the array of records to store the proc info in.  The dummy
   // element at the end makes the logic in filling them out easier to code.
@@ -2999,6 +3005,99 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
 INIT_PROC_INFO(threadInfo[i]);
   }
 
+#if KMP_OS_AIX
+  int smt_threads;
+  lpar_info_format1_t cpuinfo;
+  unsigned num_avail = __kmp_xproc;
+
+  if (__kmp_affinity.flags.verbose)
+KMP_INFORM(AffParseFilename, "KMP_AFFINITY", "system info for topology");
+
+  // Get the number of SMT threads per core.
+  int retval =
+  lpar_get_info(LPAR_INFO_FORMAT1, &cpuinfo, sizeof(lpar_info_format1_t));
+  if (!retval)
+smt_threads = cpuinfo.smt_threads;
+  else {
+CLEANUP_THREAD_INFO;
+*msg_id = kmp_i18n_str_UnknownTopology;
+return false;
+  }
+
+  // Allocate a resource set containing available system resourses.
+  rsethandle_t sys_rset = rs_alloc(RS_SYSTEM);
+  if (sys_rset == NULL) {
+CLEANUP_THREAD_INFO;
+*msg_id = kmp_i18n_str_UnknownTopology;
+return false;
+  }
+  // Allocate a resource set for the SRAD info.
+  rsethandle_t srad = rs_alloc(RS_EMPTY);
+  if (srad == NULL) {
+rs_free(sys_rset);
+CLEANUP_THREAD_INFO;
+*msg_id = kmp_i18n_str_UnknownTopology;
+return false;
+  }
+
+  // Get the SRAD system detail level.
+  int sradsdl = rs_getinfo(NULL, R_SRADSDL, 0);
+  if (sradsdl < 0) {
+   

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

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

tstellar wrote:

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

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


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

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

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

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

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

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

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


[llvm-branch-commits] [mlir] e0f0c46 - [mlir][transform] replace original op to loop ops (#83537)

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

Author: Congcong Cai
Date: 2024-04-01T14:01:03-07:00
New Revision: e0f0c463b53987adab2e1d190c0e89165c126506

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

LOG: [mlir][transform] replace original op to loop ops (#83537)

(cherry picked from commit 0597644a6466ae9148b0b41cb8f95d5022e045c2)

Added: 


Modified: 
mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir

Removed: 




diff  --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp 
b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 140bdd1f2db361..be875297fc93ca 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -2092,6 +2092,7 @@ DiagnosedSilenceableFailure 
transform::ConvertToLoopsOp::applyToOne(
   scf::lowerToLoopsUsingSCFForOp(rewriter, target);
   if (failed(loops))
 return emitDefaultDefiniteFailure(target);
+  rewriter.eraseOp(target);
   return DiagnosedSilenceableFailure::success();
 }
 

diff  --git 
a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir 
b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
index 7969de0d456bb6..1b2c553b25ded0 100644
--- a/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
+++ b/mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
@@ -33,6 +33,7 @@ module attributes {transform.with_named_sequence} {
 //   CHECK: %[[MULF:.+]] = arith.mulf %[[LHS]], %[[RHS]]
 //   CHECK: %[[ADDF:.+]] = arith.addf %[[OUT]], %[[MULF]]
 //   CHECK: memref.store %[[ADDF]], %[[ARG2]][%[[IV0]], %[[IV1]]]
+//   CHECK-NOT:   linalg.matmul ins(%arg0, %arg1 : memref, 
memref)
 
 // -
 



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


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

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

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


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

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

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

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

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

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

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

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


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

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

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


[llvm-branch-commits] [clang] 76c7219 - [clang][Sema] Fix a CTAD regression after 42239d2e9 (#86914)

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

Author: Younan Zhang
Date: 2024-04-01T14:47:15-07:00
New Revision: 76c721994a11abe898848699ea82da267ebc8320

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

LOG: [clang][Sema] Fix a CTAD regression after 42239d2e9 (#86914)

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

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/concepts-friends.cpp
clang/test/SemaTemplate/ctad.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d4401a43c123e7..ebeb47a871e27b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1106,6 +1106,10 @@ Bug Fixes to C++ Support
 - Fix a crash when an unresolved overload set is encountered on the RHS of a 
``.*`` operator.
   (`#53815 `_)
 
+- Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
+  incorrect constraint substitution.
+  (`#86769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index a381d876a54c67..b619f5d729e86b 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1830,7 +1830,27 @@ static TemplateParameterList 
*GetTemplateParameterList(TemplateDecl *TD) {
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
-  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+  Decl *D = TD->getMostRecentDecl();
+  // C++11 [temp.param]p12:
+  // A default template argument shall not be specified in a friend class
+  // template declaration.
+  //
+  // Skip past friend *declarations* because they are not supposed to contain
+  // default template arguments. Moreover, these declarations may introduce
+  // template parameters living in 
diff erent template depths than the
+  // corresponding template parameters in TD, causing unmatched constraint
+  // substitution.
+  //
+  // FIXME: Diagnose such cases within a class template:
+  //  template 
+  //  struct S {
+  //template  friend struct C;
+  //  };
+  //  template struct S;
+  while (D->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None &&
+ D->getPreviousDecl())
+D = D->getPreviousDecl();
+  return cast(D)->getTemplateParameters();
 }
 
 DeclResult Sema::CheckClassTemplate(

diff  --git a/clang/test/SemaTemplate/concepts-friends.cpp 
b/clang/test/SemaTemplate/concepts-friends.cpp
index 255b0858917fb6..0b008811f13621 100644
--- a/clang/test/SemaTemplate/concepts-friends.cpp
+++ b/clang/test/SemaTemplate/concepts-friends.cpp
@@ -478,3 +478,29 @@ template  class Foo {
 };
 
 } // namespace FriendOfFriend
+
+namespace GH86769 {
+
+template 
+concept X = true;
+
+template  struct Y {
+  Y(T) {}
+  template  friend struct Y;
+  template  friend struct Y;
+  template  friend struct Y;
+};
+
+template 
+struct Z {
+  // FIXME: This is ill-formed per C++11 [temp.param]p12:
+  // A default template argument shall not be specified in a friend class
+  // template declaration.
+  template  friend struct Y;
+};
+
+template struct Y;
+template struct Z;
+Y y(1);
+
+}

diff  --git a/clang/test/SemaTemplate/ctad.cpp 
b/clang/test/SemaTemplate/ctad.cpp
index 388ed7d4cced18..ec144d4f44ba8c 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -53,4 +53,4 @@ X x;
 template struct Y { Y(T); };
 template struct Y ;
 Y y(1);
-};
+}



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


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

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

tstellar wrote:

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

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


[llvm-branch-commits] [compiler-rt] release/18.x: [tsan] Refine fstat{, 64} interceptors (#86625) (PR #87286)

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

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

Backport d5224b73ccd09a6759759791f58426b6acd4a2e2

Requested by: @MaskRay

>From f249092ef26d6fe9627b0158c7c15dee241226db Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 26 Mar 2024 14:09:39 -0700
Subject: [PATCH] [tsan] Refine fstat{,64} interceptors (#86625)

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

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

(cherry picked from commit d5224b73ccd09a6759759791f58426b6acd4a2e2)
---
 .../lib/tsan/rtl/tsan_interceptors_posix.cpp  | 43 ---
 1 file changed, 18 insertions(+), 25 deletions(-)

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

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


[llvm-branch-commits] [compiler-rt] release/18.x: [tsan] Refine fstat{, 64} interceptors (#86625) (PR #87286)

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

llvmbot wrote:

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

https://github.com/llvm/llvm-project/pull/87286
___
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] release/18.x: [tsan] Refine fstat{, 64} interceptors (#86625) (PR #87286)

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

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/87286
___
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] release/18.x: [tsan] Refine fstat{, 64} interceptors (#86625) (PR #87286)

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

llvmbot wrote:




@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (llvmbot)


Changes

Backport d5224b73ccd09a6759759791f58426b6acd4a2e2

Requested by: @MaskRay

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


1 Files Affected:

- (modified) compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp (+18-25) 


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

``




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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits


@@ -123,6 +123,9 @@ class BoltAddressTranslation {
   std::unordered_map>
   getBFBranches(uint64_t FuncOutputAddress) const;
 
+  /// Returns a secondary entry point id for a given function and offset.

maksfb wrote:

"... function at a given \p Address..."

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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {
+// The symbol could be a secondary entry in a cold fragment.
+ErrorOr SymbolValue = BC.getSymbolValue(*Symbol);
+if (SymbolValue.getError())

maksfb wrote:

Can we get a condition when `getFunctionForSymbol(Symbol)` return a function, 
but the symbol has no set value?

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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {

maksfb wrote:

```suggestion
  auto setBATSecondaryEntry = [&](const BinaryFunction &Callee) {
```

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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {
+// The symbol could be a secondary entry in a cold fragment.
+ErrorOr SymbolValue = BC.getSymbolValue(*Symbol);
+if (SymbolValue.getError())
+  return;
+
+// Containing function, not necessarily the same as symbol value.
+const uint64_t CalleeAddress = Callee->getAddress();
+const uint32_t OutputOffset = SymbolValue.get() - CalleeAddress;
+
+const uint64_t ParentAddress = BAT->fetchParentAddress(CalleeAddress);
+const uint64_t HotAddress = ParentAddress ? ParentAddress : CalleeAddress;
+
+if (const BinaryFunction *ParentBF =
+BC.getBinaryFunctionAtAddress(HotAddress))
+  CSI.DestId = ParentBF->getFunctionNumber();
+
+const uint32_t InputOffset =
+BAT->translate(CalleeAddress, OutputOffset, /*IsBranchSrc*/ false);
+
+if (!InputOffset)
+  return;
+
+CSI.EntryDiscriminator =
+BAT->getSecondaryEntryPointId(HotAddress, InputOffset) + 1;
+  };
+
   if (Symbol) {
 uint64_t EntryID = 0;
 if (const BinaryFunction *const Callee =
 BC.getFunctionForSymbol(Symbol, &EntryID)) {
   CSI.DestId = Callee->getFunctionNumber();
   CSI.EntryDiscriminator = EntryID;
+  if (BAT && BAT->isBATFunction(Callee->getAddress()))
+setBATSecondaryEntry(Callee);

maksfb wrote:

What do you think about modifying `BinaryContext::getFunctionForSymbol()` in 
the presence of BAT? We might move BAT into `BinaryContext` (from 
`RewriteInstance`) for that.

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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {
+// The symbol could be a secondary entry in a cold fragment.
+ErrorOr SymbolValue = BC.getSymbolValue(*Symbol);
+if (SymbolValue.getError())
+  return;
+
+// Containing function, not necessarily the same as symbol value.
+const uint64_t CalleeAddress = Callee->getAddress();
+const uint32_t OutputOffset = SymbolValue.get() - CalleeAddress;
+
+const uint64_t ParentAddress = BAT->fetchParentAddress(CalleeAddress);
+const uint64_t HotAddress = ParentAddress ? ParentAddress : CalleeAddress;
+
+if (const BinaryFunction *ParentBF =
+BC.getBinaryFunctionAtAddress(HotAddress))
+  CSI.DestId = ParentBF->getFunctionNumber();
+
+const uint32_t InputOffset =
+BAT->translate(CalleeAddress, OutputOffset, /*IsBranchSrc*/ false);
+
+if (!InputOffset)
+  return;
+
+CSI.EntryDiscriminator =
+BAT->getSecondaryEntryPointId(HotAddress, InputOffset) + 1;

maksfb wrote:

Can we modify `getSecondaryEntryPointId()` interface so that there's no need to 
"+1" here?

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


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

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


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {
+// The symbol could be a secondary entry in a cold fragment.
+ErrorOr SymbolValue = BC.getSymbolValue(*Symbol);
+if (SymbolValue.getError())

aaupov wrote:

We shouldn't. Let me just use `cantFail` wrapper here.

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


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

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


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {
+// The symbol could be a secondary entry in a cold fragment.
+ErrorOr SymbolValue = BC.getSymbolValue(*Symbol);
+if (SymbolValue.getError())
+  return;
+
+// Containing function, not necessarily the same as symbol value.
+const uint64_t CalleeAddress = Callee->getAddress();
+const uint32_t OutputOffset = SymbolValue.get() - CalleeAddress;
+
+const uint64_t ParentAddress = BAT->fetchParentAddress(CalleeAddress);
+const uint64_t HotAddress = ParentAddress ? ParentAddress : CalleeAddress;
+
+if (const BinaryFunction *ParentBF =
+BC.getBinaryFunctionAtAddress(HotAddress))
+  CSI.DestId = ParentBF->getFunctionNumber();
+
+const uint32_t InputOffset =
+BAT->translate(CalleeAddress, OutputOffset, /*IsBranchSrc*/ false);
+
+if (!InputOffset)
+  return;
+
+CSI.EntryDiscriminator =
+BAT->getSecondaryEntryPointId(HotAddress, InputOffset) + 1;
+  };
+
   if (Symbol) {
 uint64_t EntryID = 0;
 if (const BinaryFunction *const Callee =
 BC.getFunctionForSymbol(Symbol, &EntryID)) {
   CSI.DestId = Callee->getFunctionNumber();
   CSI.EntryDiscriminator = EntryID;
+  if (BAT && BAT->isBATFunction(Callee->getAddress()))
+setBATSecondaryEntry(Callee);

aaupov wrote:

I'd rather have `getFunctionForSymbol` stay the same, as we deal with BAT 
exclusively in profile-related code. 

Moving BAT to BC from RI would be an ergonomic change regardless.

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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits


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

maksfb wrote:

Does this happen when BAT maps are incomplete? Since BAT is part of the input, 
should this be an error instead?

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

aaupov wrote:

This is BAT writing code, so it's an internal invariant (should be an 
assertion).

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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits

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


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


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

2024-04-01 Thread Maksim Panchenko via llvm-branch-commits


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {
+// The symbol could be a secondary entry in a cold fragment.
+ErrorOr SymbolValue = BC.getSymbolValue(*Symbol);
+if (SymbolValue.getError())
+  return;
+
+// Containing function, not necessarily the same as symbol value.
+const uint64_t CalleeAddress = Callee->getAddress();
+const uint32_t OutputOffset = SymbolValue.get() - CalleeAddress;
+
+const uint64_t ParentAddress = BAT->fetchParentAddress(CalleeAddress);
+const uint64_t HotAddress = ParentAddress ? ParentAddress : CalleeAddress;
+
+if (const BinaryFunction *ParentBF =
+BC.getBinaryFunctionAtAddress(HotAddress))
+  CSI.DestId = ParentBF->getFunctionNumber();
+
+const uint32_t InputOffset =
+BAT->translate(CalleeAddress, OutputOffset, /*IsBranchSrc*/ false);
+
+if (!InputOffset)
+  return;
+
+CSI.EntryDiscriminator =
+BAT->getSecondaryEntryPointId(HotAddress, InputOffset) + 1;
+  };
+
   if (Symbol) {
 uint64_t EntryID = 0;
 if (const BinaryFunction *const Callee =
 BC.getFunctionForSymbol(Symbol, &EntryID)) {
   CSI.DestId = Callee->getFunctionNumber();
   CSI.EntryDiscriminator = EntryID;
+  if (BAT && BAT->isBATFunction(Callee->getAddress()))
+setBATSecondaryEntry(Callee);

maksfb wrote:

How about moving the adjustment logic into BAT then?

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


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

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

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

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

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

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

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

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

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

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

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


@@ -27,25 +28,55 @@ namespace bolt {
 
 /// Set CallSiteInfo destination fields from \p Symbol and return a target
 /// BinaryFunction for that symbol.
-static const BinaryFunction *setCSIDestination(const BinaryContext &BC,
-   yaml::bolt::CallSiteInfo &CSI,
-   const MCSymbol *Symbol) {
+static const BinaryFunction *
+setCSIDestination(const BinaryContext &BC, yaml::bolt::CallSiteInfo &CSI,
+  const MCSymbol *Symbol, const BoltAddressTranslation *BAT) {
   CSI.DestId = 0; // designated for unknown functions
   CSI.EntryDiscriminator = 0;
+  auto setBATSecondaryEntry = [&](const BinaryFunction *const Callee) {
+// The symbol could be a secondary entry in a cold fragment.
+ErrorOr SymbolValue = BC.getSymbolValue(*Symbol);
+if (SymbolValue.getError())
+  return;
+
+// Containing function, not necessarily the same as symbol value.
+const uint64_t CalleeAddress = Callee->getAddress();
+const uint32_t OutputOffset = SymbolValue.get() - CalleeAddress;
+
+const uint64_t ParentAddress = BAT->fetchParentAddress(CalleeAddress);
+const uint64_t HotAddress = ParentAddress ? ParentAddress : CalleeAddress;
+
+if (const BinaryFunction *ParentBF =
+BC.getBinaryFunctionAtAddress(HotAddress))
+  CSI.DestId = ParentBF->getFunctionNumber();
+
+const uint32_t InputOffset =
+BAT->translate(CalleeAddress, OutputOffset, /*IsBranchSrc*/ false);
+
+if (!InputOffset)
+  return;
+
+CSI.EntryDiscriminator =
+BAT->getSecondaryEntryPointId(HotAddress, InputOffset) + 1;
+  };
+
   if (Symbol) {
 uint64_t EntryID = 0;
 if (const BinaryFunction *const Callee =
 BC.getFunctionForSymbol(Symbol, &EntryID)) {
   CSI.DestId = Callee->getFunctionNumber();
   CSI.EntryDiscriminator = EntryID;
+  if (BAT && BAT->isBATFunction(Callee->getAddress()))
+setBATSecondaryEntry(Callee);

aaupov wrote:

Thanks, makes sense to do.

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


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

2024-04-01 Thread Younan Zhang via llvm-branch-commits

zyn0217 wrote:

@tstellar thanks!

> Fixed a regression in CTAD of clang 18 that a friend declaration that 
> befriends itself may cause incorrect constraint substitution.

is just fine to me.

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


[llvm-branch-commits] [mlir] 2898178 - Revert "[mlir] Reland the dialect conversion hanging use fix (#87297)"

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

Author: Mehdi Amini
Date: 2024-04-02T06:16:52+02:00
New Revision: 28981785ec148927c2773768e8fc1e6ddfe1a8d2

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

LOG: Revert "[mlir] Reland the dialect conversion hanging use fix (#87297)"

This reverts commit 49a4ec20a8be5888cbf225bab340dbaf204902c7.

Added: 


Modified: 
mlir/lib/Transforms/Utils/DialectConversion.cpp
mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir

Removed: 




diff  --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp 
b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 270ac0a0868960..8671c1008902a0 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -279,8 +279,6 @@ class CreateBlockRewrite : public BlockRewrite {
 auto &blockOps = block->getOperations();
 while (!blockOps.empty())
   blockOps.remove(blockOps.begin());
-for (auto arg : block->getArguments())
-  arg.dropAllUses();
 block->dropAllUses();
 if (block->getParent())
   block->erase();

diff  --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir 
b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir
index 6494e1b2719487..17eec593691860 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir
@@ -15,16 +15,3 @@ func.func @tensor_with_unknown_rank(%arg0: tensor<*xi8>) -> 
tensor<*xi8> {
   %0 = "tosa.abs"(%arg0) : (tensor<*xi8>) -> tensor<*xi8>
   return %0 : tensor<*xi8>
 }
-
-// -
-
-// CHECK-LABEL: @unranked_add
-func.func @unranked_add(%arg0 : tensor<10x10xf32> , %arg1 : tensor<10x10xf32>, 
%arg2 : tensor<*xf32>) -> (tensor<10x10xf32>) {
-  // expected-error@+3 {{failed to legalize operation 'tosa.add'}}
-  %reduce = tosa.reduce_max %arg0 {axis = 1 : i32} : (tensor<10x10xf32>) -> 
tensor<10x1xf32>
-  %1 = tosa.add %reduce, %arg1 : (tensor<10x1xf32>, tensor<10x10xf32>) -> 
tensor<10x10xf32>
-  %0 = tosa.add %1, %arg2 : (tensor<10x10xf32>, tensor<*xf32>) -> tensor<*xf32>
-  %2 = tosa.reshape %0 {new_shape = array} : (tensor<*xf32>) -> 
tensor<10x10xf32>
-  return %2 : tensor<10x10xf32>
-}
-



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


[llvm-branch-commits] [llvm] release/18.x: [X86] Fix miscompile in combineShiftRightArithmetic (PR #86728)

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

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


[llvm-branch-commits] [llvm] release/18.x: [SLP]Fix a crash if the argument of call was affected by minbitwidth analysis (PR #86731)

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

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


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

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

wangpc-pp wrote:

Ping. Are there any more comments?

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


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

2024-04-01 Thread Craig Topper via llvm-branch-commits


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

topperc wrote:

This copies v16-v17 to v22-23, but the copy was for 
`$v16_v17_v18_v19_v20_v21_v22 = COPY $v10_v11_v12_v13_v14_v15_v16` so v23 
shouldn't be touched.

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


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

2024-04-01 Thread Craig Topper via llvm-branch-commits


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

topperc wrote:

And the copy for v11 into v17 is missing.

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