reference_type_propagation.h revision acf735c13998ad2a175f5a17e7bfce220073279d
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
25namespace art {
26
27/**
28 * Propagates reference types to instructions.
29 */
30class ReferenceTypePropagation : public HOptimization {
31 public:
32  ReferenceTypePropagation(HGraph* graph,
33                           const DexFile& dex_file,
34                           const DexCompilationUnit& dex_compilation_unit,
35                           StackHandleScopeCollection* handles)
36    : HOptimization(graph, true, "reference_type_propagation"),
37      dex_file_(dex_file),
38      dex_compilation_unit_(dex_compilation_unit),
39      handles_(handles),
40      worklist_(graph->GetArena(), kDefaultWorklistSize) {}
41
42  void Run() OVERRIDE;
43
44 private:
45  void VisitNewInstance(HNewInstance* new_instance);
46  void VisitLoadClass(HLoadClass* load_class);
47  void VisitBasicBlock(HBasicBlock* block);
48  void ProcessWorklist();
49  void AddToWorklist(HPhi* phi);
50  void AddDependentInstructionsToWorklist(HPhi* phi);
51  bool UpdateNullability(HPhi* phi);
52  bool UpdateReferenceTypeInfo(HPhi* phi);
53
54  const DexFile& dex_file_;
55  const DexCompilationUnit& dex_compilation_unit_;
56  StackHandleScopeCollection* handles_;
57
58  GrowableArray<HPhi*> worklist_;
59
60  static constexpr size_t kDefaultWorklistSize = 8;
61
62  DISALLOW_COPY_AND_ASSIGN(ReferenceTypePropagation);
63};
64
65}  // namespace art
66
67#endif  // ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_
68