[Mlir-commits] [mlir] 07fbbac - [mlir] Reduce Diagnostic storage across standard library debug modes (NFC) (#226070)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 24 01:46:32 PDT 2026
Author: Mehdi Amini
Date: 2026-09-24T08:46:25Z
New Revision: 07fbbac878025ecf8f3b25f28ec38c826e6f4891
URL: https://github.com/llvm/llvm-project/commit/07fbbac878025ecf8f3b25f28ec38c826e6f4891
DIFF: https://github.com/llvm/llvm-project/commit/07fbbac878025ecf8f3b25f28ec38c826e6f4891.diff
LOG: [mlir] Reduce Diagnostic storage across standard library debug modes (NFC) (#226070)
The multi-part diagnostic support added a SmallVector of part boundaries
to Diagnostic. With libstdc++'s _GLIBCXX_DEBUG enabled, the two
std::vector members also grow substantially: sizeof(Diagnostic) reaches
288 bytes. This exceeds the 256-byte limit for default
SmallVector<Diagnostic> and breaks Transform dialect builds that use
that type.
Use zero-inline SmallVectors for the owned string buffers and attached
notes. Both collections already allocated when populated, while their
empty representation no longer grows under _GLIBCXX_DEBUG. Give the
part-boundary vector zero inline elements as well: ordinary diagnostics
have a single part and never populate it. Keep the four inline argument
slots, so common diagnostic assembly retains its existing allocation
behavior. Splitting a diagnostic now allocates boundary storage.
On this 64-bit checkout, sizeof(Diagnostic) falls from 224 to 192 bytes
normally and from 288 to 192 bytes with _GLIBCXX_DEBUG.
Assisted-by: Codex
Added:
Modified:
mlir/include/mlir/IR/Diagnostics.h
mlir/lib/IR/Diagnostics.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h
index aae14b3d6e9ec..276bfd60f0a28 100644
--- a/mlir/include/mlir/IR/Diagnostics.h
+++ b/mlir/include/mlir/IR/Diagnostics.h
@@ -157,7 +157,7 @@ inline raw_ostream &operator<<(raw_ostream &os, const DiagnosticArgument &arg) {
/// A diagnostic may contain multiple message parts that share its location,
/// severity, metadata, and attached notes. Empty message parts are ignored.
class Diagnostic {
- using NoteVector = std::vector<std::unique_ptr<Diagnostic>>;
+ using NoteVector = SmallVector<std::unique_ptr<Diagnostic>, 0>;
public:
Diagnostic(Location loc, DiagnosticSeverity severity)
@@ -318,10 +318,11 @@ class Diagnostic {
/// A list of string values used as arguments. This is used to guarantee the
/// liveness of non-constant strings used in diagnostics.
- std::vector<std::unique_ptr<char[]>> strings;
+ SmallVector<std::unique_ptr<char[]>, 0> strings;
/// The exclusive end indices in `arguments` of completed message parts.
- SmallVector<size_t, 2> messagePartEnds;
+ /// Most diagnostics have only one part, so avoid reserving inline storage.
+ SmallVector<size_t, 0> messagePartEnds;
/// A list of attached notes.
NoteVector notes;
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index ad93a9b1606fc..0dae9e4c90cf7 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -84,8 +84,9 @@ void DiagnosticArgument::print(raw_ostream &os) const {
/// Convert a Twine to a StringRef. Memory used for generating the StringRef is
/// stored in 'strings'.
-static StringRef twineToStrRef(const Twine &val,
- std::vector<std::unique_ptr<char[]>> &strings) {
+static StringRef
+twineToStrRef(const Twine &val,
+ SmallVectorImpl<std::unique_ptr<char[]>> &strings) {
// Allocate memory to hold this string.
SmallString<64> data;
auto strRef = val.toStringRef(data);
More information about the Mlir-commits
mailing list