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