aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2020-02-24 17:30:58 -0800
committerQuentin Colombet <qcolombet@apple.com>2020-02-25 10:46:29 -0800
commita12f1d6a52a195831da8f38eece08f271e2aa31b (patch)
tree0c05a585784c288ee61d64c3b2cff77a5343f666 /llvm/lib/CodeGen/MachineInstr.cpp
parenteb1c040b413a3542a7a6db2cae0d0d7bc2728a95 (diff)
downloadllvm-a12f1d6a52a195831da8f38eece08f271e2aa31b.zip
llvm-a12f1d6a52a195831da8f38eece08f271e2aa31b.tar.gz
llvm-a12f1d6a52a195831da8f38eece08f271e2aa31b.tar.bz2
[MachineInstr] Add a dumpr method
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 Differential Revision: https://reviews.llvm.org/D75094
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineInstr.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 7d4a474..a704175 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -61,6 +61,7 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/LowLevelTypeImpl.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
@@ -1463,6 +1464,37 @@ LLVM_DUMP_METHOD void MachineInstr::dump() const {
dbgs() << " ";
print(dbgs());
}
+
+LLVM_DUMP_METHOD void MachineInstr::dumprImpl(
+ const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth,
+ SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const {
+ if (Depth >= MaxDepth)
+ return;
+ if (!AlreadySeenInstrs.insert(this).second)
+ return;
+ // PadToColumn always inserts at least one space.
+ // Don't mess up the alignment if we don't want any space.
+ if (Depth)
+ fdbgs().PadToColumn(Depth * 2);
+ print(fdbgs());
+ for (const MachineOperand &MO : operands()) {
+ if (!MO.isReg() || MO.isDef())
+ continue;
+ Register Reg = MO.getReg();
+ if (Reg.isPhysical())
+ continue;
+ const MachineInstr *NewMI = MRI.getUniqueVRegDef(Reg);
+ if (NewMI == nullptr)
+ continue;
+ NewMI->dumprImpl(MRI, Depth + 1, MaxDepth, AlreadySeenInstrs);
+ }
+}
+
+LLVM_DUMP_METHOD void MachineInstr::dumpr(const MachineRegisterInfo &MRI,
+ unsigned MaxDepth) const {
+ SmallPtrSet<const MachineInstr *, 16> AlreadySeenInstrs;
+ dumprImpl(MRI, 0, MaxDepth, AlreadySeenInstrs);
+}
#endif
void MachineInstr::print(raw_ostream &OS, bool IsStandalone, bool SkipOpers,