blob: b6c6c0b658a2c951bdb479f0353b2f51f34b8383 [file] [log] [blame]
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001/*
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_SSA_BUILDER_H_
18#define ART_COMPILER_OPTIMIZING_SSA_BUILDER_H_
19
20#include "nodes.h"
21
22namespace art {
23
24static constexpr int kDefaultNumberOfLoops = 2;
25
26class SsaBuilder : public HGraphVisitor {
27 public:
28 explicit SsaBuilder(HGraph* graph)
29 : HGraphVisitor(graph),
30 current_locals_(nullptr),
31 loop_headers_(graph->GetArena(), kDefaultNumberOfLoops),
32 locals_for_(graph->GetArena(), graph->GetBlocks()->Size()) {
33 locals_for_.SetSize(graph->GetBlocks()->Size());
34 }
35
36 void BuildSsa();
37
38 GrowableArray<HInstruction*>* GetLocalsFor(HBasicBlock* block) {
39 HEnvironment* env = locals_for_.Get(block->GetBlockId());
40 if (env == nullptr) {
41 env = new (GetGraph()->GetArena()) HEnvironment(
42 GetGraph()->GetArena(), GetGraph()->GetNumberOfVRegs());
43 locals_for_.Put(block->GetBlockId(), env);
44 }
45 return env->GetVRegs();
46 }
47
48 HInstruction* ValueOfLocal(HBasicBlock* block, size_t local);
49
50 void VisitBasicBlock(HBasicBlock* block);
51 void VisitLoadLocal(HLoadLocal* load);
52 void VisitStoreLocal(HStoreLocal* store);
53 void VisitInstruction(HInstruction* instruction);
54
55 private:
56 // Locals for the current block being visited.
57 GrowableArray<HInstruction*>* current_locals_;
58
59 // Keep track of loop headers found. The last phase of the analysis iterates
60 // over these blocks to set the inputs of their phis.
61 GrowableArray<HBasicBlock*> loop_headers_;
62
63 // HEnvironment for each block.
64 GrowableArray<HEnvironment*> locals_for_;
65
66 DISALLOW_COPY_AND_ASSIGN(SsaBuilder);
67};
68
69} // namespace art
70
71#endif // ART_COMPILER_OPTIMIZING_SSA_BUILDER_H_