• 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_OPTIMIZATIONS_TYPES_RESOLVING_H
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_TYPES_RESOLVING_H
18 
19 #include "optimizer/ir/basicblock.h"
20 #include "optimizer/ir/graph.h"
21 #include "optimizer/pass.h"
22 
23 namespace panda::compiler {
24 /*
25  * TypesResolving(based on the results of the TypesAnalysis) tries to replace dynamic intrinsics to static instructions
26  * TypesResolving collects assumed types(dynamic type) of intrinsics inputs:
27  *  - If all inputs have undefined assumes type, the optimization isn't applied.
28  *  - If some inputs have undefined assumed type they are assigned the assumed type of another input.
29  * Thus each input has an assumed type.
30  * Next, optimization tries to replace the intrinsic with static instructions, taking into account the types of inputs.
31  * In case of success, the corresponding types are put in AnyType heck, which are the inputs of the intrinsic
32  */
33 class TypesResolving : public Optimization {
34 public:
35     explicit TypesResolving(Graph *graph);
36     NO_MOVE_SEMANTIC(TypesResolving);
37     NO_COPY_SEMANTIC(TypesResolving);
38     ~TypesResolving() override = default;
39 
40     bool RunImpl() override;
41 
GetPassName()42     const char *GetPassName() const override
43     {
44         return "TypesResolving";
45     }
46     void InvalidateAnalyses() override;
47 #include "intrinsics_types_resolving.inl.h"
48 
49 private:
50     AnyBaseType GetAssumedAnyType(Inst *inst);
51     bool TryInline(IntrinsicInst *intrinsic);
52     bool TryResolvePhi();
53     bool CheckInputsAnyTypesRec(Inst *phi);
54     void PropagateTypeToPhi();
55     bool DoInline(IntrinsicInst *intrinsic);
56     ArenaVector<AnyBaseType> types_;
57     ArenaVector<Inst *> phis_;
58     AnyBaseType any_type_ {AnyBaseType::UNDEFINED_TYPE};
59 };
60 }  // namespace panda::compiler
61 
62 #endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_TYPES_RESOLVING_H
63