Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +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 | #ifndef ART_COMPILER_OPTIMIZING_GRAPH_CHECKER_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_GRAPH_CHECKER_H_ |
| 19 | |
| 20 | #include "nodes.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | // A control-flow graph visitor performing various checks. |
| 25 | class GraphChecker : public HGraphVisitor { |
| 26 | public: |
Nicolas Geoffray | 1ddbf6d | 2014-10-01 14:59:23 +0000 | [diff] [blame] | 27 | GraphChecker(ArenaAllocator* allocator, HGraph* graph) |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 28 | : HGraphVisitor(graph), |
| 29 | allocator_(allocator), |
Nicolas Geoffray | 1ddbf6d | 2014-10-01 14:59:23 +0000 | [diff] [blame] | 30 | errors_(allocator, 0) {} |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 31 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 32 | // Check the whole graph (in insertion order). |
| 33 | virtual void Run() { VisitInsertionOrder(); } |
| 34 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 35 | // Check `block`. |
| 36 | virtual void VisitBasicBlock(HBasicBlock* block) OVERRIDE; |
| 37 | |
| 38 | // Check `instruction`. |
| 39 | virtual void VisitInstruction(HInstruction* instruction) OVERRIDE; |
| 40 | |
| 41 | // Was the last visit of the graph valid? |
| 42 | bool IsValid() const { |
| 43 | return errors_.IsEmpty(); |
| 44 | } |
| 45 | |
| 46 | // Get the list of detected errors. |
| 47 | const GrowableArray<std::string>& GetErrors() const { |
| 48 | return errors_; |
| 49 | } |
| 50 | |
| 51 | protected: |
| 52 | ArenaAllocator* const allocator_; |
| 53 | // The block currently visited. |
| 54 | HBasicBlock* current_block_ = nullptr; |
| 55 | // Errors encountered while checking the graph. |
| 56 | GrowableArray<std::string> errors_; |
| 57 | |
| 58 | private: |
| 59 | DISALLOW_COPY_AND_ASSIGN(GraphChecker); |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | // An SSA graph visitor performing various checks. |
| 64 | class SSAChecker : public GraphChecker { |
| 65 | public: |
| 66 | typedef GraphChecker super_type; |
| 67 | |
| 68 | SSAChecker(ArenaAllocator* allocator, HGraph* graph) |
Nicolas Geoffray | 1ddbf6d | 2014-10-01 14:59:23 +0000 | [diff] [blame] | 69 | : GraphChecker(allocator, graph) {} |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 70 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 71 | // Check the whole graph (in reverse post-order). |
| 72 | virtual void Run() { |
| 73 | // VisitReversePostOrder is used instead of VisitInsertionOrder, |
| 74 | // as the latter might visit dead blocks removed by the dominator |
| 75 | // computation. |
| 76 | VisitReversePostOrder(); |
| 77 | } |
| 78 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 79 | // Perform SSA form checks on `block`. |
| 80 | virtual void VisitBasicBlock(HBasicBlock* block) OVERRIDE; |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 81 | // Loop-related checks from block `loop_header`. |
| 82 | void CheckLoop(HBasicBlock* loop_header); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 83 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 84 | // Perform SSA form checks on instructions. |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 85 | virtual void VisitInstruction(HInstruction* instruction) OVERRIDE; |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 86 | virtual void VisitPhi(HPhi* phi) OVERRIDE; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 87 | |
| 88 | private: |
| 89 | DISALLOW_COPY_AND_ASSIGN(SSAChecker); |
| 90 | }; |
| 91 | |
| 92 | } // namespace art |
| 93 | |
| 94 | #endif // ART_COMPILER_OPTIMIZING_GRAPH_CHECKER_H_ |