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 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 19 | #include <dlfcn.h> |
| 20 | |
| 21 | #include <cctype> |
| 22 | #include <sstream> |
| 23 | |
Aart Bik | 09e8d5f | 2016-01-22 16:49:55 -0800 | [diff] [blame] | 24 | #include "bounds_check_elimination.h" |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 25 | #include "builder.h" |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 26 | #include "code_generator.h" |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 27 | #include "dead_code_elimination.h" |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 28 | #include "disassembler.h" |
Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 29 | #include "inliner.h" |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 30 | #include "licm.h" |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 31 | #include "nodes.h" |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 32 | #include "optimization.h" |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 33 | #include "reference_type_propagation.h" |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 34 | #include "register_allocator.h" |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 35 | #include "ssa_liveness_analysis.h" |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 36 | #include "utils/assembler.h" |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 37 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 38 | namespace art { |
| 39 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 40 | static bool HasWhitespace(const char* str) { |
| 41 | DCHECK(str != nullptr); |
| 42 | while (str[0] != 0) { |
| 43 | if (isspace(str[0])) { |
| 44 | return true; |
| 45 | } |
| 46 | str++; |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | class StringList { |
| 52 | public: |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 53 | enum Format { |
| 54 | kArrayBrackets, |
| 55 | kSetBrackets, |
| 56 | }; |
| 57 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 58 | // Create an empty list |
David Brazdil | f1a9ff7 | 2015-05-18 16:04:53 +0100 | [diff] [blame] | 59 | explicit StringList(Format format = kArrayBrackets) : format_(format), is_empty_(true) {} |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 60 | |
| 61 | // Construct StringList from a linked list. List element class T |
| 62 | // must provide methods `GetNext` and `Dump`. |
| 63 | template<class T> |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 64 | explicit StringList(T* first_entry, Format format = kArrayBrackets) : StringList(format) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 65 | for (T* current = first_entry; current != nullptr; current = current->GetNext()) { |
| 66 | current->Dump(NewEntryStream()); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | std::ostream& NewEntryStream() { |
| 71 | if (is_empty_) { |
| 72 | is_empty_ = false; |
| 73 | } else { |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame] | 74 | sstream_ << ","; |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 75 | } |
| 76 | return sstream_; |
| 77 | } |
| 78 | |
| 79 | private: |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 80 | Format format_; |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 81 | bool is_empty_; |
| 82 | std::ostringstream sstream_; |
| 83 | |
| 84 | friend std::ostream& operator<<(std::ostream& os, const StringList& list); |
| 85 | }; |
| 86 | |
| 87 | std::ostream& operator<<(std::ostream& os, const StringList& list) { |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 88 | switch (list.format_) { |
| 89 | case StringList::kArrayBrackets: return os << "[" << list.sstream_.str() << "]"; |
| 90 | case StringList::kSetBrackets: return os << "{" << list.sstream_.str() << "}"; |
| 91 | default: |
| 92 | LOG(FATAL) << "Invalid StringList format"; |
| 93 | UNREACHABLE(); |
| 94 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | typedef Disassembler* create_disasm_prototype(InstructionSet instruction_set, |
| 98 | DisassemblerOptions* options); |
| 99 | class HGraphVisualizerDisassembler { |
| 100 | public: |
| 101 | HGraphVisualizerDisassembler(InstructionSet instruction_set, const uint8_t* base_address) |
David Brazdil | 3a690be | 2015-06-23 10:22:38 +0100 | [diff] [blame] | 102 | : instruction_set_(instruction_set), disassembler_(nullptr) { |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 103 | libart_disassembler_handle_ = |
| 104 | dlopen(kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so", RTLD_NOW); |
| 105 | if (libart_disassembler_handle_ == nullptr) { |
| 106 | LOG(WARNING) << "Failed to dlopen libart-disassembler: " << dlerror(); |
| 107 | return; |
| 108 | } |
| 109 | create_disasm_prototype* create_disassembler = reinterpret_cast<create_disasm_prototype*>( |
| 110 | dlsym(libart_disassembler_handle_, "create_disassembler")); |
| 111 | if (create_disassembler == nullptr) { |
| 112 | LOG(WARNING) << "Could not find create_disassembler entry: " << dlerror(); |
| 113 | return; |
| 114 | } |
| 115 | // Reading the disassembly from 0x0 is easier, so we print relative |
| 116 | // addresses. We will only disassemble the code once everything has |
| 117 | // been generated, so we can read data in literal pools. |
| 118 | disassembler_ = std::unique_ptr<Disassembler>((*create_disassembler)( |
| 119 | instruction_set, |
| 120 | new DisassemblerOptions(/* absolute_addresses */ false, |
| 121 | base_address, |
| 122 | /* can_read_literals */ true))); |
| 123 | } |
| 124 | |
| 125 | ~HGraphVisualizerDisassembler() { |
| 126 | // We need to call ~Disassembler() before we close the library. |
| 127 | disassembler_.reset(); |
| 128 | if (libart_disassembler_handle_ != nullptr) { |
| 129 | dlclose(libart_disassembler_handle_); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void Disassemble(std::ostream& output, size_t start, size_t end) const { |
David Brazdil | 3a690be | 2015-06-23 10:22:38 +0100 | [diff] [blame] | 134 | if (disassembler_ == nullptr) { |
| 135 | return; |
| 136 | } |
| 137 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 138 | const uint8_t* base = disassembler_->GetDisassemblerOptions()->base_address_; |
| 139 | if (instruction_set_ == kThumb2) { |
| 140 | // ARM and Thumb-2 use the same disassembler. The bottom bit of the |
| 141 | // address is used to distinguish between the two. |
| 142 | base += 1; |
| 143 | } |
| 144 | disassembler_->Dump(output, base + start, base + end); |
| 145 | } |
| 146 | |
| 147 | private: |
| 148 | InstructionSet instruction_set_; |
| 149 | std::unique_ptr<Disassembler> disassembler_; |
| 150 | |
| 151 | void* libart_disassembler_handle_; |
| 152 | }; |
| 153 | |
| 154 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 155 | /** |
| 156 | * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra. |
| 157 | */ |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 158 | class HGraphVisualizerPrinter : public HGraphDelegateVisitor { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 159 | public: |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 160 | HGraphVisualizerPrinter(HGraph* graph, |
| 161 | std::ostream& output, |
| 162 | const char* pass_name, |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 163 | bool is_after_pass, |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 164 | bool graph_in_bad_state, |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 165 | const CodeGenerator& codegen, |
| 166 | const DisassemblyInformation* disasm_info = nullptr) |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 167 | : HGraphDelegateVisitor(graph), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 168 | output_(output), |
| 169 | pass_name_(pass_name), |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 170 | is_after_pass_(is_after_pass), |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 171 | graph_in_bad_state_(graph_in_bad_state), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 172 | codegen_(codegen), |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 173 | disasm_info_(disasm_info), |
| 174 | disassembler_(disasm_info_ != nullptr |
| 175 | ? new HGraphVisualizerDisassembler( |
| 176 | codegen_.GetInstructionSet(), |
| 177 | codegen_.GetAssembler().CodeBufferBaseAddress()) |
| 178 | : nullptr), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 179 | indent_(0) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 180 | |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 181 | void Flush() { |
| 182 | // We use "\n" instead of std::endl to avoid implicit flushing which |
| 183 | // generates too many syscalls during debug-GC tests (b/27826765). |
| 184 | output_ << std::flush; |
| 185 | } |
| 186 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 187 | void StartTag(const char* name) { |
| 188 | AddIndent(); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 189 | output_ << "begin_" << name << "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 190 | indent_++; |
| 191 | } |
| 192 | |
| 193 | void EndTag(const char* name) { |
| 194 | indent_--; |
| 195 | AddIndent(); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 196 | output_ << "end_" << name << "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void PrintProperty(const char* name, const char* property) { |
| 200 | AddIndent(); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 201 | output_ << name << " \"" << property << "\"\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void PrintProperty(const char* name, const char* property, int id) { |
| 205 | AddIndent(); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 206 | output_ << name << " \"" << property << id << "\"\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | void PrintEmptyProperty(const char* name) { |
| 210 | AddIndent(); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 211 | output_ << name << "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void PrintTime(const char* name) { |
| 215 | AddIndent(); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 216 | output_ << name << " " << time(nullptr) << "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void PrintInt(const char* name, int value) { |
| 220 | AddIndent(); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 221 | output_ << name << " " << value << "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void AddIndent() { |
| 225 | for (size_t i = 0; i < indent_; ++i) { |
| 226 | output_ << " "; |
| 227 | } |
| 228 | } |
| 229 | |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 230 | char GetTypeId(Primitive::Type type) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 231 | // Note that Primitive::Descriptor would not work for us |
| 232 | // because it does not handle reference types (that is kPrimNot). |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 233 | switch (type) { |
| 234 | case Primitive::kPrimBoolean: return 'z'; |
| 235 | case Primitive::kPrimByte: return 'b'; |
| 236 | case Primitive::kPrimChar: return 'c'; |
| 237 | case Primitive::kPrimShort: return 's'; |
| 238 | case Primitive::kPrimInt: return 'i'; |
| 239 | case Primitive::kPrimLong: return 'j'; |
| 240 | case Primitive::kPrimFloat: return 'f'; |
| 241 | case Primitive::kPrimDouble: return 'd'; |
| 242 | case Primitive::kPrimNot: return 'l'; |
| 243 | case Primitive::kPrimVoid: return 'v'; |
| 244 | } |
| 245 | LOG(FATAL) << "Unreachable"; |
| 246 | return 'v'; |
| 247 | } |
| 248 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 249 | void PrintPredecessors(HBasicBlock* block) { |
| 250 | AddIndent(); |
| 251 | output_ << "predecessors"; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 252 | for (HBasicBlock* predecessor : block->GetPredecessors()) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 253 | output_ << " \"B" << predecessor->GetBlockId() << "\" "; |
| 254 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 255 | if (block->IsEntryBlock() && (disasm_info_ != nullptr)) { |
| 256 | output_ << " \"" << kDisassemblyBlockFrameEntry << "\" "; |
| 257 | } |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 258 | output_<< "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | void PrintSuccessors(HBasicBlock* block) { |
| 262 | AddIndent(); |
| 263 | output_ << "successors"; |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 264 | for (HBasicBlock* successor : block->GetNormalSuccessors()) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 265 | output_ << " \"B" << successor->GetBlockId() << "\" "; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 266 | } |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 267 | output_<< "\n"; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void PrintExceptionHandlers(HBasicBlock* block) { |
| 271 | AddIndent(); |
| 272 | output_ << "xhandlers"; |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 273 | for (HBasicBlock* handler : block->GetExceptionalSuccessors()) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 274 | output_ << " \"B" << handler->GetBlockId() << "\" "; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 275 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 276 | if (block->IsExitBlock() && |
| 277 | (disasm_info_ != nullptr) && |
| 278 | !disasm_info_->GetSlowPathIntervals().empty()) { |
| 279 | output_ << " \"" << kDisassemblyBlockSlowPaths << "\" "; |
| 280 | } |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 281 | output_<< "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 282 | } |
| 283 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 284 | void DumpLocation(std::ostream& stream, const Location& location) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 285 | if (location.IsRegister()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 286 | codegen_.DumpCoreRegister(stream, location.reg()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 287 | } else if (location.IsFpuRegister()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 288 | codegen_.DumpFloatingPointRegister(stream, location.reg()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 289 | } else if (location.IsConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 290 | stream << "#"; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 291 | HConstant* constant = location.GetConstant(); |
| 292 | if (constant->IsIntConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 293 | stream << constant->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 294 | } else if (constant->IsLongConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 295 | stream << constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 296 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 297 | } else if (location.IsInvalid()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 298 | stream << "invalid"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 299 | } else if (location.IsStackSlot()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 300 | stream << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 301 | } else if (location.IsFpuRegisterPair()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 302 | codegen_.DumpFloatingPointRegister(stream, location.low()); |
| 303 | stream << "|"; |
| 304 | codegen_.DumpFloatingPointRegister(stream, location.high()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 305 | } else if (location.IsRegisterPair()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 306 | codegen_.DumpCoreRegister(stream, location.low()); |
| 307 | stream << "|"; |
| 308 | codegen_.DumpCoreRegister(stream, location.high()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 309 | } else if (location.IsUnallocated()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 310 | stream << "unallocated"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 311 | } else { |
| 312 | DCHECK(location.IsDoubleStackSlot()); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 313 | stream << "2x" << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 317 | std::ostream& StartAttributeStream(const char* name = nullptr) { |
| 318 | if (name == nullptr) { |
| 319 | output_ << " "; |
| 320 | } else { |
| 321 | DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes"; |
| 322 | output_ << " " << name << ":"; |
| 323 | } |
| 324 | return output_; |
| 325 | } |
| 326 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 327 | void VisitParallelMove(HParallelMove* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 328 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
| 329 | StringList moves; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 330 | for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) { |
| 331 | MoveOperands* move = instruction->MoveOperandsAt(i); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 332 | std::ostream& str = moves.NewEntryStream(); |
| 333 | DumpLocation(str, move->GetSource()); |
| 334 | str << "->"; |
| 335 | DumpLocation(str, move->GetDestination()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 336 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 337 | StartAttributeStream("moves") << moves; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 338 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 339 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 340 | void VisitIntConstant(HIntConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 341 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 342 | } |
| 343 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 344 | void VisitLongConstant(HLongConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 345 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 346 | } |
| 347 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 348 | void VisitFloatConstant(HFloatConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 349 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 350 | } |
| 351 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 352 | void VisitDoubleConstant(HDoubleConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 353 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 356 | void VisitPhi(HPhi* phi) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 357 | StartAttributeStream("reg") << phi->GetRegNumber(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 358 | StartAttributeStream("is_catch_phi") << std::boolalpha << phi->IsCatchPhi() << std::noboolalpha; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 361 | void VisitMemoryBarrier(HMemoryBarrier* barrier) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 362 | StartAttributeStream("kind") << barrier->GetBarrierKind(); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 363 | } |
| 364 | |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 365 | void VisitMonitorOperation(HMonitorOperation* monitor) OVERRIDE { |
| 366 | StartAttributeStream("kind") << (monitor->IsEnter() ? "enter" : "exit"); |
| 367 | } |
| 368 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 369 | void VisitLoadClass(HLoadClass* load_class) OVERRIDE { |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 370 | StartAttributeStream("gen_clinit_check") << std::boolalpha |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 371 | << load_class->MustGenerateClinitCheck() << std::noboolalpha; |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 372 | StartAttributeStream("needs_access_check") << std::boolalpha |
| 373 | << load_class->NeedsAccessCheck() << std::noboolalpha; |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 376 | void VisitLoadString(HLoadString* load_string) OVERRIDE { |
| 377 | StartAttributeStream("load_kind") << load_string->GetLoadKind(); |
| 378 | } |
| 379 | |
Guillaume "Vermeille" Sanchez | 9099ef7 | 2015-05-20 15:19:21 +0100 | [diff] [blame] | 380 | void VisitCheckCast(HCheckCast* check_cast) OVERRIDE { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 381 | StartAttributeStream("check_kind") << check_cast->GetTypeCheckKind(); |
Guillaume "Vermeille" Sanchez | 9099ef7 | 2015-05-20 15:19:21 +0100 | [diff] [blame] | 382 | StartAttributeStream("must_do_null_check") << std::boolalpha |
| 383 | << check_cast->MustDoNullCheck() << std::noboolalpha; |
| 384 | } |
| 385 | |
| 386 | void VisitInstanceOf(HInstanceOf* instance_of) OVERRIDE { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 387 | StartAttributeStream("check_kind") << instance_of->GetTypeCheckKind(); |
Guillaume "Vermeille" Sanchez | 9099ef7 | 2015-05-20 15:19:21 +0100 | [diff] [blame] | 388 | StartAttributeStream("must_do_null_check") << std::boolalpha |
| 389 | << instance_of->MustDoNullCheck() << std::noboolalpha; |
| 390 | } |
| 391 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame^] | 392 | void VisitArrayLength(HArrayLength* array_length) OVERRIDE { |
| 393 | StartAttributeStream("is_string_length") << std::boolalpha |
| 394 | << array_length->IsStringLength() << std::noboolalpha; |
| 395 | } |
| 396 | |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 397 | void VisitArraySet(HArraySet* array_set) OVERRIDE { |
| 398 | StartAttributeStream("value_can_be_null") << std::boolalpha |
| 399 | << array_set->GetValueCanBeNull() << std::noboolalpha; |
Roland Levillain | b133ec6 | 2016-03-23 12:40:35 +0000 | [diff] [blame] | 400 | StartAttributeStream("needs_type_check") << std::boolalpha |
| 401 | << array_set->NeedsTypeCheck() << std::noboolalpha; |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 404 | void VisitCompare(HCompare* compare) OVERRIDE { |
| 405 | ComparisonBias bias = compare->GetBias(); |
| 406 | StartAttributeStream("bias") << (bias == ComparisonBias::kGtBias |
| 407 | ? "gt" |
| 408 | : (bias == ComparisonBias::kLtBias ? "lt" : "none")); |
| 409 | } |
| 410 | |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 411 | void VisitInvoke(HInvoke* invoke) OVERRIDE { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 412 | StartAttributeStream("dex_file_index") << invoke->GetDexMethodIndex(); |
Nicolas Geoffray | 242febb | 2015-07-01 16:10:44 +0100 | [diff] [blame] | 413 | StartAttributeStream("method_name") << PrettyMethod( |
| 414 | invoke->GetDexMethodIndex(), GetGraph()->GetDexFile(), /* with_signature */ false); |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 415 | } |
| 416 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 417 | void VisitInvokeUnresolved(HInvokeUnresolved* invoke) OVERRIDE { |
| 418 | VisitInvoke(invoke); |
| 419 | StartAttributeStream("invoke_type") << invoke->GetOriginalInvokeType(); |
| 420 | } |
| 421 | |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 422 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 423 | VisitInvoke(invoke); |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 424 | StartAttributeStream("method_load_kind") << invoke->GetMethodLoadKind(); |
Scott Wakeling | d60a1af | 2015-07-22 14:32:44 +0100 | [diff] [blame] | 425 | StartAttributeStream("intrinsic") << invoke->GetIntrinsic(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 426 | if (invoke->IsStatic()) { |
| 427 | StartAttributeStream("clinit_check") << invoke->GetClinitCheckRequirement(); |
| 428 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 431 | void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE { |
| 432 | VisitInvoke(invoke); |
| 433 | StartAttributeStream("intrinsic") << invoke->GetIntrinsic(); |
| 434 | } |
| 435 | |
David Brazdil | 11edec7 | 2016-03-24 12:40:52 +0000 | [diff] [blame] | 436 | void VisitInstanceFieldGet(HInstanceFieldGet* iget) OVERRIDE { |
| 437 | StartAttributeStream("field_name") << PrettyField(iget->GetFieldInfo().GetFieldIndex(), |
| 438 | iget->GetFieldInfo().GetDexFile(), |
| 439 | /* with type */ false); |
| 440 | StartAttributeStream("field_type") << iget->GetFieldType(); |
| 441 | } |
| 442 | |
| 443 | void VisitInstanceFieldSet(HInstanceFieldSet* iset) OVERRIDE { |
| 444 | StartAttributeStream("field_name") << PrettyField(iset->GetFieldInfo().GetFieldIndex(), |
| 445 | iset->GetFieldInfo().GetDexFile(), |
| 446 | /* with type */ false); |
| 447 | StartAttributeStream("field_type") << iset->GetFieldType(); |
| 448 | } |
| 449 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 450 | void VisitUnresolvedInstanceFieldGet(HUnresolvedInstanceFieldGet* field_access) OVERRIDE { |
| 451 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 452 | } |
| 453 | |
| 454 | void VisitUnresolvedInstanceFieldSet(HUnresolvedInstanceFieldSet* field_access) OVERRIDE { |
| 455 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 456 | } |
| 457 | |
| 458 | void VisitUnresolvedStaticFieldGet(HUnresolvedStaticFieldGet* field_access) OVERRIDE { |
| 459 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 460 | } |
| 461 | |
| 462 | void VisitUnresolvedStaticFieldSet(HUnresolvedStaticFieldSet* field_access) OVERRIDE { |
| 463 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 464 | } |
| 465 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 466 | void VisitTryBoundary(HTryBoundary* try_boundary) OVERRIDE { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 467 | StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit"); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 470 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 471 | void VisitMultiplyAccumulate(HMultiplyAccumulate* instruction) OVERRIDE { |
| 472 | StartAttributeStream("kind") << instruction->GetOpKind(); |
| 473 | } |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 474 | |
| 475 | void VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) OVERRIDE { |
| 476 | StartAttributeStream("kind") << instruction->GetOpKind(); |
| 477 | } |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 478 | #endif |
| 479 | |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 480 | #ifdef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 481 | void VisitArm64DataProcWithShifterOp(HArm64DataProcWithShifterOp* instruction) OVERRIDE { |
| 482 | StartAttributeStream("kind") << instruction->GetInstrKind() << "+" << instruction->GetOpKind(); |
| 483 | if (HArm64DataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())) { |
| 484 | StartAttributeStream("shift") << instruction->GetShiftAmount(); |
| 485 | } |
| 486 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 487 | #endif |
| 488 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 489 | bool IsPass(const char* name) { |
| 490 | return strcmp(pass_name_, name) == 0; |
| 491 | } |
| 492 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 493 | void PrintInstruction(HInstruction* instruction) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 494 | output_ << instruction->DebugName(); |
| 495 | if (instruction->InputCount() > 0) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 496 | StringList inputs; |
| 497 | for (HInputIterator it(instruction); !it.Done(); it.Advance()) { |
| 498 | inputs.NewEntryStream() << GetTypeId(it.Current()->GetType()) << it.Current()->GetId(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 499 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 500 | StartAttributeStream() << inputs; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 501 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 502 | instruction->Accept(this); |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 503 | if (instruction->HasEnvironment()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 504 | StringList envs; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 505 | for (HEnvironment* environment = instruction->GetEnvironment(); |
| 506 | environment != nullptr; |
| 507 | environment = environment->GetParent()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 508 | StringList vregs; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 509 | for (size_t i = 0, e = environment->Size(); i < e; ++i) { |
| 510 | HInstruction* insn = environment->GetInstructionAt(i); |
| 511 | if (insn != nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 512 | vregs.NewEntryStream() << GetTypeId(insn->GetType()) << insn->GetId(); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 513 | } else { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 514 | vregs.NewEntryStream() << "_"; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 515 | } |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 516 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 517 | envs.NewEntryStream() << vregs; |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 518 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 519 | StartAttributeStream("env") << envs; |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 520 | } |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 521 | if (IsPass(SsaLivenessAnalysis::kLivenessPassName) |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 522 | && is_after_pass_ |
| 523 | && instruction->GetLifetimePosition() != kNoLifetime) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 524 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 525 | if (instruction->HasLiveInterval()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 526 | LiveInterval* interval = instruction->GetLiveInterval(); |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 527 | StartAttributeStream("ranges") |
| 528 | << StringList(interval->GetFirstRange(), StringList::kSetBrackets); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 529 | StartAttributeStream("uses") << StringList(interval->GetFirstUse()); |
| 530 | StartAttributeStream("env_uses") << StringList(interval->GetFirstEnvironmentUse()); |
| 531 | StartAttributeStream("is_fixed") << interval->IsFixed(); |
| 532 | StartAttributeStream("is_split") << interval->IsSplit(); |
| 533 | StartAttributeStream("is_low") << interval->IsLowInterval(); |
| 534 | StartAttributeStream("is_high") << interval->IsHighInterval(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 535 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 539 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 540 | LocationSummary* locations = instruction->GetLocations(); |
| 541 | if (locations != nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 542 | StringList inputs; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 543 | for (size_t i = 0; i < instruction->InputCount(); ++i) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 544 | DumpLocation(inputs.NewEntryStream(), locations->InAt(i)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 545 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 546 | std::ostream& attr = StartAttributeStream("locations"); |
| 547 | attr << inputs << "->"; |
| 548 | DumpLocation(attr, locations->Out()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 549 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | if (IsPass(LICM::kLoopInvariantCodeMotionPassName) |
| 553 | || IsPass(HDeadCodeElimination::kFinalDeadCodeEliminationPassName) |
| 554 | || IsPass(HDeadCodeElimination::kInitialDeadCodeEliminationPassName) |
Aart Bik | 09e8d5f | 2016-01-22 16:49:55 -0800 | [diff] [blame] | 555 | || IsPass(BoundsCheckElimination::kBoundsCheckEliminationPassName) |
Nicolas Geoffray | ad4ed08 | 2016-01-27 14:15:23 +0000 | [diff] [blame] | 556 | || IsPass(RegisterAllocator::kRegisterAllocatorPassName) |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 557 | || IsPass(HGraphBuilder::kBuilderPassName)) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 558 | HLoopInformation* info = instruction->GetBlock()->GetLoopInformation(); |
| 559 | if (info == nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 560 | StartAttributeStream("loop") << "none"; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 561 | } else { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 562 | StartAttributeStream("loop") << "B" << info->GetHeader()->GetBlockId(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 563 | HLoopInformation* outer = info->GetPreHeader()->GetLoopInformation(); |
| 564 | if (outer != nullptr) { |
| 565 | StartAttributeStream("outer_loop") << "B" << outer->GetHeader()->GetBlockId(); |
| 566 | } else { |
| 567 | StartAttributeStream("outer_loop") << "none"; |
| 568 | } |
| 569 | StartAttributeStream("irreducible") |
| 570 | << std::boolalpha << info->IsIrreducible() << std::noboolalpha; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 571 | } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 572 | } |
| 573 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 574 | if ((IsPass(HGraphBuilder::kBuilderPassName) |
Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 575 | || IsPass(HInliner::kInlinerPassName)) |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 576 | && (instruction->GetType() == Primitive::kPrimNot)) { |
| 577 | ReferenceTypeInfo info = instruction->IsLoadClass() |
| 578 | ? instruction->AsLoadClass()->GetLoadedClassRTI() |
| 579 | : instruction->GetReferenceTypeInfo(); |
| 580 | ScopedObjectAccess soa(Thread::Current()); |
| 581 | if (info.IsValid()) { |
| 582 | StartAttributeStream("klass") << PrettyDescriptor(info.GetTypeHandle().Get()); |
| 583 | StartAttributeStream("can_be_null") |
| 584 | << std::boolalpha << instruction->CanBeNull() << std::noboolalpha; |
| 585 | StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 586 | } else if (instruction->IsLoadClass()) { |
| 587 | StartAttributeStream("klass") << "unresolved"; |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 588 | } else { |
Mark Mendell | b2d38fd | 2015-11-16 12:21:53 -0500 | [diff] [blame] | 589 | // The NullConstant may be added to the graph during other passes that happen between |
| 590 | // ReferenceTypePropagation and Inliner (e.g. InstructionSimplifier). If the inliner |
| 591 | // doesn't run or doesn't inline anything, the NullConstant remains untyped. |
| 592 | // So we should check NullConstants for validity only after reference type propagation. |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 593 | DCHECK(graph_in_bad_state_ || |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 594 | (!is_after_pass_ && IsPass(HGraphBuilder::kBuilderPassName))) |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 595 | << instruction->DebugName() << instruction->GetId() << " has invalid rti " |
| 596 | << (is_after_pass_ ? "after" : "before") << " pass " << pass_name_; |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 597 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 598 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 599 | if (disasm_info_ != nullptr) { |
| 600 | DCHECK(disassembler_ != nullptr); |
| 601 | // If the information is available, disassemble the code generated for |
| 602 | // this instruction. |
| 603 | auto it = disasm_info_->GetInstructionIntervals().find(instruction); |
| 604 | if (it != disasm_info_->GetInstructionIntervals().end() |
| 605 | && it->second.start != it->second.end) { |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 606 | output_ << "\n"; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 607 | disassembler_->Disassemble(output_, it->second.start, it->second.end); |
| 608 | } |
| 609 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | void PrintInstructions(const HInstructionList& list) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 613 | for (HInstructionIterator it(list); !it.Done(); it.Advance()) { |
| 614 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 615 | int bci = 0; |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 616 | size_t num_uses = instruction->GetUses().SizeSlow(); |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 617 | AddIndent(); |
| 618 | output_ << bci << " " << num_uses << " " |
| 619 | << GetTypeId(instruction->GetType()) << instruction->GetId() << " "; |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 620 | PrintInstruction(instruction); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 621 | output_ << " " << kEndInstructionMarker << "\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 625 | void DumpStartOfDisassemblyBlock(const char* block_name, |
| 626 | int predecessor_index, |
| 627 | int successor_index) { |
| 628 | StartTag("block"); |
| 629 | PrintProperty("name", block_name); |
| 630 | PrintInt("from_bci", -1); |
| 631 | PrintInt("to_bci", -1); |
| 632 | if (predecessor_index != -1) { |
| 633 | PrintProperty("predecessors", "B", predecessor_index); |
| 634 | } else { |
| 635 | PrintEmptyProperty("predecessors"); |
| 636 | } |
| 637 | if (successor_index != -1) { |
| 638 | PrintProperty("successors", "B", successor_index); |
| 639 | } else { |
| 640 | PrintEmptyProperty("successors"); |
| 641 | } |
| 642 | PrintEmptyProperty("xhandlers"); |
| 643 | PrintEmptyProperty("flags"); |
| 644 | StartTag("states"); |
| 645 | StartTag("locals"); |
| 646 | PrintInt("size", 0); |
| 647 | PrintProperty("method", "None"); |
| 648 | EndTag("locals"); |
| 649 | EndTag("states"); |
| 650 | StartTag("HIR"); |
| 651 | } |
| 652 | |
| 653 | void DumpEndOfDisassemblyBlock() { |
| 654 | EndTag("HIR"); |
| 655 | EndTag("block"); |
| 656 | } |
| 657 | |
| 658 | void DumpDisassemblyBlockForFrameEntry() { |
| 659 | DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry, |
| 660 | -1, |
| 661 | GetGraph()->GetEntryBlock()->GetBlockId()); |
| 662 | output_ << " 0 0 disasm " << kDisassemblyBlockFrameEntry << " "; |
| 663 | GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval(); |
| 664 | if (frame_entry.start != frame_entry.end) { |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 665 | output_ << "\n"; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 666 | disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end); |
| 667 | } |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 668 | output_ << kEndInstructionMarker << "\n"; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 669 | DumpEndOfDisassemblyBlock(); |
| 670 | } |
| 671 | |
| 672 | void DumpDisassemblyBlockForSlowPaths() { |
| 673 | if (disasm_info_->GetSlowPathIntervals().empty()) { |
| 674 | return; |
| 675 | } |
| 676 | // If the graph has an exit block we attach the block for the slow paths |
| 677 | // after it. Else we just add the block to the graph without linking it to |
| 678 | // any other. |
| 679 | DumpStartOfDisassemblyBlock( |
| 680 | kDisassemblyBlockSlowPaths, |
| 681 | GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1, |
| 682 | -1); |
| 683 | for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) { |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 684 | output_ << " 0 0 disasm " << info.slow_path->GetDescription() << "\n"; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 685 | disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 686 | output_ << kEndInstructionMarker << "\n"; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 687 | } |
| 688 | DumpEndOfDisassemblyBlock(); |
| 689 | } |
| 690 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 691 | void Run() { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 692 | StartTag("cfg"); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 693 | std::string pass_desc = std::string(pass_name_) |
| 694 | + " (" |
| 695 | + (is_after_pass_ ? "after" : "before") |
| 696 | + (graph_in_bad_state_ ? ", bad_state" : "") |
| 697 | + ")"; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 698 | PrintProperty("name", pass_desc.c_str()); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 699 | if (disasm_info_ != nullptr) { |
| 700 | DumpDisassemblyBlockForFrameEntry(); |
| 701 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 702 | VisitInsertionOrder(); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 703 | if (disasm_info_ != nullptr) { |
| 704 | DumpDisassemblyBlockForSlowPaths(); |
| 705 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 706 | EndTag("cfg"); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 707 | Flush(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 708 | } |
| 709 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 710 | void VisitBasicBlock(HBasicBlock* block) OVERRIDE { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 711 | StartTag("block"); |
| 712 | PrintProperty("name", "B", block->GetBlockId()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 713 | if (block->GetLifetimeStart() != kNoLifetime) { |
| 714 | // Piggy back on these fields to show the lifetime of the block. |
| 715 | PrintInt("from_bci", block->GetLifetimeStart()); |
| 716 | PrintInt("to_bci", block->GetLifetimeEnd()); |
| 717 | } else { |
| 718 | PrintInt("from_bci", -1); |
| 719 | PrintInt("to_bci", -1); |
| 720 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 721 | PrintPredecessors(block); |
| 722 | PrintSuccessors(block); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 723 | PrintExceptionHandlers(block); |
| 724 | |
| 725 | if (block->IsCatchBlock()) { |
| 726 | PrintProperty("flags", "catch_block"); |
| 727 | } else { |
| 728 | PrintEmptyProperty("flags"); |
| 729 | } |
| 730 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 731 | if (block->GetDominator() != nullptr) { |
| 732 | PrintProperty("dominator", "B", block->GetDominator()->GetBlockId()); |
| 733 | } |
| 734 | |
| 735 | StartTag("states"); |
| 736 | StartTag("locals"); |
| 737 | PrintInt("size", 0); |
| 738 | PrintProperty("method", "None"); |
| 739 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 740 | AddIndent(); |
| 741 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 742 | output_ << instruction->GetId() << " " << GetTypeId(instruction->GetType()) |
| 743 | << instruction->GetId() << "[ "; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 744 | for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) { |
| 745 | output_ << inputs.Current()->GetId() << " "; |
| 746 | } |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 747 | output_ << "]\n"; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 748 | } |
| 749 | EndTag("locals"); |
| 750 | EndTag("states"); |
| 751 | |
| 752 | StartTag("HIR"); |
| 753 | PrintInstructions(block->GetPhis()); |
| 754 | PrintInstructions(block->GetInstructions()); |
| 755 | EndTag("HIR"); |
| 756 | EndTag("block"); |
| 757 | } |
| 758 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 759 | static constexpr const char* const kEndInstructionMarker = "<|@"; |
| 760 | static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry"; |
| 761 | static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths"; |
| 762 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 763 | private: |
| 764 | std::ostream& output_; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 765 | const char* pass_name_; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 766 | const bool is_after_pass_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 767 | const bool graph_in_bad_state_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 768 | const CodeGenerator& codegen_; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 769 | const DisassemblyInformation* disasm_info_; |
| 770 | std::unique_ptr<HGraphVisualizerDisassembler> disassembler_; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 771 | size_t indent_; |
| 772 | |
| 773 | DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter); |
| 774 | }; |
| 775 | |
| 776 | HGraphVisualizer::HGraphVisualizer(std::ostream* output, |
| 777 | HGraph* graph, |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 778 | const CodeGenerator& codegen) |
| 779 | : output_(output), graph_(graph), codegen_(codegen) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 780 | |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 781 | void HGraphVisualizer::PrintHeader(const char* method_name) const { |
| 782 | DCHECK(output_ != nullptr); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 783 | HGraphVisualizerPrinter printer(graph_, *output_, "", true, false, codegen_); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 784 | printer.StartTag("compilation"); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 785 | printer.PrintProperty("name", method_name); |
| 786 | printer.PrintProperty("method", method_name); |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 787 | printer.PrintTime("date"); |
| 788 | printer.EndTag("compilation"); |
David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 789 | printer.Flush(); |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 790 | } |
| 791 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 792 | void HGraphVisualizer::DumpGraph(const char* pass_name, |
| 793 | bool is_after_pass, |
| 794 | bool graph_in_bad_state) const { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 795 | DCHECK(output_ != nullptr); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 796 | if (!graph_->GetBlocks().empty()) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 797 | HGraphVisualizerPrinter printer(graph_, |
| 798 | *output_, |
| 799 | pass_name, |
| 800 | is_after_pass, |
| 801 | graph_in_bad_state, |
| 802 | codegen_); |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 803 | printer.Run(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 804 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 805 | } |
| 806 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 807 | void HGraphVisualizer::DumpGraphWithDisassembly() const { |
| 808 | DCHECK(output_ != nullptr); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 809 | if (!graph_->GetBlocks().empty()) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 810 | HGraphVisualizerPrinter printer(graph_, |
| 811 | *output_, |
| 812 | "disassembly", |
| 813 | /* is_after_pass */ true, |
| 814 | /* graph_in_bad_state */ false, |
| 815 | codegen_, |
| 816 | codegen_.GetDisassemblyInformation()); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 817 | printer.Run(); |
| 818 | } |
| 819 | } |
| 820 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 821 | } // namespace art |