Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [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_SSA_BUILDER_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_SSA_BUILDER_H_ |
| 19 | |
| 20 | #include "nodes.h" |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 21 | #include "optimization.h" |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | static constexpr int kDefaultNumberOfLoops = 2; |
| 26 | |
| 27 | class SsaBuilder : public HGraphVisitor { |
| 28 | public: |
| 29 | explicit SsaBuilder(HGraph* graph) |
| 30 | : HGraphVisitor(graph), |
| 31 | current_locals_(nullptr), |
| 32 | loop_headers_(graph->GetArena(), kDefaultNumberOfLoops), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 33 | locals_for_(graph->GetArena(), graph->GetBlocks().Size()) { |
| 34 | locals_for_.SetSize(graph->GetBlocks().Size()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 35 | } |
| 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 Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 55 | void VisitTemporary(HTemporary* instruction); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 57 | static HInstruction* GetFloatOrDoubleEquivalent(HInstruction* user, |
| 58 | HInstruction* instruction, |
| 59 | Primitive::Type type); |
| 60 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 61 | 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_ |