[llvm-branch-commits] [mlir] [draft] Dialect Conversion without Rollback (PR #93412)

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


@@ -1053,3 +1055,241 @@ LogicalResult mlir::applyOpPatternsAndFold(
   });
   return converged;
 }
+
+//===--===//
+// One-Shot Dialect Conversion Infrastructure
+//===--===//
+
+namespace {
+/// A conversion rewriter for the One-Shot Dialect Conversion. This rewriter
+/// immediately materializes all IR changes. It derives from
+/// `ConversionPatternRewriter` so that the existing conversion patterns can
+/// be used with the One-Shot Dialect Conversion.
+class OneShotConversionPatternRewriter : public ConversionPatternRewriter {
+public:
+  OneShotConversionPatternRewriter(MLIRContext *ctx)
+  : ConversionPatternRewriter(ctx) {}
+
+  bool canRecoverFromRewriteFailure() const override { return false; }
+
+  void replaceOp(Operation *op, ValueRange newValues) override;
+
+  void replaceOp(Operation *op, Operation *newOp) override {
+replaceOp(op, newOp->getResults());
+  }
+
+  void eraseOp(Operation *op) override { PatternRewriter::eraseOp(op); }
+
+  void eraseBlock(Block *block) override { PatternRewriter::eraseBlock(block); 
}
+
+  void inlineBlockBefore(Block *source, Block *dest, Block::iterator before,
+ ValueRange argValues = std::nullopt) override {
+PatternRewriter::inlineBlockBefore(source, dest, before, argValues);
+  }
+  using PatternRewriter::inlineBlockBefore;
+
+  void startOpModification(Operation *op) override {
+PatternRewriter::startOpModification(op);
+  }
+
+  void finalizeOpModification(Operation *op) override {
+PatternRewriter::finalizeOpModification(op);
+  }
+
+  void cancelOpModification(Operation *op) override {
+PatternRewriter::cancelOpModification(op);
+  }
+
+  void setCurrentTypeConverter(const TypeConverter *converter) override {
+typeConverter = converter;
+  }
+
+  const TypeConverter *getCurrentTypeConverter() const override {
+return typeConverter;
+  }
+
+  LogicalResult getAdapterOperands(StringRef valueDiagTag,
+   std::optional inputLoc,
+   ValueRange values,
+   SmallVector &remapped) override;
+
+private:
+  /// Build an unrealized_conversion_cast op or look it up in the cache.
+  Value buildUnrealizedConversionCast(Location loc, Type type, Value value);
+
+  /// The current type converter.
+  const TypeConverter *typeConverter;
+
+  /// A cache for unrealized_conversion_casts. To ensure that identical casts
+  /// are not built multiple times.
+  DenseMap, Value> castCache;
+};
+
+void OneShotConversionPatternRewriter::replaceOp(Operation *op,
+ ValueRange newValues) {
+  assert(op->getNumResults() == newValues.size());
+  for (auto [orig, repl] : llvm::zip_equal(op->getResults(), newValues)) {
+if (orig.getType() != repl.getType()) {
+  // Type mismatch: insert unrealized_conversion cast.
+  replaceAllUsesWith(orig, buildUnrealizedConversionCast(
+   op->getLoc(), orig.getType(), repl));
+} else {
+  // Same type: use replacement value directly.
+  replaceAllUsesWith(orig, repl);
+}
+  }
+  eraseOp(op);
+}
+
+Value OneShotConversionPatternRewriter::buildUnrealizedConversionCast(
+Location loc, Type type, Value value) {
+  auto it = castCache.find(std::make_pair(value, type));
+  if (it != castCache.end())
+return it->second;
+
+  // Insert cast at the beginning of the block (for block arguments) or right
+  // after the defining op.
+  OpBuilder::InsertionGuard g(*this);
+  Block *insertBlock = value.getParentBlock();
+  Block::iterator insertPt = insertBlock->begin();
+  if (OpResult inputRes = dyn_cast(value))
+insertPt = ++inputRes.getOwner()->getIterator();
+  setInsertionPoint(insertBlock, insertPt);
+  auto castOp = create(loc, type, value);
+  castCache[std::make_pair(value, type)] = castOp.getOutputs()[0];
+  return castOp.getOutputs()[0];
+}
+
+class ConversionPatternRewriteDriver : public GreedyPatternRewriteDriver {

matthias-springer wrote:

"One Shot" may be a misnomer. I really meant "no rollback".

I am reluctant to build something that is not compatible with the large number 
of existing conversion patterns. I would rather gradually improve the situation 
in way where users have a painless way to migrate to the new driver. Otherwise, 
is anybody going to use the new infrastructure?


https://github.com/llvm/llvm-project/pull/93412
___
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] [draft] Dialect Conversion without Rollback (PR #93412)

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


@@ -1053,3 +1055,241 @@ LogicalResult mlir::applyOpPatternsAndFold(
   });
   return converged;
 }
+
+//===--===//
+// One-Shot Dialect Conversion Infrastructure
+//===--===//
+
+namespace {
+/// A conversion rewriter for the One-Shot Dialect Conversion. This rewriter
+/// immediately materializes all IR changes. It derives from
+/// `ConversionPatternRewriter` so that the existing conversion patterns can
+/// be used with the One-Shot Dialect Conversion.
+class OneShotConversionPatternRewriter : public ConversionPatternRewriter {
+public:
+  OneShotConversionPatternRewriter(MLIRContext *ctx)
+  : ConversionPatternRewriter(ctx) {}
+
+  bool canRecoverFromRewriteFailure() const override { return false; }
+
+  void replaceOp(Operation *op, ValueRange newValues) override;
+
+  void replaceOp(Operation *op, Operation *newOp) override {
+replaceOp(op, newOp->getResults());
+  }
+
+  void eraseOp(Operation *op) override { PatternRewriter::eraseOp(op); }
+
+  void eraseBlock(Block *block) override { PatternRewriter::eraseBlock(block); 
}
+
+  void inlineBlockBefore(Block *source, Block *dest, Block::iterator before,
+ ValueRange argValues = std::nullopt) override {
+PatternRewriter::inlineBlockBefore(source, dest, before, argValues);
+  }
+  using PatternRewriter::inlineBlockBefore;
+
+  void startOpModification(Operation *op) override {
+PatternRewriter::startOpModification(op);
+  }
+
+  void finalizeOpModification(Operation *op) override {
+PatternRewriter::finalizeOpModification(op);
+  }
+
+  void cancelOpModification(Operation *op) override {
+PatternRewriter::cancelOpModification(op);
+  }
+
+  void setCurrentTypeConverter(const TypeConverter *converter) override {
+typeConverter = converter;
+  }
+
+  const TypeConverter *getCurrentTypeConverter() const override {
+return typeConverter;
+  }
+
+  LogicalResult getAdapterOperands(StringRef valueDiagTag,
+   std::optional inputLoc,
+   ValueRange values,
+   SmallVector &remapped) override;
+
+private:
+  /// Build an unrealized_conversion_cast op or look it up in the cache.
+  Value buildUnrealizedConversionCast(Location loc, Type type, Value value);
+
+  /// The current type converter.
+  const TypeConverter *typeConverter;
+
+  /// A cache for unrealized_conversion_casts. To ensure that identical casts
+  /// are not built multiple times.
+  DenseMap, Value> castCache;
+};
+
+void OneShotConversionPatternRewriter::replaceOp(Operation *op,
+ ValueRange newValues) {
+  assert(op->getNumResults() == newValues.size());
+  for (auto [orig, repl] : llvm::zip_equal(op->getResults(), newValues)) {
+if (orig.getType() != repl.getType()) {
+  // Type mismatch: insert unrealized_conversion cast.
+  replaceAllUsesWith(orig, buildUnrealizedConversionCast(
+   op->getLoc(), orig.getType(), repl));
+} else {
+  // Same type: use replacement value directly.
+  replaceAllUsesWith(orig, repl);
+}
+  }
+  eraseOp(op);
+}
+
+Value OneShotConversionPatternRewriter::buildUnrealizedConversionCast(
+Location loc, Type type, Value value) {
+  auto it = castCache.find(std::make_pair(value, type));
+  if (it != castCache.end())
+return it->second;
+
+  // Insert cast at the beginning of the block (for block arguments) or right
+  // after the defining op.
+  OpBuilder::InsertionGuard g(*this);
+  Block *insertBlock = value.getParentBlock();
+  Block::iterator insertPt = insertBlock->begin();
+  if (OpResult inputRes = dyn_cast(value))
+insertPt = ++inputRes.getOwner()->getIterator();
+  setInsertionPoint(insertBlock, insertPt);
+  auto castOp = create(loc, type, value);
+  castCache[std::make_pair(value, type)] = castOp.getOutputs()[0];
+  return castOp.getOutputs()[0];
+}
+
+class ConversionPatternRewriteDriver : public GreedyPatternRewriteDriver {

matthias-springer wrote:

What's the main issue that you see with a worklist-based approach? Imo, the 
main complexity of the dialect conversion is because of rollback and late 
materialization. I never had issues issues debugging a greedy pattern rewrite 
with `-debug` so far.

https://github.com/llvm/llvm-project/pull/93412
___
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] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

2024-05-29 Thread Ilya Biryukov via llvm-branch-commits

https://github.com/ilya-biryukov approved this pull request.

Went through the changes one more time and they definitely LGTM.
See the two small comments left from my side about documentation and release 
notes, I think they're worth fixing before landing this. Otherwise, let's ship 
it!

https://github.com/llvm/llvm-project/pull/93433
___
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] b054716 - Revert "[Support] Remove terminfo dependency (#92865)"

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

Author: Michael Buch
Date: 2024-05-29T16:11:31+01:00
New Revision: b054716c51465ca82c87934e7f9970128a3f3562

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

LOG: Revert "[Support] Remove terminfo dependency (#92865)"

This reverts commit 6bf450c7a60fa62c642e39836566da94bb9bbc91.

Added: 
llvm/cmake/modules/FindTerminfo.cmake
llvm/utils/gn/build/libs/terminfo/BUILD.gn
llvm/utils/gn/build/libs/terminfo/enable.gni

Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/cmake/caches/Fuchsia.cmake
clang/cmake/caches/VectorEngine.cmake
clang/utils/analyzer/entrypoint.py
compiler-rt/cmake/config-ix.cmake
compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
compiler-rt/lib/xray/tests/CMakeLists.txt
lldb/docs/resources/build.rst
lldb/source/Core/CMakeLists.txt
llvm/CMakeLists.txt
llvm/cmake/config-ix.cmake
llvm/cmake/modules/LLVMConfig.cmake.in
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/Config/config.h.cmake
llvm/lib/Support/CMakeLists.txt
llvm/lib/Support/Unix/Process.inc
llvm/utils/gn/README.rst
llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn
utils/bazel/.bazelrc
utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
utils/bazel/llvm_configs/config.h.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 66e764968e85ce..d5546e20873b3c 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -19,6 +19,7 @@ set(LLVM_ENABLE_LLD ON CACHE BOOL "")
 set(LLVM_ENABLE_LTO ON CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
+set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
 set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")

diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index 4d3af3ad3f4031..30a3b9116a461f 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -12,6 +12,7 @@ set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
 set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
 set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
@@ -33,6 +34,7 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
   LibXml2_ROOT
   LLVM_ENABLE_CURL
   LLVM_ENABLE_HTTPLIB
+  LLVM_ENABLE_TERMINFO
   LLVM_ENABLE_LIBEDIT
   CURL_ROOT
   OpenSSL_ROOT
@@ -45,6 +47,11 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
   CURSES_LIBRARIES
   PANEL_LIBRARIES
 
+  # Deprecated
+  Terminfo_ROOT
+
+  Terminfo_LIBRARIES
+
   # Deprecated
   LibEdit_ROOT
 

diff  --git a/clang/cmake/caches/VectorEngine.cmake 
b/clang/cmake/caches/VectorEngine.cmake
index b429fb0997d7a0..2f968a21cc407e 100644
--- a/clang/cmake/caches/VectorEngine.cmake
+++ b/clang/cmake/caches/VectorEngine.cmake
@@ -13,7 +13,9 @@
 #   ninja
 #
 
-# Disable ZLIB, and ZSTD for VE since there is no pre-compiled libraries.
+# Disable TERMINFO, ZLIB, and ZSTD for VE since there is no pre-compiled
+# libraries.
+set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "")
 

diff  --git a/clang/utils/analyzer/entrypoint.py 
b/clang/utils/analyzer/entrypoint.py
index 4deb42db0a0b1f..ff877060bad69e 100644
--- a/clang/utils/analyzer/entrypoint.py
+++ b/clang/utils/analyzer/entrypoint.py
@@ -54,7 +54,7 @@ def is_cmake_needed():
 "cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "
 "-DCMAKE_INSTALL_PREFIX=/analyzer -DLLVM_TARGETS_TO_BUILD=X86 "
 '-DLLVM_ENABLE_PROJECTS="clang;openmp" -DLLVM_BUILD_RUNTIME=OFF '
-"-DCLANG_ENABLE_ARCMT=OFF "
+"-DLLVM_ENABLE_TERMINFO=OFF -DCLANG_ENABLE_ARCMT=OFF "
 "-DCLANG_ENABLE_STATIC_ANALYZER=ON"
 )
 

diff  --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index bddaa37579fd7b..42edbe15edafb5 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -182,6 +182,21 @@ check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
 check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
 check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)
 
+# Look for terminfo library, used in unittests that depend on LLVMSupport.
+if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
+  set(MAYBE_REQUIRED REQUIRED)
+else()
+  set(MAYBE_REQUIRED)

[llvm-branch-commits] [clang] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

2024-05-29 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93433

>From 2f2aa69d1b1e421214097cb2595910da15a6c6f2 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 25 May 2024 13:57:39 -0300
Subject: [PATCH] [clang] Preserve Qualifiers and type sugar in TemplateNames

This patch improves the preservation of qualifiers
and loss of type sugar in TemplateNames.

This problem is analogous to https://reviews.llvm.org/D112374
and this patch takes a very similar approach to that patch,
except the impact here is much lesser.

When a TemplateName was written bare, without qualifications,
we wouldn't produce a QualifiedTemplate which could be used
to disambiguate it from a Canonical TemplateName. This had
effects in the TemplateName printer, which had workarounds
to deal with this, and wouldn't print the TemplateName
as-written in most situations.

There are also some related fixes to help preserve this type
sugar along the way into diagnostics, so that this patch can
be properly tested.

- Fix dropping the template keyword.
- Fix type deduction to preserve sugar in TST TemplateNames.
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/AST/TemplateName.h| 19 +++---
 clang/include/clang/Sema/Sema.h   |  3 +
 clang/lib/AST/ASTContext.cpp  | 16 ++---
 clang/lib/AST/DeclTemplate.cpp|  7 +-
 clang/lib/AST/ODRHash.cpp |  9 ++-
 clang/lib/AST/TemplateBase.cpp|  2 +-
 clang/lib/AST/TemplateName.cpp| 64 +--
 clang/lib/AST/TextNodeDumper.cpp  |  4 +-
 clang/lib/AST/Type.cpp|  3 +-
 clang/lib/AST/TypePrinter.cpp |  4 +-
 clang/lib/Sema/SemaDecl.cpp   | 15 ++---
 clang/lib/Sema/SemaDeclCXX.cpp| 12 ++--
 clang/lib/Sema/SemaExpr.cpp   |  4 +-
 clang/lib/Sema/SemaExprMember.cpp |  3 +-
 clang/lib/Sema/SemaTemplate.cpp   | 25 +---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 62 +-
 clang/lib/Sema/SemaType.cpp   | 14 ++--
 clang/lib/Sema/TreeTransform.h|  8 +--
 clang/test/AST/ast-dump-ctad-alias.cpp|  6 +-
 clang/test/AST/ast-dump-decl.cpp  |  8 +--
 clang/test/AST/ast-dump-expr.cpp  |  2 +-
 clang/test/AST/ast-dump-template-decls.cpp|  6 +-
 clang/test/AST/ast-dump-template-name.cpp |  4 +-
 clang/test/AST/ast-dump-using-template.cpp|  6 +-
 clang/test/CXX/drs/cwg1xx.cpp |  4 +-
 .../over.match.oper/p3-2a.cpp |  4 +-
 .../temp.deduct/temp.deduct.type/p9-0x.cpp|  4 +-
 clang/test/Index/print-type.cpp   |  2 +-
 clang/test/OpenMP/declare_mapper_messages.cpp |  2 +-
 .../Parser/cxx-template-template-recovery.cpp |  4 +-
 .../cxx1y-variable-templates_in_class.cpp | 10 +--
 clang/test/SemaTemplate/cwg2398.cpp   |  2 +-
 .../instantiate-requires-expr.cpp |  4 +-
 .../nested-implicit-deduction-guides.cpp  |  2 +-
 clang/unittests/AST/TemplateNameTest.cpp  | 40 ++--
 .../map/map.cons/deduct.verify.cpp| 24 +++
 .../multimap/multimap.cons/deduct.verify.cpp  | 22 +++
 .../multiset/multiset.cons/deduct.verify.cpp  | 10 +--
 .../set/set.cons/deduct.verify.cpp| 10 +--
 .../priqueue.cons/deduct.verify.cpp   | 10 +--
 .../queue/queue.cons/deduct.verify.cpp|  6 +-
 .../stack/stack.cons/deduct.verify.cpp|  6 +-
 .../array/array.cons/deduct.verify.cpp|  2 +-
 .../deque/deque.cons/deduct.verify.cpp|  2 +-
 .../forwardlist.cons/deduct.verify.cpp|  2 +-
 .../list/list.cons/deduct.verify.cpp  |  2 +-
 .../vector/vector.cons/deduct.verify.cpp  |  2 +-
 .../unord.map.cnstr/deduct.verify.cpp | 16 ++---
 .../unord.multimap.cnstr/deduct.verify.cpp| 16 ++---
 .../unord.multiset.cnstr/deduct.verify.cpp| 16 ++---
 .../unord.set.cnstr/deduct.verify.cpp | 16 ++---
 .../range.adaptors/range.join/ctad.verify.cpp |  2 +-
 .../re.regex.construct/deduct.verify.cpp  |  4 +-
 .../optional.object.ctor/deduct.verify.cpp|  2 +-
 55 files changed, 316 insertions(+), 240 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e1c6d55eeeacd..44035f48cb3f9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -819,6 +819,8 @@ Bug Fixes to AST Handling
 - Clang now properly preserves ``FoundDecls`` within a ``ConceptReference``. 
(#GH82628)
 - The presence of the ``typename`` keyword is now stored in 
``TemplateTemplateParmDecl``.
 - Fixed malformed AST generated for anonymous union access in templates. 
(#GH90842)
+- Improved preservation of qualifiers and sugar in `TemplateNames`, including
+  template keyword.
 
 Miscellaneous Bug Fixes
 ^^^
diff --git a/clang/include/clang/AST/TemplateName.h 
b/c

[llvm-branch-commits] [clang] [libcxx] [clang] fix printing of canonical template template parameters take 2 (PR #93448)

2024-05-29 Thread Vlad Serebrennikov via llvm-branch-commits

https://github.com/Endilll commented:

Changes to `Sema.h` and DR test suite look good.

https://github.com/llvm/llvm-project/pull/93448
___
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 printing of canonical template template parameters take 2 (PR #93448)

2024-05-29 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/93448

>From 62eed81cb51c1e1a150bb4f5aad8628fa178b68c Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 27 May 2024 05:51:18 -0300
Subject: [PATCH] [clang] fix printing of canonical template template
 parameters take 2

Since they can also occur as the template name of
template specializations, handle them from TemplateName
printing instead of TemplateArgument.
---
 clang/lib/AST/TemplateBase.cpp  | 11 +--
 clang/lib/AST/TemplateName.cpp  | 14 ++
 clang/test/SemaTemplate/deduction-guide.cpp | 10 +-
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 6d3c843cfd29e..46f7b79b272ef 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -544,16 +544,7 @@ void TemplateArgument::print(const PrintingPolicy &Policy, 
raw_ostream &Out,
 break;
 
   case Template: {
-TemplateName TN = getAsTemplate();
-if (const auto *TD = TN.getAsTemplateDecl();
-TD && TD->getDeclName().isEmpty()) {
-  assert(isa(TD) &&
- "Unexpected anonymous template");
-  const auto *TTP = cast(TD);
-  Out << "template-parameter-" << TTP->getDepth() << "-" << 
TTP->getIndex();
-} else {
-  TN.print(Out, Policy);
-}
+getAsTemplate().print(Out, Policy);
 break;
   }
 
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 3aae998eceeb0..3dbdad92813f6 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -292,6 +292,14 @@ void TemplateName::Profile(llvm::FoldingSetNodeID &ID) {
 
 void TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy,
  Qualified Qual) const {
+  auto handleAnonymousTTP = [](TemplateDecl *TD, raw_ostream &OS) {
+if (TemplateTemplateParmDecl *TTP = dyn_cast(TD);
+TTP && TTP->getIdentifier() == nullptr) {
+  OS << "template-parameter-" << TTP->getDepth() << "-" << TTP->getIndex();
+  return true;
+}
+return false;
+  };
   if (NameKind Kind = getKind();
   Kind == TemplateName::Template || Kind == TemplateName::UsingTemplate) {
 // After `namespace ns { using std::vector }`, what is the fully-qualified
@@ -304,6 +312,8 @@ void TemplateName::print(raw_ostream &OS, const 
PrintingPolicy &Policy,
 // names more often than to export them, thus using the original name is
 // most useful in this case.
 TemplateDecl *Template = getAsTemplateDecl();
+if (handleAnonymousTTP(Template, OS))
+  return;
 if (Qual == Qualified::None)
   OS << *Template;
 else
@@ -320,6 +330,10 @@ void TemplateName::print(raw_ostream &OS, const 
PrintingPolicy &Policy,
Underlying.getKind() == TemplateName::UsingTemplate);
 
 TemplateDecl *UTD = Underlying.getAsTemplateDecl();
+
+if (handleAnonymousTTP(UTD, OS))
+  return;
+
 if (IdentifierInfo *II = UTD->getIdentifier();
 Policy.CleanUglifiedParameters && II &&
 isa(UTD))
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 96b4cd9622a24..100b580fe9f02 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -315,19 +315,19 @@ namespace TTP {
 // CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T{{$}}
 // CHECK-NEXT:  |-TemplateTemplateParmDecl {{.+}} depth 0 index 1 TT{{$}}
 // CHECK-NEXT:  | `-TemplateTypeParmDecl {{.+}} class depth 1 index 0{{$}}
-// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} 'auto () -> B'{{$}}
-// CHECK-NEXT:  | `-ParmVarDecl {{.+}} ''{{$}}
+// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} 'auto 
(template-parameter-0-1) -> B'{{$}}
+// CHECK-NEXT:  | `-ParmVarDecl {{.+}} 'template-parameter-0-1'{{$}}
 // CHECK-NEXT:  `-CXXDeductionGuideDecl {{.+}} 'auto (A) -> TTP::B'
 // CHECK-NEXT:|-TemplateArgument type 'int'
 // CHECK-NEXT:| `-BuiltinType {{.+}} 'int'{{$}}
 // CHECK-NEXT:|-TemplateArgument template 'TTP::A'{{$}}
 // CHECK-NEXT:| `-ClassTemplateDecl {{.+}} A{{$}}
 // CHECK-NEXT:`-ParmVarDecl {{.+}} 'A':'TTP::A'{{$}}
-// CHECK-NEXT:  FunctionProtoType {{.+}} 'auto () -> B' dependent 
trailing_return cdecl{{$}}
+// CHECK-NEXT:  FunctionProtoType {{.+}} 'auto (template-parameter-0-1) -> 
B' dependent trailing_return cdecl{{$}}
 // CHECK-NEXT:  |-InjectedClassNameType {{.+}} 'B' dependent{{$}}
 // CHECK-NEXT:  | `-CXXRecord {{.+}} 'B'{{$}}
-// CHECK-NEXT:  `-ElaboratedType {{.+}} '' sugar dependent{{$}}
-// CHECK-NEXT:`-TemplateSpecializationType {{.+}} '' dependent {{$}}
+// CHECK-NEXT:  `-ElaboratedType {{.+}} 'template-parameter-0-1' sugar 
dependent{{$}}
+// CHECK-NEXT:`-TemplateSpecializationType {{.+}} 
'template-parameter-0-1' dependent template-parameter-0-1{{$}}
 // CHECK-NEXT:  `-TemplateArgument type 'T':'type-p

[llvm-branch-commits] [clang] [clang] fix printing of canonical template template parameters take 2 (PR #93448)

2024-05-29 Thread Matheus Izvekov via llvm-branch-commits

mizvekov wrote:

Sorry, there were no libcxx or Sema.h changes, it was a GitHub issue, I just 
rebased a PR stacked below this one.

https://github.com/llvm/llvm-project/pull/93448
___
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] [MTE] add stack frame history buffer (PR #86356)

2024-05-29 Thread Florian Mayer via llvm-branch-commits

fmayer wrote:

Now actually submitted: 
https://github.com/llvm/llvm-project/commit/1f67f34a5cf993f03eca8936bfb7203778c2997a

https://github.com/llvm/llvm-project/pull/86356
___
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] [draft] Dialect Conversion without Rollback (PR #93412)

2024-05-29 Thread Mehdi Amini via llvm-branch-commits


@@ -1053,3 +1055,241 @@ LogicalResult mlir::applyOpPatternsAndFold(
   });
   return converged;
 }
+
+//===--===//
+// One-Shot Dialect Conversion Infrastructure
+//===--===//
+
+namespace {
+/// A conversion rewriter for the One-Shot Dialect Conversion. This rewriter
+/// immediately materializes all IR changes. It derives from
+/// `ConversionPatternRewriter` so that the existing conversion patterns can
+/// be used with the One-Shot Dialect Conversion.
+class OneShotConversionPatternRewriter : public ConversionPatternRewriter {
+public:
+  OneShotConversionPatternRewriter(MLIRContext *ctx)
+  : ConversionPatternRewriter(ctx) {}
+
+  bool canRecoverFromRewriteFailure() const override { return false; }
+
+  void replaceOp(Operation *op, ValueRange newValues) override;
+
+  void replaceOp(Operation *op, Operation *newOp) override {
+replaceOp(op, newOp->getResults());
+  }
+
+  void eraseOp(Operation *op) override { PatternRewriter::eraseOp(op); }
+
+  void eraseBlock(Block *block) override { PatternRewriter::eraseBlock(block); 
}
+
+  void inlineBlockBefore(Block *source, Block *dest, Block::iterator before,
+ ValueRange argValues = std::nullopt) override {
+PatternRewriter::inlineBlockBefore(source, dest, before, argValues);
+  }
+  using PatternRewriter::inlineBlockBefore;
+
+  void startOpModification(Operation *op) override {
+PatternRewriter::startOpModification(op);
+  }
+
+  void finalizeOpModification(Operation *op) override {
+PatternRewriter::finalizeOpModification(op);
+  }
+
+  void cancelOpModification(Operation *op) override {
+PatternRewriter::cancelOpModification(op);
+  }
+
+  void setCurrentTypeConverter(const TypeConverter *converter) override {
+typeConverter = converter;
+  }
+
+  const TypeConverter *getCurrentTypeConverter() const override {
+return typeConverter;
+  }
+
+  LogicalResult getAdapterOperands(StringRef valueDiagTag,
+   std::optional inputLoc,
+   ValueRange values,
+   SmallVector &remapped) override;
+
+private:
+  /// Build an unrealized_conversion_cast op or look it up in the cache.
+  Value buildUnrealizedConversionCast(Location loc, Type type, Value value);
+
+  /// The current type converter.
+  const TypeConverter *typeConverter;
+
+  /// A cache for unrealized_conversion_casts. To ensure that identical casts
+  /// are not built multiple times.
+  DenseMap, Value> castCache;
+};
+
+void OneShotConversionPatternRewriter::replaceOp(Operation *op,
+ ValueRange newValues) {
+  assert(op->getNumResults() == newValues.size());
+  for (auto [orig, repl] : llvm::zip_equal(op->getResults(), newValues)) {
+if (orig.getType() != repl.getType()) {
+  // Type mismatch: insert unrealized_conversion cast.
+  replaceAllUsesWith(orig, buildUnrealizedConversionCast(
+   op->getLoc(), orig.getType(), repl));
+} else {
+  // Same type: use replacement value directly.
+  replaceAllUsesWith(orig, repl);
+}
+  }
+  eraseOp(op);
+}
+
+Value OneShotConversionPatternRewriter::buildUnrealizedConversionCast(
+Location loc, Type type, Value value) {
+  auto it = castCache.find(std::make_pair(value, type));
+  if (it != castCache.end())
+return it->second;
+
+  // Insert cast at the beginning of the block (for block arguments) or right
+  // after the defining op.
+  OpBuilder::InsertionGuard g(*this);
+  Block *insertBlock = value.getParentBlock();
+  Block::iterator insertPt = insertBlock->begin();
+  if (OpResult inputRes = dyn_cast(value))
+insertPt = ++inputRes.getOwner()->getIterator();
+  setInsertionPoint(insertBlock, insertPt);
+  auto castOp = create(loc, type, value);
+  castCache[std::make_pair(value, type)] = castOp.getOutputs()[0];
+  return castOp.getOutputs()[0];
+}
+
+class ConversionPatternRewriteDriver : public GreedyPatternRewriteDriver {

joker-eph wrote:

I don't have problem with dialect conversion complexity actually, other than 
replaceAllUsesWith not doing what it says it does, and the fact that you have 
to go through the rewriter for these. But you're not changing these aspects are 
you?

> I am reluctant to build something that is not compatible with the large 
> number of existing conversion patterns. 

Without rollback you're incompatible anyway, people can't "just adopt it". But 
otherwise what kind of incompatibility are you worried about here?


Greedy is a fixed-point iterative algorithm which has non-trivial cost 
associated with it. I don't quite get why it is suitable here?

https://github.com/llvm/llvm-project/pull/93412
___
llvm-branch-commits mailing list
llvm-branch-commi

[llvm-branch-commits] [clang] 0b32d5f - Revert "[clang] Add tanf16 builtin and support for tan constrained intrinsic (#93314)"

2024-05-29 Thread Farzon Lotfi via llvm-branch-commits

Author: Farzon Lotfi
Date: 2024-05-29T15:14:21-04:00
New Revision: 0b32d5fc9e9719a742e24e1a470bd0db7e53b8f7

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

LOG: Revert "[clang] Add tanf16 builtin and support for tan constrained 
intrinsic (#93314)"

This reverts commit b15a0a37404f36bcd9c7995de8cd16f9cb5ac8af.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/X86/math-builtins.c
clang/test/CodeGen/constrained-math-builtins.c
clang/test/CodeGen/math-libcalls.c
clang/test/CodeGenOpenCL/builtins-f16.cl
llvm/docs/LangRef.rst
llvm/include/llvm/CodeGen/ISDOpcodes.h
llvm/include/llvm/IR/ConstrainedOps.def
llvm/include/llvm/IR/Intrinsics.td
llvm/test/Assembler/fp-intrinsics-attr.ll
llvm/test/Feature/fp-intrinsics.ll

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 7bef5fd7ad40f..11982af3fa609 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate {
   let Prototype = "T(T)";
 }
 
-def TanF16F128 : Builtin, F16F128MathTemplate {
-  let Spellings = ["__builtin_tan"];
+def TanF128 : Builtin {
+  let Spellings = ["__builtin_tanf128"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
 ConstIgnoringErrnoAndExceptions];
-  let Prototype = "T(T)";
+  let Prototype = "__float128(__float128)";
 }
 
 def TanhF128 : Builtin {

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 94a7036f6233c..266bf41fd5577 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2923,18 +2923,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   SetSqrtFPAccuracy(Call);
   return RValue::get(Call);
 }
-
-case Builtin::BItan:
-case Builtin::BItanf:
-case Builtin::BItanl:
-case Builtin::BI__builtin_tan:
-case Builtin::BI__builtin_tanf:
-case Builtin::BI__builtin_tanf16:
-case Builtin::BI__builtin_tanl:
-case Builtin::BI__builtin_tanf128:
-  return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
-  *this, E, Intrinsic::tan, Intrinsic::experimental_constrained_tan));
-
 case Builtin::BItrunc:
 case Builtin::BItruncf:
 case Builtin::BItruncl:

diff  --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index 1e0f129b98610..093239b448260 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -674,10 +674,10 @@ __builtin_sqrt(f);   __builtin_sqrtf(f);  
__builtin_sqrtl(f); __builtin_
 
 __builtin_tan(f);__builtin_tanf(f);   __builtin_tanl(f); 
__builtin_tanf128(f);
 
-// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]]
-// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]]
-// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]]
-// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]]
+// NO__ERRNO: declare double @tan(double noundef) [[READNONE]]
+// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]]
+// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]]
+// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]]
 // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]]
 // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]]
 // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]]

diff  --git a/clang/test/CodeGen/constrained-math-builtins.c 
b/clang/test/CodeGen/constrained-math-builtins.c
index 6cc3a10a1e794..2de832dd2b6ca 100644
--- a/clang/test/CodeGen/constrained-math-builtins.c
+++ b/clang/test/CodeGen/constrained-math-builtins.c
@@ -183,14 +183,6 @@ void foo(double *d, float f, float *fp, long double *l, 
int *i, const char *c, _
 // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
 // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
 
-  __builtin_tan(f);__builtin_tanf(f);   __builtin_tanl(f); 
__builtin_tanf128(f);
-
-// CHECK: call double @llvm.experimental.constrained.tan.f64(double %{{.*}}, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK: call float @llvm.experimental.constrained.tan.f32(float %{{.*}}, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK: call x86_fp80 @llvm.experimental.constrained.tan.f80(x86_fp80 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")

[llvm-branch-commits] [llvm] Bump version to 18.1.7 (PR #93723)

2024-05-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar created 
https://github.com/llvm/llvm-project/pull/93723

None

>From 828c6f81112b194cd322cc38ac50b0f2e3404587 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Wed, 29 May 2024 12:37:48 -0700
Subject: [PATCH] Bump version to 18.1.7

---
 llvm/CMakeLists.txt| 2 +-
 llvm/utils/lit/lit/__init__.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 26b7b01bb1f8d..51278943847aa 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -22,7 +22,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
   set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
-  set(LLVM_VERSION_PATCH 6)
+  set(LLVM_VERSION_PATCH 7)
 endif()
 if(NOT DEFINED LLVM_VERSION_SUFFIX)
   set(LLVM_VERSION_SUFFIX)
diff --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py
index d8b0e3bd1c69e..5003d78ce5218 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__ = (18, 1, 6)
+__versioninfo__ = (18, 1, 7)
 __version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
 
 __all__ = []

___
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] Bump version to 18.1.7 (PR #93723)

2024-05-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar milestoned 
https://github.com/llvm/llvm-project/pull/93723
___
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] Bump version to 18.1.7 (PR #93723)

2024-05-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar edited 
https://github.com/llvm/llvm-project/pull/93723
___
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] Bump version to 18.1.7 (PR #93723)

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

llvmbot wrote:




@llvm/pr-subscribers-testing-tools

Author: Tom Stellard (tstellar)


Changes



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


2 Files Affected:

- (modified) llvm/CMakeLists.txt (+1-1) 
- (modified) llvm/utils/lit/lit/__init__.py (+1-1) 


``diff
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 26b7b01bb1f8d..51278943847aa 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -22,7 +22,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
   set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
-  set(LLVM_VERSION_PATCH 6)
+  set(LLVM_VERSION_PATCH 7)
 endif()
 if(NOT DEFINED LLVM_VERSION_SUFFIX)
   set(LLVM_VERSION_SUFFIX)
diff --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py
index d8b0e3bd1c69e..5003d78ce5218 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__ = (18, 1, 6)
+__versioninfo__ = (18, 1, 7)
 __version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
 
 __all__ = []

``




https://github.com/llvm/llvm-project/pull/93723
___
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] [draft] Dialect Conversion without Rollback (PR #93412)

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


@@ -1053,3 +1055,241 @@ LogicalResult mlir::applyOpPatternsAndFold(
   });
   return converged;
 }
+
+//===--===//
+// One-Shot Dialect Conversion Infrastructure
+//===--===//
+
+namespace {
+/// A conversion rewriter for the One-Shot Dialect Conversion. This rewriter
+/// immediately materializes all IR changes. It derives from
+/// `ConversionPatternRewriter` so that the existing conversion patterns can
+/// be used with the One-Shot Dialect Conversion.
+class OneShotConversionPatternRewriter : public ConversionPatternRewriter {
+public:
+  OneShotConversionPatternRewriter(MLIRContext *ctx)
+  : ConversionPatternRewriter(ctx) {}
+
+  bool canRecoverFromRewriteFailure() const override { return false; }
+
+  void replaceOp(Operation *op, ValueRange newValues) override;
+
+  void replaceOp(Operation *op, Operation *newOp) override {
+replaceOp(op, newOp->getResults());
+  }
+
+  void eraseOp(Operation *op) override { PatternRewriter::eraseOp(op); }
+
+  void eraseBlock(Block *block) override { PatternRewriter::eraseBlock(block); 
}
+
+  void inlineBlockBefore(Block *source, Block *dest, Block::iterator before,
+ ValueRange argValues = std::nullopt) override {
+PatternRewriter::inlineBlockBefore(source, dest, before, argValues);
+  }
+  using PatternRewriter::inlineBlockBefore;
+
+  void startOpModification(Operation *op) override {
+PatternRewriter::startOpModification(op);
+  }
+
+  void finalizeOpModification(Operation *op) override {
+PatternRewriter::finalizeOpModification(op);
+  }
+
+  void cancelOpModification(Operation *op) override {
+PatternRewriter::cancelOpModification(op);
+  }
+
+  void setCurrentTypeConverter(const TypeConverter *converter) override {
+typeConverter = converter;
+  }
+
+  const TypeConverter *getCurrentTypeConverter() const override {
+return typeConverter;
+  }
+
+  LogicalResult getAdapterOperands(StringRef valueDiagTag,
+   std::optional inputLoc,
+   ValueRange values,
+   SmallVector &remapped) override;
+
+private:
+  /// Build an unrealized_conversion_cast op or look it up in the cache.
+  Value buildUnrealizedConversionCast(Location loc, Type type, Value value);
+
+  /// The current type converter.
+  const TypeConverter *typeConverter;
+
+  /// A cache for unrealized_conversion_casts. To ensure that identical casts
+  /// are not built multiple times.
+  DenseMap, Value> castCache;
+};
+
+void OneShotConversionPatternRewriter::replaceOp(Operation *op,
+ ValueRange newValues) {
+  assert(op->getNumResults() == newValues.size());
+  for (auto [orig, repl] : llvm::zip_equal(op->getResults(), newValues)) {
+if (orig.getType() != repl.getType()) {
+  // Type mismatch: insert unrealized_conversion cast.
+  replaceAllUsesWith(orig, buildUnrealizedConversionCast(
+   op->getLoc(), orig.getType(), repl));
+} else {
+  // Same type: use replacement value directly.
+  replaceAllUsesWith(orig, repl);
+}
+  }
+  eraseOp(op);
+}
+
+Value OneShotConversionPatternRewriter::buildUnrealizedConversionCast(
+Location loc, Type type, Value value) {
+  auto it = castCache.find(std::make_pair(value, type));
+  if (it != castCache.end())
+return it->second;
+
+  // Insert cast at the beginning of the block (for block arguments) or right
+  // after the defining op.
+  OpBuilder::InsertionGuard g(*this);
+  Block *insertBlock = value.getParentBlock();
+  Block::iterator insertPt = insertBlock->begin();
+  if (OpResult inputRes = dyn_cast(value))
+insertPt = ++inputRes.getOwner()->getIterator();
+  setInsertionPoint(insertBlock, insertPt);
+  auto castOp = create(loc, type, value);
+  castCache[std::make_pair(value, type)] = castOp.getOutputs()[0];
+  return castOp.getOutputs()[0];
+}
+
+class ConversionPatternRewriteDriver : public GreedyPatternRewriteDriver {

matthias-springer wrote:

> I don't have problem with dialect conversion complexity actually, other than 
> replaceAllUsesWith not doing what it says it does

I tried to fix that [here](https://github.com/llvm/llvm-project/pull/84725). It 
sounded like the rollback logic was getting too complex. (I would agree with 
that.)

> Without rollback you're incompatible anyway, people can't "just adopt it".

I expect that most dialect conversions do not actually need the rollback. I am 
not aware of any passes in MLIR that require it. (But users may have their own 
passes that rely on it, that's why I asked in the RFC.) So my hope is that the 
existing patterns just work with the new driver. I only tried it with 
`NVGPUToNVVM.cpp` and `ComplexToStandard.cpp` so far, and have to try migrating 
a few more passe

[llvm-branch-commits] [mlir] [draft] Dialect Conversion without Rollback (PR #93412)

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

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/93412
___
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] [draft] Dialect Conversion without Rollback (PR #93412)

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

https://github.com/matthias-springer edited 
https://github.com/llvm/llvm-project/pull/93412
___
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] 4757e13 - Revert "[mlir][spirv] Add integration test for `vector.interleave` and `vecto…"

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

Author: Mehdi Amini
Date: 2024-05-29T14:28:05-06:00
New Revision: 4757e13b449c6d4ffa6d5088628c9de64d79e223

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

LOG: Revert "[mlir][spirv] Add integration test for `vector.interleave` and 
`vecto…"

This reverts commit c9c244423ffb8071bb838c3606052e12af537047.

Added: 


Modified: 
mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp

Removed: 
mlir/test/mlir-vulkan-runner/vector-interleave.mlir
mlir/test/mlir-vulkan-runner/vector-shuffle.mlir



diff  --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 53e73ec0d81bf..1d1db913e3df2 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -18,7 +18,6 @@
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
 #include "mlir/Conversion/SCFToSPIRV/SCFToSPIRV.h"
-#include "mlir/Conversion/VectorToSPIRV/VectorToSPIRV.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
@@ -133,7 +132,6 @@ void GPUToSPIRVPass::runOnOperation() {
 mlir::arith::populateArithToSPIRVPatterns(typeConverter, patterns);
 populateMemRefToSPIRVPatterns(typeConverter, patterns);
 populateFuncToSPIRVPatterns(typeConverter, patterns);
-populateVectorToSPIRVPatterns(typeConverter, patterns);
 
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();

diff  --git a/mlir/test/mlir-vulkan-runner/vector-interleave.mlir 
b/mlir/test/mlir-vulkan-runner/vector-interleave.mlir
deleted file mode 100644
index 2f5c319e2f5c5..0
--- a/mlir/test/mlir-vulkan-runner/vector-interleave.mlir
+++ /dev/null
@@ -1,53 +0,0 @@
-// RUN: mlir-vulkan-runner %s \
-// RUN:  --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
-// RUN:  --entry-point-result=void | FileCheck %s
-
-// CHECK: [0, 2, 1, 3]
-module attributes {
-  gpu.container_module,
-  spirv.target_env = #spirv.target_env<
-#spirv.vce, 
#spirv.resource_limits<>>
-} {
-  gpu.module @kernels {
-gpu.func @kernel_vector_interleave(%arg0 : memref<2xi32>, %arg1 : 
memref<2xi32>, %arg2 : memref<4xi32>)
-  kernel attributes { spirv.entry_point_abi = 
#spirv.entry_point_abi} {
-  %c0 = arith.constant 0 : index
-  %vec0 = vector.load %arg0[%c0] : memref<2xi32>, vector<2xi32>
-  %vec1 = vector.load %arg1[%c0] : memref<2xi32>, vector<2xi32>
-  %result = vector.interleave %vec0, %vec1 : vector<2xi32> -> vector<4xi32>
-  vector.store %result, %arg2[%c0] : memref<4xi32>, vector<4xi32>
-  gpu.return
-}
-  }
-
-  func.func @main() {
-// Allocate 3 buffers.
-%buf0 = memref.alloc() : memref<2xi32>
-%buf1 = memref.alloc() : memref<2xi32>
-%buf2 = memref.alloc() : memref<4xi32>
-
-%idx0 = arith.constant 0 : index
-%idx1 = arith.constant 1 : index
-%idx4 = arith.constant 4 : index
-
-// Initialize input buffer.
-%buf0_vals = arith.constant dense<[0, 1]> : vector<2xi32>
-%buf1_vals = arith.constant dense<[2, 3]> : vector<2xi32>
-vector.store %buf0_vals, %buf0[%idx0] : memref<2xi32>, vector<2xi32>
-vector.store %buf1_vals, %buf1[%idx0] : memref<2xi32>, vector<2xi32>
-
-// Initialize output buffer.
-%value0 = arith.constant 0 : i32
-%buf3 = memref.cast %buf2 : memref<4xi32> to memref
-call @fillResource1DInt(%buf3, %value0) : (memref, i32) -> ()
-
-gpu.launch_func @kernels::@kernel_vector_interleave
-blocks in (%idx4, %idx1, %idx1) threads in (%idx1, %idx1, %idx1)
-args(%buf0 : memref<2xi32>, %buf1 : memref<2xi32>, %buf2 : 
memref<4xi32>)
-%buf4 = memref.cast %buf3 : memref to memref<*xi32>
-call @printMemrefI32(%buf4) : (memref<*xi32>) -> ()
-return
-  }
-  func.func private @fillResource1DInt(%0 : memref, %1 : i32)
-  func.func private @printMemrefI32(%ptr : memref<*xi32>)
-}

diff  --git a/mlir/test/mlir-vulkan-runner/vector-shuffle.mlir 
b/mlir/test/mlir-vulkan-runner/vector-shuffle.mlir
deleted file mode 100644
index e29e054ccd46b..0
--- a/mlir/test/mlir-vulkan-runner/vector-shuffle.mlir
+++ /dev/null
@@ -1,53 +0,0 @@
-// RUN: mlir-vulkan-runner %s \
-// RUN:  --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
-// RUN:  --entry-point-result=void | FileCheck %s
-
-// CHECK: [2, 1, 3]
-module attributes {
-  gpu.container_module,
-  spirv.target_env = #spirv.target_env<
-#spirv.vce, 
#spirv.resource_limits<>>
-} {
-  gpu.module @kernels {
-gpu.func @kernel_vector_shuffle(%arg0 : memref<2xi32>, %arg1 : 
memref<2xi32>, %arg2 : memref<3xi32>)
-  kernel attributes { spirv.entry_poin

[llvm-branch-commits] [lldb] 9f72683 - Revert "[lldb][lldb-dap] Cleanup breakpoint filters. (#87550)"

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

Author: gulfemsavrun
Date: 2024-05-29T13:44:48-07:00
New Revision: 9f72683d223dd8b05ba5efc7590fbb9c725d55c1

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

LOG: Revert "[lldb][lldb-dap] Cleanup breakpoint filters. (#87550)"

This reverts commit cfb209b92a26f16ed7413b32da20fc436eff8c58.

Added: 


Modified: 
lldb/include/lldb/API/SBDebugger.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/API/SBDebugger.cpp
lldb/source/Symbol/TypeSystem.cpp
lldb/tools/lldb-dap/DAP.cpp
lldb/tools/lldb-dap/DAP.h
lldb/tools/lldb-dap/lldb-dap.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index 84ea9c0f772e1..af19b1faf3bf5 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -57,8 +57,6 @@ class LLDB_API SBDebugger {
 
   static const char *GetBroadcasterClass();
 
-  static bool SupportsLanguage(lldb::LanguageType language);
-
   lldb::SBBroadcaster GetBroadcaster();
 
   /// Get progress data from a SBEvent whose type is eBroadcastBitProgress.

diff  --git a/lldb/include/lldb/Symbol/TypeSystem.h 
b/lldb/include/lldb/Symbol/TypeSystem.h
index 7d48f9b316138..b4025c173a186 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -209,7 +209,6 @@ class TypeSystem : public PluginInterface,
   // TypeSystems can support more than one language
   virtual bool SupportsLanguage(lldb::LanguageType language) = 0;
 
-  static bool SupportsLanguageStatic(lldb::LanguageType language);
   // Type Completion
 
   virtual bool GetCompleteType(lldb::opaque_compiler_type_t type) = 0;

diff  --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 29da7d33dd80b..7ef0d6efd4aaa 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1742,7 +1742,3 @@ bool SBDebugger::InterruptRequested()   {
 return m_opaque_sp->InterruptRequested();
   return false;
 }
-
-bool SBDebugger::SupportsLanguage(lldb::LanguageType language) {
-  return TypeSystem::SupportsLanguageStatic(language);
-}

diff  --git a/lldb/source/Symbol/TypeSystem.cpp 
b/lldb/source/Symbol/TypeSystem.cpp
index 5d56d9b1829da..4956f10a0b0a7 100644
--- a/lldb/source/Symbol/TypeSystem.cpp
+++ b/lldb/source/Symbol/TypeSystem.cpp
@@ -335,14 +335,3 @@ TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType 
language,
   }
   return GetTypeSystemForLanguage(language);
 }
-
-bool TypeSystem::SupportsLanguageStatic(lldb::LanguageType language) {
-  if (language == eLanguageTypeUnknown)
-return false;
-
-  LanguageSet languages =
-  PluginManager::GetAllTypeSystemSupportedLanguagesForTypes();
-  if (languages.Empty())
-return false;
-  return languages[language];
-}

diff  --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 807d27c2c869d..d419f821999e6 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -32,7 +32,14 @@ namespace lldb_dap {
 DAP g_dap;
 
 DAP::DAP()
-: broadcaster("lldb-dap"), exception_breakpoints(),
+: broadcaster("lldb-dap"),
+  exception_breakpoints(
+  {{"cpp_catch", "C++ Catch", lldb::eLanguageTypeC_plus_plus},
+   {"cpp_throw", "C++ Throw", lldb::eLanguageTypeC_plus_plus},
+   {"objc_catch", "Objective-C Catch", lldb::eLanguageTypeObjC},
+   {"objc_throw", "Objective-C Throw", lldb::eLanguageTypeObjC},
+   {"swift_catch", "Swift Catch", lldb::eLanguageTypeSwift},
+   {"swift_throw", "Swift Throw", lldb::eLanguageTypeSwift}}),
   focus_tid(LLDB_INVALID_THREAD_ID), stop_at_entry(false), 
is_attach(false),
   enable_auto_variable_summaries(false),
   enable_synthetic_child_debugging(false),
@@ -58,32 +65,8 @@ DAP::DAP()
 
 DAP::~DAP() = default;
 
-void DAP::PopulateExceptionBreakpoints() {
-  exception_breakpoints = {};
-  if (debugger.SupportsLanguage(lldb::eLanguageTypeC_plus_plus)) {
-exception_breakpoints->emplace_back("cpp_catch", "C++ Catch",
-lldb::eLanguageTypeC_plus_plus);
-exception_breakpoints->emplace_back("cpp_throw", "C++ Throw",
-lldb::eLanguageTypeC_plus_plus);
-  }
-  if (debugger.SupportsLanguage(lldb::eLanguageTypeObjC)) {
-exception_breakpoints->emplace_back("objc_catch", "Objective-C Catch",
-lldb::eLanguageTypeObjC);
-exception_breakpoints->emplace_back("objc_throw", "Objective-C Throw",
-lldb::eLanguageTypeObjC);
-  }
-  if (debugger.SupportsLanguage(lldb::eLanguageTypeSwift)) {
-exception_breakpoints->emplace_back("swift_catch", "Swift Catch",
-lldb::eLanguageType

[llvm-branch-commits] [lld] [llvm] release/18.x: [lld] Fix -ObjC load behavior with LTO (#92162) (PR #92478)

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

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


[llvm-branch-commits] [llvm] release/18.x: [DAGCombiner] In mergeTruncStore, make sure we aren't storing shifted in bits. (#90939) (PR #91038)

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

https://github.com/AtariDreams reopened 
https://github.com/llvm/llvm-project/pull/91038
___
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] [BOLT] Detect .warm split functions as cold fragments (PR #93759)

2024-05-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/93759

CDSplit splits functions up to three ways: main fragment with no suffix,
and fragments with .cold and .warm suffixes.

Add .warm suffix to the regex used to recognize split fragments.

Test Plan: updated register-fragments-bolt-symbols.s



___
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] [BOLT] Detect .warm split functions as cold fragments (PR #93759)

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

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)


Changes

CDSplit splits functions up to three ways: main fragment with no suffix,
and fragments with .cold and .warm suffixes.

Add .warm suffix to the regex used to recognize split fragments.

Test Plan: updated register-fragments-bolt-symbols.s


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


3 Files Affected:

- (modified) bolt/include/bolt/Rewrite/RewriteInstance.h (+4) 
- (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+3-7) 
- (modified) bolt/test/X86/register-fragments-bolt-symbols.s (+13-1) 


``diff
diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h 
b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 64113bd026012..d8d62badcc377 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -21,6 +21,7 @@
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Regex.h"
 #include 
 #include 
 #include 
@@ -596,6 +597,9 @@ class RewriteInstance {
 
   NameResolver NR;
 
+  // Regex object matching split function names.
+  const Regex ColdFragment{"(.*)\\.(cold|warm)(\\.[0-9]+)?"};
+
   friend class RewriteInstanceDiff;
 };
 
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index 4b4913dd7a16c..fb920ebbeafc4 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -55,7 +55,6 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Regex.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/raw_ostream.h"
@@ -945,9 +944,6 @@ void RewriteInstance::discoverFileObjects() {
   BinaryFunction *PreviousFunction = nullptr;
   unsigned AnonymousId = 0;
 
-  // Regex object for matching cold fragments.
-  const Regex ColdFragment(".*\\.cold(\\.[0-9]+)?");
-
   const auto SortedSymbolsEnd =
   LastSymbol == SortedSymbols.end() ? LastSymbol : std::next(LastSymbol);
   for (auto Iter = SortedSymbols.begin(); Iter != SortedSymbolsEnd; ++Iter) {
@@ -1460,10 +1456,10 @@ void RewriteInstance::registerFragments() {
 for (StringRef Name : Function.getNames()) {
   StringRef BaseName = NR.restore(Name);
   const bool IsGlobal = BaseName == Name;
-  const size_t ColdSuffixPos = BaseName.find(".cold");
-  if (ColdSuffixPos == StringRef::npos)
+  SmallVector Matches;
+  if (!ColdFragment.match(BaseName, &Matches))
 continue;
-  StringRef ParentName = BaseName.substr(0, ColdSuffixPos);
+  StringRef ParentName = Matches[1];
   const BinaryData *BD = BC->getBinaryDataByName(ParentName);
   const uint64_t NumPossibleLocalParents =
   NR.getUniquifiedNameCount(ParentName);
diff --git a/bolt/test/X86/register-fragments-bolt-symbols.s 
b/bolt/test/X86/register-fragments-bolt-symbols.s
index 90c402b2234d7..d4f39b7acf134 100644
--- a/bolt/test/X86/register-fragments-bolt-symbols.s
+++ b/bolt/test/X86/register-fragments-bolt-symbols.s
@@ -3,8 +3,20 @@
 # RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown 
%S/cdsplit-symbol-names.s -o %t.main.o
 # RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
 # RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
-# RUN: sed -i 's|chain|chain/2|g' %t.fdata
 # RUN: llvm-strip --strip-unneeded %t.main.o
+
+## Check warm fragment name matching (produced by cdsplit)
+# RUN: %clang %cflags %t.main.o -o %t.warm.exe -Wl,-q
+# RUN: llvm-bolt %t.warm.exe -o %t.warm.bolt --split-functions 
--split-strategy=cdsplit \
+# RUN:   --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
+# RUN: link_fdata %s %t.warm.bolt %t.preagg.warm PREAGGWARM
+# PREAGGWARM: B X:0 #chain.warm# 1 0
+# RUN: perf2bolt %t.warm.bolt -p %t.preagg.warm --pa -o %t.warm.fdata -w 
%t.warm.yaml \
+# RUN:   -v=1 | FileCheck %s --check-prefix=CHECK-BOLT-WARM
+
+# CHECK-BOLT-WARM: marking chain.warm/1(*2) as a fragment of chain
+
+# RUN: sed -i 's|chain|chain/2|g' %t.fdata
 # RUN: llvm-objcopy --localize-symbol=chain %t.main.o
 # RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
 # RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \

``




https://github.com/llvm/llvm-project/pull/93759
___
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] [BOLT][BAT] Add support for three-way split functions (PR #93760)

2024-05-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/93760

In three-way split functions, if only .warm fragment is present, BAT
incorrectly overwrites the map for .warm fragment by empty .cold
fragment.

Test Plan: updated register-fragments-bolt-symbols.s



___
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] [BOLT][BAT] Add support for three-way split functions (PR #93760)

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

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)


Changes

In three-way split functions, if only .warm fragment is present, BAT
incorrectly overwrites the map for .warm fragment by empty .cold
fragment.

Test Plan: updated register-fragments-bolt-symbols.s


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


2 Files Affected:

- (modified) bolt/lib/Profile/BoltAddressTranslation.cpp (+2) 
- (modified) bolt/test/X86/register-fragments-bolt-symbols.s (+4) 


``diff
diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp 
b/bolt/lib/Profile/BoltAddressTranslation.cpp
index cdfca2b9871ac..7740862c33f04 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -129,6 +129,8 @@ void BoltAddressTranslation::write(const BinaryContext &BC, 
raw_ostream &OS) {
 LLVM_DEBUG(dbgs() << " Cold part\n");
 for (const FunctionFragment &FF :
  Function.getLayout().getSplitFragments()) {
+  if (FF.empty())
+continue;
   ColdPartSource.emplace(FF.getAddress(), Function.getOutputAddress());
   Map.clear();
   for (const BinaryBasicBlock *const BB : FF)
diff --git a/bolt/test/X86/register-fragments-bolt-symbols.s 
b/bolt/test/X86/register-fragments-bolt-symbols.s
index d4f39b7acf134..ebcf3f31f3766 100644
--- a/bolt/test/X86/register-fragments-bolt-symbols.s
+++ b/bolt/test/X86/register-fragments-bolt-symbols.s
@@ -13,8 +13,12 @@
 # PREAGGWARM: B X:0 #chain.warm# 1 0
 # RUN: perf2bolt %t.warm.bolt -p %t.preagg.warm --pa -o %t.warm.fdata -w 
%t.warm.yaml \
 # RUN:   -v=1 | FileCheck %s --check-prefix=CHECK-BOLT-WARM
+# RUN: FileCheck %s --input-file %t.warm.fdata --check-prefix=CHECK-FDATA-WARM
+# RUN: FileCheck %s --input-file %t.warm.yaml --check-prefix=CHECK-YAML-WARM
 
 # CHECK-BOLT-WARM: marking chain.warm/1(*2) as a fragment of chain
+# CHECK-FDATA-WARM: chain
+# CHECK-YAML-WARM: chain
 
 # RUN: sed -i 's|chain|chain/2|g' %t.fdata
 # RUN: llvm-objcopy --localize-symbol=chain %t.main.o

``




https://github.com/llvm/llvm-project/pull/93760
___
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] text ast-dumper: dump TemplateName for TST and DTST (PR #93766)

2024-05-29 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/93766

Implement AST text dumping of the TemplateName for TemplateSpecializationType 
and DeducedTemplateSpecializationType.

>From 4fe380db6671d38af26b80545d551c4930f1e6d5 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 30 May 2024 01:24:53 -0300
Subject: [PATCH] [clang] text ast-dumper: dump TemplateName for TST and DTST

Implement AST text dumping of the TemplateName for
TemplateSpecializationType and VisitDeducedTemplateSpecializationType.
---
 clang/include/clang/AST/TemplateName.h|  4 ++
 clang/include/clang/AST/TextNodeDumper.h  |  3 +-
 clang/lib/AST/TextNodeDumper.cpp  | 43 
 clang/test/AST/ast-dump-ctad-alias.cpp|  6 ++-
 clang/test/AST/ast-dump-template-decls.cpp| 14 --
 clang/test/AST/ast-dump-template-name.cpp |  6 +++
 clang/test/AST/ast-dump-using-template.cpp| 18 +--
 clang/test/Import/builtin-template/test.cpp   | 11 +---
 .../aggregate-deduction-candidate.cpp |  4 +-
 clang/test/SemaTemplate/deduction-guide.cpp   | 22 
 clang/test/SemaTemplate/make_integer_seq.cpp  | 50 +--
 clang/test/SemaTemplate/type_pack_element.cpp | 34 +
 12 files changed, 149 insertions(+), 66 deletions(-)

diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 876be463c71d0..7aedc086ab7d0 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -360,6 +360,10 @@ class TemplateName {
   static TemplateName getFromVoidPointer(void *Ptr) {
 return TemplateName(Ptr);
   }
+
+  /// Structural equality.
+  bool operator==(TemplateName Other) const { return Storage == Other.Storage; 
}
+  bool operator!=(TemplateName Other) const { return !operator==(Other); }
 };
 
 /// Insertion operator for diagnostics.  This allows sending TemplateName's
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 63fa16c9ec47c..caa33abd99e47 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -214,7 +214,8 @@ class TextNodeDumper
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
   void dumpTemplateArgument(const TemplateArgument &TA);
-  void dumpTemplateName(TemplateName TN);
+  void dumpBareTemplateName(TemplateName TN);
+  void dumpTemplateName(TemplateName TN, StringRef Label = {});
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index a0eedc71ea220..0e0e0a86f5cfc 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1126,7 +1126,32 @@ void TextNodeDumper::VisitIntegralTemplateArgument(const 
TemplateArgument &TA) {
   dumpTemplateArgument(TA);
 }
 
-void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+void TextNodeDumper::dumpTemplateName(TemplateName TN, StringRef Label) {
+  AddChild(Label, [=] {
+{
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TN.print(SS, PrintPolicy);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateName CanonTN = Context->getCanonicalTemplateName(TN);
+  CanonTN != TN) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTN.print(SS, PrintPolicy);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+dumpBareTemplateName(TN);
+  });
+}
+
+void TextNodeDumper::dumpBareTemplateName(TemplateName TN) {
   switch (TN.getKind()) {
   case TemplateName::Template:
 AddChild([=] { Visit(TN.getAsTemplateDecl()); });
@@ -1143,7 +1168,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 if (QTN->hasTemplateKeyword())
   OS << " keyword";
 dumpNestedNameSpecifier(QTN->getQualifier());
-dumpTemplateName(QTN->getUnderlyingTemplate());
+dumpBareTemplateName(QTN->getUnderlyingTemplate());
 return;
   }
   case TemplateName::DependentTemplate: {
@@ -1162,7 +1187,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 if (const TemplateTemplateParmDecl *P = STS->getParameter())
   AddChild("parameter", [=] { Visit(P); });
 dumpDeclRef(STS->getAssociatedDecl(), "associated");
-AddChild("replacement", [=] { dumpTemplateName(STS->getReplacement()); });
+dumpTemplateName(STS->getReplacement(), "replacement");
 return;
   }
   // FIXME: Implement these.
@@ -1182,14 +1207,14 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) 
{
   OS << " template";
   dumpTemplateArgument(TA);
-  dumpTemplateName(TA.getAsTemplate());
+  dumpBareTemplateName(TA.getAsTemplate());
 }
 
 void TextNodeDumper::VisitTe

[llvm-branch-commits] [clang] [clang] text ast-dumper: dump TemplateName for TST and DTST (PR #93766)

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

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

Implement AST text dumping of the TemplateName for TemplateSpecializationType 
and DeducedTemplateSpecializationType.

---

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


12 Files Affected:

- (modified) clang/include/clang/AST/TemplateName.h (+4) 
- (modified) clang/include/clang/AST/TextNodeDumper.h (+2-1) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+32-11) 
- (modified) clang/test/AST/ast-dump-ctad-alias.cpp (+5-1) 
- (modified) clang/test/AST/ast-dump-template-decls.cpp (+10-4) 
- (modified) clang/test/AST/ast-dump-template-name.cpp (+6) 
- (modified) clang/test/AST/ast-dump-using-template.cpp (+13-5) 
- (modified) clang/test/Import/builtin-template/test.cpp (+2-9) 
- (modified) clang/test/SemaTemplate/aggregate-deduction-candidate.cpp (+2-2) 
- (modified) clang/test/SemaTemplate/deduction-guide.cpp (+13-9) 
- (modified) clang/test/SemaTemplate/make_integer_seq.cpp (+36-14) 
- (modified) clang/test/SemaTemplate/type_pack_element.cpp (+24-10) 


``diff
diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 876be463c71d0..7aedc086ab7d0 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -360,6 +360,10 @@ class TemplateName {
   static TemplateName getFromVoidPointer(void *Ptr) {
 return TemplateName(Ptr);
   }
+
+  /// Structural equality.
+  bool operator==(TemplateName Other) const { return Storage == Other.Storage; 
}
+  bool operator!=(TemplateName Other) const { return !operator==(Other); }
 };
 
 /// Insertion operator for diagnostics.  This allows sending TemplateName's
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 63fa16c9ec47c..caa33abd99e47 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -214,7 +214,8 @@ class TextNodeDumper
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
   void dumpConceptReference(const ConceptReference *R);
   void dumpTemplateArgument(const TemplateArgument &TA);
-  void dumpTemplateName(TemplateName TN);
+  void dumpBareTemplateName(TemplateName TN);
+  void dumpTemplateName(TemplateName TN, StringRef Label = {});
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index a0eedc71ea220..0e0e0a86f5cfc 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1126,7 +1126,32 @@ void TextNodeDumper::VisitIntegralTemplateArgument(const 
TemplateArgument &TA) {
   dumpTemplateArgument(TA);
 }
 
-void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+void TextNodeDumper::dumpTemplateName(TemplateName TN, StringRef Label) {
+  AddChild(Label, [=] {
+{
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TN.print(SS, PrintPolicy);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateName CanonTN = Context->getCanonicalTemplateName(TN);
+  CanonTN != TN) {
+llvm::SmallString<128> CanonStr;
+{
+  llvm::raw_svector_ostream SS(CanonStr);
+  CanonTN.print(SS, PrintPolicy);
+}
+if (CanonStr != Str)
+  OS << ":'" << CanonStr << "'";
+  }
+}
+dumpBareTemplateName(TN);
+  });
+}
+
+void TextNodeDumper::dumpBareTemplateName(TemplateName TN) {
   switch (TN.getKind()) {
   case TemplateName::Template:
 AddChild([=] { Visit(TN.getAsTemplateDecl()); });
@@ -1143,7 +1168,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 if (QTN->hasTemplateKeyword())
   OS << " keyword";
 dumpNestedNameSpecifier(QTN->getQualifier());
-dumpTemplateName(QTN->getUnderlyingTemplate());
+dumpBareTemplateName(QTN->getUnderlyingTemplate());
 return;
   }
   case TemplateName::DependentTemplate: {
@@ -1162,7 +1187,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 if (const TemplateTemplateParmDecl *P = STS->getParameter())
   AddChild("parameter", [=] { Visit(P); });
 dumpDeclRef(STS->getAssociatedDecl(), "associated");
-AddChild("replacement", [=] { dumpTemplateName(STS->getReplacement()); });
+dumpTemplateName(STS->getReplacement(), "replacement");
 return;
   }
   // FIXME: Implement these.
@@ -1182,14 +1207,14 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
 void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) 
{
   OS << " template";
   dumpTemplateArgument(TA);
-  dumpTemplateName(TA.getAsTemplate());
+  dumpBareTemplateName(TA.getAsTemplate());
 }
 
 void TextNodeDumper::VisitTemplateExpansionTemplateArgument(
 const TemplateArgument &TA) {
   OS << " template expansion";
   dumpTemplateArgument(TA);
-  dumpTemplateName(TA.getAsTemplateOrTem

[llvm-branch-commits] [clang] a35c320 - Revert "[DebugInfo] Add flag to only emit referenced member functions (#87018)"

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

Author: Mehdi Amini
Date: 2024-05-29T22:47:35-06:00
New Revision: a35c320e18ba2abad17eab0ed162c4115601a828

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

LOG: Revert "[DebugInfo] Add flag to only emit referenced member functions 
(#87018)"

This reverts commit bfabc958c7c0d7ddc15f23383d9da836e8c6093f.

Added: 


Modified: 
clang/include/clang/Basic/DebugOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/debug-options.c

Removed: 
clang/test/CodeGenCXX/debug-info-incomplete-types.cpp



diff  --git a/clang/include/clang/Basic/DebugOptions.def 
b/clang/include/clang/Basic/DebugOptions.def
index bc96d5dfdf890..b94f6aef9ac60 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -68,8 +68,6 @@ BENIGN_DEBUGOPT(NoInlineLineTables, 1, 0) ///< Whether debug 
info should contain
   ///< inline line tables.
 
 DEBUGOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
-DEBUGOPT(DebugOmitUnreferencedMethods, 1, 0) ///< Omit unreferenced member
-///< functions in type debug info.
 
 /// Control the Assignment Tracking debug info feature.
 BENIGN_ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2,

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f64d7c60783e9..4119e69c85540 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4345,10 +4345,6 @@ defm strict_dwarf : BoolOption<"g", "strict-dwarf",
   "the specified version, avoiding features from later versions.">,
   NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
   Group;
-defm omit_unreferenced_methods : BoolGOption<"omit-unreferenced-methods",
-  CodeGenOpts<"DebugOmitUnreferencedMethods">, DefaultFalse,
-  NegFlag,
-  PosFlag, BothFlags<[], [ClangOption, CLOption, 
DXCOption]>>;
 defm column_info : BoolOption<"g", "column-info",
   CodeGenOpts<"DebugColumnInfo">, DefaultTrue,
   NegFlag,

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 5f6f911c7a6d6..9d7107abf8a6f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2836,7 +2836,7 @@ CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
 
   // Collect data fields (including static variables and any initializers).
   CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
-  if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMethods)
+  if (CXXDecl)
 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
 
   LexicalBlockStack.pop_back();

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 4e1c52462e584..97e451cfe2acb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -45,7 +45,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/BinaryFormat/Magic.h"
 #include "llvm/Config/llvm-config.h"
-#include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/CodeGen.h"
@@ -4643,7 +4642,6 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, 
const llvm::Triple &T,
   Args.addOptInFlag(CmdArgs, options::OPT_fforce_dwarf_frame,
 options::OPT_fno_force_dwarf_frame);
 
-  bool EnableTypeUnits = false;
   if (Args.hasFlag(options::OPT_fdebug_types_section,
options::OPT_fno_debug_types_section, false)) {
 if (!(T.isOSBinFormatELF() || T.isOSBinFormatWasm())) {
@@ -4654,24 +4652,11 @@ renderDebugOptions(const ToolChain &TC, const Driver 
&D, const llvm::Triple &T,
 } else if (checkDebugInfoOption(
Args.getLastArg(options::OPT_fdebug_types_section), Args, D,
TC)) {
-  EnableTypeUnits = true;
   CmdArgs.push_back("-mllvm");
   CmdArgs.push_back("-generate-type-units");
 }
   }
 
-  if (const Arg *A =
-  Args.getLastArg(options::OPT_gomit_unreferenced_methods,
-  options::OPT_gno_omit_unreferenced_methods))
-(void)checkDebugInfoOption(A, Args, D, TC);
-  if (Args.hasFlag(options::OPT_gomit_unreferenced_methods,
-   options::OPT_gno_omit_unreferenced_methods, false) &&
-  (DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor ||
-   DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo) &&
-  !EnableTypeUnits) {
-CmdArgs.push_back("-gomit-unreferenced-methods");
-  }
-
   // To avoid join/split of directory+filename, the integrated assembler 
prefers
   // the director

[llvm-branch-commits] [mlir] 52ef986 - Revert "[MLIR][Python] add ctype python binding support for bf16 (#92489)"

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

Author: Mehdi Amini
Date: 2024-05-29T23:20:35-06:00
New Revision: 52ef9864abecea0cf8d20e7eaf49c256248af5f7

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

LOG: Revert "[MLIR][Python] add ctype python binding support for bf16 (#92489)"

This reverts commit 89801c74c3e25f5a1eaa3999863be398f6a82abb.

Added: 


Modified: 
mlir/python/mlir/runtime/np_to_memref.py
mlir/python/requirements.txt
mlir/test/python/execution_engine.py

Removed: 




diff  --git a/mlir/python/mlir/runtime/np_to_memref.py 
b/mlir/python/mlir/runtime/np_to_memref.py
index 882b2751921bf..f6b706f9bc8ae 100644
--- a/mlir/python/mlir/runtime/np_to_memref.py
+++ b/mlir/python/mlir/runtime/np_to_memref.py
@@ -7,12 +7,6 @@
 import numpy as np
 import ctypes
 
-try:
-import ml_dtypes
-except ModuleNotFoundError:
-# The third-party ml_dtypes provides some optional low precision 
data-types for NumPy.
-ml_dtypes = None
-
 
 class C128(ctypes.Structure):
 """A ctype representation for MLIR's Double Complex."""
@@ -32,12 +26,6 @@ class F16(ctypes.Structure):
 _fields_ = [("f16", ctypes.c_int16)]
 
 
-class BF16(ctypes.Structure):
-"""A ctype representation for MLIR's BFloat16."""
-
-_fields_ = [("bf16", ctypes.c_int16)]
-
-
 # 
https://stackoverflow.com/questions/26921836/correct-way-to-test-for-numpy-dtype
 def as_ctype(dtp):
 """Converts dtype to ctype."""
@@ -47,8 +35,6 @@ def as_ctype(dtp):
 return C64
 if dtp == np.dtype(np.float16):
 return F16
-if ml_dtypes is not None and dtp == ml_dtypes.bfloat16:
-return BF16
 return np.ctypeslib.as_ctypes_type(dtp)
 
 
@@ -60,11 +46,6 @@ def to_numpy(array):
 return array.view("complex64")
 if array.dtype == F16:
 return array.view("float16")
-assert not (
-array.dtype == BF16 and ml_dtypes is None
-), f"bfloat16 requires the ml_dtypes package, please run:\n\npip install 
ml_dtypes\n"
-if array.dtype == BF16:
-return array.view("bfloat16")
 return array
 
 

diff  --git a/mlir/python/requirements.txt b/mlir/python/requirements.txt
index 6ec63e43adf89..acd6dbb25edaf 100644
--- a/mlir/python/requirements.txt
+++ b/mlir/python/requirements.txt
@@ -1,4 +1,3 @@
 numpy>=1.19.5, <=1.26
 pybind11>=2.9.0, <=2.10.3
-PyYAML>=5.3.1, <=6.0.1
-ml_dtypes   # provides several NumPy dtype extensions, including the bf16
\ No newline at end of file
+PyYAML>=5.3.1, <=6.0.1
\ No newline at end of file

diff  --git a/mlir/test/python/execution_engine.py 
b/mlir/test/python/execution_engine.py
index 8125bf3fb8fc9..e8b47007a8907 100644
--- a/mlir/test/python/execution_engine.py
+++ b/mlir/test/python/execution_engine.py
@@ -5,7 +5,6 @@
 from mlir.passmanager import *
 from mlir.execution_engine import *
 from mlir.runtime import *
-from ml_dtypes import bfloat16
 
 
 # Log everything to stderr and flush so that we have a unified stream to match
@@ -522,45 +521,6 @@ def testComplexUnrankedMemrefAdd():
 run(testComplexUnrankedMemrefAdd)
 
 
-# Test bf16 memrefs
-# CHECK-LABEL: TEST: testBF16Memref
-def testBF16Memref():
-with Context():
-module = Module.parse(
-"""
-module  {
-  func.func @main(%arg0: memref<1xbf16>,
-  %arg1: memref<1xbf16>) attributes { 
llvm.emit_c_interface } {
-%0 = arith.constant 0 : index
-%1 = memref.load %arg0[%0] : memref<1xbf16>
-memref.store %1, %arg1[%0] : memref<1xbf16>
-return
-  }
-} """
-)
-
-arg1 = np.array([0.5]).astype(bfloat16)
-arg2 = np.array([0.0]).astype(bfloat16)
-
-arg1_memref_ptr = ctypes.pointer(
-ctypes.pointer(get_ranked_memref_descriptor(arg1))
-)
-arg2_memref_ptr = ctypes.pointer(
-ctypes.pointer(get_ranked_memref_descriptor(arg2))
-)
-
-execution_engine = ExecutionEngine(lowerToLLVM(module))
-execution_engine.invoke("main", arg1_memref_ptr, arg2_memref_ptr)
-
-# test to-numpy utility
-# CHECK: [0.5]
-npout = ranked_memref_to_numpy(arg2_memref_ptr[0])
-log(npout)
-
-
-run(testBF16Memref)
-
-
 #  Test addition of two 2d_memref
 # CHECK-LABEL: TEST: testDynamicMemrefAdd2D
 def testDynamicMemrefAdd2D():



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