blob: 2207cd6bfac81dea28b46e8408bf7c7f8e63506e [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),
Nicolas Geoffray804d0932014-05-02 08:46:00 +010032 locals_for_(graph->GetArena(), graph->GetBlocks().Size()) {
33 locals_for_.SetSize(graph->GetBlocks().Size());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010034 }
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);
Nicolas Geoffray421e9f92014-11-11 18:21:53 +000054 void VisitTemporary(HTemporary* instruction);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010055
Nicolas Geoffray102cbed2014-10-15 18:31:05 +010056 static HInstruction* GetFloatOrDoubleEquivalent(HInstruction* user,
57 HInstruction* instruction,
58 Primitive::Type type);
59
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010060 private:
61 // Locals for the current block being visited.
62 GrowableArray<HInstruction*>* current_locals_;
63
64 // Keep track of loop headers found. The last phase of the analysis iterates
65 // over these blocks to set the inputs of their phis.
66 GrowableArray<HBasicBlock*> loop_headers_;
67
68 // HEnvironment for each block.
69 GrowableArray<HEnvironment*> locals_for_;
70
71 DISALLOW_COPY_AND_ASSIGN(SsaBuilder);
72};
73
74} // namespace art
75
76#endif // ART_COMPILER_OPTIMIZING_SSA_BUILDER_H_