From c9fcfd02a69170cedcd4cf2e66826f246dff6267 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 5 Jan 2021 16:57:30 +0000 Subject: Optimizing: Add debugging output for HInstruction. Allow printing individual instruction and its arguments with the HGraphVisualizer. Arguments are dumped "recursively" (but implemented with a queue instead of actual recursion). For example, printing the Return instruction from the method Main.testLoop17 in 530-checker-lse yields v28 Return [i27] dex_pc:23 loop:none i27 Add [i24,i26] dex_pc:22 loop:none i24 Phi [i5,i15] dex_pc:n/a reg:0 is_catch_phi:false loop:none i5 IntConstant dex_pc:0 1 loop:none i15 IntConstant dex_pc:5 2 loop:none i26 InstanceFieldGet [l6] dex_pc:20 field_name:TestClass.i field_type:Int32 loop:none l6 NullCheck [l1] dex_pc:1 env:[[i5,_,_,l1,i2]] loop:none l1 ParameterValue dex_pc:n/a loop:none Test: Manual; modify LSE to print the instruction above. Change-Id: Iaf41ba62cd6a5a36236ad0abca082ebffcf6a20e --- compiler/optimizing/graph_visualizer.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'compiler/optimizing/graph_visualizer.h') diff --git a/compiler/optimizing/graph_visualizer.h b/compiler/optimizing/graph_visualizer.h index e01d03c19c..b83e88740c 100644 --- a/compiler/optimizing/graph_visualizer.h +++ b/compiler/optimizing/graph_visualizer.h @@ -101,7 +101,7 @@ class HGraphVisualizer : public ValueObject { public: HGraphVisualizer(std::ostream* output, HGraph* graph, - const CodeGenerator& codegen); + const CodeGenerator* codegen); void PrintHeader(const char* method_name) const; void DumpGraph(const char* pass_name, bool is_after_pass, bool graph_in_bad_state) const; @@ -112,10 +112,12 @@ class HGraphVisualizer : public ValueObject { // method attributes is used. Such empty blocks don't break the c1visualizer parser. static std::string InsertMetaDataAsCompilationBlock(const std::string& meta_data); + static void DumpInstruction(std::ostream* output, HGraph* graph, HInstruction* instruction); + private: std::ostream* const output_; HGraph* const graph_; - const CodeGenerator& codegen_; + const CodeGenerator* codegen_; DISALLOW_COPY_AND_ASSIGN(HGraphVisualizer); }; -- cgit v1.2.3 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/graph_visualizer.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'compiler/optimizing/graph_visualizer.h') diff --git a/compiler/optimizing/graph_visualizer.h b/compiler/optimizing/graph_visualizer.h index b83e88740c..3429c11cbd 100644 --- a/compiler/optimizing/graph_visualizer.h +++ b/compiler/optimizing/graph_visualizer.h @@ -17,11 +17,13 @@ #ifndef ART_COMPILER_OPTIMIZING_GRAPH_VISUALIZER_H_ #define ART_COMPILER_OPTIMIZING_GRAPH_VISUALIZER_H_ +#include #include #include "arch/instruction_set.h" #include "base/arena_containers.h" #include "base/value_object.h" +#include "block_namer.h" namespace art { @@ -101,10 +103,12 @@ class HGraphVisualizer : public ValueObject { public: HGraphVisualizer(std::ostream* output, HGraph* graph, - const CodeGenerator* codegen); + const CodeGenerator* codegen, + std::optional> namer = std::nullopt); void PrintHeader(const char* method_name) const; void DumpGraph(const char* pass_name, bool is_after_pass, bool graph_in_bad_state) const; + void DumpGraphDebug() const; void DumpGraphWithDisassembly() const; // C1visualizer file format does not support inserting arbitrary metadata into a cfg @@ -115,9 +119,21 @@ class HGraphVisualizer : public ValueObject { static void DumpInstruction(std::ostream* output, HGraph* graph, HInstruction* instruction); private: + class OptionalDefaultNamer final : public BlockNamer { + public: + explicit OptionalDefaultNamer(std::optional> inner) + : namer_(inner) {} + + std::ostream& PrintName(std::ostream& os, HBasicBlock* blk) const override; + + private: + std::optional> namer_; + }; + std::ostream* const output_; HGraph* const graph_; const CodeGenerator* codegen_; + OptionalDefaultNamer namer_; DISALLOW_COPY_AND_ASSIGN(HGraphVisualizer); }; -- cgit v1.2.3