1 /* 2 * Copyright (c) 2021-2025 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_LOCATIONS_BUILDER_H 17 #define PANDA_LOCATIONS_BUILDER_H 18 19 #include "compiler/optimizer/ir/graph_visitor.h" 20 #include "compiler/optimizer/pass.h" 21 22 namespace ark::compiler { 23 class ParameterInfo; 24 25 template <Arch ARCH> // NOLINTNEXTLINE(fuchsia-multiple-inheritance) 26 class LocationsBuilder : public GraphVisitor, public Optimization { 27 public: 28 LocationsBuilder(Graph *graph, ParameterInfo *pinfo); 29 30 bool RunImpl() override; GetPassName()31 const char *GetPassName() const override 32 { 33 return "LocationsBuilder"; 34 } 35 ShouldDump()36 bool ShouldDump() const override 37 { 38 return true; 39 } 40 41 const ArenaVector<BasicBlock *> &GetBlocksToVisit() const override; 42 GetTarget()43 static constexpr Target GetTarget() 44 { 45 return Target(ARCH); 46 } GetWordType()47 static constexpr DataType::Type GetWordType() 48 { 49 return Is64BitsArch(ARCH) ? DataType::UINT64 : DataType::UINT32; 50 } 51 52 static Location GetLocationForReturn(Inst *inst); 53 54 static void VisitResolveStatic(GraphVisitor *visitor, Inst *inst); 55 static void VisitCallResolvedStatic(GraphVisitor *visitor, Inst *inst); 56 static void VisitCallStatic(GraphVisitor *visitor, Inst *inst); 57 static void VisitCallVirtual(GraphVisitor *visitor, Inst *inst); 58 static void VisitResolveVirtual(GraphVisitor *visitor, Inst *inst); 59 static void VisitCallResolvedVirtual(GraphVisitor *visitor, Inst *inst); 60 static void VisitCallIndirect(GraphVisitor *visitor, Inst *inst); 61 static void VisitCall(GraphVisitor *visitor, Inst *inst); 62 static void VisitCallDynamic(GraphVisitor *visitor, Inst *inst); 63 static void VisitCallNative(GraphVisitor *visitor, Inst *inst); 64 static void VisitIntrinsic(GraphVisitor *visitor, Inst *inst); 65 static void VisitParameter(GraphVisitor *visitor, Inst *inst); 66 static void VisitReturn(GraphVisitor *visitor, Inst *inst); 67 static void VisitThrow(GraphVisitor *visitor, Inst *inst); 68 static void VisitNewArray(GraphVisitor *visitor, Inst *inst); 69 static void VisitNewObject(GraphVisitor *visitor, Inst *inst); 70 static void VisitLiveOut(GraphVisitor *visitor, Inst *inst); 71 static void VisitMultiArray(GraphVisitor *visitor, Inst *inst); 72 static void VisitStoreStatic(GraphVisitor *visitor, Inst *inst); 73 static void VisitResolveByName(GraphVisitor *visitor, Inst *inst); 74 75 void ProcessManagedCall(Inst *inst, ParameterInfo *pinfo = nullptr); 76 void ProcessManagedCallStackRange(Inst *inst, size_t rangeStart, ParameterInfo *pinfo = nullptr); 77 78 private: 79 ParameterInfo *GetResetParameterInfo(); GetParameterInfo()80 ParameterInfo *GetParameterInfo() 81 { 82 return paramsInfo_; 83 } 84 85 #include "optimizer/ir/visitor.inc" 86 private: 87 ParameterInfo *paramsInfo_ {nullptr}; 88 }; 89 90 bool RunLocationsBuilder(Graph *graph); 91 } // namespace ark::compiler 92 93 #endif // PANDA_LOCATIONS_BUILDER_H 94