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_BUILDER_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_BUILDER_H_ |
| 19 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 20 | #include "dex_file.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 21 | #include "utils/allocation.h" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 22 | #include "utils/growable_array.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | class ArenaAllocator; |
| 27 | class Instruction; |
| 28 | class HBasicBlock; |
| 29 | class HGraph; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 30 | class HIntConstant; |
| 31 | class HInstruction; |
| 32 | class HLocal; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 33 | |
| 34 | class HGraphBuilder : public ValueObject { |
| 35 | public: |
| 36 | explicit HGraphBuilder(ArenaAllocator* arena) |
| 37 | : arena_(arena), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 38 | branch_targets_(arena, 0), |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 39 | locals_(arena, 0), |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 40 | entry_block_(nullptr), |
| 41 | exit_block_(nullptr), |
| 42 | current_block_(nullptr), |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 43 | graph_(nullptr), |
| 44 | constant0_(nullptr) { } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 45 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 46 | HGraph* BuildGraph(const DexFile::CodeItem& code); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | // Analyzes the dex instruction and adds HInstruction to the graph |
| 50 | // to execute that instruction. Returns whether the instruction can |
| 51 | // be handled. |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 52 | bool AnalyzeDexInstruction(const Instruction& instruction, int32_t dex_offset); |
| 53 | |
| 54 | // Finds all instructions that start a new block, and populates branch_targets_ with |
| 55 | // the newly created blocks. |
| 56 | void ComputeBranchTargets(const uint16_t* start, const uint16_t* end); |
| 57 | void MaybeUpdateCurrentBlock(size_t index); |
| 58 | HBasicBlock* FindBlockStartingAt(int32_t index) const; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 59 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 60 | HIntConstant* GetConstant0(); |
| 61 | HIntConstant* GetConstant(int constant); |
| 62 | void InitializeLocals(int count); |
| 63 | HLocal* GetLocalAt(int register_index) const; |
| 64 | void UpdateLocal(int register_index, HInstruction* instruction) const; |
| 65 | HInstruction* LoadLocal(int register_index) const; |
| 66 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 68 | |
| 69 | // A list of the size of the dex code holding block information for |
| 70 | // the method. If an entry contains a block, then the dex instruction |
| 71 | // starting at that entry is the first instruction of a new block. |
| 72 | GrowableArray<HBasicBlock*> branch_targets_; |
| 73 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 74 | GrowableArray<HLocal*> locals_; |
| 75 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 76 | HBasicBlock* entry_block_; |
| 77 | HBasicBlock* exit_block_; |
| 78 | HBasicBlock* current_block_; |
| 79 | HGraph* graph_; |
| 80 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 81 | HIntConstant* constant0_; |
| 82 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 83 | DISALLOW_COPY_AND_ASSIGN(HGraphBuilder); |
| 84 | }; |
| 85 | |
| 86 | } // namespace art |
| 87 | |
| 88 | #endif // ART_COMPILER_OPTIMIZING_BUILDER_H_ |