[llvm-branch-commits] [clang] [libcxx] [clang] Finish implementation of P0522 (PR #96023)

2024-06-22 Thread Nikolas Klauser via llvm-branch-commits


@@ -18,5 +18,9 @@
 #include 
 #include 
 
-// expected-error@+1 {{template template argument has different template 
parameters than its corresponding template template parameter}}
-static_assert(!std::__is_specialization_v, 
std::array>);
+#if defined(__clang__) && __clang_major__ >= 19
+// expected-error@array:* {{could not match _Size against 
'type-parameter-0-0'}}
+#else
+// expected-error@#SA {{template template argument has different template 
parameters than its corresponding template template parameter}}
+#endif

philnik777 wrote:

I'd just add an `expected-error@*:*` instead.

https://github.com/llvm/llvm-project/pull/96023
___
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] b9ceb93 - Revert "[clang-format] Don't count template template parameter as declaration…"

2024-06-22 Thread via llvm-branch-commits

Author: Mehdi Amini
Date: 2024-06-22T14:18:31+02:00
New Revision: b9ceb93bc8d7fe75365f0d9002ed8b48a0884c85

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

LOG: Revert "[clang-format] Don't count template template parameter as 
declaration…"

This reverts commit 4a7bf42a9b83144db8a11ac06cce4da21166e6a2.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 89e134144d433..55c5ecee45e0c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -127,7 +127,7 @@ class AnnotatingParser {
SmallVector &Scopes)
   : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
 IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)),
-Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
+Keywords(Keywords), Scopes(Scopes) {
 assert(IsCpp == LangOpts.CXXOperatorNames);
 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
 resetTokenMetadata();
@@ -1266,22 +1266,16 @@ class AnnotatingParser {
   }
 
   bool parseTemplateDeclaration() {
-if (!CurrentToken || CurrentToken->isNot(tok::less))
-  return false;
-
-CurrentToken->setType(TT_TemplateOpener);
-next();
-
-TemplateDeclarationDepth++;
-const bool WellFormed = parseAngle();
-TemplateDeclarationDepth--;
-if (!WellFormed)
-  return false;
-
-if (CurrentToken && TemplateDeclarationDepth == 0)
-  CurrentToken->Previous->ClosesTemplateDeclaration = true;
-
-return true;
+if (CurrentToken && CurrentToken->is(tok::less)) {
+  CurrentToken->setType(TT_TemplateOpener);
+  next();
+  if (!parseAngle())
+return false;
+  if (CurrentToken)
+CurrentToken->Previous->ClosesTemplateDeclaration = true;
+  return true;
+}
+return false;
   }
 
   bool consumeToken() {
@@ -3097,8 +3091,6 @@ class AnnotatingParser {
   // same decision irrespective of the decisions for tokens leading up to it.
   // Store this information to prevent this from causing exponential runtime.
   llvm::SmallPtrSet NonTemplateLess;
-
-  int TemplateDeclarationDepth;
 };
 
 static const int PrecedenceUnaryOperator = prec::PointerToMember + 1;

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index d3b310fe59527..12c4b7fdd5ac2 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -584,23 +584,6 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsNonTemplateAngleBrackets) {
   EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator);
 }
 
-TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) {
-  auto Tokens = annotate("template  typename X,\n"
- "  template  class Y,\n"
- "  typename... T>\n"
- "class A {};");
-  ASSERT_EQ(Tokens.size(), 28u) << Tokens;
-  EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener);
-  EXPECT_TOKEN(Tokens[3], tok::less, TT_TemplateOpener);
-  EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
-  EXPECT_FALSE(Tokens[6]->ClosesTemplateDeclaration);
-  EXPECT_TOKEN(Tokens[11], tok::less, TT_TemplateOpener);
-  EXPECT_TOKEN(Tokens[14], tok::greater, TT_TemplateCloser);
-  EXPECT_FALSE(Tokens[14]->ClosesTemplateDeclaration);
-  EXPECT_TOKEN(Tokens[21], tok::greater, TT_TemplateCloser);
-  EXPECT_TRUE(Tokens[21]->ClosesTemplateDeclaration);
-}
-
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");



___
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][Conversion] `FuncToLLVM`: Simplify bare-pointer handling (PR #96393)

2024-06-22 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer created 
https://github.com/llvm/llvm-project/pull/96393

Before this commit, there used to be a workaround in the `func.func`/`gpu.func` 
op lowering when the bare-pointer calling convention is enabled. This 
workaround "patched up" the argument materializations for memref arguments. 
This can be done directly in the argument materialization functions (as the 
TODOs in the code base indicate).

This commit effectively reverts back to the old implementation 
(a664c14001fa2359604527084c91d0864aa131a4) and adds additional checks to make 
sure that bare pointers are used only for function entry block arguments.


>From f65911a2b08c538d24a9b2044123390ceae5b4b5 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Sat, 22 Jun 2024 14:54:21 +0200
Subject: [PATCH] [mlir][Conversion] `FuncToLLVM`: Simplify bare-pointer
 handling

Before this commit, there used to be a workaround in the `func.func`/`gpu.func` 
op lowering when the bare-pointer calling convention was enabled. This 
workaround "patched up" the argument materializations for memref arguments. 
This can be done directly in the argument materialization functions (as the 
TODOs in the code base indicate).
---
 mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp |  53 
 .../Conversion/GPUCommon/GPUOpsLowering.cpp   | 128 +++---
 .../Conversion/LLVMCommon/TypeConverter.cpp   |  22 ++-
 3 files changed, 66 insertions(+), 137 deletions(-)

diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp 
b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 744236692fbb6..efb80467369a2 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -268,55 +268,6 @@ static void wrapExternalFunction(OpBuilder &builder, 
Location loc,
   }
 }
 
-/// Modifies the body of the function to construct the `MemRefDescriptor` from
-/// the bare pointer calling convention lowering of `memref` types.
-static void modifyFuncOpToUseBarePtrCallingConv(
-ConversionPatternRewriter &rewriter, Location loc,
-const LLVMTypeConverter &typeConverter, LLVM::LLVMFuncOp funcOp,
-TypeRange oldArgTypes) {
-  if (funcOp.getBody().empty())
-return;
-
-  // Promote bare pointers from memref arguments to memref descriptors at the
-  // beginning of the function so that all the memrefs in the function have a
-  // uniform representation.
-  Block *entryBlock = &funcOp.getBody().front();
-  auto blockArgs = entryBlock->getArguments();
-  assert(blockArgs.size() == oldArgTypes.size() &&
- "The number of arguments and types doesn't match");
-
-  OpBuilder::InsertionGuard guard(rewriter);
-  rewriter.setInsertionPointToStart(entryBlock);
-  for (auto it : llvm::zip(blockArgs, oldArgTypes)) {
-BlockArgument arg = std::get<0>(it);
-Type argTy = std::get<1>(it);
-
-// Unranked memrefs are not supported in the bare pointer calling
-// convention. We should have bailed out before in the presence of
-// unranked memrefs.
-assert(!isa(argTy) &&
-   "Unranked memref is not supported");
-auto memrefTy = dyn_cast(argTy);
-if (!memrefTy)
-  continue;
-
-// Replace barePtr with a placeholder (undef), promote barePtr to a ranked
-// or unranked memref descriptor and replace placeholder with the last
-// instruction of the memref descriptor.
-// TODO: The placeholder is needed to avoid replacing barePtr uses in the
-// MemRef descriptor instructions. We may want to have a utility in the
-// rewriter to properly handle this use case.
-Location loc = funcOp.getLoc();
-auto placeholder = rewriter.create(
-loc, typeConverter.convertType(memrefTy));
-rewriter.replaceUsesOfBlockArgument(arg, placeholder);
-
-Value desc = MemRefDescriptor::fromStaticShape(rewriter, loc, 
typeConverter,
-   memrefTy, arg);
-rewriter.replaceOp(placeholder, {desc});
-  }
-}
-
 FailureOr
 mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 ConversionPatternRewriter &rewriter,
@@ -462,10 +413,6 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 wrapForExternalCallers(rewriter, funcOp->getLoc(), converter, funcOp,
newFuncOp);
 }
-  } else {
-modifyFuncOpToUseBarePtrCallingConv(
-rewriter, funcOp->getLoc(), converter, newFuncOp,
-llvm::cast(funcOp.getFunctionType()).getInputs());
   }
 
   return newFuncOp;
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp 
b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
index 7ea05b7e7f6c1..6053e34f30a41 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
@@ -182,35 +182,6 @@ GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp 
gpuFuncOp, OpAdaptor adaptor,
  &signatureConversion)))
 return failure();
 
-  /

[llvm-branch-commits] [mlir] [mlir][Conversion] `FuncToLLVM`: Simplify bare-pointer handling (PR #96393)

2024-06-22 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-gpu

Author: Matthias Springer (matthias-springer)


Changes

Before this commit, there used to be a workaround in the `func.func`/`gpu.func` 
op lowering when the bare-pointer calling convention is enabled. This 
workaround "patched up" the argument materializations for memref arguments. 
This can be done directly in the argument materialization functions (as the 
TODOs in the code base indicate).

This commit effectively reverts back to the old implementation 
(a664c14001fa2359604527084c91d0864aa131a4) and adds additional checks to make 
sure that bare pointers are used only for function entry block arguments.


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


3 Files Affected:

- (modified) mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp (-53) 
- (modified) mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp (+49-79) 
- (modified) mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp (+17-5) 


``diff
diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp 
b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 744236692fbb6..efb80467369a2 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -268,55 +268,6 @@ static void wrapExternalFunction(OpBuilder &builder, 
Location loc,
   }
 }
 
-/// Modifies the body of the function to construct the `MemRefDescriptor` from
-/// the bare pointer calling convention lowering of `memref` types.
-static void modifyFuncOpToUseBarePtrCallingConv(
-ConversionPatternRewriter &rewriter, Location loc,
-const LLVMTypeConverter &typeConverter, LLVM::LLVMFuncOp funcOp,
-TypeRange oldArgTypes) {
-  if (funcOp.getBody().empty())
-return;
-
-  // Promote bare pointers from memref arguments to memref descriptors at the
-  // beginning of the function so that all the memrefs in the function have a
-  // uniform representation.
-  Block *entryBlock = &funcOp.getBody().front();
-  auto blockArgs = entryBlock->getArguments();
-  assert(blockArgs.size() == oldArgTypes.size() &&
- "The number of arguments and types doesn't match");
-
-  OpBuilder::InsertionGuard guard(rewriter);
-  rewriter.setInsertionPointToStart(entryBlock);
-  for (auto it : llvm::zip(blockArgs, oldArgTypes)) {
-BlockArgument arg = std::get<0>(it);
-Type argTy = std::get<1>(it);
-
-// Unranked memrefs are not supported in the bare pointer calling
-// convention. We should have bailed out before in the presence of
-// unranked memrefs.
-assert(!isa(argTy) &&
-   "Unranked memref is not supported");
-auto memrefTy = dyn_cast(argTy);
-if (!memrefTy)
-  continue;
-
-// Replace barePtr with a placeholder (undef), promote barePtr to a ranked
-// or unranked memref descriptor and replace placeholder with the last
-// instruction of the memref descriptor.
-// TODO: The placeholder is needed to avoid replacing barePtr uses in the
-// MemRef descriptor instructions. We may want to have a utility in the
-// rewriter to properly handle this use case.
-Location loc = funcOp.getLoc();
-auto placeholder = rewriter.create(
-loc, typeConverter.convertType(memrefTy));
-rewriter.replaceUsesOfBlockArgument(arg, placeholder);
-
-Value desc = MemRefDescriptor::fromStaticShape(rewriter, loc, 
typeConverter,
-   memrefTy, arg);
-rewriter.replaceOp(placeholder, {desc});
-  }
-}
-
 FailureOr
 mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 ConversionPatternRewriter &rewriter,
@@ -462,10 +413,6 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 wrapForExternalCallers(rewriter, funcOp->getLoc(), converter, funcOp,
newFuncOp);
 }
-  } else {
-modifyFuncOpToUseBarePtrCallingConv(
-rewriter, funcOp->getLoc(), converter, newFuncOp,
-llvm::cast(funcOp.getFunctionType()).getInputs());
   }
 
   return newFuncOp;
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp 
b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
index 7ea05b7e7f6c1..6053e34f30a41 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
@@ -182,35 +182,6 @@ GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp 
gpuFuncOp, OpAdaptor adaptor,
  &signatureConversion)))
 return failure();
 
-  // If bare memref pointers are being used, remap them back to memref
-  // descriptors This must be done after signature conversion to get rid of the
-  // unrealized casts.
-  if (getTypeConverter()->getOptions().useBarePtrCallConv) {
-OpBuilder::InsertionGuard guard(rewriter);
-rewriter.setInsertionPointToStart(&llvmFuncOp.getBody().front());
-for (const auto [idx, argTy] :
- llvm::enumerate(gpuFuncOp.getArgumentTypes())) {
- 

[llvm-branch-commits] [mlir] [mlir][Conversion] `FuncToLLVM`: Simplify bare-pointer handling (PR #96393)

2024-06-22 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-llvm

Author: Matthias Springer (matthias-springer)


Changes

Before this commit, there used to be a workaround in the `func.func`/`gpu.func` 
op lowering when the bare-pointer calling convention is enabled. This 
workaround "patched up" the argument materializations for memref arguments. 
This can be done directly in the argument materialization functions (as the 
TODOs in the code base indicate).

This commit effectively reverts back to the old implementation 
(a664c14001fa2359604527084c91d0864aa131a4) and adds additional checks to make 
sure that bare pointers are used only for function entry block arguments.


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


3 Files Affected:

- (modified) mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp (-53) 
- (modified) mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp (+49-79) 
- (modified) mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp (+17-5) 


``diff
diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp 
b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 744236692fbb6..efb80467369a2 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -268,55 +268,6 @@ static void wrapExternalFunction(OpBuilder &builder, 
Location loc,
   }
 }
 
-/// Modifies the body of the function to construct the `MemRefDescriptor` from
-/// the bare pointer calling convention lowering of `memref` types.
-static void modifyFuncOpToUseBarePtrCallingConv(
-ConversionPatternRewriter &rewriter, Location loc,
-const LLVMTypeConverter &typeConverter, LLVM::LLVMFuncOp funcOp,
-TypeRange oldArgTypes) {
-  if (funcOp.getBody().empty())
-return;
-
-  // Promote bare pointers from memref arguments to memref descriptors at the
-  // beginning of the function so that all the memrefs in the function have a
-  // uniform representation.
-  Block *entryBlock = &funcOp.getBody().front();
-  auto blockArgs = entryBlock->getArguments();
-  assert(blockArgs.size() == oldArgTypes.size() &&
- "The number of arguments and types doesn't match");
-
-  OpBuilder::InsertionGuard guard(rewriter);
-  rewriter.setInsertionPointToStart(entryBlock);
-  for (auto it : llvm::zip(blockArgs, oldArgTypes)) {
-BlockArgument arg = std::get<0>(it);
-Type argTy = std::get<1>(it);
-
-// Unranked memrefs are not supported in the bare pointer calling
-// convention. We should have bailed out before in the presence of
-// unranked memrefs.
-assert(!isa(argTy) &&
-   "Unranked memref is not supported");
-auto memrefTy = dyn_cast(argTy);
-if (!memrefTy)
-  continue;
-
-// Replace barePtr with a placeholder (undef), promote barePtr to a ranked
-// or unranked memref descriptor and replace placeholder with the last
-// instruction of the memref descriptor.
-// TODO: The placeholder is needed to avoid replacing barePtr uses in the
-// MemRef descriptor instructions. We may want to have a utility in the
-// rewriter to properly handle this use case.
-Location loc = funcOp.getLoc();
-auto placeholder = rewriter.create(
-loc, typeConverter.convertType(memrefTy));
-rewriter.replaceUsesOfBlockArgument(arg, placeholder);
-
-Value desc = MemRefDescriptor::fromStaticShape(rewriter, loc, 
typeConverter,
-   memrefTy, arg);
-rewriter.replaceOp(placeholder, {desc});
-  }
-}
-
 FailureOr
 mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 ConversionPatternRewriter &rewriter,
@@ -462,10 +413,6 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 wrapForExternalCallers(rewriter, funcOp->getLoc(), converter, funcOp,
newFuncOp);
 }
-  } else {
-modifyFuncOpToUseBarePtrCallingConv(
-rewriter, funcOp->getLoc(), converter, newFuncOp,
-llvm::cast(funcOp.getFunctionType()).getInputs());
   }
 
   return newFuncOp;
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp 
b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
index 7ea05b7e7f6c1..6053e34f30a41 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
@@ -182,35 +182,6 @@ GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp 
gpuFuncOp, OpAdaptor adaptor,
  &signatureConversion)))
 return failure();
 
-  // If bare memref pointers are being used, remap them back to memref
-  // descriptors This must be done after signature conversion to get rid of the
-  // unrealized casts.
-  if (getTypeConverter()->getOptions().useBarePtrCallConv) {
-OpBuilder::InsertionGuard guard(rewriter);
-rewriter.setInsertionPointToStart(&llvmFuncOp.getBody().front());
-for (const auto [idx, argTy] :
- llvm::enumerate(gpuFuncOp.getArgumentTypes())) {
-  auto memrefTy = dyn_cast

[llvm-branch-commits] [mlir] [mlir][Conversion] `FuncToLLVM`: Simplify bare-pointer handling (PR #96393)

2024-06-22 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer updated 
https://github.com/llvm/llvm-project/pull/96393

>From 2d838580bf8c17ea7a17d73415b3c64c1775b37d Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Sat, 22 Jun 2024 14:54:21 +0200
Subject: [PATCH] [mlir][Conversion] `FuncToLLVM`: Simplify bare-pointer
 handling

Before this commit, there used to be a workaround in the `func.func`/`gpu.func` 
op lowering when the bare-pointer calling convention was enabled. This 
workaround "patched up" the argument materializations for memref arguments. 
This can be done directly in the argument materialization functions (as the 
TODOs in the code base indicate).
---
 mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp | 53 ---
 .../Conversion/GPUCommon/GPUOpsLowering.cpp   | 29 --
 .../Conversion/LLVMCommon/TypeConverter.cpp   | 22 ++--
 3 files changed, 17 insertions(+), 87 deletions(-)

diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp 
b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 744236692fbb6..efb80467369a2 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -268,55 +268,6 @@ static void wrapExternalFunction(OpBuilder &builder, 
Location loc,
   }
 }
 
-/// Modifies the body of the function to construct the `MemRefDescriptor` from
-/// the bare pointer calling convention lowering of `memref` types.
-static void modifyFuncOpToUseBarePtrCallingConv(
-ConversionPatternRewriter &rewriter, Location loc,
-const LLVMTypeConverter &typeConverter, LLVM::LLVMFuncOp funcOp,
-TypeRange oldArgTypes) {
-  if (funcOp.getBody().empty())
-return;
-
-  // Promote bare pointers from memref arguments to memref descriptors at the
-  // beginning of the function so that all the memrefs in the function have a
-  // uniform representation.
-  Block *entryBlock = &funcOp.getBody().front();
-  auto blockArgs = entryBlock->getArguments();
-  assert(blockArgs.size() == oldArgTypes.size() &&
- "The number of arguments and types doesn't match");
-
-  OpBuilder::InsertionGuard guard(rewriter);
-  rewriter.setInsertionPointToStart(entryBlock);
-  for (auto it : llvm::zip(blockArgs, oldArgTypes)) {
-BlockArgument arg = std::get<0>(it);
-Type argTy = std::get<1>(it);
-
-// Unranked memrefs are not supported in the bare pointer calling
-// convention. We should have bailed out before in the presence of
-// unranked memrefs.
-assert(!isa(argTy) &&
-   "Unranked memref is not supported");
-auto memrefTy = dyn_cast(argTy);
-if (!memrefTy)
-  continue;
-
-// Replace barePtr with a placeholder (undef), promote barePtr to a ranked
-// or unranked memref descriptor and replace placeholder with the last
-// instruction of the memref descriptor.
-// TODO: The placeholder is needed to avoid replacing barePtr uses in the
-// MemRef descriptor instructions. We may want to have a utility in the
-// rewriter to properly handle this use case.
-Location loc = funcOp.getLoc();
-auto placeholder = rewriter.create(
-loc, typeConverter.convertType(memrefTy));
-rewriter.replaceUsesOfBlockArgument(arg, placeholder);
-
-Value desc = MemRefDescriptor::fromStaticShape(rewriter, loc, 
typeConverter,
-   memrefTy, arg);
-rewriter.replaceOp(placeholder, {desc});
-  }
-}
-
 FailureOr
 mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 ConversionPatternRewriter &rewriter,
@@ -462,10 +413,6 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
 wrapForExternalCallers(rewriter, funcOp->getLoc(), converter, funcOp,
newFuncOp);
 }
-  } else {
-modifyFuncOpToUseBarePtrCallingConv(
-rewriter, funcOp->getLoc(), converter, newFuncOp,
-llvm::cast(funcOp.getFunctionType()).getInputs());
   }
 
   return newFuncOp;
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp 
b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
index 3e6fcc076fb4d..6053e34f30a41 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
@@ -182,35 +182,6 @@ GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp 
gpuFuncOp, OpAdaptor adaptor,
  &signatureConversion)))
 return failure();
 
-  // If bare memref pointers are being used, remap them back to memref
-  // descriptors This must be done after signature conversion to get rid of the
-  // unrealized casts.
-  if (getTypeConverter()->getOptions().useBarePtrCallConv) {
-OpBuilder::InsertionGuard guard(rewriter);
-rewriter.setInsertionPointToStart(&llvmFuncOp.getBody().front());
-for (const auto [idx, argTy] :
- llvm::enumerate(gpuFuncOp.getArgumentTypes())) {
-  auto memrefTy = dyn_cast(argTy);
-  if (!memrefTy)
-continue;
-  assert(memrefTy.has

[llvm-branch-commits] [llvm] [AMDGPU] Codegen support for constrained multi-dword sloads (PR #96163)

2024-06-22 Thread Christudasan Devadasan via llvm-branch-commits


@@ -867,13 +867,104 @@ def SMRDBufferImm   : ComplexPattern;
 def SMRDBufferImm32 : ComplexPattern;
 def SMRDBufferSgprImm : ComplexPattern;
 
+class SMRDAlignedLoadPat : PatFrag <(ops node:$ptr), (Op 
node:$ptr), [{
+  // Returns true if it is a naturally aligned multi-dword load.
+  LoadSDNode *Ld = cast(N);
+  unsigned Size = Ld->getMemoryVT().getStoreSize();
+  return (Size <= 4) || (Ld->getAlign().value() >= PowerOf2Ceil(Size));

cdevadas wrote:

Isn't it 12 >= 16 or 16 >=16?
The PowerOf2Ceil intends to catch the first case where the specified Align is 
smaller than its natural alignment.

https://github.com/llvm/llvm-project/pull/96163
___
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] [Hashing] Use a non-deterministic seed (PR #96282)

2024-06-22 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/96282


___
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] [Hashing] Use a non-deterministic seed (PR #96282)

2024-06-22 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/96282
___
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] [Hashing] Use a non-deterministic seed (PR #96282)

2024-06-22 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/96282


___
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++] Implement std::move_only_function (P0288R9) (PR #94670)

2024-06-22 Thread Adrian Vogelsgesang via llvm-branch-commits


@@ -0,0 +1,93 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___FUNCTIONAL_MOVE_ONLY_FUNCTION_H
+#define _LIBCPP___FUNCTIONAL_MOVE_ONLY_FUNCTION_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+// move_only_function design:
+//
+// move_only_function has a small buffer with a size of `3 * sizeof(void*)` 
bytes. This buffer can only be used when the
+// object that should be stored is trivially relocatable (currently only when 
it is trivially move constructible and
+// trivially destructible). There is also a bool in the lower bits of the vptr 
stored which is set when the contained
+// object is not trivially destructible.
+//
+// trivially relocatable: It would also be possible to store 
nothrow_move_constructible types, but that would mean
+// that move_only_function itself would not be trivially relocatable anymore. 
The decision to keep move_only_function
+// trivially relocatable was made because we expect move_only_function to be 
mostly used to store a functor. To only
+// forward functors there is std::function_ref (not voted in yet, expected in 
C++26).
+//
+// buffer size: We did a survey of six implementations from various vendors. 
Three of them had a buffer size of 24 bytes
+// on 64 bit systems. This also allows storing a std::string or std::vector 
inside the small buffer (once the compiler
+// has full support of trivially_relocatable annotations).
+//
+// trivially-destructible bit: This allows us to keep the overall binary size 
smaller because we don't have to store
+// a pointer to a noop function inside the vtable. It also avoids loading the 
vtable during destruction, potentially
+// resulting in fewer cache misses. The downside is that calling the function 
now also requires setting the lower bits
+// of the pointer to zero, but this is a very fast operation on modern CPUs.

vogelsgesang wrote:

Does the same also apply for `function_ref`? Should it be possible to turn a 
`move_only_function` / `copyable_function` into a `function_ref` without 
double-wrapping?

https://github.com/llvm/llvm-project/pull/94670
___
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] Hash-based function matching (PR #95821)

2024-06-22 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/95821
___
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] Hash-based function matching (PR #95821)

2024-06-22 Thread Amir Ayupov via llvm-branch-commits


@@ -439,6 +482,11 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
 
   BC.setNumUnusedProfiledObjects(NumUnused);
 
+  if (opts::Lite)
+for (BinaryFunction *BF : BC.getAllBinaryFunctions())
+  if (ProfiledFunctions.find(BF) == ProfiledFunctions.end())

aaupov wrote:

At this point we're supposed to have attached the profile to BF:
```suggestion
  if (!BF->hasProfile())
```

https://github.com/llvm/llvm-project/pull/95821
___
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] Hash-based function matching (PR #95821)

2024-06-22 Thread Amir Ayupov via llvm-branch-commits


@@ -0,0 +1,65 @@
+## Test YAMLProfileReader support for pass-through blocks in non-matching 
edges:
+## match the profile edge A -> C to the CFG with blocks A -> B -> C.

aaupov wrote:

Please update the test description.

https://github.com/llvm/llvm-project/pull/95821
___
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] Hash-based function matching (PR #95821)

2024-06-22 Thread Amir Ayupov via llvm-branch-commits

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

LG overall, with a couple of nits. 

https://github.com/llvm/llvm-project/pull/95821
___
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] Hash-based function matching (PR #95821)

2024-06-22 Thread Amir Ayupov via llvm-branch-commits


@@ -374,15 +386,34 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
 // the profile.
 Function.setExecutionCount(BinaryFunction::COUNT_NO_PROFILE);
 
-// Recompute hash once per function.
-if (!opts::IgnoreHash)
-  Function.computeHash(YamlBP.Header.IsDFSOrder,
-   YamlBP.Header.HashFunction);
-
-if (profileMatches(YamlBF, Function))
+if (profileMatches(YamlBF, Function)) {
   matchProfileToFunction(YamlBF, Function);
+  ++MatchedWithExactName;
+}
   }
 
+  // Uses the strict hash of profiled and binary functions to match functions
+  // that are not matched by name or common name.
+  if (opts::MatchProfileWithFunctionHash) {
+std::unordered_map StrictHashToBF;
+StrictHashToBF.reserve(BC.getBinaryFunctions().size());
+
+for (auto &[_, BF] : BC.getBinaryFunctions())
+  StrictHashToBF[BF.getHash()] = &BF;
+
+for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
+  if (YamlBF.Used)
+continue;
+  auto It = StrictHashToBF.find(YamlBF.Hash);
+  if (It != StrictHashToBF.end() && !ProfiledFunctions.count(It->second)) {
+auto *BF = It->second;

aaupov wrote:

nit: LLVM's guideline is to use explicit type here: [LLVM Coding 
Standards](https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable)

https://github.com/llvm/llvm-project/pull/95821
___
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] Hash-based function matching (PR #95821)

2024-06-22 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/95821

>From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:39:02 -0700
Subject: [PATCH 01/19] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index f0fcb1c130002..2bca83c9d11ec 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
 
   for (auto& [_, BF] : BC.getBinaryFunctions()) {
+if (!ProfiledFunctions.count(&BF))
+  continue;
 StrictBinaryFunctionHashes[BF.getHash()] = &BF;
   }
 

>From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:39:39 -0700
Subject: [PATCH 02/19] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 2bca83c9d11ec..56474a67307ed 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
 
   // Uses the strict hash of profiled and binary functions to match functions
   // that are not matched by name or common name.
-  std::unordered_map StrictBinaryFunctionHashes;
+  std::unordered_map StrictBinaryFunctionHashes;
   StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
 
-  for (auto& [_, BF] : BC.getBinaryFunctions()) {
+  for (auto &[_, BF] : BC.getBinaryFunctions()) {
 if (!ProfiledFunctions.count(&BF))
   continue;
 StrictBinaryFunctionHashes[BF.getHash()] = &BF;
@@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
 
   for (auto YamlBF : YamlBP.Functions) {
 auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash);
-if (It != StrictBinaryFunctionHashes.end() && 
!ProfiledFunctions.count(It->second)) {
+if (It != StrictBinaryFunctionHashes.end() &&
+!ProfiledFunctions.count(It->second)) {
   auto *BF = It->second;
   matchProfileToFunction(YamlBF, *BF);
 }

>From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:55:58 -0700
Subject: [PATCH 03/19] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp   | 2 +-
 bolt/test/X86/profile-passthrough-block.test | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 56474a67307ed..779d60bce3b66 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
 
   for (auto &[_, BF] : BC.getBinaryFunctions()) {
-if (!ProfiledFunctions.count(&BF))
+if (ProfiledFunctions.count(&BF))
   continue;
 StrictBinaryFunctionHashes[BF.getHash()] = &BF;
   }
diff --git a/bolt/test/X86/profile-passthrough-block.test 
b/bolt/test/X86/profile-passthrough-block.test
index 1b875885260dc..ed2a8117ddfc4 100644
--- a/bolt/test/X86/profile-passthrough-block.test
+++ b/bolt/test/X86/profile-passthrough-block.test
@@ -57,7 +57,7 @@ header:
 functions:
   - name:main
 fid: 0
-hash:0x
+hash:0x0001
 exec:1
 nblocks: 6
 blocks:

>From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:58:22 -0700
Subject: [PATCH 04/19] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 779d60bce3b66..e3d30bfdb74e4 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   }
 
   for (auto YamlBF : YamlBP.Functions) {
+if (YamlBF.Used)
+  continue;
 auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash);
 if (It != StrictBinaryFunctionHashes.end() &&
 !ProfiledFunctions.count(It->second)) {

>From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 16:00:27 -0700
Subject: [PATCH 05/19] spr amend

Created using spr 1.3.4
---
 bolt/test/X86/profile-passthrough-block.test | 2 +-
 1 file changed, 1 insertion(+), 1 deleti