reference_type_propagation.h revision d9994f069dfeaa32ba929ca78816b5b83e2a4134
1/* 2 * Copyright (C) 2015 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_REFERENCE_TYPE_PROPAGATION_H_ 18#define ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_ 19 20#include "base/arena_containers.h" 21#include "driver/dex_compilation_unit.h" 22#include "handle_scope-inl.h" 23#include "nodes.h" 24#include "optimization.h" 25#include "optimizing_compiler_stats.h" 26 27namespace art { 28 29/** 30 * Propagates reference types to instructions. 31 */ 32class ReferenceTypePropagation : public HOptimization { 33 public: 34 ReferenceTypePropagation(HGraph* graph, 35 StackHandleScopeCollection* handles, 36 bool is_first_run, 37 const char* name = kReferenceTypePropagationPassName); 38 39 // Visit a single instruction. 40 void Visit(HInstruction* instruction); 41 42 void Run() OVERRIDE; 43 44 static constexpr const char* kReferenceTypePropagationPassName = "reference_type_propagation"; 45 46 private: 47 class HandleCache { 48 public: 49 explicit HandleCache(StackHandleScopeCollection* handles) : handles_(handles) { } 50 51 template <typename T> 52 MutableHandle<T> NewHandle(T* object) SHARED_REQUIRES(Locks::mutator_lock_) { 53 return handles_->NewHandle(object); 54 } 55 56 ReferenceTypeInfo::TypeHandle GetObjectClassHandle(); 57 ReferenceTypeInfo::TypeHandle GetClassClassHandle(); 58 ReferenceTypeInfo::TypeHandle GetStringClassHandle(); 59 ReferenceTypeInfo::TypeHandle GetThrowableClassHandle(); 60 61 private: 62 StackHandleScopeCollection* handles_; 63 64 ReferenceTypeInfo::TypeHandle object_class_handle_; 65 ReferenceTypeInfo::TypeHandle class_class_handle_; 66 ReferenceTypeInfo::TypeHandle string_class_handle_; 67 ReferenceTypeInfo::TypeHandle throwable_class_handle_; 68 }; 69 70 class RTPVisitor; 71 72 void VisitPhi(HPhi* phi); 73 void VisitBasicBlock(HBasicBlock* block); 74 void UpdateBoundType(HBoundType* bound_type) SHARED_REQUIRES(Locks::mutator_lock_); 75 void UpdatePhi(HPhi* phi) SHARED_REQUIRES(Locks::mutator_lock_); 76 void BoundTypeForIfNotNull(HBasicBlock* block); 77 void BoundTypeForIfInstanceOf(HBasicBlock* block); 78 void ProcessWorklist(); 79 void AddToWorklist(HInstruction* instr); 80 void AddDependentInstructionsToWorklist(HInstruction* instr); 81 82 bool UpdateNullability(HInstruction* instr); 83 bool UpdateReferenceTypeInfo(HInstruction* instr); 84 85 static void UpdateArrayGet(HArrayGet* instr, HandleCache* handle_cache) 86 SHARED_REQUIRES(Locks::mutator_lock_); 87 88 ReferenceTypeInfo MergeTypes(const ReferenceTypeInfo& a, const ReferenceTypeInfo& b) 89 SHARED_REQUIRES(Locks::mutator_lock_); 90 91 void ValidateTypes(); 92 93 HandleCache handle_cache_; 94 95 ArenaVector<HInstruction*> worklist_; 96 97 // Whether this reference type propagation is the first run we are doing. 98 const bool is_first_run_; 99 100 static constexpr size_t kDefaultWorklistSize = 8; 101 102 DISALLOW_COPY_AND_ASSIGN(ReferenceTypePropagation); 103}; 104 105} // namespace art 106 107#endif // ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_ 108