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 #ifndef ECMASCRIPT_COMPILER_PGO_TYPE_PGO_HCLASS_GENERATOR_H 16 #define ECMASCRIPT_COMPILER_PGO_TYPE_PGO_HCLASS_GENERATOR_H 17 18 #include "ecmascript/compiler/pgo_type/pgo_type_manager.h" 19 #include "ecmascript/compiler/pgo_type/pgo_type_recorder.h" 20 #include "ecmascript/js_hclass.h" 21 22 namespace panda::ecmascript::kungfu { 23 24 class PGOHClassGenerator { 25 public: PGOHClassGenerator(const PGOTypeRecorder & typeRecorder,PGOTypeManager * ptManager)26 PGOHClassGenerator(const PGOTypeRecorder &typeRecorder, PGOTypeManager *ptManager) 27 : typeRecorder_(typeRecorder), ptManager_(ptManager) {} 28 29 bool FindHClassLayoutDesc(PGOSampleType type) const; 30 // The hclass of object literal needs to be created from cached 31 bool GenerateHClass(PGOSampleType type, bool isCache) const; 32 bool GenerateIHClass(PGOSampleType type, const JSHandle<JSObject> &prototype) const; 33 34 private: 35 void CaculateMaxNumOfObj( 36 const PGOHClassTreeDesc *desc, const HClassLayoutDesc *parent, uint32_t lastNum, uint32_t &maxNum) const; 37 bool CheckIsValid(PGOSampleType type, uint32_t maxNum, bool isCache) const; 38 void CaculateMaxNumOfObjIncludeProtoTransition(PGOSampleType type, uint32_t &maxNum) const; 39 JSHandle<JSHClass> CreateRootPHClass( 40 ProfileType rootType, const HClassLayoutDesc *layoutDesc, uint32_t maxNum, bool isTransitionPhc) const; 41 JSHandle<JSHClass> CreateRootCHClass( 42 ProfileType rootType, const HClassLayoutDesc *layoutDesc, uint32_t maxNum) const; 43 JSHandle<JSHClass> CreateRootHClass( 44 ProfileType rootType, const HClassLayoutDesc *layoutDesc, uint32_t maxNum, bool isCache) const; 45 46 void CreateChildHClass(ProfileType rootType, const PGOHClassTreeDesc *desc, const JSHandle<JSHClass> &parent, 47 const HClassLayoutDesc *parentLayoutDesc) const; 48 49 const PGOTypeRecorder &typeRecorder_; 50 PGOTypeManager *ptManager_; 51 }; 52 } // panda::ecmascript::kungfu 53 #endif // ECMASCRIPT_COMPILER_PGO_TYPE_PGO_HCLASS_GENERATOR_H 54