[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-13 Thread Carlos Alberto Enciso via lldb-commits

CarlosAlbertoEnciso wrote:

@aengelke This change causes multiple compile errors on Windows when trying to 
build any MLIR executable or tools, using MS Visual Studio 2019.

https://github.com/llvm/llvm-project/pull/207516
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Alexis Engelke via lldb-commits

https://github.com/aengelke closed 
https://github.com/llvm/llvm-project/pull/207516
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Alexis Engelke via lldb-commits

https://github.com/aengelke updated 
https://github.com/llvm/llvm-project/pull/207516

>From ef7186efff12c9c51bcf1a14855940e5497e6d8b Mon Sep 17 00:00:00 2001
From: Alexis Engelke 
Date: Sat, 4 Jul 2026 15:22:04 +
Subject: [PATCH 1/3] [spr] initial version

Created using spr 1.3.8-wip
---
 .../DataFormatters/FormatterBytecode.cpp  |  16 +-
 .../llvm/DebugInfo/CodeView/Formatters.h  |   2 +-
 .../llvm/DebugInfo/PDB/Native/FormatUtil.h|   2 +-
 llvm/include/llvm/Support/FormatAdapters.h|  25 ++-
 llvm/include/llvm/Support/FormatCommon.h  |   8 +-
 llvm/include/llvm/Support/FormatProviders.h   |  22 +--
 llvm/include/llvm/Support/FormatVariadic.h|  20 +--
 .../llvm/Support/FormatVariadicDetails.h  | 158 +-
 llvm/lib/Support/FormatVariadic.cpp   |   2 -
 llvm/tools/llvm-xray/xray-stacks.cpp  |   2 +-
 llvm/unittests/ADT/TwineTest.cpp  |   2 +-
 llvm/unittests/Support/FormatVariadicTest.cpp |  32 ++--
 mlir/include/mlir/TableGen/Format.h   |  24 ++-
 mlir/lib/TableGen/Format.cpp  |  12 +-
 mlir/tools/mlir-tblgen/RewriterGen.cpp|   8 +-
 15 files changed, 120 insertions(+), 215 deletions(-)

diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp 
b/lldb/source/DataFormatters/FormatterBytecode.cpp
index 1936524d37dfc..786f9198a53d0 100644
--- a/lldb/source/DataFormatters/FormatterBytecode.cpp
+++ b/lldb/source/DataFormatters/FormatterBytecode.cpp
@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));
 else if (auto u = std::get_if(&arg))
-  format(build_format_adapter(u));
+  format(FormatFunctor(u));
 else if (auto i = std::get_if(&arg))
-  format(build_format_adapter(i));
+  format(FormatFunctor(i));
 else if (auto valobj = std::get_if(&arg)) {
   if (!valobj->get())
-format(build_format_adapter("null object"));
+format(FormatFunctor("null object"));
   else
-format(build_format_adapter(valobj->get()->GetValueAsCString()));
+format(FormatFunctor(valobj->get()->GetValueAsCString()));
 } else if (auto type = std::get_if(&arg))
-  format(build_format_adapter(type->GetDisplayTypeName()));
+  format(FormatFunctor(type->GetDisplayTypeName()));
 else if (auto sel = std::get_if(&arg))
-  format(build_format_adapter(toString(*sel)));
+  format(FormatFunctor(toString(*sel)));
   }
   data.Push(s);
   return llvm::Error::success();
diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h 
b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index bf0340be901e7..dd802d1b144b0 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -34,7 +34,7 @@ class LLVM_ABI GuidAdapter final : public 
FormatAdapter> {
   explicit GuidAdapter(ArrayRef Guid);
   explicit GuidAdapter(StringRef Guid);
 
-  void format(raw_ostream &Stream, StringRef Style) override;
+  void format(raw_ostream &Stream, StringRef Style);
 };
 
 } // end namespace detail
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h 
b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index 7f70d4157c358..97fb3a12f1501 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -72,7 +72,7 @@ struct EndianAdapter final
   explicit EndianAdapter(EndianType &&Item)
   : FormatAdapter(std::move(Item)) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
+  void format(llvm::raw_ostream &Stream, StringRef Style) {
 format_provider::format(static_cast(this->Item), Stream, Style);
   }
 };
diff --git a/llvm/include/llvm/Support/FormatAdapters.h 
b/llvm/include/llvm/Support/FormatAdapters.h
index 91e9c41d8a395..5a22c0bbde8f4 100644
--- a/llvm/include/llvm/Support/FormatAdapters.h
+++ b/llvm/include/llvm/Support/FormatAdapters.h
@@ -16,8 +16,7 @@
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
-template 
-class FormatAdapter : public support::detail::format_adapter {
+template  class FormatAdapter {
 protected:
   explicit FormatAdapter(T &&Item) : Item(std::forward(Item)) {}
 
@@ -36,8 +35,8 @@ template  class AlignAdapter final : public 
FormatAdapter {
   : FormatAdapter(std::forward(Item)), Where(Where), Amount(Amount),
 Fill(Fill) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
-auto Adapter = detail::build_format_adapter(std::forward(this->Item));
+  void format(llvm::raw_ostream &St

[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Fangrui Song via lldb-commits

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


https://github.com/llvm/llvm-project/pull/207516
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Fangrui Song via lldb-commits


@@ -254,19 +253,18 @@ class FmtStrVecObject : public FmtObjectBase {
 ///in C++ code generation.
 template 
 inline auto tgfmt(StringRef fmt, const FmtContext *ctx, Ts &&...vals)
--> FmtObject<
-decltype(std::make_tuple(llvm::support::detail::build_format_adapter(
-std::forward(vals))...))> {
+-> FmtObject(vals))...))> {
   using ParamTuple = decltype(std::make_tuple(
-  llvm::support::detail::build_format_adapter(std::forward(vals))...));
+  llvm::support::detail::FormatFunctor(std::forward(vals))...));
   return FmtObject(
   fmt, ctx,
-  std::make_tuple(llvm::support::detail::build_format_adapter(
-  std::forward(vals))...));
+  std::make_tuple(
+  llvm::support::detail::FormatFunctor(std::forward(vals))...));
 }
 
-inline FmtStrVecObject tgfmt(StringRef fmt, const FmtContext *ctx,
- ArrayRef params) {
+inline FmtStrVecObject tgfmtv(StringRef fmt, const FmtContext *ctx,

MaskRay wrote:

Either FmtStrVecObject or `tgfmtv` should have a comment.

https://github.com/llvm/llvm-project/pull/207516
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Alexis Engelke via lldb-commits


@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));

aengelke wrote:

Added a template deduction guide for this.

https://github.com/llvm/llvm-project/pull/207516
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Alexis Engelke via lldb-commits

https://github.com/aengelke updated 
https://github.com/llvm/llvm-project/pull/207516

>From ef7186efff12c9c51bcf1a14855940e5497e6d8b Mon Sep 17 00:00:00 2001
From: Alexis Engelke 
Date: Sat, 4 Jul 2026 15:22:04 +
Subject: [PATCH 1/2] [spr] initial version

Created using spr 1.3.8-wip
---
 .../DataFormatters/FormatterBytecode.cpp  |  16 +-
 .../llvm/DebugInfo/CodeView/Formatters.h  |   2 +-
 .../llvm/DebugInfo/PDB/Native/FormatUtil.h|   2 +-
 llvm/include/llvm/Support/FormatAdapters.h|  25 ++-
 llvm/include/llvm/Support/FormatCommon.h  |   8 +-
 llvm/include/llvm/Support/FormatProviders.h   |  22 +--
 llvm/include/llvm/Support/FormatVariadic.h|  20 +--
 .../llvm/Support/FormatVariadicDetails.h  | 158 +-
 llvm/lib/Support/FormatVariadic.cpp   |   2 -
 llvm/tools/llvm-xray/xray-stacks.cpp  |   2 +-
 llvm/unittests/ADT/TwineTest.cpp  |   2 +-
 llvm/unittests/Support/FormatVariadicTest.cpp |  32 ++--
 mlir/include/mlir/TableGen/Format.h   |  24 ++-
 mlir/lib/TableGen/Format.cpp  |  12 +-
 mlir/tools/mlir-tblgen/RewriterGen.cpp|   8 +-
 15 files changed, 120 insertions(+), 215 deletions(-)

diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp 
b/lldb/source/DataFormatters/FormatterBytecode.cpp
index 1936524d37dfc..786f9198a53d0 100644
--- a/lldb/source/DataFormatters/FormatterBytecode.cpp
+++ b/lldb/source/DataFormatters/FormatterBytecode.cpp
@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));
 else if (auto u = std::get_if(&arg))
-  format(build_format_adapter(u));
+  format(FormatFunctor(u));
 else if (auto i = std::get_if(&arg))
-  format(build_format_adapter(i));
+  format(FormatFunctor(i));
 else if (auto valobj = std::get_if(&arg)) {
   if (!valobj->get())
-format(build_format_adapter("null object"));
+format(FormatFunctor("null object"));
   else
-format(build_format_adapter(valobj->get()->GetValueAsCString()));
+format(FormatFunctor(valobj->get()->GetValueAsCString()));
 } else if (auto type = std::get_if(&arg))
-  format(build_format_adapter(type->GetDisplayTypeName()));
+  format(FormatFunctor(type->GetDisplayTypeName()));
 else if (auto sel = std::get_if(&arg))
-  format(build_format_adapter(toString(*sel)));
+  format(FormatFunctor(toString(*sel)));
   }
   data.Push(s);
   return llvm::Error::success();
diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h 
b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index bf0340be901e7..dd802d1b144b0 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -34,7 +34,7 @@ class LLVM_ABI GuidAdapter final : public 
FormatAdapter> {
   explicit GuidAdapter(ArrayRef Guid);
   explicit GuidAdapter(StringRef Guid);
 
-  void format(raw_ostream &Stream, StringRef Style) override;
+  void format(raw_ostream &Stream, StringRef Style);
 };
 
 } // end namespace detail
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h 
b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index 7f70d4157c358..97fb3a12f1501 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -72,7 +72,7 @@ struct EndianAdapter final
   explicit EndianAdapter(EndianType &&Item)
   : FormatAdapter(std::move(Item)) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
+  void format(llvm::raw_ostream &Stream, StringRef Style) {
 format_provider::format(static_cast(this->Item), Stream, Style);
   }
 };
diff --git a/llvm/include/llvm/Support/FormatAdapters.h 
b/llvm/include/llvm/Support/FormatAdapters.h
index 91e9c41d8a395..5a22c0bbde8f4 100644
--- a/llvm/include/llvm/Support/FormatAdapters.h
+++ b/llvm/include/llvm/Support/FormatAdapters.h
@@ -16,8 +16,7 @@
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
-template 
-class FormatAdapter : public support::detail::format_adapter {
+template  class FormatAdapter {
 protected:
   explicit FormatAdapter(T &&Item) : Item(std::forward(Item)) {}
 
@@ -36,8 +35,8 @@ template  class AlignAdapter final : public 
FormatAdapter {
   : FormatAdapter(std::forward(Item)), Where(Where), Amount(Amount),
 Fill(Fill) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
-auto Adapter = detail::build_format_adapter(std::forward(this->Item));
+  void format(llvm::raw_ostream &St

[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Sergei Barannikov via lldb-commits

https://github.com/s-barannikov edited 
https://github.com/llvm/llvm-project/pull/207516
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Sergei Barannikov via lldb-commits


@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));

s-barannikov wrote:

Is it possible to get build_format_adapter back so that we don't have to 
specify template arguments everywhere?

https://github.com/llvm/llvm-project/pull/207516
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread via lldb-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-lldb

Author: Alexis Engelke (aengelke)


Changes

Currently, formatv erases types using a base class and calls the virtual
function format() to format the objects. To avoid these vtables,
refactor formatv to instead store function_refs to a functor (struct
with overloaded operator()). This saves ~5kiB in vtables.

Additionally, add a static assertion that a formatter is present instead
of relying on errors due to missing templates. This requires a little
change to MLIR's tgfmt to use a different name -- previously, the
substitution failure on ArrayRef<> would cause the variadic function to
be skipped, but a static assertion failure is not a substitution error.

Also, simplify the code in FormatVariadicDetails to use if constexpr
instead of template overloads with enable_if, making the code shorter
and easier to read.


---

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


15 Files Affected:

- (modified) lldb/source/DataFormatters/FormatterBytecode.cpp (+8-8) 
- (modified) llvm/include/llvm/DebugInfo/CodeView/Formatters.h (+1-1) 
- (modified) llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h (+1-1) 
- (modified) llvm/include/llvm/Support/FormatAdapters.h (+11-14) 
- (modified) llvm/include/llvm/Support/FormatCommon.h (+4-4) 
- (modified) llvm/include/llvm/Support/FormatProviders.h (+4-18) 
- (modified) llvm/include/llvm/Support/FormatVariadic.h (+9-11) 
- (modified) llvm/include/llvm/Support/FormatVariadicDetails.h (+41-117) 
- (modified) llvm/lib/Support/FormatVariadic.cpp (-2) 
- (modified) llvm/tools/llvm-xray/xray-stacks.cpp (+1-1) 
- (modified) llvm/unittests/ADT/TwineTest.cpp (+1-1) 
- (modified) llvm/unittests/Support/FormatVariadicTest.cpp (+19-13) 
- (modified) mlir/include/mlir/TableGen/Format.h (+11-13) 
- (modified) mlir/lib/TableGen/Format.cpp (+5-7) 
- (modified) mlir/tools/mlir-tblgen/RewriterGen.cpp (+4-4) 


``diff
diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp 
b/lldb/source/DataFormatters/FormatterBytecode.cpp
index 1936524d37dfc..786f9198a53d0 100644
--- a/lldb/source/DataFormatters/FormatterBytecode.cpp
+++ b/lldb/source/DataFormatters/FormatterBytecode.cpp
@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));
 else if (auto u = std::get_if(&arg))
-  format(build_format_adapter(u));
+  format(FormatFunctor(u));
 else if (auto i = std::get_if(&arg))
-  format(build_format_adapter(i));
+  format(FormatFunctor(i));
 else if (auto valobj = std::get_if(&arg)) {
   if (!valobj->get())
-format(build_format_adapter("null object"));
+format(FormatFunctor("null object"));
   else
-format(build_format_adapter(valobj->get()->GetValueAsCString()));
+format(FormatFunctor(valobj->get()->GetValueAsCString()));
 } else if (auto type = std::get_if(&arg))
-  format(build_format_adapter(type->GetDisplayTypeName()));
+  format(FormatFunctor(type->GetDisplayTypeName()));
 else if (auto sel = std::get_if(&arg))
-  format(build_format_adapter(toString(*sel)));
+  format(FormatFunctor(toString(*sel)));
   }
   data.Push(s);
   return llvm::Error::success();
diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h 
b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index bf0340be901e7..dd802d1b144b0 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -34,7 +34,7 @@ class LLVM_ABI GuidAdapter final : public 
FormatAdapter> {
   explicit GuidAdapter(ArrayRef Guid);
   explicit GuidAdapter(StringRef Guid);
 
-  void format(raw_ostream &Stream, StringRef Style) override;
+  void format(raw_ostream &Stream, StringRef Style);
 };
 
 } // end namespace detail
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h 
b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index 7f70d4157c358..97fb3a12f1501 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -72,7 +72,7 @@ struct EndianAdapter final
   explicit EndianAdapter(EndianType &&Item)
   : FormatAdapter(std::move(Item)) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
+  void format(llvm::raw_ostream &Stream, StringRef Style) {
 format_provider::format(static_cast(this->Item), Stream, Style);
   }
 };
diff --git a/llvm/include/llvm/Support/FormatAdapters.h 
b/llvm/include

[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread via lldb-commits

llvmorg-github-actions[bot] wrote:



@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-llvm-support

Author: Alexis Engelke (aengelke)


Changes

Currently, formatv erases types using a base class and calls the virtual
function format() to format the objects. To avoid these vtables,
refactor formatv to instead store function_refs to a functor (struct
with overloaded operator()). This saves ~5kiB in vtables.

Additionally, add a static assertion that a formatter is present instead
of relying on errors due to missing templates. This requires a little
change to MLIR's tgfmt to use a different name -- previously, the
substitution failure on ArrayRef<> would cause the variadic function to
be skipped, but a static assertion failure is not a substitution error.

Also, simplify the code in FormatVariadicDetails to use if constexpr
instead of template overloads with enable_if, making the code shorter
and easier to read.


---

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


15 Files Affected:

- (modified) lldb/source/DataFormatters/FormatterBytecode.cpp (+8-8) 
- (modified) llvm/include/llvm/DebugInfo/CodeView/Formatters.h (+1-1) 
- (modified) llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h (+1-1) 
- (modified) llvm/include/llvm/Support/FormatAdapters.h (+11-14) 
- (modified) llvm/include/llvm/Support/FormatCommon.h (+4-4) 
- (modified) llvm/include/llvm/Support/FormatProviders.h (+4-18) 
- (modified) llvm/include/llvm/Support/FormatVariadic.h (+9-11) 
- (modified) llvm/include/llvm/Support/FormatVariadicDetails.h (+41-117) 
- (modified) llvm/lib/Support/FormatVariadic.cpp (-2) 
- (modified) llvm/tools/llvm-xray/xray-stacks.cpp (+1-1) 
- (modified) llvm/unittests/ADT/TwineTest.cpp (+1-1) 
- (modified) llvm/unittests/Support/FormatVariadicTest.cpp (+19-13) 
- (modified) mlir/include/mlir/TableGen/Format.h (+11-13) 
- (modified) mlir/lib/TableGen/Format.cpp (+5-7) 
- (modified) mlir/tools/mlir-tblgen/RewriterGen.cpp (+4-4) 


``diff
diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp 
b/lldb/source/DataFormatters/FormatterBytecode.cpp
index 1936524d37dfc..786f9198a53d0 100644
--- a/lldb/source/DataFormatters/FormatterBytecode.cpp
+++ b/lldb/source/DataFormatters/FormatterBytecode.cpp
@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));
 else if (auto u = std::get_if(&arg))
-  format(build_format_adapter(u));
+  format(FormatFunctor(u));
 else if (auto i = std::get_if(&arg))
-  format(build_format_adapter(i));
+  format(FormatFunctor(i));
 else if (auto valobj = std::get_if(&arg)) {
   if (!valobj->get())
-format(build_format_adapter("null object"));
+format(FormatFunctor("null object"));
   else
-format(build_format_adapter(valobj->get()->GetValueAsCString()));
+format(FormatFunctor(valobj->get()->GetValueAsCString()));
 } else if (auto type = std::get_if(&arg))
-  format(build_format_adapter(type->GetDisplayTypeName()));
+  format(FormatFunctor(type->GetDisplayTypeName()));
 else if (auto sel = std::get_if(&arg))
-  format(build_format_adapter(toString(*sel)));
+  format(FormatFunctor(toString(*sel)));
   }
   data.Push(s);
   return llvm::Error::success();
diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h 
b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index bf0340be901e7..dd802d1b144b0 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -34,7 +34,7 @@ class LLVM_ABI GuidAdapter final : public 
FormatAdapter> {
   explicit GuidAdapter(ArrayRef Guid);
   explicit GuidAdapter(StringRef Guid);
 
-  void format(raw_ostream &Stream, StringRef Style) override;
+  void format(raw_ostream &Stream, StringRef Style);
 };
 
 } // end namespace detail
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h 
b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index 7f70d4157c358..97fb3a12f1501 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -72,7 +72,7 @@ struct EndianAdapter final
   explicit EndianAdapter(EndianType &&Item)
   : FormatAdapter(std::move(Item)) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
+  void format(llvm::raw_ostream &Stream, StringRef Style) {
 format_provider::format(static_cast(this->Item), Stream, Style);
   }
 };
diff --git a/llvm/include/llvm/S

[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread via lldb-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-llvm-adt

Author: Alexis Engelke (aengelke)


Changes

Currently, formatv erases types using a base class and calls the virtual
function format() to format the objects. To avoid these vtables,
refactor formatv to instead store function_refs to a functor (struct
with overloaded operator()). This saves ~5kiB in vtables.

Additionally, add a static assertion that a formatter is present instead
of relying on errors due to missing templates. This requires a little
change to MLIR's tgfmt to use a different name -- previously, the
substitution failure on ArrayRef<> would cause the variadic function to
be skipped, but a static assertion failure is not a substitution error.

Also, simplify the code in FormatVariadicDetails to use if constexpr
instead of template overloads with enable_if, making the code shorter
and easier to read.


---

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


15 Files Affected:

- (modified) lldb/source/DataFormatters/FormatterBytecode.cpp (+8-8) 
- (modified) llvm/include/llvm/DebugInfo/CodeView/Formatters.h (+1-1) 
- (modified) llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h (+1-1) 
- (modified) llvm/include/llvm/Support/FormatAdapters.h (+11-14) 
- (modified) llvm/include/llvm/Support/FormatCommon.h (+4-4) 
- (modified) llvm/include/llvm/Support/FormatProviders.h (+4-18) 
- (modified) llvm/include/llvm/Support/FormatVariadic.h (+9-11) 
- (modified) llvm/include/llvm/Support/FormatVariadicDetails.h (+41-117) 
- (modified) llvm/lib/Support/FormatVariadic.cpp (-2) 
- (modified) llvm/tools/llvm-xray/xray-stacks.cpp (+1-1) 
- (modified) llvm/unittests/ADT/TwineTest.cpp (+1-1) 
- (modified) llvm/unittests/Support/FormatVariadicTest.cpp (+19-13) 
- (modified) mlir/include/mlir/TableGen/Format.h (+11-13) 
- (modified) mlir/lib/TableGen/Format.cpp (+5-7) 
- (modified) mlir/tools/mlir-tblgen/RewriterGen.cpp (+4-4) 


``diff
diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp 
b/lldb/source/DataFormatters/FormatterBytecode.cpp
index 1936524d37dfc..786f9198a53d0 100644
--- a/lldb/source/DataFormatters/FormatterBytecode.cpp
+++ b/lldb/source/DataFormatters/FormatterBytecode.cpp
@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));
 else if (auto u = std::get_if(&arg))
-  format(build_format_adapter(u));
+  format(FormatFunctor(u));
 else if (auto i = std::get_if(&arg))
-  format(build_format_adapter(i));
+  format(FormatFunctor(i));
 else if (auto valobj = std::get_if(&arg)) {
   if (!valobj->get())
-format(build_format_adapter("null object"));
+format(FormatFunctor("null object"));
   else
-format(build_format_adapter(valobj->get()->GetValueAsCString()));
+format(FormatFunctor(valobj->get()->GetValueAsCString()));
 } else if (auto type = std::get_if(&arg))
-  format(build_format_adapter(type->GetDisplayTypeName()));
+  format(FormatFunctor(type->GetDisplayTypeName()));
 else if (auto sel = std::get_if(&arg))
-  format(build_format_adapter(toString(*sel)));
+  format(FormatFunctor(toString(*sel)));
   }
   data.Push(s);
   return llvm::Error::success();
diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h 
b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index bf0340be901e7..dd802d1b144b0 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -34,7 +34,7 @@ class LLVM_ABI GuidAdapter final : public 
FormatAdapter> {
   explicit GuidAdapter(ArrayRef Guid);
   explicit GuidAdapter(StringRef Guid);
 
-  void format(raw_ostream &Stream, StringRef Style) override;
+  void format(raw_ostream &Stream, StringRef Style);
 };
 
 } // end namespace detail
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h 
b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index 7f70d4157c358..97fb3a12f1501 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -72,7 +72,7 @@ struct EndianAdapter final
   explicit EndianAdapter(EndianType &&Item)
   : FormatAdapter(std::move(Item)) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
+  void format(llvm::raw_ostream &Stream, StringRef Style) {
 format_provider::format(static_cast(this->Item), Stream, Style);
   }
 };
diff --git a/llvm/include/llvm/Support/FormatAdapters.h 
b/llvm/inc

[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread via lldb-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-mlir

Author: Alexis Engelke (aengelke)


Changes

Currently, formatv erases types using a base class and calls the virtual
function format() to format the objects. To avoid these vtables,
refactor formatv to instead store function_refs to a functor (struct
with overloaded operator()). This saves ~5kiB in vtables.

Additionally, add a static assertion that a formatter is present instead
of relying on errors due to missing templates. This requires a little
change to MLIR's tgfmt to use a different name -- previously, the
substitution failure on ArrayRef<> would cause the variadic function to
be skipped, but a static assertion failure is not a substitution error.

Also, simplify the code in FormatVariadicDetails to use if constexpr
instead of template overloads with enable_if, making the code shorter
and easier to read.


---

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


15 Files Affected:

- (modified) lldb/source/DataFormatters/FormatterBytecode.cpp (+8-8) 
- (modified) llvm/include/llvm/DebugInfo/CodeView/Formatters.h (+1-1) 
- (modified) llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h (+1-1) 
- (modified) llvm/include/llvm/Support/FormatAdapters.h (+11-14) 
- (modified) llvm/include/llvm/Support/FormatCommon.h (+4-4) 
- (modified) llvm/include/llvm/Support/FormatProviders.h (+4-18) 
- (modified) llvm/include/llvm/Support/FormatVariadic.h (+9-11) 
- (modified) llvm/include/llvm/Support/FormatVariadicDetails.h (+41-117) 
- (modified) llvm/lib/Support/FormatVariadic.cpp (-2) 
- (modified) llvm/tools/llvm-xray/xray-stacks.cpp (+1-1) 
- (modified) llvm/unittests/ADT/TwineTest.cpp (+1-1) 
- (modified) llvm/unittests/Support/FormatVariadicTest.cpp (+19-13) 
- (modified) mlir/include/mlir/TableGen/Format.h (+11-13) 
- (modified) mlir/lib/TableGen/Format.cpp (+5-7) 
- (modified) mlir/tools/mlir-tblgen/RewriterGen.cpp (+4-4) 


``diff
diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp 
b/lldb/source/DataFormatters/FormatterBytecode.cpp
index 1936524d37dfc..786f9198a53d0 100644
--- a/lldb/source/DataFormatters/FormatterBytecode.cpp
+++ b/lldb/source/DataFormatters/FormatterBytecode.cpp
@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));
 else if (auto u = std::get_if(&arg))
-  format(build_format_adapter(u));
+  format(FormatFunctor(u));
 else if (auto i = std::get_if(&arg))
-  format(build_format_adapter(i));
+  format(FormatFunctor(i));
 else if (auto valobj = std::get_if(&arg)) {
   if (!valobj->get())
-format(build_format_adapter("null object"));
+format(FormatFunctor("null object"));
   else
-format(build_format_adapter(valobj->get()->GetValueAsCString()));
+format(FormatFunctor(valobj->get()->GetValueAsCString()));
 } else if (auto type = std::get_if(&arg))
-  format(build_format_adapter(type->GetDisplayTypeName()));
+  format(FormatFunctor(type->GetDisplayTypeName()));
 else if (auto sel = std::get_if(&arg))
-  format(build_format_adapter(toString(*sel)));
+  format(FormatFunctor(toString(*sel)));
   }
   data.Push(s);
   return llvm::Error::success();
diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h 
b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index bf0340be901e7..dd802d1b144b0 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -34,7 +34,7 @@ class LLVM_ABI GuidAdapter final : public 
FormatAdapter> {
   explicit GuidAdapter(ArrayRef Guid);
   explicit GuidAdapter(StringRef Guid);
 
-  void format(raw_ostream &Stream, StringRef Style) override;
+  void format(raw_ostream &Stream, StringRef Style);
 };
 
 } // end namespace detail
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h 
b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index 7f70d4157c358..97fb3a12f1501 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -72,7 +72,7 @@ struct EndianAdapter final
   explicit EndianAdapter(EndianType &&Item)
   : FormatAdapter(std::move(Item)) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
+  void format(llvm::raw_ostream &Stream, StringRef Style) {
 format_provider::format(static_cast(this->Item), Stream, Style);
   }
 };
diff --git a/llvm/include/llvm/Support/FormatAdapters.h 
b/llvm/include

[Lldb-commits] [lldb] [llvm] [mlir] [Support] Remove virtual functions from formatv (PR #207516)

2026-07-04 Thread Alexis Engelke via lldb-commits

https://github.com/aengelke created 
https://github.com/llvm/llvm-project/pull/207516

Currently, formatv erases types using a base class and calls the virtual
function format() to format the objects. To avoid these vtables,
refactor formatv to instead store function_refs to a functor (struct
with overloaded operator()). This saves ~5kiB in vtables.

Additionally, add a static assertion that a formatter is present instead
of relying on errors due to missing templates. This requires a little
change to MLIR's tgfmt to use a different name -- previously, the
substitution failure on ArrayRef<> would cause the variadic function to
be skipped, but a static assertion failure is not a substitution error.

Also, simplify the code in FormatVariadicDetails to use if constexpr
instead of template overloads with enable_if, making the code shorter
and easier to read.


>From ef7186efff12c9c51bcf1a14855940e5497e6d8b Mon Sep 17 00:00:00 2001
From: Alexis Engelke 
Date: Sat, 4 Jul 2026 15:22:04 +
Subject: [PATCH] [spr] initial version

Created using spr 1.3.8-wip
---
 .../DataFormatters/FormatterBytecode.cpp  |  16 +-
 .../llvm/DebugInfo/CodeView/Formatters.h  |   2 +-
 .../llvm/DebugInfo/PDB/Native/FormatUtil.h|   2 +-
 llvm/include/llvm/Support/FormatAdapters.h|  25 ++-
 llvm/include/llvm/Support/FormatCommon.h  |   8 +-
 llvm/include/llvm/Support/FormatProviders.h   |  22 +--
 llvm/include/llvm/Support/FormatVariadic.h|  20 +--
 .../llvm/Support/FormatVariadicDetails.h  | 158 +-
 llvm/lib/Support/FormatVariadic.cpp   |   2 -
 llvm/tools/llvm-xray/xray-stacks.cpp  |   2 +-
 llvm/unittests/ADT/TwineTest.cpp  |   2 +-
 llvm/unittests/Support/FormatVariadicTest.cpp |  32 ++--
 mlir/include/mlir/TableGen/Format.h   |  24 ++-
 mlir/lib/TableGen/Format.cpp  |  12 +-
 mlir/tools/mlir-tblgen/RewriterGen.cpp|   8 +-
 15 files changed, 120 insertions(+), 215 deletions(-)

diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp 
b/lldb/source/DataFormatters/FormatterBytecode.cpp
index 1936524d37dfc..786f9198a53d0 100644
--- a/lldb/source/DataFormatters/FormatterBytecode.cpp
+++ b/lldb/source/DataFormatters/FormatterBytecode.cpp
@@ -107,26 +107,26 @@ static llvm::Error FormatImpl(DataStack &data) {
 }
 using namespace llvm::support::detail;
 auto arg = data[data.size() - num_args + r.Index];
-auto format = [&](format_adapter &&adapter) {
+auto format = [&](FormatFunctorRef &&adapter) {
   llvm::FmtAlign Align(adapter, r.Where, r.Width, r.Pad);
   Align.format(os, r.Options);
 };
 
 if (auto s = std::get_if(&arg))
-  format(build_format_adapter(s->c_str()));
+  format(FormatFunctor(s->c_str()));
 else if (auto u = std::get_if(&arg))
-  format(build_format_adapter(u));
+  format(FormatFunctor(u));
 else if (auto i = std::get_if(&arg))
-  format(build_format_adapter(i));
+  format(FormatFunctor(i));
 else if (auto valobj = std::get_if(&arg)) {
   if (!valobj->get())
-format(build_format_adapter("null object"));
+format(FormatFunctor("null object"));
   else
-format(build_format_adapter(valobj->get()->GetValueAsCString()));
+format(FormatFunctor(valobj->get()->GetValueAsCString()));
 } else if (auto type = std::get_if(&arg))
-  format(build_format_adapter(type->GetDisplayTypeName()));
+  format(FormatFunctor(type->GetDisplayTypeName()));
 else if (auto sel = std::get_if(&arg))
-  format(build_format_adapter(toString(*sel)));
+  format(FormatFunctor(toString(*sel)));
   }
   data.Push(s);
   return llvm::Error::success();
diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h 
b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index bf0340be901e7..dd802d1b144b0 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -34,7 +34,7 @@ class LLVM_ABI GuidAdapter final : public 
FormatAdapter> {
   explicit GuidAdapter(ArrayRef Guid);
   explicit GuidAdapter(StringRef Guid);
 
-  void format(raw_ostream &Stream, StringRef Style) override;
+  void format(raw_ostream &Stream, StringRef Style);
 };
 
 } // end namespace detail
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h 
b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index 7f70d4157c358..97fb3a12f1501 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -72,7 +72,7 @@ struct EndianAdapter final
   explicit EndianAdapter(EndianType &&Item)
   : FormatAdapter(std::move(Item)) {}
 
-  void format(llvm::raw_ostream &Stream, StringRef Style) override {
+  void format(llvm::raw_ostream &Stream, StringRef Style) {
 format_provider::format(static_cast(this->Item), Stream, Style);
   }
 };
diff --git a/llvm/include/llvm/Support/FormatAdapters.h 
b/llvm/include/llvm/Support/Forma