[PATCH] D75094: [MachineInstr] Add a dumpr method
Quentin Colombet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 17:40:02 PST 2020
qcolombet created this revision.
qcolombet added reviewers: dsanders, volkan, arsenm, aditya_nandakumar, aemerson, paquette.
Herald added subscribers: hiraditya, wdng.
Herald added a project: LLVM.
Add a dump method that recursively prints an instruction and all
the instructions defining its operands and so on.
This is helpful when looking at combiner issue.
NFC
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75094
Files:
llvm/include/llvm/CodeGen/MachineInstr.h
llvm/lib/CodeGen/MachineInstr.cpp
Index: llvm/lib/CodeGen/MachineInstr.cpp
===================================================================
--- llvm/lib/CodeGen/MachineInstr.cpp
+++ llvm/lib/CodeGen/MachineInstr.cpp
@@ -1463,6 +1463,32 @@
dbgs() << " ";
print(dbgs());
}
+
+LLVM_DUMP_METHOD void MachineInstr::dumprImpl(
+ const MachineRegisterInfo &MRI, unsigned Depth, Optional<unsigned> MaxDepth,
+ SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const {
+ if (MaxDepth && Depth >= *MaxDepth)
+ return;
+ if (!AlreadySeenInstrs.insert(this).second)
+ return;
+ std::string Prefix;
+ for (unsigned i = 0; i != Depth; ++i)
+ Prefix += " ";
+ dbgs() << Prefix;
+ dump();
+ for (const MachineOperand &MO : operands()) {
+ const MachineInstr *NewMI;
+ if (!MO.isReg() || MO.isDef() || !(NewMI = MRI.getVRegDef(MO.getReg())))
+ continue;
+ NewMI->dumprImpl(MRI, Depth + 1, MaxDepth, AlreadySeenInstrs);
+ }
+}
+
+LLVM_DUMP_METHOD void MachineInstr::dumpr(const MachineRegisterInfo &MRI,
+ Optional<unsigned> MaxDepth) const {
+ SmallPtrSet<const MachineInstr *, 16> AlreadySeenInstrs;
+ dumprImpl(MRI, 0, MaxDepth, AlreadySeenInstrs);
+}
#endif
void MachineInstr::print(raw_ostream &OS, bool IsStandalone, bool SkipOpers,
Index: llvm/include/llvm/CodeGen/MachineInstr.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineInstr.h
+++ llvm/include/llvm/CodeGen/MachineInstr.h
@@ -262,6 +262,11 @@
// MachineInstrs are pool-allocated and owned by MachineFunction.
friend class MachineFunction;
+ void
+ dumprImpl(const MachineRegisterInfo &MRI, unsigned Depth,
+ Optional<unsigned> MaxDepth,
+ SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const;
+
public:
MachineInstr(const MachineInstr &) = delete;
MachineInstr &operator=(const MachineInstr &) = delete;
@@ -1534,6 +1539,10 @@
bool AddNewLine = true,
const TargetInstrInfo *TII = nullptr) const;
void dump() const;
+ /// Print on dbgs() the current instruction and the instructions defining its
+ /// operands and so on until we reach \p MaxDepth.
+ void dumpr(const MachineRegisterInfo &MRI,
+ Optional<unsigned> MaxDepth = None) const;
/// @}
//===--------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75094.246351.patch
Type: text/x-patch
Size: 2403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200225/d60b03ac/attachment.bin>
More information about the llvm-commits
mailing list