reference_type_propagation.h revision 10e244f9e7f6d96a95c910a2bedef5bd3810c637
1184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray/*
210e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle * Copyright (C) 2015 The Android Open Source Project
3184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray *
4184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
5184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * you may not use this file except in compliance with the License.
6184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * You may obtain a copy of the License at
7184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray *
8184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
9184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray *
10184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
11184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
12184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * See the License for the specific language governing permissions and
14184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray * limitations under the License.
15184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray */
16184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
1710e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#ifndef ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_
1810e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#define ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_
19184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
20184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray#include "nodes.h"
2110e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#include "optimization.h"
22184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
23184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffraynamespace art {
24184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
2510e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle/**
2610e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle * Propagates reference types to instructions.
2710e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle * TODO: Currently only nullability is computed.
2810e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle */
2910e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravleclass ReferenceTypePropagation : public HOptimization {
30184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray public:
3110e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle  explicit ReferenceTypePropagation(HGraph* graph)
3210e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle    : HOptimization(graph, true, "reference_type_propagation"),
3310e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle      worklist_(graph->GetArena(), kDefaultWorklistSize) {}
34184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
3510e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle  void Run() OVERRIDE;
36184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
37184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray private:
38184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray  void VisitBasicBlock(HBasicBlock* block);
39184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray  void ProcessWorklist();
40184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray  void AddToWorklist(HPhi* phi);
41184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray  void AddDependentInstructionsToWorklist(HPhi* phi);
4210e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle  bool UpdateNullability(HPhi* phi);
43184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
44184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray  GrowableArray<HPhi*> worklist_;
45184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
46184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray  static constexpr size_t kDefaultWorklistSize = 8;
47184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
4810e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle  DISALLOW_COPY_AND_ASSIGN(ReferenceTypePropagation);
49184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray};
50184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
51184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray}  // namespace art
52184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray
5310e244f9e7f6d96a95c910a2bedef5bd3810c637Calin Juravle#endif  // ART_COMPILER_OPTIMIZING_REFERENCE_TYPE_PROPAGATION_H_
54