[llvm] 05e8d9f - [AsmWriter] Add emitMDNodeAnnot (#198317)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 07:55:58 PDT 2026
Author: Harald van Dijk
Date: 2026-06-03T15:55:52+01:00
New Revision: 05e8d9f86a1d29e32d92a04ff9f0371f25057f33
URL: https://github.com/llvm/llvm-project/commit/05e8d9f86a1d29e32d92a04ff9f0371f25057f33
DIFF: https://github.com/llvm/llvm-project/commit/05e8d9f86a1d29e32d92a04ff9f0371f25057f33.diff
LOG: [AsmWriter] Add emitMDNodeAnnot (#198317)
Similarly to the other AAW::emit*Annot functions, this may be used to
emit a comment before a metadata node.
Added:
Modified:
llvm/include/llvm/IR/AssemblyAnnotationWriter.h
llvm/lib/IR/AsmWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/AssemblyAnnotationWriter.h b/llvm/include/llvm/IR/AssemblyAnnotationWriter.h
index d68bcbf85b2b7..bcc5244c0b93e 100644
--- a/llvm/include/llvm/IR/AssemblyAnnotationWriter.h
+++ b/llvm/include/llvm/IR/AssemblyAnnotationWriter.h
@@ -23,6 +23,7 @@ namespace llvm {
class Function;
class BasicBlock;
class Instruction;
+class MDNode;
class Value;
class formatted_raw_ostream;
@@ -53,6 +54,10 @@ class LLVM_ABI AssemblyAnnotationWriter {
virtual void emitInstructionAnnot(const Instruction *,
formatted_raw_ostream &) {}
+ /// emitMDNodeAnnot - This may be implemented to emit a string right before a
+ /// metadata node is emitted.
+ virtual void emitMDNodeAnnot(const MDNode *, formatted_raw_ostream &) {}
+
/// printInfoComment - This may be implemented to emit a comment to the
/// right of an instruction or global value.
virtual void printInfoComment(const Value &, formatted_raw_ostream &) {}
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index b0727cae346f0..52ed28f71f615 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -4980,6 +4980,9 @@ void AssemblyWriter::printMetadataAttachments(
}
void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) {
+ if (AnnotationWriter)
+ AnnotationWriter->emitMDNodeAnnot(Node, Out);
+
Out << '!' << Slot << " = ";
printMDNodeBody(Node);
Out << "\n";
More information about the llvm-commits
mailing list