• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class PGOHClassGenerator {
24 public:
25     enum class Status: uint8_t {
26         NONE = 0x00UL,
27         ISCACHE = 0x01UL,
28     };
29 
30     PGOHClassGenerator(const PGOTypeRecorder &typeRecorder, PGOTypeManager *ptManager, Status status = Status::NONE)
typeRecorder_(typeRecorder)31         : typeRecorder_(typeRecorder), ptManager_(ptManager), status_(status) {}
32 
33     bool FindHClassLayoutDesc(PGOSampleType type) const;
34     bool GenerateHClass(PGOSampleType type) const;
35     bool GenerateIHClass(PGOSampleType type, const JSHandle<JSTaggedValue> &prototype) const;
36 
37     bool IsCache() const;
38     void SetStatus(Status status) const;
39 
40 private:
41     void CalculateMaxNumOfObj(
42         const PGOHClassTreeDesc *desc, const HClassLayoutDesc *parent, uint32_t lastNum, uint32_t &maxNum) const;
43     bool CheckIsValid(PGOSampleType type, uint32_t maxNum) const;
44     void CalculateMaxNumOfObjIncludeProtoTransition(PGOSampleType type, uint32_t &maxNum) const;
45     JSHandle<JSHClass> CreateRootPHClass(
46         ProfileType rootType, const HClassLayoutDesc *layoutDesc, uint32_t maxNum, bool isTransitionPhc) const;
47     JSHandle<JSHClass> CreateRootCHClass(
48         ProfileType rootType, const HClassLayoutDesc *layoutDesc, uint32_t maxNum) const;
49     JSHandle<JSHClass> CreateRootHClass(
50         ProfileType rootType, const HClassLayoutDesc *layoutDesc, uint32_t maxNum) const;
51     JSHandle<JSHClass> CreateRootHClassWithCached(
52         ProfileType rootType, const HClassLayoutDesc *layoutDesc, uint32_t literalLength, uint32_t maxPropsNum) const;
53 
54     void CreateChildHClass(ProfileType rootType, const PGOHClassTreeDesc *desc, const JSHandle<JSHClass> &parent,
55         const HClassLayoutDesc *parentLayoutDesc) const;
56 
57     const PGOTypeRecorder &typeRecorder_;
58     PGOTypeManager *ptManager_;
59     mutable Status status_;
60 };
61 }  // panda::ecmascript::kungfu
62 #endif // ECMASCRIPT_COMPILER_PGO_TYPE_PGO_HCLASS_GENERATOR_H
63