blob: 2cbd51aa103ab559e89163263a5bb9047f3836a6 [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"
Nicolas Geoffray31596742014-11-24 15:28:45 +000021#include "optimization.h"
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010022
23namespace art {
24
25static constexpr int kDefaultNumberOfLoops = 2;
26
27class SsaBuilder : public HGraphVisitor {
28 public:
29 explicit SsaBuilder(HGraph* graph)
30 : HGraphVisitor(graph),
31 current_locals_(nullptr),
32 loop_headers_(graph->GetArena(), kDefaultNumberOfLoops),
Nicolas Geoffray804d0932014-05-02 08:46:00 +010033 locals_for_(graph->GetArena(), graph->GetBlocks().Size()) {
34 locals_for_.SetSize(graph->GetBlocks().Size());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010035 }
36
37 void BuildSsa();
38
39 GrowableArray<HInstruction*>* GetLocalsFor(HBasicBlock* block) {
40 HEnvironment* env = locals_for_.Get(block->GetBlockId());
41 if (env == nullptr) {
42 env = new (GetGraph()->GetArena()) HEnvironment(
43 GetGraph()->GetArena(), GetGraph()->GetNumberOfVRegs());
44 locals_for_.Put(block->GetBlockId(), env);
45 }
46 return env->GetVRegs();
47 }
48
49 HInstruction* ValueOfLocal(HBasicBlock* block, size_t local);
50
51 void VisitBasicBlock(HBasicBlock* block);
52 void VisitLoadLocal(HLoadLocal* load);
53 void VisitStoreLocal(HStoreLocal* store);
54 void VisitInstruction(HInstruction* instruction);
Nicolas Geoffray421e9f92014-11-11 18:21:53 +000055 void VisitTemporary(HTemporary* instruction);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010056
Nicolas Geoffray102cbed2014-10-15 18:31:05 +010057 static HInstruction* GetFloatOrDoubleEquivalent(HInstruction* user,
58 HInstruction* instruction,
59 Primitive::Type type);
60
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010061 private:
62 // Locals for the current block being visited.
63 GrowableArray<HInstruction*>* current_locals_;
64
65 // Keep track of loop headers found. The last phase of the analysis iterates
66 // over these blocks to set the inputs of their phis.
67 GrowableArray<HBasicBlock*> loop_headers_;
68
69 // HEnvironment for each block.
70 GrowableArray<HEnvironment*> locals_for_;
71
72 DISALLOW_COPY_AND_ASSIGN(SsaBuilder);
73};
74
75} // namespace art
76
77#endif // ART_COMPILER_OPTIMIZING_SSA_BUILDER_H_