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
16#ifndef ECMASCRIPT_COMPILER_STUB_BUILDER_H
17#define ECMASCRIPT_COMPILER_STUB_BUILDER_H
18
19#include "ecmascript/base/config.h"
20#include "ecmascript/compiler/call_signature.h"
21#include "ecmascript/compiler/circuit_builder.h"
22#include "ecmascript/compiler/lcr_gate_meta_data.h"
23#include "ecmascript/compiler/profiler_operation.h"
24#include "ecmascript/compiler/share_gate_meta_data.h"
25#include "ecmascript/compiler/variable_type.h"
26
27namespace panda::ecmascript::kungfu {
28struct StringInfoGateRef;
29using namespace panda::ecmascript;
30// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
31#define DEFVARIABLE(varname, type, val) Variable varname(GetEnvironment(), type, NextVariableId(), val)
32
33#define SUBENTRY(messageId, condition)                                              \
34    GateRef glueArg = PtrArgument(0);                                               \
35    auto env = GetEnvironment();                                                    \
36    Label subEntry(env);                                                            \
37    env->SubCfgEntry(&subEntry);                                                    \
38    Label nextLabel(env);                                                           \
39    Assert(messageId, __LINE__, glueArg, condition, &nextLabel);                    \
40    Bind(&nextLabel)
41#define SUBENTRY_WITH_GLUE(messageId, condition, glueArg)                           \
42    auto env = GetEnvironment();                                                    \
43    Label subEntry(env);                                                            \
44    env->SubCfgEntry(&subEntry);                                                    \
45    Label nextLabel(env);                                                           \
46    Assert(messageId, __LINE__, glueArg, condition, &nextLabel);                    \
47    Bind(&nextLabel)
48
49#ifndef NDEBUG
50#define ASM_ASSERT(messageId, condition)                                            \
51    if (!GetEnvironment()->GetCircuit()->IsOptimizedOrFastJit() &&                  \
52        !GetEnvironment()->IsBaselineBuiltin()) {                                   \
53        SUBENTRY(messageId, condition);                                             \
54        EXITENTRY();                                                                \
55    }
56#define ASM_ASSERT_WITH_GLUE(messageId, condition, glue)                            \
57    SUBENTRY_WITH_GLUE(messageId, condition, glue)
58#elif defined(ENABLE_ASM_ASSERT)
59#define ASM_ASSERT(messageId, condition)                                            \
60    if (!GetEnvironment()->GetCircuit()->IsOptimizedOrFastJit() &&                  \
61        !GetEnvironment()->IsBaselineBuiltin()) {                                   \
62        SUBENTRY(messageId, condition);                                             \
63        EXITENTRY();                                                                \
64    }
65#define ASM_ASSERT_WITH_GLUE(messageId, condition, glue)                            \
66    SUBENTRY_WITH_GLUE(messageId, condition, glue)
67#else
68#define ASM_ASSERT(messageId, ...) ((void)0)
69#define ASM_ASSERT_WITH_GLUE(messageId, ...) ((void)0)
70#endif
71
72#ifndef NDEBUG
73#define EXITENTRY()                                                                 \
74    GetEnvironment()->SubCfgExit()
75#elif defined(ENABLE_ASM_ASSERT)
76#define EXITENTRY()                                                                 \
77    GetEnvironment()->SubCfgExit()
78#else
79#define EXITENTRY() ((void)0)
80#endif
81
82class StubBuilder {
83public:
84    explicit StubBuilder(StubBuilder *parent)
85        : callSignature_(parent->GetCallSignature()), env_(parent->GetEnvironment()) {}
86    StubBuilder(CallSignature *callSignature, Environment *env)
87        : callSignature_(callSignature), env_(env) {}
88    explicit StubBuilder(Environment *env)
89        : env_(env) {}
90    virtual ~StubBuilder() = default;
91    NO_MOVE_SEMANTIC(StubBuilder);
92    NO_COPY_SEMANTIC(StubBuilder);
93    virtual void GenerateCircuit() = 0;
94    Environment *GetEnvironment() const
95    {
96        return env_;
97    }
98    CallSignature *GetCallSignature() const
99    {
100        return callSignature_;
101    }
102    int NextVariableId();
103    // constant
104    GateRef Int8(int8_t value);
105    GateRef Int16(int16_t value);
106    GateRef Int32(int32_t value);
107    GateRef Int64(int64_t value);
108    GateRef TaggedInt(int32_t value);
109    GateRef StringPtr(std::string_view str);
110    GateRef IntPtr(int64_t value);
111    GateRef IntPtrSize();
112    GateRef RelocatableData(uint64_t value);
113    GateRef True();
114    GateRef False();
115    GateRef Boolean(bool value);
116    GateRef Double(double value);
117    GateRef Undefined();
118    GateRef Hole();
119    GateRef SpecialHole();
120    GateRef Null();
121    GateRef NullPtr();
122    GateRef Exception();
123    // parameter
124    GateRef Argument(size_t index);
125    GateRef Int1Argument(size_t index);
126    GateRef Int32Argument(size_t index);
127    GateRef Int64Argument(size_t index);
128    GateRef TaggedArgument(size_t index);
129    GateRef TaggedPointerArgument(size_t index);
130    GateRef PtrArgument(size_t index);
131    GateRef Float32Argument(size_t index);
132    GateRef Float64Argument(size_t index);
133    GateRef Alloca(int size);
134    // control flow
135    GateRef Return(GateRef value);
136    GateRef Return();
137    void Bind(Label *label);
138    void Jump(Label *label);
139
140#define BRANCH(condition, trueLabel, falseLabel)                       \
141    {                                                                  \
142        std::ostringstream os;                                         \
143        os << __func__ << ": " << #trueLabel << "- " << #falseLabel;   \
144        Branch(condition, trueLabel, falseLabel, os.str().c_str());    \
145    }
146
147    void Branch(GateRef condition, Label *trueLabel, Label *falseLabel, const char *comment = nullptr);
148
149#define BRANCH_LIKELY(condition, trueLabel, falseLabel)                                  \
150    {                                                                                    \
151        std::ostringstream os;                                                           \
152        os << __func__ << ": " << #trueLabel << "(likely)- " << #falseLabel;             \
153        BranchPredict(condition, trueLabel, falseLabel,                                  \
154            BranchWeight::DEOPT_WEIGHT, BranchWeight::ONE_WEIGHT, os.str().c_str());     \
155    }
156
157#define BRANCH_UNLIKELY(condition, trueLabel, falseLabel)                                \
158    {                                                                                    \
159        std::ostringstream os;                                                           \
160        os << __func__ << ": " << #trueLabel << "(unlikely)- " << #falseLabel;           \
161        BranchPredict(condition, trueLabel, falseLabel,                                  \
162            BranchWeight::ONE_WEIGHT, BranchWeight::DEOPT_WEIGHT, os.str().c_str());     \
163    }
164
165#define BRANCH_NO_WEIGHT(condition, trueLabel, falseLabel)                               \
166    {                                                                                    \
167        std::ostringstream os;                                                           \
168        os << __func__ << ": " << #trueLabel << "(no weight)- " << #falseLabel;          \
169        BranchPredict(condition, trueLabel, falseLabel,                                  \
170            BranchWeight::ZERO_WEIGHT, BranchWeight::ZERO_WEIGHT, os.str().c_str());     \
171    }
172
173    void BranchPredict(GateRef condition, Label *trueLabel, Label *falseLabel,
174                       uint32_t trueWeight = BranchWeight::ONE_WEIGHT, uint32_t falseWeight = BranchWeight::ONE_WEIGHT,
175                       const char *comment = nullptr);
176
177    void Switch(GateRef index, Label *defaultLabel, int64_t *keysValue, Label *keysLabel, int numberOfKeys);
178    void LoopBegin(Label *loopHead);
179    void LoopEnd(Label *loopHead);
180    /// LoopEnd with safepoint
181    void LoopEnd(Label *loopHead, Environment *env, GateRef glue);
182    GateRef CheckSuspend(GateRef glue);
183    // call operation
184    GateRef CallRuntime(GateRef glue, int index, const std::vector<GateRef>& args);
185    GateRef CallRuntime(GateRef glue, int index, GateRef argc, GateRef argv);
186    GateRef CallNGCRuntime(GateRef glue, int index,
187                           const std::vector<GateRef>& args, GateRef hir = Circuit::NullGate());
188    GateRef FastCallOptimized(GateRef glue, GateRef code,
189                              const std::vector<GateRef>& args, GateRef hir = Circuit::NullGate());
190    GateRef CallOptimized(GateRef glue, GateRef code,
191                          const std::vector<GateRef>& args, GateRef hir = Circuit::NullGate());
192    GateRef GetAotCodeAddr(GateRef jsFunc);
193    GateRef CallStub(GateRef glue, int index, const std::initializer_list<GateRef>& args);
194    GateRef CallBuiltinRuntime(GateRef glue, const std::initializer_list<GateRef>& args, bool isNew = false);
195    GateRef CallBuiltinRuntimeWithNewTarget(GateRef glue, const std::initializer_list<GateRef>& args);
196    void DebugPrint(GateRef thread, std::initializer_list<GateRef> args);
197    void FatalPrint(GateRef thread, std::initializer_list<GateRef> args);
198    // memory
199    GateRef Load(VariableType type, GateRef base, GateRef offset);
200    GateRef Load(VariableType type, GateRef base);
201    void Store(VariableType type,
202               GateRef glue,
203               GateRef base,
204               GateRef offset,
205               GateRef value,
206               MemoryAttribute mAttr = MemoryAttribute::Default());
207    // arithmetic
208    GateRef TaggedCastToIntPtr(GateRef x);
209    GateRef Int16Add(GateRef x, GateRef y);
210    GateRef Int32Add(GateRef x, GateRef y);
211    GateRef Int64Add(GateRef x, GateRef y);
212    GateRef DoubleAdd(GateRef x, GateRef y);
213    GateRef PtrAdd(GateRef x, GateRef y);
214    GateRef PtrSub(GateRef x, GateRef y);
215    GateRef PtrMul(GateRef x, GateRef y);
216    GateRef IntPtrEqual(GateRef x, GateRef y);
217    GateRef Int16Sub(GateRef x, GateRef y);
218    GateRef Int32Sub(GateRef x, GateRef y);
219    GateRef Int64Sub(GateRef x, GateRef y);
220    GateRef DoubleSub(GateRef x, GateRef y);
221    GateRef Int32Mul(GateRef x, GateRef y);
222    GateRef Int64Mul(GateRef x, GateRef y);
223    GateRef DoubleMul(GateRef x, GateRef y);
224    GateRef DoubleDiv(GateRef x, GateRef y);
225    GateRef Int32Div(GateRef x, GateRef y);
226    GateRef Int32Mod(GateRef x, GateRef y);
227    GateRef DoubleMod(GateRef x, GateRef y);
228    GateRef Int64Div(GateRef x, GateRef y);
229    GateRef IntPtrDiv(GateRef x, GateRef y);
230    // bit operation
231    GateRef Int32Or(GateRef x, GateRef y);
232    GateRef Int8And(GateRef x, GateRef y);
233    GateRef Int8Xor(GateRef x, GateRef y);
234    GateRef Int32And(GateRef x, GateRef y);
235    GateRef IntPtrAnd(GateRef x, GateRef y);
236    GateRef BitAnd(GateRef x, GateRef y);
237    GateRef BitOr(GateRef x, GateRef y);
238    GateRef Int32Not(GateRef x);
239    GateRef IntPtrNot(GateRef x);
240    GateRef BoolNot(GateRef x);
241    GateRef Int32Xor(GateRef x, GateRef y);
242    GateRef FixLoadType(GateRef x);
243    GateRef Int64Or(GateRef x, GateRef y);
244    GateRef IntPtrOr(GateRef x, GateRef y);
245    GateRef Int64And(GateRef x, GateRef y);
246    GateRef Int64Xor(GateRef x, GateRef y);
247    GateRef Int64Not(GateRef x);
248    GateRef Int16LSL(GateRef x, GateRef y);
249    GateRef Int32LSL(GateRef x, GateRef y);
250    GateRef Int64LSL(GateRef x, GateRef y);
251    GateRef IntPtrLSL(GateRef x, GateRef y);
252    GateRef Int8LSR(GateRef x, GateRef y);
253    GateRef Int32LSR(GateRef x, GateRef y);
254    GateRef Int64LSR(GateRef x, GateRef y);
255    GateRef IntPtrLSR(GateRef x, GateRef y);
256    GateRef Int32ASR(GateRef x, GateRef y);
257    GateRef TaggedIsInt(GateRef x);
258    GateRef TaggedIsDouble(GateRef x);
259    GateRef TaggedIsObject(GateRef x);
260    GateRef TaggedIsNumber(GateRef x);
261    GateRef TaggedIsNumeric(GateRef x);
262    GateRef TaggedIsHole(GateRef x);
263    GateRef TaggedIsNotHole(GateRef x);
264    GateRef TaggedIsUndefined(GateRef x);
265    GateRef TaggedIsException(GateRef x);
266    GateRef TaggedIsSpecial(GateRef x);
267    GateRef TaggedIsRegularObject(GateRef x);
268    GateRef TaggedIsHeapObject(GateRef x);
269    GateRef TaggedIsAccessor(GateRef x);
270    GateRef ObjectAddressToRange(GateRef x);
271    GateRef RegionInSpace(GateRef region, RegionSpaceFlag space);
272    GateRef RegionInSpace(GateRef region, RegionSpaceFlag spaceBegin, RegionSpaceFlag spaceEnd);
273    GateRef InEdenGeneration(GateRef region);
274    GateRef InYoungGeneration(GateRef region);
275    GateRef InGeneralYoungGeneration(GateRef region);
276    GateRef InGeneralOldGeneration(GateRef region);
277    GateRef InSharedHeap(GateRef region);
278    GateRef InSharedSweepableSpace(GateRef region);
279    GateRef TaggedIsGeneratorObject(GateRef x);
280    GateRef TaggedIsJSArray(GateRef x);
281    GateRef IsTaggedArray(GateRef x);
282    GateRef TaggedIsAsyncGeneratorObject(GateRef x);
283    GateRef TaggedIsJSGlobalObject(GateRef x);
284    GateRef TaggedIsWeak(GateRef x);
285    GateRef TaggedIsPrototypeHandler(GateRef x);
286    GateRef TaggedIsStoreTSHandler(GateRef x);
287    GateRef TaggedIsTransWithProtoHandler(GateRef x);
288    GateRef TaggedIsTransitionHandler(GateRef x);
289    GateRef TaggedIsString(GateRef obj);
290    GateRef TaggedIsStringIterator(GateRef obj);
291    GateRef TaggedIsSharedObj(GateRef obj);
292    GateRef BothAreString(GateRef x, GateRef y);
293    GateRef TaggedIsStringOrSymbol(GateRef obj);
294    GateRef TaggedIsSymbol(GateRef obj);
295    GateRef TaggedIsArrayBuffer(GateRef obj);
296    GateRef TaggedIsProtoChangeMarker(GateRef obj);
297    GateRef GetNextPositionForHash(GateRef last, GateRef count, GateRef size);
298    GateRef DoubleIsNAN(GateRef x);
299    GateRef DoubleIsINF(GateRef x);
300    GateRef DoubleIsNanOrInf(GateRef x);
301    GateRef DoubleAbs(GateRef x);
302    GateRef DoubleIsInteger(GateRef x);
303    GateRef DoubleTrunc(GateRef x);
304    GateRef TaggedIsNull(GateRef x);
305    GateRef TaggedIsUndefinedOrNull(GateRef x);
306    GateRef TaggedIsUndefinedOrNullOrHole(GateRef x);
307    GateRef TaggedIsTrue(GateRef x);
308    GateRef TaggedIsFalse(GateRef x);
309    GateRef TaggedIsBoolean(GateRef x);
310    GateRef TaggedGetInt(GateRef x);
311    GateRef NumberGetInt(GateRef glue, GateRef x);
312    GateRef TaggedGetNumber(GateRef x);
313    GateRef Int8ToTaggedInt(GateRef x);
314    GateRef Int16ToTaggedInt(GateRef x);
315    GateRef IntToTaggedPtr(GateRef x);
316    GateRef IntToTaggedInt(GateRef x);
317    GateRef Int64ToTaggedInt(GateRef x);
318    GateRef Int64ToTaggedIntPtr(GateRef x);
319    GateRef DoubleToTaggedDoublePtr(GateRef x);
320    GateRef BooleanToTaggedBooleanPtr(GateRef x);
321    GateRef TaggedPtrToTaggedDoublePtr(GateRef x);
322    GateRef TaggedPtrToTaggedIntPtr(GateRef x);
323    GateRef CastDoubleToInt64(GateRef x);
324    GateRef CastFloat32ToInt32(GateRef x);
325    GateRef TaggedTrue();
326    GateRef TaggedFalse();
327    GateRef TaggedUndefined();
328    // compare operation
329    GateRef Int8Equal(GateRef x, GateRef y);
330    GateRef Int8GreaterThanOrEqual(GateRef x, GateRef y);
331    GateRef Equal(GateRef x, GateRef y);
332    GateRef NotEqual(GateRef x, GateRef y);
333    GateRef Int32Equal(GateRef x, GateRef y);
334    GateRef Int32NotEqual(GateRef x, GateRef y);
335    GateRef Int64Equal(GateRef x, GateRef y);
336    GateRef DoubleEqual(GateRef x, GateRef y);
337    GateRef DoubleNotEqual(GateRef x, GateRef y);
338    GateRef Int64NotEqual(GateRef x, GateRef y);
339    GateRef DoubleLessThan(GateRef x, GateRef y);
340    GateRef DoubleLessThanOrEqual(GateRef x, GateRef y);
341    GateRef DoubleGreaterThan(GateRef x, GateRef y);
342    GateRef DoubleGreaterThanOrEqual(GateRef x, GateRef y);
343    GateRef Int32GreaterThan(GateRef x, GateRef y);
344    GateRef Int32LessThan(GateRef x, GateRef y);
345    GateRef Int32GreaterThanOrEqual(GateRef x, GateRef y);
346    GateRef Int32LessThanOrEqual(GateRef x, GateRef y);
347    GateRef Int32UnsignedGreaterThan(GateRef x, GateRef y);
348    GateRef Int32UnsignedLessThan(GateRef x, GateRef y);
349    GateRef Int32UnsignedGreaterThanOrEqual(GateRef x, GateRef y);
350    GateRef Int32UnsignedLessThanOrEqual(GateRef x, GateRef y);
351    GateRef Int64GreaterThan(GateRef x, GateRef y);
352    GateRef Int64LessThan(GateRef x, GateRef y);
353    GateRef Int64LessThanOrEqual(GateRef x, GateRef y);
354    GateRef Int64GreaterThanOrEqual(GateRef x, GateRef y);
355    GateRef Int64UnsignedLessThanOrEqual(GateRef x, GateRef y);
356    GateRef Int64UnsignedGreaterThan(GateRef x, GateRef y);
357    GateRef Int64UnsignedGreaterThanOrEqual(GateRef x, GateRef y);
358    GateRef IntPtrGreaterThan(GateRef x, GateRef y);
359    // cast operation
360    GateRef ChangeInt64ToIntPtr(GateRef val);
361    GateRef ZExtInt32ToPtr(GateRef val);
362    GateRef ChangeIntPtrToInt32(GateRef val);
363    GateRef ToLength(GateRef glue, GateRef target);
364    GateRef ToIndex(GateRef glue, GateRef tagged);
365
366    // math operation
367    GateRef Sqrt(GateRef x);
368    GateRef GetSetterFromAccessor(GateRef accessor);
369    GateRef GetElementsArray(GateRef object);
370    void SetElementsArray(VariableType type, GateRef glue, GateRef object, GateRef elementsArray,
371                          MemoryAttribute mAttr = MemoryAttribute::Default());
372    GateRef GetPropertiesArray(GateRef object);
373    // SetProperties in js_object.h
374    void SetPropertiesArray(VariableType type, GateRef glue, GateRef object, GateRef propsArray,
375                            MemoryAttribute mAttr = MemoryAttribute::Default());
376    GateRef GetHash(GateRef object);
377    void SetHash(GateRef glue, GateRef object, GateRef hash);
378    GateRef GetLengthOfTaggedArray(GateRef array);
379    GateRef GetLengthOfJSTypedArray(GateRef array);
380    GateRef GetExtractLengthOfTaggedArray(GateRef array);
381    // object operation
382    GateRef IsJSHClass(GateRef obj);
383    GateRef LoadHClass(GateRef object);
384    void CanNotConvertNotValidObject(GateRef obj);
385    void IsNotPropertyKey(GateRef obj);
386    GateRef CreateDataProperty(GateRef glue, GateRef obj, GateRef proKey, GateRef value);
387    GateRef CreateDataPropertyOrThrow(GateRef glue, GateRef onj, GateRef proKey, GateRef value);
388    GateRef DefineField(GateRef glue, GateRef obj, GateRef proKey, GateRef value);
389    void StoreHClass(GateRef glue, GateRef object, GateRef hClass);
390    void StoreHClassWithoutBarrier(GateRef glue, GateRef object, GateRef hClass);
391    void StoreBuiltinHClass(GateRef glue, GateRef object, GateRef hClass);
392    void StorePrototype(GateRef glue, GateRef hclass, GateRef prototype);
393    void CopyAllHClass(GateRef glue, GateRef dstHClass, GateRef scrHClass);
394    GateRef GetObjectType(GateRef hClass);
395    GateRef IsDictionaryMode(GateRef object);
396    GateRef IsDictionaryModeByHClass(GateRef hClass);
397    GateRef IsDictionaryElement(GateRef hClass);
398    GateRef IsStableElements(GateRef hClass);
399    GateRef HasConstructorByHClass(GateRef hClass);
400    GateRef HasConstructor(GateRef object);
401    GateRef IsClassConstructorFromBitField(GateRef bitfield);
402    GateRef IsClassConstructor(GateRef object);
403    GateRef IsClassPrototype(GateRef object);
404    GateRef IsExtensible(GateRef object);
405    GateRef TaggedObjectIsEcmaObject(GateRef obj);
406    GateRef IsEcmaObject(GateRef obj);
407    GateRef IsDataView(GateRef obj);
408    GateRef IsSymbol(GateRef obj);
409    GateRef IsString(GateRef obj);
410    GateRef IsLineString(GateRef obj);
411    GateRef IsSlicedString(GateRef obj);
412    GateRef IsConstantString(GateRef obj);
413    GateRef IsLiteralString(GateRef obj);
414    GateRef IsTreeString(GateRef obj);
415    GateRef TreeStringIsFlat(GateRef string);
416    GateRef TaggedIsBigInt(GateRef obj);
417    GateRef TaggedIsPropertyBox(GateRef obj);
418    GateRef TaggedObjectIsBigInt(GateRef obj);
419    GateRef IsJsProxy(GateRef obj);
420    GateRef IsJSShared(GateRef obj);
421    GateRef IsProfileTypeInfoCell0(GateRef obj);
422    GateRef IsJSGlobalObject(GateRef obj);
423    GateRef IsNativeModuleFailureInfo(GateRef obj);
424    GateRef IsModuleNamespace(GateRef obj);
425    GateRef IsSourceTextModule(GateRef obj);
426    GateRef ObjIsSpecialContainer(GateRef obj);
427    GateRef IsJSPrimitiveRef(GateRef obj);
428    GateRef IsJSFunctionBase(GateRef obj);
429    GateRef IsConstructor(GateRef object);
430    GateRef IsBase(GateRef func);
431    GateRef IsDerived(GateRef func);
432    GateRef IsJsArray(GateRef obj);
433    GateRef IsJsSArray(GateRef obj);
434    GateRef IsByteArray(GateRef obj);
435    GateRef IsJsCOWArray(GateRef obj);
436    GateRef IsCOWArray(GateRef obj);
437    GateRef IsMutantTaggedArray(GateRef elements);
438    GateRef IsJSObject(GateRef obj);
439    GateRef IsEnumerable(GateRef attr);
440    GateRef IsWritable(GateRef attr);
441    GateRef IsConfigable(GateRef attr);
442    GateRef IsDefaultAttribute(GateRef attr);
443    GateRef IsArrayLengthWritable(GateRef glue, GateRef receiver);
444    GateRef IsAccessor(GateRef attr);
445    GateRef IsInlinedProperty(GateRef attr);
446    GateRef IsField(GateRef attr);
447    GateRef IsNonSharedStoreField(GateRef attr);
448    GateRef IsStoreShared(GateRef attr);
449    GateRef IsElement(GateRef attr);
450    GateRef IsStringElement(GateRef attr);
451    GateRef IsNumber(GateRef attr);
452    GateRef IsStringLength(GateRef attr);
453    GateRef IsTypedArrayElement(GateRef attr);
454    GateRef IsNonExist(GateRef attr);
455    GateRef IsJSAPIVector(GateRef attr);
456    GateRef IsJSAPIStack(GateRef obj);
457    GateRef IsJSAPIPlainArray(GateRef obj);
458    GateRef IsJSAPIQueue(GateRef obj);
459    GateRef IsJSAPIDeque(GateRef obj);
460    GateRef IsJSAPILightWeightMap(GateRef obj);
461    GateRef IsJSAPILightWeightSet(GateRef obj);
462    GateRef IsLinkedNode(GateRef obj);
463    GateRef IsJSAPIHashMap(GateRef obj);
464    GateRef IsJSAPIHashSet(GateRef obj);
465    GateRef IsJSAPILinkedList(GateRef obj);
466    GateRef IsJSAPIList(GateRef obj);
467    GateRef IsJSAPIArrayList(GateRef obj);
468    GateRef IsJSCollator(GateRef obj);
469    GateRef IsJSObjectType(GateRef obj, JSType jsType);
470    GateRef IsJSRegExp(GateRef obj);
471    GateRef GetTarget(GateRef proxyObj);
472    GateRef HandlerBaseIsAccessor(GateRef attr);
473    GateRef HandlerBaseIsJSArray(GateRef attr);
474    GateRef HandlerBaseIsInlinedProperty(GateRef attr);
475    GateRef HandlerBaseGetOffset(GateRef attr);
476    GateRef HandlerBaseGetAttrIndex(GateRef attr);
477    GateRef HandlerBaseGetRep(GateRef attr);
478    GateRef IsInvalidPropertyBox(GateRef obj);
479    GateRef IsAccessorPropertyBox(GateRef obj);
480    GateRef GetValueFromPropertyBox(GateRef obj);
481    void SetValueToPropertyBox(GateRef glue, GateRef obj, GateRef value);
482    GateRef GetTransitionHClass(GateRef obj);
483    GateRef GetTransitionHandlerInfo(GateRef obj);
484    GateRef GetTransWithProtoHClass(GateRef obj);
485    GateRef GetTransWithProtoHandlerInfo(GateRef obj);
486    GateRef GetProtoCell(GateRef object);
487    GateRef GetPrototypeHandlerHolder(GateRef object);
488    GateRef GetPrototypeHandlerHandlerInfo(GateRef object);
489    GateRef GetStoreTSHandlerHolder(GateRef object);
490    GateRef GetStoreTSHandlerHandlerInfo(GateRef object);
491    inline GateRef GetLengthOfJSArray(GateRef array);
492    inline GateRef GetPrototype(GateRef glue, GateRef object);
493    GateRef GetHasChanged(GateRef object);
494    GateRef HclassIsPrototypeHandler(GateRef hClass);
495    GateRef HclassIsTransitionHandler(GateRef hClass);
496    GateRef HclassIsPropertyBox(GateRef hClass);
497    GateRef PropAttrGetOffset(GateRef attr);
498    GateRef GetCtorPrototype(GateRef ctor);
499    GateRef HasFunctionPrototype(GateRef ctor);
500    GateRef InstanceOf(GateRef glue, GateRef object, GateRef target, GateRef profileTypeInfo, GateRef slotId,
501        ProfileOperation callback);
502    GateRef OrdinaryHasInstance(GateRef glue, GateRef target, GateRef obj);
503    void TryFastHasInstance(GateRef glue, GateRef instof, GateRef target, GateRef object, Label *fastPath,
504                            Label *exit, Variable *result, ProfileOperation callback);
505    GateRef ConvertTaggedValueWithElementsKind(GateRef glue, GateRef value, GateRef extraKind);
506    GateRef SameValue(GateRef glue, GateRef left, GateRef right);
507    GateRef SameValueZero(GateRef glue, GateRef left, GateRef right);
508    GateRef HasStableElements(GateRef glue, GateRef obj);
509    GateRef IsStableJSArguments(GateRef glue, GateRef obj);
510    GateRef IsStableJSArray(GateRef glue, GateRef obj);
511    GateRef IsTypedArray(GateRef obj);
512    GateRef IsStableArguments(GateRef hClass);
513    GateRef IsStableArray(GateRef hClass);
514    GateRef GetProfileTypeInfo(GateRef jsFunc);
515    GateRef UpdateProfileTypeInfo(GateRef glue, GateRef jsFunc);
516    // SetDictionaryOrder func in property_attribute.h
517    GateRef SetDictionaryOrderFieldInPropAttr(GateRef attr, GateRef value);
518    GateRef GetPrototypeFromHClass(GateRef hClass);
519    GateRef GetEnumCacheFromHClass(GateRef hClass);
520    GateRef GetProtoChangeMarkerFromHClass(GateRef hClass);
521    GateRef GetLayoutFromHClass(GateRef hClass);
522    GateRef GetBitFieldFromHClass(GateRef hClass);
523    GateRef GetLengthFromString(GateRef value);
524    GateRef CalcHashcodeForInt(GateRef value);
525    void CalcHashcodeForDouble(GateRef value, Variable *res, Label *exit);
526    void CalcHashcodeForObject(GateRef glue, GateRef value, Variable *res, Label *exit);
527    GateRef GetHashcodeFromString(GateRef glue, GateRef value, GateRef hir = Circuit::NullGate());
528    inline GateRef IsIntegerString(GateRef string);
529    inline void SetRawHashcode(GateRef glue, GateRef str, GateRef rawHashcode, GateRef isInteger);
530    inline GateRef GetRawHashFromString(GateRef value);
531    GateRef TryGetHashcodeFromString(GateRef string);
532    inline GateRef GetMixHashcode(GateRef string);
533    GateRef GetFirstFromTreeString(GateRef string);
534    GateRef GetSecondFromTreeString(GateRef string);
535    GateRef GetIsAllTaggedPropFromHClass(GateRef hclass);
536    void SetBitFieldToHClass(GateRef glue, GateRef hClass, GateRef bitfield);
537    void SetIsAllTaggedProp(GateRef glue, GateRef hclass, GateRef hasRep);
538    void SetPrototypeToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef proto);
539    void SetProtoChangeDetailsToHClass(VariableType type, GateRef glue, GateRef hClass,
540                                       GateRef protoChange);
541    void SetLayoutToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef attr,
542                           MemoryAttribute mAttr = MemoryAttribute::Default());
543    void SetHClassTypeIDToHClass(GateRef glue, GateRef hClass, GateRef id);
544    void SetEnumCacheToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef key);
545    void SetTransitionsToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef transition);
546    void SetParentToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef parent);
547    void SetIsProtoTypeToHClass(GateRef glue, GateRef hClass, GateRef value);
548    inline void SetIsTS(GateRef glue, GateRef hClass, GateRef value);
549    GateRef IsProtoTypeHClass(GateRef hClass);
550    void SetPropertyInlinedProps(GateRef glue, GateRef obj, GateRef hClass,
551                                 GateRef value, GateRef attrOffset, VariableType type = VariableType::JS_ANY(),
552                                 MemoryAttribute mAttr = MemoryAttribute::Default());
553    GateRef GetPropertyInlinedProps(GateRef obj, GateRef hClass,
554        GateRef index);
555    GateRef GetInlinedPropOffsetFromHClass(GateRef hclass, GateRef attrOffset);
556
557    void IncNumberOfProps(GateRef glue, GateRef hClass);
558    GateRef GetNumberOfPropsFromHClass(GateRef hClass);
559    GateRef HasDeleteProperty(GateRef hClass);
560    GateRef IsTSHClass(GateRef hClass);
561    void SetNumberOfPropsToHClass(GateRef glue, GateRef hClass, GateRef value);
562    void SetElementsKindToTrackInfo(GateRef glue, GateRef trackInfo, GateRef elementsKind);
563    void SetSpaceFlagToTrackInfo(GateRef glue, GateRef trackInfo, GateRef spaceFlag);
564    GateRef GetElementsKindFromHClass(GateRef hClass);
565    GateRef GetObjectSizeFromHClass(GateRef hClass);
566    GateRef GetInlinedPropsStartFromHClass(GateRef hClass);
567    GateRef GetInlinedPropertiesFromHClass(GateRef hClass);
568    void ThrowTypeAndReturn(GateRef glue, int messageId, GateRef val);
569    GateRef GetValueFromTaggedArray(GateRef elements, GateRef index);
570    GateRef GetDataPtrInTaggedArray(GateRef array);
571    GateRef GetUnsharedConstpoolIndex(GateRef constpool);
572    GateRef GetUnsharedConstpoolFromGlue(GateRef glue, GateRef constpool);
573    GateRef GetUnsharedConstpool(GateRef array, GateRef index);
574    GateRef GetValueFromMutantTaggedArray(GateRef elements, GateRef index);
575    void CheckUpdateSharedType(bool isDicMode, Variable *result, GateRef glue, GateRef receiver, GateRef attr,
576                               GateRef value, Label *executeSetProp, Label *exit);
577    void CheckUpdateSharedType(bool isDicMode, Variable *result, GateRef glue, GateRef receiver, GateRef attr,
578                               GateRef value, Label *executeSetProp, Label *exit, GateRef SCheckModelIsCHECK);
579    void MatchFieldType(Variable *result, GateRef glue, GateRef fieldType, GateRef value, Label *executeSetProp,
580                               Label *exit);
581    GateRef GetFieldTypeFromHandler(GateRef attr);
582    GateRef ClearSharedStoreKind(GateRef handlerInfo);
583    GateRef UpdateSOutOfBoundsForHandler(GateRef handlerInfo);
584    void RestoreElementsKindToGeneric(GateRef glue, GateRef jsHClass);
585    GateRef GetTaggedValueWithElementsKind(GateRef receiver, GateRef index);
586    void FastSetValueWithElementsKind(GateRef glue, GateRef elements, GateRef rawValue,
587                                      GateRef index, ElementsKind kind);
588    GateRef SetValueWithElementsKind(GateRef glue, GateRef receiver, GateRef rawValue, GateRef index,
589                                     GateRef needTransition, GateRef extraKind);
590    GateRef CopyJSArrayToTaggedArrayArgs(GateRef glue, GateRef srcObj);
591    void SetValueToTaggedArrayWithAttr(
592        GateRef glue, GateRef array, GateRef index, GateRef key, GateRef val, GateRef attr);
593    void SetValueToTaggedArrayWithRep(
594        GateRef glue, GateRef array, GateRef index, GateRef val, GateRef rep, Label *repChange);
595
596    void SetValueToTaggedArray(VariableType valType, GateRef glue, GateRef array, GateRef index, GateRef val,
597                               MemoryAttribute mAttr = MemoryAttribute::Default());
598    void UpdateValueAndAttributes(GateRef glue, GateRef elements, GateRef index, GateRef value, GateRef attr);
599    GateRef IsSpecialIndexedObj(GateRef jsType);
600    GateRef IsSpecialContainer(GateRef jsType);
601    GateRef IsSharedArray(GateRef jsType);
602    GateRef IsAccessorInternal(GateRef value);
603    template<typename DictionaryT>
604    GateRef GetAttributesFromDictionary(GateRef elements, GateRef entry);
605    template<typename DictionaryT>
606    GateRef GetValueFromDictionary(GateRef elements, GateRef entry);
607    template<typename DictionaryT>
608    GateRef GetKeyFromDictionary(GateRef elements, GateRef entry);
609    GateRef GetPropAttrFromLayoutInfo(GateRef layout, GateRef entry);
610    void UpdateFieldType(GateRef glue, GateRef hclass, GateRef attr);
611    GateRef GetPropertiesAddrFromLayoutInfo(GateRef layout);
612    GateRef GetPropertyMetaDataFromAttr(GateRef attr);
613    GateRef TranslateToRep(GateRef value);
614    GateRef GetKeyFromLayoutInfo(GateRef layout, GateRef entry);
615    void MatchFieldType(GateRef glue, GateRef fieldType, GateRef value, Label *executeSetProp, Label *typeMismatch);
616    GateRef FindElementWithCache(GateRef glue, GateRef layoutInfo, GateRef hClass,
617        GateRef key, GateRef propsNum, GateRef hir = Circuit::NullGate());
618    GateRef FindElementFromNumberDictionary(GateRef glue, GateRef elements, GateRef index);
619    GateRef FindEntryFromNameDictionary(GateRef glue, GateRef elements, GateRef key, GateRef hir = Circuit::NullGate());
620    GateRef IsMatchInTransitionDictionary(GateRef element, GateRef key, GateRef metaData, GateRef attr);
621    GateRef FindEntryFromTransitionDictionary(GateRef glue, GateRef elements, GateRef key, GateRef metaData);
622    GateRef JSObjectGetProperty(GateRef obj, GateRef hClass, GateRef propAttr);
623    void JSObjectSetProperty(GateRef glue, GateRef obj, GateRef hClass, GateRef attr, GateRef key, GateRef value);
624    GateRef ShouldCallSetter(GateRef receiver, GateRef holder, GateRef accessor, GateRef attr);
625    GateRef CallSetterHelper(GateRef glue, GateRef holder, GateRef accessor,  GateRef value, ProfileOperation callback);
626    GateRef SetHasConstructorCondition(GateRef glue, GateRef receiver, GateRef key);
627    GateRef AddPropertyByName(GateRef glue, GateRef receiver, GateRef key, GateRef value, GateRef propertyAttributes,
628        ProfileOperation callback);
629    GateRef IsUtf16String(GateRef string);
630    GateRef IsUtf8String(GateRef string);
631    GateRef IsInternalString(GateRef string);
632    GateRef IsDigit(GateRef ch);
633    void TryToGetInteger(GateRef string, Variable *num, Label *success, Label *failed);
634    GateRef StringToElementIndex(GateRef glue, GateRef string);
635    GateRef ComputeElementCapacity(GateRef oldLength);
636    GateRef ComputeNonInlinedFastPropsCapacity(GateRef glue, GateRef oldLength,
637                                               GateRef maxNonInlinedFastPropsCapacity);
638    GateRef FindTransitions(GateRef glue, GateRef hClass, GateRef key, GateRef attr, GateRef value);
639    GateRef CheckHClassForRep(GateRef hClass, GateRef rep);
640    void TransitionForRepChange(GateRef glue, GateRef receiver, GateRef key, GateRef attr);
641    void TransitToElementsKind(GateRef glue, GateRef receiver, GateRef value, GateRef kind);
642    void TryMigrateToGenericKindForJSObject(GateRef glue, GateRef receiver, GateRef oldKind);
643    GateRef TaggedToRepresentation(GateRef value);
644    GateRef TaggedToElementKind(GateRef value);
645    GateRef LdGlobalRecord(GateRef glue, GateRef key);
646    GateRef LoadFromField(GateRef receiver, GateRef handlerInfo);
647    GateRef LoadGlobal(GateRef cell);
648    GateRef LoadElement(GateRef glue, GateRef receiver, GateRef key);
649    GateRef LoadStringElement(GateRef glue, GateRef receiver, GateRef key);
650    GateRef TryToElementsIndex(GateRef glue, GateRef key);
651    GateRef CheckPolyHClass(GateRef cachedValue, GateRef hClass);
652    GateRef LoadICWithHandler(
653        GateRef glue, GateRef receiver, GateRef holder, GateRef handler, ProfileOperation callback);
654    GateRef StoreICWithHandler(GateRef glue, GateRef receiver, GateRef holder,
655                               GateRef value, GateRef handler, ProfileOperation callback = ProfileOperation());
656    GateRef TaggedArraySetValue(GateRef glue, GateRef receiver, GateRef value, GateRef index, GateRef capacity);
657    GateRef ICStoreElement(GateRef glue, GateRef receiver, GateRef key, GateRef value, GateRef handlerInfo,
658                           bool updateHandler = false, GateRef profileTypeInfo = Gate::InvalidGateRef,
659                           GateRef slotId = Gate::InvalidGateRef);
660    GateRef GetArrayLength(GateRef object);
661    GateRef DoubleToInt(GateRef glue, GateRef x, size_t bits = base::INT32_BITS);
662    void SetArrayLength(GateRef glue, GateRef object, GateRef len);
663    GateRef StoreField(GateRef glue, GateRef receiver, GateRef value, GateRef handler, ProfileOperation callback);
664    GateRef StoreWithTransition(GateRef glue, GateRef receiver, GateRef value, GateRef handler,
665                             ProfileOperation callback, bool withPrototype = false);
666    GateRef StoreGlobal(GateRef glue, GateRef value, GateRef cell);
667    void JSHClassAddProperty(GateRef glue, GateRef receiver, GateRef key, GateRef attr, GateRef value);
668    void NotifyHClassChanged(GateRef glue, GateRef oldHClass, GateRef newHClass);
669    GateRef GetInt64OfTInt(GateRef x);
670    GateRef GetInt32OfTInt(GateRef x);
671    GateRef GetDoubleOfTInt(GateRef x);
672    GateRef GetDoubleOfTDouble(GateRef x);
673    GateRef GetInt32OfTNumber(GateRef x);
674    GateRef GetDoubleOfTNumber(GateRef x);
675    GateRef LoadObjectFromWeakRef(GateRef x);
676    GateRef ExtFloat32ToDouble(GateRef x);
677    GateRef ChangeInt32ToFloat32(GateRef x);
678    GateRef ChangeInt32ToFloat64(GateRef x);
679    GateRef ChangeUInt32ToFloat64(GateRef x);
680    GateRef ChangeFloat64ToInt32(GateRef x);
681    GateRef TruncDoubleToFloat32(GateRef x);
682    GateRef DeletePropertyOrThrow(GateRef glue, GateRef obj, GateRef value);
683    inline GateRef ToObject(GateRef glue, GateRef obj);
684    GateRef DeleteProperty(GateRef glue, GateRef obj, GateRef value);
685    inline GateRef OrdinaryNewJSObjectCreate(GateRef glue, GateRef proto);
686    inline GateRef NewJSPrimitiveRef(GateRef glue, size_t index, GateRef obj);
687    GateRef ModuleNamespaceDeleteProperty(GateRef glue, GateRef obj, GateRef value);
688    GateRef Int64ToTaggedPtr(GateRef x);
689    GateRef TruncInt16ToInt8(GateRef x);
690    GateRef TruncInt32ToInt16(GateRef x);
691    GateRef TruncInt32ToInt8(GateRef x);
692    GateRef TruncFloatToInt64(GateRef x);
693    GateRef CastInt32ToFloat32(GateRef x);
694    GateRef CastInt64ToFloat64(GateRef x);
695    GateRef SExtInt32ToInt64(GateRef x);
696    GateRef SExtInt16ToInt64(GateRef x);
697    GateRef SExtInt16ToInt32(GateRef x);
698    GateRef SExtInt8ToInt64(GateRef x);
699    GateRef SExtInt8ToInt32(GateRef x);
700    GateRef SExtInt1ToInt64(GateRef x);
701    GateRef SExtInt1ToInt32(GateRef x);
702    GateRef ZExtInt8ToInt16(GateRef x);
703    GateRef ZExtInt32ToInt64(GateRef x);
704    GateRef ZExtInt1ToInt64(GateRef x);
705    GateRef ZExtInt1ToInt32(GateRef x);
706    GateRef ZExtInt8ToInt32(GateRef x);
707    GateRef ZExtInt8ToInt64(GateRef x);
708    GateRef ZExtInt8ToPtr(GateRef x);
709    GateRef ZExtInt16ToPtr(GateRef x);
710    GateRef SExtInt32ToPtr(GateRef x);
711    GateRef ZExtInt16ToInt32(GateRef x);
712    GateRef ZExtInt16ToInt64(GateRef x);
713    GateRef TruncInt64ToInt32(GateRef x);
714    GateRef TruncPtrToInt32(GateRef x);
715    GateRef TruncInt64ToInt1(GateRef x);
716    GateRef TruncInt32ToInt1(GateRef x);
717    GateRef GetGlobalConstantAddr(GateRef index);
718    GateRef GetGlobalConstantOffset(ConstantIndex index);
719    GateRef IsCallableFromBitField(GateRef bitfield);
720    GateRef IsCallable(GateRef obj);
721    GateRef GetOffsetFieldInPropAttr(GateRef attr);
722    GateRef SetOffsetFieldInPropAttr(GateRef attr, GateRef value);
723    GateRef SetIsInlinePropsFieldInPropAttr(GateRef attr, GateRef value);
724    GateRef SetTrackTypeInPropAttr(GateRef attr, GateRef type);
725    GateRef GetTrackTypeInPropAttr(GateRef attr);
726    GateRef GetSharedFieldTypeInPropAttr(GateRef attr);
727    GateRef GetDictSharedFieldTypeInPropAttr(GateRef attr);
728    GateRef GetRepInPropAttr(GateRef attr);
729    GateRef IsIntRepInPropAttr(GateRef attr);
730    GateRef IsDoubleRepInPropAttr(GateRef attr);
731    GateRef IsTaggedRepInPropAttr(GateRef attr);
732    GateRef SetTaggedRepInPropAttr(GateRef attr);
733    template<class T>
734    void SetHClassBit(GateRef glue, GateRef hClass, GateRef value);
735    template<typename DictionaryT>
736    void UpdateValueInDict(GateRef glue, GateRef elements, GateRef index, GateRef value);
737    GateRef GetBitMask(GateRef bitoffset);
738    GateRef IntPtrEuqal(GateRef x, GateRef y);
739    GateRef IntPtrNotEqual(GateRef x, GateRef y);
740    void SetValueWithAttr(GateRef glue, GateRef obj, GateRef offset, GateRef key, GateRef value, GateRef attr);
741    void SetValueWithRep(GateRef glue, GateRef obj, GateRef offset, GateRef value, GateRef rep, Label *repChange);
742    void VerifyBarrier(GateRef glue, GateRef obj, GateRef offset, GateRef value);
743    void SetValueWithBarrier(GateRef glue, GateRef obj, GateRef offset, GateRef value, bool withEden = false,
744                             MemoryAttribute::ShareFlag share = MemoryAttribute::UNKNOWN);
745    GateRef GetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index,
746                               ProfileOperation callback, GateRef hir = Circuit::NullGate());
747    GateRef GetPropertyByName(GateRef glue, GateRef receiver, GateRef key,
748                              ProfileOperation callback, GateRef isInternal, bool canUseIsInternal = false);
749    GateRef FastGetPropertyByName(GateRef glue, GateRef obj, GateRef key, ProfileOperation callback);
750    GateRef FastGetPropertyByIndex(GateRef glue, GateRef obj, GateRef index,
751                                   ProfileOperation callback, GateRef hir = Circuit::NullGate());
752    GateRef GetPropertyByValue(GateRef glue, GateRef receiver, GateRef keyValue, ProfileOperation callback);
753    void FastSetPropertyByName(GateRef glue, GateRef obj, GateRef key, GateRef value,
754        ProfileOperation callback = ProfileOperation());
755    void FastSetPropertyByIndex(GateRef glue, GateRef obj, GateRef index, GateRef value);
756    GateRef SetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index,
757        GateRef value, bool useOwn, ProfileOperation callback = ProfileOperation(), bool defineSemantics = false);
758    GateRef DefinePropertyByIndex(GateRef glue, GateRef receiver, GateRef index, GateRef value);
759    GateRef SetPropertyByName(GateRef glue, GateRef receiver, GateRef key,
760        GateRef value, bool useOwn, GateRef isInternal, ProfileOperation callback = ProfileOperation(),
761        bool canUseIsInternal = false, bool defineSemantics = false); // Crawl prototype chain
762    GateRef DefinePropertyByName(GateRef glue, GateRef receiver, GateRef key,
763        GateRef value, GateRef isInternal, GateRef SCheckModelIsCHECK,
764        ProfileOperation callback = ProfileOperation());
765    GateRef SetPropertyByValue(GateRef glue, GateRef receiver, GateRef key, GateRef value, bool useOwn,
766        ProfileOperation callback = ProfileOperation(), bool defineSemantics = false);
767    GateRef DefinePropertyByValue(GateRef glue, GateRef receiver, GateRef key, GateRef value,
768        GateRef SCheckModelIsCHECK, ProfileOperation callback = ProfileOperation());
769    GateRef GetParentEnv(GateRef object);
770    GateRef GetSendableParentEnv(GateRef object);
771    GateRef GetPropertiesFromLexicalEnv(GateRef object, GateRef index);
772    GateRef GetPropertiesFromSendableEnv(GateRef object, GateRef index);
773    GateRef GetKeyFromLexivalEnv(GateRef lexicalEnv, GateRef levelIndex, GateRef slotIndex);
774    void SetPropertiesToLexicalEnv(GateRef glue, GateRef object, GateRef index, GateRef value);
775    void SetPropertiesToSendableEnv(GateRef glue, GateRef object, GateRef index, GateRef value);
776    GateRef GetHomeObjectFromJSFunction(GateRef object);
777    GateRef GetCallFieldFromMethod(GateRef method);
778    GateRef GetSendableEnvFromModule(GateRef module);
779    GateRef GetProtoOrHClass(GateRef function);
780    GateRef IsSendableFunctionModule(GateRef module);
781    inline GateRef GetBuiltinId(GateRef method);
782    void SetLexicalEnvToFunction(GateRef glue, GateRef object, GateRef lexicalEnv,
783                                 MemoryAttribute mAttr = MemoryAttribute::Default());
784    void SetProtoTransRootHClassToFunction(GateRef glue, GateRef object, GateRef hclass,
785                                           MemoryAttribute mAttr = MemoryAttribute::Default());
786    void SetProtoOrHClassToFunction(GateRef glue, GateRef function, GateRef value,
787                                    MemoryAttribute mAttr = MemoryAttribute::Default());
788    void SetWorkNodePointerToFunction(GateRef glue, GateRef function, GateRef value,
789                                      MemoryAttribute mAttr = MemoryAttribute::Default());
790    void SetHomeObjectToFunction(GateRef glue, GateRef function, GateRef value,
791                                 MemoryAttribute mAttr = MemoryAttribute::Default());
792    void SetModuleToFunction(GateRef glue, GateRef function, GateRef value,
793                             MemoryAttribute mAttr = MemoryAttribute::Default());
794    void SetMethodToFunction(GateRef glue, GateRef function, GateRef value,
795                             MemoryAttribute mAttr = MemoryAttribute::Default());
796    void SetCodeEntryToFunctionFromMethod(GateRef glue, GateRef function, GateRef value);
797    void SetCodeEntryToFunctionFromFuncEntry(GateRef glue, GateRef function, GateRef value);
798    void SetCompiledCodeFlagToFunctionFromMethod(GateRef glue, GateRef function, GateRef value);
799    void SetLengthToFunction(GateRef glue, GateRef function, GateRef value);
800    void SetRawProfileTypeInfoToFunction(GateRef glue, GateRef function, GateRef value,
801                                         MemoryAttribute mAttr = MemoryAttribute::Default());
802    void SetValueToProfileTypeInfoCell(GateRef glue, GateRef profileTypeInfoCell, GateRef value);
803    void UpdateProfileTypeInfoCellType(GateRef glue, GateRef profileTypeInfoCell);
804    void SetJSObjectTaggedField(GateRef glue, GateRef object, size_t offset, GateRef value);
805    void SetSendableEnvToModule(GateRef glue, GateRef module, GateRef value,
806                                MemoryAttribute mAttr = MemoryAttribute::Default());
807    void SetCompiledCodeFlagToFunction(GateRef glue, GateRef function, GateRef value);
808    void SetCompiledFastCallFlagToFunction(GateRef glue, GateRef function, GateRef value);
809    void SetCompiledFuncEntry(GateRef glue, GateRef jsFunc, GateRef codeEntry, GateRef isFastCall);
810    GateRef GetFuncEntryDes(GateRef glue, GateRef machineCode, GateRef codeAddr);
811    GateRef GetFuncEntryDesAddress(GateRef machineCode);
812    GateRef IsAlign(GateRef address, GateRef alignByte);
813    void SetTaskConcurrentFuncFlagToFunction(GateRef glue, GateRef function, GateRef value);
814    void SetBitFieldToFunction(GateRef glue, GateRef function, GateRef value);
815    void SetMachineCodeToFunction(GateRef glue, GateRef function, GateRef value,
816                                  MemoryAttribute mAttr = MemoryAttribute::Default());
817    void SetTypedArrayName(GateRef glue, GateRef typedArray, GateRef name,
818                           MemoryAttribute mAttr = MemoryAttribute::Default());
819    void SetContentType(GateRef glue, GateRef typedArray, GateRef type);
820    void SetViewedArrayBufferOrByteArray(GateRef glue, GateRef typedArray, GateRef data,
821                                         MemoryAttribute mAttr = MemoryAttribute::Default());
822    void SetByteLength(GateRef glue, GateRef typedArray, GateRef byteLength);
823    void SetByteOffset(GateRef glue, GateRef typedArray, GateRef offset);
824    void SetTypedArrayLength(GateRef glue, GateRef typedArray, GateRef arrayLength);
825    GateRef GetGlobalObject(GateRef glue);
826    GateRef GetMethodFromFunction(GateRef function);
827    GateRef GetModuleFromFunction(GateRef function);
828    GateRef GetLengthFromFunction(GateRef function);
829    GateRef GetHomeObjectFromFunction(GateRef function);
830    GateRef GetEntryIndexOfGlobalDictionary(GateRef entry);
831    GateRef GetBoxFromGlobalDictionary(GateRef object, GateRef entry);
832    GateRef GetValueFromGlobalDictionary(GateRef object, GateRef entry);
833    GateRef GetPropertiesFromJSObject(GateRef object);
834    template<OpCode Op, MachineType Type>
835    GateRef BinaryOp(GateRef x, GateRef y);
836    template<OpCode Op, MachineType Type>
837    GateRef BinaryOpWithOverflow(GateRef x, GateRef y);
838    GateRef GetGlobalOwnProperty(GateRef glue, GateRef receiver, GateRef key, ProfileOperation callback);
839    GateRef AddElementInternal(GateRef glue, GateRef receiver, GateRef index, GateRef value, GateRef attr);
840    GateRef ShouldTransToDict(GateRef capcity, GateRef index);
841    void NotifyStableArrayElementsGuardians(GateRef glue, GateRef receiver);
842    GateRef GrowElementsCapacity(GateRef glue, GateRef receiver, GateRef capacity);
843
844    inline GateRef GetObjectFromConstPool(GateRef constpool, GateRef index);
845    GateRef GetConstPoolFromFunction(GateRef jsFunc);
846    GateRef GetStringFromConstPool(GateRef glue, GateRef constpool, GateRef index);
847    GateRef GetMethodFromConstPool(GateRef glue, GateRef constpool, GateRef index);
848    GateRef GetArrayLiteralFromConstPool(GateRef glue, GateRef constpool, GateRef index, GateRef module);
849    GateRef GetObjectLiteralFromConstPool(GateRef glue, GateRef constpool, GateRef index, GateRef module);
850    void SetElementsKindToJSHClass(GateRef glue, GateRef jsHclass, GateRef elementsKind);
851    void SetExtensibleToBitfield(GateRef glue, GateRef obj, bool isExtensible);
852    void SetCallableToBitfield(GateRef glue, GateRef obj, bool isCallable);
853
854    // fast path
855    GateRef FastEqual(GateRef glue, GateRef left, GateRef right, ProfileOperation callback);
856    GateRef FastStrictEqual(GateRef glue, GateRef left, GateRef right, ProfileOperation callback);
857    GateRef FastStringEqual(GateRef glue, GateRef left, GateRef right);
858    GateRef FastMod(GateRef gule, GateRef left, GateRef right, ProfileOperation callback);
859    GateRef FastTypeOf(GateRef left, GateRef right);
860    GateRef FastMul(GateRef glue, GateRef left, GateRef right, ProfileOperation callback);
861    GateRef FastDiv(GateRef left, GateRef right, ProfileOperation callback);
862    GateRef FastAdd(GateRef glue, GateRef left, GateRef right, ProfileOperation callback);
863    GateRef FastSub(GateRef glue, GateRef left, GateRef right, ProfileOperation callback);
864    GateRef FastToBoolean(GateRef value, bool flag = true);
865    GateRef FastToBooleanWithProfile(GateRef value, ProfileOperation callback, bool flag = true);
866    GateRef FastToBooleanWithProfileBaseline(GateRef value, ProfileOperation callback, bool flag = true);
867
868    // Add SpecialContainer
869    GateRef GetContainerProperty(GateRef glue, GateRef receiver, GateRef index, GateRef jsType);
870    GateRef JSAPIContainerGet(GateRef glue, GateRef receiver, GateRef index);
871
872    // for-in
873    GateRef NextInternal(GateRef glue, GateRef iter);
874    GateRef GetLengthFromForInIterator(GateRef iter);
875    GateRef GetIndexFromForInIterator(GateRef iter);
876    GateRef GetKeysFromForInIterator(GateRef iter);
877    GateRef GetObjectFromForInIterator(GateRef iter);
878    GateRef GetCachedHclassFromForInIterator(GateRef iter);
879    void SetLengthOfForInIterator(GateRef glue, GateRef iter, GateRef length);
880    void SetIndexOfForInIterator(GateRef glue, GateRef iter, GateRef index);
881    void SetKeysOfForInIterator(GateRef glue, GateRef iter, GateRef keys);
882    void SetObjectOfForInIterator(GateRef glue, GateRef iter, GateRef object);
883    void SetCachedHclassOfForInIterator(GateRef glue, GateRef iter, GateRef hclass);
884    void IncreaseInteratorIndex(GateRef glue, GateRef iter, GateRef index);
885    void SetNextIndexOfArrayIterator(GateRef glue, GateRef iter, GateRef nextIndex);
886    void SetIteratedArrayOfArrayIterator(GateRef glue, GateRef iter, GateRef iteratedArray);
887    void SetBitFieldOfArrayIterator(GateRef glue, GateRef iter, GateRef kind);
888    GateRef GetEnumCacheKind(GateRef glue, GateRef enumCache);
889    GateRef GetEmptyArray(GateRef glue);
890    GateRef IsEnumCacheValid(GateRef receiver, GateRef cachedHclass, GateRef kind);
891    GateRef NeedCheckProperty(GateRef receiver);
892
893    GateRef EnumerateObjectProperties(GateRef glue, GateRef obj);
894    GateRef GetFunctionPrototype(GateRef glue, size_t index);
895    GateRef ToPrototypeOrObj(GateRef glue, GateRef obj);
896    GateRef IsSpecialKeysObject(GateRef obj);
897    GateRef IsSlowKeysObject(GateRef obj);
898    GateRef TryGetEnumCache(GateRef glue, GateRef obj);
899    GateRef GetNumberOfElements(GateRef obj);
900    GateRef IsSimpleEnumCacheValid(GateRef obj);
901    GateRef IsEnumCacheWithProtoChainInfoValid(GateRef obj);
902
903    // Exception handle
904    GateRef HasPendingException(GateRef glue);
905    void ReturnExceptionIfAbruptCompletion(GateRef glue);
906
907    // ElementsKind Operations
908    GateRef ValueIsSpecialHole(GateRef x);
909    GateRef ElementsKindIsIntOrHoleInt(GateRef kind);
910    GateRef ElementsKindIsNumOrHoleNum(GateRef kind);
911    GateRef ElementsKindIsHeapKind(GateRef kind);
912    GateRef ElementsKindHasHole(GateRef kind);
913    void MigrateArrayWithKind(GateRef glue, GateRef object, GateRef oldKind, GateRef newKind);
914    GateRef MigrateFromRawValueToHeapValues(GateRef glue, GateRef object, GateRef needCOW, GateRef isIntKind);
915    GateRef MigrateFromHeapValueToRawValue(GateRef glue, GateRef object, GateRef needCOW, GateRef isIntKind);
916    void MigrateFromHoleIntToHoleNumber(GateRef glue, GateRef object);
917    void MigrateFromHoleNumberToHoleInt(GateRef glue, GateRef object);
918
919    // method operator
920    GateRef IsJSFunction(GateRef obj);
921    GateRef IsBoundFunction(GateRef obj);
922    GateRef IsJSOrBoundFunction(GateRef obj);
923    GateRef GetMethodFromJSFunctionOrProxy(GateRef jsfunc);
924    GateRef IsNativeMethod(GateRef method);
925    GateRef GetFuncKind(GateRef method);
926    GateRef HasPrototype(GateRef kind);
927    GateRef HasAccessor(GateRef kind);
928    GateRef IsClassConstructorKind(GateRef kind);
929    GateRef IsGeneratorKind(GateRef kind);
930    GateRef IsBaseKind(GateRef kind);
931    GateRef IsBaseConstructorKind(GateRef kind);
932    GateRef IsSendableFunction(GateRef method);
933
934    GateRef IsAOTLiteralInfo(GateRef info);
935    GateRef GetIhcFromAOTLiteralInfo(GateRef info);
936    GateRef IsAotWithCallField(GateRef method);
937    GateRef IsFastCall(GateRef method);
938    GateRef JudgeAotAndFastCall(GateRef jsFunc, CircuitBuilder::JudgeMethodType type);
939    GateRef GetInternalString(GateRef glue, GateRef key);
940    GateRef GetExpectedNumOfArgs(GateRef method);
941    GateRef GetMethod(GateRef glue, GateRef obj, GateRef key, GateRef profileTypeInfo, GateRef slotId);
942    // proxy operator
943    GateRef GetMethodFromJSProxy(GateRef proxy);
944    GateRef GetHandlerFromJSProxy(GateRef proxy);
945    GateRef GetTargetFromJSProxy(GateRef proxy);
946    inline void SetHotnessCounter(GateRef glue, GateRef method, GateRef value);
947    inline void SaveHotnessCounterIfNeeded(GateRef glue, GateRef sp, GateRef hotnessCounter, JSCallMode mode);
948    inline void SavePcIfNeeded(GateRef glue);
949    inline void SaveJumpSizeIfNeeded(GateRef glue, GateRef jumpSize);
950    inline GateRef ComputeTaggedArraySize(GateRef length);
951    inline GateRef GetGlobalConstantValue(
952        VariableType type, GateRef glue, ConstantIndex index);
953    inline GateRef GetSingleCharTable(GateRef glue);
954    inline GateRef IsEnableElementsKind(GateRef glue);
955    inline GateRef GetGlobalEnvValue(VariableType type, GateRef env, size_t index);
956    GateRef CallGetterHelper(GateRef glue, GateRef receiver, GateRef holder,
957                             GateRef accessor, ProfileOperation callback, GateRef hir = Circuit::NullGate());
958    GateRef ConstructorCheck(GateRef glue, GateRef ctor, GateRef outPut, GateRef thisObj);
959    GateRef GetCallSpreadArgs(GateRef glue, GateRef array, ProfileOperation callBack);
960    GateRef GetIterator(GateRef glue, GateRef obj, ProfileOperation callback);
961    // For BaselineJIT
962    GateRef FastToBooleanBaseline(GateRef value, bool flag = true);
963    GateRef GetBaselineCodeAddr(GateRef baselineCode);
964
965    GateRef IsFastTypeArray(GateRef jsType);
966    GateRef GetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef jsType);
967    GateRef SetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef value,
968                                       GateRef jsType);
969    GateRef TryStringOrSymbolToElementIndex(GateRef glue, GateRef key);
970    inline GateRef DispatchBuiltins(GateRef glue, GateRef builtinsId, const std::vector<GateRef>& args);
971    inline GateRef DispatchBuiltinsWithArgv(GateRef glue, GateRef builtinsId, const std::vector<GateRef>& args);
972    GateRef ComputeSizeUtf8(GateRef length);
973    GateRef ComputeSizeUtf16(GateRef length);
974    GateRef AlignUp(GateRef x, GateRef alignment);
975    inline void SetLength(GateRef glue, GateRef str, GateRef length, bool compressed);
976    inline void SetLength(GateRef glue, GateRef str, GateRef length, GateRef isCompressed);
977    void Assert(int messageId, int line, GateRef glue, GateRef condition, Label *nextLabel);
978
979    GateRef GetNormalStringData(const StringInfoGateRef &stringInfoGate);
980
981    void Comment(GateRef glue, const std::string &str);
982    GateRef ToNumber(GateRef glue, GateRef tagged);
983    inline GateRef LoadPfHeaderFromConstPool(GateRef jsFunc);
984    GateRef RemoveTaggedWeakTag(GateRef weak);
985    inline GateRef LoadHCIndexFromConstPool(GateRef cachedArray, GateRef cachedLength, GateRef traceId, Label *miss);
986    inline GateRef LoadHCIndexInfosFromConstPool(GateRef jsFunc);
987    inline GateRef GetAttrIndex(GateRef index);
988    inline GateRef GetAttr(GateRef layoutInfo, GateRef index);
989    inline GateRef GetKey(GateRef layoutInfo, GateRef index);
990    inline GateRef GetKeyIndex(GateRef index);
991    GateRef CalArrayRelativePos(GateRef index, GateRef arrayLen);
992    GateRef AppendSkipHole(GateRef glue, GateRef first, GateRef second, GateRef copyLength);
993    GateRef IntToEcmaString(GateRef glue, GateRef number);
994    GateRef ToCharCode(GateRef number);
995    GateRef NumberToString(GateRef glue, GateRef number);
996    inline GateRef GetViewedArrayBuffer(GateRef dataView);
997    inline GateRef GetByteOffset(GateRef dataView);
998    inline GateRef GetByteLength(GateRef dataView);
999    inline GateRef GetArrayBufferData(GateRef buffer);
1000    inline GateRef GetArrayBufferByteLength(GateRef buffer);
1001    inline void SetArrayBufferByteLength(GateRef glue, GateRef buffer, GateRef length);
1002    GateRef IsDetachedBuffer(GateRef buffer);
1003    inline GateRef IsMarkerCellValid(GateRef cell);
1004    inline GateRef GetAccessorHasChanged(GateRef obj);
1005    inline GateRef ComputeTaggedTypedArraySize(GateRef elementSize, GateRef length);
1006    GateRef ChangeTaggedPointerToInt64(GateRef x);
1007    GateRef GetLastLeaveFrame(GateRef glue);
1008    inline GateRef GetPropertiesCache(GateRef glue);
1009    GateRef GetIndexFromPropertiesCache(GateRef glue, GateRef cache, GateRef cls, GateRef key,
1010                                        GateRef hir = Circuit::NullGate());
1011    inline void SetToPropertiesCache(GateRef glue, GateRef cache, GateRef cls, GateRef key, GateRef result,
1012                                     GateRef hir = Circuit::NullGate());
1013    GateRef HashFromHclassAndKey(GateRef glue, GateRef cls, GateRef key, GateRef hir = Circuit::NullGate());
1014    GateRef GetKeyHashCode(GateRef glue, GateRef key, GateRef hir = Circuit::NullGate());
1015    inline GateRef GetSortedKey(GateRef layoutInfo, GateRef index);
1016    inline GateRef GetSortedIndex(GateRef layoutInfo, GateRef index);
1017    inline GateRef GetSortedIndex(GateRef attr);
1018    inline void StoreWithoutBarrier(VariableType type, GateRef base, GateRef offset, GateRef value);
1019    GateRef DefineFunc(GateRef glue, GateRef constpool, GateRef index,
1020                       FunctionKind targetKind = FunctionKind::LAST_FUNCTION_KIND);
1021    GateRef BinarySearch(GateRef glue, GateRef layoutInfo, GateRef key, GateRef propsNum,
1022                         GateRef hir = Circuit::NullGate());
1023    void UpdateProfileTypeInfoCellToFunction(GateRef glue, GateRef function,
1024                                             GateRef profileTypeInfo, GateRef slotId);
1025    GateRef Loadlocalmodulevar(GateRef glue, GateRef index, GateRef module);
1026    GateRef GetArgumentsElements(GateRef glue, GateRef argvTaggedArray, GateRef argv);
1027    void TryToJitReuseCompiledFunc(GateRef glue, GateRef jsFunc, GateRef profileTypeInfoCell);
1028    GateRef GetIsFastCall(GateRef machineCode);
1029
1030    enum OverlapKind {
1031        // NotOverlap means the source and destination memory are not overlap,
1032        // or overlap but the start of source is larger than destination.
1033        // then we will copy the memory from left to right.
1034        NotOverlap,
1035        // MustOverlap mean the source and destination memory are overlap,
1036        // and the start of source is lesser than destination.
1037        // then we will copy the memory from right to left.
1038        MustOverlap,
1039        // Unknown means all the kinds above are possible, it will select the suitable one in runtime.
1040        Unknown,
1041    };
1042    template <OverlapKind kind>
1043    void ArrayCopy(GateRef glue, GateRef src, GateRef dst, GateRef length,
1044                   MemoryAttribute mAttr = MemoryAttribute::Default());
1045protected:
1046    static constexpr int LOOP_UNROLL_FACTOR = 2;
1047private:
1048    using BinaryOperation = std::function<GateRef(Environment*, GateRef, GateRef)>;
1049    template<OpCode Op>
1050    GateRef FastAddSubAndMul(GateRef glue, GateRef left, GateRef right, ProfileOperation callback);
1051    GateRef FastIntDiv(GateRef left, GateRef right, Label *bailout, ProfileOperation callback);
1052    template<OpCode Op>
1053    GateRef FastBinaryOp(GateRef glue, GateRef left, GateRef right,
1054                         const BinaryOperation& intOp, const BinaryOperation& floatOp, ProfileOperation callback);
1055    GateRef TryStringAdd(Environment *env, GateRef glue, GateRef left, GateRef right,
1056                         const BinaryOperation& intOp, const BinaryOperation& floatOp, ProfileOperation callback);
1057    GateRef NumberOperation(Environment *env, GateRef left, GateRef right,
1058                            const BinaryOperation& intOp,
1059                            const BinaryOperation& floatOp,
1060                            ProfileOperation callback);
1061    void SetSValueWithBarrier(GateRef glue, GateRef obj, GateRef offset, GateRef value, GateRef objectRegion,
1062                                      GateRef valueRegion);
1063
1064    void SetNonSValueWithBarrier(GateRef glue, GateRef obj, GateRef offset, GateRef value, GateRef objectRegion,
1065                                     GateRef valueRegion, bool withEden);
1066    void InitializeArguments();
1067    void CheckDetectorName(GateRef glue, GateRef key, Label *fallthrough, Label *slow);
1068    GateRef CanDoubleRepresentInt(GateRef exp, GateRef expBits, GateRef fractionBits);
1069    GateRef CalIteratorKey(GateRef glue);
1070
1071    CallSignature *callSignature_ {nullptr};
1072    Environment *env_;
1073};
1074}  // namespace panda::ecmascript::kungfu
1075#endif  // ECMASCRIPT_COMPILER_STUB_BUILDER_H
1076