blob: ec636d8c0bb313549a66526ddbc0f38e53c8d9d8 [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"
Vladimir Markoe2727152019-10-10 10:46:42 +010024#include "base/macros.h"
Ian Rogers0279ebb2014-10-08 17:27:48 -070025#include "base/value_object.h"
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010026
Vladimir Markoe2727152019-10-10 10:46:42 +010027namespace art HIDDEN {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010028
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010029class CodeGenerator;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010030class DexCompilationUnit;
31class HGraph;
Alexandre Rameseb7b7392015-06-19 14:47:01 +010032class HInstruction;
33class SlowPathCode;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010034
35/**
David Brazdilee690a32014-12-01 17:04:16 +000036 * This class outputs the HGraph in the C1visualizer format.
37 * Note: Currently only works if the compiler is single threaded.
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010038 */
Alexandre Rameseb7b7392015-06-19 14:47:01 +010039struct GeneratedCodeInterval {
40 size_t start;
41 size_t end;
42};
43
44struct SlowPathCodeInfo {
45 const SlowPathCode* slow_path;
46 GeneratedCodeInterval code_interval;
47};
48
49// This information is filled by the code generator. It will be used by the
50// graph visualizer to associate disassembly of the generated code with the
51// instructions and slow paths. We assume that the generated code follows the
52// following structure:
53// - frame entry
54// - instructions
55// - slow paths
56class DisassemblyInformation {
57 public:
58 explicit DisassemblyInformation(ArenaAllocator* allocator)
59 : frame_entry_interval_({0, 0}),
60 instruction_intervals_(std::less<const HInstruction*>(), allocator->Adapter()),
61 slow_path_intervals_(allocator->Adapter()) {}
62
63 void SetFrameEntryInterval(size_t start, size_t end) {
64 frame_entry_interval_ = {start, end};
65 }
66
67 void AddInstructionInterval(HInstruction* instr, size_t start, size_t end) {
68 instruction_intervals_.Put(instr, {start, end});
69 }
70
71 void AddSlowPathInterval(SlowPathCode* slow_path, size_t start, size_t end) {
72 slow_path_intervals_.push_back({slow_path, {start, end}});
73 }
74
75 GeneratedCodeInterval GetFrameEntryInterval() const {
76 return frame_entry_interval_;
77 }
78
79 GeneratedCodeInterval* GetFrameEntryInterval() {
80 return &frame_entry_interval_;
81 }
82
83 const ArenaSafeMap<const HInstruction*, GeneratedCodeInterval>& GetInstructionIntervals() const {
84 return instruction_intervals_;
85 }
86
87 ArenaSafeMap<const HInstruction*, GeneratedCodeInterval>* GetInstructionIntervals() {
88 return &instruction_intervals_;
89 }
90
91 const ArenaVector<SlowPathCodeInfo>& GetSlowPathIntervals() const { return slow_path_intervals_; }
92
93 ArenaVector<SlowPathCodeInfo>* GetSlowPathIntervals() { return &slow_path_intervals_; }
94
95 private:
96 GeneratedCodeInterval frame_entry_interval_;
97 ArenaSafeMap<const HInstruction*, GeneratedCodeInterval> instruction_intervals_;
98 ArenaVector<SlowPathCodeInfo> slow_path_intervals_;
99};
100
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100101class HGraphVisualizer : public ValueObject {
102 public:
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100103 HGraphVisualizer(std::ostream* output,
104 HGraph* graph,
David Brazdil62e074f2015-04-07 18:09:37 +0100105 const CodeGenerator& codegen);
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100106
David Brazdil62e074f2015-04-07 18:09:37 +0100107 void PrintHeader(const char* method_name) const;
David Brazdilffee3d32015-07-06 11:48:53 +0100108 void DumpGraph(const char* pass_name, bool is_after_pass, bool graph_in_bad_state) const;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100109 void DumpGraphWithDisassembly() const;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100110
111 private:
112 std::ostream* const output_;
113 HGraph* const graph_;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100114 const CodeGenerator& codegen_;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100115
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100116 DISALLOW_COPY_AND_ASSIGN(HGraphVisualizer);
117};
118
119} // namespace art
120
121#endif // ART_COMPILER_OPTIMIZING_GRAPH_VISUALIZER_H_