1 /* 2 * Copyright (c) 2023 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 ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_RECORD_H 17 #define ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_RECORD_H 18 19 #include "ecmascript/pgo_profiler/pgo_profiler_decoder.h" 20 #include "ecmascript/pgo_profiler/types/pgo_profiler_type.h" 21 22 namespace panda::ecmascript::kungfu { 23 using PGOProfilerDecoder = pgo::PGOProfilerDecoder; 24 using PGOHClassTreeDesc = pgo::PGOHClassTreeDesc; 25 using PGODefineOpType = pgo::PGODefineOpType; 26 using RootHClassLayoutDesc = pgo::RootHClassLayoutDesc; 27 using PGORWOpType = pgo::PGORWOpType; 28 29 class PGOTypeRecorder { 30 public: 31 explicit PGOTypeRecorder(const PGOProfilerDecoder &decoder); 32 PGOTypeRecorder(const PGOProfilerDecoder &decoder, const JSPandaFile *jsPandaFile, uint32_t methodOffset); 33 ~PGOTypeRecorder() = default; 34 35 std::vector<ElementsKind> GetElementsKindsForUser(int32_t offset) const; 36 ElementsKind GetElementsKindForCreater(int32_t offset) const; 37 uint32_t GetElementsLength(int32_t offset) const; 38 39 PGOTypeRef GetPGOType(int32_t offset) const; 40 GetPGODefOpType(int32_t bcOffset)41 inline PGODefineOpType GetPGODefOpType(int32_t bcOffset) const 42 { 43 auto typeIter = bcOffsetPGODefOpTypeMap_.find(bcOffset); 44 if (typeIter == bcOffsetPGODefOpTypeMap_.end()) { 45 return PGODefineOpType(ProfileType::PROFILE_TYPE_NONE); 46 } 47 return *(typeIter->second); 48 } 49 GetHClassTreeDesc(PGOSampleType type,PGOHClassTreeDesc ** desc)50 inline bool GetHClassTreeDesc(PGOSampleType type, PGOHClassTreeDesc **desc) const 51 { 52 return decoder_.GetHClassTreeDesc(type, desc); 53 } 54 55 template <typename Callback> IterateHClassTreeDesc(Callback callback)56 void IterateHClassTreeDesc(Callback callback) const 57 { 58 decoder_.IterateHClassTreeDesc(callback); 59 } 60 61 private: 62 const PGOProfilerDecoder &decoder_; 63 std::unordered_map<int32_t, const PGOSampleType*> bcOffsetPGOOpTypeMap_ {}; 64 std::unordered_map<int32_t, const PGORWOpType*> bcOffsetPGORwTypeMap_ {}; 65 std::unordered_map<int32_t, const PGODefineOpType*> bcOffsetPGODefOpTypeMap_; 66 }; 67 } // panda::ecmascript::kungfu 68 #endif // ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_RECORD_H 69