1 /* 2 * Copyright (c) 2023-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 COMPILER_OPTIMIZER_OPTIMIZATIONS_PHI_TYPE_RESOLVING_H 17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_PHI_TYPE_RESOLVING_H 18 19 #include "optimizer/ir/basicblock.h" 20 #include "optimizer/ir/graph.h" 21 #include "optimizer/pass.h" 22 23 namespace ark::compiler { 24 /* 25 * PhiTypeResolving finds Phi instructions of Any type whose inputs are CastValueToAnyType instructions with the same 26 * primitive type, and creates single CastValueToAnyType instructions with Phi of this primitive type as an input 27 */ 28 class PhiTypeResolving : public Optimization { 29 public: 30 explicit PhiTypeResolving(Graph *graph); 31 NO_MOVE_SEMANTIC(PhiTypeResolving); 32 NO_COPY_SEMANTIC(PhiTypeResolving); 33 ~PhiTypeResolving() override = default; 34 35 bool RunImpl() override; 36 GetPassName()37 const char *GetPassName() const override 38 { 39 return "PhiTypeResolving"; 40 } 41 void InvalidateAnalyses() override; 42 43 private: 44 bool CheckInputsAnyTypesRec(Inst *phi); 45 void PropagateTypeToPhi(); 46 ArenaVector<Inst *> phis_; 47 AnyBaseType anyType_ {AnyBaseType::UNDEFINED_TYPE}; 48 }; 49 } // namespace ark::compiler 50 51 #endif // COMPILER_OPTIMIZER_OPTIMIZATIONS_PHI_TYPE_RESOLVING_H 52