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)24 explicit ICStubBuilder(StubBuilder *parent) 25 : StubBuilder(parent) {} 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 template<ICStubType type> 70 void NamedICAccessor(Variable* cachedHandler, Label *tryICHandler); 71 template<ICStubType type> 72 void NamedICAccessorWithMega(Variable* cachedHandler, Label *tryICHandler); 73 void ValuedICAccessor(Variable* cachedHandler, Label *tryICHandler, Label* tryElementIC); SetLabels(Label * tryFastPath,Label * slowPath,Label * success)74 void SetLabels(Label* tryFastPath, Label *slowPath, Label *success) 75 { 76 tryFastPath_ = tryFastPath; 77 slowPath_ = slowPath; 78 success_ = success; 79 } 80 81 GateRef glue_ {Circuit::NullGate()}; 82 GateRef receiver_ {0}; 83 GateRef profileTypeInfo_ {0}; 84 GateRef value_ {0}; 85 GateRef slotId_ {0}; 86 GateRef propKey_ {0}; 87 GateRef megaStubCache_ {0}; 88 ProfileOperation callback_; 89 90 Label *tryFastPath_ {nullptr}; 91 Label *slowPath_ {nullptr}; 92 Label *success_ {nullptr}; 93 }; 94 } // namespace panda::ecmascript::kungfu 95 #endif // ECMASCRIPT_COMPILER_IC_STUB_BUILDER_H 96