[PATCH] D81321: Compatibility of AnnotationWriter with BasicBlock Class

Kirill Naumov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 18:27:18 PDT 2020


knaumov created this revision.
knaumov added reviewers: apilipenko, davidxl, eraman, fedor.sergeev.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

In our downstream, we need to annotate only individual BasicBlocks and not the full Function. This change allows us to use AnnotationWriter with BasicBlock through BB.print() method. This implementation is identical to the existing one for Function.


https://reviews.llvm.org/D81321

Files:
  llvm/include/llvm/IR/BasicBlock.h
  llvm/lib/IR/AsmWriter.cpp


Index: llvm/lib/IR/AsmWriter.cpp
===================================================================
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -4330,6 +4330,17 @@
   W.printFunction(this);
 }
 
+void BasicBlock::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
+                     bool ShouldPreserveUseListOrder,
+                     bool IsForDebug) const {
+  SlotTracker SlotTable(this->getModule());
+  formatted_raw_ostream OS(ROS);
+  AssemblyWriter W(OS, SlotTable, this->getModule(), AAW,
+                   IsForDebug,
+                   ShouldPreserveUseListOrder);
+  W.printBasicBlock(this);
+}
+
 void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
                    bool ShouldPreserveUseListOrder, bool IsForDebug) const {
   SlotTracker SlotTable(this);
Index: llvm/include/llvm/IR/BasicBlock.h
===================================================================
--- llvm/include/llvm/IR/BasicBlock.h
+++ llvm/include/llvm/IR/BasicBlock.h
@@ -31,6 +31,7 @@
 
 namespace llvm {
 
+class AssemblyAnnotationWriter;
 class CallInst;
 class Function;
 class LandingPadInst;
@@ -276,6 +277,12 @@
                    static_cast<const BasicBlock *>(this)->getUniqueSuccessor());
   }
 
+  /// Print the basic block to an output stream with an optional
+  /// AssemblyAnnotationWriter.
+  void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr,
+             bool ShouldPreserveUseListOrder = false,
+             bool IsForDebug = false) const;
+
   //===--------------------------------------------------------------------===//
   /// Instruction iterator methods
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81321.268975.patch
Type: text/x-patch
Size: 1645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200606/a9c0d968/attachment.bin>


More information about the llvm-commits mailing list