blob: 5493601adccb5b522751cc55c9752e9c278908c7 [file] [log] [blame]
Calin Juravle10e244f2015-01-26 18:54:32 +00001/*
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 Marko2aaa4b52015-09-17 17:03:26 +010020#include "base/arena_containers.h"
Calin Juravleacf735c2015-02-12 15:25:22 +000021#include "driver/dex_compilation_unit.h"
22#include "handle_scope-inl.h"
Calin Juravle10e244f2015-01-26 18:54:32 +000023#include "nodes.h"
24#include "optimization.h"
Calin Juravleb1498f62015-02-16 13:13:29 +000025#include "optimizing_compiler_stats.h"
Calin Juravle10e244f2015-01-26 18:54:32 +000026
27namespace art {
28
29/**
30 * Propagates reference types to instructions.
Calin Juravle10e244f2015-01-26 18:54:32 +000031 */
Calin Juravle6c0c4f22015-06-12 15:40:42 +000032class ReferenceTypePropagation : public HOptimization {
Calin Juravle10e244f2015-01-26 18:54:32 +000033 public:
Calin Juravlea5ae3c32015-07-28 14:40:50 +000034 ReferenceTypePropagation(HGraph* graph,
35 StackHandleScopeCollection* handles,
Calin Juravle2e768302015-07-28 14:41:11 +000036 const char* name = kReferenceTypePropagationPassName);
Calin Juravle10e244f2015-01-26 18:54:32 +000037
38 void Run() OVERRIDE;
39
Andreas Gampe7c3952f2015-02-19 18:21:24 -080040 static constexpr const char* kReferenceTypePropagationPassName = "reference_type_propagation";
41
Calin Juravle10e244f2015-01-26 18:54:32 +000042 private:
Calin Juravleb1498f62015-02-16 13:13:29 +000043 void VisitPhi(HPhi* phi);
Calin Juravle10e244f2015-01-26 18:54:32 +000044 void VisitBasicBlock(HBasicBlock* block);
Mathieu Chartier90443472015-07-16 20:32:27 -070045 void UpdateBoundType(HBoundType* bound_type) SHARED_REQUIRES(Locks::mutator_lock_);
46 void UpdatePhi(HPhi* phi) SHARED_REQUIRES(Locks::mutator_lock_);
Calin Juravle61d544b2015-02-23 16:46:57 +000047 void BoundTypeForIfNotNull(HBasicBlock* block);
Calin Juravleb1498f62015-02-16 13:13:29 +000048 void BoundTypeForIfInstanceOf(HBasicBlock* block);
Calin Juravle10e244f2015-01-26 18:54:32 +000049 void ProcessWorklist();
Calin Juravleb1498f62015-02-16 13:13:29 +000050 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 Chartier90443472015-07-16 20:32:27 -070057 SHARED_REQUIRES(Locks::mutator_lock_);
Calin Juravleacf735c2015-02-12 15:25:22 +000058
Calin Juravleacf735c2015-02-12 15:25:22 +000059 StackHandleScopeCollection* handles_;
Calin Juravle10e244f2015-01-26 18:54:32 +000060
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010061 ArenaVector<HInstruction*> worklist_;
Calin Juravle10e244f2015-01-26 18:54:32 +000062
Calin Juravle2e768302015-07-28 14:41:11 +000063 ReferenceTypeInfo::TypeHandle object_class_handle_;
64 ReferenceTypeInfo::TypeHandle class_class_handle_;
65 ReferenceTypeInfo::TypeHandle string_class_handle_;
David Brazdilbbd733e2015-08-18 17:48:17 +010066 ReferenceTypeInfo::TypeHandle throwable_class_handle_;
Calin Juravle2e768302015-07-28 14:41:11 +000067
Calin Juravle10e244f2015-01-26 18:54:32 +000068 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_