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 #ifndef ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_ID_H 16 #define ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_ID_H 17 18 #include "ecmascript/pgo_profiler/types/pgo_profile_type.h" 19 #include "ecmascript/mem/c_string.h" 20 #include "ecmascript/jspandafile/js_pandafile.h" 21 #include "ecmascript/pgo_profiler/types/pgo_profile_type.h" 22 23 namespace panda::ecmascript { 24 class JSPandaFile; 25 26 namespace kungfu { 27 using ProfileType = pgo::ProfileType; 28 using ProfileTyper = std::pair<ProfileType, ProfileType>; 29 using ProfileTypeTuple = std::tuple<ProfileType, ProfileType, uint64_t>; 30 31 class PGOTypeLocation { 32 public: 33 enum class Type : uint8_t { 34 LOCAL, 35 PROTOTYPE, 36 CONSTRUCTOR, 37 }; 38 39 explicit PGOTypeLocation(const JSPandaFile *jsPandaFile, uint32_t methodOffset, 40 int32_t bcIdx); PGOTypeLocation(const CString & abcName,uint32_t methodOffset,int32_t bcIdx)41 explicit PGOTypeLocation(const CString &abcName, uint32_t methodOffset, 42 int32_t bcIdx) 43 : abcName_(abcName), methodOffset_(methodOffset), bcIdx_(bcIdx) {} 44 45 bool operator==(const PGOTypeLocation &loc) const 46 { 47 return abcName_ == loc.abcName_ && 48 methodOffset_ == loc.methodOffset_ && 49 bcIdx_ == loc.bcIdx_ && 50 type_ == loc.type_; 51 } 52 ChangeType(Type type)53 PGOTypeLocation ChangeType(Type type) const 54 { 55 auto loc = *this; 56 loc.type_ = type; 57 return loc; 58 } 59 GetAbcName()60 const CString& GetAbcName() const 61 { 62 return abcName_; 63 } 64 GetMethodOffset()65 uint32_t GetMethodOffset() const 66 { 67 return methodOffset_; 68 } 69 GetBcIdx()70 int32_t GetBcIdx() const 71 { 72 return bcIdx_; 73 } 74 75 private: 76 CString abcName_; 77 uint32_t methodOffset_; 78 int32_t bcIdx_; 79 Type type_ { Type::LOCAL }; 80 }; 81 82 struct HashPGOTypeLocation { operatorHashPGOTypeLocation83 size_t operator()(const PGOTypeLocation &loc) const 84 { 85 return std::hash<CString>()(loc.GetAbcName()) ^ 86 std::hash<uint32_t>()(loc.GetMethodOffset()) ^ 87 std::hash<int32_t>()(loc.GetBcIdx()); 88 } 89 }; 90 } // panda::ecmascript::kungfu 91 } 92 #endif // ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_ID_H 93