Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [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 | #ifndef ART_COMPILER_OPTIMIZING_PRETTY_PRINTER_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_PRETTY_PRINTER_H_ |
| 19 | |
| 20 | #include "nodes.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | class HPrettyPrinter : public HGraphVisitor { |
| 25 | public: |
| 26 | explicit HPrettyPrinter(HGraph* graph) : HGraphVisitor(graph) { } |
| 27 | |
| 28 | virtual void VisitInstruction(HInstruction* instruction) { |
| 29 | PrintString(" "); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 30 | PrintInt(instruction->GetId()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 31 | PrintString(": "); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 32 | PrintString(instruction->DebugName()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 33 | if (instruction->InputCount() != 0) { |
| 34 | PrintString("("); |
| 35 | bool first = true; |
| 36 | for (HInputIterator it(instruction); !it.Done(); it.Advance()) { |
| 37 | if (first) { |
| 38 | first = false; |
| 39 | } else { |
| 40 | PrintString(", "); |
| 41 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 42 | PrintInt(it.Current()->GetId()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 43 | } |
| 44 | PrintString(")"); |
| 45 | } |
| 46 | if (instruction->HasUses()) { |
| 47 | PrintString(" ["); |
| 48 | bool first = true; |
| 49 | for (HUseIterator it(instruction); !it.Done(); it.Advance()) { |
| 50 | if (first) { |
| 51 | first = false; |
| 52 | } else { |
| 53 | PrintString(", "); |
| 54 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 55 | PrintInt(it.Current()->GetId()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 56 | } |
| 57 | PrintString("]"); |
| 58 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 59 | PrintNewLine(); |
| 60 | } |
| 61 | |
| 62 | virtual void VisitBasicBlock(HBasicBlock* block) { |
| 63 | PrintString("BasicBlock "); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 64 | PrintInt(block->GetBlockId()); |
| 65 | const GrowableArray<HBasicBlock*>* blocks = block->GetPredecessors(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 66 | if (!blocks->IsEmpty()) { |
| 67 | PrintString(", pred: "); |
| 68 | for (size_t i = 0; i < blocks->Size() -1; i++) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 69 | PrintInt(blocks->Get(i)->GetBlockId()); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 70 | PrintString(", "); |
| 71 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 72 | PrintInt(blocks->Peek()->GetBlockId()); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 73 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 74 | blocks = block->GetSuccessors(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 75 | if (!blocks->IsEmpty()) { |
| 76 | PrintString(", succ: "); |
| 77 | for (size_t i = 0; i < blocks->Size() - 1; i++) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 78 | PrintInt(blocks->Get(i)->GetBlockId()); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 79 | PrintString(", "); |
| 80 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 81 | PrintInt(blocks->Peek()->GetBlockId()); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 82 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 83 | PrintNewLine(); |
| 84 | HGraphVisitor::VisitBasicBlock(block); |
| 85 | } |
| 86 | |
| 87 | virtual void PrintNewLine() = 0; |
| 88 | virtual void PrintInt(int value) = 0; |
| 89 | virtual void PrintString(const char* value) = 0; |
| 90 | |
| 91 | private: |
| 92 | DISALLOW_COPY_AND_ASSIGN(HPrettyPrinter); |
| 93 | }; |
| 94 | |
| 95 | } // namespace art |
| 96 | |
| 97 | #endif // ART_COMPILER_OPTIMIZING_PRETTY_PRINTER_H_ |