• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_OBJECT_TYPE_PROPAGATION_H
17 #define PANDA_OBJECT_TYPE_PROPAGATION_H
18 
19 #include "optimizer/pass.h"
20 #include "optimizer/ir/graph.h"
21 #include "optimizer/ir/graph_visitor.h"
22 
23 namespace ark::compiler {
24 // NOLINTNEXTLINE(fuchsia-multiple-inheritance)
25 class ObjectTypePropagation final : public Analysis, public GraphVisitor {
26 public:
ObjectTypePropagation(Graph * graph)27     explicit ObjectTypePropagation(Graph *graph) : Analysis(graph) {}
28     NO_MOVE_SEMANTIC(ObjectTypePropagation);
29     NO_COPY_SEMANTIC(ObjectTypePropagation);
30     ~ObjectTypePropagation() override = default;
31 
GetBlocksToVisit()32     const ArenaVector<BasicBlock *> &GetBlocksToVisit() const override
33     {
34         return GetGraph()->GetBlocksRPO();
35     }
36 
GetPassName()37     const char *GetPassName() const override
38     {
39         return "ObjectTypePropagation";
40     }
41 
42     bool RunImpl() override;
43 
44 protected:
45     static void VisitNewObject(GraphVisitor *v, Inst *i);
46     static void VisitParameter(GraphVisitor *v, Inst *i);
47     static void VisitNewArray(GraphVisitor *v, Inst *i);
48     static void VisitLoadArray(GraphVisitor *v, Inst *i);
49     static void VisitLoadString(GraphVisitor *v, Inst *i);
50     static void VisitLoadObject(GraphVisitor *v, Inst *i);
51     static void VisitCallStatic(GraphVisitor *v, Inst *i);
52     static void VisitCallVirtual(GraphVisitor *v, Inst *i);
53     static void VisitNullCheck(GraphVisitor *v, Inst *i);
54     static void VisitRefTypeCheck(GraphVisitor *v, Inst *i);
55 
56 #include "optimizer/ir/visitor.inc"
57 
58 private:
59     static void ProcessManagedCall(GraphVisitor *v, CallInst *inst);
60     ObjectTypeInfo GetPhiTypeInfo(Inst *inst);
61 
62 private:
63     InstVector *visitedPhis_ {nullptr};
64     Marker visited_ {UNDEF_MARKER};
65 };
66 }  // namespace ark::compiler
67 
68 #endif  // PANDA_OBJECT_TYPE_PROPAGATION_H
69