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/stub_builder.h" 18 19 namespace panda::ecmascript::kungfu { 20 enum class ICStubType { LOAD, STORE }; 21 class ICStubBuilder : public StubBuilder { 22 public: ICStubBuilder(StubBuilder * parent)23 explicit ICStubBuilder(StubBuilder *parent) 24 : StubBuilder(parent) {} 25 ~ICStubBuilder() override = default; 26 NO_MOVE_SEMANTIC(ICStubBuilder); 27 NO_COPY_SEMANTIC(ICStubBuilder); GenerateCircuit()28 void GenerateCircuit() override {} 29 30 void SetParameters(GateRef glue, GateRef receiver, GateRef profileTypeInfo, 31 GateRef value, GateRef slotId, ProfileOperation callback = ProfileOperation()) 32 { 33 glue_ = glue; 34 receiver_ = receiver; 35 profileTypeInfo_ = profileTypeInfo; 36 value_ = value; 37 slotId_ = slotId; 38 callback_ = callback; 39 } 40 41 void SetParameters(GateRef glue, GateRef receiver, GateRef profileTypeInfo, 42 GateRef value, GateRef slotId, GateRef propKey, ProfileOperation callback = ProfileOperation()) 43 { 44 SetParameters(glue, receiver, profileTypeInfo, value, slotId, callback); 45 propKey_ = propKey; 46 } 47 48 void LoadICByName(Variable* result, Label* tryFastPath, Label *slowPath, Label *success, 49 ProfileOperation callback); 50 void StoreICByName(Variable* result, Label* tryFastPath, Label *slowPath, Label *success); 51 void LoadICByValue(Variable* result, Label* tryFastPath, Label *slowPath, Label *success, 52 ProfileOperation callback); 53 void StoreICByValue(Variable* result, Label* tryFastPath, Label *slowPath, Label *success); 54 void TryLoadGlobalICByName(Variable* result, Label* tryFastPath, Label *slowPath, Label *success); 55 void TryStoreGlobalICByName(Variable* result, Label* tryFastPath, Label *slowPath, Label *success); 56 private: 57 template<ICStubType type> 58 void NamedICAccessor(Variable* cachedHandler, Label *tryICHandler); 59 void ValuedICAccessor(Variable* cachedHandler, Label *tryICHandler, Label* tryElementIC); SetLabels(Label * tryFastPath,Label * slowPath,Label * success)60 void SetLabels(Label* tryFastPath, Label *slowPath, Label *success) 61 { 62 tryFastPath_ = tryFastPath; 63 slowPath_ = slowPath; 64 success_ = success; 65 } 66 67 GateRef glue_ {Circuit::NullGate()}; 68 GateRef receiver_ {0}; 69 GateRef profileTypeInfo_ {0}; 70 GateRef value_ {0}; 71 GateRef slotId_ {0}; 72 GateRef propKey_ {0}; 73 ProfileOperation callback_; 74 75 Label *tryFastPath_ {nullptr}; 76 Label *slowPath_ {nullptr}; 77 Label *success_ {nullptr}; 78 }; 79 } // namespace panda::ecmascript::kungfu 80 #endif // ECMASCRIPT_COMPILER_IC_STUB_BUILDER_H 81