• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_IC_STUB_BUILDER_H
16 #define ECMASCRIPT_COMPILER_IC_STUB_BUILDER_H
17 #include "ecmascript/compiler/share_gate_meta_data.h"
18 #include "ecmascript/compiler/stub_builder.h"
19 
20 namespace panda::ecmascript::kungfu {
21 enum class ICStubType { LOAD, STORE };
22 class ICStubBuilder : public StubBuilder {
23 public:
ICStubBuilder(StubBuilder * parent,GateRef globalEnv)24     ICStubBuilder(StubBuilder *parent, GateRef globalEnv)
25         : StubBuilder(parent, globalEnv) {}
26     ~ICStubBuilder() override = default;
27     NO_MOVE_SEMANTIC(ICStubBuilder);
28     NO_COPY_SEMANTIC(ICStubBuilder);
GenerateCircuit()29     void GenerateCircuit() override {}
30 
31     void SetParameters(GateRef glue, GateRef receiver, GateRef profileTypeInfo, GateRef value, GateRef slotId,
32                        ProfileOperation callback = ProfileOperation())
33     {
34         glue_ = glue;
35         receiver_ = receiver;
36         profileTypeInfo_ = profileTypeInfo;
37         value_ = value;
38         slotId_ = slotId;
39         callback_ = callback;
40     }
41 
42     void SetParameters(GateRef glue, GateRef receiver, GateRef profileTypeInfo, GateRef value, GateRef slotId,
43                        GateRef propKey, ProfileOperation callback = ProfileOperation())
44     {
45         SetParameters(glue, receiver, profileTypeInfo, value, slotId, callback);
46         propKey_ = propKey;
47     }
48 
49     void SetParameters(GateRef glue, GateRef receiver, GateRef profileTypeInfo, GateRef value, GateRef slotId,
50                        GateRef megaStubCache, GateRef propKey, ProfileOperation callback = ProfileOperation())
51     {
52         SetParameters(glue, receiver, profileTypeInfo, value, slotId, propKey_, callback);
53         propKey_ = propKey;
54         megaStubCache_ = megaStubCache;
55     }
56 
57     void LoadICByName(Variable* result, Label* tryFastPath, Label *slowPath, Label *success,
58         ProfileOperation callback);
59     void LoadICByNameWithMega(Variable *result, Label *tryFastPath, Label *slowPath, Label *success,
60                               ProfileOperation callback);
61     void StoreICByName(Variable *result, Label *tryFastPath, Label *slowPath, Label *success);
62     void StoreICByNameWithMega(Variable *result, Label *tryFastPath, Label *slowPath, Label *success);
63     void LoadICByValue(Variable* result, Label* tryFastPath, Label *slowPath, Label *success,
64         ProfileOperation callback);
65     void StoreICByValue(Variable* result, Label* tryFastPath, Label *slowPath, Label *success);
66     void TryLoadGlobalICByName(Variable* result, Label* tryFastPath, Label *slowPath, Label *success);
67     void TryStoreGlobalICByName(Variable* result, Label* tryFastPath, Label *slowPath, Label *success);
68 private:
69     struct PrimitiveLoadICInfo {
70         GateRef glue;
71         GateRef glueGlobalEnv;
72         GateRef profileFirstValue;
73         Label *tryICHandler;
74         Variable *cachedHandler;
75     };
76     void TryDesignatePrimitiveLoadIC(Label &tryDesignatePrimitive, Label &notDesignatePrimitive,
77                                      PrimitiveType primitiveType, PrimitiveLoadICInfo info);
78     void TryPrimitiveLoadIC(Variable* cachedHandler, Label *tryICHandler);
79     template<ICStubType type>
80     void NamedICAccessor(Variable* cachedHandler, Label *tryICHandler);
81     template<ICStubType type>
82     void NamedICAccessorWithMega(Variable* cachedHandler, Label *tryICHandler);
83     void ValuedICAccessor(Variable* cachedHandler, Label *tryICHandler, Label* tryElementIC);
SetLabels(Label * tryFastPath,Label * slowPath,Label * success)84     void SetLabels(Label* tryFastPath, Label *slowPath, Label *success)
85     {
86         tryFastPath_ = tryFastPath;
87         slowPath_ = slowPath;
88         success_ = success;
89     }
90 
91     GateRef glue_ {Circuit::NullGate()};
92     GateRef receiver_ {0};
93     GateRef profileTypeInfo_ {0};
94     GateRef value_ {0};
95     GateRef slotId_ {0};
96     GateRef propKey_ {0};
97     GateRef megaStubCache_ {0};
98     ProfileOperation callback_;
99 
100     Label *tryFastPath_ {nullptr};
101     Label *slowPath_ {nullptr};
102     Label *success_ {nullptr};
103 };
104 }  // namespace panda::ecmascript::kungfu
105 #endif  // ECMASCRIPT_COMPILER_IC_STUB_BUILDER_H
106