Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 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 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame^] | 20 | #include "base/arena_containers.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 21 | #include "driver/dex_compilation_unit.h" |
| 22 | #include "handle_scope-inl.h" |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 23 | #include "nodes.h" |
| 24 | #include "optimization.h" |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 25 | #include "optimizing_compiler_stats.h" |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | /** |
| 30 | * Propagates reference types to instructions. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 31 | */ |
Calin Juravle | 6c0c4f2 | 2015-06-12 15:40:42 +0000 | [diff] [blame] | 32 | class ReferenceTypePropagation : public HOptimization { |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 33 | public: |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 34 | ReferenceTypePropagation(HGraph* graph, |
| 35 | StackHandleScopeCollection* handles, |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 36 | const char* name = kReferenceTypePropagationPassName); |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 37 | |
| 38 | void Run() OVERRIDE; |
| 39 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 40 | static constexpr const char* kReferenceTypePropagationPassName = "reference_type_propagation"; |
| 41 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 42 | private: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 43 | void VisitPhi(HPhi* phi); |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 44 | void VisitBasicBlock(HBasicBlock* block); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 45 | void UpdateBoundType(HBoundType* bound_type) SHARED_REQUIRES(Locks::mutator_lock_); |
| 46 | void UpdatePhi(HPhi* phi) SHARED_REQUIRES(Locks::mutator_lock_); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 47 | void BoundTypeForIfNotNull(HBasicBlock* block); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 48 | void BoundTypeForIfInstanceOf(HBasicBlock* block); |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 49 | void ProcessWorklist(); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 50 | void AddToWorklist(HInstruction* instr); |
| 51 | void AddDependentInstructionsToWorklist(HInstruction* instr); |
| 52 | |
| 53 | bool UpdateNullability(HInstruction* instr); |
| 54 | bool UpdateReferenceTypeInfo(HInstruction* instr); |
| 55 | |
| 56 | ReferenceTypeInfo MergeTypes(const ReferenceTypeInfo& a, const ReferenceTypeInfo& b) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 57 | SHARED_REQUIRES(Locks::mutator_lock_); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 58 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 59 | StackHandleScopeCollection* handles_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 60 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame^] | 61 | ArenaVector<HInstruction*> worklist_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 62 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 63 | ReferenceTypeInfo::TypeHandle object_class_handle_; |
| 64 | ReferenceTypeInfo::TypeHandle class_class_handle_; |
| 65 | ReferenceTypeInfo::TypeHandle string_class_handle_; |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 66 | ReferenceTypeInfo::TypeHandle throwable_class_handle_; |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 67 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 68 | static constexpr size_t kDefaultWorklistSize = 8; |
| 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(ReferenceTypePropagation); |
| 71 | }; |
| 72 | |
| 73 | } // namespace art |
| 74 | |
| 75 | #endif // ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_ |