blob: fbeb7a7dab80404dc16dbb444ca925e143d36398 [file] [log] [blame]
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001/*
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
20#include "utils/allocation.h"
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000021#include "utils/growable_array.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000022
23namespace art {
24
25class ArenaAllocator;
26class Instruction;
27class HBasicBlock;
28class HGraph;
29
30class HGraphBuilder : public ValueObject {
31 public:
32 explicit HGraphBuilder(ArenaAllocator* arena)
33 : arena_(arena),
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000034 branch_targets_(arena, 0),
Nicolas Geoffray818f2102014-02-18 16:43:35 +000035 entry_block_(nullptr),
36 exit_block_(nullptr),
37 current_block_(nullptr),
38 graph_(nullptr) { }
39
40 HGraph* BuildGraph(const uint16_t* start, const uint16_t* end);
41
42 private:
43 // Analyzes the dex instruction and adds HInstruction to the graph
44 // to execute that instruction. Returns whether the instruction can
45 // be handled.
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000046 bool AnalyzeDexInstruction(const Instruction& instruction, int32_t dex_offset);
47
48 // Finds all instructions that start a new block, and populates branch_targets_ with
49 // the newly created blocks.
50 void ComputeBranchTargets(const uint16_t* start, const uint16_t* end);
51 void MaybeUpdateCurrentBlock(size_t index);
52 HBasicBlock* FindBlockStartingAt(int32_t index) const;
Nicolas Geoffray818f2102014-02-18 16:43:35 +000053
54 ArenaAllocator* const arena_;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000055
56 // A list of the size of the dex code holding block information for
57 // the method. If an entry contains a block, then the dex instruction
58 // starting at that entry is the first instruction of a new block.
59 GrowableArray<HBasicBlock*> branch_targets_;
60
Nicolas Geoffray818f2102014-02-18 16:43:35 +000061 HBasicBlock* entry_block_;
62 HBasicBlock* exit_block_;
63 HBasicBlock* current_block_;
64 HGraph* graph_;
65
66 DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
67};
68
69} // namespace art
70
71#endif // ART_COMPILER_OPTIMIZING_BUILDER_H_