• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 panda::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), visitedPhis_(graph->GetLocalAllocator()->Adapter())
28     {
29     }
30     NO_MOVE_SEMANTIC(ObjectTypePropagation);
31     NO_COPY_SEMANTIC(ObjectTypePropagation);
32     ~ObjectTypePropagation() override = default;
33 
GetBlocksToVisit()34     const ArenaVector<BasicBlock *> &GetBlocksToVisit() const override
35     {
36         return GetGraph()->GetBlocksRPO();
37     }
38 
GetPassName()39     const char *GetPassName() const override
40     {
41         return "ObjectTypePropagation";
42     }
43 
44     bool RunImpl() override;
45 
46 protected:
47     static void VisitNewObject(GraphVisitor *v, Inst *inst);
48     static void VisitParameter(GraphVisitor *v, Inst *inst);
49     static void VisitNewArray(GraphVisitor *v, Inst *inst);
50     static void VisitLoadArray(GraphVisitor *v, Inst *inst);
51     static void VisitLoadString(GraphVisitor *v, Inst *inst);
52     static void VisitLoadObject(GraphVisitor *v, Inst *inst);
53     static void VisitCallStatic(GraphVisitor *v, Inst *inst);
54     static void VisitCallVirtual(GraphVisitor *v, Inst *inst);
55     static void VisitNullCheck(GraphVisitor *v, Inst *inst);
56     static void VisitRefTypeCheck(GraphVisitor *v, Inst *inst);
57 
58 #include "optimizer/ir/visitor.inc"
59 
60 private:
61     static void ProcessManagedCall(GraphVisitor *v, CallInst *inst);
62     ObjectTypeInfo GetPhiTypeInfo(Inst *inst);
63 
64 private:
65     InstVector visitedPhis_;
66     Marker visited_ {UNDEF_MARKER};
67 };
68 }  // namespace panda::compiler
69 
70 #endif  // PANDA_OBJECT_TYPE_PROPAGATION_H
71