reference_type_propagation.h revision a5ae3c3f468ffe3a317b498d7fde1f8e9325346a
1184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray/* 210e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle * Copyright (C) 2015 The Android Open Source Project 3184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * 4184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * you may not use this file except in compliance with the License. 6184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * You may obtain a copy of the License at 7184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * 8184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * 10184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * See the License for the specific language governing permissions and 14184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * limitations under the License. 15184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray */ 16184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 1710e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#ifndef ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_ 1810e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#define ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_ 19184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 20acf735c13998ad2a175f5a17e7bfce220073279dCalin Juravle#include "driver/dex_compilation_unit.h" 21acf735c13998ad2a175f5a17e7bfce220073279dCalin Juravle#include "handle_scope-inl.h" 22184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray#include "nodes.h" 2310e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#include "optimization.h" 24b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle#include "optimizing_compiler_stats.h" 25184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 26184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffraynamespace art { 27184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 2810e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle/** 2910e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle * Propagates reference types to instructions. 3010e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle */ 316c0c4f230f417ed484bae5c01b79551af7659389Calin Juravleclass ReferenceTypePropagation : public HOptimization { 32184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray public: 33a5ae3c3f468ffe3a317b498d7fde1f8e9325346aCalin Juravle ReferenceTypePropagation(HGraph* graph, 34a5ae3c3f468ffe3a317b498d7fde1f8e9325346aCalin Juravle StackHandleScopeCollection* handles, 35a5ae3c3f468ffe3a317b498d7fde1f8e9325346aCalin Juravle const char* name = kReferenceTypePropagationPassName) 36a5ae3c3f468ffe3a317b498d7fde1f8e9325346aCalin Juravle : HOptimization(graph, name), 37beba9302bec33d72beb582970bf23d056f62641fCalin Juravle handles_(handles), 38beba9302bec33d72beb582970bf23d056f62641fCalin Juravle worklist_(graph->GetArena(), kDefaultWorklistSize) {} 39184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 4010e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle void Run() OVERRIDE; 41184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 427c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe static constexpr const char* kReferenceTypePropagationPassName = "reference_type_propagation"; 437c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe 44184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray private: 45b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle void VisitPhi(HPhi* phi); 46184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray void VisitBasicBlock(HBasicBlock* block); 4790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier void UpdateBoundType(HBoundType* bound_type) SHARED_REQUIRES(Locks::mutator_lock_); 4890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier void UpdatePhi(HPhi* phi) SHARED_REQUIRES(Locks::mutator_lock_); 4961d544bfb812d79f5c9ddad171198836cea719dbCalin Juravle void BoundTypeForIfNotNull(HBasicBlock* block); 50b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle void BoundTypeForIfInstanceOf(HBasicBlock* block); 51184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray void ProcessWorklist(); 52b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle void AddToWorklist(HInstruction* instr); 53b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle void AddDependentInstructionsToWorklist(HInstruction* instr); 54b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle 55b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle bool UpdateNullability(HInstruction* instr); 56b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle bool UpdateReferenceTypeInfo(HInstruction* instr); 57b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle 58b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle ReferenceTypeInfo MergeTypes(const ReferenceTypeInfo& a, const ReferenceTypeInfo& b) 5990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 60acf735c13998ad2a175f5a17e7bfce220073279dCalin Juravle 61acf735c13998ad2a175f5a17e7bfce220073279dCalin Juravle StackHandleScopeCollection* handles_; 62184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 63b1498f67b444c897fa8f1530777ef118e05aa631Calin Juravle GrowableArray<HInstruction*> worklist_; 64184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 65184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray static constexpr size_t kDefaultWorklistSize = 8; 66184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 6710e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle DISALLOW_COPY_AND_ASSIGN(ReferenceTypePropagation); 68184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray}; 69184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 70184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray} // namespace art 71184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 7210e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#endif // ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_ 73