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" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | static constexpr int kDefaultNumberOfLoops = 2; |
| 25 | |
| 26 | class SsaBuilder : public HGraphVisitor { |
| 27 | public: |
| 28 | explicit SsaBuilder(HGraph* graph) |
| 29 | : HGraphVisitor(graph), |
| 30 | current_locals_(nullptr), |
| 31 | loop_headers_(graph->GetArena(), kDefaultNumberOfLoops), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 32 | locals_for_(graph->GetArena(), graph->GetBlocks().Size()) { |
| 33 | locals_for_.SetSize(graph->GetBlocks().Size()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 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 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 55 | static HInstruction* GetFloatOrDoubleEquivalent(HInstruction* user, |
| 56 | HInstruction* instruction, |
| 57 | Primitive::Type type); |
| 58 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 59 | private: |
| 60 | // Locals for the current block being visited. |
| 61 | GrowableArray<HInstruction*>* current_locals_; |
| 62 | |
| 63 | // Keep track of loop headers found. The last phase of the analysis iterates |
| 64 | // over these blocks to set the inputs of their phis. |
| 65 | GrowableArray<HBasicBlock*> loop_headers_; |
| 66 | |
| 67 | // HEnvironment for each block. |
| 68 | GrowableArray<HEnvironment*> locals_for_; |
| 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(SsaBuilder); |
| 71 | }; |
| 72 | |
| 73 | } // namespace art |
| 74 | |
| 75 | #endif // ART_COMPILER_OPTIMIZING_SSA_BUILDER_H_ |