Add operator<< for HGraph and HInstructions.
Include helpers for printing arguments as well.
Test: ./test.py --host
Change-Id: I692fd5bd32a8a39da0defd9454d56ccf2480f229
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index d57eaf0..e815474 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 @@
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());