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