reference_type_propagation.h revision 77e48c64e7c1c0084217b8df1b47ac6367e61cc7
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 "driver/dex_compilation_unit.h"
21#include "handle_scope-inl.h"
22#include "nodes.h"
23#include "optimization.h"
24#include "optimizing_compiler_stats.h"
25
26namespace art {
27
28/**
29 * Propagates reference types to instructions.
30 */
31class ReferenceTypePropagation : public HOptimization, public HGraphDelegateVisitor {
32 public:
33  ReferenceTypePropagation(HGraph* graph, StackHandleScopeCollection* handles)
34    : HOptimization(graph, true, kReferenceTypePropagationPassName),
35      HGraphDelegateVisitor(graph),
36      handles_(handles),
37      worklist_(graph->GetArena(), kDefaultWorklistSize) {}
38
39  void Run() OVERRIDE;
40
41  static constexpr const char* kReferenceTypePropagationPassName = "reference_type_propagation";
42
43 private:
44  void VisitNewInstance(HNewInstance* new_instance);
45  void VisitLoadClass(HLoadClass* load_class);
46  void VisitNewArray(HNewArray* instr);
47  void VisitPhi(HPhi* phi);
48  void VisitBasicBlock(HBasicBlock* block);
49  void UpdateFieldAccessTypeInfo(HInstruction* instr, const FieldInfo& info);
50  void SetClassAsTypeInfo(HInstruction* instr, mirror::Class* klass);
51
52  void UpdateBoundType(HBoundType* bound_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
53  void UpdatePhi(HPhi* phi) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
54
55  void BoundTypeForIfNotNull(HBasicBlock* block);
56  void BoundTypeForIfInstanceOf(HBasicBlock* block);
57  void UpdateReferenceTypeInfo(HInstruction* instr, uint16_t type_idx, const DexFile& dex_file);
58  void VisitInstanceFieldGet(HInstanceFieldGet* instr);
59  void VisitStaticFieldGet(HStaticFieldGet* instr);
60  void VisitInvoke(HInvoke* instr);
61
62  void ProcessWorklist();
63  void AddToWorklist(HInstruction* instr);
64  void AddDependentInstructionsToWorklist(HInstruction* instr);
65
66  bool UpdateNullability(HInstruction* instr);
67  bool UpdateReferenceTypeInfo(HInstruction* instr);
68
69  ReferenceTypeInfo MergeTypes(const ReferenceTypeInfo& a, const ReferenceTypeInfo& b)
70      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
71
72  StackHandleScopeCollection* handles_;
73
74  GrowableArray<HInstruction*> worklist_;
75
76  static constexpr size_t kDefaultWorklistSize = 8;
77
78  DISALLOW_COPY_AND_ASSIGN(ReferenceTypePropagation);
79};
80
81}  // namespace art
82
83#endif  // ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_
84