• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 COMPILER_OPTIMIZER_ANALYSIS_TYPES_ANALISYS_H
17 #define COMPILER_OPTIMIZER_ANALYSIS_TYPES_ANALISYS_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 /**
25  * TypesAnalysis sets assumed types(dynamic type) to phi instruction.
26  * If a PHI is user of a CastValueToAnyType, the type of CastValueToAnyType is set as assumed type of the PHI
27  * If a PHI is input of AnyTypeCheck, the type of CastValueToAnyType is set as assumed type of the PHI
28  * If a PHI has assumed type and we try to set another type, we change assumed type to undefine.
29  * If an assumed type is set for PHI, then we try to assign the type for all PHI that are inputs of the current PHI
30  */
31 // NOLINTNEXTLINE(fuchsia-multiple-inheritance)
32 class TypesAnalysis final : public Analysis, public GraphVisitor {
33 public:
TypesAnalysis(Graph * graph)34     explicit TypesAnalysis(Graph *graph) : Analysis(graph) {}
35     NO_MOVE_SEMANTIC(TypesAnalysis);
36     NO_COPY_SEMANTIC(TypesAnalysis);
37     ~TypesAnalysis() override = default;
38 
GetBlocksToVisit()39     const ArenaVector<BasicBlock *> &GetBlocksToVisit() const override
40     {
41         return GetGraph()->GetBlocksRPO();
42     }
43 
GetPassName()44     const char *GetPassName() const override
45     {
46         return "TypesAnalysis";
47     }
48 
49     bool RunImpl() override;
50 
51 protected:
52     static void VisitCastValueToAnyType(GraphVisitor *v, Inst *inst);
53     static void VisitAnyTypeCheck(GraphVisitor *v, Inst *inst);
54 
55 #include "optimizer/ir/visitor.inc"
56 private:
57     void MarkedPhiRec(PhiInst *phi, AnyBaseType type);
58     Marker marker_ {UNDEF_MARKER};
59 };
60 }  // namespace panda::compiler
61 
62 #endif  // COMPILER_OPTIMIZER_ANALYSIS_TYPES_ANALISYS_H
63