[PATCH] D89567: [AsmWriter] Construct SlotTracker with the function
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 10:43:02 PDT 2020
kazu created this revision.
kazu added reviewers: apilipenko, knaumov.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
kazu requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89567
Files:
llvm/lib/IR/AsmWriter.cpp
llvm/test/Other/bb-badref.ll
Index: llvm/test/Other/bb-badref.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/IR/AsmWriter.cpp
===================================================================
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -4406,7 +4406,7 @@
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89567.298668.patch
Type: text/x-patch
Size: 1096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201016/e3a86bd6/attachment.bin>
More information about the llvm-commits
mailing list