Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1 | /* |
| 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 | #include "graph_visualizer.h" |
| 18 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 19 | #include "code_generator.h" |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 20 | #include "licm.h" |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 21 | #include "nodes.h" |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 22 | #include "optimization.h" |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 23 | #include "register_allocator.h" |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 24 | #include "ssa_liveness_analysis.h" |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | /** |
| 29 | * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra. |
| 30 | */ |
| 31 | class HGraphVisualizerPrinter : public HGraphVisitor { |
| 32 | public: |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 33 | HGraphVisualizerPrinter(HGraph* graph, |
| 34 | std::ostream& output, |
| 35 | const char* pass_name, |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 36 | bool is_after_pass, |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 37 | const CodeGenerator& codegen) |
| 38 | : HGraphVisitor(graph), |
| 39 | output_(output), |
| 40 | pass_name_(pass_name), |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 41 | is_after_pass_(is_after_pass), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 42 | codegen_(codegen), |
| 43 | indent_(0) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 44 | |
| 45 | void StartTag(const char* name) { |
| 46 | AddIndent(); |
| 47 | output_ << "begin_" << name << std::endl; |
| 48 | indent_++; |
| 49 | } |
| 50 | |
| 51 | void EndTag(const char* name) { |
| 52 | indent_--; |
| 53 | AddIndent(); |
| 54 | output_ << "end_" << name << std::endl; |
| 55 | } |
| 56 | |
| 57 | void PrintProperty(const char* name, const char* property) { |
| 58 | AddIndent(); |
| 59 | output_ << name << " \"" << property << "\"" << std::endl; |
| 60 | } |
| 61 | |
| 62 | void PrintProperty(const char* name, const char* property, int id) { |
| 63 | AddIndent(); |
| 64 | output_ << name << " \"" << property << id << "\"" << std::endl; |
| 65 | } |
| 66 | |
| 67 | void PrintEmptyProperty(const char* name) { |
| 68 | AddIndent(); |
| 69 | output_ << name << std::endl; |
| 70 | } |
| 71 | |
| 72 | void PrintTime(const char* name) { |
| 73 | AddIndent(); |
Jean Christophe Beyler | 0ada95d | 2014-12-04 11:20:20 -0800 | [diff] [blame] | 74 | output_ << name << " " << time(nullptr) << std::endl; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void PrintInt(const char* name, int value) { |
| 78 | AddIndent(); |
| 79 | output_ << name << " " << value << std::endl; |
| 80 | } |
| 81 | |
| 82 | void AddIndent() { |
| 83 | for (size_t i = 0; i < indent_; ++i) { |
| 84 | output_ << " "; |
| 85 | } |
| 86 | } |
| 87 | |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 88 | char GetTypeId(Primitive::Type type) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 89 | // Note that Primitive::Descriptor would not work for us |
| 90 | // because it does not handle reference types (that is kPrimNot). |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 91 | switch (type) { |
| 92 | case Primitive::kPrimBoolean: return 'z'; |
| 93 | case Primitive::kPrimByte: return 'b'; |
| 94 | case Primitive::kPrimChar: return 'c'; |
| 95 | case Primitive::kPrimShort: return 's'; |
| 96 | case Primitive::kPrimInt: return 'i'; |
| 97 | case Primitive::kPrimLong: return 'j'; |
| 98 | case Primitive::kPrimFloat: return 'f'; |
| 99 | case Primitive::kPrimDouble: return 'd'; |
| 100 | case Primitive::kPrimNot: return 'l'; |
| 101 | case Primitive::kPrimVoid: return 'v'; |
| 102 | } |
| 103 | LOG(FATAL) << "Unreachable"; |
| 104 | return 'v'; |
| 105 | } |
| 106 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 107 | void PrintPredecessors(HBasicBlock* block) { |
| 108 | AddIndent(); |
| 109 | output_ << "predecessors"; |
| 110 | for (size_t i = 0, e = block->GetPredecessors().Size(); i < e; ++i) { |
| 111 | HBasicBlock* predecessor = block->GetPredecessors().Get(i); |
| 112 | output_ << " \"B" << predecessor->GetBlockId() << "\" "; |
| 113 | } |
| 114 | output_<< std::endl; |
| 115 | } |
| 116 | |
| 117 | void PrintSuccessors(HBasicBlock* block) { |
| 118 | AddIndent(); |
| 119 | output_ << "successors"; |
| 120 | for (size_t i = 0, e = block->GetSuccessors().Size(); i < e; ++i) { |
| 121 | HBasicBlock* successor = block->GetSuccessors().Get(i); |
| 122 | output_ << " \"B" << successor->GetBlockId() << "\" "; |
| 123 | } |
| 124 | output_<< std::endl; |
| 125 | } |
| 126 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 127 | void DumpLocation(Location location) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 128 | if (location.IsRegister()) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 129 | codegen_.DumpCoreRegister(output_, location.reg()); |
| 130 | } else if (location.IsFpuRegister()) { |
| 131 | codegen_.DumpFloatingPointRegister(output_, location.reg()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 132 | } else if (location.IsConstant()) { |
| 133 | output_ << "constant"; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 134 | HConstant* constant = location.GetConstant(); |
| 135 | if (constant->IsIntConstant()) { |
| 136 | output_ << " " << constant->AsIntConstant()->GetValue(); |
| 137 | } else if (constant->IsLongConstant()) { |
| 138 | output_ << " " << constant->AsLongConstant()->GetValue(); |
| 139 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 140 | } else if (location.IsInvalid()) { |
| 141 | output_ << "invalid"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 142 | } else if (location.IsStackSlot()) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 143 | output_ << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 144 | } else if (location.IsFpuRegisterPair()) { |
| 145 | codegen_.DumpFloatingPointRegister(output_, location.low()); |
| 146 | output_ << " and "; |
| 147 | codegen_.DumpFloatingPointRegister(output_, location.high()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 148 | } else if (location.IsRegisterPair()) { |
| 149 | codegen_.DumpCoreRegister(output_, location.low()); |
| 150 | output_ << " and "; |
| 151 | codegen_.DumpCoreRegister(output_, location.high()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 152 | } else if (location.IsUnallocated()) { |
| 153 | output_ << "<U>"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 154 | } else { |
| 155 | DCHECK(location.IsDoubleStackSlot()); |
| 156 | output_ << "2x" << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 160 | void VisitParallelMove(HParallelMove* instruction) OVERRIDE { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 161 | output_ << " ("; |
| 162 | for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) { |
| 163 | MoveOperands* move = instruction->MoveOperandsAt(i); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 164 | DumpLocation(move->GetSource()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 165 | output_ << " -> "; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 166 | DumpLocation(move->GetDestination()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 167 | if (i + 1 != e) { |
| 168 | output_ << ", "; |
| 169 | } |
| 170 | } |
| 171 | output_ << ")"; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 172 | output_ << " (liveness: " << instruction->GetLifetimePosition() << ")"; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 173 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 174 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 175 | void VisitIntConstant(HIntConstant* instruction) OVERRIDE { |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 176 | output_ << " " << instruction->GetValue(); |
| 177 | } |
| 178 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 179 | void VisitLongConstant(HLongConstant* instruction) OVERRIDE { |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 180 | output_ << " " << instruction->GetValue(); |
| 181 | } |
| 182 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 183 | void VisitFloatConstant(HFloatConstant* instruction) OVERRIDE { |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 184 | output_ << " " << instruction->GetValue(); |
| 185 | } |
| 186 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 187 | void VisitDoubleConstant(HDoubleConstant* instruction) OVERRIDE { |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 188 | output_ << " " << instruction->GetValue(); |
| 189 | } |
| 190 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 191 | void VisitPhi(HPhi* phi) OVERRIDE { |
| 192 | output_ << " " << phi->GetRegNumber(); |
| 193 | } |
| 194 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 195 | bool IsPass(const char* name) { |
| 196 | return strcmp(pass_name_, name) == 0; |
| 197 | } |
| 198 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 199 | void PrintInstruction(HInstruction* instruction) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 200 | output_ << instruction->DebugName(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 201 | instruction->Accept(this); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 202 | if (instruction->InputCount() > 0) { |
| 203 | output_ << " [ "; |
| 204 | for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) { |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 205 | output_ << GetTypeId(inputs.Current()->GetType()) << inputs.Current()->GetId() << " "; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 206 | } |
| 207 | output_ << "]"; |
| 208 | } |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 209 | if (instruction->HasEnvironment()) { |
| 210 | HEnvironment* env = instruction->GetEnvironment(); |
| 211 | output_ << " (env: [ "; |
| 212 | for (size_t i = 0, e = env->Size(); i < e; ++i) { |
| 213 | HInstruction* insn = env->GetInstructionAt(i); |
| 214 | if (insn != nullptr) { |
| 215 | output_ << GetTypeId(insn->GetType()) << insn->GetId() << " "; |
| 216 | } else { |
| 217 | output_ << " _ "; |
| 218 | } |
| 219 | } |
| 220 | output_ << "])"; |
| 221 | } |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 222 | if (IsPass(SsaLivenessAnalysis::kLivenessPassName) |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 223 | && is_after_pass_ |
| 224 | && instruction->GetLifetimePosition() != kNoLifetime) { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 225 | output_ << " (liveness: " << instruction->GetLifetimePosition(); |
| 226 | if (instruction->HasLiveInterval()) { |
| 227 | output_ << " "; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 228 | const LiveInterval& interval = *instruction->GetLiveInterval(); |
| 229 | interval.Dump(output_); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 230 | } |
| 231 | output_ << ")"; |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 232 | } else if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 233 | LocationSummary* locations = instruction->GetLocations(); |
| 234 | if (locations != nullptr) { |
| 235 | output_ << " ( "; |
| 236 | for (size_t i = 0; i < instruction->InputCount(); ++i) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 237 | DumpLocation(locations->InAt(i)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 238 | output_ << " "; |
| 239 | } |
| 240 | output_ << ")"; |
| 241 | if (locations->Out().IsValid()) { |
| 242 | output_ << " -> "; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 243 | DumpLocation(locations->Out()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 244 | } |
| 245 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 246 | output_ << " (liveness: " << instruction->GetLifetimePosition() << ")"; |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 247 | } else if (IsPass(LICM::kLoopInvariantCodeMotionPassName)) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 248 | output_ << " ( loop_header:"; |
| 249 | HLoopInformation* info = instruction->GetBlock()->GetLoopInformation(); |
| 250 | if (info == nullptr) { |
| 251 | output_ << "null )"; |
| 252 | } else { |
| 253 | output_ << "B" << info->GetHeader()->GetBlockId() << " )"; |
| 254 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 255 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void PrintInstructions(const HInstructionList& list) { |
| 259 | const char* kEndInstructionMarker = "<|@"; |
| 260 | for (HInstructionIterator it(list); !it.Done(); it.Advance()) { |
| 261 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 262 | int bci = 0; |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 263 | size_t num_uses = 0; |
| 264 | for (HUseIterator<HInstruction*> use_it(instruction->GetUses()); |
| 265 | !use_it.Done(); |
| 266 | use_it.Advance()) { |
| 267 | ++num_uses; |
| 268 | } |
| 269 | AddIndent(); |
| 270 | output_ << bci << " " << num_uses << " " |
| 271 | << GetTypeId(instruction->GetType()) << instruction->GetId() << " "; |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 272 | PrintInstruction(instruction); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 273 | output_ << kEndInstructionMarker << std::endl; |
| 274 | } |
| 275 | } |
| 276 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 277 | void Run() { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 278 | StartTag("cfg"); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 279 | std::string pass_desc = std::string(pass_name_) + (is_after_pass_ ? " (after)" : " (before)"); |
| 280 | PrintProperty("name", pass_desc.c_str()); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 281 | VisitInsertionOrder(); |
| 282 | EndTag("cfg"); |
| 283 | } |
| 284 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 285 | void VisitBasicBlock(HBasicBlock* block) OVERRIDE { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 286 | StartTag("block"); |
| 287 | PrintProperty("name", "B", block->GetBlockId()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 288 | if (block->GetLifetimeStart() != kNoLifetime) { |
| 289 | // Piggy back on these fields to show the lifetime of the block. |
| 290 | PrintInt("from_bci", block->GetLifetimeStart()); |
| 291 | PrintInt("to_bci", block->GetLifetimeEnd()); |
| 292 | } else { |
| 293 | PrintInt("from_bci", -1); |
| 294 | PrintInt("to_bci", -1); |
| 295 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 296 | PrintPredecessors(block); |
| 297 | PrintSuccessors(block); |
| 298 | PrintEmptyProperty("xhandlers"); |
| 299 | PrintEmptyProperty("flags"); |
| 300 | if (block->GetDominator() != nullptr) { |
| 301 | PrintProperty("dominator", "B", block->GetDominator()->GetBlockId()); |
| 302 | } |
| 303 | |
| 304 | StartTag("states"); |
| 305 | StartTag("locals"); |
| 306 | PrintInt("size", 0); |
| 307 | PrintProperty("method", "None"); |
| 308 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 309 | AddIndent(); |
| 310 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 311 | output_ << instruction->GetId() << " " << GetTypeId(instruction->GetType()) |
| 312 | << instruction->GetId() << "[ "; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 313 | for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) { |
| 314 | output_ << inputs.Current()->GetId() << " "; |
| 315 | } |
| 316 | output_ << "]" << std::endl; |
| 317 | } |
| 318 | EndTag("locals"); |
| 319 | EndTag("states"); |
| 320 | |
| 321 | StartTag("HIR"); |
| 322 | PrintInstructions(block->GetPhis()); |
| 323 | PrintInstructions(block->GetInstructions()); |
| 324 | EndTag("HIR"); |
| 325 | EndTag("block"); |
| 326 | } |
| 327 | |
| 328 | private: |
| 329 | std::ostream& output_; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 330 | const char* pass_name_; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 331 | const bool is_after_pass_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 332 | const CodeGenerator& codegen_; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 333 | size_t indent_; |
| 334 | |
| 335 | DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter); |
| 336 | }; |
| 337 | |
| 338 | HGraphVisualizer::HGraphVisualizer(std::ostream* output, |
| 339 | HGraph* graph, |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 340 | const CodeGenerator& codegen) |
| 341 | : output_(output), graph_(graph), codegen_(codegen) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 342 | |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 343 | void HGraphVisualizer::PrintHeader(const char* method_name) const { |
| 344 | DCHECK(output_ != nullptr); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 345 | HGraphVisualizerPrinter printer(graph_, *output_, "", true, codegen_); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 346 | printer.StartTag("compilation"); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 347 | printer.PrintProperty("name", method_name); |
| 348 | printer.PrintProperty("method", method_name); |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 349 | printer.PrintTime("date"); |
| 350 | printer.EndTag("compilation"); |
| 351 | } |
| 352 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 353 | void HGraphVisualizer::DumpGraph(const char* pass_name, bool is_after_pass) const { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 354 | DCHECK(output_ != nullptr); |
| 355 | if (!graph_->GetBlocks().IsEmpty()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 356 | HGraphVisualizerPrinter printer(graph_, *output_, pass_name, is_after_pass, codegen_); |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 357 | printer.Run(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 358 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | } // namespace art |