[llvm] 96f372c - [AsmWriter] Construct SlotTracker with the function

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 15:02:06 PDT 2020


Author: Kazu Hirata
Date: 2020-10-20T15:01:40-07:00
New Revision: 96f372c1e7402595edd2ae9f86b9bdfa22dc1045

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

LOG: [AsmWriter] Construct SlotTracker with the function

This patch teaches BasicBlock::print to construct an instance of
SlotTracker with the containing function.

Without this patch, we dump:

*** IR Dump After LoopInstSimplifyPass ***
; Preheader:
  br label %1

; Loop:
<badref>:                                         ; preds = %1, %0
  br label %1

Note "<badref>" above.  This happens because BasicBlock::print calls:

  SlotTracker SlotTable(this->getModule());

Note that this constructor does not add the contents of functions to
the slot table.  That is, basic blocks are left unnumbered.

This patch fixes the problem by switching to:

  SlotTracker SlotTable(this->getParent());

which does add the contents of the Module and the function,
this->getParent(), to the slot table.

Differential Revision: https://reviews.llvm.org/D89567

Added: 
    llvm/test/Other/bb-badref.ll

Modified: 
    llvm/lib/IR/AsmWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 6d6a8adab3e8..53fea4fcbb24 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -4417,7 +4417,7 @@ void Function::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
 void BasicBlock::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
                      bool ShouldPreserveUseListOrder,
                      bool IsForDebug) const {
-  SlotTracker SlotTable(this->getModule());
+  SlotTracker SlotTable(this->getParent());
   formatted_raw_ostream OS(ROS);
   AssemblyWriter W(OS, SlotTable, this->getModule(), AAW,
                    IsForDebug,

diff  --git a/llvm/test/Other/bb-badref.ll b/llvm/test/Other/bb-badref.ll
new file mode 100644
index 000000000000..ad361ae9efd7
--- /dev/null
+++ b/llvm/test/Other/bb-badref.ll
@@ -0,0 +1,14 @@
+; RUN: opt -passes=loop-instsimplify -print-after-all -disable-output -S < %s 2>&1 | FileCheck %s
+
+; loop-instsimplify dumps individual basic blocks as part of a loop,
+; not a function.  Verify that the non-entry basic block is labeled as
+; "1", not "<badref>".
+
+; CHECK-NOT: <badref>
+
+define void @foo() {
+  br label %1
+
+1:
+  br label %1
+}


        


More information about the llvm-commits mailing list