[llvm-branch-commits] [mlir] [MLIR][OpenMP] Emit descriptive errors for all unsupported clauses (PR #114037)

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

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

This patch improves error reporting in the MLIR to LLVM IR translation pass for 
the 'omp' dialect by emitting descriptive errors when encountering clauses not 
yet supported by that pass.

Additionally, not-yet-implemented errors previously missing for some clauses 
are added, to avoid silently ignoring them.

Error messages related to inlining of `omp.private` and `omp.declare_reduction` 
regions have been updated to use the same format.

>From b96e79258a9b54e4d9962bc250af2138e25fec7b Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 29 Oct 2024 11:18:07 +
Subject: [PATCH] [MLIR][OpenMP] Emit descriptive errors for all unsupported
 clauses

This patch improves error reporting in the MLIR to LLVM IR translation pass for
the 'omp' dialect by emitting descriptive errors when encountering clauses not
yet supported by that pass.

Additionally, not-yet-implemented errors previously missing for some clauses
are added, to avoid silently ignoring them.

Error messages related to inlining of `omp.private` and `omp.declare_reduction`
regions have been updated to use the same format.
---
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  | 340 --
 mlir/test/Target/LLVMIR/openmp-todo.mlir  | 212 +--
 2 files changed, 421 insertions(+), 131 deletions(-)

diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 1df7b3c083a3a7..fc7d11b33ab242 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -571,7 +571,8 @@ makeReductionGen(omp::DeclareReductionOp decl, 
llvm::IRBuilderBase &builder,
 if (failed(inlineConvertOmpRegions(decl.getReductionRegion(),
"omp.reduction.nonatomic.body", builder,
moduleTranslation, &phis)))
-  return llvm::createStringError("failed reduction region translation");
+  return llvm::createStringError(
+  "failed to inline `combiner` region of `omp.declare_reduction`");
 assert(phis.size() == 1);
 result = phis[0];
 return builder.saveIP();
@@ -604,7 +605,8 @@ makeAtomicReductionGen(omp::DeclareReductionOp decl,
 if (failed(inlineConvertOmpRegions(decl.getAtomicReductionRegion(),
"omp.reduction.atomic.body", builder,
moduleTranslation, &phis)))
-  return llvm::createStringError("failed reduction region translation");
+  return llvm::createStringError(
+  "failed to inline `atomic` region of `omp.declare_reduction`");
 assert(phis.empty());
 return builder.saveIP();
   };
@@ -640,6 +642,13 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase 
&builder,
   return success();
 }
 
+static LogicalResult orderedRegionSupported(omp::OrderedRegionOp op) {
+  if (op.getParLevelSimd())
+return op.emitError("parallelization-level clause set not yet supported");
+
+  return success();
+}
+
 /// Converts an OpenMP 'ordered_region' operation into LLVM IR using
 /// OpenMPIRBuilder.
 static LogicalResult
@@ -648,9 +657,8 @@ convertOmpOrderedRegion(Operation &opInst, 
llvm::IRBuilderBase &builder,
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
   auto orderedRegionOp = cast(opInst);
 
-  // TODO: The code generation for ordered simd directive is not supported yet.
-  if (orderedRegionOp.getParLevelSimd())
-return opInst.emitError("unhandled clauses for translation to LLVM IR");
+  if (failed(orderedRegionSupported(orderedRegionOp)))
+return failure();
 
   auto bodyGenCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP) {
 // OrderedOp has only one region associated with it.
@@ -717,9 +725,10 @@ allocReductionVars(T loop, ArrayRef 
reductionArgs,
   SmallVector phis;
   if (failed(inlineConvertOmpRegions(allocRegion, "omp.reduction.alloc",
  builder, moduleTranslation, &phis)))
-return failure();
-  assert(phis.size() == 1 && "expected one allocation to be yielded");
+return loop.emitError(
+"failed to inline `alloc` region of `omp.declare_reduction`");
 
+  assert(phis.size() == 1 && "expected one allocation to be yielded");
   builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
 
   // Allocate reduction variable (which is a pointer to the real reduction
@@ -985,6 +994,16 @@ static LogicalResult allocAndInitializeReductionVars(
   return success();
 }
 
+static LogicalResult sectionsOpSupported(omp::SectionsOp op) {
+  if (!op.getAllocateVars().empty() || !op.getAllocatorVars().empty())
+return op.emitError("allocate clause not yet supported");
+
+  if (!op.getPrivateVars().empty() || op.getPrivateSyms())
+return op.emitEr

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Emit descriptive errors for all unsupported clauses (PR #114037)

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

llvmbot wrote:



@llvm/pr-subscribers-mlir-llvm

@llvm/pr-subscribers-flang-openmp

Author: Sergio Afonso (skatrak)


Changes

This patch improves error reporting in the MLIR to LLVM IR translation pass for 
the 'omp' dialect by emitting descriptive errors when encountering clauses not 
yet supported by that pass.

Additionally, not-yet-implemented errors previously missing for some clauses 
are added, to avoid silently ignoring them.

Error messages related to inlining of `omp.private` and `omp.declare_reduction` 
regions have been updated to use the same format.

---

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


2 Files Affected:

- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+236-104) 
- (modified) mlir/test/Target/LLVMIR/openmp-todo.mlir (+185-27) 


``diff
diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 1df7b3c083a3a7..fc7d11b33ab242 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -571,7 +571,8 @@ makeReductionGen(omp::DeclareReductionOp decl, 
llvm::IRBuilderBase &builder,
 if (failed(inlineConvertOmpRegions(decl.getReductionRegion(),
"omp.reduction.nonatomic.body", builder,
moduleTranslation, &phis)))
-  return llvm::createStringError("failed reduction region translation");
+  return llvm::createStringError(
+  "failed to inline `combiner` region of `omp.declare_reduction`");
 assert(phis.size() == 1);
 result = phis[0];
 return builder.saveIP();
@@ -604,7 +605,8 @@ makeAtomicReductionGen(omp::DeclareReductionOp decl,
 if (failed(inlineConvertOmpRegions(decl.getAtomicReductionRegion(),
"omp.reduction.atomic.body", builder,
moduleTranslation, &phis)))
-  return llvm::createStringError("failed reduction region translation");
+  return llvm::createStringError(
+  "failed to inline `atomic` region of `omp.declare_reduction`");
 assert(phis.empty());
 return builder.saveIP();
   };
@@ -640,6 +642,13 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase 
&builder,
   return success();
 }
 
+static LogicalResult orderedRegionSupported(omp::OrderedRegionOp op) {
+  if (op.getParLevelSimd())
+return op.emitError("parallelization-level clause set not yet supported");
+
+  return success();
+}
+
 /// Converts an OpenMP 'ordered_region' operation into LLVM IR using
 /// OpenMPIRBuilder.
 static LogicalResult
@@ -648,9 +657,8 @@ convertOmpOrderedRegion(Operation &opInst, 
llvm::IRBuilderBase &builder,
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
   auto orderedRegionOp = cast(opInst);
 
-  // TODO: The code generation for ordered simd directive is not supported yet.
-  if (orderedRegionOp.getParLevelSimd())
-return opInst.emitError("unhandled clauses for translation to LLVM IR");
+  if (failed(orderedRegionSupported(orderedRegionOp)))
+return failure();
 
   auto bodyGenCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP) {
 // OrderedOp has only one region associated with it.
@@ -717,9 +725,10 @@ allocReductionVars(T loop, ArrayRef 
reductionArgs,
   SmallVector phis;
   if (failed(inlineConvertOmpRegions(allocRegion, "omp.reduction.alloc",
  builder, moduleTranslation, &phis)))
-return failure();
-  assert(phis.size() == 1 && "expected one allocation to be yielded");
+return loop.emitError(
+"failed to inline `alloc` region of `omp.declare_reduction`");
 
+  assert(phis.size() == 1 && "expected one allocation to be yielded");
   builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
 
   // Allocate reduction variable (which is a pointer to the real reduction
@@ -985,6 +994,16 @@ static LogicalResult allocAndInitializeReductionVars(
   return success();
 }
 
+static LogicalResult sectionsOpSupported(omp::SectionsOp op) {
+  if (!op.getAllocateVars().empty() || !op.getAllocatorVars().empty())
+return op.emitError("allocate clause not yet supported");
+
+  if (!op.getPrivateVars().empty() || op.getPrivateSyms())
+return op.emitError("privatization clauses not yet supported");
+
+  return success();
+}
+
 static LogicalResult
 convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
@@ -994,12 +1013,8 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase 
&builder,
 
   auto sectionsOp = cast(opInst);
 
-  // TODO: Support the following clauses: private, firstprivate, lastprivate,
-  // allocate
-  if (!sectionsOp.getAllocateVar

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Emit descriptive errors for all unsupported clauses (PR #114037)

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

skatrak wrote:

PR stack:
- #114036
- #114037

https://github.com/llvm/llvm-project/pull/114037
___
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/19.x: [Inliner] Don't propagate access attr to byval params (#112256) (PR #112365)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/112365

>From 74b2743bd5b89c8184c1b3c1dd7ba49f41a5ba3f Mon Sep 17 00:00:00 2001
From: goldsteinn <35538541+goldste...@users.noreply.github.com>
Date: Tue, 15 Oct 2024 10:25:16 -0400
Subject: [PATCH]  [Inliner] Don't propagate access attr to byval params
 (#112256)

- **[Inliner] Add tests for bad propagationg of access attr for `byval`
param; NFC**
- **[Inliner] Don't propagate access attr to `byval` params**

We previously only handled the case where the `byval` attr was in the
callbase's param attr list. This PR also handles the case if the
`ByVal` was a param attr on the function's param attr list.

(cherry picked from commit 3c777f04f065dda5f0c80eaaef2a7f623ccc20ed)
---
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  2 +-
 .../Inline/access-attributes-prop.ll  | 20 +++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp 
b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 68696789530f4a..fda1c22cc1fb7d 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1395,7 +1395,7 @@ static void AddParamAndFnBasicAttributes(const CallBase 
&CB,
 if (!Arg)
   continue;
 
-if (AL.hasParamAttr(I, Attribute::ByVal))
+if (NewInnerCB->paramHasAttr(I, Attribute::ByVal))
   // It's unsound to propagate memory attributes to byval arguments.
   // Even if CalledFunction doesn't e.g. write to the argument,
   // the call to NewInnerCB may write to its by-value copy.
diff --git a/llvm/test/Transforms/Inline/access-attributes-prop.ll 
b/llvm/test/Transforms/Inline/access-attributes-prop.ll
index 2c55f5f3b1f6ca..5051c92345ec75 100644
--- a/llvm/test/Transforms/Inline/access-attributes-prop.ll
+++ b/llvm/test/Transforms/Inline/access-attributes-prop.ll
@@ -580,3 +580,23 @@ define ptr @callee_bad_param_prop(ptr readonly %x) {
   %r = tail call ptr @llvm.ptrmask(ptr %x, i64 -1)
   ret ptr %r
 }
+
+define dso_local void @foo_byval_readonly2(ptr readonly %p) {
+; CHECK-LABEL: define {{[^@]+}}@foo_byval_readonly2
+; CHECK-SAME: (ptr readonly [[P:%.*]]) {
+; CHECK-NEXT:call void @bar4(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+  call void @bar4(ptr %p)
+  ret void
+}
+
+define void @prop_byval_readonly2(ptr %p) {
+; CHECK-LABEL: define {{[^@]+}}@prop_byval_readonly2
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:call void @bar4(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+  call void @foo_byval_readonly2(ptr %p)
+  ret void
+}

___
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] 74b2743 - [Inliner] Don't propagate access attr to byval params (#112256)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

Author: goldsteinn
Date: 2024-10-29T09:48:10+01:00
New Revision: 74b2743bd5b89c8184c1b3c1dd7ba49f41a5ba3f

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

LOG:  [Inliner] Don't propagate access attr to byval params (#112256)

- **[Inliner] Add tests for bad propagationg of access attr for `byval`
param; NFC**
- **[Inliner] Don't propagate access attr to `byval` params**

We previously only handled the case where the `byval` attr was in the
callbase's param attr list. This PR also handles the case if the
`ByVal` was a param attr on the function's param attr list.

(cherry picked from commit 3c777f04f065dda5f0c80eaaef2a7f623ccc20ed)

Added: 


Modified: 
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/Inline/access-attributes-prop.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp 
b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 68696789530f4a..fda1c22cc1fb7d 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1395,7 +1395,7 @@ static void AddParamAndFnBasicAttributes(const CallBase 
&CB,
 if (!Arg)
   continue;
 
-if (AL.hasParamAttr(I, Attribute::ByVal))
+if (NewInnerCB->paramHasAttr(I, Attribute::ByVal))
   // It's unsound to propagate memory attributes to byval arguments.
   // Even if CalledFunction doesn't e.g. write to the argument,
   // the call to NewInnerCB may write to its by-value copy.

diff  --git a/llvm/test/Transforms/Inline/access-attributes-prop.ll 
b/llvm/test/Transforms/Inline/access-attributes-prop.ll
index 2c55f5f3b1f6ca..5051c92345ec75 100644
--- a/llvm/test/Transforms/Inline/access-attributes-prop.ll
+++ b/llvm/test/Transforms/Inline/access-attributes-prop.ll
@@ -580,3 +580,23 @@ define ptr @callee_bad_param_prop(ptr readonly %x) {
   %r = tail call ptr @llvm.ptrmask(ptr %x, i64 -1)
   ret ptr %r
 }
+
+define dso_local void @foo_byval_readonly2(ptr readonly %p) {
+; CHECK-LABEL: define {{[^@]+}}@foo_byval_readonly2
+; CHECK-SAME: (ptr readonly [[P:%.*]]) {
+; CHECK-NEXT:call void @bar4(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+  call void @bar4(ptr %p)
+  ret void
+}
+
+define void @prop_byval_readonly2(ptr %p) {
+; CHECK-LABEL: define {{[^@]+}}@prop_byval_readonly2
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:call void @bar4(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+  call void @foo_byval_readonly2(ptr %p)
+  ret void
+}



___
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/19.x: [Inliner] Don't propagate access attr to byval params (#112256) (PR #112365)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/112365
___
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/19.x: [Inliner] Don't propagate access attr to byval params (#112256) (PR #112365)

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

github-actions[bot] wrote:

@goldsteinn (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.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/112365
___
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/19.x: [Clang] Instantiate Typedefs referenced by type alias deduction guides (#111804) (PR #112293)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/112293

>From 2717eeb2584005e08bc0b2c1b77954ff156a5bab Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 11 Oct 2024 10:31:27 +0800
Subject: [PATCH] [Clang] Instantiate Typedefs referenced by type alias
 deduction guides (#111804)

TypedefNameDecl referenced by a synthesized CTAD guide for type aliases
was not transformed previously, resulting in a substitution failure in
BuildDeductionGuideForTypeAlias() when substituting into the
right-hand-side deduction guide.

This patch fixes it in the way we have been doing since
https://reviews.llvm.org/D80743. We transform all the function
parameters, parenting referenced TypedefNameDecls with the
CXXDeductionGuideDecl. Then we instantiate these declarations in
FindInstantiatedDecl() as we build up the eventual deduction guide,
using the mechanism introduced in D80743

Fixes #111508

(cherry picked from commit 0bc02b999a9686ba240b7a68d3f1cbbf037d2170)
---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 21 ---
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  | 13 
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index 0602d07c6b9b0d..1bf82b31def977 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -69,8 +69,8 @@ class ExtractTypeForDeductionGuide
   ExtractTypeForDeductionGuide(
   Sema &SemaRef,
   llvm::SmallVectorImpl &MaterializedTypedefs,
-  ClassTemplateDecl *NestedPattern,
-  const MultiLevelTemplateArgumentList *OuterInstantiationArgs)
+  ClassTemplateDecl *NestedPattern = nullptr,
+  const MultiLevelTemplateArgumentList *OuterInstantiationArgs = nullptr)
   : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
 NestedPattern(NestedPattern),
 OuterInstantiationArgs(OuterInstantiationArgs) {
@@ -1263,10 +1263,25 @@ FunctionTemplateDecl 
*DeclareAggregateDeductionGuideForTypeAlias(
   getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate).first;
   if (!RHSTemplate)
 return nullptr;
+
+  llvm::SmallVector TypedefDecls;
+  llvm::SmallVector NewParamTypes;
+  ExtractTypeForDeductionGuide TypeAliasTransformer(SemaRef, TypedefDecls);
+  for (QualType P : ParamTypes) {
+QualType Type = TypeAliasTransformer.TransformType(P);
+if (Type.isNull())
+  return nullptr;
+NewParamTypes.push_back(Type);
+  }
+
   auto *RHSDeductionGuide = SemaRef.DeclareAggregateDeductionGuideFromInitList(
-  RHSTemplate, ParamTypes, Loc);
+  RHSTemplate, NewParamTypes, Loc);
   if (!RHSDeductionGuide)
 return nullptr;
+
+  for (TypedefNameDecl *TD : TypedefDecls)
+TD->setDeclContext(RHSDeductionGuide->getTemplatedDecl());
+
   return BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate,
  RHSDeductionGuide, Loc);
 }
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 5392573fcdb9d5..675c32a81f1ae8 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -481,3 +481,16 @@ struct Out {
 Out::B out(100); // deduced to Out::A;
 static_assert(__is_same(decltype(out), Out::A));
 }
+
+namespace GH111508 {
+
+template  struct S {
+  using T = V;
+  T Data;
+};
+
+template  using Alias = S;
+
+Alias A(42);
+
+} // namespace GH111508

___
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/19.x: [Clang] Instantiate Typedefs referenced by type alias deduction guides (#111804) (PR #112293)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/112293

>From 19c571a631d962f05264c539f035f5e7fc5c166b Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 11 Oct 2024 10:31:27 +0800
Subject: [PATCH] [Clang] Instantiate Typedefs referenced by type alias
 deduction guides (#111804)

TypedefNameDecl referenced by a synthesized CTAD guide for type aliases
was not transformed previously, resulting in a substitution failure in
BuildDeductionGuideForTypeAlias() when substituting into the
right-hand-side deduction guide.

This patch fixes it in the way we have been doing since
https://reviews.llvm.org/D80743. We transform all the function
parameters, parenting referenced TypedefNameDecls with the
CXXDeductionGuideDecl. Then we instantiate these declarations in
FindInstantiatedDecl() as we build up the eventual deduction guide,
using the mechanism introduced in D80743

Fixes #111508

(cherry picked from commit 0bc02b999a9686ba240b7a68d3f1cbbf037d2170)
---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 21 ---
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  | 13 
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index 0602d07c6b9b0d..1bf82b31def977 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -69,8 +69,8 @@ class ExtractTypeForDeductionGuide
   ExtractTypeForDeductionGuide(
   Sema &SemaRef,
   llvm::SmallVectorImpl &MaterializedTypedefs,
-  ClassTemplateDecl *NestedPattern,
-  const MultiLevelTemplateArgumentList *OuterInstantiationArgs)
+  ClassTemplateDecl *NestedPattern = nullptr,
+  const MultiLevelTemplateArgumentList *OuterInstantiationArgs = nullptr)
   : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
 NestedPattern(NestedPattern),
 OuterInstantiationArgs(OuterInstantiationArgs) {
@@ -1263,10 +1263,25 @@ FunctionTemplateDecl 
*DeclareAggregateDeductionGuideForTypeAlias(
   getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate).first;
   if (!RHSTemplate)
 return nullptr;
+
+  llvm::SmallVector TypedefDecls;
+  llvm::SmallVector NewParamTypes;
+  ExtractTypeForDeductionGuide TypeAliasTransformer(SemaRef, TypedefDecls);
+  for (QualType P : ParamTypes) {
+QualType Type = TypeAliasTransformer.TransformType(P);
+if (Type.isNull())
+  return nullptr;
+NewParamTypes.push_back(Type);
+  }
+
   auto *RHSDeductionGuide = SemaRef.DeclareAggregateDeductionGuideFromInitList(
-  RHSTemplate, ParamTypes, Loc);
+  RHSTemplate, NewParamTypes, Loc);
   if (!RHSDeductionGuide)
 return nullptr;
+
+  for (TypedefNameDecl *TD : TypedefDecls)
+TD->setDeclContext(RHSDeductionGuide->getTemplatedDecl());
+
   return BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate,
  RHSDeductionGuide, Loc);
 }
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 5392573fcdb9d5..675c32a81f1ae8 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -481,3 +481,16 @@ struct Out {
 Out::B out(100); // deduced to Out::A;
 static_assert(__is_same(decltype(out), Out::A));
 }
+
+namespace GH111508 {
+
+template  struct S {
+  using T = V;
+  T Data;
+};
+
+template  using Alias = S;
+
+Alias A(42);
+
+} // namespace GH111508

___
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][bufferization] Add support for non-unique `func.return` (PR #114017)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

Draft. Do not review yet.

Depends on #113999.


>From e88daefdd87df823bbfbe34cb44cb9ef00bd4e62 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Tue, 29 Oct 2024 09:51:11 +0100
Subject: [PATCH] [mlir][bufferization] Add support for non-unique
 `func.return`

---
 .../FuncBufferizableOpInterfaceImpl.cpp   |  75 +++-
 .../Transforms/OneShotModuleBufferize.cpp | 179 +-
 .../one-shot-module-bufferize-invalid.mlir|  22 +--
 .../Transforms/one-shot-module-bufferize.mlir |  24 +++
 4 files changed, 190 insertions(+), 110 deletions(-)

diff --git 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
index a372e87d8335f1..2d9cca0c5816e7 100644
--- 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
+++ 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
@@ -41,18 +41,13 @@ void FuncAnalysisState::startFunctionAnalysis(FuncOp 
funcOp) {
 #endif // NDEBUG
 }
 
-/// Return the unique ReturnOp that terminates `funcOp`.
-/// Return nullptr if there is no such unique ReturnOp.
-static func::ReturnOp getAssumedUniqueReturnOp(FuncOp funcOp) {
-  func::ReturnOp returnOp;
-  for (Block &b : funcOp.getBody()) {
-if (auto candidateOp = dyn_cast(b.getTerminator())) {
-  if (returnOp)
-return nullptr;
-  returnOp = candidateOp;
-}
-  }
-  return returnOp;
+/// Return all top-level func.return ops in the given function.
+static SmallVector getReturnOps(FuncOp funcOp) {
+  SmallVector result;
+  for (Block &b : funcOp.getBody())
+if (auto returnOp = dyn_cast(b.getTerminator()))
+  result.push_back(returnOp);
+  return result;
 }
 
 /// Return the index-th bufferized function argument type. This assumes that 
the
@@ -372,15 +367,6 @@ struct FuncOpInterface
 getBufferType(op, value, options, invocationStack);
   }
 
-  LogicalResult verifyAnalysis(Operation *op,
-   const AnalysisState &state) const {
-auto funcOp = cast(op);
-// TODO: func.func with multiple returns are not supported.
-if (!getAssumedUniqueReturnOp(funcOp) && !funcOp.isExternal())
-  return op->emitOpError("op without unique func.return is not supported");
-return success();
-  }
-
   /// Rewrite function bbArgs and return values into buffer form. This function
   /// bufferizes the function signature and the ReturnOp. When the entire
   /// function body has been bufferized, function return types can be switched
@@ -427,41 +413,38 @@ struct FuncOpInterface
   return success();
 }
 
-// TODO: Support functions with multiple returns.
-func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOp);
-assert(returnOp && "expected func with single return op");
-assert(returnOp->getNumOperands() == retTypes.size() &&
-   "incorrect number of return values");
-Location loc = returnOp.getLoc();
-
 // 1. Bufferize every block.
 for (Block &block : funcOp.getBody())
   if (failed(bufferization::bufferizeBlockSignature(&block, rewriter,
 options)))
 return failure();
 
-// 2. Bufferize all operands of the return op.
-SmallVector returnValues;
-for (auto [returnVal, bufferizedType] :
- llvm::zip_equal(returnOp->getOperands(), retTypes)) {
-  auto tensorType = dyn_cast(returnVal.getType());
-  rewriter.setInsertionPoint(returnOp);
-
-  // If not a tensor type just forward it.
-  if (!tensorType) {
-returnValues.push_back(returnVal);
-continue;
+// 2. Bufferize the operands of the all return op.
+for (func::ReturnOp returnOp : getReturnOps(funcOp)) {
+  assert(returnOp->getNumOperands() == retTypes.size() &&
+ "incorrect number of return values");
+  SmallVector returnValues;
+  for (auto [returnVal, bufferizedType] :
+   llvm::zip_equal(returnOp->getOperands(), retTypes)) {
+auto tensorType = dyn_cast(returnVal.getType());
+rewriter.setInsertionPoint(returnOp);
+
+// If not a tensor type just forward it.
+if (!tensorType) {
+  returnValues.push_back(returnVal);
+  continue;
+}
+
+// Note: If `inferFunctionResultLayout = true`, casts are later folded
+// away.
+Value toMemrefOp = rewriter.create(
+returnOp.getLoc(), bufferizedType, returnVal);
+returnValues.push_back(toMemrefOp);
   }
 
-  // Note: If `inferFunctionResultLayout = true`, casts are later folded
-  // away.
-  Value toMemrefOp = rewriter.create(
-  loc, bufferizedType, returnVal);
-  returnValues.push_back(toMemrefOp);
+  returnOp.getOperandsMutable().assign(returnValues);
 }
 
-returnOp.getOperands

[llvm-branch-commits] [clang] 19c571a - [Clang] Instantiate Typedefs referenced by type alias deduction guides (#111804)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

Author: Younan Zhang
Date: 2024-10-29T09:52:13+01:00
New Revision: 19c571a631d962f05264c539f035f5e7fc5c166b

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

LOG: [Clang] Instantiate Typedefs referenced by type alias deduction guides 
(#111804)

TypedefNameDecl referenced by a synthesized CTAD guide for type aliases
was not transformed previously, resulting in a substitution failure in
BuildDeductionGuideForTypeAlias() when substituting into the
right-hand-side deduction guide.

This patch fixes it in the way we have been doing since
https://reviews.llvm.org/D80743. We transform all the function
parameters, parenting referenced TypedefNameDecls with the
CXXDeductionGuideDecl. Then we instantiate these declarations in
FindInstantiatedDecl() as we build up the eventual deduction guide,
using the mechanism introduced in D80743

Fixes #111508

(cherry picked from commit 0bc02b999a9686ba240b7a68d3f1cbbf037d2170)

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeductionGuide.cpp
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index 0602d07c6b9b0d..1bf82b31def977 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -69,8 +69,8 @@ class ExtractTypeForDeductionGuide
   ExtractTypeForDeductionGuide(
   Sema &SemaRef,
   llvm::SmallVectorImpl &MaterializedTypedefs,
-  ClassTemplateDecl *NestedPattern,
-  const MultiLevelTemplateArgumentList *OuterInstantiationArgs)
+  ClassTemplateDecl *NestedPattern = nullptr,
+  const MultiLevelTemplateArgumentList *OuterInstantiationArgs = nullptr)
   : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
 NestedPattern(NestedPattern),
 OuterInstantiationArgs(OuterInstantiationArgs) {
@@ -1263,10 +1263,25 @@ FunctionTemplateDecl 
*DeclareAggregateDeductionGuideForTypeAlias(
   getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate).first;
   if (!RHSTemplate)
 return nullptr;
+
+  llvm::SmallVector TypedefDecls;
+  llvm::SmallVector NewParamTypes;
+  ExtractTypeForDeductionGuide TypeAliasTransformer(SemaRef, TypedefDecls);
+  for (QualType P : ParamTypes) {
+QualType Type = TypeAliasTransformer.TransformType(P);
+if (Type.isNull())
+  return nullptr;
+NewParamTypes.push_back(Type);
+  }
+
   auto *RHSDeductionGuide = SemaRef.DeclareAggregateDeductionGuideFromInitList(
-  RHSTemplate, ParamTypes, Loc);
+  RHSTemplate, NewParamTypes, Loc);
   if (!RHSDeductionGuide)
 return nullptr;
+
+  for (TypedefNameDecl *TD : TypedefDecls)
+TD->setDeclContext(RHSDeductionGuide->getTemplatedDecl());
+
   return BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate,
  RHSDeductionGuide, Loc);
 }

diff  --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 5392573fcdb9d5..675c32a81f1ae8 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -481,3 +481,16 @@ struct Out {
 Out::B out(100); // deduced to Out::A;
 static_assert(__is_same(decltype(out), Out::A));
 }
+
+namespace GH111508 {
+
+template  struct S {
+  using T = V;
+  T Data;
+};
+
+template  using Alias = S;
+
+Alias A(42);
+
+} // namespace GH111508



___
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/19.x: [Clang] Instantiate Typedefs referenced by type alias deduction guides (#111804) (PR #112293)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/112293
___
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] 21ed37e - [LLVM] [Clang] Backport "Support for Gentoo `*t64` triples (64-bit time_t ABIs)"

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

Author: Michał Górny
Date: 2024-10-29T09:53:58+01:00
New Revision: 21ed37e3e725a7f58c2eb347519e500ebddb57ee

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

LOG: [LLVM] [Clang] Backport "Support for Gentoo `*t64` triples (64-bit time_t 
ABIs)"

This is a backport of 387b37af1aabf325e9be844361564dfad8d45c75 for 19.x,
adjusted to add new Triple::EnvironmentType members at the end to avoid
breaking backwards ABI compatibility.

Gentoo is planning to introduce a `*t64` suffix for triples that will be
used by 32-bit platforms that use 64-bit `time_t`. Add support for
parsing and accepting these triples, and while at it make clang
automatically enable the necessary glibc feature macros when this suffix
is used.

Added: 
clang/test/Preprocessor/time64.c

Modified: 
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/Targets/ARM.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Linux.cpp
llvm/include/llvm/TargetParser/Triple.h
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/Target/ARM/ARMTargetMachine.h
llvm/lib/TargetParser/ARMTargetParser.cpp
llvm/lib/TargetParser/Triple.cpp
llvm/unittests/TargetParser/TripleTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 7423626d7c3cbf..e55feedbd5c6f9 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -311,7 +311,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
 switch (Triple.getEnvironment()) {
 case llvm::Triple::Android:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
 case llvm::Triple::OpenHOS:

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 5f27c3469f861d..357c1965057c9b 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -337,6 +337,10 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
   Builder.defineMacro("_GNU_SOURCE");
 if (this->HasFloat128)
   Builder.defineMacro("__FLOAT128__");
+if (Triple.isTime64ABI()) {
+  Builder.defineMacro("_FILE_OFFSET_BITS", "64");
+  Builder.defineMacro("_TIME_BITS", "64");
+}
   }
 
 public:

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cf5e29e5a3db8d..8d9beab9fa7f88 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -177,10 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (ABIStr == "aapcs16")
   Kind = ARMABIKind::AAPCS16_VFP;
 else if (CodeGenOpts.FloatABI == "hard" ||
- (CodeGenOpts.FloatABI != "soft" &&
-  (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
-   Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
-   Triple.getEnvironment() == llvm::Triple::EABIHF)))
+ (CodeGenOpts.FloatABI != "soft" && Triple.isHardFloatABI()))
   Kind = ARMABIKind::AAPCS_VFP;
 
 return createARMTargetCodeGenInfo(CGM, Kind);

diff  --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index d032b88d7683cd..457d761039a08d 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
 case llvm::Triple::EABI:
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
   return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
 switch (getTarget().getTriple().getEnvironment()) {
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABIHF:
   return true;
 default:

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8e44d5afa40e05..ecae475f75da00 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -602,7 +602,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() =

[llvm-branch-commits] [llvm] release/19.x: [WebAssembly] Fix feature coalescing (#110647) (PR #112431)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/112431

>From 8a4228f571d5d94f50abca91353d4c14a1439208 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 15 Oct 2024 09:34:55 +0200
Subject: [PATCH] [WebAssembly] Fix feature coalescing (#110647)

This fixes a problem introduced in #80094. That PR copied negative
features from the TargetMachine to the end of the feature string. This
is not correct, because even if we have a baseline TM of say `-simd128`,
but a function with `+simd128`, the coalesced feature string should have
`+simd128`, not `-simd128`.

To address the original motivation of that PR, we should instead
explicitly materialize the negative features in the target feature
string, so that explicitly disabled default features are honored.

Unfortunately, there doesn't seem to be any way to actually test this
using llc, because `-mattr` appends the specified features to the end of
the `"target-features"` attribute. I've tested this locally by making it
prepend the features instead.

(cherry picked from commit 5a7b79c93e2e0c71aec016973f5f13d3bb2e7a62)
---
 .../Target/WebAssembly/WebAssemblyTargetMachine.cpp  | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 23539a5f4b26f1..ac9e6d5a90cb3c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -202,8 +202,7 @@ class CoalesceFeaturesAndStripAtomics final : public 
ModulePass {
   bool runOnModule(Module &M) override {
 FeatureBitset Features = coalesceFeatures(M);
 
-std::string FeatureStr =
-getFeatureString(Features, WasmTM->getTargetFeatureString());
+std::string FeatureStr = getFeatureString(Features);
 WasmTM->setTargetFeatureString(FeatureStr);
 for (auto &F : M)
   replaceFeatures(F, FeatureStr);
@@ -241,17 +240,14 @@ class CoalesceFeaturesAndStripAtomics final : public 
ModulePass {
 return Features;
   }
 
-  static std::string getFeatureString(const FeatureBitset &Features,
-  StringRef TargetFS) {
+  static std::string getFeatureString(const FeatureBitset &Features) {
 std::string Ret;
 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
   if (Features[KV.Value])
 Ret += (StringRef("+") + KV.Key + ",").str();
+  else
+Ret += (StringRef("-") + KV.Key + ",").str();
 }
-SubtargetFeatures TF{TargetFS};
-for (std::string const &F : TF.getFeatures())
-  if (!SubtargetFeatures::isEnabled(F))
-Ret += F + ",";
 return Ret;
   }
 

___
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] 6e006e1 - [WebAssembly] Fix feature coalescing (#110647)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

Author: Nikita Popov
Date: 2024-10-29T09:58:06+01:00
New Revision: 6e006e11f3509f0f3eeac9f3b092176cf7c1832f

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

LOG: [WebAssembly] Fix feature coalescing (#110647)

This fixes a problem introduced in #80094. That PR copied negative
features from the TargetMachine to the end of the feature string. This
is not correct, because even if we have a baseline TM of say `-simd128`,
but a function with `+simd128`, the coalesced feature string should have
`+simd128`, not `-simd128`.

To address the original motivation of that PR, we should instead
explicitly materialize the negative features in the target feature
string, so that explicitly disabled default features are honored.

Unfortunately, there doesn't seem to be any way to actually test this
using llc, because `-mattr` appends the specified features to the end of
the `"target-features"` attribute. I've tested this locally by making it
prepend the features instead.

(cherry picked from commit 5a7b79c93e2e0c71aec016973f5f13d3bb2e7a62)

Added: 


Modified: 
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Removed: 




diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 23539a5f4b26f1..ac9e6d5a90cb3c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -202,8 +202,7 @@ class CoalesceFeaturesAndStripAtomics final : public 
ModulePass {
   bool runOnModule(Module &M) override {
 FeatureBitset Features = coalesceFeatures(M);
 
-std::string FeatureStr =
-getFeatureString(Features, WasmTM->getTargetFeatureString());
+std::string FeatureStr = getFeatureString(Features);
 WasmTM->setTargetFeatureString(FeatureStr);
 for (auto &F : M)
   replaceFeatures(F, FeatureStr);
@@ -241,17 +240,14 @@ class CoalesceFeaturesAndStripAtomics final : public 
ModulePass {
 return Features;
   }
 
-  static std::string getFeatureString(const FeatureBitset &Features,
-  StringRef TargetFS) {
+  static std::string getFeatureString(const FeatureBitset &Features) {
 std::string Ret;
 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
   if (Features[KV.Value])
 Ret += (StringRef("+") + KV.Key + ",").str();
+  else
+Ret += (StringRef("-") + KV.Key + ",").str();
 }
-SubtargetFeatures TF{TargetFS};
-for (std::string const &F : TF.getFeatures())
-  if (!SubtargetFeatures::isEnabled(F))
-Ret += F + ",";
 return Ret;
   }
 



___
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/19.x: [WebAssembly] Fix feature coalescing (#110647) (PR #112431)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/112431

>From 6e006e11f3509f0f3eeac9f3b092176cf7c1832f Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 15 Oct 2024 09:34:55 +0200
Subject: [PATCH] [WebAssembly] Fix feature coalescing (#110647)

This fixes a problem introduced in #80094. That PR copied negative
features from the TargetMachine to the end of the feature string. This
is not correct, because even if we have a baseline TM of say `-simd128`,
but a function with `+simd128`, the coalesced feature string should have
`+simd128`, not `-simd128`.

To address the original motivation of that PR, we should instead
explicitly materialize the negative features in the target feature
string, so that explicitly disabled default features are honored.

Unfortunately, there doesn't seem to be any way to actually test this
using llc, because `-mattr` appends the specified features to the end of
the `"target-features"` attribute. I've tested this locally by making it
prepend the features instead.

(cherry picked from commit 5a7b79c93e2e0c71aec016973f5f13d3bb2e7a62)
---
 .../Target/WebAssembly/WebAssemblyTargetMachine.cpp  | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 23539a5f4b26f1..ac9e6d5a90cb3c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -202,8 +202,7 @@ class CoalesceFeaturesAndStripAtomics final : public 
ModulePass {
   bool runOnModule(Module &M) override {
 FeatureBitset Features = coalesceFeatures(M);
 
-std::string FeatureStr =
-getFeatureString(Features, WasmTM->getTargetFeatureString());
+std::string FeatureStr = getFeatureString(Features);
 WasmTM->setTargetFeatureString(FeatureStr);
 for (auto &F : M)
   replaceFeatures(F, FeatureStr);
@@ -241,17 +240,14 @@ class CoalesceFeaturesAndStripAtomics final : public 
ModulePass {
 return Features;
   }
 
-  static std::string getFeatureString(const FeatureBitset &Features,
-  StringRef TargetFS) {
+  static std::string getFeatureString(const FeatureBitset &Features) {
 std::string Ret;
 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
   if (Features[KV.Value])
 Ret += (StringRef("+") + KV.Key + ",").str();
+  else
+Ret += (StringRef("-") + KV.Key + ",").str();
 }
-SubtargetFeatures TF{TargetFS};
-for (std::string const &F : TF.getFeatures())
-  if (!SubtargetFeatures::isEnabled(F))
-Ret += F + ",";
 return Ret;
   }
 

___
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/19.x: [WebAssembly] Fix feature coalescing (#110647) (PR #112431)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/112431
___
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] [CodeGen][NewPM] Port RegUsageInfoPropagation pass to NPM (PR #114010)

2024-10-29 Thread Akshat Oke via llvm-branch-commits

https://github.com/optimisan updated 
https://github.com/llvm/llvm-project/pull/114010

>From 5f42368e15bdba242c15f9f4493b88f80a8f09b7 Mon Sep 17 00:00:00 2001
From: Akshat Oke 
Date: Tue, 29 Oct 2024 07:14:30 +
Subject: [PATCH] [CodeGen][NewPM] Port RegUsageInfoPropagation pass to NPM

---
 .../llvm/CodeGen/RegUsageInfoPropagate.h  | 25 +++
 llvm/include/llvm/InitializePasses.h  |  2 +-
 llvm/include/llvm/Passes/CodeGenPassBuilder.h |  1 +
 .../llvm/Passes/MachinePassRegistry.def   |  2 +-
 llvm/lib/CodeGen/CodeGen.cpp  |  2 +-
 llvm/lib/CodeGen/RegUsageInfoPropagate.cpp| 75 +--
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/test/CodeGen/AArch64/preserve.ll |  4 +
 8 files changed, 86 insertions(+), 26 deletions(-)
 create mode 100644 llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h

diff --git a/llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h 
b/llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h
new file mode 100644
index 00..73624015e37d9d
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h
@@ -0,0 +1,25 @@
+//===- llvm/CodeGen/RegUsageInfoPropagate.h -*- C++ 
-*-===//
+//
+// 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 LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
+#define LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+
+class RegUsageInfoPropagationPass
+: public PassInfoMixin {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+MachineFunctionAnalysisManager &MFAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
diff --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index c881dcd57006db..a9ab739af33ad8 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -258,7 +258,7 @@ void initializeRegAllocScoringPass(PassRegistry &);
 void initializeRegBankSelectPass(PassRegistry &);
 void initializeRegToMemWrapperPassPass(PassRegistry &);
 void initializeRegUsageInfoCollectorLegacyPass(PassRegistry &);
-void initializeRegUsageInfoPropagationPass(PassRegistry &);
+void initializeRegUsageInfoPropagationLegacyPass(PassRegistry &);
 void initializeRegionInfoPassPass(PassRegistry &);
 void initializeRegionOnlyPrinterPass(PassRegistry &);
 void initializeRegionOnlyViewerPass(PassRegistry &);
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h 
b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 14fcf9d79fbc23..a64ecd69e55913 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -54,6 +54,7 @@
 #include "llvm/CodeGen/PreISelIntrinsicLowering.h"
 #include "llvm/CodeGen/RegAllocFast.h"
 #include "llvm/CodeGen/RegUsageInfoCollector.h"
+#include "llvm/CodeGen/RegUsageInfoPropagate.h"
 #include "llvm/CodeGen/RegisterUsageInfo.h"
 #include "llvm/CodeGen/ReplaceWithVeclib.h"
 #include "llvm/CodeGen/SafeStack.h"
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def 
b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 36d17b713639c1..099b009a2b3fee 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -156,6 +156,7 @@ MACHINE_FUNCTION_PASS("print",
 MACHINE_FUNCTION_PASS("print", SlotIndexesPrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("print", VirtRegMapPrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
+MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass())
 MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
   RequireAllMachineFunctionPropertiesPass())
 MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass())
@@ -250,7 +251,6 @@ DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", 
PrologEpilogCodeInserterPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
-DUMMY_MACHINE_FUNCTION_PASS("reg-usage-propagation", 
RegUsageInfoPropagationPass)
 DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
 DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
 DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass)
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 76b74ea4e6fe0b..20d1417193a864 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -114,7 +114,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeRAGreedyPass(Registry);
   initializeRegAllocFastPass(Registry);
   initializeRegUsageInfoCollectorLega

[llvm-branch-commits] [clang] [Multilib] Custom flags processing for library selection (PR #110659)

2024-10-29 Thread Simon Tatham via llvm-branch-commits


@@ -95,9 +96,113 @@ MultilibSet &MultilibSet::FilterOut(FilterCallback F) {
 
 void MultilibSet::push_back(const Multilib &M) { Multilibs.push_back(M); }
 
+static void WarnUnclaimedMultilibCustomFlags(
+const Driver &D, const SmallVector &UnclaimedCustomFlagValues,
+const SmallVector &CustomFlagDecls) 
{
+  struct EditDistanceInfo {
+StringRef FlagValue;
+unsigned EditDistance;
+  };
+  const unsigned MaxEditDistance = 5;
+
+  for (StringRef Unclaimed : UnclaimedCustomFlagValues) {
+std::optional BestCandidate;
+for (const auto &Decl : CustomFlagDecls) {
+  for (const auto &Value : Decl->ValueList) {
+const std::string &FlagValueName = Value.Name;
+unsigned EditDistance =
+Unclaimed.edit_distance(FlagValueName, /*AllowReplacements=*/true,
+/*MaxEditDistance=*/MaxEditDistance);
+if (!BestCandidate || (EditDistance <= MaxEditDistance &&
+   EditDistance < BestCandidate->EditDistance)) {
+  BestCandidate = {FlagValueName, EditDistance};
+}
+  }
+}
+if (!BestCandidate)
+  D.Diag(clang::diag::warn_drv_unsupported_opt)
+  << (custom_flag::Prefix + Unclaimed).str();
+else
+  D.Diag(clang::diag::warn_drv_unsupported_opt_with_suggestion)
+  << (custom_flag::Prefix + Unclaimed).str()
+  << (custom_flag::Prefix + BestCandidate->FlagValue).str();
+  }
+}
+
+namespace clang::driver::custom_flag {
+class ValueNameToDetailMap {
+  SmallVector> Mapping;
+
+public:
+  template 
+  ValueNameToDetailMap(It FlagDeclsBegin, It FlagDeclsEnd) {
+for (auto DeclIt = FlagDeclsBegin; DeclIt != FlagDeclsEnd; ++DeclIt) {
+  const CustomFlagDeclarationPtr &Decl = *DeclIt;
+  for (const auto &Value : Decl->ValueList)
+Mapping.emplace_back(Value.Name, &Value);
+}
+  }
+
+  const CustomFlagValueDetail *get(StringRef Key) const {
+auto Iter = llvm::find_if(
+Mapping, [&](const auto &Pair) { return Pair.first == Key; });
+return Iter != Mapping.end() ? Iter->second : nullptr;
+  }
+};
+} // namespace clang::driver::custom_flag
+
+Multilib::flags_list
+MultilibSet::processCustomFlags(const Driver &D,
+const Multilib::flags_list &Flags) const {
+  Multilib::flags_list Result;
+  SmallVector
+  ClaimedCustomFlagValues;
+  SmallVector UnclaimedCustomFlagValueStrs;
+
+  const auto ValueNameToValueDetail = custom_flag::ValueNameToDetailMap(
+  CustomFlagDecls.begin(), CustomFlagDecls.end());
+
+  for (StringRef Flag : Flags) {
+if (!Flag.starts_with(custom_flag::Prefix)) {
+  Result.push_back(Flag.str());
+  continue;
+}
+
+StringRef CustomFlagValueStr = Flag.substr(custom_flag::Prefix.size());
+const custom_flag::CustomFlagValueDetail *Detail =
+ValueNameToValueDetail.get(CustomFlagValueStr);
+if (Detail)
+  ClaimedCustomFlagValues.push_back(Detail);
+else
+  UnclaimedCustomFlagValueStrs.push_back(CustomFlagValueStr);
+  }
+
+  llvm::SmallSet
+  TriggeredCustomFlagDecls;
+
+  for (auto *CustomFlagValue : llvm::reverse(ClaimedCustomFlagValues)) {
+if (!TriggeredCustomFlagDecls.insert(CustomFlagValue->Decl).second)
+  continue;
+Result.push_back(std::string(custom_flag::Prefix) + CustomFlagValue->Name);
+  }

statham-arm wrote:

Can you add some comments explaining what all this code is for, please?

It looks as if the first loop over `Flags` is picking out custom multilib 
flags, taking off the `-fmultilib-flag=` prefix, and storing them in 
`ClaimedCustomFlagValues`, and then this second loop is putting them back on to 
the result string, after putting the `-fmultilib-flag=` prefix back on.

I'm sure there's a reason why this is _not_ an elaborate no-op, but can you 
write down what the reason is? Why aren't we just putting the flags straight 
into `Result` without taking them apart and putting them back together in 
between? Without any comments it looks like a lot of processing for not much 
change.

https://github.com/llvm/llvm-project/pull/110659
___
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] [Multilib] Custom flags processing for library selection (PR #110659)

2024-10-29 Thread Simon Tatham via llvm-branch-commits


@@ -14,6 +14,12 @@ def err_drv_no_such_file_with_suggestion : Error<
 def err_drv_unsupported_opt : Error<"unsupported option '%0'">;
 def err_drv_unsupported_opt_with_suggestion : Error<
   "unsupported option '%0'; did you mean '%1'?">;
+def warn_drv_unsupported_opt : Warning<
+  "unsupported option '%0'">,
+  InGroup;
+def warn_drv_unsupported_opt_with_suggestion : Warning<
+  "unsupported option '%0'; did you mean '%1'?">,
+  InGroup;

statham-arm wrote:

You mention in the commit message that an unrecognised custom flag is a warning 
rather than an error. But I'm curious about why. If a toolchain vendor ships a 
toolchain with a collection of flags that select particular libraries, and a 
user misspells a flag in their makefile, why _wouldn't_ they want a build error 
so that they notice and fix it? A warning can easily be scrolled off the screen 
in the enormous build log.

Warnings are for cases that _might_ be mistakes by the user, but might also be 
correct, so you can't afford to refuse to build. I don't see why an 
unrecognised flag falls into that category.

It would make sense if there was some kind of standard flag that _most_ 
multilib collections agreed on, and you wanted to be able to use that flag 
everywhere and have it quietly ignored when not supported. But is that your 
intention?

https://github.com/llvm/llvm-project/pull/110659
___
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] [Multilib] Add -fmultilib-flag command-line option (PR #110658)

2024-10-29 Thread Simon Tatham via llvm-branch-commits


@@ -196,6 +196,16 @@ bool ToolChain::defaultToIEEELongDouble() const {
   return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux();
 }
 
+static void
+processARMAArch64MultilibCustomFlags(Multilib::flags_list &List,

statham-arm wrote:

Is this system intended to be permanently specific to Arm and AArch64? I don't 
really see why it should be: the need to build libraries distinguished by a 
configuration option that isn't a standard compile flag is certainly not 
specific to Arm. Perhaps this should just be called 
`processMultilibCustomFlags`?

https://github.com/llvm/llvm-project/pull/110658
___
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] Disable use of the counted_by attribute for whole struct pointers (#112636) (PR #112786)

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

github-actions[bot] wrote:

@bwendling (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.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/112786
___
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] [TableGen] Remove a pointless check for iPTRAny (PR #113732)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/113732
___
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] [CodeGen] Rename MVT::iPTRAny to MVT::pAny (PR #113733)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/113733
___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114093)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114093

Add a command-line tool `llvm-cas` to inspect the OnDisk CAS for
debugging purpose. It can be used to lookup/update ObjectStore or
put/get cache entries from ActionCache, together with other debugging
capabilities.



___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114094)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan closed 
https://github.com/llvm/llvm-project/pull/114094
___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114094)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114094

Add a command-line tool `llvm-cas` to inspect the OnDisk CAS for
debugging purpose. It can be used to lookup/update ObjectStore or
put/get cache entries from ActionCache, together with other debugging
capabilities.



___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114093)

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

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 42a1660376e339add3abe8ee8d73073dc0b49432 
71e52bbf7a1e3c6e29cc149089a0368942b40cb1 --extensions cpp -- 
llvm/tools/llvm-cas/llvm-cas.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/tools/llvm-cas/llvm-cas.cpp b/llvm/tools/llvm-cas/llvm-cas.cpp
index 291c6faf9f..b3dd0bb1f3 100644
--- a/llvm/tools/llvm-cas/llvm-cas.cpp
+++ b/llvm/tools/llvm-cas/llvm-cas.cpp
@@ -133,13 +133,12 @@ int main(int Argc, char **Argv) {
   return validateObject(*CAS, ID);
 }
 
-static Expected>
-openBuffer(StringRef DataPath) {
+static Expected> openBuffer(StringRef DataPath) {
   if (DataPath.empty())
 return createStringError(inconvertibleErrorCode(), "--data missing");
-  return errorOrToExpected(
-  DataPath == "-" ? llvm::MemoryBuffer::getSTDIN()
-  : llvm::MemoryBuffer::getFile(DataPath));
+  return errorOrToExpected(DataPath == "-"
+   ? llvm::MemoryBuffer::getSTDIN()
+   : llvm::MemoryBuffer::getFile(DataPath));
 }
 
 int dump(ObjectStore &CAS) {

``




https://github.com/llvm/llvm-project/pull/114093
___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114093)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan closed 
https://github.com/llvm/llvm-project/pull/114093
___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114104)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114104

Add a command-line tool `llvm-cas` to inspect the OnDisk CAS for
debugging purpose. It can be used to lookup/update ObjectStore or
put/get cache entries from ActionCache, together with other debugging
capabilities.



___
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] [CAS] Add OnDiskCAS (PR #114103)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114103

Add OnDiskCAS abstraction, that implements ObjectStore and ActionCache
interface using OnDiskGraphDB and OnDiskKeyValueDB.



___
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] [CAS] Add OnDiskGraphDB and OnDiskKeyValueDB (PR #114102)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114102

Add OnDiskGraphDB and OnDiskKeyValueDB that can be used to implement
ObjectStore and ActionCache respectively. Those are on-disk persistent
storage that build upon OnDiskTrieHashMap and implements key functions
that are required by LLVMCAS interfaces.

This abstraction layer defines how the objects are hashed and stored on
disk. OnDiskKeyValueDB is a basic OnDiskTrieHashMap while OnDiskGraphDB
also defines:
* How objects of various size are store on disk and are referenced by
  the trie nodes.
* How to store the references from one stored object to another object
  that is referenced.

In addition to basic APIs for ObjectStore and ActionCache, other
advances database configuration features can be implemented in this
layer without exposing to the users of the LLVMCAS interface. For
example, OnDiskGraphDB has a faulty in function to fetch data from an
upstream OnDiskGraphDB if the data is missing.



___
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] [FileSystem] Allow exclusive file lock (PR #114098)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114098

Add parameter to file lock API to allow exclusive file lock. Both Unix
and Windows support lock the file exclusively for write for one process
and LLVM OnDiskCAS uses exclusive file lock to coordinate CAS creation.



___
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] [CAS] Add ActionCache to LLVMCAS Library (PR #114097)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114097

ActionCache is used to store a mapping from CASID to CASID. The current
implementation of the ActionCache can only be used to associate the
key/value from the same hash context.

ActionCache has two operations: `put` to store the key/value and `get` to
lookup the key/value mapping. ActionCache uses the same TrieRawHashMap
data structure to store the mapping, where is CASID of the key is the
hash to index the map.

While CASIDs for key/value are often associcate with actual CAS
ObjectStore, it doesn't provide the guarantee of the existence of such
object in any ObjectStore.



___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114094)

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

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 38e5c8c7c5580224e0b3ae160491a0dcdf84490a 
ac0662b44cde12758c3e1be946651151938ee846 --extensions cpp -- 
llvm/tools/llvm-cas/llvm-cas.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/tools/llvm-cas/llvm-cas.cpp b/llvm/tools/llvm-cas/llvm-cas.cpp
index 291c6faf9f..b3dd0bb1f3 100644
--- a/llvm/tools/llvm-cas/llvm-cas.cpp
+++ b/llvm/tools/llvm-cas/llvm-cas.cpp
@@ -133,13 +133,12 @@ int main(int Argc, char **Argv) {
   return validateObject(*CAS, ID);
 }
 
-static Expected>
-openBuffer(StringRef DataPath) {
+static Expected> openBuffer(StringRef DataPath) {
   if (DataPath.empty())
 return createStringError(inconvertibleErrorCode(), "--data missing");
-  return errorOrToExpected(
-  DataPath == "-" ? llvm::MemoryBuffer::getSTDIN()
-  : llvm::MemoryBuffer::getFile(DataPath));
+  return errorOrToExpected(DataPath == "-"
+   ? llvm::MemoryBuffer::getSTDIN()
+   : llvm::MemoryBuffer::getFile(DataPath));
 }
 
 int dump(ObjectStore &CAS) {

``




https://github.com/llvm/llvm-project/pull/114094
___
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] [CAS] Add llvm-cas tools to inspect on-disk LLVMCAS (PR #114104)

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

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 7792cf341a8c8f8bb3149be2c686333636a28b67 
b35fe10335c9a5c6ab660310799d0c787b67d4e4 --extensions cpp -- 
llvm/tools/llvm-cas/llvm-cas.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/tools/llvm-cas/llvm-cas.cpp b/llvm/tools/llvm-cas/llvm-cas.cpp
index 291c6faf9f..b3dd0bb1f3 100644
--- a/llvm/tools/llvm-cas/llvm-cas.cpp
+++ b/llvm/tools/llvm-cas/llvm-cas.cpp
@@ -133,13 +133,12 @@ int main(int Argc, char **Argv) {
   return validateObject(*CAS, ID);
 }
 
-static Expected>
-openBuffer(StringRef DataPath) {
+static Expected> openBuffer(StringRef DataPath) {
   if (DataPath.empty())
 return createStringError(inconvertibleErrorCode(), "--data missing");
-  return errorOrToExpected(
-  DataPath == "-" ? llvm::MemoryBuffer::getSTDIN()
-  : llvm::MemoryBuffer::getFile(DataPath));
+  return errorOrToExpected(DataPath == "-"
+   ? llvm::MemoryBuffer::getSTDIN()
+   : llvm::MemoryBuffer::getFile(DataPath));
 }
 
 int dump(ObjectStore &CAS) {

``




https://github.com/llvm/llvm-project/pull/114104
___
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] AMDGPU: Fix producing invalid IR on vector typed getelementptr (PR #114113)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/114113
___
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] AMDGPU: Fix producing invalid IR on vector typed getelementptr (PR #114113)

2024-10-29 Thread Joseph Huber via llvm-branch-commits

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

Makes sense, thanks again.

https://github.com/llvm/llvm-project/pull/114113
___
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][func] Remove `func-bufferize` pass (PR #114152)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Matthias Springer (matthias-springer)


Changes

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `func-bufferize` pass, one of the few remaining parts of the old 
infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114017.


---

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


8 Files Affected:

- (modified) mlir/docs/Bufferization.md (+2-268) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.h (-3) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.td (-29) 
- (modified) mlir/lib/Dialect/Func/Transforms/CMakeLists.txt (-3) 
- (removed) mlir/lib/Dialect/Func/Transforms/FuncBufferize.cpp (-71) 
- (removed) mlir/test/Dialect/Func/func-bufferize.mlir (-83) 
- (modified) mlir/test/Dialect/Transform/test-pass-application.mlir (+2-2) 
- (modified) mlir/test/Integration/Dialect/MemRef/verify-memref.mlir (+1-1) 


``diff
diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index 7d38ebb38535c7..e16fe91212a1a5 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -23,11 +23,6 @@ the resulting `memref` IR has no memory leaks.
 
 ## Deprecated Passes
 
-The old dialect conversion-based bufferization passes have been deprecated and
-should not be used anymore. Most of those passes have already been removed from
-MLIR. One-Shot Bufferize produces in better bufferization results with fewer
-memory allocations and buffer copies.
-
 The buffer deallocation pass has been deprecated in favor of the 
ownership-based
 buffer deallocation pipeline. The deprecated pass has some limitations that may
 cause memory leaks in the resulting IR.
@@ -276,18 +271,13 @@ semantics (i.e., tensor result or tensor operand) that is 
not bufferizable
 `to_memref`/`to_tensor` ops around the bufferization boundary.
 
 One-Shot Bufferize can be configured to bufferize only ops from a set of
-dialects with `dialect-filter`. This can be useful for gradually migrating from
-dialect conversion-based bufferization to One-Shot Bufferize. One-Shot 
Bufferize
-must run first in such a case, because dialect conversion-based bufferization
-generates `to_tensor` ops without the `restrict` unit attribute, which One-Shot
-Bufferize cannot analyze.
+dialects with `dialect-filter`.
 
 One-Shot Bufferize can also be called programmatically with
 
[`bufferization::runOneShotBufferize`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h#L167).
 Alternatively,
 
[`bufferization::bufferizeOp`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h#L78)
-skips the analysis and inserts a copy on every buffer write, just like the
-dialect conversion-based bufferization.
+skips the analysis and inserts a copy on every buffer write.
 
 By default, function boundaries are not bufferized. This is because there are
 currently limitations around function graph bufferization: recursive
@@ -484,259 +474,3 @@ conflict detection algorithm, interested users may want 
to refer to:
 * [Original design 
document](https://discourse.llvm.org/uploads/short-url/5kckJ3DftYwQokG252teFgw3sYa.pdf)
 * [ODM talk](https://youtu.be/TXEo59CYS9A), 
([slides](https://mlir.llvm.org/OpenMeetings/2022-01-13-One-Shot-Bufferization.pdf)).
 * [LLVM Dev Meeting 2023 tutorial 
slides](https://m-sp.org/downloads/llvm_dev_2023.pdf)
-
-## Migrating from Dialect Conversion-based Bufferization
-
-Both dialect conversion-based bufferization and One-Shot Bufferize generate
-`to_tensor`/`to_memref` ops at the bufferization boundary (when run with
-`allow-unknown-ops`). They can be combined and run in sequence. However,
-One-Shot Bufferize must run first because it cannot analyze those boundary ops.
-To update existing code step-by-step, it may be useful to specify a dialect
-filter for One-Shot Bufferize, so that dialects can be switched over 
one-by-one.
-
-## Dialect Conversion-based Bufferization
-
-Disclaimer: Most dialect conversion-based bufferization has been migrated to
-One-Shot Bufferize. New users should use One-Shot Bufferize (with or without
-analysis). The following documentation is only for existing users of dialect
-conversion-based bufferization.
-
-This system is a simple application of MLIR's dialect conversion 
infrastructure.
-The bulk of the code related to bufferization is a set of ordinary
-`ConversionPattern`'s that dialect authors write for converting ops that 
operate
-on `tensor`'s to ops that operate on `memref`'s. A set of conventions a

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove `finalizing-bufferize` pass (PR #114154)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-sparse

Author: Matthias Springer (matthias-springer)


Changes

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `finalizing-bufferize` pass, one of the few remaining parts of the 
old infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114152.

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h (-4) 
- (modified) mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td (-16) 
- (modified) mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp (-75) 
- (modified) mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp 
(-2) 
- (removed) 
mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir (-95) 


``diff
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
index 72abb5b3f1f94e..8b957577292796 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
@@ -200,10 +200,6 @@ std::unique_ptr createEmptyTensorToAllocTensorPass();
 /// Drop all memref function results that are equivalent to a function 
argument.
 LogicalResult dropEquivalentBufferResults(ModuleOp module);
 
-/// Creates a pass that finalizes a partial bufferization by removing remaining
-/// bufferization.to_tensor and bufferization.to_memref operations.
-std::unique_ptr> createFinalizingBufferizePass();
-
 /// Create a pass that bufferizes all ops that implement 
BufferizableOpInterface
 /// with One-Shot Bufferize.
 std::unique_ptr createOneShotBufferizePass();
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
index cc5463ea968fc3..3e1b55cf99767f 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
@@ -343,22 +343,6 @@ def BufferResultsToOutParams : 
Pass<"buffer-results-to-out-params", "ModuleOp">
   let dependentDialects = ["memref::MemRefDialect"];
 }
 
-def FinalizingBufferize : Pass<"finalizing-bufferize", "func::FuncOp"> {
-  let summary = "Finalize a partial bufferization";
-  let description = [{
-A bufferize pass that finalizes a partial bufferization by removing
-remaining `bufferization.to_tensor` and `bufferization.to_buffer` 
operations.
-
-The removal of those operations is only possible if the operations only
-exist in pairs, i.e., all uses of `bufferization.to_tensor` operations are
-`bufferization.to_buffer` operations.
-
-This pass will fail if not all operations can be removed or if any 
operation
-with tensor typed operands remains.
-  }];
-  let constructor = "mlir::bufferization::createFinalizingBufferizePass()";
-}
-
 def DropEquivalentBufferResults : Pass<"drop-equivalent-buffer-results", 
"ModuleOp">  {
   let summary = "Remove MemRef return values that are equivalent to a bbArg";
   let description = [{
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 1d009b03754c52..62ce2583f4fa1d 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -26,7 +26,6 @@
 
 namespace mlir {
 namespace bufferization {
-#define GEN_PASS_DEF_FINALIZINGBUFFERIZE
 #define GEN_PASS_DEF_BUFFERIZATIONBUFFERIZE
 #define GEN_PASS_DEF_ONESHOTBUFFERIZE
 #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc"
@@ -98,75 +97,6 @@ void 
mlir::bufferization::populateBufferizeMaterializationLegality(
 }
 
 namespace {
-// In a finalizing bufferize conversion, we know that all tensors have been
-// converted to memrefs, thus, this op becomes an identity.
-class BufferizeToTensorOp
-: public OpConversionPattern {
-public:
-  using OpConversionPattern::OpConversionPattern;
-  LogicalResult
-  matchAndRewrite(bufferization::ToTensorOp op, OpAdaptor adaptor,
-  ConversionPatternRewriter &rewriter) const override {
-rewriter.replaceOp(op, adaptor.getMemref());
-return success();
-  }
-};
-} // namespace
-
-namespace {
-// In a finalizing bufferize conversion, we know that all tensors have been
-// converted to memrefs, thus, this op becomes an identity.
-class BufferizeToMemrefOp
-: public OpConversionPattern {
-public:
-  using OpConversionPattern::OpConversionPattern;
-  LogicalResult
-  matchAndRewrite(bufferization::ToMemrefOp op, OpAdaptor adaptor,
-  ConversionPatternRewriter &rewriter) const override {
-rewriter.replaceO

[llvm-branch-commits] [mlir] [mlir][func] Remove `func-bufferize` pass (PR #114152)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `func-bufferize` pass, one of the few remaining parts of the old 
infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114017.


>From be96e32cd32371c663943ed735eab77cdd040414 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Wed, 30 Oct 2024 00:39:28 +0100
Subject: [PATCH] [mlir][func] Remove `func-bufferize` pass

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `func-bufferize` pass, one of the few remaining parts of the old 
infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.
---
 mlir/docs/Bufferization.md| 270 +-
 .../mlir/Dialect/Func/Transforms/Passes.h |   3 -
 .../mlir/Dialect/Func/Transforms/Passes.td|  29 --
 .../Dialect/Func/Transforms/CMakeLists.txt|   3 -
 .../Dialect/Func/Transforms/FuncBufferize.cpp |  71 -
 mlir/test/Dialect/Func/func-bufferize.mlir|  83 --
 .../Transform/test-pass-application.mlir  |   4 +-
 .../Dialect/MemRef/verify-memref.mlir |   2 +-
 8 files changed, 5 insertions(+), 460 deletions(-)
 delete mode 100644 mlir/lib/Dialect/Func/Transforms/FuncBufferize.cpp
 delete mode 100644 mlir/test/Dialect/Func/func-bufferize.mlir

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index 7d38ebb38535c7..e16fe91212a1a5 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -23,11 +23,6 @@ the resulting `memref` IR has no memory leaks.
 
 ## Deprecated Passes
 
-The old dialect conversion-based bufferization passes have been deprecated and
-should not be used anymore. Most of those passes have already been removed from
-MLIR. One-Shot Bufferize produces in better bufferization results with fewer
-memory allocations and buffer copies.
-
 The buffer deallocation pass has been deprecated in favor of the 
ownership-based
 buffer deallocation pipeline. The deprecated pass has some limitations that may
 cause memory leaks in the resulting IR.
@@ -276,18 +271,13 @@ semantics (i.e., tensor result or tensor operand) that is 
not bufferizable
 `to_memref`/`to_tensor` ops around the bufferization boundary.
 
 One-Shot Bufferize can be configured to bufferize only ops from a set of
-dialects with `dialect-filter`. This can be useful for gradually migrating from
-dialect conversion-based bufferization to One-Shot Bufferize. One-Shot 
Bufferize
-must run first in such a case, because dialect conversion-based bufferization
-generates `to_tensor` ops without the `restrict` unit attribute, which One-Shot
-Bufferize cannot analyze.
+dialects with `dialect-filter`.
 
 One-Shot Bufferize can also be called programmatically with
 
[`bufferization::runOneShotBufferize`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h#L167).
 Alternatively,
 
[`bufferization::bufferizeOp`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h#L78)
-skips the analysis and inserts a copy on every buffer write, just like the
-dialect conversion-based bufferization.
+skips the analysis and inserts a copy on every buffer write.
 
 By default, function boundaries are not bufferized. This is because there are
 currently limitations around function graph bufferization: recursive
@@ -484,259 +474,3 @@ conflict detection algorithm, interested users may want 
to refer to:
 * [Original design 
document](https://discourse.llvm.org/uploads/short-url/5kckJ3DftYwQokG252teFgw3sYa.pdf)
 * [ODM talk](https://youtu.be/TXEo59CYS9A), 
([slides](https://mlir.llvm.org/OpenMeetings/2022-01-13-One-Shot-Bufferization.pdf)).
 * [LLVM Dev Meeting 2023 tutorial 
slides](https://m-sp.org/downloads/llvm_dev_2023.pdf)
-
-## Migrating from Dialect Conversion-based Bufferization
-
-Both dialect conversion-based bufferization and One-Shot Bufferize generate
-`to_tensor`/`to_memref` ops at the bufferization boundary (when run with
-`allow-unknown-ops`). They can be combined and run in sequence. However,
-One-Shot Bufferize must run first because it cannot analyze those boundary ops.
-To update existing code step-by-step, it may be useful to specify a dialect
-filter for One-Shot Bufferize, so that dialects can be switched over 
one-by-one.
-
-## Dialect Conversion-based Bufferization
-
-Disclaimer

[llvm-branch-commits] [mlir] [mlir][func] Remove `func-bufferize` pass (PR #114152)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-memref

Author: Matthias Springer (matthias-springer)


Changes

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `func-bufferize` pass, one of the few remaining parts of the old 
infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114017.


---

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


8 Files Affected:

- (modified) mlir/docs/Bufferization.md (+2-268) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.h (-3) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.td (-29) 
- (modified) mlir/lib/Dialect/Func/Transforms/CMakeLists.txt (-3) 
- (removed) mlir/lib/Dialect/Func/Transforms/FuncBufferize.cpp (-71) 
- (removed) mlir/test/Dialect/Func/func-bufferize.mlir (-83) 
- (modified) mlir/test/Dialect/Transform/test-pass-application.mlir (+2-2) 
- (modified) mlir/test/Integration/Dialect/MemRef/verify-memref.mlir (+1-1) 


``diff
diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index 7d38ebb38535c7..e16fe91212a1a5 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -23,11 +23,6 @@ the resulting `memref` IR has no memory leaks.
 
 ## Deprecated Passes
 
-The old dialect conversion-based bufferization passes have been deprecated and
-should not be used anymore. Most of those passes have already been removed from
-MLIR. One-Shot Bufferize produces in better bufferization results with fewer
-memory allocations and buffer copies.
-
 The buffer deallocation pass has been deprecated in favor of the 
ownership-based
 buffer deallocation pipeline. The deprecated pass has some limitations that may
 cause memory leaks in the resulting IR.
@@ -276,18 +271,13 @@ semantics (i.e., tensor result or tensor operand) that is 
not bufferizable
 `to_memref`/`to_tensor` ops around the bufferization boundary.
 
 One-Shot Bufferize can be configured to bufferize only ops from a set of
-dialects with `dialect-filter`. This can be useful for gradually migrating from
-dialect conversion-based bufferization to One-Shot Bufferize. One-Shot 
Bufferize
-must run first in such a case, because dialect conversion-based bufferization
-generates `to_tensor` ops without the `restrict` unit attribute, which One-Shot
-Bufferize cannot analyze.
+dialects with `dialect-filter`.
 
 One-Shot Bufferize can also be called programmatically with
 
[`bufferization::runOneShotBufferize`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h#L167).
 Alternatively,
 
[`bufferization::bufferizeOp`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h#L78)
-skips the analysis and inserts a copy on every buffer write, just like the
-dialect conversion-based bufferization.
+skips the analysis and inserts a copy on every buffer write.
 
 By default, function boundaries are not bufferized. This is because there are
 currently limitations around function graph bufferization: recursive
@@ -484,259 +474,3 @@ conflict detection algorithm, interested users may want 
to refer to:
 * [Original design 
document](https://discourse.llvm.org/uploads/short-url/5kckJ3DftYwQokG252teFgw3sYa.pdf)
 * [ODM talk](https://youtu.be/TXEo59CYS9A), 
([slides](https://mlir.llvm.org/OpenMeetings/2022-01-13-One-Shot-Bufferization.pdf)).
 * [LLVM Dev Meeting 2023 tutorial 
slides](https://m-sp.org/downloads/llvm_dev_2023.pdf)
-
-## Migrating from Dialect Conversion-based Bufferization
-
-Both dialect conversion-based bufferization and One-Shot Bufferize generate
-`to_tensor`/`to_memref` ops at the bufferization boundary (when run with
-`allow-unknown-ops`). They can be combined and run in sequence. However,
-One-Shot Bufferize must run first because it cannot analyze those boundary ops.
-To update existing code step-by-step, it may be useful to specify a dialect
-filter for One-Shot Bufferize, so that dialects can be switched over 
one-by-one.
-
-## Dialect Conversion-based Bufferization
-
-Disclaimer: Most dialect conversion-based bufferization has been migrated to
-One-Shot Bufferize. New users should use One-Shot Bufferize (with or without
-analysis). The following documentation is only for existing users of dialect
-conversion-based bufferization.
-
-This system is a simple application of MLIR's dialect conversion 
infrastructure.
-The bulk of the code related to bufferization is a set of ordinary
-`ConversionPattern`'s that dialect authors write for converting ops that 
operate
-on `tensor`'s to ops that operate on `memref`'s. A set of conven

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove `finalizing-bufferize` pass (PR #114154)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

>From 7c2f6b68d81536889deae221db5df3565089b60b Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Wed, 30 Oct 2024 00:46:05 +0100
Subject: [PATCH] [mlir][bufferization] Remove `finalizing-bufferize` pass

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `finalizing-bufferize` pass, one of the few remaining parts of the 
old infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114152.
---
 .../Bufferization/Transforms/Bufferize.h  |  6 --
 .../Dialect/Bufferization/Transforms/Passes.h |  4 -
 .../Bufferization/Transforms/Passes.td| 16 
 .../Bufferization/Transforms/Bufferize.cpp| 75 ---
 .../Pipelines/SparseTensorPipelines.cpp   |  2 -
 .../Transforms/finalizing-bufferize.mlir  | 95 ---
 6 files changed, 198 deletions(-)
 delete mode 100644 
mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir

diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
index 1603dfcbae5589..ebed2c354bfca5 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
@@ -56,12 +56,6 @@ class BufferizeTypeConverter : public TypeConverter {
 /// populateEliminateBufferizeMaterializationsPatterns.
 void populateBufferizeMaterializationLegality(ConversionTarget &target);
 
-/// Populate patterns to eliminate bufferize materializations.
-///
-/// In particular, these are the tensor_load/buffer_cast ops.
-void populateEliminateBufferizeMaterializationsPatterns(
-const BufferizeTypeConverter &typeConverter, RewritePatternSet &patterns);
-
 /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
 ///
 /// Note: This function does not resolve read-after-write conflicts. Use this
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
index 72abb5b3f1f94e..8b957577292796 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
@@ -200,10 +200,6 @@ std::unique_ptr createEmptyTensorToAllocTensorPass();
 /// Drop all memref function results that are equivalent to a function 
argument.
 LogicalResult dropEquivalentBufferResults(ModuleOp module);
 
-/// Creates a pass that finalizes a partial bufferization by removing remaining
-/// bufferization.to_tensor and bufferization.to_memref operations.
-std::unique_ptr> createFinalizingBufferizePass();
-
 /// Create a pass that bufferizes all ops that implement 
BufferizableOpInterface
 /// with One-Shot Bufferize.
 std::unique_ptr createOneShotBufferizePass();
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
index cc5463ea968fc3..3e1b55cf99767f 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
@@ -343,22 +343,6 @@ def BufferResultsToOutParams : 
Pass<"buffer-results-to-out-params", "ModuleOp">
   let dependentDialects = ["memref::MemRefDialect"];
 }
 
-def FinalizingBufferize : Pass<"finalizing-bufferize", "func::FuncOp"> {
-  let summary = "Finalize a partial bufferization";
-  let description = [{
-A bufferize pass that finalizes a partial bufferization by removing
-remaining `bufferization.to_tensor` and `bufferization.to_buffer` 
operations.
-
-The removal of those operations is only possible if the operations only
-exist in pairs, i.e., all uses of `bufferization.to_tensor` operations are
-`bufferization.to_buffer` operations.
-
-This pass will fail if not all operations can be removed or if any 
operation
-with tensor typed operands remains.
-  }];
-  let constructor = "mlir::bufferization::createFinalizingBufferizePass()";
-}
-
 def DropEquivalentBufferResults : Pass<"drop-equivalent-buffer-results", 
"ModuleOp">  {
   let summary = "Remove MemRef return values that are equivalent to a bbArg";
   let description = [{
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 1d009b03754c52..62ce2583f4fa1d 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -26,7 +26,6 @@
 
 namespace mlir {
 namespace bufferization {
-#define GEN_PASS_DEF_FINALIZINGBUFFERIZE
 #define GEN_PASS_DEF_BUFFERIZATIONBUFFERIZE
 #define GEN_PASS_DEF_ONESHOTBUFFERIZE
 #includ

[llvm-branch-commits] [mlir] [mlir][func] Remove `func-bufferize` pass (PR #114152)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-func

Author: Matthias Springer (matthias-springer)


Changes

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `func-bufferize` pass, one of the few remaining parts of the old 
infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114017.


---

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


8 Files Affected:

- (modified) mlir/docs/Bufferization.md (+2-268) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.h (-3) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.td (-29) 
- (modified) mlir/lib/Dialect/Func/Transforms/CMakeLists.txt (-3) 
- (removed) mlir/lib/Dialect/Func/Transforms/FuncBufferize.cpp (-71) 
- (removed) mlir/test/Dialect/Func/func-bufferize.mlir (-83) 
- (modified) mlir/test/Dialect/Transform/test-pass-application.mlir (+2-2) 
- (modified) mlir/test/Integration/Dialect/MemRef/verify-memref.mlir (+1-1) 


``diff
diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index 7d38ebb38535c7..e16fe91212a1a5 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -23,11 +23,6 @@ the resulting `memref` IR has no memory leaks.
 
 ## Deprecated Passes
 
-The old dialect conversion-based bufferization passes have been deprecated and
-should not be used anymore. Most of those passes have already been removed from
-MLIR. One-Shot Bufferize produces in better bufferization results with fewer
-memory allocations and buffer copies.
-
 The buffer deallocation pass has been deprecated in favor of the 
ownership-based
 buffer deallocation pipeline. The deprecated pass has some limitations that may
 cause memory leaks in the resulting IR.
@@ -276,18 +271,13 @@ semantics (i.e., tensor result or tensor operand) that is 
not bufferizable
 `to_memref`/`to_tensor` ops around the bufferization boundary.
 
 One-Shot Bufferize can be configured to bufferize only ops from a set of
-dialects with `dialect-filter`. This can be useful for gradually migrating from
-dialect conversion-based bufferization to One-Shot Bufferize. One-Shot 
Bufferize
-must run first in such a case, because dialect conversion-based bufferization
-generates `to_tensor` ops without the `restrict` unit attribute, which One-Shot
-Bufferize cannot analyze.
+dialects with `dialect-filter`.
 
 One-Shot Bufferize can also be called programmatically with
 
[`bufferization::runOneShotBufferize`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h#L167).
 Alternatively,
 
[`bufferization::bufferizeOp`](https://github.com/llvm/llvm-project/blob/ae2764e835a26bad9774803eca0a6530df2a3e2d/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h#L78)
-skips the analysis and inserts a copy on every buffer write, just like the
-dialect conversion-based bufferization.
+skips the analysis and inserts a copy on every buffer write.
 
 By default, function boundaries are not bufferized. This is because there are
 currently limitations around function graph bufferization: recursive
@@ -484,259 +474,3 @@ conflict detection algorithm, interested users may want 
to refer to:
 * [Original design 
document](https://discourse.llvm.org/uploads/short-url/5kckJ3DftYwQokG252teFgw3sYa.pdf)
 * [ODM talk](https://youtu.be/TXEo59CYS9A), 
([slides](https://mlir.llvm.org/OpenMeetings/2022-01-13-One-Shot-Bufferization.pdf)).
 * [LLVM Dev Meeting 2023 tutorial 
slides](https://m-sp.org/downloads/llvm_dev_2023.pdf)
-
-## Migrating from Dialect Conversion-based Bufferization
-
-Both dialect conversion-based bufferization and One-Shot Bufferize generate
-`to_tensor`/`to_memref` ops at the bufferization boundary (when run with
-`allow-unknown-ops`). They can be combined and run in sequence. However,
-One-Shot Bufferize must run first because it cannot analyze those boundary ops.
-To update existing code step-by-step, it may be useful to specify a dialect
-filter for One-Shot Bufferize, so that dialects can be switched over 
one-by-one.
-
-## Dialect Conversion-based Bufferization
-
-Disclaimer: Most dialect conversion-based bufferization has been migrated to
-One-Shot Bufferize. New users should use One-Shot Bufferize (with or without
-analysis). The following documentation is only for existing users of dialect
-conversion-based bufferization.
-
-This system is a simple application of MLIR's dialect conversion 
infrastructure.
-The bulk of the code related to bufferization is a set of ordinary
-`ConversionPattern`'s that dialect authors write for converting ops that 
operate
-on `tensor`'s to ops that operate on `memref`'s. A set of conventi

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove `finalizing-bufferize` pass (PR #114154)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `finalizing-bufferize` pass, one of the few remaining parts of the 
old infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114152.

>From e353503a55f1a76cc28a343e3ed2bf6bc0946357 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Wed, 30 Oct 2024 00:46:05 +0100
Subject: [PATCH] [mlir][bufferization] Remove `finalizing-bufferize` pass

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `finalizing-bufferize` pass, one of the few remaining parts of the 
old infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114152.
---
 .../Dialect/Bufferization/Transforms/Passes.h |  4 -
 .../Bufferization/Transforms/Passes.td| 16 
 .../Bufferization/Transforms/Bufferize.cpp| 75 ---
 .../Pipelines/SparseTensorPipelines.cpp   |  2 -
 .../Transforms/finalizing-bufferize.mlir  | 95 ---
 5 files changed, 192 deletions(-)
 delete mode 100644 
mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir

diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
index 72abb5b3f1f94e..8b957577292796 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
@@ -200,10 +200,6 @@ std::unique_ptr createEmptyTensorToAllocTensorPass();
 /// Drop all memref function results that are equivalent to a function 
argument.
 LogicalResult dropEquivalentBufferResults(ModuleOp module);
 
-/// Creates a pass that finalizes a partial bufferization by removing remaining
-/// bufferization.to_tensor and bufferization.to_memref operations.
-std::unique_ptr> createFinalizingBufferizePass();
-
 /// Create a pass that bufferizes all ops that implement 
BufferizableOpInterface
 /// with One-Shot Bufferize.
 std::unique_ptr createOneShotBufferizePass();
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
index cc5463ea968fc3..3e1b55cf99767f 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
@@ -343,22 +343,6 @@ def BufferResultsToOutParams : 
Pass<"buffer-results-to-out-params", "ModuleOp">
   let dependentDialects = ["memref::MemRefDialect"];
 }
 
-def FinalizingBufferize : Pass<"finalizing-bufferize", "func::FuncOp"> {
-  let summary = "Finalize a partial bufferization";
-  let description = [{
-A bufferize pass that finalizes a partial bufferization by removing
-remaining `bufferization.to_tensor` and `bufferization.to_buffer` 
operations.
-
-The removal of those operations is only possible if the operations only
-exist in pairs, i.e., all uses of `bufferization.to_tensor` operations are
-`bufferization.to_buffer` operations.
-
-This pass will fail if not all operations can be removed or if any 
operation
-with tensor typed operands remains.
-  }];
-  let constructor = "mlir::bufferization::createFinalizingBufferizePass()";
-}
-
 def DropEquivalentBufferResults : Pass<"drop-equivalent-buffer-results", 
"ModuleOp">  {
   let summary = "Remove MemRef return values that are equivalent to a bbArg";
   let description = [{
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 1d009b03754c52..62ce2583f4fa1d 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -26,7 +26,6 @@
 
 namespace mlir {
 namespace bufferization {
-#define GEN_PASS_DEF_FINALIZINGBUFFERIZE
 #define GEN_PASS_DEF_BUFFERIZATIONBUFFERIZE
 #define GEN_PASS_DEF_ONESHOTBUFFERIZE
 #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc"
@@ -98,75 +97,6 @@ void 
mlir::bufferization::populateBufferizeMaterializationLegality(
 }
 
 namespace {
-// In a finalizing bufferize conversion, we know that all tensors have been
-// converted to memrefs, thus, this op becomes an identity.
-class BufferizeToTensorOp
-: public OpConversionPattern {
-public:
-  using OpConversionPattern::OpConversionPattern;
-  LogicalResult
-  matchAndRewrite(bufferization::ToTensorOp op, OpAdaptor adaptor,
-  ConversionPatternRewriter &rewriter) const ove

[llvm-branch-commits] [mlir] [mlir][bufferization] Add support for non-unique `func.return` (PR #114017)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

>From 684ac4a0795d5fadef5a16a3acd45eddf838c857 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Tue, 29 Oct 2024 09:51:11 +0100
Subject: [PATCH] [mlir][bufferization] Add support for non-unique
 `func.return`

---
 .../FuncBufferizableOpInterfaceImpl.cpp   |  75 +++-
 .../Transforms/OneShotModuleBufferize.cpp | 179 +-
 .../one-shot-module-bufferize-analysis.mlir   |  45 +
 .../one-shot-module-bufferize-invalid.mlir|  22 +--
 .../Transforms/one-shot-module-bufferize.mlir |  24 +++
 5 files changed, 235 insertions(+), 110 deletions(-)

diff --git 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
index 6e91d3b89a7c79..195b17fcf902a2 100644
--- 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
+++ 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
@@ -41,18 +41,13 @@ void FuncAnalysisState::startFunctionAnalysis(FuncOp 
funcOp) {
 #endif // NDEBUG
 }
 
-/// Return the unique ReturnOp that terminates `funcOp`.
-/// Return nullptr if there is no such unique ReturnOp.
-static func::ReturnOp getAssumedUniqueReturnOp(FuncOp funcOp) {
-  func::ReturnOp returnOp;
-  for (Block &b : funcOp.getBody()) {
-if (auto candidateOp = dyn_cast(b.getTerminator())) {
-  if (returnOp)
-return nullptr;
-  returnOp = candidateOp;
-}
-  }
-  return returnOp;
+/// Return all top-level func.return ops in the given function.
+static SmallVector getReturnOps(FuncOp funcOp) {
+  SmallVector result;
+  for (Block &b : funcOp.getBody())
+if (auto returnOp = dyn_cast(b.getTerminator()))
+  result.push_back(returnOp);
+  return result;
 }
 
 /// Return the index-th bufferized function argument type. This assumes that 
the
@@ -372,15 +367,6 @@ struct FuncOpInterface
 getBufferType(op, value, options, invocationStack);
   }
 
-  LogicalResult verifyAnalysis(Operation *op,
-   const AnalysisState &state) const {
-auto funcOp = cast(op);
-// TODO: func.func with multiple returns are not supported.
-if (!getAssumedUniqueReturnOp(funcOp) && !funcOp.isExternal())
-  return op->emitOpError("op without unique func.return is not supported");
-return success();
-  }
-
   /// Rewrite function bbArgs and return values into buffer form. This function
   /// bufferizes the function signature and the ReturnOp. When the entire
   /// function body has been bufferized, function return types can be switched
@@ -427,41 +413,38 @@ struct FuncOpInterface
   return success();
 }
 
-// TODO: Support functions with multiple returns.
-func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOp);
-assert(returnOp && "expected func with single return op");
-assert(returnOp->getNumOperands() == retTypes.size() &&
-   "incorrect number of return values");
-Location loc = returnOp.getLoc();
-
 // 1. Bufferize every block.
 for (Block &block : funcOp.getBody())
   if (failed(bufferization::bufferizeBlockSignature(&block, rewriter,
 options)))
 return failure();
 
-// 2. Bufferize all operands of the return op.
-SmallVector returnValues;
-for (auto [returnVal, bufferizedType] :
- llvm::zip_equal(returnOp->getOperands(), retTypes)) {
-  auto tensorType = dyn_cast(returnVal.getType());
-  rewriter.setInsertionPoint(returnOp);
-
-  // If not a tensor type just forward it.
-  if (!tensorType) {
-returnValues.push_back(returnVal);
-continue;
+// 2. Bufferize the operands of the all return op.
+for (func::ReturnOp returnOp : getReturnOps(funcOp)) {
+  assert(returnOp->getNumOperands() == retTypes.size() &&
+ "incorrect number of return values");
+  SmallVector returnValues;
+  for (auto [returnVal, bufferizedType] :
+   llvm::zip_equal(returnOp->getOperands(), retTypes)) {
+auto tensorType = dyn_cast(returnVal.getType());
+rewriter.setInsertionPoint(returnOp);
+
+// If not a tensor type just forward it.
+if (!tensorType) {
+  returnValues.push_back(returnVal);
+  continue;
+}
+
+// Note: If `inferFunctionResultLayout = true`, casts are later folded
+// away.
+Value toMemrefOp = rewriter.create(
+returnOp.getLoc(), bufferizedType, returnVal);
+returnValues.push_back(toMemrefOp);
   }
 
-  // Note: If `inferFunctionResultLayout = true`, casts are later folded
-  // away.
-  Value toMemrefOp = rewriter.create(
-  loc, bufferizedType, returnVal);
-  returnValues.push_back(toMemrefOp);
+  returnOp.getOperandsMutable().assign(returnValues);
 }
 
-returnOp.g

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove remaining dialect conversion-based infra parts (PR #114155)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-func

Author: Matthias Springer (matthias-springer)


Changes

This commit removes the last remaining components of the dialect 
conversion-based bufferization passes.

Note for LLVM integration: If you depend on these components, migrate to 
One-Shot Bufferize or copy them to your codebase.

Depends on #114154.

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
(-23) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.h (-4) 
- (modified) mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp (+3-2) 
- (modified) mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp (-73) 


``diff
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
index ebed2c354bfca5..2f495d304b4a56 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
@@ -38,24 +38,6 @@ struct BufferizationStatistics {
   int64_t numTensorOutOfPlace = 0;
 };
 
-/// A helper type converter class that automatically populates the relevant
-/// materializations and type conversions for bufferization.
-class BufferizeTypeConverter : public TypeConverter {
-public:
-  BufferizeTypeConverter();
-};
-
-/// Marks ops used by bufferization for type conversion materializations as
-/// "legal" in the given ConversionTarget.
-///
-/// This function should be called by all bufferization passes using
-/// BufferizeTypeConverter so that materializations work properly. One 
exception
-/// is bufferization passes doing "full" conversions, where it can be desirable
-/// for even the materializations to remain illegal so that they are 
eliminated,
-/// such as via the patterns in
-/// populateEliminateBufferizeMaterializationsPatterns.
-void populateBufferizeMaterializationLegality(ConversionTarget &target);
-
 /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
 ///
 /// Note: This function does not resolve read-after-write conflicts. Use this
@@ -81,11 +63,6 @@ LogicalResult bufferizeOp(Operation *op, const 
BufferizationOptions &options,
 LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
   const BufferizationOptions &options);
 
-/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
-/// old (deprecated) partial, dialect conversion-based bufferization passes. A
-/// copy will be inserted before every buffer write.
-BufferizationOptions getPartialBufferizationOptions();
-
 } // namespace bufferization
 } // namespace mlir
 
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
index 02fc9e1d934390..0248f068320c54 100644
--- a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
@@ -18,10 +18,6 @@
 #include "mlir/Pass/Pass.h"
 
 namespace mlir {
-namespace bufferization {
-class BufferizeTypeConverter;
-} // namespace bufferization
-
 class RewritePatternSet;
 
 namespace func {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index 8fffdbf664c3f4..da77a735cd59d7 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -11,6 +11,8 @@
 
//===--===//
 
 #include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
@@ -138,8 +140,7 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, 
uint64_t alignment,
   alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
 : IntegerAttr();
 
-  BufferizeTypeConverter typeConverter;
-  auto memrefType = cast(typeConverter.convertType(type));
+  auto memrefType = 
cast(getMemRefTypeWithStaticIdentityLayout(type));
   if (memorySpace)
 memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
   auto global = globalBuilder.create(
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 62ce2583f4fa1d..6f0cdfa20f7be5 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -37,65 +37,6 @@ namespace bufferization {
 using namespace mlir;
 using namespace mlir::bufferization;
 
-//===--===//
-// BufferizeTypeC

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove remaining dialect conversion-based infra parts (PR #114155)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

This commit removes the last remaining components of the dialect 
conversion-based bufferization passes.

Note for LLVM integration: If you depend on these components, migrate to 
One-Shot Bufferize or copy them to your codebase.

Depends on #114154.

>From 9192d2d5329910bbc2e641ac979eef40760f Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Wed, 30 Oct 2024 00:58:32 +0100
Subject: [PATCH] [mlir][bufferization] Remove remaining dialect
 conversion-based infra parts

This commit removes the last remaining components of the dialect 
conversion-based bufferization passes.

Note for LLVM integration: If you depend on these components, migrate to 
One-Shot Bufferize or copy them to your codebase.

Depends on #114154.
---
 .../Bufferization/Transforms/Bufferize.h  | 23 --
 .../mlir/Dialect/Func/Transforms/Passes.h |  4 -
 .../Bufferization/Transforms/BufferUtils.cpp  |  5 +-
 .../Bufferization/Transforms/Bufferize.cpp| 73 ---
 4 files changed, 3 insertions(+), 102 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
index ebed2c354bfca5..2f495d304b4a56 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
@@ -38,24 +38,6 @@ struct BufferizationStatistics {
   int64_t numTensorOutOfPlace = 0;
 };
 
-/// A helper type converter class that automatically populates the relevant
-/// materializations and type conversions for bufferization.
-class BufferizeTypeConverter : public TypeConverter {
-public:
-  BufferizeTypeConverter();
-};
-
-/// Marks ops used by bufferization for type conversion materializations as
-/// "legal" in the given ConversionTarget.
-///
-/// This function should be called by all bufferization passes using
-/// BufferizeTypeConverter so that materializations work properly. One 
exception
-/// is bufferization passes doing "full" conversions, where it can be desirable
-/// for even the materializations to remain illegal so that they are 
eliminated,
-/// such as via the patterns in
-/// populateEliminateBufferizeMaterializationsPatterns.
-void populateBufferizeMaterializationLegality(ConversionTarget &target);
-
 /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
 ///
 /// Note: This function does not resolve read-after-write conflicts. Use this
@@ -81,11 +63,6 @@ LogicalResult bufferizeOp(Operation *op, const 
BufferizationOptions &options,
 LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
   const BufferizationOptions &options);
 
-/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
-/// old (deprecated) partial, dialect conversion-based bufferization passes. A
-/// copy will be inserted before every buffer write.
-BufferizationOptions getPartialBufferizationOptions();
-
 } // namespace bufferization
 } // namespace mlir
 
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
index 02fc9e1d934390..0248f068320c54 100644
--- a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
@@ -18,10 +18,6 @@
 #include "mlir/Pass/Pass.h"
 
 namespace mlir {
-namespace bufferization {
-class BufferizeTypeConverter;
-} // namespace bufferization
-
 class RewritePatternSet;
 
 namespace func {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index 8fffdbf664c3f4..da77a735cd59d7 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -11,6 +11,8 @@
 
//===--===//
 
 #include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
@@ -138,8 +140,7 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, 
uint64_t alignment,
   alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
 : IntegerAttr();
 
-  BufferizeTypeConverter typeConverter;
-  auto memrefType = cast(typeConverter.convertType(type));
+  auto memrefType = 
cast(getMemRefTypeWithStaticIdentityLayout(type));
   if (memorySpace)
 memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
   auto global = globalBuilder.create(
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 62ce2583f4fa1d..6f0c

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove remaining dialect conversion-based infra parts (PR #114155)

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

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 7c2f6b68d81536889deae221db5df3565089b60b 
9192d2d5329910bbc2e641ac979eef40760f --extensions cpp,h -- 
mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
mlir/include/mlir/Dialect/Func/Transforms/Passes.h 
mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp 
mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
``





View the diff from clang-format here.


``diff
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index da77a735cd..b11803da19 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -140,7 +140,8 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, 
uint64_t alignment,
   alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
 : IntegerAttr();
 
-  auto memrefType = 
cast(getMemRefTypeWithStaticIdentityLayout(type));
+  auto memrefType =
+  cast(getMemRefTypeWithStaticIdentityLayout(type));
   if (memorySpace)
 memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
   auto global = globalBuilder.create(

``




https://github.com/llvm/llvm-project/pull/114155
___
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] [DataLayout][LangRef] Split non-integral and unstable pointer properties (PR #105735)

2024-10-29 Thread Alexander Richardson via llvm-branch-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/105735

>From e4bd1181d160b8728e7d4158417a83e183bd1709 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Thu, 22 Aug 2024 14:36:04 -0700
Subject: [PATCH 1/3] fix indentation in langref

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 200224c78be004..1a59fba65815cc 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3103,19 +3103,19 @@ as follows:
 ``A``
 Specifies the address space of objects created by '``alloca``'.
 Defaults to the default address space of 0.
-``p[][n]::[:][:]``
+``p[][]::[:][:]``
 This specifies the *size* of a pointer and its  and
 \erred alignments for address space ``n``.  is optional
 and defaults to . The fourth parameter  is the size of 
the
 index that used for address calculation, which must be less than or equal
 to the pointer size. If not
 specified, the default index size is equal to the pointer size. All sizes
-are in bits. The address space, ``n``, is optional, and if not specified,
-denotes the default address space 0. The value of ``n`` must be
-in the range [1,2^24).
+are in bits. The , is optional, and if not specified,
+denotes the default address space 0. The value of  must
+be in the range [1,2^24).
 The optional are used to specify properties of pointers in this
-address space: the character ``u`` marks pointers as having an unstable
-representation and ```n`` marks pointers as non-integral (i.e. having
+address space: the character ``u`` marks pointers as having an unstable
+representation and ``n`` marks pointers as non-integral (i.e. having
 additional metadata). See :ref:`Non-Integral Pointer Types `.
 
 ``i:[:]``

>From db97145d3a653f2999b5935f9b1cb4550230689d Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Fri, 25 Oct 2024 12:51:11 -0700
Subject: [PATCH 2/3] include feedback

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst | 30 +-
 llvm/include/llvm/IR/DataLayout.h |  8 
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index c137318af678b6..3c3d0e0b4ab8ee 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -659,7 +659,7 @@ LLVM IR optionally allows the frontend to denote pointers 
in certain address
 spaces as "non-integral" or "unstable" (or both "non-integral" and "unstable")
 via the :ref:`datalayout string`.
 
-These exact implications of these properties are target-specific, but the
+The exact implications of these properties are target-specific, but the
 following IR semantics and restrictions to optimization passes apply:
 
 Unstable pointer representation
@@ -668,7 +668,7 @@ Unstable pointer representation
 Pointers in this address space have an *unspecified* bitwise representation
 (i.e. not backed by a fixed integer). The bitwise pattern of such pointers is
 allowed to change in a target-specific way. For example, this could be a 
pointer
-type used for with copying garbage collection where the garbage collector could
+type used with copying garbage collection where the garbage collector could
 update the pointer at any time in the collection sweep.
 
 ``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for
@@ -705,10 +705,10 @@ representation of the pointer.
 Non-integral pointer representation
 ^^^
 
-Pointers are not represented as an address, but may instead include
+Pointers are not represented as just an address, but may instead include
 additional metadata such as bounds information or a temporal identifier.
 Examples include AMDGPU buffer descriptors with a 128-bit fat pointer and a
-32-bit offset or CHERI capabilities that contain bounds, permissions and an
+32-bit offset, or CHERI capabilities that contain bounds, permissions and an
 out-of-band validity bit. In general, these pointers cannot be re-created
 from just an integer value.
 
@@ -716,23 +716,25 @@ In most cases pointers with a non-integral representation 
behave exactly the
 same as an integral pointer, the only difference is that it is not possible to
 create a pointer just from an address.
 
-"Non-integral" pointers also impose restrictions on the optimizer, but in
-general these are less restrictive than for "unstable" pointers. The main
+"Non-integral" pointers also impose restrictions on transformation passes, but
+in general these are less restrictive than for "unstable" pointers. The main
 difference compared to integral pointers is that ``inttoptr`` instructions
 should not be inserted by passes as they may not be able to create a valid
 pointer. This property also means that ``inttoptr(ptrtoint(x))`` cannot be
 folded to ``x`` as the ``

[llvm-branch-commits] [llvm] [DataLayout][LangRef] Split non-integral and unstable pointer properties (PR #105735)

2024-10-29 Thread Alexander Richardson via llvm-branch-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/105735

>From e4bd1181d160b8728e7d4158417a83e183bd1709 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Thu, 22 Aug 2024 14:36:04 -0700
Subject: [PATCH 1/3] fix indentation in langref

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 200224c78be004..1a59fba65815cc 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3103,19 +3103,19 @@ as follows:
 ``A``
 Specifies the address space of objects created by '``alloca``'.
 Defaults to the default address space of 0.
-``p[][n]::[:][:]``
+``p[][]::[:][:]``
 This specifies the *size* of a pointer and its  and
 \erred alignments for address space ``n``.  is optional
 and defaults to . The fourth parameter  is the size of 
the
 index that used for address calculation, which must be less than or equal
 to the pointer size. If not
 specified, the default index size is equal to the pointer size. All sizes
-are in bits. The address space, ``n``, is optional, and if not specified,
-denotes the default address space 0. The value of ``n`` must be
-in the range [1,2^24).
+are in bits. The , is optional, and if not specified,
+denotes the default address space 0. The value of  must
+be in the range [1,2^24).
 The optional are used to specify properties of pointers in this
-address space: the character ``u`` marks pointers as having an unstable
-representation and ```n`` marks pointers as non-integral (i.e. having
+address space: the character ``u`` marks pointers as having an unstable
+representation and ``n`` marks pointers as non-integral (i.e. having
 additional metadata). See :ref:`Non-Integral Pointer Types `.
 
 ``i:[:]``

>From db97145d3a653f2999b5935f9b1cb4550230689d Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Fri, 25 Oct 2024 12:51:11 -0700
Subject: [PATCH 2/3] include feedback

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst | 30 +-
 llvm/include/llvm/IR/DataLayout.h |  8 
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index c137318af678b6..3c3d0e0b4ab8ee 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -659,7 +659,7 @@ LLVM IR optionally allows the frontend to denote pointers 
in certain address
 spaces as "non-integral" or "unstable" (or both "non-integral" and "unstable")
 via the :ref:`datalayout string`.
 
-These exact implications of these properties are target-specific, but the
+The exact implications of these properties are target-specific, but the
 following IR semantics and restrictions to optimization passes apply:
 
 Unstable pointer representation
@@ -668,7 +668,7 @@ Unstable pointer representation
 Pointers in this address space have an *unspecified* bitwise representation
 (i.e. not backed by a fixed integer). The bitwise pattern of such pointers is
 allowed to change in a target-specific way. For example, this could be a 
pointer
-type used for with copying garbage collection where the garbage collector could
+type used with copying garbage collection where the garbage collector could
 update the pointer at any time in the collection sweep.
 
 ``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for
@@ -705,10 +705,10 @@ representation of the pointer.
 Non-integral pointer representation
 ^^^
 
-Pointers are not represented as an address, but may instead include
+Pointers are not represented as just an address, but may instead include
 additional metadata such as bounds information or a temporal identifier.
 Examples include AMDGPU buffer descriptors with a 128-bit fat pointer and a
-32-bit offset or CHERI capabilities that contain bounds, permissions and an
+32-bit offset, or CHERI capabilities that contain bounds, permissions and an
 out-of-band validity bit. In general, these pointers cannot be re-created
 from just an integer value.
 
@@ -716,23 +716,25 @@ In most cases pointers with a non-integral representation 
behave exactly the
 same as an integral pointer, the only difference is that it is not possible to
 create a pointer just from an address.
 
-"Non-integral" pointers also impose restrictions on the optimizer, but in
-general these are less restrictive than for "unstable" pointers. The main
+"Non-integral" pointers also impose restrictions on transformation passes, but
+in general these are less restrictive than for "unstable" pointers. The main
 difference compared to integral pointers is that ``inttoptr`` instructions
 should not be inserted by passes as they may not be able to create a valid
 pointer. This property also means that ``inttoptr(ptrtoint(x))`` cannot be
 folded to ``x`` as the ``

[llvm-branch-commits] [llvm] [DataLayout][LangRef] Split non-integral and unstable pointer properties (PR #105735)

2024-10-29 Thread Alexander Richardson via llvm-branch-commits

arichardson wrote:

I've added a new test and hopefully addressed all comments.

https://github.com/llvm/llvm-project/pull/105735
___
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] AMDGPU: Improve vector of pointer handling in amdgpu-promote-alloca (PR #114144)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/114144

None

>From 5fb1bed79e2a51343d9d0dbd5b295a1eefb04756 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Tue, 29 Oct 2024 14:44:53 -0700
Subject: [PATCH] AMDGPU: Improve vector of pointer handling in
 amdgpu-promote-alloca

---
 .../lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp |  73 +++---
 .../promote-alloca-invalid-vector-gep.ll  |  44 
 .../AMDGPU/promote-alloca-vector-gep.ll   | 243 ++
 3 files changed, 277 insertions(+), 83 deletions(-)
 delete mode 100644 
llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/promote-alloca-vector-gep.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 7dd7388376f474..9834b0f7f4b2f5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -1115,9 +1115,10 @@ bool 
AMDGPUPromoteAllocaImpl::binaryOpIsDerivedFromSameAlloca(
   if (Val == OtherOp)
 OtherOp = Inst->getOperand(OpIdx1);
 
-  if (isa(OtherOp))
+  if (isa(OtherOp) || isa(OtherOp))
 return true;
 
+  // TODO: getUnderlyingObject will not work on a vector getelementptr
   Value *OtherObj = getUnderlyingObject(OtherOp);
   if (!isa(OtherObj))
 return false;
@@ -1195,36 +1196,19 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
   continue;
 }
 
-// TODO: If we know the address is only observed through flat pointers, we
-// could still promote.
-if (UseInst->getOpcode() == Instruction::AddrSpaceCast)
-  return false;
-
-// Do not promote vector/aggregate type instructions. It is hard to track
-// their users.
-if (isa(User) || isa(User))
-  return false;
-
-// TODO: Handle vectors of pointers.
-if (!User->getType()->isPointerTy())
-  return false;
-
 if (GetElementPtrInst *GEP = dyn_cast(UseInst)) {
   // Be conservative if an address could be computed outside the bounds of
   // the alloca.
   if (!GEP->isInBounds())
 return false;
-}
-
-// Only promote a select if we know that the other select operand is from
-// another pointer that will also be promoted.
-if (SelectInst *SI = dyn_cast(UseInst)) {
+} else if (SelectInst *SI = dyn_cast(UseInst)) {
+  // Only promote a select if we know that the other select operand is from
+  // another pointer that will also be promoted.
   if (!binaryOpIsDerivedFromSameAlloca(BaseAlloca, Val, SI, 1, 2))
 return false;
-}
+} else if (PHINode *Phi = dyn_cast(UseInst)) {
+  // Repeat for phis.
 
-// Repeat for phis.
-if (PHINode *Phi = dyn_cast(UseInst)) {
   // TODO: Handle more complex cases. We should be able to replace loops
   // over arrays.
   switch (Phi->getNumIncomingValues()) {
@@ -1237,6 +1221,15 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
   default:
 return false;
   }
+} else if (!isa(User)) {
+  // Do not promote vector/aggregate type instructions. It is hard to track
+  // their users.
+
+  // Do not promote addrspacecast.
+  //
+  // TODO: If we know the address is only observed through flat pointers, 
we
+  // could still promote.
+  return false;
 }
 
 WorkList.push_back(User);
@@ -1490,17 +1483,21 @@ bool 
AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
 
   SmallVector DeferredIntrs;
 
+  PointerType *NewPtrTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
+
   for (Value *V : WorkList) {
 CallInst *Call = dyn_cast(V);
 if (!Call) {
   if (ICmpInst *CI = dyn_cast(V)) {
-PointerType *NewTy = PointerType::get(Context, 
AMDGPUAS::LOCAL_ADDRESS);
+Value *LHS = CI->getOperand(0);
+Value *RHS = CI->getOperand(1);
 
-if (isa(CI->getOperand(0)))
-  CI->setOperand(0, ConstantPointerNull::get(NewTy));
+Type *NewTy = LHS->getType()->getWithNewType(NewPtrTy);
+if (isa(LHS))
+  CI->setOperand(0, Constant::getNullValue(NewTy));
 
-if (isa(CI->getOperand(1)))
-  CI->setOperand(1, ConstantPointerNull::get(NewTy));
+if (isa(RHS))
+  CI->setOperand(1, Constant::getNullValue(NewTy));
 
 continue;
   }
@@ -1510,25 +1507,23 @@ bool 
AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
   if (isa(V))
 continue;
 
-  PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
-
-  assert(isa(V->getType()));
+  assert(V->getType()->isPtrOrPtrVectorTy());
 
-  // FIXME: It doesn't really make sense to try to do this for all
-  // instructions.
+  Type *NewTy = V->getType()->getWithNewType(NewPtrTy);
   V->mutateType(NewTy);
 
   // Adjust the types of any constant operands.
   if (SelectInst *SI = dyn_cast(V)) {
-if (isa(SI->getOperand(1)))
- 

[llvm-branch-commits] [llvm] AMDGPU: Improve vector of pointer handling in amdgpu-promote-alloca (PR #114144)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/114144?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#114144** https://app.graphite.dev/github/pr/llvm/llvm-project/114144?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈
* **#114113** https://app.graphite.dev/github/pr/llvm/llvm-project/114113?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#114091** https://app.graphite.dev/github/pr/llvm/llvm-project/114091?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`

This stack of pull requests is managed by Graphite. https://stacking.dev/?utm_source=stack-comment";>Learn more about 
stacking.


 Join @arsenm and the rest of your teammates on https://graphite.dev?utm-source=stack-comment";>https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="11px" height="11px"/> Graphite
  

https://github.com/llvm/llvm-project/pull/114144
___
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] AMDGPU: Improve vector of pointer handling in amdgpu-promote-alloca (PR #114144)

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

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)


Changes



---

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


3 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp (+34-39) 
- (removed) llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll (-44) 
- (added) llvm/test/CodeGen/AMDGPU/promote-alloca-vector-gep.ll (+243) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 7dd7388376f474..9834b0f7f4b2f5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -1115,9 +1115,10 @@ bool 
AMDGPUPromoteAllocaImpl::binaryOpIsDerivedFromSameAlloca(
   if (Val == OtherOp)
 OtherOp = Inst->getOperand(OpIdx1);
 
-  if (isa(OtherOp))
+  if (isa(OtherOp) || isa(OtherOp))
 return true;
 
+  // TODO: getUnderlyingObject will not work on a vector getelementptr
   Value *OtherObj = getUnderlyingObject(OtherOp);
   if (!isa(OtherObj))
 return false;
@@ -1195,36 +1196,19 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
   continue;
 }
 
-// TODO: If we know the address is only observed through flat pointers, we
-// could still promote.
-if (UseInst->getOpcode() == Instruction::AddrSpaceCast)
-  return false;
-
-// Do not promote vector/aggregate type instructions. It is hard to track
-// their users.
-if (isa(User) || isa(User))
-  return false;
-
-// TODO: Handle vectors of pointers.
-if (!User->getType()->isPointerTy())
-  return false;
-
 if (GetElementPtrInst *GEP = dyn_cast(UseInst)) {
   // Be conservative if an address could be computed outside the bounds of
   // the alloca.
   if (!GEP->isInBounds())
 return false;
-}
-
-// Only promote a select if we know that the other select operand is from
-// another pointer that will also be promoted.
-if (SelectInst *SI = dyn_cast(UseInst)) {
+} else if (SelectInst *SI = dyn_cast(UseInst)) {
+  // Only promote a select if we know that the other select operand is from
+  // another pointer that will also be promoted.
   if (!binaryOpIsDerivedFromSameAlloca(BaseAlloca, Val, SI, 1, 2))
 return false;
-}
+} else if (PHINode *Phi = dyn_cast(UseInst)) {
+  // Repeat for phis.
 
-// Repeat for phis.
-if (PHINode *Phi = dyn_cast(UseInst)) {
   // TODO: Handle more complex cases. We should be able to replace loops
   // over arrays.
   switch (Phi->getNumIncomingValues()) {
@@ -1237,6 +1221,15 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
   default:
 return false;
   }
+} else if (!isa(User)) {
+  // Do not promote vector/aggregate type instructions. It is hard to track
+  // their users.
+
+  // Do not promote addrspacecast.
+  //
+  // TODO: If we know the address is only observed through flat pointers, 
we
+  // could still promote.
+  return false;
 }
 
 WorkList.push_back(User);
@@ -1490,17 +1483,21 @@ bool 
AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
 
   SmallVector DeferredIntrs;
 
+  PointerType *NewPtrTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
+
   for (Value *V : WorkList) {
 CallInst *Call = dyn_cast(V);
 if (!Call) {
   if (ICmpInst *CI = dyn_cast(V)) {
-PointerType *NewTy = PointerType::get(Context, 
AMDGPUAS::LOCAL_ADDRESS);
+Value *LHS = CI->getOperand(0);
+Value *RHS = CI->getOperand(1);
 
-if (isa(CI->getOperand(0)))
-  CI->setOperand(0, ConstantPointerNull::get(NewTy));
+Type *NewTy = LHS->getType()->getWithNewType(NewPtrTy);
+if (isa(LHS))
+  CI->setOperand(0, Constant::getNullValue(NewTy));
 
-if (isa(CI->getOperand(1)))
-  CI->setOperand(1, ConstantPointerNull::get(NewTy));
+if (isa(RHS))
+  CI->setOperand(1, Constant::getNullValue(NewTy));
 
 continue;
   }
@@ -1510,25 +1507,23 @@ bool 
AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
   if (isa(V))
 continue;
 
-  PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
-
-  assert(isa(V->getType()));
+  assert(V->getType()->isPtrOrPtrVectorTy());
 
-  // FIXME: It doesn't really make sense to try to do this for all
-  // instructions.
+  Type *NewTy = V->getType()->getWithNewType(NewPtrTy);
   V->mutateType(NewTy);
 
   // Adjust the types of any constant operands.
   if (SelectInst *SI = dyn_cast(V)) {
-if (isa(SI->getOperand(1)))
-  SI->setOperand(1, ConstantPointerNull::get(NewTy));
+if (isa(SI->getOperand(1)))
+  SI->setOperand(1, Constant::getNullValue(NewTy));
 
-if (isa(SI->getOperand(2)))
-  SI->setOperand(2, Consta

[llvm-branch-commits] [mlir] [mlir][bufferization] Add support for non-unique `func.return` (PR #114017)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

>From 35223119257ac8afd71803871fcaa08fb19da4a5 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Tue, 29 Oct 2024 09:51:11 +0100
Subject: [PATCH] [mlir][bufferization] Add support for non-unique
 `func.return`

---
 .../FuncBufferizableOpInterfaceImpl.cpp   |  75 +++-
 .../Transforms/OneShotModuleBufferize.cpp | 179 +-
 .../one-shot-module-bufferize-analysis.mlir   |  45 +
 .../one-shot-module-bufferize-invalid.mlir|  22 +--
 .../Transforms/one-shot-module-bufferize.mlir |  24 +++
 5 files changed, 235 insertions(+), 110 deletions(-)

diff --git 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
index 6e91d3b89a7c79..195b17fcf902a2 100644
--- 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
+++ 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
@@ -41,18 +41,13 @@ void FuncAnalysisState::startFunctionAnalysis(FuncOp 
funcOp) {
 #endif // NDEBUG
 }
 
-/// Return the unique ReturnOp that terminates `funcOp`.
-/// Return nullptr if there is no such unique ReturnOp.
-static func::ReturnOp getAssumedUniqueReturnOp(FuncOp funcOp) {
-  func::ReturnOp returnOp;
-  for (Block &b : funcOp.getBody()) {
-if (auto candidateOp = dyn_cast(b.getTerminator())) {
-  if (returnOp)
-return nullptr;
-  returnOp = candidateOp;
-}
-  }
-  return returnOp;
+/// Return all top-level func.return ops in the given function.
+static SmallVector getReturnOps(FuncOp funcOp) {
+  SmallVector result;
+  for (Block &b : funcOp.getBody())
+if (auto returnOp = dyn_cast(b.getTerminator()))
+  result.push_back(returnOp);
+  return result;
 }
 
 /// Return the index-th bufferized function argument type. This assumes that 
the
@@ -372,15 +367,6 @@ struct FuncOpInterface
 getBufferType(op, value, options, invocationStack);
   }
 
-  LogicalResult verifyAnalysis(Operation *op,
-   const AnalysisState &state) const {
-auto funcOp = cast(op);
-// TODO: func.func with multiple returns are not supported.
-if (!getAssumedUniqueReturnOp(funcOp) && !funcOp.isExternal())
-  return op->emitOpError("op without unique func.return is not supported");
-return success();
-  }
-
   /// Rewrite function bbArgs and return values into buffer form. This function
   /// bufferizes the function signature and the ReturnOp. When the entire
   /// function body has been bufferized, function return types can be switched
@@ -427,41 +413,38 @@ struct FuncOpInterface
   return success();
 }
 
-// TODO: Support functions with multiple returns.
-func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOp);
-assert(returnOp && "expected func with single return op");
-assert(returnOp->getNumOperands() == retTypes.size() &&
-   "incorrect number of return values");
-Location loc = returnOp.getLoc();
-
 // 1. Bufferize every block.
 for (Block &block : funcOp.getBody())
   if (failed(bufferization::bufferizeBlockSignature(&block, rewriter,
 options)))
 return failure();
 
-// 2. Bufferize all operands of the return op.
-SmallVector returnValues;
-for (auto [returnVal, bufferizedType] :
- llvm::zip_equal(returnOp->getOperands(), retTypes)) {
-  auto tensorType = dyn_cast(returnVal.getType());
-  rewriter.setInsertionPoint(returnOp);
-
-  // If not a tensor type just forward it.
-  if (!tensorType) {
-returnValues.push_back(returnVal);
-continue;
+// 2. Bufferize the operands of the all return op.
+for (func::ReturnOp returnOp : getReturnOps(funcOp)) {
+  assert(returnOp->getNumOperands() == retTypes.size() &&
+ "incorrect number of return values");
+  SmallVector returnValues;
+  for (auto [returnVal, bufferizedType] :
+   llvm::zip_equal(returnOp->getOperands(), retTypes)) {
+auto tensorType = dyn_cast(returnVal.getType());
+rewriter.setInsertionPoint(returnOp);
+
+// If not a tensor type just forward it.
+if (!tensorType) {
+  returnValues.push_back(returnVal);
+  continue;
+}
+
+// Note: If `inferFunctionResultLayout = true`, casts are later folded
+// away.
+Value toMemrefOp = rewriter.create(
+returnOp.getLoc(), bufferizedType, returnVal);
+returnValues.push_back(toMemrefOp);
   }
 
-  // Note: If `inferFunctionResultLayout = true`, casts are later folded
-  // away.
-  Value toMemrefOp = rewriter.create(
-  loc, bufferizedType, returnVal);
-  returnValues.push_back(toMemrefOp);
+  returnOp.getOperandsMutable().assign(returnValues);
 }
 
-returnOp.g

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove remaining dialect conversion-based infra parts (PR #114155)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

>From d1d51e36de6a31bd6d7cef395a3da1bde692cbde Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Wed, 30 Oct 2024 00:58:32 +0100
Subject: [PATCH] [mlir][bufferization] Remove remaining dialect
 conversion-based infra parts

This commit removes the last remaining components of the dialect 
conversion-based bufferization passes.

Note for LLVM integration: If you depend on these components, migrate to 
One-Shot Bufferize or copy them to your codebase.

Depends on #114154.
---
 .../Bufferization/Transforms/Bufferize.h  | 23 --
 .../mlir/Dialect/Func/Transforms/Passes.h |  4 -
 .../Bufferization/Transforms/BufferUtils.cpp  |  6 +-
 .../Bufferization/Transforms/Bufferize.cpp| 73 ---
 4 files changed, 4 insertions(+), 102 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
index ebed2c354bfca5..2f495d304b4a56 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
@@ -38,24 +38,6 @@ struct BufferizationStatistics {
   int64_t numTensorOutOfPlace = 0;
 };
 
-/// A helper type converter class that automatically populates the relevant
-/// materializations and type conversions for bufferization.
-class BufferizeTypeConverter : public TypeConverter {
-public:
-  BufferizeTypeConverter();
-};
-
-/// Marks ops used by bufferization for type conversion materializations as
-/// "legal" in the given ConversionTarget.
-///
-/// This function should be called by all bufferization passes using
-/// BufferizeTypeConverter so that materializations work properly. One 
exception
-/// is bufferization passes doing "full" conversions, where it can be desirable
-/// for even the materializations to remain illegal so that they are 
eliminated,
-/// such as via the patterns in
-/// populateEliminateBufferizeMaterializationsPatterns.
-void populateBufferizeMaterializationLegality(ConversionTarget &target);
-
 /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
 ///
 /// Note: This function does not resolve read-after-write conflicts. Use this
@@ -81,11 +63,6 @@ LogicalResult bufferizeOp(Operation *op, const 
BufferizationOptions &options,
 LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
   const BufferizationOptions &options);
 
-/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
-/// old (deprecated) partial, dialect conversion-based bufferization passes. A
-/// copy will be inserted before every buffer write.
-BufferizationOptions getPartialBufferizationOptions();
-
 } // namespace bufferization
 } // namespace mlir
 
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
index 02fc9e1d934390..0248f068320c54 100644
--- a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
@@ -18,10 +18,6 @@
 #include "mlir/Pass/Pass.h"
 
 namespace mlir {
-namespace bufferization {
-class BufferizeTypeConverter;
-} // namespace bufferization
-
 class RewritePatternSet;
 
 namespace func {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index 8fffdbf664c3f4..b11803da19ef98 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -11,6 +11,8 @@
 
//===--===//
 
 #include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
@@ -138,8 +140,8 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, 
uint64_t alignment,
   alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
 : IntegerAttr();
 
-  BufferizeTypeConverter typeConverter;
-  auto memrefType = cast(typeConverter.convertType(type));
+  auto memrefType =
+  cast(getMemRefTypeWithStaticIdentityLayout(type));
   if (memorySpace)
 memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
   auto global = globalBuilder.create(
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 62ce2583f4fa1d..6f0cdfa20f7be5 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -37,65 +37,6 @@ namespace bufferization {
 using namespace mlir;
 using namespace mlir::bufferization

[llvm-branch-commits] [mlir] [mlir][bufferization] Add support for non-unique `func.return` (PR #114017)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

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

>From 13808b4f86dba3f3baa652b41e769d2a19973028 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Tue, 29 Oct 2024 09:51:11 +0100
Subject: [PATCH] [mlir][bufferization] Add support for non-unique
 `func.return`

---
 .../FuncBufferizableOpInterfaceImpl.cpp   |  75 +++-
 .../Transforms/OneShotModuleBufferize.cpp | 179 +-
 .../one-shot-module-bufferize-invalid.mlir|  22 +--
 .../Transforms/one-shot-module-bufferize.mlir |  24 +++
 4 files changed, 190 insertions(+), 110 deletions(-)

diff --git 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
index 6e91d3b89a7c79..195b17fcf902a2 100644
--- 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
+++ 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
@@ -41,18 +41,13 @@ void FuncAnalysisState::startFunctionAnalysis(FuncOp 
funcOp) {
 #endif // NDEBUG
 }
 
-/// Return the unique ReturnOp that terminates `funcOp`.
-/// Return nullptr if there is no such unique ReturnOp.
-static func::ReturnOp getAssumedUniqueReturnOp(FuncOp funcOp) {
-  func::ReturnOp returnOp;
-  for (Block &b : funcOp.getBody()) {
-if (auto candidateOp = dyn_cast(b.getTerminator())) {
-  if (returnOp)
-return nullptr;
-  returnOp = candidateOp;
-}
-  }
-  return returnOp;
+/// Return all top-level func.return ops in the given function.
+static SmallVector getReturnOps(FuncOp funcOp) {
+  SmallVector result;
+  for (Block &b : funcOp.getBody())
+if (auto returnOp = dyn_cast(b.getTerminator()))
+  result.push_back(returnOp);
+  return result;
 }
 
 /// Return the index-th bufferized function argument type. This assumes that 
the
@@ -372,15 +367,6 @@ struct FuncOpInterface
 getBufferType(op, value, options, invocationStack);
   }
 
-  LogicalResult verifyAnalysis(Operation *op,
-   const AnalysisState &state) const {
-auto funcOp = cast(op);
-// TODO: func.func with multiple returns are not supported.
-if (!getAssumedUniqueReturnOp(funcOp) && !funcOp.isExternal())
-  return op->emitOpError("op without unique func.return is not supported");
-return success();
-  }
-
   /// Rewrite function bbArgs and return values into buffer form. This function
   /// bufferizes the function signature and the ReturnOp. When the entire
   /// function body has been bufferized, function return types can be switched
@@ -427,41 +413,38 @@ struct FuncOpInterface
   return success();
 }
 
-// TODO: Support functions with multiple returns.
-func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOp);
-assert(returnOp && "expected func with single return op");
-assert(returnOp->getNumOperands() == retTypes.size() &&
-   "incorrect number of return values");
-Location loc = returnOp.getLoc();
-
 // 1. Bufferize every block.
 for (Block &block : funcOp.getBody())
   if (failed(bufferization::bufferizeBlockSignature(&block, rewriter,
 options)))
 return failure();
 
-// 2. Bufferize all operands of the return op.
-SmallVector returnValues;
-for (auto [returnVal, bufferizedType] :
- llvm::zip_equal(returnOp->getOperands(), retTypes)) {
-  auto tensorType = dyn_cast(returnVal.getType());
-  rewriter.setInsertionPoint(returnOp);
-
-  // If not a tensor type just forward it.
-  if (!tensorType) {
-returnValues.push_back(returnVal);
-continue;
+// 2. Bufferize the operands of the all return op.
+for (func::ReturnOp returnOp : getReturnOps(funcOp)) {
+  assert(returnOp->getNumOperands() == retTypes.size() &&
+ "incorrect number of return values");
+  SmallVector returnValues;
+  for (auto [returnVal, bufferizedType] :
+   llvm::zip_equal(returnOp->getOperands(), retTypes)) {
+auto tensorType = dyn_cast(returnVal.getType());
+rewriter.setInsertionPoint(returnOp);
+
+// If not a tensor type just forward it.
+if (!tensorType) {
+  returnValues.push_back(returnVal);
+  continue;
+}
+
+// Note: If `inferFunctionResultLayout = true`, casts are later folded
+// away.
+Value toMemrefOp = rewriter.create(
+returnOp.getLoc(), bufferizedType, returnVal);
+returnValues.push_back(toMemrefOp);
   }
 
-  // Note: If `inferFunctionResultLayout = true`, casts are later folded
-  // away.
-  Value toMemrefOp = rewriter.create(
-  loc, bufferizedType, returnVal);
-  returnValues.push_back(toMemrefOp);
+  returnOp.getOperandsMutable().assign(returnValues);
 }
 
-returnOp.getOperandsMutable().assign(returnValues);
-
 // 3. Set 

[llvm-branch-commits] [mlir] [mlir][bufferization] Remove remaining dialect conversion-based infra parts (PR #114155)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-bufferization

Author: Matthias Springer (matthias-springer)


Changes

This commit removes the last remaining components of the dialect 
conversion-based bufferization passes.

Note for LLVM integration: If you depend on these components, migrate to 
One-Shot Bufferize or copy them to your codebase.

Depends on #114154.

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
(-23) 
- (modified) mlir/include/mlir/Dialect/Func/Transforms/Passes.h (-4) 
- (modified) mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp (+3-2) 
- (modified) mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp (-73) 


``diff
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
index ebed2c354bfca5..2f495d304b4a56 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Bufferize.h
@@ -38,24 +38,6 @@ struct BufferizationStatistics {
   int64_t numTensorOutOfPlace = 0;
 };
 
-/// A helper type converter class that automatically populates the relevant
-/// materializations and type conversions for bufferization.
-class BufferizeTypeConverter : public TypeConverter {
-public:
-  BufferizeTypeConverter();
-};
-
-/// Marks ops used by bufferization for type conversion materializations as
-/// "legal" in the given ConversionTarget.
-///
-/// This function should be called by all bufferization passes using
-/// BufferizeTypeConverter so that materializations work properly. One 
exception
-/// is bufferization passes doing "full" conversions, where it can be desirable
-/// for even the materializations to remain illegal so that they are 
eliminated,
-/// such as via the patterns in
-/// populateEliminateBufferizeMaterializationsPatterns.
-void populateBufferizeMaterializationLegality(ConversionTarget &target);
-
 /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`.
 ///
 /// Note: This function does not resolve read-after-write conflicts. Use this
@@ -81,11 +63,6 @@ LogicalResult bufferizeOp(Operation *op, const 
BufferizationOptions &options,
 LogicalResult bufferizeBlockSignature(Block *block, RewriterBase &rewriter,
   const BufferizationOptions &options);
 
-/// Return `BufferizationOptions` such that the `bufferizeOp` behaves like the
-/// old (deprecated) partial, dialect conversion-based bufferization passes. A
-/// copy will be inserted before every buffer write.
-BufferizationOptions getPartialBufferizationOptions();
-
 } // namespace bufferization
 } // namespace mlir
 
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
index 02fc9e1d934390..0248f068320c54 100644
--- a/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Func/Transforms/Passes.h
@@ -18,10 +18,6 @@
 #include "mlir/Pass/Pass.h"
 
 namespace mlir {
-namespace bufferization {
-class BufferizeTypeConverter;
-} // namespace bufferization
-
 class RewritePatternSet;
 
 namespace func {
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index 8fffdbf664c3f4..da77a735cd59d7 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -11,6 +11,8 @@
 
//===--===//
 
 #include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
@@ -138,8 +140,7 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, 
uint64_t alignment,
   alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
 : IntegerAttr();
 
-  BufferizeTypeConverter typeConverter;
-  auto memrefType = cast(typeConverter.convertType(type));
+  auto memrefType = 
cast(getMemRefTypeWithStaticIdentityLayout(type));
   if (memorySpace)
 memrefType = MemRefType::Builder(memrefType).setMemorySpace(memorySpace);
   auto global = globalBuilder.create(
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 62ce2583f4fa1d..6f0cdfa20f7be5 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -37,65 +37,6 @@ namespace bufferization {
 using namespace mlir;
 using namespace mlir::bufferization;
 
-//===--===//
-// Buffe

[llvm-branch-commits] [mlir] [mlir][bufferization] Add support for non-unique `func.return` (PR #114017)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-bufferization

Author: Matthias Springer (matthias-springer)


Changes

Multiple `func.return` ops inside of a `func.func` op are now supported during 
bufferization. This PR extends the code base in 3 places:

- When inferring function return types, `memref.cast` ops are folded away only 
if all `func.return` ops have matching buffer types. (E.g., we don't fold if 
two `return` ops have operands with different layout maps.)
- The alias sets of all `func.return` ops are merged. That's because aliasing 
is a "may be" property.
- The equivalence sets of all `func.return` ops are taken only if they match. 
If different `func.return` ops have different equivalence sets for their 
operands, the equivalence information is dropped. That's because equivalence is 
a "must be" property.

Depends on #113999.


---

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


5 Files Affected:

- (modified) 
mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
(+29-46) 
- (modified) 
mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp (+135-44) 
- (modified) 
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
 (+45) 
- (modified) 
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir
 (+2-20) 
- (modified) 
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir (+24) 


``diff
diff --git 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
index 6e91d3b89a7c79..195b17fcf902a2 100644
--- 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
+++ 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
@@ -41,18 +41,13 @@ void FuncAnalysisState::startFunctionAnalysis(FuncOp 
funcOp) {
 #endif // NDEBUG
 }
 
-/// Return the unique ReturnOp that terminates `funcOp`.
-/// Return nullptr if there is no such unique ReturnOp.
-static func::ReturnOp getAssumedUniqueReturnOp(FuncOp funcOp) {
-  func::ReturnOp returnOp;
-  for (Block &b : funcOp.getBody()) {
-if (auto candidateOp = dyn_cast(b.getTerminator())) {
-  if (returnOp)
-return nullptr;
-  returnOp = candidateOp;
-}
-  }
-  return returnOp;
+/// Return all top-level func.return ops in the given function.
+static SmallVector getReturnOps(FuncOp funcOp) {
+  SmallVector result;
+  for (Block &b : funcOp.getBody())
+if (auto returnOp = dyn_cast(b.getTerminator()))
+  result.push_back(returnOp);
+  return result;
 }
 
 /// Return the index-th bufferized function argument type. This assumes that 
the
@@ -372,15 +367,6 @@ struct FuncOpInterface
 getBufferType(op, value, options, invocationStack);
   }
 
-  LogicalResult verifyAnalysis(Operation *op,
-   const AnalysisState &state) const {
-auto funcOp = cast(op);
-// TODO: func.func with multiple returns are not supported.
-if (!getAssumedUniqueReturnOp(funcOp) && !funcOp.isExternal())
-  return op->emitOpError("op without unique func.return is not supported");
-return success();
-  }
-
   /// Rewrite function bbArgs and return values into buffer form. This function
   /// bufferizes the function signature and the ReturnOp. When the entire
   /// function body has been bufferized, function return types can be switched
@@ -427,41 +413,38 @@ struct FuncOpInterface
   return success();
 }
 
-// TODO: Support functions with multiple returns.
-func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOp);
-assert(returnOp && "expected func with single return op");
-assert(returnOp->getNumOperands() == retTypes.size() &&
-   "incorrect number of return values");
-Location loc = returnOp.getLoc();
-
 // 1. Bufferize every block.
 for (Block &block : funcOp.getBody())
   if (failed(bufferization::bufferizeBlockSignature(&block, rewriter,
 options)))
 return failure();
 
-// 2. Bufferize all operands of the return op.
-SmallVector returnValues;
-for (auto [returnVal, bufferizedType] :
- llvm::zip_equal(returnOp->getOperands(), retTypes)) {
-  auto tensorType = dyn_cast(returnVal.getType());
-  rewriter.setInsertionPoint(returnOp);
-
-  // If not a tensor type just forward it.
-  if (!tensorType) {
-returnValues.push_back(returnVal);
-continue;
+// 2. Bufferize the operands of the all return op.
+for (func::ReturnOp returnOp : getReturnOps(funcOp)) {
+  assert(returnOp->getNumOperands() == retTypes.size() &&
+ "incorrect number of return values");
+  SmallVector returnValues;
+  for (auto [returnVal, bufferizedType] :
+   llvm::zip_equal(returnOp->getOperands(), re

[llvm-branch-commits] [mlir] [mlir][bufferization] Add support for non-unique `func.return` (PR #114017)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/114017
___
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][bufferization] Add support for non-unique `func.return` (PR #114017)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Matthias Springer (matthias-springer)


Changes

Multiple `func.return` ops inside of a `func.func` op are now supported during 
bufferization. This PR extends the code base in 3 places:

- When inferring function return types, `memref.cast` ops are folded away only 
if all `func.return` ops have matching buffer types. (E.g., we don't fold if 
two `return` ops have operands with different layout maps.)
- The alias sets of all `func.return` ops are merged. That's because aliasing 
is a "may be" property.
- The equivalence sets of all `func.return` ops are taken only if they match. 
If different `func.return` ops have different equivalence sets for their 
operands, the equivalence information is dropped. That's because equivalence is 
a "must be" property.

Depends on #113999.


---

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


5 Files Affected:

- (modified) 
mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
(+29-46) 
- (modified) 
mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp (+135-44) 
- (modified) 
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
 (+45) 
- (modified) 
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir
 (+2-20) 
- (modified) 
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir (+24) 


``diff
diff --git 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
index 6e91d3b89a7c79..195b17fcf902a2 100644
--- 
a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
+++ 
b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
@@ -41,18 +41,13 @@ void FuncAnalysisState::startFunctionAnalysis(FuncOp 
funcOp) {
 #endif // NDEBUG
 }
 
-/// Return the unique ReturnOp that terminates `funcOp`.
-/// Return nullptr if there is no such unique ReturnOp.
-static func::ReturnOp getAssumedUniqueReturnOp(FuncOp funcOp) {
-  func::ReturnOp returnOp;
-  for (Block &b : funcOp.getBody()) {
-if (auto candidateOp = dyn_cast(b.getTerminator())) {
-  if (returnOp)
-return nullptr;
-  returnOp = candidateOp;
-}
-  }
-  return returnOp;
+/// Return all top-level func.return ops in the given function.
+static SmallVector getReturnOps(FuncOp funcOp) {
+  SmallVector result;
+  for (Block &b : funcOp.getBody())
+if (auto returnOp = dyn_cast(b.getTerminator()))
+  result.push_back(returnOp);
+  return result;
 }
 
 /// Return the index-th bufferized function argument type. This assumes that 
the
@@ -372,15 +367,6 @@ struct FuncOpInterface
 getBufferType(op, value, options, invocationStack);
   }
 
-  LogicalResult verifyAnalysis(Operation *op,
-   const AnalysisState &state) const {
-auto funcOp = cast(op);
-// TODO: func.func with multiple returns are not supported.
-if (!getAssumedUniqueReturnOp(funcOp) && !funcOp.isExternal())
-  return op->emitOpError("op without unique func.return is not supported");
-return success();
-  }
-
   /// Rewrite function bbArgs and return values into buffer form. This function
   /// bufferizes the function signature and the ReturnOp. When the entire
   /// function body has been bufferized, function return types can be switched
@@ -427,41 +413,38 @@ struct FuncOpInterface
   return success();
 }
 
-// TODO: Support functions with multiple returns.
-func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOp);
-assert(returnOp && "expected func with single return op");
-assert(returnOp->getNumOperands() == retTypes.size() &&
-   "incorrect number of return values");
-Location loc = returnOp.getLoc();
-
 // 1. Bufferize every block.
 for (Block &block : funcOp.getBody())
   if (failed(bufferization::bufferizeBlockSignature(&block, rewriter,
 options)))
 return failure();
 
-// 2. Bufferize all operands of the return op.
-SmallVector returnValues;
-for (auto [returnVal, bufferizedType] :
- llvm::zip_equal(returnOp->getOperands(), retTypes)) {
-  auto tensorType = dyn_cast(returnVal.getType());
-  rewriter.setInsertionPoint(returnOp);
-
-  // If not a tensor type just forward it.
-  if (!tensorType) {
-returnValues.push_back(returnVal);
-continue;
+// 2. Bufferize the operands of the all return op.
+for (func::ReturnOp returnOp : getReturnOps(funcOp)) {
+  assert(returnOp->getNumOperands() == retTypes.size() &&
+ "incorrect number of return values");
+  SmallVector returnValues;
+  for (auto [returnVal, bufferizedType] :
+   llvm::zip_equal(returnOp->getOperands(), retTypes)) {
+  

[llvm-branch-commits] [mlir] [mlir][bufferization] Add support for non-unique `func.return` (PR #114017)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/114017
___
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][bufferization] Add support for non-unique `func.return` (PR #114017)

2024-10-29 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer ready_for_review 
https://github.com/llvm/llvm-project/pull/114017
___
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][bufferization] Remove `finalizing-bufferize` pass (PR #114154)

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

llvmbot wrote:




@llvm/pr-subscribers-mlir-bufferization

Author: Matthias Springer (matthias-springer)


Changes

The dialect conversion-based bufferization passes have been migrated to 
One-Shot Bufferize about two years ago. To clean up the code base, this commit 
removes the `finalizing-bufferize` pass, one of the few remaining parts of the 
old infrastructure. Most bufferization passes have already been removed.

Note for LLVM integration: If you depend on this pass, migrate to One-Shot 
Bufferize or copy the pass to your codebase.

Depends on #114152.

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h (-4) 
- (modified) mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td (-16) 
- (modified) mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp (-75) 
- (modified) mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp 
(-2) 
- (removed) 
mlir/test/Dialect/Bufferization/Transforms/finalizing-bufferize.mlir (-95) 


``diff
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
index 72abb5b3f1f94e..8b957577292796 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
@@ -200,10 +200,6 @@ std::unique_ptr createEmptyTensorToAllocTensorPass();
 /// Drop all memref function results that are equivalent to a function 
argument.
 LogicalResult dropEquivalentBufferResults(ModuleOp module);
 
-/// Creates a pass that finalizes a partial bufferization by removing remaining
-/// bufferization.to_tensor and bufferization.to_memref operations.
-std::unique_ptr> createFinalizingBufferizePass();
-
 /// Create a pass that bufferizes all ops that implement 
BufferizableOpInterface
 /// with One-Shot Bufferize.
 std::unique_ptr createOneShotBufferizePass();
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td 
b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
index cc5463ea968fc3..3e1b55cf99767f 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
@@ -343,22 +343,6 @@ def BufferResultsToOutParams : 
Pass<"buffer-results-to-out-params", "ModuleOp">
   let dependentDialects = ["memref::MemRefDialect"];
 }
 
-def FinalizingBufferize : Pass<"finalizing-bufferize", "func::FuncOp"> {
-  let summary = "Finalize a partial bufferization";
-  let description = [{
-A bufferize pass that finalizes a partial bufferization by removing
-remaining `bufferization.to_tensor` and `bufferization.to_buffer` 
operations.
-
-The removal of those operations is only possible if the operations only
-exist in pairs, i.e., all uses of `bufferization.to_tensor` operations are
-`bufferization.to_buffer` operations.
-
-This pass will fail if not all operations can be removed or if any 
operation
-with tensor typed operands remains.
-  }];
-  let constructor = "mlir::bufferization::createFinalizingBufferizePass()";
-}
-
 def DropEquivalentBufferResults : Pass<"drop-equivalent-buffer-results", 
"ModuleOp">  {
   let summary = "Remove MemRef return values that are equivalent to a bbArg";
   let description = [{
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp 
b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 1d009b03754c52..62ce2583f4fa1d 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -26,7 +26,6 @@
 
 namespace mlir {
 namespace bufferization {
-#define GEN_PASS_DEF_FINALIZINGBUFFERIZE
 #define GEN_PASS_DEF_BUFFERIZATIONBUFFERIZE
 #define GEN_PASS_DEF_ONESHOTBUFFERIZE
 #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc"
@@ -98,75 +97,6 @@ void 
mlir::bufferization::populateBufferizeMaterializationLegality(
 }
 
 namespace {
-// In a finalizing bufferize conversion, we know that all tensors have been
-// converted to memrefs, thus, this op becomes an identity.
-class BufferizeToTensorOp
-: public OpConversionPattern {
-public:
-  using OpConversionPattern::OpConversionPattern;
-  LogicalResult
-  matchAndRewrite(bufferization::ToTensorOp op, OpAdaptor adaptor,
-  ConversionPatternRewriter &rewriter) const override {
-rewriter.replaceOp(op, adaptor.getMemref());
-return success();
-  }
-};
-} // namespace
-
-namespace {
-// In a finalizing bufferize conversion, we know that all tensors have been
-// converted to memrefs, thus, this op becomes an identity.
-class BufferizeToMemrefOp
-: public OpConversionPattern {
-public:
-  using OpConversionPattern::OpConversionPattern;
-  LogicalResult
-  matchAndRewrite(bufferization::ToMemrefOp op, OpAdaptor adaptor,
-  ConversionPatternRewriter &rewriter) const override {
-rewriter.r

[llvm-branch-commits] [llvm] AMDGPU: Improve vector of pointer handling in amdgpu-promote-alloca (PR #114144)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/114144
___
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] Emit descriptive errors for all unsupported clauses (PR #114037)

2024-10-29 Thread Michael Kruse via llvm-branch-commits


@@ -640,6 +642,13 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase 
&builder,
   return success();
 }
 
+static LogicalResult orderedRegionSupported(omp::OrderedRegionOp op) {

Meinersbur wrote:

[function names should start with a 
verb](https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly):
 `checkWhetherOrderedRegionSupported` or maybe `checkImplementationStatus`.

A Doxygen brief could explain the purpose of this function (not exactly what it 
is checking, I can see that in the code).

This applies to the helper functions below as well. I don't see the point of 
extracting out a single check, but seems useful if there are multiple checks 
and apply the same pattern here as well.

https://github.com/llvm/llvm-project/pull/114037
___
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] Emit descriptive errors for all unsupported clauses (PR #114037)

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

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

>From 5f9c42714f1f8168adcb55ef72bf10fd0f6db81a Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 29 Oct 2024 11:18:07 +
Subject: [PATCH 1/2] [MLIR][OpenMP] Emit descriptive errors for all
 unsupported clauses

This patch improves error reporting in the MLIR to LLVM IR translation pass for
the 'omp' dialect by emitting descriptive errors when encountering clauses not
yet supported by that pass.

Additionally, not-yet-implemented errors previously missing for some clauses
are added, to avoid silently ignoring them.

Error messages related to inlining of `omp.private` and `omp.declare_reduction`
regions have been updated to use the same format.
---
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  | 340 --
 mlir/test/Target/LLVMIR/openmp-todo.mlir  | 212 +--
 2 files changed, 421 insertions(+), 131 deletions(-)

diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 4d189b1f40c46b..582a68f4c00a47 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -581,7 +581,8 @@ makeReductionGen(omp::DeclareReductionOp decl, 
llvm::IRBuilderBase &builder,
 if (failed(inlineConvertOmpRegions(decl.getReductionRegion(),
"omp.reduction.nonatomic.body", builder,
moduleTranslation, &phis)))
-  return llvm::createStringError("failed reduction region translation");
+  return llvm::createStringError(
+  "failed to inline `combiner` region of `omp.declare_reduction`");
 assert(phis.size() == 1);
 result = phis[0];
 return builder.saveIP();
@@ -614,7 +615,8 @@ makeAtomicReductionGen(omp::DeclareReductionOp decl,
 if (failed(inlineConvertOmpRegions(decl.getAtomicReductionRegion(),
"omp.reduction.atomic.body", builder,
moduleTranslation, &phis)))
-  return llvm::createStringError("failed reduction region translation");
+  return llvm::createStringError(
+  "failed to inline `atomic` region of `omp.declare_reduction`");
 assert(phis.empty());
 return builder.saveIP();
   };
@@ -650,6 +652,13 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase 
&builder,
   return success();
 }
 
+static LogicalResult orderedRegionSupported(omp::OrderedRegionOp op) {
+  if (op.getParLevelSimd())
+return op.emitError("parallelization-level clause set not yet supported");
+
+  return success();
+}
+
 /// Converts an OpenMP 'ordered_region' operation into LLVM IR using
 /// OpenMPIRBuilder.
 static LogicalResult
@@ -658,9 +667,8 @@ convertOmpOrderedRegion(Operation &opInst, 
llvm::IRBuilderBase &builder,
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
   auto orderedRegionOp = cast(opInst);
 
-  // TODO: The code generation for ordered simd directive is not supported yet.
-  if (orderedRegionOp.getParLevelSimd())
-return opInst.emitError("unhandled clauses for translation to LLVM IR");
+  if (failed(orderedRegionSupported(orderedRegionOp)))
+return failure();
 
   auto bodyGenCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP) {
 // OrderedOp has only one region associated with it.
@@ -727,9 +735,10 @@ allocReductionVars(T loop, ArrayRef 
reductionArgs,
   SmallVector phis;
   if (failed(inlineConvertOmpRegions(allocRegion, "omp.reduction.alloc",
  builder, moduleTranslation, &phis)))
-return failure();
-  assert(phis.size() == 1 && "expected one allocation to be yielded");
+return loop.emitError(
+"failed to inline `alloc` region of `omp.declare_reduction`");
 
+  assert(phis.size() == 1 && "expected one allocation to be yielded");
   builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
 
   // Allocate reduction variable (which is a pointer to the real reduction
@@ -995,6 +1004,16 @@ static LogicalResult allocAndInitializeReductionVars(
   return success();
 }
 
+static LogicalResult sectionsOpSupported(omp::SectionsOp op) {
+  if (!op.getAllocateVars().empty() || !op.getAllocatorVars().empty())
+return op.emitError("allocate clause not yet supported");
+
+  if (!op.getPrivateVars().empty() || op.getPrivateSyms())
+return op.emitError("privatization clauses not yet supported");
+
+  return success();
+}
+
 static LogicalResult
 convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
@@ -1004,12 +1023,8 @@ convertOmpSections(Operation &opInst, 
llvm::IRBuilderBase &builder,
 
   auto sectionsOp = cast(opInst);
 
-  // TODO: Support the following clauses: private, firstprivate, lastprivat

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Emit descriptive errors for all unsupported clauses (PR #114037)

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


@@ -640,6 +642,13 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase 
&builder,
   return success();
 }
 
+static LogicalResult orderedRegionSupported(omp::OrderedRegionOp op) {

skatrak wrote:

Thanks for the comment @Meinersbur. I was actually planning on creating a 
follow-up PR to centralize this a bit more, but I decided that it might help 
address your comments so I made these changes here. Yes, the idea is to have 
this be called for all operations regardless of how many unimplemented clauses 
they have, for consistency. Hopefully the template approach I updated this PR 
with works for you.

https://github.com/llvm/llvm-project/pull/114037
___
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] Emit descriptive errors for all unsupported clauses (PR #114037)

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

https://github.com/skatrak edited 
https://github.com/llvm/llvm-project/pull/114037
___
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] [FileSystem] Allow exclusive file lock (PR #114098)

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

llvmbot wrote:




@llvm/pr-subscribers-platform-windows

Author: Steven Wu (cachemeifyoucan)


Changes

Add parameter to file lock API to allow exclusive file lock. Both Unix
and Windows support lock the file exclusively for write for one process
and LLVM OnDiskCAS uses exclusive file lock to coordinate CAS creation.


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


4 Files Affected:

- (modified) llvm/include/llvm/Support/FileSystem.h (+6-2) 
- (modified) llvm/lib/Support/Unix/Path.inc (+7-4) 
- (modified) llvm/lib/Support/Windows/Path.inc (+8-4) 
- (modified) llvm/unittests/Support/ProgramTest.cpp (+76) 


``diff
diff --git a/llvm/include/llvm/Support/FileSystem.h 
b/llvm/include/llvm/Support/FileSystem.h
index 9cf53360b4e9662..38ad0e712b32eda 100644
--- a/llvm/include/llvm/Support/FileSystem.h
+++ b/llvm/include/llvm/Support/FileSystem.h
@@ -1184,12 +1184,16 @@ openNativeFileForRead(const Twine &Name, OpenFlags 
Flags = OF_None,
 /// descriptor.
 std::error_code
 tryLockFile(int FD,
-std::chrono::milliseconds Timeout = std::chrono::milliseconds(0));
+std::chrono::milliseconds Timeout = std::chrono::milliseconds(0),
+bool Exclusive = true);
 
 /// Lock the file.
 ///
 /// This function acts as @ref tryLockFile but it waits infinitely.
-std::error_code lockFile(int FD);
+/// \param FD file descriptor to use for locking.
+/// \param Exclusive if \p true use exclusive/writer lock, otherwise use
+/// shared/reader lock.
+std::error_code lockFile(int FD, bool Exclusive = true);
 
 /// Unlock the file.
 ///
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 44097bad7b46edc..9f6f15bbd05f2d8 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -1223,13 +1223,14 @@ Expected readNativeFileSlice(file_t FD, 
MutableArrayRef Buf,
   return NumRead;
 }
 
-std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout) {
+std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout,
+bool Exclusive) {
   auto Start = std::chrono::steady_clock::now();
   auto End = Start + Timeout;
   do {
 struct flock Lock;
 memset(&Lock, 0, sizeof(Lock));
-Lock.l_type = F_WRLCK;
+Lock.l_type = Exclusive ? F_WRLCK : F_RDLCK;
 Lock.l_whence = SEEK_SET;
 Lock.l_start = 0;
 Lock.l_len = 0;
@@ -1238,15 +1239,17 @@ std::error_code tryLockFile(int FD, 
std::chrono::milliseconds Timeout) {
 int Error = errno;
 if (Error != EACCES && Error != EAGAIN)
   return std::error_code(Error, std::generic_category());
+if (Timeout.count() == 0)
+  break;
 usleep(1000);
   } while (std::chrono::steady_clock::now() < End);
   return make_error_code(errc::no_lock_available);
 }
 
-std::error_code lockFile(int FD) {
+std::error_code lockFile(int FD, bool Exclusive) {
   struct flock Lock;
   memset(&Lock, 0, sizeof(Lock));
-  Lock.l_type = F_WRLCK;
+  Lock.l_type = Exclusive ? F_WRLCK : F_RDLCK;
   Lock.l_whence = SEEK_SET;
   Lock.l_start = 0;
   Lock.l_len = 0;
diff --git a/llvm/lib/Support/Windows/Path.inc 
b/llvm/lib/Support/Windows/Path.inc
index c4bd5e24723517a..07ee3d96be5ec6b 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -1327,8 +1327,10 @@ Expected readNativeFileSlice(file_t FileHandle,
   return readNativeFileImpl(FileHandle, Buf, &Overlapped);
 }
 
-std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout) {
-  DWORD Flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
+std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout,
+bool Exclusive) {
+  DWORD Flags = Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
+  Flags |= LOCKFILE_FAIL_IMMEDIATELY;
   OVERLAPPED OV = {};
   file_t File = convertFDToNativeFile(FD);
   auto Start = std::chrono::steady_clock::now();
@@ -1338,6 +1340,8 @@ std::error_code tryLockFile(int FD, 
std::chrono::milliseconds Timeout) {
   return std::error_code();
 DWORD Error = ::GetLastError();
 if (Error == ERROR_LOCK_VIOLATION) {
+  if (Timeout.count() == 0)
+break;
   ::Sleep(1);
   continue;
 }
@@ -1346,8 +1350,8 @@ std::error_code tryLockFile(int FD, 
std::chrono::milliseconds Timeout) {
   return mapWindowsError(ERROR_LOCK_VIOLATION);
 }
 
-std::error_code lockFile(int FD) {
-  DWORD Flags = LOCKFILE_EXCLUSIVE_LOCK;
+std::error_code lockFile(int FD, bool Exclusive) {
+  DWORD Flags = Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
   OVERLAPPED OV = {};
   file_t File = convertFDToNativeFile(FD);
   if (::LockFileEx(File, Flags, 0, MAXDWORD, MAXDWORD, &OV))
diff --git a/llvm/unittests/Support/ProgramTest.cpp 
b/llvm/unittests/Support/ProgramTest.cpp
index b1b35eacd1f6187..93db38b47096671 100644
--- a/llvm/unittests/Support/ProgramTest.cpp
+++ b/llvm/unittests/Support/ProgramTest.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/Comman

[llvm-branch-commits] [CAS] Add MappedFileRegionBumpPtr (PR #114099)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114099

Add MappedFileRegionBumpPtr which can be served as a file system backed
persistent memory allocator. The allocator works like a BumpPtrAllocator,
and is designed to be thread safe and process safe.

The implementation relies on the POSIX compliance of file system and
doesn't work on all file systems. If the file system supports lazy tail
(doesn't allocate disk space if the tail of the large file is not used),
user has more flexibility to declare a larger capacity.

The allocator works by using a atomically updated bump ptr at a location
that can be customized by the user. The atomic pointer points to the
next available space to allocate, and the allocator will resize/truncate
to current usage once all clients closed the allocator.



___
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] [CAS] Add OnDiskHashMappedTrie (PR #114100)

2024-10-29 Thread Steven Wu via llvm-branch-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/114100

Add OnDiskHashMappedTrie. This is a on-disk persistent hash map that
uses a Trie data structure that is similar to TrieRawHashMap.
OnDiskHashMappedTrie is thread safe and process safe. It is mostly lock
free, except it internally coordinates cross process creation and
closing using file lock.

TODO: consider rename to OnDiskTrieHashMap to match TrieRawHashMap.



___
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] Fix C23 constexpr crashes (#112708) (PR #112855)

2024-10-29 Thread Aaron Ballman via llvm-branch-commits

AaronBallman wrote:

> This has conflicts now. Can someone fix it and I can merge it for 19.1.4

I took a shot at resolving the conflicts (I think Mariya is out on vacation 
currently).

https://github.com/llvm/llvm-project/pull/112855
___
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] Fix C23 constexpr crashes (#112708) (PR #112855)

2024-10-29 Thread Aaron Ballman via llvm-branch-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/112855

>From fb40fba6f9caf44a1e839525efdaebdf936c2934 Mon Sep 17 00:00:00 2001
From: Mariya Podchishchaeva 
Date: Fri, 18 Oct 2024 10:18:34 +0200
Subject: [PATCH] [clang] Fix C23 constexpr crashes (#112708)

Before using a constexpr variable that is not properly initialized check
that it is valid.

Fixes https://github.com/llvm/llvm-project/issues/109095
Fixes https://github.com/llvm/llvm-project/issues/112516
---
 clang/lib/AST/Decl.cpp  | 10 +++---
 clang/test/Sema/constexpr.c | 17 +
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 490c4a2fc525cd..bc7cce0bcd7fc2 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2503,7 +2503,8 @@ bool VarDecl::isUsableInConstantExpressions(const 
ASTContext &Context) const {
   if (!DefVD->mightBeUsableInConstantExpressions(Context))
 return false;
   //   ... and its initializer is a constant initializer.
-  if (Context.getLangOpts().CPlusPlus && !DefVD->hasConstantInitialization())
+  if ((Context.getLangOpts().CPlusPlus || getLangOpts().C23) &&
+  !DefVD->hasConstantInitialization())
 return false;
   // C++98 [expr.const]p1:
   //   An integral constant-expression can involve only [...] const variables
@@ -2610,8 +2611,11 @@ bool VarDecl::hasICEInitializer(const ASTContext 
&Context) const {
 }
 
 bool VarDecl::hasConstantInitialization() const {
-  // In C, all globals (and only globals) have constant initialization.
-  if (hasGlobalStorage() && !getASTContext().getLangOpts().CPlusPlus)
+  // In C, all globals and constexpr variables should have constant
+  // initialization. For constexpr variables in C check that initializer is a
+  // constant initializer because they can be used in constant expressions.
+  if (hasGlobalStorage() && !getASTContext().getLangOpts().CPlusPlus &&
+  !isConstexpr())
 return true;
 
   // In C++, it depends on whether the evaluation at the point of definition
diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c
index 8286cd2107d2f2..fe014fadb11ec8 100644
--- a/clang/test/Sema/constexpr.c
+++ b/clang/test/Sema/constexpr.c
@@ -357,3 +357,20 @@ void infsNaNs() {
   constexpr double db5 = LD_SNAN; // expected-error {{constexpr initializer 
evaluates to nan which is not exactly representable in type 'const double'}}
   constexpr double db6 = INF;
 }
+
+struct S11 {
+  int len;
+};
+void ghissue112516() {
+  struct S11 *s11 = 0;
+  constexpr int num = s11->len; // expected-error {{constexpr variable 'num' 
must be initialized by a constant expression}}
+  void *Arr[num];
+}
+
+void ghissue109095() {
+  constexpr char c[] = { 'a' };
+  constexpr int i = c[1]; // expected-error {{constexpr variable 'i' must be 
initialized by a constant expression}}\
+  // expected-note {{declared here}}
+  _Static_assert(i == c[0]); // expected-error {{static assertion expression 
is not an integral constant expression}}\
+ // expected-note {{initializer of 'i' is not a 
constant expression}}
+}

___
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] 17365df - Bump version to 19.1.3

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

Author: Tobias Hieta
Date: 2024-10-29T09:57:40+01:00
New Revision: 17365dfd21011cbd5972a88dd5dd45575f2c81ec

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

LOG: Bump version to 19.1.3

Added: 


Modified: 
cmake/Modules/LLVMVersion.cmake
libcxx/include/__config
llvm/utils/gn/secondary/llvm/version.gni
llvm/utils/lit/lit/__init__.py
llvm/utils/mlgo-utils/mlgo/__init__.py

Removed: 




diff  --git a/cmake/Modules/LLVMVersion.cmake b/cmake/Modules/LLVMVersion.cmake
index e521cf77fd58a1..d57561fcd17482 100644
--- a/cmake/Modules/LLVMVersion.cmake
+++ b/cmake/Modules/LLVMVersion.cmake
@@ -7,7 +7,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
   set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
-  set(LLVM_VERSION_PATCH 2)
+  set(LLVM_VERSION_PATCH 3)
 endif()
 if(NOT DEFINED LLVM_VERSION_SUFFIX)
   set(LLVM_VERSION_SUFFIX)

diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 272375907eb50e..ecb21a705c5152 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -27,7 +27,7 @@
 // _LIBCPP_VERSION represents the version of libc++, which matches the version 
of LLVM.
 // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), 
_LIBCPP_VERSION is
 // defined to XXYYZZ.
-#  define _LIBCPP_VERSION 190102
+#  define _LIBCPP_VERSION 190103
 
 #  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
 #  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)

diff  --git a/llvm/utils/gn/secondary/llvm/version.gni 
b/llvm/utils/gn/secondary/llvm/version.gni
index 1e041c6b506bb5..fa570bad3b1bea 100644
--- a/llvm/utils/gn/secondary/llvm/version.gni
+++ b/llvm/utils/gn/secondary/llvm/version.gni
@@ -1,4 +1,4 @@
 llvm_version_major = 19
 llvm_version_minor = 1
-llvm_version_patch = 2
+llvm_version_patch = 3
 llvm_version = "$llvm_version_major.$llvm_version_minor.$llvm_version_patch"

diff  --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py
index cebdf15cefc55c..9c7b53d82aae21 100644
--- a/llvm/utils/lit/lit/__init__.py
+++ b/llvm/utils/lit/lit/__init__.py
@@ -2,7 +2,7 @@
 
 __author__ = "Daniel Dunbar"
 __email__ = "dan...@minormatter.com"
-__versioninfo__ = (19, 1, 2)
+__versioninfo__ = (19, 1, 3)
 __version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
 
 __all__ = []

diff  --git a/llvm/utils/mlgo-utils/mlgo/__init__.py 
b/llvm/utils/mlgo-utils/mlgo/__init__.py
index 99fd714184410e..95aa8e2684d06a 100644
--- a/llvm/utils/mlgo-utils/mlgo/__init__.py
+++ b/llvm/utils/mlgo-utils/mlgo/__init__.py
@@ -4,7 +4,7 @@
 
 from datetime import timezone, datetime
 
-__versioninfo__ = (19, 1, 2)
+__versioninfo__ = (19, 1, 3)
 __version__ = (
 ".".join(str(v) for v in __versioninfo__)
 + "dev"



___
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] AMDGPU: Fix producing invalid IR on vector typed getelementptr (PR #114113)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/114113?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#114113** https://app.graphite.dev/github/pr/llvm/llvm-project/114113?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈
* **#114091** https://app.graphite.dev/github/pr/llvm/llvm-project/114091?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`

This stack of pull requests is managed by Graphite. https://stacking.dev/?utm_source=stack-comment";>Learn more about 
stacking.


 Join @arsenm and the rest of your teammates on https://graphite.dev?utm-source=stack-comment";>https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="11px" height="11px"/> Graphite
  

https://github.com/llvm/llvm-project/pull/114113
___
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] AMDGPU: Fix producing invalid IR on vector typed getelementptr (PR #114113)

2024-10-29 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/114113

This did not consider the IR change to allow a scalar base with a vector
offset part. Reject any users that are not explicitly handled.

In this situation we could handle the vector GEP, but that is a larger
change. This just avoids the IR verifier error by rejecting it.

>From be705d086aa6fe501c7fc3c80d1ac63711e205f8 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Tue, 29 Oct 2024 10:26:10 -0700
Subject: [PATCH] AMDGPU: Fix producing invalid IR on vector typed
 getelementptr

This did not consider the IR change to allow a scalar base with a vector
offset part. Reject any users that are not explicitly handled.

In this situation we could handle the vector GEP, but that is a larger
change. This just avoids the IR verifier error by rejecting it.
---
 .../lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp | 18 ++--
 .../promote-alloca-invalid-vector-gep.ll  | 44 +++
 2 files changed, 58 insertions(+), 4 deletions(-)
 create mode 100644 
llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index f8744d6a483cff..7dd7388376f474 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -1159,7 +1159,6 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
 if (LoadInst *LI = dyn_cast(UseInst)) {
   if (LI->isVolatile())
 return false;
-
   continue;
 }
 
@@ -1170,12 +1169,19 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
   // Reject if the stored value is not the pointer operand.
   if (SI->getPointerOperand() != Val)
 return false;
-} else if (AtomicRMWInst *RMW = dyn_cast(UseInst)) {
+  continue;
+}
+
+if (AtomicRMWInst *RMW = dyn_cast(UseInst)) {
   if (RMW->isVolatile())
 return false;
-} else if (AtomicCmpXchgInst *CAS = dyn_cast(UseInst)) {
+  continue;
+}
+
+if (AtomicCmpXchgInst *CAS = dyn_cast(UseInst)) {
   if (CAS->isVolatile())
 return false;
+  continue;
 }
 
 // Only promote a select if we know that the other select operand
@@ -1186,6 +1192,7 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
 
   // May need to rewrite constant operands.
   WorkList.push_back(ICmp);
+  continue;
 }
 
 // TODO: If we know the address is only observed through flat pointers, we
@@ -1198,8 +1205,9 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
 if (isa(User) || isa(User))
   return false;
 
+// TODO: Handle vectors of pointers.
 if (!User->getType()->isPointerTy())
-  continue;
+  return false;
 
 if (GetElementPtrInst *GEP = dyn_cast(UseInst)) {
   // Be conservative if an address could be computed outside the bounds of
@@ -1504,6 +1512,8 @@ bool 
AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
 
   PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
 
+  assert(isa(V->getType()));
+
   // FIXME: It doesn't really make sense to try to do this for all
   // instructions.
   V->mutateType(NewTy);
diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll 
b/llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll
new file mode 100644
index 00..b0d578e421e280
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 5
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-promote-alloca < %s | 
FileCheck %s
+
+; Check that invalid IR is not produced on a vector typed
+; getelementptr with a scalar alloca pointer base.
+
+define amdgpu_kernel void @scalar_alloca_ptr_with_vector_gep_offset() {
+; CHECK-LABEL: define amdgpu_kernel void 
@scalar_alloca_ptr_with_vector_gep_offset() {
+; CHECK-NEXT:  [[BB:.*:]]
+; CHECK-NEXT:[[ALLOCA:%.*]] = alloca i32, align 4, addrspace(5)
+; CHECK-NEXT:[[GETELEMENTPTR:%.*]] = getelementptr inbounds i8, ptr 
addrspace(5) [[ALLOCA]], <4 x i64> 
+; CHECK-NEXT:[[EXTRACTELEMENT:%.*]] = extractelement <4 x ptr 
addrspace(5)> [[GETELEMENTPTR]], i64 0
+; CHECK-NEXT:store i32 0, ptr addrspace(5) [[EXTRACTELEMENT]], align 4
+; CHECK-NEXT:ret void
+;
+bb:
+  %alloca = alloca i32, align 4, addrspace(5)
+  %getelementptr = getelementptr inbounds i8, ptr addrspace(5) %alloca, <4 x 
i64> 
+  %extractelement = extractelement <4 x ptr addrspace(5)> %getelementptr, i64 0
+  store i32 0, ptr addrspace(5) %extractelement
+  ret void
+}
+
+define amdgpu_kernel void @scalar_alloca_ptr_with_vector_gep_offset_select(i1 
%cond) {
+; CHECK-LABEL: define amdgpu_kernel void 
@scalar_alloca_ptr_with_vector_gep_offset_select(
+; CHECK-SAME: i1 [[COND:%.*]]) {
+; CHECK-NEXT:  [[BB:.*:]]
+; CHECK-NEXT:[[ALLO

[llvm-branch-commits] [llvm] AMDGPU: Fix producing invalid IR on vector typed getelementptr (PR #114113)

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

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)


Changes

This did not consider the IR change to allow a scalar base with a vector
offset part. Reject any users that are not explicitly handled.

In this situation we could handle the vector GEP, but that is a larger
change. This just avoids the IR verifier error by rejecting it.

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


2 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp (+14-4) 
- (added) llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll (+44) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index f8744d6a483cff..7dd7388376f474 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -1159,7 +1159,6 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
 if (LoadInst *LI = dyn_cast(UseInst)) {
   if (LI->isVolatile())
 return false;
-
   continue;
 }
 
@@ -1170,12 +1169,19 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
   // Reject if the stored value is not the pointer operand.
   if (SI->getPointerOperand() != Val)
 return false;
-} else if (AtomicRMWInst *RMW = dyn_cast(UseInst)) {
+  continue;
+}
+
+if (AtomicRMWInst *RMW = dyn_cast(UseInst)) {
   if (RMW->isVolatile())
 return false;
-} else if (AtomicCmpXchgInst *CAS = dyn_cast(UseInst)) {
+  continue;
+}
+
+if (AtomicCmpXchgInst *CAS = dyn_cast(UseInst)) {
   if (CAS->isVolatile())
 return false;
+  continue;
 }
 
 // Only promote a select if we know that the other select operand
@@ -1186,6 +1192,7 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
 
   // May need to rewrite constant operands.
   WorkList.push_back(ICmp);
+  continue;
 }
 
 // TODO: If we know the address is only observed through flat pointers, we
@@ -1198,8 +1205,9 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
 if (isa(User) || isa(User))
   return false;
 
+// TODO: Handle vectors of pointers.
 if (!User->getType()->isPointerTy())
-  continue;
+  return false;
 
 if (GetElementPtrInst *GEP = dyn_cast(UseInst)) {
   // Be conservative if an address could be computed outside the bounds of
@@ -1504,6 +1512,8 @@ bool 
AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
 
   PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
 
+  assert(isa(V->getType()));
+
   // FIXME: It doesn't really make sense to try to do this for all
   // instructions.
   V->mutateType(NewTy);
diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll 
b/llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll
new file mode 100644
index 00..b0d578e421e280
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-invalid-vector-gep.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 5
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-promote-alloca < %s | 
FileCheck %s
+
+; Check that invalid IR is not produced on a vector typed
+; getelementptr with a scalar alloca pointer base.
+
+define amdgpu_kernel void @scalar_alloca_ptr_with_vector_gep_offset() {
+; CHECK-LABEL: define amdgpu_kernel void 
@scalar_alloca_ptr_with_vector_gep_offset() {
+; CHECK-NEXT:  [[BB:.*:]]
+; CHECK-NEXT:[[ALLOCA:%.*]] = alloca i32, align 4, addrspace(5)
+; CHECK-NEXT:[[GETELEMENTPTR:%.*]] = getelementptr inbounds i8, ptr 
addrspace(5) [[ALLOCA]], <4 x i64> 
+; CHECK-NEXT:[[EXTRACTELEMENT:%.*]] = extractelement <4 x ptr 
addrspace(5)> [[GETELEMENTPTR]], i64 0
+; CHECK-NEXT:store i32 0, ptr addrspace(5) [[EXTRACTELEMENT]], align 4
+; CHECK-NEXT:ret void
+;
+bb:
+  %alloca = alloca i32, align 4, addrspace(5)
+  %getelementptr = getelementptr inbounds i8, ptr addrspace(5) %alloca, <4 x 
i64> 
+  %extractelement = extractelement <4 x ptr addrspace(5)> %getelementptr, i64 0
+  store i32 0, ptr addrspace(5) %extractelement
+  ret void
+}
+
+define amdgpu_kernel void @scalar_alloca_ptr_with_vector_gep_offset_select(i1 
%cond) {
+; CHECK-LABEL: define amdgpu_kernel void 
@scalar_alloca_ptr_with_vector_gep_offset_select(
+; CHECK-SAME: i1 [[COND:%.*]]) {
+; CHECK-NEXT:  [[BB:.*:]]
+; CHECK-NEXT:[[ALLOCA:%.*]] = alloca i32, align 4, addrspace(5)
+; CHECK-NEXT:[[GETELEMENTPTR0:%.*]] = getelementptr inbounds i8, ptr 
addrspace(5) [[ALLOCA]], <4 x i64> 
+; CHECK-NEXT:[[GETELEMENTPTR1:%.*]] = getelementptr inbounds i8, ptr 
addrspace(5) [[ALLOCA]], <4 x i64> 
+; CHECK-NEXT:[[SELECT:%.*]] = select i1 [[COND]], <4 x ptr addrspace(5)> 
[[GETELEMENTPTR0]], <4 x ptr addrspace(5)> [[GETELEMENTPTR1]]
+; CHECK-NEXT:[[EXTRACTELEMENT:%.*]] = extractelement <4 x ptr 
addrspace(5)>

[llvm-branch-commits] [llvm] release/19.x: [NFC] fix build failure (#100993) (PR #112551)

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

github-actions[bot] wrote:

@mgorny (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.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/112551
___
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/19.x: [AVR][MC] Fix incorrect range of relative jumps (#109124) (PR #113969)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/113969

>From 936710a0a18bdf8ac1655f6e3bb518b20bb41aea Mon Sep 17 00:00:00 2001
From: Ben Shi <2283975...@qq.com>
Date: Fri, 20 Sep 2024 11:40:07 +0800
Subject: [PATCH] [AVR][MC] Fix incorrect range of relative jumps (#109124)

'rjmp .+4094' is legal but rejected by llvm-mc since
86a60e7f1e8f361f84ccb6e656e848dd4fbaa713, and this patch fixed that
range issue.

(cherry picked from commit 8c3b94f420a20a45dd07f3e12d6a6d649858f452)
---
 .../Target/AVR/MCTargetDesc/AVRAsmBackend.cpp |  6 +--
 llvm/test/MC/AVR/inst-rjmp.s  | 40 ++-
 2 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp 
b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
index 388d58a82214d1..c0bc1276967bf0 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
@@ -88,15 +88,15 @@ static void adjustBranch(unsigned Size, const MCFixup 
&Fixup, uint64_t &Value,
 /// Adjusts the value of a relative branch target before fixup application.
 static void adjustRelativeBranch(unsigned Size, const MCFixup &Fixup,
  uint64_t &Value, MCContext *Ctx = nullptr) {
+  // Jumps are relative to the current instruction.
+  Value -= 2;
+
   // We have one extra bit of precision because the value is rightshifted by
   // one.
   signed_width(Size + 1, Value, std::string("branch target"), Fixup, Ctx);
 
   // Rightshifts the value by one.
   AVR::fixups::adjustBranchTarget(Value);
-
-  // Jumps are relative to the current instruction.
-  Value -= 1;
 }
 
 /// 22-bit absolute fixup.
diff --git a/llvm/test/MC/AVR/inst-rjmp.s b/llvm/test/MC/AVR/inst-rjmp.s
index cc843a58b55d2c..2d7aa401feacf0 100644
--- a/llvm/test/MC/AVR/inst-rjmp.s
+++ b/llvm/test/MC/AVR/inst-rjmp.s
@@ -19,25 +19,28 @@ end:
 x:
   rjmp x
   .short 0xc00f
+  rjmp .+4094
 
-; CHECK: rjmp (.Ltmp0+2)+2  ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: (.Ltmp0+2)+2, 
kind: fixup_13_pcrel
-; CHECK: rjmp (.Ltmp1-2)+2  ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: (.Ltmp1-2)+2, 
kind: fixup_13_pcrel
-; CHECK: rjmp foo   ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: foo, kind: 
fixup_13_pcrel
-; CHECK: rjmp (.Ltmp2+8)+2  ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: (.Ltmp2+8)+2, 
kind: fixup_13_pcrel
-; CHECK: rjmp end   ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: end, kind: 
fixup_13_pcrel
-; CHECK: rjmp (.Ltmp3+0)+2  ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: (.Ltmp3+0)+2, 
kind: fixup_13_pcrel
-; CHECK: rjmp (.Ltmp4-4)+2  ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: (.Ltmp4-4)+2, 
kind: fixup_13_pcrel
-; CHECK: rjmp (.Ltmp5-6)+2  ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: (.Ltmp5-6)+2, 
kind: fixup_13_pcrel
-; CHECK: rjmp x ; encoding: [A,0b1100]
-; CHECK-NEXT:   ;   fixup A - offset: 0, value: x, kind: 
fixup_13_pcrel
+; CHECK: rjmp (.Ltmp0+2)+2; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: (.Ltmp0+2)+2, 
kind: fixup_13_pcrel
+; CHECK: rjmp (.Ltmp1-2)+2; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: (.Ltmp1-2)+2, 
kind: fixup_13_pcrel
+; CHECK: rjmp foo ; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: foo, kind: 
fixup_13_pcrel
+; CHECK: rjmp (.Ltmp2+8)+2; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: (.Ltmp2+8)+2, 
kind: fixup_13_pcrel
+; CHECK: rjmp end ; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: end, kind: 
fixup_13_pcrel
+; CHECK: rjmp (.Ltmp3+0)+2; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: (.Ltmp3+0)+2, 
kind: fixup_13_pcrel
+; CHECK: rjmp (.Ltmp4-4)+2; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: (.Ltmp4-4)+2, 
kind: fixup_13_pcrel
+; CHECK: rjmp (.Ltmp5-6)+2; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: (.Ltmp5-6)+2, 
kind: fixup_13_pcrel
+; CHECK: rjmp x   ; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: x, kind: 
fixup_13_pcrel
+; CHECK: rjmp (.Ltmp6+4094)+2 ; encoding: [A,0b1100]
+; CHECK-NEXT: ;   fixup A - offset: 0, value: (.Ltmp6+4094)+2, 
kind: fixup_13_pcrel
 
 ; INST-LABEL: :
 ; INST-NEXT: 01 c0  rjmp  .+2
@@ -54,3 +57,4 @@ x:
 ; INST-LABEL: :
 ; INST-NEXT: ff cf  rjmp  .-2
 ; INST

[llvm-branch-commits] [llvm] release/19.x: [RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (#109513) (PR #114089)

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

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/114089
___
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/19.x: [RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (#109513) (PR #114089)

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

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

Backport c3d3cef8d58377b02032b07b5f094a402a70435a

Requested by: @topperc

>From 55446b4aa6610362e05181c9680c828a98ae34e9 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Sun, 22 Sep 2024 22:31:36 -0700
Subject: [PATCH] [RISCV] Don't delete all fixups in
 RISCVMCCodeEmitter::expandLongCondBr. (#109513)

The Fixups vector passed into this function may already have fixups in
it from earlier instructions. We should not erase those. We just want to
erase fixups added by this function.

Fixes #108612.

(cherry picked from commit c3d3cef8d58377b02032b07b5f094a402a70435a)
---
 llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp | 7 ++-
 llvm/test/MC/RISCV/rv64-relax-all.s   | 6 ++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp 
b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
index 0863345b0c6dc6..c9636b2c702508 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
@@ -283,13 +283,18 @@ void RISCVMCCodeEmitter::expandLongCondBr(const MCInst 
&MI,
 Offset = 4;
   }
 
+  // Save the number fixups.
+  size_t FixupStartIndex = Fixups.size();
+
   // Emit an unconditional jump to the destination.
   MCInst TmpInst =
   MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).addOperand(SrcSymbol);
   uint32_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
   support::endian::write(CB, Binary, llvm::endianness::little);
 
-  Fixups.clear();
+  // Drop any fixup added so we can add the correct one.
+  Fixups.resize(FixupStartIndex);
+
   if (SrcSymbol.isExpr()) {
 Fixups.push_back(MCFixup::create(Offset, SrcSymbol.getExpr(),
  MCFixupKind(RISCV::fixup_riscv_jal),
diff --git a/llvm/test/MC/RISCV/rv64-relax-all.s 
b/llvm/test/MC/RISCV/rv64-relax-all.s
index 70a3f77540c997..6705d6ecfb5b62 100644
--- a/llvm/test/MC/RISCV/rv64-relax-all.s
+++ b/llvm/test/MC/RISCV/rv64-relax-all.s
@@ -14,3 +14,9 @@ c.beqz a0, NEAR
 # INSTR:   c.j0x0 
 # RELAX-INSTR: jalzero, 0x0 
 c.j NEAR
+
+bnez s0, .foo
+j.foo
+beqz s0, .foo
+.foo:
+ret

___
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/19.x: [RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (#109513) (PR #114089)

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

llvmbot wrote:

@wangpc-pp What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/114089
___
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/19.x: [RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (#109513) (PR #114089)

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

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: None (llvmbot)


Changes

Backport c3d3cef8d58377b02032b07b5f094a402a70435a

Requested by: @topperc

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


2 Files Affected:

- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp (+6-1) 
- (modified) llvm/test/MC/RISCV/rv64-relax-all.s (+6) 


``diff
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp 
b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
index 0863345b0c6dc6..c9636b2c702508 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
@@ -283,13 +283,18 @@ void RISCVMCCodeEmitter::expandLongCondBr(const MCInst 
&MI,
 Offset = 4;
   }
 
+  // Save the number fixups.
+  size_t FixupStartIndex = Fixups.size();
+
   // Emit an unconditional jump to the destination.
   MCInst TmpInst =
   MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).addOperand(SrcSymbol);
   uint32_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
   support::endian::write(CB, Binary, llvm::endianness::little);
 
-  Fixups.clear();
+  // Drop any fixup added so we can add the correct one.
+  Fixups.resize(FixupStartIndex);
+
   if (SrcSymbol.isExpr()) {
 Fixups.push_back(MCFixup::create(Offset, SrcSymbol.getExpr(),
  MCFixupKind(RISCV::fixup_riscv_jal),
diff --git a/llvm/test/MC/RISCV/rv64-relax-all.s 
b/llvm/test/MC/RISCV/rv64-relax-all.s
index 70a3f77540c997..6705d6ecfb5b62 100644
--- a/llvm/test/MC/RISCV/rv64-relax-all.s
+++ b/llvm/test/MC/RISCV/rv64-relax-all.s
@@ -14,3 +14,9 @@ c.beqz a0, NEAR
 # INSTR:   c.j0x0 
 # RELAX-INSTR: jalzero, 0x0 
 c.j NEAR
+
+bnez s0, .foo
+j.foo
+beqz s0, .foo
+.foo:
+ret

``




https://github.com/llvm/llvm-project/pull/114089
___
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/19.x: [RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (#109513) (PR #114089)

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

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: None (llvmbot)


Changes

Backport c3d3cef8d58377b02032b07b5f094a402a70435a

Requested by: @topperc

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


2 Files Affected:

- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp (+6-1) 
- (modified) llvm/test/MC/RISCV/rv64-relax-all.s (+6) 


``diff
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp 
b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
index 0863345b0c6dc6..c9636b2c702508 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
@@ -283,13 +283,18 @@ void RISCVMCCodeEmitter::expandLongCondBr(const MCInst 
&MI,
 Offset = 4;
   }
 
+  // Save the number fixups.
+  size_t FixupStartIndex = Fixups.size();
+
   // Emit an unconditional jump to the destination.
   MCInst TmpInst =
   MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).addOperand(SrcSymbol);
   uint32_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
   support::endian::write(CB, Binary, llvm::endianness::little);
 
-  Fixups.clear();
+  // Drop any fixup added so we can add the correct one.
+  Fixups.resize(FixupStartIndex);
+
   if (SrcSymbol.isExpr()) {
 Fixups.push_back(MCFixup::create(Offset, SrcSymbol.getExpr(),
  MCFixupKind(RISCV::fixup_riscv_jal),
diff --git a/llvm/test/MC/RISCV/rv64-relax-all.s 
b/llvm/test/MC/RISCV/rv64-relax-all.s
index 70a3f77540c997..6705d6ecfb5b62 100644
--- a/llvm/test/MC/RISCV/rv64-relax-all.s
+++ b/llvm/test/MC/RISCV/rv64-relax-all.s
@@ -14,3 +14,9 @@ c.beqz a0, NEAR
 # INSTR:   c.j0x0 
 # RELAX-INSTR: jalzero, 0x0 
 c.j NEAR
+
+bnez s0, .foo
+j.foo
+beqz s0, .foo
+.foo:
+ret

``




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


[llvm-branch-commits] [lld] [PAC][lld] Use braa instr in PAC PLT sequence with valid PAuth core info (PR #113945)

2024-10-29 Thread Anton Korobeynikov via llvm-branch-commits

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


[llvm-branch-commits] [lld] [PAC][lld] Use braa instr in PAC PLT sequence with valid PAuth core info (PR #113945)

2024-10-29 Thread Anton Korobeynikov via llvm-branch-commits


@@ -999,7 +999,9 @@ class AArch64BtiPac final : public AArch64 {
 
 private:
   bool btiHeader; // bti instruction needed in PLT Header and Entry
-  bool pacEntry;  // autia1716 instruction needed in PLT Entry
+  bool pacEntry;  // Authenticated branch needed in PLT Entry

asl wrote:

maybe we can just have enum here instead of pair of bools? E.g.
``enum {
  Unsigned,
  SignedHint,  // use autia1716 instruction in PLT entry
  Signed // can use non-hint braa instruction
}
```

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


[llvm-branch-commits] [lld] [PAC][lld] Use braa instr in PAC PLT sequence with valid PAuth core info (PR #113945)

2024-10-29 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/113945
___
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] [CodeGen][NewPM] Port RegUsageInfoCollector pass to NPM (PR #113874)

2024-10-29 Thread Akshat Oke via llvm-branch-commits

https://github.com/optimisan updated 
https://github.com/llvm/llvm-project/pull/113874

>From 7394bab5609ec2dc56f1851143d8eebb4a5f5b63 Mon Sep 17 00:00:00 2001
From: Akshat Oke 
Date: Mon, 28 Oct 2024 06:22:49 +
Subject: [PATCH 1/3] [CodeGen][NewPM] Port RegUsageInfoCollector pass to NPM

---
 .../llvm/CodeGen/RegUsageInfoCollector.h  | 25 
 llvm/include/llvm/InitializePasses.h  |  2 +-
 llvm/include/llvm/Passes/CodeGenPassBuilder.h |  1 +
 .../llvm/Passes/MachinePassRegistry.def   |  2 +-
 llvm/lib/CodeGen/CodeGen.cpp  |  2 +-
 llvm/lib/CodeGen/RegUsageInfoCollector.cpp| 60 +--
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/test/CodeGen/AMDGPU/ipra-regmask.ll  |  5 ++
 8 files changed, 76 insertions(+), 22 deletions(-)
 create mode 100644 llvm/include/llvm/CodeGen/RegUsageInfoCollector.h

diff --git a/llvm/include/llvm/CodeGen/RegUsageInfoCollector.h 
b/llvm/include/llvm/CodeGen/RegUsageInfoCollector.h
new file mode 100644
index 00..6b88cc4f99089e
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/RegUsageInfoCollector.h
@@ -0,0 +1,25 @@
+//===- llvm/CodeGen/RegUsageInfoCollector.h -*- C++ 
-*-===//
+//
+// 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 LLVM_CODEGEN_REGUSAGEINFOCOLLECTOR_H
+#define LLVM_CODEGEN_REGUSAGEINFOCOLLECTOR_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+
+class RegUsageInfoCollectorPass
+: public AnalysisInfoMixin {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+MachineFunctionAnalysisManager &MFAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_REGUSAGEINFOCOLLECTOR_H
diff --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index f6f6797ec9f87c..c881dcd57006db 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -257,7 +257,7 @@ void 
initializeRegAllocPriorityAdvisorAnalysisPass(PassRegistry &);
 void initializeRegAllocScoringPass(PassRegistry &);
 void initializeRegBankSelectPass(PassRegistry &);
 void initializeRegToMemWrapperPassPass(PassRegistry &);
-void initializeRegUsageInfoCollectorPass(PassRegistry &);
+void initializeRegUsageInfoCollectorLegacyPass(PassRegistry &);
 void initializeRegUsageInfoPropagationPass(PassRegistry &);
 void initializeRegionInfoPassPass(PassRegistry &);
 void initializeRegionOnlyPrinterPass(PassRegistry &);
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h 
b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index e5de62935a8e48..14fcf9d79fbc23 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -53,6 +53,7 @@
 #include "llvm/CodeGen/PHIElimination.h"
 #include "llvm/CodeGen/PreISelIntrinsicLowering.h"
 #include "llvm/CodeGen/RegAllocFast.h"
+#include "llvm/CodeGen/RegUsageInfoCollector.h"
 #include "llvm/CodeGen/RegisterUsageInfo.h"
 #include "llvm/CodeGen/ReplaceWithVeclib.h"
 #include "llvm/CodeGen/SafeStack.h"
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def 
b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 183a777a93b9fa..36d17b713639c1 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -155,6 +155,7 @@ MACHINE_FUNCTION_PASS("print",
   MachinePostDominatorTreePrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("print", SlotIndexesPrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("print", VirtRegMapPrinterPass(dbgs()))
+MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
 MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
   RequireAllMachineFunctionPropertiesPass())
 MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass())
@@ -249,7 +250,6 @@ DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", 
PrologEpilogCodeInserterPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
-DUMMY_MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass)
 DUMMY_MACHINE_FUNCTION_PASS("reg-usage-propagation", 
RegUsageInfoPropagationPass)
 DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
 DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index cf5c35fe81b4c7..76b74ea4e6fe0b 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -113,7 +113,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeRABasicPass(Registry);
   initializeRAGreedyPass(Registry);
   initializeRegAllocFastPass(Reg

[llvm-branch-commits] [lld] [llvm] [CGData][llvm-cgdata] Support for stable function map (PR #112664)

2024-10-29 Thread Kyungwoo Lee via llvm-branch-commits

https://github.com/kyulee-com updated 
https://github.com/llvm/llvm-project/pull/112664

>From c7913f9fff736da4cc6a78a17e41dc539bc75e8a Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee 
Date: Mon, 9 Sep 2024 19:38:05 -0700
Subject: [PATCH 1/2] [CGData][llvm-cgdata] Support for stable function map

This introduces a new cgdata format for stable function maps.
The raw data is embedded in the __llvm_merge section during compile time.
This data can be read and merged using the llvm-cgdata tool, into an indexed 
cgdata file. Consequently, the tool is now capable of handling either outlined 
hash trees, stable function maps, or both, as they are orthogonal.
---
 lld/test/MachO/cgdata-generate.s  |  6 +-
 llvm/docs/CommandGuide/llvm-cgdata.rst| 16 ++--
 llvm/include/llvm/CGData/CodeGenData.h| 24 +-
 llvm/include/llvm/CGData/CodeGenData.inc  | 12 ++-
 llvm/include/llvm/CGData/CodeGenDataReader.h  | 29 ++-
 llvm/include/llvm/CGData/CodeGenDataWriter.h  | 17 +++-
 llvm/lib/CGData/CodeGenData.cpp   | 30 ---
 llvm/lib/CGData/CodeGenDataReader.cpp | 63 +-
 llvm/lib/CGData/CodeGenDataWriter.cpp | 30 ++-
 llvm/test/tools/llvm-cgdata/empty.test|  8 +-
 llvm/test/tools/llvm-cgdata/error.test| 13 +--
 .../merge-combined-funcmap-hashtree.test  | 66 +++
 .../llvm-cgdata/merge-funcmap-archive.test| 83 +++
 .../llvm-cgdata/merge-funcmap-concat.test | 78 +
 .../llvm-cgdata/merge-funcmap-double.test | 79 ++
 .../llvm-cgdata/merge-funcmap-single.test | 36 
 ...chive.test => merge-hashtree-archive.test} |  8 +-
 ...concat.test => merge-hashtree-concat.test} |  6 +-
 ...double.test => merge-hashtree-double.test} |  8 +-
 ...single.test => merge-hashtree-single.test} |  4 +-
 llvm/tools/llvm-cgdata/llvm-cgdata.cpp| 48 ---
 21 files changed, 577 insertions(+), 87 deletions(-)
 create mode 100644 
llvm/test/tools/llvm-cgdata/merge-combined-funcmap-hashtree.test
 create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-archive.test
 create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-concat.test
 create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-double.test
 create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-single.test
 rename llvm/test/tools/llvm-cgdata/{merge-archive.test => 
merge-hashtree-archive.test} (91%)
 rename llvm/test/tools/llvm-cgdata/{merge-concat.test => 
merge-hashtree-concat.test} (93%)
 rename llvm/test/tools/llvm-cgdata/{merge-double.test => 
merge-hashtree-double.test} (90%)
 rename llvm/test/tools/llvm-cgdata/{merge-single.test => 
merge-hashtree-single.test} (92%)

diff --git a/lld/test/MachO/cgdata-generate.s b/lld/test/MachO/cgdata-generate.s
index 174df39d666c5d..f942ae07f64e0e 100644
--- a/lld/test/MachO/cgdata-generate.s
+++ b/lld/test/MachO/cgdata-generate.s
@@ -3,12 +3,12 @@
 
 # RUN: rm -rf %t; split-file %s %t
 
-# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata.
+# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata.
 # RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
-# RUN: od -t x1 -j 24 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ 
/g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt
+# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ 
/g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt
 # RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > 
%t/merge-1.s
 # RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
-# RUN: od -t x1 -j 24 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ 
/g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt
+# RUN: od -t x1 -j 32 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ 
/g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt
 # RUN: sed "s//$(cat %t/raw-2-bytes.txt)/g" %t/merge-template.s > 
%t/merge-2.s
 
 # RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-1.s -o 
%t/merge-1.o
diff --git a/llvm/docs/CommandGuide/llvm-cgdata.rst 
b/llvm/docs/CommandGuide/llvm-cgdata.rst
index f592e1508844ee..0670decd087e39 100644
--- a/llvm/docs/CommandGuide/llvm-cgdata.rst
+++ b/llvm/docs/CommandGuide/llvm-cgdata.rst
@@ -11,15 +11,13 @@ SYNOPSIS
 DESCRIPTION
 ---
 
-The :program:llvm-cgdata utility parses raw codegen data embedded
-in compiled binary files and merges them into a single .cgdata file.
-It can also inspect and manipulate .cgdata files.
-Currently, the tool supports saving and restoring outlined hash trees,
-enabling global function outlining across modules, allowing for more
-efficient function outlining in subsequent compilations.
-The design is extensible, allowing for the incorporation of additional
-codegen summaries and optimization techniques, such as global function
-merging, in the f

[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegUsageInfoPropagation pass to NPM (PR #114010)

2024-10-29 Thread Akshat Oke via llvm-branch-commits

https://github.com/optimisan created 
https://github.com/llvm/llvm-project/pull/114010

None

>From f84d99b53730031fef705949a5fd34283e9e9eeb Mon Sep 17 00:00:00 2001
From: Akshat Oke 
Date: Tue, 29 Oct 2024 07:14:30 +
Subject: [PATCH] [CodeGen][NewPM] Port RegUsageInfoPropagation pass to NPM

---
 .../llvm/CodeGen/RegUsageInfoPropagate.h  | 25 ++
 llvm/include/llvm/InitializePasses.h  |  2 +-
 llvm/include/llvm/Passes/CodeGenPassBuilder.h |  1 +
 .../llvm/Passes/MachinePassRegistry.def   |  2 +-
 llvm/lib/CodeGen/CodeGen.cpp  |  2 +-
 llvm/lib/CodeGen/RegUsageInfoPropagate.cpp| 76 +--
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/test/CodeGen/AArch64/preserve.ll |  4 +
 8 files changed, 88 insertions(+), 25 deletions(-)
 create mode 100644 llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h

diff --git a/llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h 
b/llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h
new file mode 100644
index 00..73624015e37d9d
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h
@@ -0,0 +1,25 @@
+//===- llvm/CodeGen/RegUsageInfoPropagate.h -*- C++ 
-*-===//
+//
+// 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 LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
+#define LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+
+class RegUsageInfoPropagationPass
+: public PassInfoMixin {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+MachineFunctionAnalysisManager &MFAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
diff --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index c881dcd57006db..a9ab739af33ad8 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -258,7 +258,7 @@ void initializeRegAllocScoringPass(PassRegistry &);
 void initializeRegBankSelectPass(PassRegistry &);
 void initializeRegToMemWrapperPassPass(PassRegistry &);
 void initializeRegUsageInfoCollectorLegacyPass(PassRegistry &);
-void initializeRegUsageInfoPropagationPass(PassRegistry &);
+void initializeRegUsageInfoPropagationLegacyPass(PassRegistry &);
 void initializeRegionInfoPassPass(PassRegistry &);
 void initializeRegionOnlyPrinterPass(PassRegistry &);
 void initializeRegionOnlyViewerPass(PassRegistry &);
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h 
b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 14fcf9d79fbc23..a64ecd69e55913 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -54,6 +54,7 @@
 #include "llvm/CodeGen/PreISelIntrinsicLowering.h"
 #include "llvm/CodeGen/RegAllocFast.h"
 #include "llvm/CodeGen/RegUsageInfoCollector.h"
+#include "llvm/CodeGen/RegUsageInfoPropagate.h"
 #include "llvm/CodeGen/RegisterUsageInfo.h"
 #include "llvm/CodeGen/ReplaceWithVeclib.h"
 #include "llvm/CodeGen/SafeStack.h"
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def 
b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 36d17b713639c1..099b009a2b3fee 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -156,6 +156,7 @@ MACHINE_FUNCTION_PASS("print",
 MACHINE_FUNCTION_PASS("print", SlotIndexesPrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("print", VirtRegMapPrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
+MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass())
 MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
   RequireAllMachineFunctionPropertiesPass())
 MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass())
@@ -250,7 +251,6 @@ DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", 
PrologEpilogCodeInserterPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass)
 DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
-DUMMY_MACHINE_FUNCTION_PASS("reg-usage-propagation", 
RegUsageInfoPropagationPass)
 DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
 DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
 DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass)
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 76b74ea4e6fe0b..20d1417193a864 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -114,7 +114,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeRAGreedyPass(Registry);
   initializeRegAllocFastPass(Registry);
   initializeRegUsageInfoCollecto

[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegUsageInfoPropagation pass to NPM (PR #114010)

2024-10-29 Thread Akshat Oke via llvm-branch-commits

optimisan wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/114010?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#114010** https://app.graphite.dev/github/pr/llvm/llvm-project/114010?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈
* **#113874** https://app.graphite.dev/github/pr/llvm/llvm-project/113874?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#113873** https://app.graphite.dev/github/pr/llvm/llvm-project/113873?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`

This stack of pull requests is managed by Graphite. https://stacking.dev/?utm_source=stack-comment";>Learn more about 
stacking.


 Join @optimisan and the rest of your teammates on https://graphite.dev?utm-source=stack-comment";>https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="11px" height="11px"/> Graphite
  

https://github.com/llvm/llvm-project/pull/114010
___
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/19.x: [AVR][MC] Fix incorrect range of relative jumps (#109124) (PR #113969)

2024-10-29 Thread Jianjian Guan via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/113969
___
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] [llvm] [LLVM] [Clang] Backport "Support for Gentoo `*t64` triples (64-bit time_t ABIs)" (PR #112364)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/112364

>From 21ed37e3e725a7f58c2eb347519e500ebddb57ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 
Date: Mon, 14 Oct 2024 13:18:04 +0200
Subject: [PATCH] [LLVM] [Clang] Backport "Support for Gentoo `*t64` triples
 (64-bit time_t ABIs)"

This is a backport of 387b37af1aabf325e9be844361564dfad8d45c75 for 19.x,
adjusted to add new Triple::EnvironmentType members at the end to avoid
breaking backwards ABI compatibility.

Gentoo is planning to introduce a `*t64` suffix for triples that will be
used by 32-bit platforms that use 64-bit `time_t`. Add support for
parsing and accepting these triples, and while at it make clang
automatically enable the necessary glibc feature macros when this suffix
is used.
---
 clang/lib/Basic/Targets/ARM.cpp|  2 +
 clang/lib/Basic/Targets/OSTargets.h|  4 ++
 clang/lib/CodeGen/CodeGenModule.cpp|  5 +-
 clang/lib/CodeGen/Targets/ARM.cpp  |  3 ++
 clang/lib/Driver/Driver.cpp|  5 +-
 clang/lib/Driver/ToolChains/Arch/ARM.cpp   |  7 +++
 clang/lib/Driver/ToolChains/Gnu.cpp|  2 +
 clang/lib/Driver/ToolChains/Linux.cpp  |  1 +
 clang/test/Preprocessor/time64.c   | 12 +
 llvm/include/llvm/TargetParser/Triple.h| 35 ++---
 llvm/lib/Target/ARM/ARMSubtarget.h |  4 +-
 llvm/lib/Target/ARM/ARMTargetMachine.cpp   |  2 +
 llvm/lib/Target/ARM/ARMTargetMachine.h |  1 +
 llvm/lib/TargetParser/ARMTargetParser.cpp  |  3 ++
 llvm/lib/TargetParser/Triple.cpp   |  6 +++
 llvm/unittests/TargetParser/TripleTest.cpp | 58 ++
 16 files changed, 138 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/Preprocessor/time64.c

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 7423626d7c3cbf..e55feedbd5c6f9 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -311,7 +311,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
 switch (Triple.getEnvironment()) {
 case llvm::Triple::Android:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
 case llvm::Triple::OpenHOS:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 5f27c3469f861d..357c1965057c9b 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -337,6 +337,10 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
   Builder.defineMacro("_GNU_SOURCE");
 if (this->HasFloat128)
   Builder.defineMacro("__FLOAT128__");
+if (Triple.isTime64ABI()) {
+  Builder.defineMacro("_FILE_OFFSET_BITS", "64");
+  Builder.defineMacro("_TIME_BITS", "64");
+}
   }
 
 public:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cf5e29e5a3db8d..8d9beab9fa7f88 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -177,10 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (ABIStr == "aapcs16")
   Kind = ARMABIKind::AAPCS16_VFP;
 else if (CodeGenOpts.FloatABI == "hard" ||
- (CodeGenOpts.FloatABI != "soft" &&
-  (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
-   Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
-   Triple.getEnvironment() == llvm::Triple::EABIHF)))
+ (CodeGenOpts.FloatABI != "soft" && Triple.isHardFloatABI()))
   Kind = ARMABIKind::AAPCS_VFP;
 
 return createARMTargetCodeGenInfo(CGM, Kind);
diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index d032b88d7683cd..457d761039a08d 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
 case llvm::Triple::EABI:
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
   return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
 switch (getTarget().getTriple().getEnvironment()) {
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABIHF:
   return true;
 default:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8e44d5afa40e05..ecae475f75da00 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -602,7 +602,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {

[llvm-branch-commits] [clang] release/19.x: [clang-format] Handle template opener/closer in braced list (#112494) (PR #112815)

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

github-actions[bot] wrote:

@owenca (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.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/112815
___
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] [Serialization] Handle uninitialized type constraints (PR #113182)

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

cor3ntin wrote:

@tru Yes! (This fixes a few regression that are addressed in main in using a 
much more intrusive set of changes)

https://github.com/llvm/llvm-project/pull/113182
___
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] [Serialization] Handle uninitialized type constraints (PR #113182)

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

github-actions[bot] wrote:

@falbrechtskirchinger (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.  When you are done, 
please add the release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/113182
___
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] ab51ecc - [Serialization] Handle uninitialized type constraints

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

Author: Florian Albrechtskirchinger
Date: 2024-10-29T11:09:39+01:00
New Revision: ab51eccf88f5321e7c60591c5546b254b6afab99

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

LOG: [Serialization] Handle uninitialized type constraints

The ASTWriter currently assumes template type constraints to be
initialized ((bool)getTypeConstraint() == hasTypeConstraint()). Issues
#99036 and #109354 identified a scenario where this assertion is
violated.

This patch removes the assumption and adds another boolean to the
serialization, to explicitly encode whether the type constraint has been
initialized.

The same issue was incidentally fixed on the main branch by #79.
This solution avoids backporting #79 and its dependencies.

Added: 


Modified: 
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/PCH/cxx2a-constraints-crash.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index c118f3818467d9..154acdfbe03276 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2665,7 +2665,8 @@ void 
ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
 
   D->setDeclaredWithTypename(Record.readInt());
 
-  if (D->hasTypeConstraint()) {
+  const bool TypeConstraintInitialized = Record.readBool();
+  if (TypeConstraintInitialized && D->hasTypeConstraint()) {
 ConceptReference *CR = nullptr;
 if (Record.readBool())
   CR = Record.readConceptReference();

diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 8a4ca54349e38f..ff1334340874b2 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1880,7 +1880,7 @@ void 
ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   Record.push_back(D->wasDeclaredWithTypename());
 
   const TypeConstraint *TC = D->getTypeConstraint();
-  assert((bool)TC == D->hasTypeConstraint());
+  Record.push_back(/*TypeConstraintInitialized=*/TC != nullptr);
   if (TC) {
 auto *CR = TC->getConceptReference();
 Record.push_back(CR != nullptr);
@@ -1898,7 +1898,7 @@ void 
ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   if (OwnsDefaultArg)
 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
 
-  if (!TC && !OwnsDefaultArg &&
+  if (!D->hasTypeConstraint() && !OwnsDefaultArg &&
   D->getDeclContext() == D->getLexicalDeclContext() &&
   !D->isInvalidDecl() && !D->hasAttrs() &&
   !D->isTopLevelDeclInObjCContainer() && !D->isImplicit() &&
@@ -2561,6 +2561,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   // TemplateTypeParmDecl
   Abv->Add(
   BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // wasDeclaredWithTypename
+  Abv->Add(BitCodeAbbrevOp(0));// TypeConstraintInitialized
   Abv->Add(BitCodeAbbrevOp(0));// OwnsDefaultArg
   DeclTemplateTypeParmAbbrev = Stream.EmitAbbrev(std::move(Abv));
 

diff  --git a/clang/test/PCH/cxx2a-constraints-crash.cpp 
b/clang/test/PCH/cxx2a-constraints-crash.cpp
index 637c55f0c879c9..6126a0509fa4a9 100644
--- a/clang/test/PCH/cxx2a-constraints-crash.cpp
+++ b/clang/test/PCH/cxx2a-constraints-crash.cpp
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t
-// RUN: %clang_cc1 -std=c++2a -include-pch %t -verify %s
-
-// expected-no-diagnostics
+// RUN: %clang_cc1 -std=c++2a -fallow-pch-with-compiler-errors -emit-pch -o %t 
%s -verify
+// RUN: %clang_cc1 -std=c++2a -fallow-pch-with-compiler-errors -include-pch %t 
%s -verify
 
 #ifndef HEADER
 #define HEADER
@@ -27,3 +25,12 @@ int main() {
 }
 
 #endif
+
+namespace GH99036 {
+
+template 
+concept C; // expected-error {{expected '='}}
+
+template  void f(); // expected-error {{unknown type name 'C'}}
+
+} // namespace GH99036



___
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] [Serialization] Handle uninitialized type constraints (PR #113182)

2024-10-29 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/113182

>From ab51eccf88f5321e7c60591c5546b254b6afab99 Mon Sep 17 00:00:00 2001
From: Florian Albrechtskirchinger 
Date: Mon, 21 Oct 2024 12:24:58 +0200
Subject: [PATCH] [Serialization] Handle uninitialized type constraints

The ASTWriter currently assumes template type constraints to be
initialized ((bool)getTypeConstraint() == hasTypeConstraint()). Issues
#99036 and #109354 identified a scenario where this assertion is
violated.

This patch removes the assumption and adds another boolean to the
serialization, to explicitly encode whether the type constraint has been
initialized.

The same issue was incidentally fixed on the main branch by #79.
This solution avoids backporting #79 and its dependencies.
---
 clang/lib/Serialization/ASTReaderDecl.cpp  |  3 ++-
 clang/lib/Serialization/ASTWriterDecl.cpp  |  5 +++--
 clang/test/PCH/cxx2a-constraints-crash.cpp | 15 +++
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index c118f3818467d9..154acdfbe03276 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2665,7 +2665,8 @@ void 
ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
 
   D->setDeclaredWithTypename(Record.readInt());
 
-  if (D->hasTypeConstraint()) {
+  const bool TypeConstraintInitialized = Record.readBool();
+  if (TypeConstraintInitialized && D->hasTypeConstraint()) {
 ConceptReference *CR = nullptr;
 if (Record.readBool())
   CR = Record.readConceptReference();
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 8a4ca54349e38f..ff1334340874b2 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1880,7 +1880,7 @@ void 
ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   Record.push_back(D->wasDeclaredWithTypename());
 
   const TypeConstraint *TC = D->getTypeConstraint();
-  assert((bool)TC == D->hasTypeConstraint());
+  Record.push_back(/*TypeConstraintInitialized=*/TC != nullptr);
   if (TC) {
 auto *CR = TC->getConceptReference();
 Record.push_back(CR != nullptr);
@@ -1898,7 +1898,7 @@ void 
ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   if (OwnsDefaultArg)
 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
 
-  if (!TC && !OwnsDefaultArg &&
+  if (!D->hasTypeConstraint() && !OwnsDefaultArg &&
   D->getDeclContext() == D->getLexicalDeclContext() &&
   !D->isInvalidDecl() && !D->hasAttrs() &&
   !D->isTopLevelDeclInObjCContainer() && !D->isImplicit() &&
@@ -2561,6 +2561,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   // TemplateTypeParmDecl
   Abv->Add(
   BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // wasDeclaredWithTypename
+  Abv->Add(BitCodeAbbrevOp(0));// TypeConstraintInitialized
   Abv->Add(BitCodeAbbrevOp(0));// OwnsDefaultArg
   DeclTemplateTypeParmAbbrev = Stream.EmitAbbrev(std::move(Abv));
 
diff --git a/clang/test/PCH/cxx2a-constraints-crash.cpp 
b/clang/test/PCH/cxx2a-constraints-crash.cpp
index 637c55f0c879c9..6126a0509fa4a9 100644
--- a/clang/test/PCH/cxx2a-constraints-crash.cpp
+++ b/clang/test/PCH/cxx2a-constraints-crash.cpp
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t
-// RUN: %clang_cc1 -std=c++2a -include-pch %t -verify %s
-
-// expected-no-diagnostics
+// RUN: %clang_cc1 -std=c++2a -fallow-pch-with-compiler-errors -emit-pch -o %t 
%s -verify
+// RUN: %clang_cc1 -std=c++2a -fallow-pch-with-compiler-errors -include-pch %t 
%s -verify
 
 #ifndef HEADER
 #define HEADER
@@ -27,3 +25,12 @@ int main() {
 }
 
 #endif
+
+namespace GH99036 {
+
+template 
+concept C; // expected-error {{expected '='}}
+
+template  void f(); // expected-error {{unknown type name 'C'}}
+
+} // namespace GH99036

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


  1   2   >