From dc281e776c0395b54200c62626f90417f092a2bf Mon Sep 17 00:00:00 2001 From: Alex Light Date: Wed, 6 Jan 2021 12:35:31 -0800 Subject: Add operator<< for HGraph and HInstructions. Include helpers for printing arguments as well. Test: ./test.py --host Change-Id: I692fd5bd32a8a39da0defd9454d56ccf2480f229 --- compiler/optimizing/nodes.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'compiler/optimizing/nodes.h') diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 125f86be81..73db7e541f 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -33,6 +33,7 @@ #include "base/stl_util.h" #include "base/transform_array_ref.h" #include "art_method.h" +#include "block_namer.h" #include "class_root.h" #include "compilation_kind.h" #include "data_type.h" @@ -423,6 +424,9 @@ class HGraph : public ArenaObject { blocks_.reserve(kDefaultNumberOfBlocks); } + std::ostream& Dump(std::ostream& os, + std::optional> namer = std::nullopt); + ArenaAllocator* GetAllocator() const { return allocator_; } ArenaStack* GetArenaStack() const { return arena_stack_; } @@ -881,6 +885,10 @@ class HGraph : public ArenaObject { DISALLOW_COPY_AND_ASSIGN(HGraph); }; +inline std::ostream& operator<<(std::ostream& os, HGraph& graph) { + return graph.Dump(os); +} + class HLoopInformation : public ArenaObject { public: HLoopInformation(HBasicBlock* header, HGraph* graph) @@ -2112,6 +2120,8 @@ class HEnvironment : public ArenaObject { DISALLOW_COPY_AND_ASSIGN(HEnvironment); }; +std::ostream& operator<<(std::ostream& os, const HInstruction& rhs); + class HInstruction : public ArenaObject { public: #define DECLARE_KIND(type, super) k##type, @@ -2147,6 +2157,21 @@ class HInstruction : public ArenaObject { std::ostream& Dump(std::ostream& os, bool dump_args = false); + // Helper for dumping without argument information using operator<< + struct NoArgsDump { + const HInstruction* ins; + }; + NoArgsDump DumpWithoutArgs() const { + return NoArgsDump{this}; + } + // Helper for dumping with argument information using operator<< + struct ArgsDump { + const HInstruction* ins; + }; + ArgsDump DumpWithArgs() const { + return ArgsDump{this}; + } + HInstruction* GetNext() const { return next_; } HInstruction* GetPrevious() const { return previous_; } @@ -2672,6 +2697,10 @@ class HInstruction : public ArenaObject { friend class HInstructionList; }; std::ostream& operator<<(std::ostream& os, HInstruction::InstructionKind rhs); +std::ostream& operator<<(std::ostream& os, const HInstruction::NoArgsDump rhs); +std::ostream& operator<<(std::ostream& os, const HInstruction::ArgsDump rhs); +std::ostream& operator<<(std::ostream& os, const HUseList& lst); +std::ostream& operator<<(std::ostream& os, const HUseList& lst); // Iterates over the instructions, while preserving the next instruction // in case the current instruction gets removed from the list by the user -- cgit v1.2.3-59-g8ed1b