diff options
author | 2021-01-06 12:35:31 -0800 | |
---|---|---|
committer | 2021-01-08 22:35:17 +0000 | |
commit | dc281e776c0395b54200c62626f90417f092a2bf (patch) | |
tree | 5e0a458e7ec1968f365b5a6dcc7454d417f11416 /compiler/optimizing/nodes.cc | |
parent | da946fc92b3f6f9664167ef3a0f1324694417b71 (diff) |
Add operator<< for HGraph and HInstructions.
Include helpers for printing arguments as well.
Test: ./test.py --host
Change-Id: I692fd5bd32a8a39da0defd9454d56ccf2480f229
Diffstat (limited to 'compiler/optimizing/nodes.cc')
-rw-r--r-- | compiler/optimizing/nodes.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index d57eaf0b60..e815474b6e 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -17,6 +17,7 @@ #include <algorithm> #include <cfloat> +#include <functional> #include "art_method-inl.h" #include "base/arena_allocator.h" @@ -1955,6 +1956,58 @@ std::ostream& operator<<(std::ostream& os, HInstruction::InstructionKind rhs) { return os; } +std::ostream& operator<<(std::ostream& os, const HInstruction::NoArgsDump rhs) { + // TODO Really this should be const but that would require const-ifying + // graph-visualizer and HGraphVisitor which are tangled up everywhere. + return const_cast<HInstruction*>(rhs.ins)->Dump(os, /* dump_args= */ false); +} + +std::ostream& operator<<(std::ostream& os, const HInstruction::ArgsDump rhs) { + // TODO Really this should be const but that would require const-ifying + // graph-visualizer and HGraphVisitor which are tangled up everywhere. + return const_cast<HInstruction*>(rhs.ins)->Dump(os, /* dump_args= */ true); +} + +std::ostream& operator<<(std::ostream& os, const HInstruction& rhs) { + return os << rhs.DumpWithoutArgs(); +} + +std::ostream& operator<<(std::ostream& os, const HUseList<HInstruction*>& lst) { + os << "Instructions["; + bool first = true; + for (const auto& hi : lst) { + if (!first) { + os << ", "; + } + first = false; + os << hi.GetUser()->DebugName() << "[id: " << hi.GetUser()->GetId() + << ", blk: " << hi.GetUser()->GetBlock()->GetBlockId() << "]@" << hi.GetIndex(); + } + os << "]"; + return os; +} + +std::ostream& operator<<(std::ostream& os, const HUseList<HEnvironment*>& lst) { + os << "Environments["; + bool first = true; + for (const auto& hi : lst) { + if (!first) { + os << ", "; + } + first = false; + os << *hi.GetUser()->GetHolder() << "@" << hi.GetIndex(); + } + os << "]"; + return os; +} + +std::ostream& HGraph::Dump(std::ostream& os, + std::optional<std::reference_wrapper<const BlockNamer>> namer) { + HGraphVisualizer vis(&os, this, nullptr, namer); + vis.DumpGraphDebug(); + return os; +} + void HInstruction::MoveBefore(HInstruction* cursor, bool do_checks) { if (do_checks) { DCHECK(!IsPhi()); |