blob: 66588f6e36ee8a9d483da0ee26fb0155ea8a63e2 [file] [log] [blame]
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_GRAPH_VISUALIZER_H_
18#define ART_COMPILER_OPTIMIZING_GRAPH_VISUALIZER_H_
19
Ian Rogerscf7f1912014-10-22 22:06:39 -070020#include <ostream>
21
Alexandre Rameseb7b7392015-06-19 14:47:01 +010022#include "arch/instruction_set.h"
23#include "base/arena_containers.h"
Ian Rogers0279ebb2014-10-08 17:27:48 -070024#include "base/value_object.h"
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010025
26namespace art {
27
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010028class CodeGenerator;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010029class DexCompilationUnit;
30class HGraph;
Alexandre Rameseb7b7392015-06-19 14:47:01 +010031class HInstruction;
32class SlowPathCode;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010033
34/**
David Brazdilee690a32014-12-01 17:04:16 +000035 * This class outputs the HGraph in the C1visualizer format.
36 * Note: Currently only works if the compiler is single threaded.
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010037 */
Alexandre Rameseb7b7392015-06-19 14:47:01 +010038struct GeneratedCodeInterval {
39 size_t start;
40 size_t end;
41};
42
43struct SlowPathCodeInfo {
44 const SlowPathCode* slow_path;
45 GeneratedCodeInterval code_interval;
46};
47
48// This information is filled by the code generator. It will be used by the
49// graph visualizer to associate disassembly of the generated code with the
50// instructions and slow paths. We assume that the generated code follows the
51// following structure:
52// - frame entry
53// - instructions
54// - slow paths
55class DisassemblyInformation {
56 public:
57 explicit DisassemblyInformation(ArenaAllocator* allocator)
58 : frame_entry_interval_({0, 0}),
59 instruction_intervals_(std::less<const HInstruction*>(), allocator->Adapter()),
60 slow_path_intervals_(allocator->Adapter()) {}
61
62 void SetFrameEntryInterval(size_t start, size_t end) {
63 frame_entry_interval_ = {start, end};
64 }
65
66 void AddInstructionInterval(HInstruction* instr, size_t start, size_t end) {
67 instruction_intervals_.Put(instr, {start, end});
68 }
69
70 void AddSlowPathInterval(SlowPathCode* slow_path, size_t start, size_t end) {
71 slow_path_intervals_.push_back({slow_path, {start, end}});
72 }
73
74 GeneratedCodeInterval GetFrameEntryInterval() const {
75 return frame_entry_interval_;
76 }
77
78 GeneratedCodeInterval* GetFrameEntryInterval() {
79 return &frame_entry_interval_;
80 }
81
82 const ArenaSafeMap<const HInstruction*, GeneratedCodeInterval>& GetInstructionIntervals() const {
83 return instruction_intervals_;
84 }
85
86 ArenaSafeMap<const HInstruction*, GeneratedCodeInterval>* GetInstructionIntervals() {
87 return &instruction_intervals_;
88 }
89
90 const ArenaVector<SlowPathCodeInfo>& GetSlowPathIntervals() const { return slow_path_intervals_; }
91
92 ArenaVector<SlowPathCodeInfo>* GetSlowPathIntervals() { return &slow_path_intervals_; }
93
94 private:
95 GeneratedCodeInterval frame_entry_interval_;
96 ArenaSafeMap<const HInstruction*, GeneratedCodeInterval> instruction_intervals_;
97 ArenaVector<SlowPathCodeInfo> slow_path_intervals_;
98};
99
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100100class HGraphVisualizer : public ValueObject {
101 public:
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100102 HGraphVisualizer(std::ostream* output,
103 HGraph* graph,
David Brazdil62e074f2015-04-07 18:09:37 +0100104 const CodeGenerator& codegen);
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100105
David Brazdil62e074f2015-04-07 18:09:37 +0100106 void PrintHeader(const char* method_name) const;
David Brazdilffee3d32015-07-06 11:48:53 +0100107 void DumpGraph(const char* pass_name, bool is_after_pass, bool graph_in_bad_state) const;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100108 void DumpGraphWithDisassembly() const;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100109
110 private:
111 std::ostream* const output_;
112 HGraph* const graph_;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100113 const CodeGenerator& codegen_;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100114
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100115 DISALLOW_COPY_AND_ASSIGN(HGraphVisualizer);
116};
117
118} // namespace art
119
120#endif // ART_COMPILER_OPTIMIZING_GRAPH_VISUALIZER_H_