• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "ecmascript/compiler/access_object_stub_builder.h"
17 #include "ecmascript/compiler/baseline/baseline_stubs.h"
18 #include "ecmascript/compiler/baseline/baseline_stubs-inl.h"
19 #include "ecmascript/compiler/baseline/baseline_call_signature.h"
20 #include "ecmascript/compiler/call_stub_builder.h"
21 #include "ecmascript/compiler/new_object_stub_builder.h"
22 #include "ecmascript/compiler/operations_stub_builder.h"
23 #include "ecmascript/compiler/profiler_stub_builder.h"
24 #include "ecmascript/dfx/vm_thread_control.h"
25 #include "ecmascript/interpreter/interpreter.h"
26 #include "ecmascript/js_async_generator_object.h"
27 
28 namespace panda::ecmascript::kungfu {
29 using namespace panda::ecmascript;
30 static constexpr uint32_t ONE_BYTE_SIZE = 8;
31 static constexpr uint32_t TWO_BYTE_SIZE = 16;
32 static constexpr uint32_t THREE_BYTE_SIZE = 24;
33 static constexpr uint32_t ONE_BYTE_ALL_ONE = 0xFF;
34 static constexpr uint32_t TWO_BYTE_ALL_ONE = 0xFFFF;
35 
36 #define PARAM_INDEX(opcode, param) static_cast<size_t>(opcode##CallSignature::ParameterIndex::param)
37 
38 #define METHOD_ENTRY_ENV_DEFINED(func)                                                            \
39     GateRef isDebugModeOffset = IntPtr(JSThread::GlueData::GetIsDebugModeOffset(env->Is32Bit())); \
40     GateRef isDebugMode = Load(VariableType::BOOL(), glue, isDebugModeOffset);                    \
41     Label isDebugModeTrue(env);                                                                   \
42     Label isDebugModeFalse(env);                                                                  \
43     BRANCH(isDebugMode, &isDebugModeTrue, &isDebugModeFalse);                                     \
44     Bind(&isDebugModeTrue);                                                                       \
45     {                                                                                             \
46         CallRuntime(glue, RTSTUB_ID(MethodEntry), { func });                                      \
47         Jump(&isDebugModeFalse);                                                                  \
48     }                                                                                             \
49     Bind(&isDebugModeFalse)
50 
51 #define UPDATE_HOTNESS(func, callback)                                                                         \
52     varHotnessCounter = Int32Add(offset, *varHotnessCounter);                                                  \
53     BRANCH(Int32LessThan(*varHotnessCounter, Int32(0)), &slowPath, &dispatch);                                 \
54     Bind(&slowPath);                                                                                           \
55     {                                                                                                          \
56         GateRef iVecOffset = IntPtr(JSThread::GlueData::GetInterruptVectorOffset(env->IsArch32Bit()));         \
57         GateRef interruptsFlag = Load(VariableType::INT8(), glue, iVecOffset);                                 \
58         varHotnessCounter = Int32(EcmaInterpreter::METHOD_HOTNESS_THRESHOLD);                                  \
59         Label initialized(env);                                                                                \
60         Label callRuntime(env);                                                                                \
61         BRANCH(BitOr(TaggedIsUndefined(*varProfileTypeInfo),                                                   \
62                      Int8Equal(interruptsFlag, Int8(VmThreadControl::VM_NEED_SUSPENSION))),                    \
63             &callRuntime, &initialized);                                                                       \
64         Bind(&callRuntime);                                                                                    \
65         if (!(callback).IsEmpty()) {                                                                           \
66             varProfileTypeInfo = CallRuntime(glue, RTSTUB_ID(UpdateHotnessCounterWithProf), { func });         \
67         } else {                                                                                               \
68             varProfileTypeInfo = CallRuntime(glue, RTSTUB_ID(UpdateHotnessCounter), { func });                 \
69         }                                                                                                      \
70         Label handleException(env);                                                                            \
71         Label noException(env);                                                                                \
72         BRANCH(HasPendingException(glue), &handleException, &noException);                                     \
73         Bind(&handleException);                                                                                \
74         {                                                                                                      \
75             DISPATCH_LAST();                                                                                   \
76             Return();                                                                                          \
77         }                                                                                                      \
78         Bind(&noException);                                                                                    \
79         {                                                                                                      \
80             Jump(&dispatch);                                                                                   \
81         }                                                                                                      \
82         Bind(&initialized);                                                                                    \
83         (callback).TryDump();                                                                                  \
84         (callback).TryJitCompile();                                                                            \
85         Jump(&dispatch);                                                                                       \
86     }                                                                                                          \
87     Bind(&dispatch);
88 
89 enum ActualNumArgsOfCall : uint8_t { CALLARG0 = 0, CALLARG1, CALLARGS2, CALLARGS3 };
90 
91 CallSignature BaselineStubCSigns::callSigns_[BaselineStubCSigns::NUM_OF_STUBS];
92 
93 #define CHECK_EXCEPTION(res)                                                  \
94     CheckException(glue, sp, res)
95 
96 #define CHECK_EXCEPTION_RETURN(res)                                           \
97     CheckExceptionReturn(glue, sp, res)
98 
99 #define CHECK_EXCEPTION_WITH_JUMP(res, jump)                                      \
100     CheckExceptionWithJump(glue, sp, res, acc, jump)
101 
102 #define CHECK_EXCEPTION_WITH_JUMP_RETURN(res, jump)                               \
103     CheckExceptionWithJumpAndReturn(glue, sp, res, acc, jump)
104 
105 #define CHECK_EXCEPTION_WITH_ACC(res)                                             \
106     CheckExceptionWithVar(glue, sp, res, acc)
107 
108 #define CHECK_EXCEPTION_WITH_VARACC(res)                                          \
109     CheckExceptionWithVar(glue, sp, res, *varAcc)
110 
111 #define CHECK_PENDING_EXCEPTION(res)                                         \
112     CheckPendingException(glue, sp, res, acc)
113 
114 #define INT_PTR(opcode)                                                                   \
115     IntPtr(BytecodeInstruction::Size(BytecodeInstruction::Opcode::opcode))
116 
117 #define METHOD_ENTRY(func)                                                                        \
118     auto env = GetEnvironment();                                                                  \
119     METHOD_ENTRY_ENV_DEFINED(func)
120 
121 #define METHOD_EXIT()                                                                             \
122     auto debugModeOffset = JSThread::GlueData::GetIsDebugModeOffset(env->Is32Bit());              \
123     auto tracingOffset = JSThread::GlueData::GetIsTracingOffset(env->Is32Bit());                  \
124     Label NeedCallRuntimeTrue(env);                                                               \
125     Label NeedCallRuntimeFalse(env);                                                              \
126     Branch(LogicOrBuilder(env)                                                                    \
127         .Or(Load(VariableType::BOOL(), glue, IntPtr(debugModeOffset)))                            \
128         .Or(Load(VariableType::BOOL(), glue, IntPtr(tracingOffset)))                              \
129         .Done(), &NeedCallRuntimeTrue, &NeedCallRuntimeFalse);                                    \
130     Bind(&NeedCallRuntimeTrue);                                                                   \
131     {                                                                                             \
132         CallRuntime(glue, RTSTUB_ID(MethodExit), {});                                             \
133         Jump(&NeedCallRuntimeFalse);                                                              \
134     }                                                                                             \
135     Bind(&NeedCallRuntimeFalse)
136 
137 #define DISPATCH(opcode) DISPATCH_BAK(OFFSET, INT_PTR(opcode))
138 #define DISPATCH_BAK(TYPE, ...) DISPATCH_##TYPE(__VA_ARGS__)
139 #define DISPATCH_LAST()                                                                           \
140     DispatchLast(glue, sp, acc)                                                                   \
141 
142 #define DISPATCH_LAST_WITH_ACC()                                                                  \
143     DispatchLast(glue, sp, acc)                                                                   \
144 
145 #define DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineBianryOP)                              \
146     GateRef glue = PtrArgument(PARAM_INDEX(BaselineBianryOP, GLUE));                              \
147     GateRef sp = PtrArgument(PARAM_INDEX(BaselineBianryOP, SP));                                  \
148     GateRef left = TaggedArgument(PARAM_INDEX(BaselineBianryOP, LEFT));                           \
149     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineBianryOP, SLOT_ID));                       \
150                                                                                                   \
151     GateRef frame = GetFrame(sp);                                                                 \
152     GateRef acc = GetAccFromFrame(frame);                                                         \
153     GateRef func = GetFunctionFromFrame(frame);                                                   \
154     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(func);                               \
155                                                                                                   \
156     ProfileOperation callback(                                                                    \
157         [this, glue, func, slotId, profileTypeInfo](const std::initializer_list<GateRef> &values, \
158                                                     OperationType type) {                         \
159             ProfilerStubBuilder profiler(this);                                                   \
160             profiler.PGOProfiler(glue, func, profileTypeInfo, slotId, values, type);              \
161         }, nullptr)
162 
163 #define DEFINE_SINGLEOP_PARAM_AND_PROFILE_CALLBACK(BaselineBianryOP)                              \
164     GateRef glue = PtrArgument(PARAM_INDEX(BaselineBianryOP, GLUE));                              \
165     GateRef sp = PtrArgument(PARAM_INDEX(BaselineBianryOP, SP));                                  \
166     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineBianryOP, SLOT_ID));                       \
167                                                                                                   \
168     GateRef frame = GetFrame(sp);                                                                 \
169     GateRef acc = GetAccFromFrame(frame);                                                         \
170     GateRef func = GetFunctionFromFrame(frame);                                                   \
171     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(func);                               \
172                                                                                                   \
173     ProfileOperation callback(                                                                    \
174         [this, glue, func, slotId, profileTypeInfo](const std::initializer_list<GateRef> &values, \
175                                                     OperationType type) {                         \
176             ProfilerStubBuilder profiler(this);                                                   \
177             profiler.PGOProfiler(glue, func, profileTypeInfo, slotId, values, type);              \
178         }, nullptr)
179 
180 
181 #define DEFINE_PROFILE_CALLBACK(glue, sp, slotId)                                                    \
182     GateRef frame = GetFrame(sp);                                                                    \
183     GateRef curFunc = GetFunctionFromFrame(frame);                                                   \
184     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(curFunc);                               \
185     ProfileOperation callback(                                                                       \
186         [this, glue, curFunc, slotId, profileTypeInfo](const std::initializer_list<GateRef> &values, \
187                                                        OperationType type) {                         \
188             ProfilerStubBuilder profiler(this);                                                      \
189             profiler.PGOProfiler(glue, curFunc, profileTypeInfo, slotId, values, type);              \
190         }, nullptr)
191 
192 #define DEFINE_BY_NAME(newIc)                                                                                        \
193     DEFVARIABLE(holder, VariableType::JS_ANY(), receiver);                                                           \
194     Label icPath(env);                                                                                               \
195     Label whichPath(env);                                                                                            \
196     Label slowPath(env);                                                                                             \
197     Label exit(env);                                                                                                 \
198     Label isEcmaObj(env);                                                                                            \
199     /*hclass hit -> ic path*/                                                                                        \
200     Label tryGetHclass(env);                                                                                         \
201     Label firstValueHeapObject(env);                                                                                 \
202     Label hclassNotHit(env);                                                                                         \
203     BRANCH(IsEcmaObject(receiver), &isEcmaObj, &slowPath);                                                           \
204     Bind(&isEcmaObj);                                                                                                \
205     BRANCH(TaggedIsUndefined(profileTypeInfo), &hclassNotHit, &tryGetHclass);                                        \
206     Bind(&tryGetHclass);                                                                                             \
207     {                                                                                                                \
208         GateRef firstValue = GetValueFromTaggedArray(profileTypeInfo, slotId);                                       \
209         BRANCH(TaggedIsHeapObject(firstValue), &firstValueHeapObject, &hclassNotHit);                                \
210         Bind(&firstValueHeapObject);                                                                                 \
211         GateRef hclass = LoadHClass(*holder);                                                                        \
212         BRANCH(Equal(LoadObjectFromWeakRef(firstValue), hclass), &whichPath, &hclassNotHit);                         \
213     }                                                                                                                \
214     Bind(&hclassNotHit);                                                                                             \
215     /* found entry -> slow path*/                                                                                    \
216     Label loopHead(env);                                                                                             \
217     Label loopEnd(env);                                                                                              \
218     Label loopExit(env);                                                                                             \
219     Jump(&loopHead);                                                                                                 \
220     LoopBegin(&loopHead);                                                                                            \
221     {                                                                                                                \
222         GateRef hclass = LoadHClass(*holder);                                                                        \
223         GateRef jsType = GetObjectType(hclass);                                                                      \
224         Label findProperty(env);                                                                                     \
225         BRANCH(IsSpecialIndexedObj(jsType), &slowPath, &findProperty);                                               \
226         Bind(&findProperty);                                                                                         \
227         Label isDicMode(env);                                                                                        \
228         Label notDicMode(env);                                                                                       \
229         BRANCH(IsDictionaryModeByHClass(hclass), &isDicMode, &notDicMode);                                           \
230         Bind(&isDicMode);                                                                                            \
231         {                                                                                                            \
232             GateRef array = GetPropertiesArray(*holder);                                                             \
233             GateRef entry = FindEntryFromNameDictionary(glue, array, propKey);                                       \
234             BRANCH(Int32NotEqual(entry, Int32(-1)), &slowPath, &loopExit);                                           \
235         }                                                                                                            \
236         Bind(&notDicMode);                                                                                           \
237         {                                                                                                            \
238             GateRef layOutInfo = GetLayoutFromHClass(hclass);                                                        \
239             GateRef propsNum = GetNumberOfPropsFromHClass(hclass);                                                   \
240             GateRef entry = FindElementWithCache(glue, layOutInfo, hclass, propKey, propsNum);                       \
241             BRANCH(Int32NotEqual(entry, Int32(-1)), &slowPath, &loopExit);                                           \
242         }                                                                                                            \
243         Bind(&loopExit);                                                                                             \
244         {                                                                                                            \
245             holder = GetPrototypeFromHClass(LoadHClass(*holder));                                                    \
246             BRANCH(TaggedIsHeapObject(*holder), &loopEnd, &whichPath);                                               \
247         }                                                                                                            \
248         Bind(&loopEnd);                                                                                              \
249         LoopEnd(&loopHead, env, glue);                                                                               \
250     }                                                                                                                \
251     Bind(&whichPath);                                                                                                \
252     {                                                                                                                \
253         BRANCH(newIc, &icPath, &slowPath);                                                                           \
254     }                                                                                                                \
255     Bind(&icPath);                                                                                                   \
256     {                                                                                                                \
257         /* IC do the same thing as stobjbyname */                                                                    \
258         AccessObjectStubBuilder builder(this);                                                                       \
259         StringIdInfo stringIdInfo(constpool, stringId);                                                              \
260         result = builder.StoreObjByName(glue, receiver, 0, stringIdInfo, acc, profileTypeInfo, slotId, callback);    \
261         Jump(&exit);                                                                                                 \
262     }                                                                                                                \
263     Bind(&slowPath);                                                                                                 \
264     {                                                                                                                \
265         result = DefineField(glue, receiver, propKey, acc);                                                          \
266         Jump(&exit);                                                                                                 \
267     }                                                                                                                \
268     Bind(&exit)
269 
Initialize()270 void BaselineStubCSigns::Initialize()
271 {
272 #define INIT_SIGNATURES(name)                                                              \
273     name##CallSignature::Initialize(&callSigns_[name]);                                    \
274     callSigns_[name].SetID(name);                                                          \
275     callSigns_[name].SetName(std::string("BaselineStub_") + #name);                        \
276     callSigns_[name].SetConstructor(                                                       \
277         [](void* env) {                                                                    \
278             return static_cast<void*>(                                                     \
279                 new name##StubBuilder(&callSigns_[name], static_cast<Environment*>(env))); \
280         });
281 
282     BASELINE_STUB_ID_LIST(INIT_SIGNATURES)
283 #undef INIT_SIGNATURES
284 }
285 
GetCSigns(std::vector<const CallSignature * > & outCSigns)286 void BaselineStubCSigns::GetCSigns(std::vector<const CallSignature*>& outCSigns)
287 {
288     for (size_t i = 0; i < NUM_OF_STUBS; i++) {
289         outCSigns.push_back(&callSigns_[i]);
290     }
291 }
292 
GenerateCircuit()293 void BaselineTryLdGLobalByNameImm8ID16StubBuilder::GenerateCircuit()
294 {
295     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTryLdGLobalByNameImm8ID16, GLUE));
296     GateRef sp = PtrArgument(PARAM_INDEX(BaselineTryLdGLobalByNameImm8ID16, SP));
297     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineTryLdGLobalByNameImm8ID16, STRING_ID));
298     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineTryLdGLobalByNameImm8ID16, SLOT_ID));
299     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
300 
301     GateRef acc = GetAccFromFrame(frame);
302     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
303     GateRef method = GetMethodFromFunction(curFunc);
304     GateRef constpool = GetConstpoolFromMethod(method);
305     AccessObjectStubBuilder builder(this);
306     StringIdInfo info(constpool, stringId);
307     GateRef result = builder.TryLoadGlobalByName(glue, 0, info, profileTypeInfo, slotId, callback);
308     CHECK_EXCEPTION_WITH_VARACC(result);
309 }
310 
GenerateCircuit()311 void BaselineCallArg1Imm8V8StubBuilder::GenerateCircuit()
312 {
313     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallArg1Imm8V8, GLUE));
314     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallArg1Imm8V8, SP));
315     GateRef arg0No = Int32Argument(PARAM_INDEX(BaselineCallArg1Imm8V8, ARG0));
316     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallArg1Imm8V8, SLOT_ID));
317 
318     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
319     GateRef curMethod = GetMethodFromFunction(curFunc);
320     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
321     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
322     GateRef a0Value = GetVregValue(sp, ZExtInt32ToPtr(arg0No));
323     GateRef actualNumArgs = Int32(ActualNumArgsOfCall::CALLARG1);
324     GateRef acc = GetAccFromFrame(frame);
325     METHOD_ENTRY(acc);
326     Label noNeedCheckException(env);
327     Label exit(env);
328     GateRef jumpSize = INT_PTR(CALLARG1_IMM8_V8);
329     JSCallArgs callArgs(JSCallMode::CALL_ARG1);
330     callArgs.callArgs = { a0Value, 0, 0 };
331     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
332     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
333     Bind(&exit);
334     CHECK_PENDING_EXCEPTION(*result);
335     Bind(&noNeedCheckException);
336     Return(*result);
337 }
338 
GenerateCircuit()339 void BaselineStToGlobalRecordImm16ID16StubBuilder::GenerateCircuit()
340 {
341     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStToGlobalRecordImm16ID16, GLUE));
342     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStToGlobalRecordImm16ID16, SP));
343     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStToGlobalRecordImm16ID16, ACC));
344     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStToGlobalRecordImm16ID16, STRING_ID));
345 
346     GateRef frame = GetFrame(sp);
347     GateRef func = GetFunctionFromFrame(frame);
348     GateRef method = GetMethodFromFunction(func);
349     GateRef constpool = GetConstpoolFromMethod(method);
350     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
351     GateRef result = CallRuntime(glue, RTSTUB_ID(StGlobalRecord),
352                                  { propKey, acc, TaggedFalse() });
353     CHECK_EXCEPTION_RETURN(result);
354 }
355 
GenerateCircuit()356 void BaselineLdaStrID16StubBuilder::GenerateCircuit()
357 {
358     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdaStrID16, GLUE));
359     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdaStrID16, SP));
360     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdaStrID16, STRING_ID));
361 
362     GateRef func = GetFunctionFromFrame(GetFrame(sp));
363     GateRef method = GetMethodFromFunction(func);
364     GateRef constpool = GetConstpoolFromMethod(method);
365     GateRef result = GetStringFromConstPool(glue, constpool, stringId);
366     Return(result);
367 }
368 
GenerateCircuit()369 void BaselineLdsymbolStubBuilder::GenerateCircuit()
370 {
371     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdsymbol, GLUE));
372 
373     GateRef result = CallRuntime(glue, RTSTUB_ID(GetSymbolFunction), {});
374 
375     Return(result);
376 }
377 
GenerateCircuit()378 void BaselineLdglobalStubBuilder::GenerateCircuit()
379 {
380     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdglobal, GLUE));
381 
382     GateRef result = GetGlobalObject(glue);
383 
384     Return(result);
385 }
386 
GenerateCircuit()387 void BaselinePoplexenvStubBuilder::GenerateCircuit()
388 {
389     GateRef glue = PtrArgument(PARAM_INDEX(BaselinePoplexenv, GLUE));
390     GateRef sp = PtrArgument(PARAM_INDEX(BaselinePoplexenv, SP));
391 
392     GateRef state = GetFrame(sp);
393     GateRef currentLexEnv = GetEnvFromFrame(state);
394     GateRef parentLexEnv = GetParentEnv(currentLexEnv);
395     SetEnvToFrame(glue, state, parentLexEnv);
396     Return();
397 }
398 
GenerateCircuit()399 void BaselineGetunmappedargsStubBuilder::GenerateCircuit()
400 {
401     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGetunmappedargs, GLUE));
402     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGetunmappedargs, SP));
403     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineGetunmappedargs, ACC));
404 
405     DEFVARIABLE(argumentsList, VariableType::JS_ANY(), Hole());
406     DEFVARIABLE(argumentsObj, VariableType::JS_ANY(), Hole());
407     auto env = GetEnvironment();
408     GateRef startIdxAndNumArgs = GetStartIdxAndNumArgs(sp, Int32(0));
409     // 32: high 32 bits = startIdx, low 32 bits = numArgs
410     GateRef startIdx = TruncInt64ToInt32(Int64LSR(startIdxAndNumArgs, Int64(32)));
411     GateRef numArgs = TruncInt64ToInt32(startIdxAndNumArgs);
412 
413     Label newArgumentsObj(env);
414     Label checkException(env);
415     Label dispatch(env);
416     Label slowPath(env);
417     NewObjectStubBuilder newBuilder(this);
418     newBuilder.SetParameters(glue, 0);
419     Label afterArgumentsList(env);
420     newBuilder.NewArgumentsList(&argumentsList, &afterArgumentsList, sp, startIdx, numArgs);
421     Bind(&afterArgumentsList);
422     Branch(TaggedIsException(*argumentsList), &slowPath, &newArgumentsObj);
423     Bind(&newArgumentsObj);
424     Label afterArgumentsObj(env);
425     newBuilder.NewArgumentsObj(&argumentsObj, &afterArgumentsObj, *argumentsList, numArgs);
426     Bind(&afterArgumentsObj);
427     Branch(TaggedIsException(*argumentsObj), &slowPath, &checkException);
428     Bind(&checkException);
429     Branch(HasPendingException(glue), &slowPath, &dispatch);
430     Bind(&dispatch);
431     {
432         Return(*argumentsObj);
433     }
434 
435     Bind(&slowPath);
436     {
437         GateRef res = CallRuntime(glue, RTSTUB_ID(GetUnmapedArgs), {});
438         CHECK_EXCEPTION_WITH_ACC(res);
439     }
440 }
441 
GenerateCircuit()442 void BaselineAsyncfunctionenterStubBuilder::GenerateCircuit()
443 {
444     GateRef glue = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionenter, GLUE));
445     GateRef sp = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionenter, SP));
446 
447     GateRef result = CallRuntime(glue, RTSTUB_ID(AsyncFunctionEnter), {});
448 
449     CHECK_EXCEPTION_RETURN(result);
450 }
451 
GenerateCircuit()452 void BaselineCreateasyncgeneratorobjV8StubBuilder::GenerateCircuit()
453 {
454     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateasyncgeneratorobjV8, GLUE));
455     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateasyncgeneratorobjV8, SP));
456     GateRef genFunc = TaggedArgument(PARAM_INDEX(BaselineCreateasyncgeneratorobjV8, GEN_FUNC));
457 
458     auto env = GetEnvironment();
459     GateRef result = CallRuntime(glue, RTSTUB_ID(CreateAsyncGeneratorObj), { genFunc });
460     Label isException(env);
461     Label notException(env);
462     Branch(TaggedIsException(result), &isException, &notException);
463     Bind(&isException);
464     {
465         GateRef acc = GetAccFromFrame(GetFrame(sp));
466         DISPATCH_LAST();
467         Return(result);
468     }
469     Bind(&notException);
470     Return(result);
471 }
472 
GenerateCircuit()473 void BaselineDebuggerStubBuilder::GenerateCircuit()
474 {
475     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDebugger, GLUE));
476 
477     CallRuntime(glue, RTSTUB_ID(NotifyDebuggerStatement), {});
478     Return();
479 }
480 
GenerateCircuit()481 void BaselineGetpropiteratorStubBuilder::GenerateCircuit()
482 {
483     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGetpropiterator, GLUE));
484     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGetpropiterator, SP));
485     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineGetpropiterator, ACC));
486 
487     NewObjectStubBuilder newBuilder(this);
488     GateRef result = newBuilder.EnumerateObjectProperties(glue, acc);
489     CHECK_EXCEPTION_RETURN(result);
490 }
491 
GenerateCircuit()492 void BaselineGetiteratorImm8StubBuilder::GenerateCircuit()
493 {
494     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGetiteratorImm8, GLUE));
495     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGetiteratorImm8, SP));
496     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineGetiteratorImm8, SLOT_ID));
497     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
498 
499     GateRef acc = GetAccFromFrame(frame);
500     GateRef res = GetIterator(glue, acc, callback);
501 
502     CHECK_PENDING_EXCEPTION(res);
503 }
504 
GenerateCircuit()505 void BaselineGetiteratorImm16StubBuilder::GenerateCircuit()
506 {
507     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGetiteratorImm16, GLUE));
508     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGetiteratorImm16, SP));
509     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineGetiteratorImm16, SLOT_ID));
510     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
511 
512     GateRef acc = GetAccFromFrame(frame);
513     GateRef res = GetIterator(glue, acc, callback);
514 
515     CHECK_PENDING_EXCEPTION(res);
516 }
517 
GenerateCircuit()518 void BaselineCloseiteratorImm8V8StubBuilder::GenerateCircuit()
519 {
520     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCloseiteratorImm8V8, GLUE));
521     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCloseiteratorImm8V8, SP));
522     GateRef iter = TaggedArgument(PARAM_INDEX(BaselineCloseiteratorImm8V8, ITER));
523 
524     GateRef frame = GetFrame(sp);
525     GateRef acc = GetAccFromFrame(frame);
526     GateRef result = CallRuntime(glue, RTSTUB_ID(CloseIterator), { iter });
527     CHECK_EXCEPTION_WITH_ACC(result);
528 }
529 
GenerateCircuit()530 void BaselineCloseiteratorImm16V8StubBuilder::GenerateCircuit()
531 {
532     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCloseiteratorImm16V8, GLUE));
533     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCloseiteratorImm16V8, SP));
534     GateRef iter = TaggedArgument(PARAM_INDEX(BaselineCloseiteratorImm16V8, ITER));
535 
536     GateRef frame = GetFrame(sp);
537     GateRef acc = GetAccFromFrame(frame);
538     GateRef result = CallRuntime(glue, RTSTUB_ID(CloseIterator), { iter });
539     CHECK_EXCEPTION_WITH_ACC(result);
540 }
541 
GenerateCircuit()542 void BaselineAsyncgeneratorresolveV8V8V8StubBuilder::GenerateCircuit()
543 {
544     GateRef glue = PtrArgument(PARAM_INDEX(BaselineAsyncgeneratorresolveV8V8V8, GLUE));
545     GateRef sp = PtrArgument(PARAM_INDEX(BaselineAsyncgeneratorresolveV8V8V8, SP));
546     GateRef offset = Int32Argument(PARAM_INDEX(BaselineAsyncgeneratorresolveV8V8V8, OFFSET));
547     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineAsyncgeneratorresolveV8V8V8, V0));
548     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineAsyncgeneratorresolveV8V8V8, V1));
549     GateRef v2 = Int32Argument(PARAM_INDEX(BaselineAsyncgeneratorresolveV8V8V8, V2));
550 
551     GateRef frame = GetFrame(sp);
552     GateRef curMethod = GetMethodFromFunction(GetFunctionFromFrame(frame));
553     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
554     GateRef constpool = GetConstpoolFromMethod(curMethod);
555     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(GetFunctionFromFrame(frame));
556     GateRef acc = GetAccFromFrame(frame);
557     ProfileOperation callback;
558 
559     GateRef asyncGenerator = GetVregValue(sp, ZExtInt8ToPtr(v0));
560     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v1));
561     GateRef flag = GetVregValue(sp, ZExtInt8ToPtr(v2));
562 
563     auto env = GetEnvironment();
564     METHOD_EXIT();
565     DEFVARIABLE(varSp, VariableType::NATIVE_POINTER(), sp);
566     DEFVARIABLE(prevState, VariableType::NATIVE_POINTER(), sp);
567     DEFVARIABLE(varConstpool, VariableType::JS_POINTER(), constpool);
568     DEFVARIABLE(varProfileTypeInfo, VariableType::JS_POINTER(), profileTypeInfo);
569     DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter);
570     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
571 
572     Label isBaselineBuiltinFrame(env);
573     Label notBaselineBuiltinFrame(env);
574     Label pcEqualNullptr(env);
575     Label pcNotEqualNullptr(env);
576     Label pcEqualBaseline(env);
577     Label pcNotEqualBaseline(env);
578     Label updateHotness(env);
579     Label isStable(env);
580     Label tryContinue(env);
581     Label dispatch(env);
582     Label slowPath(env);
583 
584     GateRef res = CallRuntime(glue, RTSTUB_ID(AsyncGeneratorResolve),
585                               { asyncGenerator, value, flag });
586     Label isException(env);
587     Label notException(env);
588     Branch(TaggedIsException(res), &isException, &notException);
589     Bind(&isException);
590     {
591         DISPATCH_LAST();
592         Return();
593     }
594     Bind(&notException);
595     Branch(TaggedIsUndefined(*varProfileTypeInfo), &updateHotness, &isStable);
596     Bind(&isStable);
597     {
598         Branch(ProfilerStubBuilder(env).IsProfileTypeInfoDumped(*varProfileTypeInfo, callback), &tryContinue,
599             &updateHotness);
600     }
601     Bind(&updateHotness);
602     {
603         GateRef function = GetFunctionFromFrame(frame);
604         GateRef thisMethod = Load(VariableType::JS_ANY(), function, IntPtr(JSFunctionBase::METHOD_OFFSET));
605         UPDATE_HOTNESS(*varSp, callback);
606         SetHotnessCounter(glue, thisMethod, *varHotnessCounter);
607         Jump(&tryContinue);
608     }
609 
610     Bind(&tryContinue);
611 #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
612     GateRef curFunc = GetFunctionFromFrame(frame);
613     CallNGCRuntime(glue, RTSTUB_ID(EndCallTimer), { glue, curFunc });
614 #endif
615     GateRef currentSp = *varSp;
616     varSp = Load(VariableType::NATIVE_POINTER(), frame,
617         IntPtr(AsmInterpretedFrame::GetBaseOffset(env->IsArch32Bit())));
618 
619     GateRef typePos = PtrSub(*varSp, IntPtr(JSTaggedValue::TaggedTypeSize()));
620     GateRef maybeFrameType = Load(VariableType::INT64(), typePos);
621     BRANCH(Int64Equal(maybeFrameType, Int64(static_cast<int64_t>(FrameType::BASELINE_BUILTIN_FRAME))),
622            &isBaselineBuiltinFrame, &notBaselineBuiltinFrame);
623     Bind(&isBaselineBuiltinFrame);
624     {
625         varSp = Load(VariableType::NATIVE_POINTER(), *varSp);
626         Jump(&notBaselineBuiltinFrame);
627     }
628     Bind(&notBaselineBuiltinFrame);
629     prevState = GetFrame(*varSp);
630     GateRef varPc = GetPcFromFrame(*prevState);
631     Branch(IntPtrEqual(varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr);
632     Bind(&pcEqualNullptr);
633     {
634         GateRef result = CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { res, *varSp, currentSp });
635         (void) result;
636         Return();
637     }
638     Bind(&pcNotEqualNullptr);
639     BRANCH(IntPtrEqual(varPc, IntPtr(BASELINEJIT_PC_FLAG)), &pcEqualBaseline, &pcNotEqualBaseline);
640     Bind(&pcEqualBaseline);
641     {
642         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturnBaseline), { res, *varSp, currentSp });
643         Return();
644     }
645     Bind(&pcNotEqualBaseline);
646     {
647         GateRef function = GetFunctionFromFrame(*prevState);
648         GateRef thisMethod = Load(VariableType::JS_ANY(), function, IntPtr(JSFunctionBase::METHOD_OFFSET));
649         varConstpool = GetConstpoolFromMethod(thisMethod);
650         varProfileTypeInfo = GetProfileTypeInfoFromFunction(function);
651         varHotnessCounter = GetHotnessCounterFromMethod(thisMethod);
652         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
653         GateRef result = CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch),
654                                         { glue, currentSp, varPc, *varConstpool, *varProfileTypeInfo,
655                                         res, *varHotnessCounter, jumpSize });
656         (void) result;
657         Return();
658     }
659 }
660 
GenerateCircuit()661 void BaselineCreateemptyobjectStubBuilder::GenerateCircuit()
662 {
663     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateemptyobject, GLUE));
664     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateemptyobject, SP));
665     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCreateemptyobject, SLOT_ID));
666     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
667 
668     NewObjectStubBuilder newBuilder(this);
669     GateRef result = newBuilder.CreateEmptyObject(glue);
670     Return(result);
671 }
672 
GenerateCircuit()673 void BaselineCreateemptyarrayImm8StubBuilder::GenerateCircuit()
674 {
675     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateemptyarrayImm8, GLUE));
676     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateemptyarrayImm8, SP));
677     GateRef traceId = Int32Argument(PARAM_INDEX(BaselineCreateemptyarrayImm8, TRACE_ID));
678     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCreateemptyarrayImm8, SLOT_ID));
679 
680     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
681     NewObjectStubBuilder newBuilder(this);
682     GateRef result = newBuilder.CreateEmptyArray(glue, curFunc, { 0, traceId, false },
683                                                  profileTypeInfo, slotId, callback);
684     Return(result);
685 }
686 
GenerateCircuit()687 void BaselineCreateemptyarrayImm16StubBuilder::GenerateCircuit()
688 {
689     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateemptyarrayImm16, GLUE));
690     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateemptyarrayImm16, SP));
691     GateRef traceId = Int32Argument(PARAM_INDEX(BaselineCreateemptyarrayImm16, TRACE_ID));
692     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCreateemptyarrayImm16, SLOTID));
693 
694     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
695 
696     NewObjectStubBuilder newBuilder(this);
697     GateRef result =
698         newBuilder.CreateEmptyArray(glue, curFunc, { 0, traceId, false }, profileTypeInfo, slotId, callback);
699     Return(result);
700 }
701 
GenerateCircuit()702 void BaselineCreategeneratorobjV8StubBuilder::GenerateCircuit()
703 {
704     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreategeneratorobjV8, GLUE));
705     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreategeneratorobjV8, SP));
706     GateRef genFunc = TaggedArgument(PARAM_INDEX(BaselineCreategeneratorobjV8, GEN_FUNC));
707 
708     GateRef frame = GetFrame(sp);
709     GateRef acc = GetAccFromFrame(frame);
710     GateRef result = CallRuntime(glue, RTSTUB_ID(CreateGeneratorObj), { genFunc });
711     CHECK_EXCEPTION_WITH_ACC(result);
712 }
713 
GenerateCircuit()714 void BaselineCreateiterresultobjV8V8StubBuilder::GenerateCircuit()
715 {
716     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateiterresultobjV8V8, GLUE));
717     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateiterresultobjV8V8, SP));
718     GateRef value = TaggedArgument(PARAM_INDEX(BaselineCreateiterresultobjV8V8, VALUE));
719     GateRef flag = TaggedArgument(PARAM_INDEX(BaselineCreateiterresultobjV8V8, FLAG));
720 
721     GateRef frame = GetFrame(sp);
722     GateRef acc = GetAccFromFrame(frame);
723     GateRef result = CallRuntime(glue, RTSTUB_ID(CreateIterResultObj), { value, flag });
724     CHECK_EXCEPTION_WITH_ACC(result);
725 }
726 
GenerateCircuit()727 void BaselineCreateobjectwithexcludedkeysImm8V8V8StubBuilder::GenerateCircuit()
728 {
729     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateobjectwithexcludedkeysImm8V8V8, GLUE));
730     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateobjectwithexcludedkeysImm8V8V8, SP));
731     GateRef numKeys = Int32Argument(PARAM_INDEX(BaselineCreateobjectwithexcludedkeysImm8V8V8, NUMKEYS));
732     GateRef obj = TaggedArgument(PARAM_INDEX(BaselineCreateobjectwithexcludedkeysImm8V8V8, OBJ));
733     GateRef firstArgRegIdx =
734         Int32Argument(PARAM_INDEX(BaselineCreateobjectwithexcludedkeysImm8V8V8, FIRST_ARG_REG_IDX));
735 
736     GateRef acc = GetAccFromFrame(GetFrame(sp));
737     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateObjectWithExcludedKeys),
738         { Int16ToTaggedInt(numKeys), obj, Int16ToTaggedInt(firstArgRegIdx) });
739     CHECK_EXCEPTION_WITH_ACC(res);
740 }
741 
GenerateCircuit()742 void BaselineCallthis0Imm8V8StubBuilder::GenerateCircuit()
743 {
744     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallthis0Imm8V8, GLUE));
745     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallthis0Imm8V8, SP));
746     GateRef thisValueNo = Int32Argument(PARAM_INDEX(BaselineCallthis0Imm8V8, THIS_VALUE_NO));
747     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallthis0Imm8V8, SLOT_ID));
748     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
749     GateRef thisValue = GetVregValue(sp, ZExtInt32ToPtr(thisValueNo));
750     GateRef acc = GetAccFromFrame(frame);
751     GateRef curMethod = GetMethodFromFunction(curFunc);
752     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
753 
754     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
755     METHOD_ENTRY(acc);
756     Label noNeedCheckException(env);
757     Label exit(env);
758     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARG0);
759     GateRef jumpSize = INT_PTR(CALLTHIS0_IMM8_V8);
760     JSCallArgs callArgs(JSCallMode::CALL_THIS_ARG0);
761     callArgs.callArgsWithThis = { 0, 0, 0, thisValue };
762     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
763     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
764     Bind(&exit);
765     CHECK_PENDING_EXCEPTION(*result);
766     Bind(&noNeedCheckException);
767     Return(*result);
768 }
769 
GenerateCircuit()770 void BaselineCreatearraywithbufferImm8Id16StubBuilder::GenerateCircuit()
771 {
772     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreatearraywithbufferImm8Id16, GLUE));
773     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreatearraywithbufferImm8Id16, SP));
774     GateRef traceId = Int32Argument(PARAM_INDEX(BaselineCreatearraywithbufferImm8Id16, TRACE_ID));
775     GateRef imm = Int32Argument(PARAM_INDEX(BaselineCreatearraywithbufferImm8Id16, IMM));
776     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCreatearraywithbufferImm8Id16, SLOTID));
777 
778     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
779     GateRef acc = GetAccFromFrame(frame);
780     NewObjectStubBuilder newBuilder(this);
781     GateRef res = newBuilder.CreateArrayWithBuffer(
782         glue, imm, curFunc, { 0, traceId, false }, profileTypeInfo, slotId, callback);
783     CHECK_EXCEPTION_WITH_ACC(res);
784 }
785 
GenerateCircuit()786 void BaselineCreatearraywithbufferImm16Id16StubBuilder::GenerateCircuit()
787 {
788     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreatearraywithbufferImm16Id16, GLUE));
789     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreatearraywithbufferImm16Id16, SP));
790     GateRef traceId = Int32Argument(PARAM_INDEX(BaselineCreatearraywithbufferImm16Id16, TRACE_ID));
791     GateRef imm = Int32Argument(PARAM_INDEX(BaselineCreatearraywithbufferImm16Id16, IMM));
792     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCreatearraywithbufferImm16Id16, SLOTID));
793     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
794 
795     GateRef acc = GetAccFromFrame(frame);
796     NewObjectStubBuilder newBuilder(this);
797     GateRef res = newBuilder.CreateArrayWithBuffer(
798         glue, imm, curFunc, { 0, traceId, false }, profileTypeInfo, slotId, callback);
799     CHECK_EXCEPTION_WITH_ACC(res);
800 }
801 
GenerateCircuit()802 void BaselineCallthis1Imm8V8V8StubBuilder::GenerateCircuit()
803 {
804     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallthis1Imm8V8V8, GLUE));
805     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallthis1Imm8V8V8, SP));
806     GateRef thisValueId = Int32Argument(PARAM_INDEX(BaselineCallthis1Imm8V8V8, THIS_VALUE_ID));
807     GateRef a0ValueId = Int32Argument(PARAM_INDEX(BaselineCallthis1Imm8V8V8, A0_VALUE_ID));
808     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallthis1Imm8V8V8, SLOT_ID));
809     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
810     GateRef thisValue = GetVregValue(sp, ZExtInt32ToPtr(thisValueId));
811     GateRef a0Value = GetVregValue(sp, ZExtInt32ToPtr(a0ValueId));
812     GateRef curMethod = GetMethodFromFunction(curFunc);
813     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
814 
815     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
816     GateRef acc = GetAccFromFrame(frame);
817     METHOD_ENTRY(acc);
818     Label noNeedCheckException(env);
819     Label exit(env);
820     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARG1);
821     GateRef jumpSize = INT_PTR(CALLTHIS1_IMM8_V8_V8);
822     JSCallArgs callArgs(JSCallMode::CALL_THIS_ARG1);
823     callArgs.callArgsWithThis = { a0Value, 0, 0, thisValue };
824     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
825     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
826     Bind(&exit);
827     CHECK_PENDING_EXCEPTION(*result);
828     Bind(&noNeedCheckException);
829     Return(*result);
830 }
831 
GenerateCircuit()832 void BaselineCallthis2Imm8V8V8V8StubBuilder::GenerateCircuit()
833 {
834     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallthis2Imm8V8V8V8, GLUE));
835     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallthis2Imm8V8V8V8, SP));
836     GateRef thisValueId = Int32Argument(PARAM_INDEX(BaselineCallthis2Imm8V8V8V8, THIS_VALUE_ID));
837     GateRef a0ValueId = Int32Argument(PARAM_INDEX(BaselineCallthis2Imm8V8V8V8, A0_VALUE_ID));
838     GateRef a1ValueId = Int32Argument(PARAM_INDEX(BaselineCallthis2Imm8V8V8V8, A1_VALUE_ID));
839     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallthis2Imm8V8V8V8, SLOT_ID));
840     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
841 
842     GateRef a0Value = GetVregValue(sp, ZExtInt32ToPtr(a0ValueId));
843     GateRef a1Value = GetVregValue(sp, ZExtInt32ToPtr(a1ValueId));
844     GateRef thisValue = GetVregValue(sp, ZExtInt32ToPtr(thisValueId));
845     GateRef curMethod = GetMethodFromFunction(curFunc);
846     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
847 
848     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
849     GateRef acc = GetAccFromFrame(frame);
850     METHOD_ENTRY(acc);
851     Label noNeedCheckException(env);
852     Label exit(env);
853     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARGS2);
854     GateRef jumpSize = INT_PTR(CALLTHIS2_IMM8_V8_V8_V8);
855     JSCallArgs callArgs(JSCallMode::CALL_THIS_ARG2);
856     callArgs.callArgsWithThis = { a0Value, a1Value, 0, thisValue };
857     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
858     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
859     Bind(&exit);
860     CHECK_PENDING_EXCEPTION(*result);
861     Bind(&noNeedCheckException);
862     Return(*result);
863 }
864 
GenerateCircuit()865 void BaselineCreateobjectwithbufferImm8Id16StubBuilder::GenerateCircuit()
866 {
867     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateobjectwithbufferImm8Id16, GLUE));
868     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateobjectwithbufferImm8Id16, SP));
869     GateRef imm = Int32Argument(PARAM_INDEX(BaselineCreateobjectwithbufferImm8Id16, IMM));
870     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCreateobjectwithbufferImm8Id16, SLOT_ID));
871     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
872     GateRef acc = GetAccFromFrame(frame);
873     GateRef method = GetMethodFromFunction(curFunc);
874     GateRef constpool = GetConstpoolFromMethod(method);
875     GateRef currentEnv = GetEnvFromFrame(frame);
876     GateRef module = GetModuleFromFunction(curFunc);
877     GateRef result = GetObjectLiteralFromConstPool(glue, constpool, imm, module);
878     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateObjectHavingMethod), { result, currentEnv });
879     callback.ProfileCreateObject(res);
880     CHECK_EXCEPTION_WITH_ACC(res);
881 }
882 
GenerateCircuit()883 void BaselineCreateobjectwithbufferImm16Id16StubBuilder::GenerateCircuit()
884 {
885     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateobjectwithbufferImm16Id16, GLUE));
886     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateobjectwithbufferImm16Id16, SP));
887     GateRef imm = Int32Argument(PARAM_INDEX(BaselineCreateobjectwithbufferImm16Id16, IMM));
888     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCreateobjectwithbufferImm16Id16, SLOT_ID));
889     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
890 
891     GateRef acc = GetAccFromFrame(frame);
892     GateRef method = GetMethodFromFunction(curFunc);
893     GateRef constpool = GetConstpoolFromMethod(method);
894     GateRef currentEnv = GetEnvFromFrame(GetFrame(sp));
895     GateRef module = GetModuleFromFunction(curFunc);
896     GateRef result = GetObjectLiteralFromConstPool(glue, constpool, imm, module);
897     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateObjectHavingMethod), { result, currentEnv });
898     callback.ProfileCreateObject(res);
899     CHECK_EXCEPTION_WITH_ACC(res);
900 }
901 
GenerateCircuit()902 void BaselineCreateregexpwithliteralImm8Id16Imm8StubBuilder::GenerateCircuit()
903 {
904     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateregexpwithliteralImm8Id16Imm8, GLUE));
905     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateregexpwithliteralImm8Id16Imm8, SP));
906     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineCreateregexpwithliteralImm8Id16Imm8, STRING_ID));
907     GateRef flags = Int32Argument(PARAM_INDEX(BaselineCreateregexpwithliteralImm8Id16Imm8, FLAGS));
908 
909     GateRef frame = GetFrame(sp);
910     GateRef acc = GetAccFromFrame(frame);
911     GateRef func = GetFunctionFromFrame(frame);
912     GateRef method = GetMethodFromFunction(func);
913     GateRef constpool = GetConstpoolFromMethod(method);
914     GateRef pattern = GetStringFromConstPool(glue, constpool, stringId);
915     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateRegExpWithLiteral),
916                               { pattern, Int8ToTaggedInt(flags) });
917     CHECK_EXCEPTION_WITH_ACC(res);
918 }
919 
GenerateCircuit()920 void BaselineCreateregexpwithliteralImm16Id16Imm8StubBuilder::GenerateCircuit()
921 {
922     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCreateregexpwithliteralImm16Id16Imm8, GLUE));
923     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCreateregexpwithliteralImm16Id16Imm8, SP));
924     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineCreateregexpwithliteralImm16Id16Imm8, STRING_ID));
925     GateRef flags = Int32Argument(PARAM_INDEX(BaselineCreateregexpwithliteralImm16Id16Imm8, FLAGS));
926 
927     GateRef frame = GetFrame(sp);
928     GateRef acc = GetAccFromFrame(frame);
929     GateRef func = GetFunctionFromFrame(frame);
930     GateRef method = GetMethodFromFunction(func);
931     GateRef constpool = GetConstpoolFromMethod(method);
932     GateRef pattern = GetStringFromConstPool(glue, constpool, stringId);
933     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateRegExpWithLiteral),
934                               { pattern, Int8ToTaggedInt(flags) });
935     CHECK_EXCEPTION_WITH_ACC(res);
936 }
937 
GenerateCircuit()938 void BaselineNewobjapplyImm8V8StubBuilder::GenerateCircuit()
939 {
940     GateRef glue = PtrArgument(PARAM_INDEX(BaselineNewobjapplyImm8V8, GLUE));
941     GateRef sp = PtrArgument(PARAM_INDEX(BaselineNewobjapplyImm8V8, SP));
942     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineNewobjapplyImm8V8, ACC));
943     GateRef func = TaggedArgument(PARAM_INDEX(BaselineNewobjapplyImm8V8, FUNC));
944 
945     GateRef result = CallRuntime(glue, RTSTUB_ID(NewObjApply), { func, acc }); // acc is array
946     CHECK_EXCEPTION_WITH_ACC(result);
947 }
948 
GenerateCircuit()949 void BaselineNewobjapplyImm16V8StubBuilder::GenerateCircuit()
950 {
951     GateRef glue = PtrArgument(PARAM_INDEX(BaselineNewobjapplyImm16V8, GLUE));
952     GateRef sp = PtrArgument(PARAM_INDEX(BaselineNewobjapplyImm16V8, SP));
953     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineNewobjapplyImm16V8, ACC));
954     GateRef func = TaggedArgument(PARAM_INDEX(BaselineNewobjapplyImm16V8, FUNC));
955 
956     GateRef result = CallRuntime(glue, RTSTUB_ID(NewObjApply), { func, acc }); // acc is array
957     CHECK_EXCEPTION_WITH_ACC(result);
958 }
959 
GenerateCircuit()960 void BaselineNewlexenvImm8StubBuilder::GenerateCircuit()
961 {
962     GateRef glue = PtrArgument(PARAM_INDEX(BaselineNewlexenvImm8, GLUE));
963     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineNewlexenvImm8, ACC));
964     GateRef numVars = Int32Argument(PARAM_INDEX(BaselineNewlexenvImm8, NUM_VARS));
965     GateRef sp = PtrArgument(PARAM_INDEX(BaselineNewlexenvImm8, SP));
966     auto parent = GetEnvFromFrame(GetFrame(sp));
967 
968     DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
969     auto env = GetEnvironment();
970 
971     NewObjectStubBuilder newBuilder(this);
972     newBuilder.SetParameters(glue, 0);
973     Label afterNew(env);
974     newBuilder.NewLexicalEnv(&result, &afterNew, numVars, parent);
975     Bind(&afterNew);
976     Label notException(env);
977     CHECK_EXCEPTION_WITH_JUMP_RETURN(*result, &notException);
978     Bind(&notException);
979     SetEnvToFrame(glue, GetFrame(sp), *result);
980     Return(*result);
981 }
982 
GenerateCircuit()983 void BaselineNewlexenvwithnameImm8Id16StubBuilder::GenerateCircuit()
984 {
985     GateRef glue = PtrArgument(PARAM_INDEX(BaselineNewlexenvwithnameImm8Id16, GLUE));
986     GateRef sp = PtrArgument(PARAM_INDEX(BaselineNewlexenvwithnameImm8Id16, SP));
987     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineNewlexenvwithnameImm8Id16, ACC));
988     GateRef numVars = Int32Argument(PARAM_INDEX(BaselineNewlexenvwithnameImm8Id16, NUM_VARS));
989     GateRef scopeId = Int32Argument(PARAM_INDEX(BaselineNewlexenvwithnameImm8Id16, SCOPEID));
990 
991     auto env = GetEnvironment();
992     GateRef res = CallRuntime(glue, RTSTUB_ID(NewLexicalEnvWithName),
993                               { Int16ToTaggedInt(numVars), Int16ToTaggedInt(scopeId) });
994     Label notException(env);
995     CHECK_EXCEPTION_WITH_JUMP_RETURN(res, &notException);
996     Bind(&notException);
997     GateRef state = GetFrame(sp);
998     SetEnvToFrame(glue, state, res);
999     Return(res);
1000 }
1001 
GenerateCircuit()1002 void BaselineAdd2Imm8V8StubBuilder::GenerateCircuit()
1003 {
1004     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineAdd2Imm8V8);
1005     OperationsStubBuilder builder(this);
1006     GateRef result = builder.Add(glue, left, acc, callback);
1007     CHECK_EXCEPTION_WITH_ACC(result);
1008 }
1009 
GenerateCircuit()1010 void BaselineSub2Imm8V8StubBuilder::GenerateCircuit()
1011 {
1012     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineSub2Imm8V8);
1013     OperationsStubBuilder builder(this);
1014     GateRef result = builder.Sub(glue, left, acc, callback);
1015     CHECK_EXCEPTION_WITH_ACC(result);
1016 }
1017 
GenerateCircuit()1018 void BaselineMul2Imm8V8StubBuilder::GenerateCircuit()
1019 {
1020     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineMul2Imm8V8);
1021     OperationsStubBuilder builder(this);
1022     GateRef result = builder.Mul(glue, left, acc, callback);
1023     CHECK_EXCEPTION_WITH_ACC(result);
1024 }
1025 
GenerateCircuit()1026 void BaselineDiv2Imm8V8StubBuilder::GenerateCircuit()
1027 {
1028     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineDiv2Imm8V8);
1029     OperationsStubBuilder builder(this);
1030     GateRef result = builder.Div(glue, left, acc, callback);
1031     CHECK_EXCEPTION_WITH_ACC(result);
1032 }
1033 
GenerateCircuit()1034 void BaselineMod2Imm8V8StubBuilder::GenerateCircuit()
1035 {
1036     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineMod2Imm8V8);
1037     OperationsStubBuilder builder(this);
1038     GateRef result = builder.Mod(glue, left, acc, callback);
1039     CHECK_EXCEPTION_WITH_ACC(result);
1040 }
1041 
GenerateCircuit()1042 void BaselineEqImm8V8StubBuilder::GenerateCircuit()
1043 {
1044     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineEqImm8V8);
1045     OperationsStubBuilder builder(this);
1046     GateRef result = builder.Equal(glue, left, acc, callback);
1047     CHECK_EXCEPTION_WITH_ACC(result);
1048 }
1049 
GenerateCircuit()1050 void BaselineNoteqImm8V8StubBuilder::GenerateCircuit()
1051 {
1052     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineNoteqImm8V8);
1053     OperationsStubBuilder builder(this);
1054     GateRef result = builder.NotEqual(glue, left, acc, callback);
1055     CHECK_EXCEPTION_WITH_ACC(result);
1056 }
1057 
GenerateCircuit()1058 void BaselineLessImm8V8StubBuilder::GenerateCircuit()
1059 {
1060     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineLessImm8V8);
1061     OperationsStubBuilder builder(this);
1062     GateRef result = builder.Less(glue, left, acc, callback);
1063     CHECK_EXCEPTION_WITH_ACC(result);
1064 }
1065 
GenerateCircuit()1066 void BaselineLesseqImm8V8StubBuilder::GenerateCircuit()
1067 {
1068     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineLesseqImm8V8);
1069     OperationsStubBuilder builder(this);
1070     GateRef result = builder.LessEq(glue, left, acc, callback);
1071     CHECK_EXCEPTION_WITH_ACC(result);
1072 }
1073 
GenerateCircuit()1074 void BaselineGreaterImm8V8StubBuilder::GenerateCircuit()
1075 {
1076     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineGreaterImm8V8);
1077     OperationsStubBuilder builder(this);
1078     GateRef result = builder.Greater(glue, left, acc, callback);
1079     CHECK_EXCEPTION_WITH_ACC(result);
1080 }
1081 
GenerateCircuit()1082 void BaselineGreatereqImm8V8StubBuilder::GenerateCircuit()
1083 {
1084     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineGreatereqImm8V8);
1085     OperationsStubBuilder builder(this);
1086     GateRef result = builder.GreaterEq(glue, left, acc, callback);
1087     CHECK_EXCEPTION_WITH_ACC(result);
1088 }
1089 
GenerateCircuit()1090 void BaselineShl2Imm8V8StubBuilder::GenerateCircuit()
1091 {
1092     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineShl2Imm8V8);
1093     OperationsStubBuilder builder(this);
1094     GateRef result = builder.Shl(glue, left, acc, callback);
1095     CHECK_EXCEPTION_WITH_ACC(result);
1096 }
1097 
GenerateCircuit()1098 void BaselineShr2Imm8V8StubBuilder::GenerateCircuit()
1099 {
1100     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineShr2Imm8V8);
1101     OperationsStubBuilder builder(this);
1102     GateRef result = builder.Shr(glue, left, acc, callback);
1103     CHECK_EXCEPTION_WITH_ACC(result);
1104 }
1105 
GenerateCircuit()1106 void BaselineAshr2Imm8V8StubBuilder::GenerateCircuit()
1107 {
1108     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineAshr2Imm8V8);
1109     OperationsStubBuilder builder(this);
1110     GateRef result = builder.Ashr(glue, left, acc, callback);
1111     CHECK_EXCEPTION_WITH_ACC(result);
1112 }
1113 
GenerateCircuit()1114 void BaselineAnd2Imm8V8StubBuilder::GenerateCircuit()
1115 {
1116     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineAnd2Imm8V8);
1117     OperationsStubBuilder builder(this);
1118     GateRef result = builder.And(glue, left, acc, callback);
1119     CHECK_EXCEPTION_WITH_ACC(result);
1120 }
1121 
GenerateCircuit()1122 void BaselineOr2Imm8V8StubBuilder::GenerateCircuit()
1123 {
1124     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineOr2Imm8V8);
1125     OperationsStubBuilder builder(this);
1126     GateRef result = builder.Or(glue, left, acc, callback);
1127     CHECK_EXCEPTION_WITH_ACC(result);
1128 }
1129 
GenerateCircuit()1130 void BaselineXor2Imm8V8StubBuilder::GenerateCircuit()
1131 {
1132     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineXor2Imm8V8);
1133     OperationsStubBuilder builder(this);
1134     GateRef result = builder.Xor(glue, left, acc, callback);
1135     CHECK_EXCEPTION_WITH_ACC(result);
1136 }
1137 
GenerateCircuit()1138 void BaselineExpImm8V8StubBuilder::GenerateCircuit()
1139 {
1140     GateRef glue = PtrArgument(PARAM_INDEX(BaselineExpImm8V8, GLUE));
1141     GateRef sp = PtrArgument(PARAM_INDEX(BaselineExpImm8V8, SP));
1142     GateRef base = TaggedArgument(PARAM_INDEX(BaselineExpImm8V8, BASE));
1143     GateRef acc = GetAccFromFrame(GetFrame(sp));
1144 
1145     GateRef result = CallRuntime(glue, RTSTUB_ID(Exp), { base, acc });
1146     CHECK_EXCEPTION_WITH_ACC(result);
1147 }
1148 
GenerateCircuit()1149 void BaselineTypeofImm8StubBuilder::GenerateCircuit()
1150 {
1151     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTypeofImm8, GLUE));
1152     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineTypeofImm8, ACC));
1153 
1154     GateRef result = FastTypeOf(glue, acc);
1155     Return(result);
1156 }
1157 
GenerateCircuit()1158 void BaselineTypeofImm16StubBuilder::GenerateCircuit()
1159 {
1160     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTypeofImm16, GLUE));
1161     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineTypeofImm16, ACC));
1162 
1163     GateRef result = FastTypeOf(glue, acc);
1164     Return(result);
1165 }
1166 
GenerateCircuit()1167 void BaselineTonumberImm8StubBuilder::GenerateCircuit()
1168 {
1169     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTonumberImm8, GLUE));
1170     GateRef sp = PtrArgument(PARAM_INDEX(BaselineTonumberImm8, SP));
1171     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineTonumberImm8, ACC));
1172 
1173     auto env = GetEnvironment();
1174     Label valueIsNumber(env);
1175     Label valueNotNumber(env);
1176     Branch(TaggedIsNumber(acc), &valueIsNumber, &valueNotNumber);
1177     Bind(&valueIsNumber);
1178     {
1179         Return(acc);
1180     }
1181     Bind(&valueNotNumber);
1182     {
1183         GateRef result = CallRuntime(glue, RTSTUB_ID(ToNumber), { acc });
1184         CHECK_EXCEPTION_RETURN(result);
1185     }
1186 }
1187 
GenerateCircuit()1188 void BaselineTonumericImm8StubBuilder::GenerateCircuit()
1189 {
1190     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTonumericImm8, GLUE));
1191     GateRef sp = PtrArgument(PARAM_INDEX(BaselineTonumericImm8, SP));
1192     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineTonumericImm8, ACC));
1193 
1194     auto env = GetEnvironment();
1195     Label valueIsNumeric(env);
1196     Label valueNotNumeric(env);
1197     Branch(TaggedIsNumeric(acc), &valueIsNumeric, &valueNotNumeric);
1198     Bind(&valueIsNumeric);
1199     {
1200         Return(acc);
1201     }
1202     Bind(&valueNotNumeric);
1203     {
1204         GateRef result = CallRuntime(glue, RTSTUB_ID(ToNumeric), { acc });
1205         CHECK_EXCEPTION_RETURN(result);
1206     }
1207 }
1208 
GenerateCircuit()1209 void BaselineNegImm8StubBuilder::GenerateCircuit()
1210 {
1211     DEFINE_SINGLEOP_PARAM_AND_PROFILE_CALLBACK(BaselineNegImm8);
1212     OperationsStubBuilder builder(this);
1213     GateRef result = builder.Neg(glue, acc, callback);
1214     CHECK_EXCEPTION_WITH_ACC(result);
1215 }
1216 
GenerateCircuit()1217 void BaselineNotImm8StubBuilder::GenerateCircuit()
1218 {
1219     DEFINE_SINGLEOP_PARAM_AND_PROFILE_CALLBACK(BaselineNotImm8);
1220     OperationsStubBuilder builder(this);
1221     GateRef result = builder.Not(glue, acc, callback);
1222     CHECK_EXCEPTION_WITH_ACC(result);
1223 }
1224 
GenerateCircuit()1225 void BaselineIncImm8StubBuilder::GenerateCircuit()
1226 {
1227     DEFINE_SINGLEOP_PARAM_AND_PROFILE_CALLBACK(BaselineIncImm8);
1228     OperationsStubBuilder builder(this);
1229     GateRef result = builder.Inc(glue, acc, callback);
1230     CHECK_EXCEPTION_WITH_ACC(result);
1231 }
1232 
GenerateCircuit()1233 void BaselineDecImm8StubBuilder::GenerateCircuit()
1234 {
1235     DEFINE_SINGLEOP_PARAM_AND_PROFILE_CALLBACK(BaselineDecImm8);
1236     OperationsStubBuilder builder(this);
1237     GateRef result = builder.Dec(glue, acc, callback);
1238     CHECK_EXCEPTION_WITH_ACC(result);
1239 }
1240 
GenerateCircuit()1241 void BaselineIsinImm8V8StubBuilder::GenerateCircuit()
1242 {
1243     GateRef glue = PtrArgument(PARAM_INDEX(BaselineIsinImm8V8, GLUE));
1244     GateRef sp = PtrArgument(PARAM_INDEX(BaselineIsinImm8V8, SP));
1245     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineIsinImm8V8, ACC));
1246     GateRef prop = TaggedArgument(PARAM_INDEX(BaselineIsinImm8V8, PROP));
1247     ProfileOperation callback;
1248 
1249     GateRef result = CallRuntime(glue, RTSTUB_ID(IsIn), { prop, acc }); // acc is obj
1250     CHECK_EXCEPTION_WITH_ACC(result);
1251 }
1252 
GenerateCircuit()1253 void BaselineInstanceofImm8V8StubBuilder::GenerateCircuit()
1254 {
1255     GateRef glue = PtrArgument(PARAM_INDEX(BaselineInstanceofImm8V8, GLUE));
1256     GateRef sp = PtrArgument(PARAM_INDEX(BaselineInstanceofImm8V8, SP));
1257     GateRef objId = Int32Argument(PARAM_INDEX(BaselineInstanceofImm8V8, OBJ_ID));
1258     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineInstanceofImm8V8, SLOTID));
1259     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1260 
1261     GateRef obj = GetVregValue(sp, ZExtInt32ToPtr(objId));
1262     GateRef acc = GetAccFromFrame(frame);
1263     AccessObjectStubBuilder builder(this);
1264     GateRef result = InstanceOf(glue, obj, acc, profileTypeInfo, slotId, callback);
1265     CHECK_PENDING_EXCEPTION(result);
1266 }
1267 
GenerateCircuit()1268 void BaselineStrictnoteqImm8V8StubBuilder::GenerateCircuit()
1269 {
1270     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineStrictnoteqImm8V8);
1271     OperationsStubBuilder builder(this);
1272     GateRef result = builder.StrictNotEqual(glue, left, acc, callback);
1273     Return(result);
1274 }
1275 
GenerateCircuit()1276 void BaselineStricteqImm8V8StubBuilder::GenerateCircuit()
1277 {
1278     DEFINE_BINARYOP_PARAM_AND_PROFILE_CALLBACK(BaselineStricteqImm8V8);
1279     OperationsStubBuilder builder(this);
1280     GateRef result = builder.StrictEqual(glue, left, acc, callback);
1281     Return(result);
1282 }
1283 
GenerateCircuit()1284 void BaselineIstrueStubBuilder::GenerateCircuit()
1285 {
1286     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineIstrue, ACC));
1287 
1288     GateRef result = FastToBooleanBaseline(acc, true);
1289     Return(result);
1290 }
1291 
GenerateCircuit()1292 void BaselineCallRuntimeIstruePrefImm8StubBuilder::GenerateCircuit()
1293 {
1294     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeIstruePrefImm8, GLUE));
1295     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeIstruePrefImm8, SP));
1296     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeIstruePrefImm8, ACC));
1297     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallRuntimeIstruePrefImm8, SLOT_ID));
1298     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1299 
1300     GateRef result = FastToBooleanWithProfileBaseline(acc, callback, true);
1301     Return(result);
1302 }
1303 
GenerateCircuit()1304 void BaselineIsfalseStubBuilder::GenerateCircuit()
1305 {
1306     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineIsfalse, ACC));
1307 
1308     GateRef result = FastToBooleanBaseline(acc, false);
1309     Return(result);
1310 }
1311 
GenerateCircuit()1312 void BaselineCallRuntimeIsfalsePrefImm8StubBuilder::GenerateCircuit()
1313 {
1314     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeIsfalsePrefImm8, GLUE));
1315     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeIsfalsePrefImm8, SP));
1316     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeIsfalsePrefImm8, ACC));
1317     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallRuntimeIsfalsePrefImm8, SLOT_ID));
1318     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1319 
1320     GateRef result = FastToBooleanWithProfileBaseline(acc, callback, false);
1321     Return(result);
1322 }
1323 
1324 
GenerateCircuit()1325 void BaselineCallthis3Imm8V8V8V8V8StubBuilder::GenerateCircuit()
1326 {
1327     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallthis3Imm8V8V8V8V8, GLUE));
1328     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallthis3Imm8V8V8V8V8, SP));
1329     GateRef thisValueId = Int32Argument(PARAM_INDEX(BaselineCallthis3Imm8V8V8V8V8, THIS_VALUE_ID));
1330     GateRef argIds = Int32Argument(PARAM_INDEX(BaselineCallthis3Imm8V8V8V8V8, ARG_IDS));
1331     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallthis3Imm8V8V8V8V8, SLOT_ID));
1332 
1333     GateRef arg0Id = Int32And(argIds, Int32(ONE_BYTE_ALL_ONE));
1334     GateRef arg1Id = Int32And(Int32LSR(argIds, Int32(ONE_BYTE_SIZE)), Int32(ONE_BYTE_ALL_ONE));
1335     GateRef arg2Id = Int32And(Int32LSR(argIds, Int32(TWO_BYTE_SIZE)), Int32(ONE_BYTE_ALL_ONE));
1336 
1337     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1338 
1339     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARGS3);
1340 
1341     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
1342 
1343     GateRef acc = GetAccFromFrame(frame);
1344     GateRef curMethod = GetMethodFromFunction(curFunc);
1345     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
1346     METHOD_ENTRY(acc);
1347     GateRef a0Value = GetVregValue(sp, ZExtInt32ToPtr(arg0Id));
1348     GateRef a1Value = GetVregValue(sp, ZExtInt32ToPtr(arg1Id));
1349     GateRef a2Value = GetVregValue(sp, ZExtInt32ToPtr(arg2Id));
1350     GateRef thisValue = GetVregValue(sp, ZExtInt32ToPtr(thisValueId));
1351     Label noNeedCheckException(env);
1352     Label exit(env);
1353     GateRef jumpSize = INT_PTR(CALLTHIS3_IMM8_V8_V8_V8_V8);
1354     JSCallArgs callArgs(JSCallMode::CALL_THIS_ARG3);
1355     callArgs.callArgsWithThis = { a0Value, a1Value, a2Value, thisValue };
1356     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
1357     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1358     Bind(&exit);
1359     CHECK_PENDING_EXCEPTION(*result);
1360     Bind(&noNeedCheckException);
1361     Return(*result);
1362 }
1363 
GenerateCircuit()1364 void BaselineCallthisrangeImm8Imm8V8StubBuilder::GenerateCircuit()
1365 {
1366     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallthisrangeImm8Imm8V8, GLUE));
1367     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallthisrangeImm8Imm8V8, SP));
1368     GateRef actualNumArgs = Int32Argument(PARAM_INDEX(BaselineCallthisrangeImm8Imm8V8, ACTUAL_NUM_ARGS));
1369     GateRef thisReg = Int32Argument(PARAM_INDEX(BaselineCallthisrangeImm8Imm8V8, THIS_REG));
1370     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallthisrangeImm8Imm8V8, SLOT_ID));
1371     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1372     GateRef curMethod = GetMethodFromFunction(curFunc);
1373     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
1374     GateRef numArgs = ZExtInt32ToPtr(actualNumArgs);
1375 
1376     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
1377     GateRef acc = GetAccFromFrame(frame);
1378     METHOD_ENTRY(acc);
1379     Label noNeedCheckException(env);
1380     Label exit(env);
1381     GateRef thisValue = GetVregValue(sp, ZExtInt8ToPtr(thisReg));
1382     GateRef argv = PtrAdd(sp, PtrMul(PtrAdd(ZExtInt8ToPtr(thisReg), IntPtr(1)), IntPtr(8)));
1383     GateRef jumpSize = INT_PTR(CALLTHISRANGE_IMM8_IMM8_V8);
1384     JSCallArgs callArgs(JSCallMode::CALL_THIS_WITH_ARGV);
1385     callArgs.callArgvWithThis = { numArgs, argv, thisValue };
1386     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
1387     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1388     Bind(&exit);
1389     CHECK_PENDING_EXCEPTION(*result);
1390     Bind(&noNeedCheckException);
1391     Return(*result);
1392 }
1393 
GenerateCircuit()1394 void BaselineSupercallthisrangeImm8Imm8V8StubBuilder::GenerateCircuit()
1395 {
1396     GateRef glue = PtrArgument(PARAM_INDEX(BaselineSupercallthisrangeImm8Imm8V8, GLUE));
1397     GateRef sp = PtrArgument(PARAM_INDEX(BaselineSupercallthisrangeImm8Imm8V8, SP));
1398     GateRef range = Int32Argument(PARAM_INDEX(BaselineSupercallthisrangeImm8Imm8V8, RANGE));
1399     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineSupercallthisrangeImm8Imm8V8, V0));
1400     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineSupercallthisrangeImm8Imm8V8, HOTNESS_COUNTER));
1401     ProfileOperation callback;
1402 
1403     DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
1404     DEFVARIABLE(thisObj, VariableType::JS_ANY(), Undefined());
1405     auto env = GetEnvironment();
1406     GateRef actualNumArgs = ZExtInt16ToInt32(range);
1407     GateRef frame = GetFrame(sp);
1408     GateRef thisFunc = GetFunctionFromFrame(frame);
1409     GateRef newTarget = GetNewTarget(sp);
1410     GateRef superCtor = GetPrototype(glue, thisFunc);
1411 
1412     Label ctorIsHeapObject(env);
1413     Label ctorIsJSFunction(env);
1414     Label ctorIsConstructor(env);
1415     Label fastPath(env);
1416     Label slowPath(env);
1417     Label checkResult(env);
1418     Label threadCheck(env);
1419     Label dispatch(env);
1420     Label ctorIsBase(env);
1421     Label ctorNotBase(env);
1422     Label isException(env);
1423     Label noNeedCheckException(env);
1424     Label exit(env);
1425 
1426     Branch(TaggedIsHeapObject(superCtor), &ctorIsHeapObject, &slowPath);
1427     Bind(&ctorIsHeapObject);
1428     Branch(IsJSFunction(superCtor), &ctorIsJSFunction, &slowPath);
1429     Bind(&ctorIsJSFunction);
1430     Branch(IsConstructor(superCtor), &ctorIsConstructor, &slowPath);
1431     Bind(&ctorIsConstructor);
1432     Branch(TaggedIsUndefined(newTarget), &slowPath, &fastPath);
1433     Bind(&fastPath);
1434     {
1435         Branch(IsBase(superCtor), &ctorIsBase, &ctorNotBase);
1436         Bind(&ctorIsBase);
1437         {
1438             NewObjectStubBuilder newBuilder(this);
1439             thisObj = newBuilder.FastSuperAllocateThis(glue, superCtor, newTarget);
1440             Branch(HasPendingException(glue), &isException, &ctorNotBase);
1441         }
1442         Bind(&ctorNotBase);
1443         {
1444             // skip function
1445             GateRef argv = PtrAdd(sp, PtrMul(ZExtInt16ToPtr(v0), IntPtr(JSTaggedValue::TaggedTypeSize())));
1446             GateRef jumpSize = IntPtr(-BytecodeInstruction::Size(BytecodeInstruction::Format::IMM8_IMM8_V8));
1447             METHOD_ENTRY_ENV_DEFINED(superCtor);
1448             JSCallArgs callArgs(JSCallMode::SUPER_CALL_WITH_ARGV);
1449             callArgs.superCallArgs = {
1450                 thisFunc, Int16ToTaggedInt(v0), ZExtInt32ToPtr(actualNumArgs), argv, *thisObj, newTarget
1451             };
1452             CallStubBuilder callBuilder(this, glue, superCtor, actualNumArgs, jumpSize, &res, hotnessCounter, callArgs,
1453                 callback);
1454             callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1455             Bind(&exit);
1456             Jump(&threadCheck);
1457         }
1458     }
1459     Bind(&slowPath);
1460     {
1461         res = CallRuntime(glue, RTSTUB_ID(SuperCall),
1462                           { thisFunc, Int16ToTaggedInt(v0), Int16ToTaggedInt(range) });
1463         Jump(&checkResult);
1464     }
1465     Bind(&checkResult);
1466     {
1467         Branch(TaggedIsException(*res), &isException, &dispatch);
1468     }
1469     Bind(&threadCheck);
1470     {
1471         Branch(HasPendingException(glue), &isException, &dispatch);
1472     }
1473     Bind(&isException);
1474     {
1475         GateRef acc = GetAccFromFrame(frame);
1476         DISPATCH_LAST();
1477         Return(acc);
1478     }
1479     Bind(&dispatch);
1480     Return(*res);
1481     Bind(&noNeedCheckException);
1482     Return(*res);
1483 }
1484 
GenerateCircuit()1485 void BaselineSupercallarrowrangeImm8Imm8V8StubBuilder::GenerateCircuit()
1486 {
1487     GateRef glue = PtrArgument(PARAM_INDEX(BaselineSupercallarrowrangeImm8Imm8V8, GLUE));
1488     GateRef sp = PtrArgument(PARAM_INDEX(BaselineSupercallarrowrangeImm8Imm8V8, SP));
1489     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineSupercallarrowrangeImm8Imm8V8, ACC));
1490     GateRef range = Int32Argument(PARAM_INDEX(BaselineSupercallarrowrangeImm8Imm8V8, RANGE));
1491     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineSupercallarrowrangeImm8Imm8V8, V0));
1492 
1493     GateRef res = CallRuntime(glue, RTSTUB_ID(SuperCall),
1494         { acc, Int16ToTaggedInt(v0), Int8ToTaggedInt(range) });
1495     CHECK_EXCEPTION_WITH_ACC(res);
1496 }
1497 
GenerateCircuit()1498 void BaselineDefinefuncImm8Id16Imm8StubBuilder::GenerateCircuit()
1499 {
1500     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefinefuncImm8Id16Imm8, GLUE));
1501     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefinefuncImm8Id16Imm8, SP));
1502     GateRef methodId = Int32Argument(PARAM_INDEX(BaselineDefinefuncImm8Id16Imm8, METHODID));
1503     GateRef length = Int32Argument(PARAM_INDEX(BaselineDefinefuncImm8Id16Imm8, LENGTH));
1504     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineDefinefuncImm8Id16Imm8, SLOT_ID));
1505 
1506     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1507     GateRef method = GetMethodFromFunction(curFunc);
1508     GateRef constpool = GetConstpoolFromMethod(method);
1509 
1510     auto env = GetEnvironment();
1511     GateRef acc = GetAccFromFrame(frame);
1512     GateRef result = DefineFunc(glue, constpool, methodId);
1513     Label notException(env);
1514     CHECK_EXCEPTION_WITH_JUMP_RETURN(result, &notException);
1515     Bind(&notException);
1516     {
1517         SetLengthToFunction(glue, result, length);
1518         GateRef envHandle = GetEnvFromFrame(frame);
1519         SetLexicalEnvToFunction(glue, result, envHandle);
1520         GateRef currentFunc = GetFunctionFromFrame(frame);
1521         SetModuleToFunction(glue, result, GetModuleFromFunction(currentFunc));
1522         SetHomeObjectToFunction(glue, result, GetHomeObjectFromFunction(currentFunc));
1523         callback.ProfileDefineClass(result);
1524         Return(result);
1525     }
1526 }
1527 
GenerateCircuit()1528 void BaselineDefinefuncImm16Id16Imm8StubBuilder::GenerateCircuit()
1529 {
1530     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefinefuncImm16Id16Imm8, GLUE));
1531     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefinefuncImm16Id16Imm8, SP));
1532     GateRef methodId = Int32Argument(PARAM_INDEX(BaselineDefinefuncImm16Id16Imm8, METHODID));
1533     GateRef length = Int32Argument(PARAM_INDEX(BaselineDefinefuncImm16Id16Imm8, LENGTH));
1534     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineDefinefuncImm16Id16Imm8, SLOT_ID));
1535     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1536 
1537     GateRef method = GetMethodFromFunction(curFunc);
1538     GateRef constpool = GetConstpoolFromMethod(method);
1539     auto env = GetEnvironment();
1540     GateRef acc = GetAccFromFrame(frame);
1541 
1542     GateRef result = DefineFunc(glue, constpool, methodId);
1543     Label notException(env);
1544     CHECK_EXCEPTION_WITH_JUMP_RETURN(result, &notException);
1545     Bind(&notException);
1546     {
1547         SetLengthToFunction(glue, result, length);
1548         GateRef envHandle = GetEnvFromFrame(frame);
1549         SetLexicalEnvToFunction(glue, result, envHandle);
1550         GateRef currentFunc = GetFunctionFromFrame(frame);
1551         SetModuleToFunction(glue, result, GetModuleFromFunction(currentFunc));
1552         SetHomeObjectToFunction(glue, result, GetHomeObjectFromFunction(currentFunc));
1553         callback.ProfileDefineClass(result);
1554         Return(result);
1555     }
1556 }
1557 
GenerateCircuit()1558 void BaselineDefinemethodImm8Id16Imm8StubBuilder::GenerateCircuit()
1559 {
1560     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefinemethodImm8Id16Imm8, GLUE));
1561     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDefinemethodImm8Id16Imm8, ACC));
1562     GateRef methodId = Int32Argument(PARAM_INDEX(BaselineDefinemethodImm8Id16Imm8, METHODID));
1563     GateRef length = Int32Argument(PARAM_INDEX(BaselineDefinemethodImm8Id16Imm8, LENGTH));
1564     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefinemethodImm8Id16Imm8, SP));
1565     ProfileOperation callback;
1566 
1567     GateRef func = GetFunctionFromFrame(GetFrame(sp));
1568     GateRef method = GetMethodFromFunction(func);
1569     GateRef constpool = GetConstpoolFromMethod(method);
1570     auto env = GetEnvironment();
1571     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
1572     GateRef lexEnv = GetEnvFromFrame(GetFrame(sp));
1573     DEFVARIABLE(result, VariableType::JS_POINTER(),
1574         GetMethodFromConstPool(glue, constpool, methodId));
1575     result = CallRuntime(glue, RTSTUB_ID(DefineMethod), { *result, acc, Int8ToTaggedInt(length),
1576                                                           lexEnv, GetModule(sp) });
1577     Label notException(env);
1578     CHECK_EXCEPTION_WITH_JUMP_RETURN(*result, &notException);
1579     Bind(&notException);
1580     Return(*result);
1581 }
1582 
GenerateCircuit()1583 void BaselineDefinemethodImm16Id16Imm8StubBuilder::GenerateCircuit()
1584 {
1585     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefinemethodImm16Id16Imm8, GLUE));
1586     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDefinemethodImm16Id16Imm8, ACC));
1587     GateRef methodId = Int32Argument(PARAM_INDEX(BaselineDefinemethodImm16Id16Imm8, METHODID));
1588     GateRef length = Int32Argument(PARAM_INDEX(BaselineDefinemethodImm16Id16Imm8, LENGTH));
1589     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefinemethodImm16Id16Imm8, SP));
1590     ProfileOperation callback;
1591 
1592     GateRef func = GetFunctionFromFrame(GetFrame(sp));
1593     GateRef method = GetMethodFromFunction(func);
1594     GateRef constpool = GetConstpoolFromMethod(method);
1595     auto env = GetEnvironment();
1596     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
1597     GateRef lexEnv = GetEnvFromFrame(GetFrame(sp));
1598     DEFVARIABLE(result, VariableType::JS_POINTER(),
1599         GetMethodFromConstPool(glue, constpool, methodId));
1600     result = CallRuntime(glue, RTSTUB_ID(DefineMethod), { *result, acc, Int8ToTaggedInt(length),
1601                                                           lexEnv, GetModule(sp) });
1602     Label notException(env);
1603     CHECK_EXCEPTION_WITH_JUMP_RETURN(*result, &notException);
1604     Bind(&notException);
1605     Return(*result);
1606 }
1607 
GenerateCircuit()1608 void BaselineCallarg0Imm8StubBuilder::GenerateCircuit()
1609 {
1610     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallarg0Imm8, GLUE));
1611     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallarg0Imm8, SP));
1612     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallarg0Imm8, SLOT_ID));
1613     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1614 
1615     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
1616     GateRef acc = GetAccFromFrame(frame);
1617     METHOD_ENTRY(acc);
1618     Label noNeedCheckException(env);
1619     Label exit(env);
1620     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARG0);
1621     GateRef jumpSize = INT_PTR(CALLARG0_IMM8);
1622     GateRef curMethod = GetMethodFromFunction(curFunc);
1623     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
1624     JSCallArgs callArgs(JSCallMode::CALL_ARG0);
1625     callArgs.callArgs = { 0, 0, 0 };
1626     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
1627     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1628     Bind(&exit);
1629     CHECK_PENDING_EXCEPTION(*result);
1630     Bind(&noNeedCheckException);
1631     Return(*result);
1632 }
1633 
GenerateCircuit()1634 void BaselineSupercallspreadImm8V8StubBuilder::GenerateCircuit()
1635 {
1636     GateRef glue = PtrArgument(PARAM_INDEX(BaselineSupercallspreadImm8V8, GLUE));
1637     GateRef sp = PtrArgument(PARAM_INDEX(BaselineSupercallspreadImm8V8, SP));
1638     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineSupercallspreadImm8V8, ACC));
1639     GateRef array = TaggedArgument(PARAM_INDEX(BaselineSupercallspreadImm8V8, ARRARY));
1640     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineSupercallspreadImm8V8, HOTNESS_COUNTER));
1641     ProfileOperation callback;
1642 
1643     DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
1644     DEFVARIABLE(thisObj, VariableType::JS_ANY(), Undefined());
1645     auto env = GetEnvironment();
1646     GateRef newTarget = GetNewTarget(sp);
1647     GateRef superCtor = GetPrototype(glue, acc);
1648 
1649     Label dispatch(env);
1650     Label normalPath(env);
1651     Label slowPath(env);
1652     Label ctorIsJSFunction(env);
1653     Label ctorIsBase(env);
1654     Label ctorNotBase(env);
1655     Label ctorIsHeapObject(env);
1656     Label ctorIsConstructor(env);
1657     Label threadCheck(env);
1658     Label isException(env);
1659     Label noNeedCheckException(env);
1660     Label exit(env);
1661 
1662     Branch(TaggedIsHeapObject(superCtor), &ctorIsHeapObject, &slowPath);
1663     Bind(&ctorIsHeapObject);
1664     Branch(IsJSFunction(superCtor), &ctorIsJSFunction, &slowPath);
1665     Bind(&ctorIsJSFunction);
1666     Branch(IsConstructor(superCtor), &ctorIsConstructor, &slowPath);
1667     Bind(&ctorIsConstructor);
1668     Branch(TaggedIsUndefined(newTarget), &slowPath, &normalPath);
1669     Bind(&normalPath);
1670     {
1671         Branch(IsBase(superCtor), &ctorIsBase, &ctorNotBase);
1672         Bind(&ctorIsBase);
1673         {
1674             NewObjectStubBuilder objBuilder(this);
1675             thisObj = objBuilder.FastSuperAllocateThis(glue, superCtor, newTarget);
1676             Branch(HasPendingException(glue), &isException, &ctorNotBase);
1677         }
1678         Bind(&ctorNotBase);
1679         {
1680             GateRef argvLen = Load(VariableType::INT32(), array, IntPtr(JSArray::LENGTH_OFFSET));
1681             GateRef srcElements = GetCallSpreadArgs(glue, array, callback);
1682             GateRef jumpSize = IntPtr(-BytecodeInstruction::Size(BytecodeInstruction::Format::IMM8_V8));
1683             METHOD_ENTRY_ENV_DEFINED(superCtor);
1684             GateRef elementsPtr = PtrAdd(srcElements, IntPtr(TaggedArray::DATA_OFFSET));
1685             JSCallArgs callArgs(JSCallMode::SUPER_CALL_SPREAD_WITH_ARGV);
1686             callArgs.superCallArgs = { acc, array, ZExtInt32ToPtr(argvLen), elementsPtr, *thisObj, newTarget };
1687             CallStubBuilder callBuilder(this, glue, superCtor, argvLen, jumpSize, &res, hotnessCounter, callArgs,
1688                 callback);
1689             callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1690             Bind(&exit);
1691             Jump(&threadCheck);
1692         }
1693     }
1694     Bind(&slowPath);
1695     {
1696         res = CallRuntime(glue, RTSTUB_ID(SuperCallSpread), { acc, array });
1697         Jump(&threadCheck);
1698     }
1699     Bind(&threadCheck);
1700     {
1701         GateRef resVal = *res;
1702         GateRef isError = LogicAndBuilder(env).And(TaggedIsException(resVal)).And(HasPendingException(glue)).Done();
1703         Branch(isError, &isException, &dispatch);
1704     }
1705     Bind(&isException);
1706     {
1707         DISPATCH_LAST();
1708         Return(acc);
1709     }
1710     Bind(&dispatch);
1711     Return(*res);
1712     Bind(&noNeedCheckException);
1713     Return(*res);
1714 }
1715 
GenerateCircuit()1716 void BaselineApplyImm8V8V8StubBuilder::GenerateCircuit()
1717 {
1718     GateRef glue = PtrArgument(PARAM_INDEX(BaselineApplyImm8V8V8, GLUE));
1719     GateRef sp = PtrArgument(PARAM_INDEX(BaselineApplyImm8V8V8, SP));
1720     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineApplyImm8V8V8, ACC));
1721     GateRef obj = TaggedArgument(PARAM_INDEX(BaselineApplyImm8V8V8, OBJ));
1722     GateRef array = TaggedArgument(PARAM_INDEX(BaselineApplyImm8V8V8, ARRARY));
1723 
1724     GateRef res = CallRuntime(glue, RTSTUB_ID(CallSpread), { acc, obj, array });
1725     CHECK_PENDING_EXCEPTION(res);
1726 }
1727 
GenerateCircuit()1728 void BaselineCallargs2Imm8V8V8StubBuilder::GenerateCircuit()
1729 {
1730     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallargs2Imm8V8V8, GLUE));
1731     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallargs2Imm8V8V8, SP));
1732     GateRef arg0No = Int32Argument(PARAM_INDEX(BaselineCallargs2Imm8V8V8, ARG0_NO));
1733     GateRef arg1No = Int32Argument(PARAM_INDEX(BaselineCallargs2Imm8V8V8, ARG1_NO));
1734     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallargs2Imm8V8V8, SLOT_ID));
1735     GateRef a0Value = GetVregValue(sp, ZExtInt32ToPtr(arg0No));
1736     GateRef a1Value = GetVregValue(sp, ZExtInt32ToPtr(arg1No));
1737     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1738 
1739     GateRef acc = GetAccFromFrame(frame);
1740     GateRef curMethod = GetMethodFromFunction(curFunc);
1741     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
1742 
1743     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
1744     METHOD_ENTRY(acc);
1745     Label noNeedCheckException(env);
1746     Label exit(env);
1747     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARGS2);
1748     GateRef jumpSize = INT_PTR(CALLARGS2_IMM8_V8_V8);
1749     JSCallArgs callArgs(JSCallMode::CALL_ARG2);
1750     callArgs.callArgs = { a0Value, a1Value, 0 };
1751     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
1752     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1753     Bind(&exit);
1754     CHECK_PENDING_EXCEPTION(*result);
1755     Bind(&noNeedCheckException);
1756     Return(*result);
1757 }
1758 
GenerateCircuit()1759 void BaselineCallargs3Imm8V8V8V8StubBuilder::GenerateCircuit()
1760 {
1761     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallargs3Imm8V8V8V8, GLUE));
1762     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallargs3Imm8V8V8V8, SP));
1763     GateRef arg0No = Int32Argument(PARAM_INDEX(BaselineCallargs3Imm8V8V8V8, ARG0_NO));
1764     GateRef arg1No = Int32Argument(PARAM_INDEX(BaselineCallargs3Imm8V8V8V8, ARG1_NO));
1765     GateRef arg2No = Int32Argument(PARAM_INDEX(BaselineCallargs3Imm8V8V8V8, ARG2_NO));
1766     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallargs3Imm8V8V8V8, SLOT_ID));
1767 
1768     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1769     GateRef curMethod = GetMethodFromFunction(curFunc);
1770     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
1771     GateRef arg0Value = GetVregValue(sp, ZExtInt32ToPtr(arg0No));
1772     GateRef arg1Value = GetVregValue(sp, ZExtInt32ToPtr(arg1No));
1773     GateRef arg2Value = GetVregValue(sp, ZExtInt32ToPtr(arg2No));
1774     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
1775     GateRef acc = GetAccFromFrame(frame);
1776     METHOD_ENTRY(acc);
1777     Label noNeedCheckException(env);
1778     Label exit(env);
1779     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARGS3);
1780     GateRef jumpSize = INT_PTR(CALLARGS3_IMM8_V8_V8_V8);
1781     JSCallArgs callArgs(JSCallMode::CALL_ARG3);
1782     callArgs.callArgs = { arg0Value, arg1Value, arg2Value };
1783     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
1784     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1785     Bind(&exit);
1786     CHECK_PENDING_EXCEPTION(*result);
1787     Bind(&noNeedCheckException);
1788     Return(*result);
1789 }
1790 
GenerateCircuit()1791 void BaselineCallrangeImm8Imm8V8StubBuilder::GenerateCircuit()
1792 {
1793     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallrangeImm8Imm8V8, GLUE));
1794     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallrangeImm8Imm8V8, SP));
1795     GateRef actualNumArgs = Int32Argument(PARAM_INDEX(BaselineCallrangeImm8Imm8V8, ACTUAL_NUM_ARGS));
1796     GateRef argStart = Int32Argument(PARAM_INDEX(BaselineCallrangeImm8Imm8V8, ARG_START));
1797     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallrangeImm8Imm8V8, SLOT_ID));
1798     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1799 
1800     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
1801     GateRef acc = GetAccFromFrame(frame);
1802     GateRef curMethod = GetMethodFromJSFunctionOrProxy(curFunc);
1803     GateRef hotnessCounter = GetHotnessCounterFromMethod(curMethod);
1804     METHOD_ENTRY(acc);
1805     Label noNeedCheckException(env);
1806     Label exit(env);
1807     GateRef argv = PtrAdd(sp, PtrMul(ZExtInt32ToPtr(argStart), IntPtr(8)));
1808     GateRef jumpSize = INT_PTR(CALLRANGE_IMM8_IMM8_V8);
1809     GateRef numArgs = ZExtInt32ToPtr(actualNumArgs);
1810     JSCallArgs callArgs(JSCallMode::CALL_WITH_ARGV);
1811     callArgs.callArgv = { numArgs, argv };
1812     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
1813     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
1814     Bind(&exit);
1815     CHECK_PENDING_EXCEPTION(*result);
1816     Bind(&noNeedCheckException);
1817     Return(*result);
1818 }
1819 
GenerateCircuit()1820 void BaselineLdexternalmodulevarImm8StubBuilder::GenerateCircuit()
1821 {
1822     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdexternalmodulevarImm8, GLUE));
1823     GateRef index = Int32Argument(PARAM_INDEX(BaselineLdexternalmodulevarImm8, INDEX));
1824 
1825     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(LdExternalModuleVarByIndex), { Int8ToTaggedInt(index) });
1826     Return(moduleRef);
1827 }
1828 
GenerateCircuit()1829 void BaselineLdthisbynameImm8Id16StubBuilder::GenerateCircuit()
1830 {
1831     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdthisbynameImm8Id16, GLUE));
1832     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdthisbynameImm8Id16, SP));
1833     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdthisbynameImm8Id16, STRING_ID));
1834     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdthisbynameImm8Id16, SLOT_ID));
1835     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1836 
1837     GateRef method = GetMethodFromFunction(curFunc);
1838     GateRef constpool = GetConstpoolFromMethod(method);
1839     GateRef receiver = GetThisFromFrame(frame);
1840 
1841     AccessObjectStubBuilder builder(this);
1842     StringIdInfo stringIdInfo(constpool, stringId);
1843     GateRef result = builder.LoadObjByName(glue, receiver, 0, stringIdInfo, profileTypeInfo, slotId, callback);
1844     CHECK_EXCEPTION_RETURN(result);
1845 }
1846 
GenerateCircuit()1847 void BaselineDefinegettersetterbyvalueV8V8V8V8StubBuilder::GenerateCircuit()
1848 {
1849     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefinegettersetterbyvalueV8V8V8V8, GLUE));
1850     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefinegettersetterbyvalueV8V8V8V8, SP));
1851     GateRef offset = Int32Argument(PARAM_INDEX(BaselineDefinegettersetterbyvalueV8V8V8V8, OFFSET));
1852     GateRef vregIds = Int32Argument(PARAM_INDEX(BaselineDefinegettersetterbyvalueV8V8V8V8, VREG_IDS));
1853 
1854     GateRef objectVregId = Int32And(vregIds, Int32(ONE_BYTE_ALL_ONE));
1855     GateRef propkeyVregId = Int32And(Int32LSR(vregIds, Int32(ONE_BYTE_SIZE)), Int32(ONE_BYTE_ALL_ONE));
1856     GateRef getterVregId = Int32And(Int32LSR(vregIds, Int32(TWO_BYTE_SIZE)), Int32(ONE_BYTE_ALL_ONE));
1857     GateRef setterVregId = Int32And(Int32LSR(vregIds, Int32(THREE_BYTE_SIZE)), Int32(ONE_BYTE_ALL_ONE));
1858 
1859     GateRef obj = GetVregValue(sp, ZExtInt32ToPtr(objectVregId));
1860     GateRef prop = GetVregValue(sp, ZExtInt32ToPtr(propkeyVregId));
1861     GateRef getter = GetVregValue(sp, ZExtInt32ToPtr(getterVregId));
1862     GateRef setter = GetVregValue(sp, ZExtInt32ToPtr(setterVregId));
1863 
1864     GateRef frame = GetFrame(sp);
1865     GateRef acc = GetAccFromFrame(frame);
1866 
1867     GateRef func = GetFunctionFromFrame(frame);
1868     GateRef offsetPtr = TaggedPtrToTaggedIntPtr(IntPtr(offset));
1869     GateRef res = CallRuntime(glue, RTSTUB_ID(DefineGetterSetterByValue),
1870                               { obj, prop, getter, setter, acc, func, offsetPtr }); // acc is flag
1871     CHECK_EXCEPTION_WITH_ACC(res);
1872 }
1873 
GenerateCircuit()1874 void BaselineLdthisbynameImm16Id16StubBuilder::GenerateCircuit()
1875 {
1876     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdthisbynameImm16Id16, GLUE));
1877     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdthisbynameImm16Id16, SP));
1878     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdthisbynameImm16Id16, STRING_ID));
1879     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdthisbynameImm16Id16, SLOT_ID));
1880     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1881 
1882     GateRef method = GetMethodFromFunction(curFunc);
1883     GateRef constpool = GetConstpoolFromMethod(method);
1884     GateRef receiver = GetThisFromFrame(frame);
1885 
1886     AccessObjectStubBuilder builder(this);
1887     StringIdInfo stringIdInfo(constpool, stringId);
1888     GateRef result = builder.LoadObjByName(glue, receiver, 0, stringIdInfo, profileTypeInfo, slotId, callback);
1889     CHECK_EXCEPTION_RETURN(result);
1890 }
1891 
GenerateCircuit()1892 void BaselineStthisbynameImm8Id16StubBuilder::GenerateCircuit()
1893 {
1894     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStthisbynameImm8Id16, GLUE));
1895     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStthisbynameImm8Id16, SP));
1896     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStthisbynameImm8Id16, STRING_ID));
1897     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStthisbynameImm8Id16, SLOT_ID));
1898 
1899     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1900     GateRef method = GetMethodFromFunction(curFunc);
1901     GateRef constpool = GetConstpoolFromMethod(method);
1902     GateRef acc = GetAccFromFrame(frame);
1903     AccessObjectStubBuilder builder(this);
1904     GateRef receiver = GetThisFromFrame(frame);
1905     StringIdInfo stringIdInfo(constpool, stringId);
1906     GateRef result =
1907         builder.StoreObjByName(glue, receiver, 0, stringIdInfo, acc, profileTypeInfo, slotId, callback);
1908     CHECK_EXCEPTION(result);
1909 }
1910 
GenerateCircuit()1911 void BaselineStthisbynameImm16Id16StubBuilder::GenerateCircuit()
1912 {
1913     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStthisbynameImm16Id16, GLUE));
1914     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStthisbynameImm16Id16, SP));
1915     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStthisbynameImm16Id16, STRING_ID));
1916     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStthisbynameImm16Id16, SLOT_ID));
1917     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1918 
1919     GateRef method = GetMethodFromFunction(curFunc);
1920     GateRef constpool = GetConstpoolFromMethod(method);
1921     GateRef acc = GetAccFromFrame(frame);
1922     AccessObjectStubBuilder builder(this);
1923     GateRef receiver = GetThisFromFrame(frame);
1924     StringIdInfo stringIdInfo(constpool, stringId);
1925     GateRef result = builder.StoreObjByName(glue, receiver, 0, stringIdInfo, acc, profileTypeInfo, slotId, callback);
1926     CHECK_EXCEPTION(result);
1927 }
1928 
GenerateCircuit()1929 void BaselineLdthisbyvalueImm8StubBuilder::GenerateCircuit()
1930 {
1931     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdthisbyvalueImm8, GLUE));
1932     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdthisbyvalueImm8, SP));
1933     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdthisbyvalueImm8, SLOT_ID));
1934     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1935 
1936     GateRef acc = GetAccFromFrame(frame);
1937 
1938     AccessObjectStubBuilder builder(this);
1939     GateRef receiver = GetThisFromFrame(frame);
1940     GateRef result = builder.LoadObjByValue(glue, receiver, acc, profileTypeInfo, slotId, callback);
1941     CHECK_EXCEPTION_RETURN(result);
1942 }
1943 
GenerateCircuit()1944 void BaselineLdthisbyvalueImm16StubBuilder::GenerateCircuit()
1945 {
1946     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdthisbyvalueImm16, GLUE));
1947     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdthisbyvalueImm16, SP));
1948     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdthisbyvalueImm16, SLOT_ID));
1949     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1950 
1951     GateRef acc = GetAccFromFrame(frame);
1952 
1953     AccessObjectStubBuilder builder(this);
1954     GateRef receiver = GetThisFromFrame(frame);
1955     GateRef result = builder.LoadObjByValue(glue, receiver, acc, profileTypeInfo, slotId, callback);
1956     CHECK_EXCEPTION_RETURN(result);
1957 }
1958 
GenerateCircuit()1959 void BaselineStthisbyvalueImm8V8StubBuilder::GenerateCircuit()
1960 {
1961     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStthisbyvalueImm8V8, GLUE));
1962     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStthisbyvalueImm8V8, SP));
1963     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStthisbyvalueImm8V8, SLOT_ID));
1964     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStthisbyvalueImm8V8, PROP_KEY));
1965     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1966 
1967     GateRef acc = GetAccFromFrame(frame);
1968     AccessObjectStubBuilder builder(this);
1969     GateRef receiver = GetThisFromFrame(frame);
1970     GateRef result = builder.StoreObjByValue(glue, receiver, propKey, acc, profileTypeInfo, slotId, callback);
1971     CHECK_EXCEPTION(result);
1972 }
1973 
GenerateCircuit()1974 void BaselineStthisbyvalueImm16V8StubBuilder::GenerateCircuit()
1975 {
1976     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStthisbyvalueImm16V8, GLUE));
1977     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStthisbyvalueImm16V8, SP));
1978     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStthisbyvalueImm16V8, SLOT_ID));
1979     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStthisbyvalueImm16V8, PROP_KEY));
1980     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
1981 
1982     GateRef acc = GetAccFromFrame(frame);
1983     AccessObjectStubBuilder builder(this);
1984     GateRef receiver = GetThisFromFrame(frame);
1985     GateRef result = builder.StoreObjByValue(glue, receiver, propKey, acc, profileTypeInfo, slotId, callback);
1986     CHECK_EXCEPTION(result);
1987 }
1988 
GenerateCircuit()1989 void BaselineDynamicimportStubBuilder::GenerateCircuit()
1990 {
1991     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDynamicimport, GLUE));
1992     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDynamicimport, SP));
1993 
1994     GateRef frame = GetFrame(sp);
1995     GateRef acc = GetAccFromFrame(frame);
1996     GateRef currentFunc = GetFunctionFromFrame(frame);
1997     GateRef res = CallRuntime(glue, RTSTUB_ID(DynamicImport), { acc, currentFunc });
1998     CHECK_EXCEPTION_WITH_ACC(res);
1999 }
2000 
GenerateCircuit()2001 void BaselineDefineclasswithbufferImm8Id16Id16Imm16V8StubBuilder::GenerateCircuit()
2002 {
2003     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefineclasswithbufferImm8Id16Id16Imm16V8, GLUE));
2004     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefineclasswithbufferImm8Id16Id16Imm16V8, SP));
2005     GateRef methodId = Int32Argument(PARAM_INDEX(BaselineDefineclasswithbufferImm8Id16Id16Imm16V8, METHOD_ID));
2006     GateRef literalId = Int32Argument(PARAM_INDEX(BaselineDefineclasswithbufferImm8Id16Id16Imm16V8, LITERRAL_ID));
2007     GateRef length = Int32Argument(PARAM_INDEX(BaselineDefineclasswithbufferImm8Id16Id16Imm16V8, LENGTH));
2008     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDefineclasswithbufferImm8Id16Id16Imm16V8, V0));
2009     ProfileOperation callback;
2010     GateRef proto = GetVregValue(sp, ZExtInt8ToPtr(v0));
2011 
2012     GateRef frame = GetFrame(sp);
2013     GateRef currentFunc = GetFunctionFromFrame(frame);
2014     GateRef method = GetMethodFromFunction(currentFunc);
2015     GateRef constpool = GetConstpoolFromMethod(method);
2016 
2017     auto env = GetEnvironment();
2018     GateRef lexicalEnv = GetEnvFromFrame(frame);
2019     GateRef module = GetModuleFromFunction(currentFunc);
2020     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateClassWithBuffer),
2021                               { proto, lexicalEnv, constpool,
2022                                 Int16ToTaggedInt(methodId),
2023                                 Int16ToTaggedInt(literalId), module,
2024                                 Int16ToTaggedInt(length)});
2025 
2026     Label isException(env);
2027     Label isNotException(env);
2028     Branch(TaggedIsException(res), &isException, &isNotException);
2029     Bind(&isException);
2030     {
2031         GateRef acc = GetAccFromFrame(frame);
2032         DISPATCH_LAST_WITH_ACC();
2033         Return(acc);
2034     }
2035     Bind(&isNotException);
2036     callback.ProfileDefineClass(res);
2037     Return(res);
2038 }
2039 
GenerateCircuit()2040 void BaselineDefineclasswithbufferImm16Id16Id16Imm16V8StubBuilder::GenerateCircuit()
2041 {
2042     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefineclasswithbufferImm16Id16Id16Imm16V8, GLUE));
2043     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefineclasswithbufferImm16Id16Id16Imm16V8, SP));
2044     GateRef methodLiteralId =
2045         Int32Argument(PARAM_INDEX(BaselineDefineclasswithbufferImm16Id16Id16Imm16V8, METHOD_LITERIAL_ID));
2046     GateRef lengthAndProtoId =
2047         Int32Argument(PARAM_INDEX(BaselineDefineclasswithbufferImm16Id16Id16Imm16V8, COUNT_SUPERCLASS_ID));
2048     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineDefineclasswithbufferImm16Id16Id16Imm16V8, SLOT_ID));
2049     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2050 
2051     GateRef methodId = Int32And(methodLiteralId, Int32(TWO_BYTE_ALL_ONE));
2052     GateRef literalId = Int32And(Int32LSR(methodLiteralId, Int32(TWO_BYTE_SIZE)), Int32(TWO_BYTE_ALL_ONE));
2053     GateRef length = Int32And(lengthAndProtoId, Int32(TWO_BYTE_SIZE));
2054     GateRef protoVregId = Int32And(Int32LSR(lengthAndProtoId, Int32(TWO_BYTE_SIZE)), Int32(TWO_BYTE_ALL_ONE));
2055     GateRef proto = GetVregValue(sp, ZExtInt32ToPtr(protoVregId));
2056 
2057     GateRef method = GetMethodFromFunction(curFunc);
2058     GateRef constpool = GetConstpoolFromMethod(method);
2059     auto env = GetEnvironment();
2060     GateRef lexicalEnv = GetEnvFromFrame(frame);
2061     GateRef module = GetModuleFromFunction(curFunc);
2062     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateClassWithBuffer),
2063                               { proto, lexicalEnv, constpool,
2064                                 IntToTaggedInt(methodId),
2065                                 IntToTaggedInt(literalId), module,
2066                                 IntToTaggedInt(length)});
2067     Label isException(env);
2068     Label isNotException(env);
2069     Branch(TaggedIsException(res), &isException, &isNotException);
2070     Bind(&isException);
2071     {
2072         GateRef acc = GetAccFromFrame(frame);
2073         DISPATCH_LAST_WITH_ACC();
2074         Return(res);
2075     }
2076     Bind(&isNotException);
2077     callback.ProfileDefineClass(res);
2078     Return(res);
2079 }
2080 
GenerateCircuit()2081 void BaselineResumegeneratorStubBuilder::GenerateCircuit()
2082 {
2083     GateRef glue = PtrArgument(PARAM_INDEX(BaselineResumegenerator, GLUE));
2084     GateRef sp = PtrArgument(PARAM_INDEX(BaselineResumegenerator, SP));
2085     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineResumegenerator, ACC));
2086     (void) sp;
2087     (void) glue;
2088 
2089     auto env = GetEnvironment();
2090     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
2091 
2092 #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
2093     GateRef frame = GetFrame(sp);
2094     GateRef curFunc = GetFunctionFromFrame(frame);
2095     CallNGCRuntime(glue, RTSTUB_ID(StartCallTimer), { glue, curFunc, False() });
2096 #endif
2097     Label isAsyncGeneratorObj(env);
2098     Label notAsyncGeneratorObj(env);
2099     Label dispatch(env);
2100     Branch(TaggedIsAsyncGeneratorObject(acc), &isAsyncGeneratorObj, &notAsyncGeneratorObj);
2101     Bind(&isAsyncGeneratorObj);
2102     {
2103         GateRef resumeResultOffset = IntPtr(JSAsyncGeneratorObject::GENERATOR_RESUME_RESULT_OFFSET);
2104         varAcc = Load(VariableType::JS_ANY(), acc, resumeResultOffset);
2105         Jump(&dispatch);
2106     }
2107     Bind(&notAsyncGeneratorObj);
2108     {
2109         GateRef resumeResultOffset = IntPtr(JSGeneratorObject::GENERATOR_RESUME_RESULT_OFFSET);
2110         varAcc = Load(VariableType::JS_ANY(), acc, resumeResultOffset);
2111         Jump(&dispatch);
2112     }
2113     Bind(&dispatch);
2114     Return(*varAcc);
2115 }
2116 
GenerateCircuit()2117 void BaselineGetresumemodStubBuilder::GenerateCircuit()
2118 {
2119     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineGetresumemod, ACC));
2120     auto env = GetEnvironment();
2121     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
2122 
2123     Label isAsyncGeneratorObj(env);
2124     Label notAsyncGeneratorObj(env);
2125     Label dispatch(env);
2126     Branch(TaggedIsAsyncGeneratorObject(acc), &isAsyncGeneratorObj, &notAsyncGeneratorObj);
2127     Bind(&isAsyncGeneratorObj);
2128     {
2129         varAcc = IntToTaggedPtr(GetResumeModeFromAsyncGeneratorObject(acc));
2130         Jump(&dispatch);
2131     }
2132     Bind(&notAsyncGeneratorObj);
2133     {
2134         varAcc = IntToTaggedPtr(GetResumeModeFromGeneratorObject(acc));
2135         Jump(&dispatch);
2136     }
2137     Bind(&dispatch);
2138     Return(*varAcc);
2139 }
2140 
GenerateCircuit()2141 void BaselineGettemplateobjectImm8StubBuilder::GenerateCircuit()
2142 {
2143     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGettemplateobjectImm8, GLUE));
2144     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGettemplateobjectImm8, SP));
2145     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineGettemplateobjectImm8, ACC));
2146 
2147     GateRef result = CallRuntime(glue, RTSTUB_ID(GetTemplateObject), { acc });
2148     CHECK_EXCEPTION_WITH_ACC(result);
2149 }
2150 
GenerateCircuit()2151 void BaselineGettemplateobjectImm16StubBuilder::GenerateCircuit()
2152 {
2153     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGettemplateobjectImm16, GLUE));
2154     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGettemplateobjectImm16, SP));
2155     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineGettemplateobjectImm16, ACC));
2156 
2157     GateRef literal = acc;
2158     GateRef result = CallRuntime(glue, RTSTUB_ID(GetTemplateObject), { literal });
2159     CHECK_EXCEPTION_WITH_ACC(result);
2160 }
2161 
GenerateCircuit()2162 void BaselineGetnextpropnameV8StubBuilder::GenerateCircuit()
2163 {
2164     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGetnextpropnameV8, GLUE));
2165     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGetnextpropnameV8, SP));
2166     GateRef iter = TaggedArgument(PARAM_INDEX(BaselineGetnextpropnameV8, ITER));
2167 
2168     GateRef frame = GetFrame(sp);
2169     GateRef acc = GetAccFromFrame(frame);
2170     GateRef result = NextInternal(glue, iter);
2171     CHECK_EXCEPTION_WITH_ACC(result);
2172 }
2173 
GenerateCircuit()2174 void BaselineSetobjectwithprotoImm8V8StubBuilder::GenerateCircuit()
2175 {
2176     GateRef glue = PtrArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm8V8, GLUE));
2177     GateRef sp = PtrArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm8V8, SP));
2178     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm8V8, ACC));
2179     GateRef proto = TaggedArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm8V8, PROTO));
2180 
2181     auto env = GetEnvironment();
2182 
2183     GateRef result = CallRuntime(glue, RTSTUB_ID(SetObjectWithProto), { proto, acc });
2184     Label notException(env);
2185     CHECK_EXCEPTION_WITH_JUMP(result, &notException);
2186     Bind(&notException);
2187     Return();
2188 }
2189 
GenerateCircuit()2190 void BaselineDelobjpropV8StubBuilder::GenerateCircuit()
2191 {
2192     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDelobjpropV8, GLUE));
2193     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDelobjpropV8, SP));
2194     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDelobjpropV8, ACC));
2195     GateRef obj = TaggedArgument(PARAM_INDEX(BaselineDelobjpropV8, OBJ));
2196 
2197     GateRef result = DeletePropertyOrThrow(glue, obj, acc);
2198     CHECK_EXCEPTION_WITH_ACC(result);
2199 }
2200 
GenerateCircuit()2201 void BaselineAsyncfunctionawaituncaughtV8StubBuilder::GenerateCircuit()
2202 {
2203     GateRef glue = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionawaituncaughtV8, GLUE));
2204     GateRef sp = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionawaituncaughtV8, SP));
2205     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineAsyncfunctionawaituncaughtV8, ACC));
2206     GateRef asyncFuncObj = TaggedArgument(PARAM_INDEX(BaselineAsyncfunctionawaituncaughtV8, ASYNC_FUNC_OBJ));
2207 
2208     GateRef result = CallRuntime(glue, RTSTUB_ID(AsyncFunctionAwaitUncaught), { asyncFuncObj, acc });
2209     CHECK_EXCEPTION_WITH_ACC(result);
2210 }
2211 
GenerateCircuit()2212 void BaselineCopydatapropertiesV8StubBuilder::GenerateCircuit()
2213 {
2214     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCopydatapropertiesV8, GLUE));
2215     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCopydatapropertiesV8, SP));
2216     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCopydatapropertiesV8, ACC));
2217     GateRef dst = TaggedArgument(PARAM_INDEX(BaselineCopydatapropertiesV8, DST));
2218 
2219     GateRef result = CallRuntime(glue, RTSTUB_ID(CopyDataProperties), { dst, acc });
2220     CHECK_EXCEPTION_WITH_ACC(result);
2221 }
2222 
GenerateCircuit()2223 void BaselineStarrayspreadV8V8StubBuilder::GenerateCircuit()
2224 {
2225     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStarrayspreadV8V8, GLUE));
2226     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStarrayspreadV8V8, SP));
2227     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStarrayspreadV8V8, ACC));
2228     GateRef dst = TaggedArgument(PARAM_INDEX(BaselineStarrayspreadV8V8, DST));
2229     GateRef index = TaggedArgument(PARAM_INDEX(BaselineStarrayspreadV8V8, INDEX));
2230 
2231     GateRef result = CallRuntime(glue, RTSTUB_ID(StArraySpread), { dst, index, acc }); // acc is res
2232     CHECK_EXCEPTION_WITH_ACC(result);
2233 }
2234 
GenerateCircuit()2235 void BaselineSetobjectwithprotoImm16V8StubBuilder::GenerateCircuit()
2236 {
2237     GateRef glue = PtrArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm16V8, GLUE));
2238     GateRef sp = PtrArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm16V8, SP));
2239     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm16V8, ACC));
2240     GateRef proto = TaggedArgument(PARAM_INDEX(BaselineSetobjectwithprotoImm16V8, PROTO));
2241 
2242     auto env = GetEnvironment();
2243 
2244     GateRef result = CallRuntime(glue, RTSTUB_ID(SetObjectWithProto), { proto, acc });
2245     Label notException(env);
2246     CHECK_EXCEPTION_WITH_JUMP(result, &notException);
2247     Bind(&notException);
2248     Return();
2249 }
2250 
GenerateCircuit()2251 void BaselineLdobjbyvalueImm8V8StubBuilder::GenerateCircuit()
2252 {
2253     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdobjbyvalueImm8V8, GLUE));
2254     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdobjbyvalueImm8V8, SP));
2255     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineLdobjbyvalueImm8V8, RECEIVER));
2256     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdobjbyvalueImm8V8, SLOTID));
2257     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2258 
2259     GateRef acc = GetAccFromFrame(frame);
2260     AccessObjectStubBuilder builder(this);
2261     GateRef result = builder.LoadObjByValue(glue, receiver, acc, profileTypeInfo, slotId, callback);
2262     CHECK_EXCEPTION_RETURN(result);
2263 }
2264 
GenerateCircuit()2265 void BaselineLdobjbyvalueImm16V8StubBuilder::GenerateCircuit()
2266 {
2267     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdobjbyvalueImm16V8, GLUE));
2268     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdobjbyvalueImm16V8, SP));
2269     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineLdobjbyvalueImm16V8, RECEIVER));
2270     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdobjbyvalueImm16V8, SLOTID));
2271     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2272 
2273     GateRef acc = GetAccFromFrame(frame);
2274     AccessObjectStubBuilder builder(this);
2275     GateRef result = builder.LoadObjByValue(glue, receiver, acc, profileTypeInfo, slotId, callback);
2276     CHECK_EXCEPTION_RETURN(result);
2277 }
2278 
GenerateCircuit()2279 void BaselineStobjbyvalueImm8V8V8StubBuilder::GenerateCircuit()
2280 {
2281     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStobjbyvalueImm8V8V8, GLUE));
2282     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStobjbyvalueImm8V8V8, SP));
2283     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStobjbyvalueImm8V8V8, RECEIVER));
2284     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStobjbyvalueImm8V8V8, SLOTID));
2285     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStobjbyvalueImm8V8V8, PROP_KEY));
2286     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2287 
2288     GateRef acc = GetAccFromFrame(frame);
2289     AccessObjectStubBuilder builder(this);
2290     GateRef result = builder.StoreObjByValue(glue, receiver, propKey, acc, profileTypeInfo, slotId, callback);
2291     CHECK_EXCEPTION(result);
2292 }
2293 
GenerateCircuit()2294 void BaselineStobjbyvalueImm16V8V8StubBuilder::GenerateCircuit()
2295 {
2296     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStobjbyvalueImm16V8V8, GLUE));
2297     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStobjbyvalueImm16V8V8, SP));
2298     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStobjbyvalueImm16V8V8, RECEIVER));
2299     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStobjbyvalueImm16V8V8, SLOTID));
2300     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStobjbyvalueImm16V8V8, PROP_KEY));
2301     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2302 
2303     GateRef acc = GetAccFromFrame(frame);
2304     AccessObjectStubBuilder builder(this);
2305     GateRef result = builder.StoreObjByValue(glue, receiver, propKey, acc, profileTypeInfo, slotId, callback);
2306     CHECK_EXCEPTION(result);
2307 }
2308 
GenerateCircuit()2309 void BaselineStownbyvalueImm8V8V8StubBuilder::GenerateCircuit()
2310 {
2311     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbyvalueImm8V8V8, GLUE));
2312     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbyvalueImm8V8V8, SP));
2313     GateRef receiverId = Int32Argument(PARAM_INDEX(BaselineStownbyvalueImm8V8V8, RECEIVER_ID));
2314     GateRef propKeyId = Int32Argument(PARAM_INDEX(BaselineStownbyvalueImm8V8V8, PROP_KEY_ID));
2315     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStownbyvalueImm8V8V8, SLOT_ID));
2316     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2317 
2318     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(receiverId));
2319     GateRef propKey = GetVregValue(sp, ZExtInt32ToPtr(propKeyId));
2320     GateRef acc = GetAccFromFrame(frame);
2321 
2322     auto env = GetEnvironment();
2323     Label isHeapObject(env);
2324     Label slowPath(env);
2325     Branch(TaggedIsHeapObject(receiver), &isHeapObject, &slowPath);
2326     Bind(&isHeapObject);
2327     Label notClassConstructor(env);
2328     Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
2329     Bind(&notClassConstructor);
2330     Label notClassPrototype(env);
2331     Branch(IsClassPrototype(receiver), &slowPath, &notClassPrototype);
2332     Bind(&notClassPrototype);
2333     {
2334         // fast path
2335         GateRef result = SetPropertyByValue(glue, receiver, propKey, acc, true, callback); // acc is value
2336         Label notHole(env);
2337         Branch(TaggedIsHole(result), &slowPath, &notHole);
2338         Bind(&notHole);
2339         CHECK_EXCEPTION(result);
2340     }
2341     Bind(&slowPath);
2342     {
2343         GateRef result = CallRuntime(glue, RTSTUB_ID(StOwnByValue), { receiver, propKey, acc });
2344         CHECK_EXCEPTION(result);
2345     }
2346 }
2347 
GenerateCircuit()2348 void BaselineStownbyvalueImm16V8V8StubBuilder::GenerateCircuit()
2349 {
2350     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbyvalueImm16V8V8, GLUE));
2351     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbyvalueImm16V8V8, SP));
2352     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStownbyvalueImm16V8V8, RECEIVER));
2353     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStownbyvalueImm16V8V8, PROP_KEY));
2354     GateRef slotId = TaggedArgument(PARAM_INDEX(BaselineStownbyvalueImm16V8V8, SLOT_ID));
2355     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2356 
2357     GateRef acc = GetAccFromFrame(frame);
2358     auto env = GetEnvironment();
2359     Label isHeapObject(env);
2360     Label slowPath(env);
2361     Branch(TaggedIsHeapObject(receiver), &isHeapObject, &slowPath);
2362     Bind(&isHeapObject);
2363     Label notClassConstructor(env);
2364     Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
2365     Bind(&notClassConstructor);
2366     Label notClassPrototype(env);
2367     Branch(IsClassPrototype(receiver), &slowPath, &notClassPrototype);
2368     Bind(&notClassPrototype);
2369     {
2370         // fast path
2371         GateRef result = SetPropertyByValue(glue, receiver, propKey, acc, true, callback); // acc is value
2372         Label notHole(env);
2373         Branch(TaggedIsHole(result), &slowPath, &notHole);
2374         Bind(&notHole);
2375         CHECK_EXCEPTION(result);
2376     }
2377     Bind(&slowPath);
2378     {
2379         GateRef result = CallRuntime(glue, RTSTUB_ID(StOwnByValue), { receiver, propKey, acc });
2380         CHECK_EXCEPTION(result);
2381     }
2382 }
2383 
GenerateCircuit()2384 void BaselineLdsuperbyvalueImm8V8StubBuilder::GenerateCircuit()
2385 {
2386     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm8V8, GLUE));
2387     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm8V8, SP));
2388     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm8V8, ACC));
2389     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm8V8, RECEIVER));
2390 
2391     GateRef result = CallRuntime(glue, RTSTUB_ID(LdSuperByValue), {  receiver, acc }); // sp for thisFunc
2392     CHECK_EXCEPTION_WITH_ACC(result);
2393 }
2394 
GenerateCircuit()2395 void BaselineLdsuperbyvalueImm16V8StubBuilder::GenerateCircuit()
2396 {
2397     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm16V8, GLUE));
2398     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm16V8, SP));
2399     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm16V8, ACC));
2400     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineLdsuperbyvalueImm16V8, RECEIVER));
2401 
2402     GateRef result = CallRuntime(glue, RTSTUB_ID(LdSuperByValue), {  receiver, acc }); // sp for thisFunc
2403     CHECK_EXCEPTION_WITH_ACC(result);
2404 }
2405 
GenerateCircuit()2406 void BaselineStsuperbyvalueImm8V8V8StubBuilder::GenerateCircuit()
2407 {
2408     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStsuperbyvalueImm8V8V8, GLUE));
2409     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStsuperbyvalueImm8V8V8, SP));
2410     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStsuperbyvalueImm8V8V8, RECEIVER));
2411     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStsuperbyvalueImm8V8V8, PROP_KEY));
2412     GateRef acc = GetAccFromFrame(GetFrame(sp));
2413     ProfileOperation callback;
2414 
2415     // acc is value, sp for thisFunc
2416     GateRef result = CallRuntime(glue, RTSTUB_ID(StSuperByValue), { receiver, propKey, acc });
2417     CHECK_EXCEPTION(result);
2418 }
2419 
GenerateCircuit()2420 void BaselineStsuperbyvalueImm16V8V8StubBuilder::GenerateCircuit()
2421 {
2422     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStsuperbyvalueImm16V8V8, GLUE));
2423     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStsuperbyvalueImm16V8V8, SP));
2424     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStsuperbyvalueImm16V8V8, RECEIVER));
2425     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStsuperbyvalueImm16V8V8, PROP_KEY));
2426     GateRef acc = GetAccFromFrame(GetFrame(sp));
2427     ProfileOperation callback;
2428 
2429     // acc is value, sp for thisFunc
2430     GateRef result = CallRuntime(glue, RTSTUB_ID(StSuperByValue), { receiver, propKey, acc });
2431     CHECK_EXCEPTION(result);
2432 }
2433 
GenerateCircuit()2434 void BaselineLdobjbyindexImm8Imm16StubBuilder::GenerateCircuit()
2435 {
2436     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdobjbyindexImm8Imm16, GLUE));
2437     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdobjbyindexImm8Imm16, SP));
2438     GateRef index = Int32Argument(PARAM_INDEX(BaselineLdobjbyindexImm8Imm16, INDEX));
2439     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdobjbyindexImm8Imm16, SLOT_ID));
2440     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2441 
2442     auto env = GetEnvironment();
2443     GateRef acc = GetAccFromFrame(frame);
2444     Label fastPath(env);
2445     Label slowPath(env);
2446     Branch(TaggedIsHeapObject(acc), &fastPath, &slowPath);
2447     Bind(&fastPath);
2448     {
2449         GateRef result = GetPropertyByIndex(glue, acc, index, callback);
2450         Label notHole(env);
2451         Branch(TaggedIsHole(result), &slowPath, &notHole);
2452         Bind(&notHole);
2453         CHECK_EXCEPTION_WITH_ACC(result);
2454     }
2455     Bind(&slowPath);
2456     {
2457         GateRef result = CallRuntime(glue, RTSTUB_ID(LdObjByIndex),
2458                                      { acc, IntToTaggedInt(index), TaggedFalse(), Undefined() });
2459         CHECK_EXCEPTION_WITH_ACC(result);
2460     }
2461 }
2462 
GenerateCircuit()2463 void BaselineLdobjbyindexImm16Imm16StubBuilder::GenerateCircuit()
2464 {
2465     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdobjbyindexImm16Imm16, GLUE));
2466     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdobjbyindexImm16Imm16, SP));
2467     GateRef index = Int32Argument(PARAM_INDEX(BaselineLdobjbyindexImm16Imm16, INDEX));
2468     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdobjbyindexImm16Imm16, SLOT_ID));
2469     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2470 
2471     auto env = GetEnvironment();
2472     GateRef acc = GetAccFromFrame(frame);
2473     Label fastPath(env);
2474     Label slowPath(env);
2475     Branch(TaggedIsHeapObject(acc), &fastPath, &slowPath);
2476     Bind(&fastPath);
2477     {
2478         GateRef result = GetPropertyByIndex(glue, acc, index, callback);
2479         Label notHole(env);
2480         Branch(TaggedIsHole(result), &slowPath, &notHole);
2481         Bind(&notHole);
2482         CHECK_EXCEPTION_WITH_ACC(result);
2483     }
2484     Bind(&slowPath);
2485     {
2486         GateRef result = CallRuntime(glue, RTSTUB_ID(LdObjByIndex),
2487                                      { acc, IntToTaggedInt(index), TaggedFalse(), Undefined() });
2488         CHECK_EXCEPTION_WITH_ACC(result);
2489     }
2490 }
2491 
GenerateCircuit()2492 void BaselineStobjbyindexImm8V8Imm16StubBuilder::GenerateCircuit()
2493 {
2494     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStobjbyindexImm8V8Imm16, GLUE));
2495     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStobjbyindexImm8V8Imm16, SP));
2496     GateRef receiver = Int32Argument(PARAM_INDEX(BaselineStobjbyindexImm8V8Imm16, RECEIVER));
2497     GateRef index = Int32Argument(PARAM_INDEX(BaselineStobjbyindexImm8V8Imm16, INDEX));
2498     GateRef acc = GetAccFromFrame(GetFrame(sp));
2499 
2500     auto env = GetEnvironment();
2501     Label fastPath(env);
2502     Label slowPath(env);
2503     Branch(TaggedIsHeapObject(receiver), &fastPath, &slowPath);
2504     Bind(&fastPath);
2505     {
2506         GateRef result = SetPropertyByIndex(glue, receiver, index, acc, false);
2507         Label notHole(env);
2508         Branch(TaggedIsHole(result), &slowPath, &notHole);
2509         Bind(&notHole);
2510         CHECK_EXCEPTION(result);
2511     }
2512     Bind(&slowPath);
2513     {
2514         GateRef result = CallRuntime(glue, RTSTUB_ID(StObjByIndex),
2515                                      { receiver, IntToTaggedInt(index), acc });
2516         CHECK_EXCEPTION(result);
2517     }
2518 }
2519 
GenerateCircuit()2520 void BaselineStobjbyindexImm16V8Imm16StubBuilder::GenerateCircuit()
2521 {
2522     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStobjbyindexImm16V8Imm16, GLUE));
2523     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStobjbyindexImm16V8Imm16, SP));
2524     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStobjbyindexImm16V8Imm16, RECEIVER));
2525     GateRef index = Int32Argument(PARAM_INDEX(BaselineStobjbyindexImm16V8Imm16, INDEX));
2526     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStobjbyindexImm16V8Imm16, SLOT_ID));
2527     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2528     GateRef acc = GetAccFromFrame(frame);
2529     auto env = GetEnvironment();
2530     Label fastPath(env);
2531     Label slowPath(env);
2532     Branch(TaggedIsHeapObject(receiver), &fastPath, &slowPath);
2533     Bind(&fastPath);
2534     {
2535         GateRef result = SetPropertyByIndex(glue, receiver, index, acc, false);
2536         Label notHole(env);
2537         Branch(TaggedIsHole(result), &slowPath, &notHole);
2538         Bind(&notHole);
2539         CHECK_EXCEPTION(result);
2540     }
2541     Bind(&slowPath);
2542     {
2543         GateRef result = CallRuntime(glue, RTSTUB_ID(StObjByIndex),
2544                                      { receiver, IntToTaggedInt(index), acc });
2545         CHECK_EXCEPTION(result);
2546     }
2547 }
2548 
GenerateCircuit()2549 void BaselineStownbyindexImm8V8Imm16StubBuilder::GenerateCircuit()
2550 {
2551     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbyindexImm8V8Imm16, GLUE));
2552     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbyindexImm8V8Imm16, SP));
2553     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStownbyindexImm8V8Imm16, ACC));
2554     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStownbyindexImm8V8Imm16, RECEIVER));
2555     GateRef index = Int32Argument(PARAM_INDEX(BaselineStownbyindexImm8V8Imm16, INDEX));
2556 
2557     auto env = GetEnvironment();
2558     Label isHeapObject(env);
2559     Label slowPath(env);
2560     Branch(TaggedIsHeapObject(receiver), &isHeapObject, &slowPath);
2561     Bind(&isHeapObject);
2562     Label notClassConstructor(env);
2563     Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
2564     Bind(&notClassConstructor);
2565     Label notClassPrototype(env);
2566     Branch(IsClassPrototype(receiver), &slowPath, &notClassPrototype);
2567     Bind(&notClassPrototype);
2568     {
2569         // fast path
2570         GateRef result = SetPropertyByIndex(glue, receiver, index, acc, true); // acc is value
2571         Label notHole(env);
2572         Branch(TaggedIsHole(result), &slowPath, &notHole);
2573         Bind(&notHole);
2574         CHECK_EXCEPTION(result);
2575     }
2576     Bind(&slowPath);
2577     {
2578         GateRef result = CallRuntime(glue, RTSTUB_ID(StOwnByIndex),
2579                                      { receiver, IntToTaggedInt(index), acc });
2580         CHECK_EXCEPTION(result);
2581     }
2582 }
2583 
GenerateCircuit()2584 void BaselineStownbyindexImm16V8Imm16StubBuilder::GenerateCircuit()
2585 {
2586     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbyindexImm16V8Imm16, GLUE));
2587     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbyindexImm16V8Imm16, SP));
2588     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStownbyindexImm16V8Imm16, ACC));
2589     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStownbyindexImm16V8Imm16, RECEIVER));
2590     GateRef index = Int32Argument(PARAM_INDEX(BaselineStownbyindexImm16V8Imm16, INDEX));
2591 
2592     auto env = GetEnvironment();
2593     Label isHeapObject(env);
2594     Label slowPath(env);
2595     BRANCH(TaggedIsHeapObject(receiver), &isHeapObject, &slowPath);
2596     Bind(&isHeapObject);
2597     Label notClassConstructor(env);
2598     BRANCH(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
2599     Bind(&notClassConstructor);
2600     Label notClassPrototype(env);
2601     BRANCH(IsClassPrototype(receiver), &slowPath, &notClassPrototype);
2602     Bind(&notClassPrototype);
2603     {
2604         // fast path
2605         GateRef result = SetPropertyByIndex(glue, receiver, index, acc, true); // acc is value
2606         Label notHole(env);
2607         BRANCH(TaggedIsHole(result), &slowPath, &notHole);
2608         Bind(&notHole);
2609         CHECK_EXCEPTION(result);
2610     }
2611     Bind(&slowPath);
2612     {
2613         GateRef result = CallRuntime(glue, RTSTUB_ID(StOwnByIndex),
2614                                      { receiver, IntToTaggedInt(index), acc });
2615         CHECK_EXCEPTION(result);
2616     }
2617 }
2618 
GenerateCircuit()2619 void BaselineAsyncfunctionresolveV8StubBuilder::GenerateCircuit()
2620 {
2621     GateRef glue = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionresolveV8, GLUE));
2622     GateRef sp = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionresolveV8, SP));
2623     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineAsyncfunctionresolveV8, ACC));
2624     GateRef asyncFuncObj = TaggedArgument(PARAM_INDEX(BaselineAsyncfunctionresolveV8, ASYNC_FUNC_OBJ));
2625 
2626     GateRef res = CallRuntime(glue, RTSTUB_ID(AsyncFunctionResolveOrReject),
2627                               { asyncFuncObj, acc, TaggedTrue() });
2628     CHECK_EXCEPTION_WITH_ACC(res);
2629 }
2630 
GenerateCircuit()2631 void BaselineAsyncfunctionrejectV8StubBuilder::GenerateCircuit()
2632 {
2633     GateRef glue = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionrejectV8, GLUE));
2634     GateRef sp = PtrArgument(PARAM_INDEX(BaselineAsyncfunctionrejectV8, SP));
2635     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineAsyncfunctionrejectV8, ACC));
2636     GateRef asyncFuncObj = TaggedArgument(PARAM_INDEX(BaselineAsyncfunctionrejectV8, ASYNC_FUNC_OBJ));
2637 
2638     GateRef res = CallRuntime(glue, RTSTUB_ID(AsyncFunctionResolveOrReject),
2639                               { asyncFuncObj, acc, TaggedFalse() });
2640     CHECK_EXCEPTION_WITH_ACC(res);
2641 }
2642 
GenerateCircuit()2643 void BaselineCopyrestargsImm8StubBuilder::GenerateCircuit()
2644 {
2645     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCopyrestargsImm8, GLUE));
2646     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCopyrestargsImm8, SP));
2647     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCopyrestargsImm8, ACC));
2648     GateRef restIdx = Int32Argument(PARAM_INDEX(BaselineCopyrestargsImm8, REST_IDX));
2649 
2650     DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
2651     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
2652     auto env = GetEnvironment();
2653     GateRef startIdxAndNumArgs = GetStartIdxAndNumArgs(sp, restIdx);
2654     GateRef startIdx = TruncInt64ToInt32(Int64LSR(startIdxAndNumArgs, Int64(32)));
2655     GateRef numArgs = TruncInt64ToInt32(startIdxAndNumArgs);
2656     Label dispatch(env);
2657     Label slowPath(env);
2658     GateRef glueGlobalEnvOffset = IntPtr(JSThread::GlueData::GetGlueGlobalEnvOffset(env->Is32Bit()));
2659     GateRef glueGlobalEnv = Load(VariableType::NATIVE_POINTER(), glue, glueGlobalEnvOffset);
2660     auto arrayFunc = GetGlobalEnvValue(VariableType::JS_ANY(), glueGlobalEnv, GlobalEnv::ARRAY_FUNCTION_INDEX);
2661     GateRef intialHClass = Load(VariableType::JS_ANY(), arrayFunc, IntPtr(JSFunction::PROTO_OR_DYNCLASS_OFFSET));
2662     NewObjectStubBuilder newBuilder(this);
2663     newBuilder.SetParameters(glue, 0);
2664     res = newBuilder.NewJSArrayWithSize(intialHClass, numArgs);
2665     GateRef lengthOffset = IntPtr(JSArray::LENGTH_OFFSET);
2666     Store(VariableType::INT32(), glue, *res, lengthOffset, TruncInt64ToInt32(numArgs));
2667     GateRef accessor = GetGlobalConstantValue(VariableType::JS_ANY(), glue, ConstantIndex::ARRAY_LENGTH_ACCESSOR);
2668     SetPropertyInlinedProps(glue, *res, intialHClass, accessor, Int32(JSArray::LENGTH_INLINE_PROPERTY_INDEX));
2669     SetExtensibleToBitfield(glue, *res, true);
2670     Label setArgumentsBegin(env);
2671     Label setArgumentsAgain(env);
2672     Label setArgumentsEnd(env);
2673     GateRef elements = GetElementsArray(*res);
2674     Branch(Int32UnsignedLessThan(*i, numArgs), &setArgumentsBegin, &setArgumentsEnd);
2675     LoopBegin(&setArgumentsBegin);
2676     {
2677         GateRef idx = ZExtInt32ToPtr(Int32Add(startIdx, *i));
2678         GateRef receiver = Load(VariableType::JS_ANY(), sp, PtrMul(IntPtr(sizeof(JSTaggedType)), idx));
2679         SetValueToTaggedArray(VariableType::JS_ANY(), glue, elements, *i, receiver);
2680         i = Int32Add(*i, Int32(1));
2681         Branch(Int32UnsignedLessThan(*i, numArgs), &setArgumentsAgain, &setArgumentsEnd);
2682         Bind(&setArgumentsAgain);
2683     }
2684     LoopEnd(&setArgumentsBegin);
2685     Bind(&setArgumentsEnd);
2686     Branch(HasPendingException(glue), &slowPath, &dispatch);
2687     Bind(&dispatch);
2688     {
2689         Return(*res);
2690     }
2691 
2692     Bind(&slowPath);
2693     {
2694         GateRef result2 = CallRuntime(glue, RTSTUB_ID(CopyRestArgs), { IntToTaggedInt(restIdx) });
2695         CHECK_EXCEPTION_WITH_ACC(result2);
2696     }
2697 }
2698 
GenerateCircuit()2699 void BaselineLdlexvarImm4Imm4StubBuilder::GenerateCircuit()
2700 {
2701     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdlexvarImm4Imm4, SP));
2702     GateRef level = Int32Argument(PARAM_INDEX(BaselineLdlexvarImm4Imm4, LEVEL));
2703     GateRef slot = Int32Argument(PARAM_INDEX(BaselineLdlexvarImm4Imm4, SLOT));
2704 
2705     auto env = GetEnvironment();
2706     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(GetFrame(sp)));
2707     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
2708 
2709     Label loopHead(env);
2710     Label loopEnd(env);
2711     Label afterLoop(env);
2712     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
2713     LoopBegin(&loopHead);
2714     currentEnv = GetParentEnv(*currentEnv);
2715     i = Int32Add(*i, Int32(1));
2716     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
2717     Bind(&loopEnd);
2718     LoopEnd(&loopHead);
2719     Bind(&afterLoop);
2720     GateRef variable = GetPropertiesFromLexicalEnv(*currentEnv, slot);
2721     Return(variable);
2722 }
2723 
GenerateCircuit()2724 void BaselineStlexvarImm4Imm4StubBuilder::GenerateCircuit()
2725 {
2726     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStlexvarImm4Imm4, GLUE));
2727     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStlexvarImm4Imm4, SP));
2728     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStlexvarImm4Imm4, ACC));
2729     GateRef level = Int32Argument(PARAM_INDEX(BaselineStlexvarImm4Imm4, LEVEL));
2730     GateRef slot = Int32Argument(PARAM_INDEX(BaselineStlexvarImm4Imm4, SLOT));
2731 
2732     auto env = GetEnvironment();
2733     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(GetFrame(sp)));
2734     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
2735 
2736     Label loopHead(env);
2737     Label loopEnd(env);
2738     Label afterLoop(env);
2739     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
2740     LoopBegin(&loopHead);
2741     currentEnv = GetParentEnv(*currentEnv);
2742     i = Int32Add(*i, Int32(1));
2743     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
2744     Bind(&loopEnd);
2745     LoopEnd(&loopHead);
2746     Bind(&afterLoop);
2747     SetPropertiesToLexicalEnv(glue, *currentEnv, slot, acc);
2748     Return();
2749 }
2750 
GenerateCircuit()2751 void BaselineGetmodulenamespaceImm8StubBuilder::GenerateCircuit()
2752 {
2753     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGetmodulenamespaceImm8, GLUE));
2754     GateRef index = Int32Argument(PARAM_INDEX(BaselineGetmodulenamespaceImm8, INDEX));
2755 
2756     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(GetModuleNamespaceByIndex), { IntToTaggedInt(index) });
2757     Return(moduleRef);
2758 }
2759 
GenerateCircuit()2760 void BaselineStmodulevarImm8StubBuilder::GenerateCircuit()
2761 {
2762     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStmodulevarImm8, GLUE));
2763     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStmodulevarImm8, ACC));
2764     GateRef index = Int32Argument(PARAM_INDEX(BaselineStmodulevarImm8, INDEX));
2765 
2766     CallRuntime(glue, RTSTUB_ID(StModuleVarByIndex), { IntToTaggedInt(index), acc });
2767     Return();
2768 }
2769 
GenerateCircuit()2770 void BaselineTryldglobalbynameImm16Id16StubBuilder::GenerateCircuit()
2771 {
2772     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTryldglobalbynameImm16Id16, GLUE));
2773     GateRef sp = PtrArgument(PARAM_INDEX(BaselineTryldglobalbynameImm16Id16, SP));
2774     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineTryldglobalbynameImm16Id16, SLOTID));
2775     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineTryldglobalbynameImm16Id16, STRING_ID));
2776     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2777 
2778     GateRef acc = GetAccFromFrame(frame);
2779     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
2780     GateRef method = GetMethodFromFunction(curFunc);
2781     GateRef constpool = GetConstpoolFromMethod(method);
2782     AccessObjectStubBuilder builder(this);
2783     StringIdInfo info(constpool, stringId);
2784     GateRef result = builder.TryLoadGlobalByName(glue, 0, info, profileTypeInfo, slotId, callback);
2785     CHECK_EXCEPTION_WITH_VARACC(result);
2786 }
2787 
GenerateCircuit()2788 void BaselineTrystglobalbynameImm8Id16StubBuilder::GenerateCircuit()
2789 {
2790     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTrystglobalbynameImm8Id16, GLUE));
2791     GateRef sp = PtrArgument(PARAM_INDEX(BaselineTrystglobalbynameImm8Id16, SP));
2792     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineTrystglobalbynameImm8Id16, STRING_ID));
2793     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineTrystglobalbynameImm8Id16, SLOTID));
2794     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2795 
2796     GateRef method = GetMethodFromFunction(curFunc);
2797     GateRef constpool = GetConstpoolFromMethod(method);
2798     GateRef acc = GetAccFromFrame(frame);
2799     AccessObjectStubBuilder builder(this);
2800     StringIdInfo info(constpool, stringId);
2801     GateRef result =
2802         builder.TryStoreGlobalByName(glue, 0, info, acc, profileTypeInfo, slotId, callback);
2803     CHECK_EXCEPTION(result);
2804 }
2805 
GenerateCircuit()2806 void BaselineTrystglobalbynameImm16Id16StubBuilder::GenerateCircuit()
2807 {
2808     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTrystglobalbynameImm16Id16, GLUE));
2809     GateRef sp = PtrArgument(PARAM_INDEX(BaselineTrystglobalbynameImm16Id16, SP));
2810     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineTrystglobalbynameImm16Id16, SLOTID));
2811     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineTrystglobalbynameImm16Id16, STRING_ID));
2812     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2813 
2814     GateRef method = GetMethodFromFunction(curFunc);
2815     GateRef constpool = GetConstpoolFromMethod(method);
2816     GateRef acc = GetAccFromFrame(frame);
2817     AccessObjectStubBuilder builder(this);
2818     StringIdInfo info(constpool, stringId);
2819     GateRef result =
2820         builder.TryStoreGlobalByName(glue, 0, info, acc, profileTypeInfo, slotId, callback);
2821     CHECK_EXCEPTION(result);
2822 }
2823 
GenerateCircuit()2824 void BaselineLdglobalvarImm16Id16StubBuilder::GenerateCircuit()
2825 {
2826     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdglobalvarImm16Id16, GLUE));
2827     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdglobalvarImm16Id16, SP));
2828     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdglobalvarImm16Id16, SLOTID));
2829     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdglobalvarImm16Id16, STRING_ID));
2830     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2831 
2832     GateRef acc = GetAccFromFrame(frame);
2833     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
2834     GateRef method = GetMethodFromFunction(curFunc);
2835     GateRef constpool = GetConstpoolFromMethod(method);
2836     AccessObjectStubBuilder builder(this);
2837     StringIdInfo info(constpool, stringId);
2838     GateRef result = builder.LoadGlobalVar(glue, 0, info, profileTypeInfo, slotId, callback);
2839     CHECK_EXCEPTION_WITH_VARACC(result);
2840 }
2841 
GenerateCircuit()2842 void BaselineStglobalvarImm16Id16StubBuilder::GenerateCircuit()
2843 {
2844     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStglobalvarImm16Id16, GLUE));
2845     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStglobalvarImm16Id16, SP));
2846     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStglobalvarImm16Id16, ACC));
2847     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStglobalvarImm16Id16, SLOTID));
2848     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStglobalvarImm16Id16, STRING_ID));
2849     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(GetFunctionFromFrame(GetFrame(sp)));
2850     ProfileOperation callback;
2851 
2852     GateRef frame = GetFrame(sp);
2853     GateRef func = GetFunctionFromFrame(frame);
2854     GateRef method = GetMethodFromFunction(func);
2855     GateRef constpool = GetConstpoolFromMethod(method);
2856     AccessObjectStubBuilder builder(this);
2857     StringIdInfo info(constpool, stringId);
2858     GateRef result = builder.StoreGlobalVar(glue, 0, info, acc, profileTypeInfo, slotId);
2859     CHECK_EXCEPTION(result);
2860 }
2861 
GenerateCircuit()2862 void BaselineLdobjbynameImm8Id16StubBuilder::GenerateCircuit()
2863 {
2864     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdobjbynameImm8Id16, GLUE));
2865     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdobjbynameImm8Id16, SP));
2866     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdobjbynameImm8Id16, SLOTID));
2867     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdobjbynameImm8Id16, STRING_ID));
2868     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2869 
2870     GateRef method = GetMethodFromFunction(curFunc);
2871     GateRef constpool = GetConstpoolFromMethod(method);
2872     GateRef receiver = GetAccFromFrame(frame);
2873     AccessObjectStubBuilder builder(this);
2874     StringIdInfo stringIdInfo(constpool, stringId);
2875     GateRef result = builder.LoadObjByName(glue, receiver, 0, stringIdInfo, profileTypeInfo, slotId, callback);
2876     CHECK_EXCEPTION_RETURN(result);
2877 }
2878 
GenerateCircuit()2879 void BaselineLdobjbynameImm16Id16StubBuilder::GenerateCircuit()
2880 {
2881     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdobjbynameImm16Id16, GLUE));
2882     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdobjbynameImm16Id16, SP));
2883     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineLdobjbynameImm16Id16, SLOTID));
2884     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdobjbynameImm16Id16, STRING_ID));
2885     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2886 
2887     GateRef method = GetMethodFromFunction(curFunc);
2888     GateRef constpool = GetConstpoolFromMethod(method);
2889     GateRef acc = GetAccFromFrame(frame);
2890     AccessObjectStubBuilder builder(this);
2891     StringIdInfo stringIdInfo(constpool, stringId);
2892     GateRef result = builder.LoadObjByName(glue, acc, 0, stringIdInfo, profileTypeInfo,
2893                                            slotId, callback);
2894     CHECK_EXCEPTION_RETURN(result);
2895 }
2896 
GenerateCircuit()2897 void BaselineStobjbynameImm8Id16V8StubBuilder::GenerateCircuit()
2898 {
2899     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStobjbynameImm8Id16V8, GLUE));
2900     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStobjbynameImm8Id16V8, SP));
2901     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStobjbynameImm8Id16V8, SLOTID));
2902     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStobjbynameImm8Id16V8, STRING_ID));
2903     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStobjbynameImm8Id16V8, RECEIVER));
2904     ProfileOperation callback;
2905 
2906     GateRef frame = GetFrame(sp);
2907     GateRef func = GetFunctionFromFrame(frame);
2908     GateRef method = GetMethodFromFunction(func);
2909     GateRef constpool = GetConstpoolFromMethod(method);
2910     GateRef acc = GetAccFromFrame(frame);
2911     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(func);
2912 
2913     AccessObjectStubBuilder builder(this);
2914     StringIdInfo stringIdInfo(constpool, stringId);
2915     GateRef result =
2916         builder.StoreObjByName(glue, receiver, 0, stringIdInfo, acc, profileTypeInfo, slotId, callback);
2917     CHECK_EXCEPTION(result);
2918 }
2919 
GenerateCircuit()2920 void BaselineStobjbynameImm16Id16V8StubBuilder::GenerateCircuit()
2921 {
2922     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStobjbynameImm16Id16V8, GLUE));
2923     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStobjbynameImm16Id16V8, SP));
2924     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStobjbynameImm16Id16V8, SLOTID));
2925     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStobjbynameImm16Id16V8, STRING_ID));
2926     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStobjbynameImm16Id16V8, RECEIVER));
2927     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2928 
2929     GateRef method = GetMethodFromFunction(curFunc);
2930     GateRef constpool = GetConstpoolFromMethod(method);
2931     GateRef acc = GetAccFromFrame(frame);
2932     AccessObjectStubBuilder builder(this);
2933     StringIdInfo stringIdInfo(constpool, stringId);
2934     GateRef result = builder.StoreObjByName(glue, receiver, 0, stringIdInfo, acc, profileTypeInfo,
2935                                             slotId, callback);
2936     CHECK_EXCEPTION(result);
2937 }
2938 
GenerateCircuit()2939 void BaselineStownbynameImm8Id16V8StubBuilder::GenerateCircuit()
2940 {
2941     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbynameImm8Id16V8, GLUE));
2942     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbynameImm8Id16V8, SP));
2943     GateRef receiverId = Int32Argument(PARAM_INDEX(BaselineStownbynameImm8Id16V8, RECEIVER_ID));
2944     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStownbynameImm8Id16V8, STRING_ID));
2945     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStownbynameImm8Id16V8, SLOT_ID));
2946     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2947 
2948     GateRef method = GetMethodFromFunction(curFunc);
2949     GateRef constpool = GetConstpoolFromMethod(method);
2950     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(receiverId));
2951     GateRef acc = GetAccFromFrame(frame);
2952     auto env = GetEnvironment();
2953     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
2954     DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
2955     Label checkResult(env);
2956 
2957     Label isJSObject(env);
2958     Label slowPath(env);
2959     Branch(IsJSObject(receiver), &isJSObject, &slowPath);
2960     Bind(&isJSObject);
2961     {
2962         Label notClassConstructor(env);
2963         Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
2964         Bind(&notClassConstructor);
2965         {
2966             Label fastPath(env);
2967             Branch(IsClassPrototype(receiver), &slowPath, &fastPath);
2968             Bind(&fastPath);
2969             {
2970                 result = SetPropertyByName(glue, receiver, propKey, acc, true, True(), callback);
2971                 Branch(TaggedIsHole(*result), &slowPath, &checkResult);
2972             }
2973         }
2974     }
2975     Bind(&slowPath);
2976     {
2977         result = CallRuntime(glue, RTSTUB_ID(StOwnByName), { receiver, propKey, acc });
2978         Jump(&checkResult);
2979     }
2980     Bind(&checkResult);
2981     {
2982         CHECK_EXCEPTION(*result);
2983     }
2984 }
2985 
GenerateCircuit()2986 void BaselineStownbynameImm16Id16V8StubBuilder::GenerateCircuit()
2987 {
2988     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbynameImm16Id16V8, GLUE));
2989     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbynameImm16Id16V8, SP));
2990     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStownbynameImm16Id16V8, RECEIVER));
2991     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStownbynameImm16Id16V8, STRING_ID));
2992     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStownbynameImm16Id16V8, SLOT_ID));
2993     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
2994 
2995     GateRef acc = GetAccFromFrame(frame);
2996     GateRef method = GetMethodFromFunction(curFunc);
2997     GateRef constpool = GetConstpoolFromMethod(method);
2998     auto env = GetEnvironment();
2999     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3000     DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
3001     Label checkResult(env);
3002 
3003     Label isJSObject(env);
3004     Label slowPath(env);
3005     Branch(IsJSObject(receiver), &isJSObject, &slowPath);
3006     Bind(&isJSObject);
3007     {
3008         Label notClassConstructor(env);
3009         Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
3010         Bind(&notClassConstructor);
3011         {
3012             Label fastPath(env);
3013             Branch(IsClassPrototype(receiver), &slowPath, &fastPath);
3014             Bind(&fastPath);
3015             {
3016                 result = SetPropertyByName(glue, receiver, propKey, acc, true, True(), callback);
3017                 Branch(TaggedIsHole(*result), &slowPath, &checkResult);
3018             }
3019         }
3020     }
3021     Bind(&slowPath);
3022     {
3023         result = CallRuntime(glue, RTSTUB_ID(StOwnByName), { receiver, propKey, acc });
3024         Jump(&checkResult);
3025     }
3026     Bind(&checkResult);
3027     {
3028         CHECK_EXCEPTION(*result);
3029     }
3030 }
3031 
GenerateCircuit()3032 void BaselineLdsuperbynameImm8Id16StubBuilder::GenerateCircuit()
3033 {
3034     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdsuperbynameImm8Id16, GLUE));
3035     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdsuperbynameImm8Id16, SP));
3036     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdsuperbynameImm8Id16, STRING_ID));
3037 
3038     GateRef frame = GetFrame(sp);
3039     GateRef acc = GetAccFromFrame(frame);
3040     GateRef func = GetFunctionFromFrame(frame);
3041     GateRef method = GetMethodFromFunction(func);
3042     GateRef constpool = GetConstpoolFromMethod(method);
3043     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3044     GateRef result = CallRuntime(glue, RTSTUB_ID(LdSuperByValue), { acc, propKey });
3045     CHECK_EXCEPTION_RETURN(result);
3046 }
3047 
GenerateCircuit()3048 void BaselineLdsuperbynameImm16Id16StubBuilder::GenerateCircuit()
3049 {
3050     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdsuperbynameImm16Id16, GLUE));
3051     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdsuperbynameImm16Id16, SP));
3052     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdsuperbynameImm16Id16, STRING_ID));
3053 
3054     GateRef frame = GetFrame(sp);
3055     GateRef acc = GetAccFromFrame(frame);
3056     GateRef func = GetFunctionFromFrame(frame);
3057     GateRef method = GetMethodFromFunction(func);
3058     GateRef constpool = GetConstpoolFromMethod(method);
3059     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3060     GateRef result = CallRuntime(glue, RTSTUB_ID(LdSuperByValue), { acc, propKey });
3061     CHECK_EXCEPTION_RETURN(result);
3062 }
3063 
GenerateCircuit()3064 void BaselineStsuperbynameImm8Id16V8StubBuilder::GenerateCircuit()
3065 {
3066     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStsuperbynameImm8Id16V8, GLUE));
3067     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStsuperbynameImm8Id16V8, SP));
3068     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStsuperbynameImm8Id16V8, ACC));
3069     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStsuperbynameImm8Id16V8, RECEIVER));
3070     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStsuperbynameImm8Id16V8, STRING_ID));
3071     ProfileOperation callback;
3072 
3073     GateRef func = GetFunctionFromFrame(GetFrame(sp));
3074     GateRef method = GetMethodFromFunction(func);
3075     GateRef constpool = GetConstpoolFromMethod(method);
3076     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3077     GateRef result = CallRuntime(glue, RTSTUB_ID(StSuperByValue), { receiver, propKey, acc });
3078     CHECK_EXCEPTION(result);
3079 }
3080 
GenerateCircuit()3081 void BaselineStsuperbynameImm16Id16V8StubBuilder::GenerateCircuit()
3082 {
3083     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStsuperbynameImm16Id16V8, GLUE));
3084     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStsuperbynameImm16Id16V8, SP));
3085     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStsuperbynameImm16Id16V8, ACC));
3086     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStsuperbynameImm16Id16V8, RECEIVER));
3087     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStsuperbynameImm16Id16V8, STRING_ID));
3088     ProfileOperation callback;
3089 
3090     GateRef func = GetFunctionFromFrame(GetFrame(sp));
3091     GateRef method = GetMethodFromFunction(func);
3092     GateRef constpool = GetConstpoolFromMethod(method);
3093     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3094     GateRef result = CallRuntime(glue, RTSTUB_ID(StSuperByValue), { receiver, propKey, acc });
3095     CHECK_EXCEPTION(result);
3096 }
3097 
GenerateCircuit()3098 void BaselineLdlocalmodulevarImm8StubBuilder::GenerateCircuit()
3099 {
3100     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdlocalmodulevarImm8, GLUE));
3101     GateRef index = Int32Argument(PARAM_INDEX(BaselineLdlocalmodulevarImm8, INDEX));
3102 
3103     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(LdLocalModuleVarByIndex), { Int8ToTaggedInt(index) });
3104     Return(moduleRef);
3105 }
3106 
GenerateCircuit()3107 void BaselineStconsttoglobalrecordImm16Id16StubBuilder::GenerateCircuit()
3108 {
3109     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStconsttoglobalrecordImm16Id16, GLUE));
3110     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStconsttoglobalrecordImm16Id16, SP));
3111     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStconsttoglobalrecordImm16Id16, ACC));
3112     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStconsttoglobalrecordImm16Id16, STRING_ID));
3113 
3114     GateRef func = GetFunctionFromFrame(GetFrame(sp));
3115     GateRef method = GetMethodFromFunction(func);
3116     GateRef constpool = GetConstpoolFromMethod(method);
3117     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3118     GateRef result = CallRuntime(glue, RTSTUB_ID(StGlobalRecord),
3119                                  { propKey, acc, TaggedTrue() });
3120     CHECK_EXCEPTION(result);
3121 }
3122 
GenerateCircuit()3123 void BaselineStownbyvaluewithnamesetImm8V8V8StubBuilder::GenerateCircuit()
3124 {
3125     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm8V8V8, GLUE));
3126     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm8V8V8, SP));
3127     GateRef receiverId = Int32Argument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm8V8V8, RECEIVER_ID));
3128     GateRef propKeyId = Int32Argument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm8V8V8, PROP_KEY_ID));
3129     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm8V8V8, SLOT_ID));
3130     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
3131     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(receiverId));
3132     GateRef propKey = GetVregValue(sp, ZExtInt32ToPtr(propKeyId));
3133     GateRef acc = GetAccFromFrame(frame);
3134 
3135     auto env = GetEnvironment();
3136     Label isHeapObject(env);
3137     Label slowPath(env);
3138     Label notClassConstructor(env);
3139     Label notClassPrototype(env);
3140     Label notHole(env);
3141     Label notException(env);
3142     Label notException1(env);
3143     Branch(TaggedIsHeapObject(receiver), &isHeapObject, &slowPath);
3144     Bind(&isHeapObject);
3145     {
3146         Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
3147         Bind(&notClassConstructor);
3148         {
3149             Branch(IsClassPrototype(receiver), &slowPath, &notClassPrototype);
3150             Bind(&notClassPrototype);
3151             {
3152                 GateRef res = SetPropertyByValue(glue, receiver, propKey, acc, true, callback);
3153                 Branch(TaggedIsHole(res), &slowPath, &notHole);
3154                 Bind(&notHole);
3155                 {
3156                     CHECK_EXCEPTION_WITH_JUMP(res, &notException);
3157                     Bind(&notException);
3158                     CallRuntime(glue, RTSTUB_ID(SetFunctionNameNoPrefix), { acc, propKey });
3159                     Return();
3160                 }
3161             }
3162         }
3163     }
3164     Bind(&slowPath);
3165     {
3166         GateRef res = CallRuntime(glue, RTSTUB_ID(StOwnByValueWithNameSet), { receiver, propKey, acc });
3167         CHECK_EXCEPTION_WITH_JUMP(res, &notException1);
3168         Bind(&notException1);
3169         Return();
3170     }
3171 }
3172 
GenerateCircuit()3173 void BaselineStownbyvaluewithnamesetImm16V8V8StubBuilder::GenerateCircuit()
3174 {
3175     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm16V8V8, GLUE));
3176     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm16V8V8, SP));
3177     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm16V8V8, RECEIVER));
3178     GateRef propKey = TaggedArgument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm16V8V8, PROP_KEY));
3179     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStownbyvaluewithnamesetImm16V8V8, SLOT_ID));
3180     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
3181 
3182     GateRef acc = GetAccFromFrame(frame);
3183     auto env = GetEnvironment();
3184     Label isHeapObject(env);
3185     Label slowPath(env);
3186     Label notClassConstructor(env);
3187     Label notClassPrototype(env);
3188     Label notHole(env);
3189     Label notException(env);
3190     Label notException1(env);
3191     Branch(TaggedIsHeapObject(receiver), &isHeapObject, &slowPath);
3192     Bind(&isHeapObject);
3193     {
3194         Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
3195         Bind(&notClassConstructor);
3196         {
3197             Branch(IsClassPrototype(receiver), &slowPath, &notClassPrototype);
3198             Bind(&notClassPrototype);
3199             {
3200                 GateRef res = SetPropertyByValue(glue, receiver, propKey, acc, true, callback);
3201                 Branch(TaggedIsHole(res), &slowPath, &notHole);
3202                 Bind(&notHole);
3203                 {
3204                     CHECK_EXCEPTION_WITH_JUMP(res, &notException);
3205                     Bind(&notException);
3206                     CallRuntime(glue, RTSTUB_ID(SetFunctionNameNoPrefix), { acc, propKey });
3207                     Return();
3208                 }
3209             }
3210         }
3211     }
3212     Bind(&slowPath);
3213     {
3214         GateRef res = CallRuntime(glue, RTSTUB_ID(StOwnByValueWithNameSet), { receiver, propKey, acc });
3215         CHECK_EXCEPTION_WITH_JUMP(res, &notException1);
3216         Bind(&notException1);
3217         Return();
3218     }
3219 }
3220 
GenerateCircuit()3221 void BaselineStownbynamewithnamesetImm8Id16V8StubBuilder::GenerateCircuit()
3222 {
3223     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbynamewithnamesetImm8Id16V8, GLUE));
3224     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbynamewithnamesetImm8Id16V8, SP));
3225     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStownbynamewithnamesetImm8Id16V8, STRING_ID));
3226     GateRef receiverId = Int32Argument(PARAM_INDEX(BaselineStownbynamewithnamesetImm8Id16V8, RECEIVER_ID));
3227     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStownbynamewithnamesetImm8Id16V8, SLOT_ID));
3228     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
3229 
3230     GateRef method = GetMethodFromFunction(curFunc);
3231     GateRef constpool = GetConstpoolFromMethod(method);
3232     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(receiverId));
3233     GateRef acc = GetAccFromFrame(frame);
3234     auto env = GetEnvironment();
3235     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3236     Label isJSObject(env);
3237     Label notJSObject(env);
3238     Label notClassConstructor(env);
3239     Label notClassPrototype(env);
3240     Label notHole(env);
3241     Label notException(env);
3242     Label notException1(env);
3243     Branch(IsJSObject(receiver), &isJSObject, &notJSObject);
3244     Bind(&isJSObject);
3245     {
3246         Branch(IsClassConstructor(receiver), &notJSObject, &notClassConstructor);
3247         Bind(&notClassConstructor);
3248         {
3249             Branch(IsClassPrototype(receiver), &notJSObject, &notClassPrototype);
3250             Bind(&notClassPrototype);
3251             {
3252                 GateRef res = SetPropertyByName(glue, receiver, propKey, acc, true, True(), callback);
3253                 Branch(TaggedIsHole(res), &notJSObject, &notHole);
3254                 Bind(&notHole);
3255                 {
3256                     CHECK_EXCEPTION_WITH_JUMP(res, &notException);
3257                     Bind(&notException);
3258                     CallRuntime(glue, RTSTUB_ID(SetFunctionNameNoPrefix), { acc, propKey });
3259                     Return();
3260                 }
3261             }
3262         }
3263     }
3264     Bind(&notJSObject);
3265     {
3266         GateRef res = CallRuntime(glue, RTSTUB_ID(StOwnByNameWithNameSet), { receiver, propKey, acc });
3267         CHECK_EXCEPTION_WITH_JUMP(res, &notException1);
3268         Bind(&notException1);
3269         Return();
3270     }
3271 }
3272 
GenerateCircuit()3273 void BaselineStownbynamewithnamesetImm16Id16V8StubBuilder::GenerateCircuit()
3274 {
3275     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStownbynamewithnamesetImm16Id16V8, GLUE));
3276     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStownbynamewithnamesetImm16Id16V8, SP));
3277     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineStownbynamewithnamesetImm16Id16V8, STRING_ID));
3278     GateRef receiver = TaggedArgument(PARAM_INDEX(BaselineStownbynamewithnamesetImm16Id16V8, RECEIVER));
3279     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineStownbynamewithnamesetImm16Id16V8, SLOT_ID));
3280     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
3281 
3282     GateRef acc = GetAccFromFrame(frame);
3283     GateRef method = GetMethodFromFunction(curFunc);
3284     GateRef constpool = GetConstpoolFromMethod(method);
3285     auto env = GetEnvironment();
3286     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
3287     Label isJSObject(env);
3288     Label notJSObject(env);
3289     Label notClassConstructor(env);
3290     Label notClassPrototype(env);
3291     Label notHole(env);
3292     Label notException(env);
3293     Label notException1(env);
3294     Branch(IsJSObject(receiver), &isJSObject, &notJSObject);
3295     Bind(&isJSObject);
3296     {
3297         Branch(IsClassConstructor(receiver), &notJSObject, &notClassConstructor);
3298         Bind(&notClassConstructor);
3299         {
3300             Branch(IsClassPrototype(receiver), &notJSObject, &notClassPrototype);
3301             Bind(&notClassPrototype);
3302             {
3303                 GateRef res = SetPropertyByName(glue, receiver, propKey, acc, true, True(), callback);
3304                 Branch(TaggedIsHole(res), &notJSObject, &notHole);
3305                 Bind(&notHole);
3306                 {
3307                     CHECK_EXCEPTION_WITH_JUMP(res, &notException);
3308                     Bind(&notException);
3309                     CallRuntime(glue, RTSTUB_ID(SetFunctionNameNoPrefix), { acc, propKey });
3310                     Return();
3311                 }
3312             }
3313         }
3314     }
3315     Bind(&notJSObject);
3316     {
3317         GateRef res = CallRuntime(glue, RTSTUB_ID(StOwnByNameWithNameSet), { receiver, propKey, acc });
3318         CHECK_EXCEPTION_WITH_JUMP(res, &notException1);
3319         Bind(&notException1);
3320         Return();
3321     }
3322 }
3323 
GenerateCircuit()3324 void BaselineLdbigintId16StubBuilder::GenerateCircuit()
3325 {
3326     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdbigintId16, GLUE));
3327     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdbigintId16, SP));
3328     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineLdbigintId16, STRING_ID));
3329 
3330     GateRef frame = GetFrame(sp);
3331     GateRef acc = GetAccFromFrame(frame);
3332     GateRef func = GetFunctionFromFrame(frame);
3333     GateRef method = GetMethodFromFunction(func);
3334     GateRef constpool = GetConstpoolFromMethod(method);
3335     GateRef numberBigInt = GetStringFromConstPool(glue, constpool, stringId);
3336     GateRef res = CallRuntime(glue, RTSTUB_ID(LdBigInt), { numberBigInt });
3337     CHECK_EXCEPTION_WITH_ACC(res);
3338 }
3339 
GenerateCircuit()3340 void BaselineFldaiImm64StubBuilder::GenerateCircuit()
3341 {
3342     GateRef imm = CastInt64ToFloat64(Int64Argument(PARAM_INDEX(BaselineFldaiImm64, IMM)));
3343 
3344     GateRef result = DoubleToTaggedDoublePtr(imm);
3345     Return(result);
3346 }
3347 
GenerateCircuit()3348 void BaselineReturnStubBuilder::GenerateCircuit()
3349 {
3350     GateRef glue = PtrArgument(PARAM_INDEX(BaselineReturn, GLUE));
3351     GateRef sp = PtrArgument(PARAM_INDEX(BaselineReturn, SP));
3352     GateRef curPcOffset = Int32Argument(PARAM_INDEX(BaselineReturn, OFFSET));
3353 
3354     DEFVARIABLE(varSp, VariableType::NATIVE_POINTER(), sp);
3355     GateRef frame = GetFrame(*varSp);
3356     GateRef acc = GetAccFromFrame(frame);
3357 
3358     auto env = GetEnvironment();
3359     GateRef pc = GetPcFromFrame(frame);
3360     GateRef curFunction = GetFunctionFromFrame(frame);
3361     GateRef curMethod =
3362         Load(VariableType::JS_ANY(), curFunction, IntPtr(JSFunctionBase::METHOD_OFFSET));
3363     GateRef constpool =
3364         Load(VariableType::JS_POINTER(), curMethod, IntPtr(Method::CONSTANT_POOL_OFFSET));
3365     GateRef raw =
3366         Load(VariableType::JS_POINTER(), curFunction, IntPtr(JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET));
3367     GateRef profileTypeInfo =
3368         Load(VariableType::JS_POINTER(), raw, IntPtr(ProfileTypeInfoCell::VALUE_OFFSET));
3369     GateRef hotnessCounter =
3370         Load(VariableType::INT32(), curMethod, IntPtr(Method::LITERAL_INFO_OFFSET));
3371     ProfileOperation callback;
3372 
3373     DEFVARIABLE(varPc, VariableType::NATIVE_POINTER(), pc);
3374     DEFVARIABLE(prevState, VariableType::NATIVE_POINTER(), sp);
3375     DEFVARIABLE(varConstpool, VariableType::JS_POINTER(), constpool);
3376     DEFVARIABLE(varProfileTypeInfo, VariableType::JS_POINTER(), profileTypeInfo);
3377     DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter);
3378 
3379     Label isBaselineBuiltinFrame(env);
3380     Label notBaselineBuiltinFrame(env);
3381     Label pcEqualNullptr(env);
3382     Label pcNotEqualNullptr(env);
3383     Label pcEqualBaseline(env);
3384     Label pcNotEqualBaseline(env);
3385     Label updateHotness(env);
3386     Label isStable(env);
3387     Label tryContinue(env);
3388     Label dispatch(env);
3389     Label slowPath(env);
3390 
3391     BRANCH(TaggedIsUndefined(*varProfileTypeInfo), &updateHotness, &isStable);
3392     Bind(&isStable);
3393     {
3394         GateRef varProfileTypeInfoVal = *varProfileTypeInfo;
3395         GateRef isProfileDumpedAndJitCompiled = LogicAndBuilder(env)
3396             .And(ProfilerStubBuilder(env).IsProfileTypeInfoDumped(varProfileTypeInfoVal, callback))
3397             .And(ProfilerStubBuilder(env).IsCompiledOrTryCompile(
3398                 glue, GetFunctionFromFrame(frame), varProfileTypeInfoVal, callback))
3399             .Done();
3400         BRANCH(isProfileDumpedAndJitCompiled, &tryContinue, &updateHotness);
3401     }
3402     Bind(&updateHotness);
3403     {
3404         GateRef offset = Int32Not(curPcOffset);
3405         UPDATE_HOTNESS(*varSp, callback);
3406         SetHotnessCounter(glue, curMethod, *varHotnessCounter);
3407         Jump(&tryContinue);
3408     }
3409 
3410     Bind(&tryContinue);
3411 
3412     GateRef currentSp = *varSp;
3413     varSp = Load(VariableType::NATIVE_POINTER(), frame,
3414                  IntPtr(AsmInterpretedFrame::GetBaseOffset(env->IsArch32Bit())));
3415 
3416     GateRef typePos = PtrSub(*varSp, IntPtr(JSTaggedValue::TaggedTypeSize()));
3417     GateRef maybeFrameType = Load(VariableType::INT64(), typePos);
3418     BRANCH(Int64Equal(maybeFrameType, Int64(static_cast<int64_t>(FrameType::BASELINE_BUILTIN_FRAME))),
3419            &isBaselineBuiltinFrame, &notBaselineBuiltinFrame);
3420     Bind(&isBaselineBuiltinFrame);
3421     {
3422         varSp = Load(VariableType::NATIVE_POINTER(), *varSp);
3423         Jump(&notBaselineBuiltinFrame);
3424     }
3425     Bind(&notBaselineBuiltinFrame);
3426     prevState = GetFrame(*varSp);
3427     varPc = GetPcFromFrame(*prevState);
3428     Branch(IntPtrEqual(*varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr);
3429     Bind(&pcEqualNullptr);
3430     {
3431         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { acc, *varSp, currentSp });
3432         Return();
3433     }
3434     Bind(&pcNotEqualNullptr);
3435     BRANCH(IntPtrEqual(*varPc, IntPtr(BASELINEJIT_PC_FLAG)), &pcEqualBaseline, &pcNotEqualBaseline);
3436     Bind(&pcEqualBaseline);
3437     {
3438         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
3439         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturnBaseline), { acc, *varSp, currentSp, jumpSize });
3440         Return();
3441     }
3442     Bind(&pcNotEqualBaseline);
3443     {
3444         GateRef function = GetFunctionFromFrame(*prevState);
3445         GateRef method = Load(VariableType::JS_ANY(), function, IntPtr(JSFunctionBase::METHOD_OFFSET));
3446         varConstpool = GetConstpoolFromMethod(method);
3447         varProfileTypeInfo = GetProfileTypeInfoFromFunction(function);
3448         varHotnessCounter = GetHotnessCounterFromMethod(method);
3449         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
3450         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch),
3451                        { glue, currentSp, *varPc, *varConstpool, *varProfileTypeInfo,
3452                          acc, *varHotnessCounter, jumpSize });
3453         Return();
3454     }
3455 }
3456 
GenerateCircuit()3457 void BaselineLdlexvarImm8Imm8StubBuilder::GenerateCircuit()
3458 {
3459     GateRef level = Int32Argument(PARAM_INDEX(BaselineLdlexvarImm8Imm8, LEVEL));
3460     GateRef slot = Int32Argument(PARAM_INDEX(BaselineLdlexvarImm8Imm8, SLOT));
3461     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdlexvarImm8Imm8, SP));
3462 
3463     auto env = GetEnvironment();
3464     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(GetFrame(sp)));
3465     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
3466 
3467     Label loopHead(env);
3468     Label loopEnd(env);
3469     Label afterLoop(env);
3470     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
3471     LoopBegin(&loopHead);
3472     currentEnv = GetParentEnv(*currentEnv);
3473     i = Int32Add(*i, Int32(1));
3474     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
3475     Bind(&loopEnd);
3476     LoopEnd(&loopHead);
3477     Bind(&afterLoop);
3478     GateRef variable = GetPropertiesFromLexicalEnv(*currentEnv, slot);
3479     Return(variable);
3480 }
3481 
GenerateCircuit()3482 void BaselineStlexvarImm8Imm8StubBuilder::GenerateCircuit()
3483 {
3484     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStlexvarImm8Imm8, GLUE));
3485     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineStlexvarImm8Imm8, ACC));
3486     GateRef level = Int32Argument(PARAM_INDEX(BaselineStlexvarImm8Imm8, LEVEL));
3487     GateRef slot = Int32Argument(PARAM_INDEX(BaselineStlexvarImm8Imm8, SLOT));
3488     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStlexvarImm8Imm8, SP));
3489 
3490     auto env = GetEnvironment();
3491     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(GetFrame(sp)));
3492     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
3493 
3494     Label loopHead(env);
3495     Label loopEnd(env);
3496     Label afterLoop(env);
3497     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
3498     LoopBegin(&loopHead);
3499     currentEnv = GetParentEnv(*currentEnv);
3500     i = Int32Add(*i, Int32(1));
3501     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
3502     Bind(&loopEnd);
3503     LoopEnd(&loopHead);
3504     Bind(&afterLoop);
3505     SetPropertiesToLexicalEnv(glue, *currentEnv, slot, acc);
3506     Return();
3507 }
3508 
3509 // GLUE
GenerateCircuit()3510 void BaselineJnstricteqV8Imm16StubBuilder::GenerateCircuit()
3511 {
3512     Return();
3513 }
3514 
GenerateCircuit()3515 void BaselineAsyncgeneratorrejectV8StubBuilder::GenerateCircuit()
3516 {
3517     GateRef glue = PtrArgument(PARAM_INDEX(BaselineAsyncgeneratorrejectV8, GLUE));
3518     GateRef sp = PtrArgument(PARAM_INDEX(BaselineAsyncgeneratorrejectV8, SP));
3519     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineAsyncgeneratorrejectV8, ACC));
3520     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineAsyncgeneratorrejectV8, V0));
3521     GateRef asyncGenerator = GetVregValue(sp, ZExtInt8ToPtr(v0));
3522 
3523     GateRef result = CallRuntime(glue, RTSTUB_ID(AsyncGeneratorReject),
3524                                  { asyncGenerator, acc });
3525     CHECK_EXCEPTION_RETURN(result);
3526 }
3527 
GenerateCircuit()3528 void BaselineSetgeneratorstateImm8StubBuilder::GenerateCircuit()
3529 {
3530     GateRef glue = PtrArgument(PARAM_INDEX(BaselineSetgeneratorstateImm8, GLUE));
3531     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineSetgeneratorstateImm8, ACC));
3532     GateRef index = Int32Argument(PARAM_INDEX(BaselineSetgeneratorstateImm8, INDEX));
3533 
3534     CallRuntime(glue, RTSTUB_ID(SetGeneratorState), { acc, IntToTaggedInt(index) });
3535     Return();
3536 }
3537 
GenerateCircuit()3538 void BaselineGetasynciteratorImm8StubBuilder::GenerateCircuit()
3539 {
3540     GateRef glue = PtrArgument(PARAM_INDEX(BaselineGetasynciteratorImm8, GLUE));
3541     GateRef sp = PtrArgument(PARAM_INDEX(BaselineGetasynciteratorImm8, SP));
3542     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineGetasynciteratorImm8, ACC));
3543 
3544     GateRef res = CallRuntime(glue, RTSTUB_ID(GetAsyncIterator), { acc });
3545     CHECK_PENDING_EXCEPTION(res);
3546 }
3547 
GenerateCircuit()3548 void BaselineLdPrivatePropertyImm8Imm16Imm16StubBuilder::GenerateCircuit()
3549 {
3550     GateRef glue = PtrArgument(PARAM_INDEX(BaselineLdPrivatePropertyImm8Imm16Imm16, GLUE));
3551     GateRef sp = PtrArgument(PARAM_INDEX(BaselineLdPrivatePropertyImm8Imm16Imm16, SP));
3552     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineLdPrivatePropertyImm8Imm16Imm16, ACC));
3553     GateRef levelIndex = Int32Argument(PARAM_INDEX(BaselineLdPrivatePropertyImm8Imm16Imm16, INDEX0));
3554     GateRef slotIndex = Int32Argument(PARAM_INDEX(BaselineLdPrivatePropertyImm8Imm16Imm16, INDEX1));
3555     GateRef lexicalEnv = TaggedPointerArgument(PARAM_INDEX(BaselineLdPrivatePropertyImm8Imm16Imm16, ENV));
3556 
3557     GateRef res = CallRuntime(glue, RTSTUB_ID(LdPrivateProperty), {lexicalEnv,
3558         IntToTaggedInt(levelIndex), IntToTaggedInt(slotIndex), acc});  // acc as obj
3559     CHECK_EXCEPTION_WITH_ACC(res);
3560 }
3561 
GenerateCircuit()3562 void BaselineStPrivatePropertyImm8Imm16Imm16V8StubBuilder::GenerateCircuit()
3563 {
3564     GateRef glue = PtrArgument(PARAM_INDEX(BaselineStPrivatePropertyImm8Imm16Imm16V8, GLUE));
3565     GateRef sp = PtrArgument(PARAM_INDEX(BaselineStPrivatePropertyImm8Imm16Imm16V8, SP));
3566     GateRef levelIndex = Int32Argument(PARAM_INDEX(BaselineStPrivatePropertyImm8Imm16Imm16V8, INDEX0));
3567     GateRef slotIndex = Int32Argument(PARAM_INDEX(BaselineStPrivatePropertyImm8Imm16Imm16V8, INDEX1));
3568     GateRef index3 = Int32Argument(PARAM_INDEX(BaselineStPrivatePropertyImm8Imm16Imm16V8, INDEX2));
3569     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(index3));
3570 
3571     GateRef frame = GetFrame(sp);
3572     GateRef acc = GetAccFromFrame(frame);
3573     GateRef lexicalEnv = GetEnvFromFrame(frame);
3574 
3575     GateRef res = CallRuntime(glue, RTSTUB_ID(StPrivateProperty), {lexicalEnv,
3576         IntToTaggedInt(levelIndex), IntToTaggedInt(slotIndex), obj, acc});  // acc as value
3577     CHECK_EXCEPTION_WITH_ACC(res);
3578 }
3579 
GenerateCircuit()3580 void BaselineTestInImm8Imm16Imm16StubBuilder::GenerateCircuit()
3581 {
3582     GateRef glue = PtrArgument(PARAM_INDEX(BaselineTestInImm8Imm16Imm16, GLUE));
3583     GateRef sp = PtrArgument(PARAM_INDEX(BaselineTestInImm8Imm16Imm16, SP));
3584     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineTestInImm8Imm16Imm16, ACC));
3585     GateRef levelIndex = Int32Argument(PARAM_INDEX(BaselineTestInImm8Imm16Imm16, INDEX0));
3586     GateRef slotIndex = Int32Argument(PARAM_INDEX(BaselineTestInImm8Imm16Imm16, INDEX1));
3587     GateRef lexicalEnv = TaggedPointerArgument(PARAM_INDEX(BaselineTestInImm8Imm16Imm16, ENV));
3588 
3589     GateRef res = CallRuntime(glue, RTSTUB_ID(TestIn), {lexicalEnv,
3590         IntToTaggedInt(levelIndex), IntToTaggedInt(slotIndex), acc});  // acc as obj
3591     CHECK_EXCEPTION_WITH_ACC(res);
3592 }
3593 
GenerateCircuit()3594 void BaselineDeprecatedLdlexenvPrefNoneStubBuilder::GenerateCircuit()
3595 {
3596     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdlexenvPrefNone, SP));
3597     GateRef state = GetFrame(sp);
3598 
3599     GateRef env = GetEnvFromFrame(state);
3600     Return(env);
3601 }
3602 
GenerateCircuit()3603 void BaselineWideCreateobjectwithexcludedkeysPrefImm16V8V8StubBuilder::GenerateCircuit()
3604 {
3605     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideCreateobjectwithexcludedkeysPrefImm16V8V8, GLUE));
3606     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideCreateobjectwithexcludedkeysPrefImm16V8V8, SP));
3607     GateRef numKeys = Int32Argument(PARAM_INDEX(BaselineWideCreateobjectwithexcludedkeysPrefImm16V8V8, V0));
3608     GateRef objId = Int32Argument(PARAM_INDEX(BaselineWideCreateobjectwithexcludedkeysPrefImm16V8V8, V1));
3609     GateRef firstArgRegIdx = Int32Argument(PARAM_INDEX(BaselineWideCreateobjectwithexcludedkeysPrefImm16V8V8, V2));
3610 
3611     GateRef acc = GetAccFromFrame(GetFrame(sp));
3612     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(objId));
3613     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateObjectWithExcludedKeys),
3614         { Int16ToTaggedInt(numKeys), obj, Int16ToTaggedInt(firstArgRegIdx) });
3615     CHECK_EXCEPTION_WITH_ACC(res);
3616 }
3617 
GenerateCircuit()3618 void BaselineThrowPrefNoneStubBuilder::GenerateCircuit()
3619 {
3620     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowPrefNone, GLUE));
3621     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowPrefNone, SP));
3622     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineThrowPrefNone, ACC));
3623 
3624     CallRuntime(glue, RTSTUB_ID(Throw), { acc });
3625     DISPATCH_LAST();
3626     Return();
3627 }
3628 
GenerateCircuit()3629 void BaselineDeprecatedPoplexenvPrefNoneStubBuilder::GenerateCircuit()
3630 {
3631     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedPoplexenvPrefNone, GLUE));
3632     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedPoplexenvPrefNone, SP));
3633 
3634     GateRef state = GetFrame(sp);
3635     GateRef currentLexEnv = GetEnvFromFrame(state);
3636     GateRef parentLexEnv = GetParentEnv(currentLexEnv);
3637     SetEnvToFrame(glue, state, parentLexEnv);
3638     Return();
3639 }
3640 
GenerateCircuit()3641 void BaselineWideNewobjrangePrefImm16V8StubBuilder::GenerateCircuit()
3642 {
3643     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideNewobjrangePrefImm16V8, GLUE));
3644     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideNewobjrangePrefImm16V8, SP));
3645     GateRef numArgs = Int32Argument(PARAM_INDEX(BaselineWideNewobjrangePrefImm16V8, NUM_ARGS));
3646     GateRef firstArgRegIdx = Int32Argument(PARAM_INDEX(BaselineWideNewobjrangePrefImm16V8, IDX));
3647     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineWideNewobjrangePrefImm16V8, HOTNESS_COUNTER));
3648     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineWideNewobjrangePrefImm16V8, SLOT_ID));
3649     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
3650     GateRef acc = GetAccFromFrame(frame);
3651     GateRef firstArgOffset = Int16(1);
3652     GateRef ctor = GetVregValue(sp, ZExtInt16ToPtr(firstArgRegIdx));
3653 
3654     DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
3655     DEFVARIABLE(thisObj, VariableType::JS_ANY(), Undefined());
3656     auto env = GetEnvironment();
3657     GateRef actualNumArgs = ZExtInt16ToInt32(Int16Sub(numArgs, firstArgOffset));
3658 
3659     Label ctorIsHeapObject(env);
3660     Label ctorIsJSFunction(env);
3661     Label fastPath(env);
3662     Label slowPath(env);
3663     Label checkResult(env);
3664     Label threadCheck(env);
3665     Label dispatch(env);
3666     Label ctorIsBase(env);
3667     Label ctorNotBase(env);
3668     Label isException(env);
3669     Label noNeedCheckException(env);
3670     Label exit(env);
3671 
3672     Branch(TaggedIsHeapObject(ctor), &ctorIsHeapObject, &slowPath);
3673     Bind(&ctorIsHeapObject);
3674     Branch(IsJSFunction(ctor), &ctorIsJSFunction, &slowPath);
3675     Bind(&ctorIsJSFunction);
3676     Branch(IsConstructor(ctor), &fastPath, &slowPath);
3677     Bind(&fastPath);
3678     {
3679         Branch(IsBase(ctor), &ctorIsBase, &ctorNotBase);
3680         Bind(&ctorIsBase);
3681         {
3682             NewObjectStubBuilder newBuilder(this);
3683             thisObj = newBuilder.FastNewThisObject(glue, ctor);
3684             Branch(HasPendingException(glue), &isException, &ctorNotBase);
3685         }
3686         Bind(&ctorNotBase);
3687         {
3688             GateRef argv = PtrAdd(sp,
3689                 PtrMul(PtrAdd(firstArgRegIdx, firstArgOffset), IntPtr(8))); // 8: skip function
3690             GateRef jumpSize = IntPtr(-BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_IMM16_V8));
3691             JSCallArgs callArgs(JSCallMode::DEPRECATED_CALL_CONSTRUCTOR_WITH_ARGV);
3692             callArgs.callConstructorArgs = { ZExtInt32ToPtr(actualNumArgs), argv, *thisObj };
3693             CallStubBuilder callBuilder(this, glue, ctor, actualNumArgs, jumpSize, &res, hotnessCounter, callArgs,
3694                 callback);
3695             callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
3696             Bind(&exit);
3697             Jump(&threadCheck);
3698         }
3699     }
3700     Bind(&slowPath);
3701     {
3702         GateRef firstArgIdx = Int16Add(firstArgRegIdx, firstArgOffset);
3703         GateRef length = Int16Sub(numArgs, firstArgOffset);
3704         res = CallRuntime(glue, RTSTUB_ID(NewObjRange),
3705                           { ctor, ctor, Int16ToTaggedInt(firstArgIdx), Int16ToTaggedInt(length) });
3706         Jump(&checkResult);
3707     }
3708     Bind(&checkResult);
3709     {
3710         Branch(TaggedIsException(*res), &isException, &dispatch);
3711     }
3712     Bind(&threadCheck);
3713     {
3714         Branch(HasPendingException(glue), &isException, &dispatch);
3715     }
3716     Bind(&isException);
3717     {
3718         DISPATCH_LAST();
3719         Return(acc);
3720     }
3721     Bind(&dispatch);
3722     Return(*res);
3723     Bind(&noNeedCheckException);
3724     Return(*res);
3725 }
3726 
GenerateCircuit()3727 void BaselineThrowNotexistsPrefNoneStubBuilder::GenerateCircuit()
3728 {
3729     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowNotexistsPrefNone, GLUE));
3730     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowNotexistsPrefNone, SP));
3731 
3732     GateRef frame = GetFrame(sp);
3733     GateRef acc = GetAccFromFrame(frame);
3734     CallRuntime(glue, RTSTUB_ID(ThrowThrowNotExists), {});
3735     DISPATCH_LAST();
3736     Return();
3737 }
3738 
GenerateCircuit()3739 void BaselineDeprecatedGetiteratornextPrefV8V8StubBuilder::GenerateCircuit()
3740 {
3741     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedGetiteratornextPrefV8V8, GLUE));
3742     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedGetiteratornextPrefV8V8, SP));
3743     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedGetiteratornextPrefV8V8, V0));
3744     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedGetiteratornextPrefV8V8, V1));
3745     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v0));
3746     GateRef method = GetVregValue(sp, ZExtInt8ToPtr(v1));
3747 
3748     GateRef frame = GetFrame(sp);
3749     GateRef acc = GetAccFromFrame(frame);
3750     GateRef result = CallRuntime(glue, RTSTUB_ID(GetIteratorNext), { obj, method });
3751     CHECK_EXCEPTION_WITH_ACC(result);
3752 }
3753 
GenerateCircuit()3754 void BaselineWideNewlexenvPrefImm16StubBuilder::GenerateCircuit()
3755 {
3756     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideNewlexenvPrefImm16, GLUE));
3757     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideNewlexenvPrefImm16, SP));
3758     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideNewlexenvPrefImm16, ACC));
3759     GateRef numVars = Int32Argument(PARAM_INDEX(BaselineWideNewlexenvPrefImm16, NUM_VARS));
3760     GateRef state = GetFrame(sp);
3761 
3762     DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
3763     auto env = GetEnvironment();
3764     auto parent = GetEnvFromFrame(state);
3765     NewObjectStubBuilder newBuilder(this);
3766     newBuilder.SetParameters(glue, 0);
3767     Label afterNew(env);
3768     newBuilder.NewLexicalEnv(&result, &afterNew, numVars, parent);
3769     Bind(&afterNew);
3770     Label notException(env);
3771     CHECK_EXCEPTION_WITH_JUMP_RETURN(*result, &notException);
3772     Bind(&notException);
3773     SetEnvToFrame(glue, state, *result);
3774     Return(*result);
3775 }
3776 
GenerateCircuit()3777 void BaselineThrowPatternnoncoerciblePrefNoneStubBuilder::GenerateCircuit()
3778 {
3779     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowPatternnoncoerciblePrefNone, GLUE));
3780     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowPatternnoncoerciblePrefNone, SP));
3781 
3782     GateRef frame = GetFrame(sp);
3783     GateRef acc = GetAccFromFrame(frame);
3784     CallRuntime(glue, RTSTUB_ID(ThrowPatternNonCoercible), {});
3785     DISPATCH_LAST();
3786     Return();
3787 }
3788 
GenerateCircuit()3789 void BaselineDeprecatedCreatearraywithbufferPrefImm16StubBuilder::GenerateCircuit()
3790 {
3791     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCreatearraywithbufferPrefImm16, GLUE));
3792     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCreatearraywithbufferPrefImm16, SP));
3793     GateRef immI16 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCreatearraywithbufferPrefImm16, IMM_I16));
3794     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineDeprecatedCreatearraywithbufferPrefImm16, SLOT_ID));
3795     GateRef profileTypeInfo =
3796         TaggedPointerArgument(PARAM_INDEX(BaselineDeprecatedCreatearraywithbufferPrefImm16, PROFILE_TYPE_INFO));
3797     GateRef pc = PtrArgument(PARAM_INDEX(BaselineDeprecatedCreatearraywithbufferPrefImm16, PC));
3798     GateRef imm = ZExtInt16ToInt32(immI16);
3799 
3800     GateRef frame = GetFrame(sp);
3801     GateRef acc = GetAccFromFrame(frame);
3802     GateRef currentFunc = GetFunctionFromFrame(frame);
3803     ProfileOperation callback;
3804     NewObjectStubBuilder newBuilder(this);
3805     GateRef res = newBuilder.CreateArrayWithBuffer(
3806         glue, imm, currentFunc, { pc, 0, true }, profileTypeInfo, slotId, callback);
3807     CHECK_EXCEPTION_WITH_ACC(res);
3808 }
3809 
GenerateCircuit()3810 void BaselineWideNewlexenvwithnamePrefImm16Id16StubBuilder::GenerateCircuit()
3811 {
3812     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideNewlexenvwithnamePrefImm16Id16, GLUE));
3813     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideNewlexenvwithnamePrefImm16Id16, SP));
3814     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideNewlexenvwithnamePrefImm16Id16, ACC));
3815     GateRef numVars = Int32Argument(PARAM_INDEX(BaselineWideNewlexenvwithnamePrefImm16Id16, NUM_VARS));
3816     GateRef scopeId = Int32Argument(PARAM_INDEX(BaselineWideNewlexenvwithnamePrefImm16Id16, SCOPE_ID));
3817 
3818     auto env = GetEnvironment();
3819     GateRef res = CallRuntime(glue, RTSTUB_ID(NewLexicalEnvWithName),
3820                               { Int16ToTaggedInt(numVars), Int16ToTaggedInt(scopeId) });
3821     Label notException(env);
3822     CHECK_EXCEPTION_WITH_JUMP_RETURN(res, &notException);
3823     Bind(&notException);
3824     GateRef state = GetFrame(sp);
3825     SetEnvToFrame(glue, state, res);
3826     Return(res);
3827 }
3828 
GenerateCircuit()3829 void BaselineThrowDeletesuperpropertyPrefNoneStubBuilder::GenerateCircuit()
3830 {
3831     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowDeletesuperpropertyPrefNone, GLUE));
3832     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowDeletesuperpropertyPrefNone, SP));
3833 
3834     GateRef frame = GetFrame(sp);
3835     GateRef acc = GetAccFromFrame(frame);
3836     CallRuntime(glue, RTSTUB_ID(ThrowDeleteSuperProperty), {});
3837     DISPATCH_LAST();
3838     Return();
3839 }
3840 
GenerateCircuit()3841 void BaselineDeprecatedCreateobjectwithbufferPrefImm16StubBuilder::GenerateCircuit()
3842 {
3843     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCreateobjectwithbufferPrefImm16, GLUE));
3844     GateRef immI16 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCreateobjectwithbufferPrefImm16, IMM_I16));
3845     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCreateobjectwithbufferPrefImm16, SP));
3846     GateRef imm = ZExtInt16ToInt32(immI16);
3847 
3848     GateRef frame = GetFrame(sp);
3849     GateRef acc = GetAccFromFrame(frame);
3850     GateRef func = GetFunctionFromFrame(frame);
3851     GateRef method = GetMethodFromFunction(func);
3852     GateRef constpool = GetConstpoolFromMethod(method);
3853     GateRef module = GetModuleFromFunction(func);
3854     GateRef result = GetObjectLiteralFromConstPool(glue, constpool, imm, module);
3855     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateObjectWithBuffer), { result });
3856     CHECK_EXCEPTION_WITH_ACC(res);
3857 }
3858 
3859 // GLUE, SP, NUM_ARGS, FIRST_ARG_REG_IDX
GenerateCircuit()3860 void BaselineNewobjrangeImm8Imm8V8StubBuilder::GenerateCircuit()
3861 {
3862     GateRef glue = PtrArgument(PARAM_INDEX(BaselineNewobjrangeImm8Imm8V8, GLUE));
3863     GateRef sp = PtrArgument(PARAM_INDEX(BaselineNewobjrangeImm8Imm8V8, SP));
3864     GateRef numArgs = Int32Argument(PARAM_INDEX(BaselineNewobjrangeImm8Imm8V8, NUM_ARGS));
3865     GateRef firstArgRegIdx = Int32Argument(PARAM_INDEX(BaselineNewobjrangeImm8Imm8V8, FIRST_ARG_REG_IDX));
3866     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineNewobjrangeImm8Imm8V8, SLOT_ID));
3867     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
3868     GateRef acc = GetAccFromFrame(frame);
3869     GateRef method = GetMethodFromFunction(curFunc);
3870     GateRef hotnessCounter = GetHotnessCounterFromMethod(method);
3871 
3872     DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
3873     DEFVARIABLE(thisObj, VariableType::JS_ANY(), Undefined());
3874     auto env = GetEnvironment();
3875     GateRef firstArgOffset = Int32(1);
3876     GateRef ctor = GetVregValue(sp, ZExtInt32ToPtr(firstArgRegIdx));
3877     GateRef actualNumArgs = Int32Sub(numArgs, firstArgOffset);
3878 
3879     Label ctorIsHeapObject(env);
3880     Label ctorIsJSFunction(env);
3881     Label fastPath(env);
3882     Label slowPath(env);
3883     Label checkResult(env);
3884     Label threadCheck(env);
3885     Label dispatch(env);
3886     Label ctorIsBase(env);
3887     Label ctorNotBase(env);
3888     Label isException(env);
3889     Label noNeedCheckException(env);
3890     Label exit(env);
3891 
3892     Branch(TaggedIsHeapObject(ctor), &ctorIsHeapObject, &slowPath);
3893     Bind(&ctorIsHeapObject);
3894     Branch(IsJSFunction(ctor), &ctorIsJSFunction, &slowPath);
3895     Bind(&ctorIsJSFunction);
3896     Branch(IsConstructor(ctor), &fastPath, &slowPath);
3897     Bind(&fastPath);
3898     {
3899         Branch(IsBase(ctor), &ctorIsBase, &ctorNotBase);
3900         Bind(&ctorIsBase);
3901         {
3902             NewObjectStubBuilder newBuilder(this);
3903             thisObj = newBuilder.FastNewThisObject(glue, ctor);
3904             Branch(HasPendingException(glue), &isException, &ctorNotBase);
3905         }
3906         Bind(&ctorNotBase);
3907         {
3908             GateRef argv = PtrAdd(sp, PtrMul(
3909                 PtrAdd(firstArgRegIdx, firstArgOffset), IntPtr(8))); // 8: skip function
3910             GateRef jumpSize = IntPtr(-BytecodeInstruction::Size(BytecodeInstruction::Format::IMM8_IMM8_V8));
3911             METHOD_ENTRY_ENV_DEFINED(ctor);
3912             JSCallArgs callArgs(JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV);
3913             callArgs.callConstructorArgs = { ZExtInt32ToPtr(actualNumArgs), argv, *thisObj };
3914             CallStubBuilder callBuilder(this, glue, ctor, actualNumArgs, jumpSize, &res, hotnessCounter, callArgs,
3915                 callback);
3916             callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
3917             Bind(&exit);
3918             Jump(&threadCheck);
3919         }
3920     }
3921     Bind(&slowPath);
3922     {
3923         GateRef firstArgIdx = Int32Add(firstArgRegIdx, firstArgOffset);
3924         GateRef length = Int32Sub(numArgs, firstArgOffset);
3925         res = CallRuntime(glue, RTSTUB_ID(NewObjRange),
3926                           { ctor, ctor, IntToTaggedInt(firstArgIdx), IntToTaggedInt(length) });
3927         Jump(&checkResult);
3928     }
3929     Bind(&checkResult);
3930     {
3931         Branch(TaggedIsException(*res), &isException, &dispatch);
3932     }
3933     Bind(&threadCheck);
3934     {
3935         Branch(HasPendingException(glue), &isException, &dispatch);
3936     }
3937     Bind(&isException);
3938     {
3939         DISPATCH_LAST();
3940         Return(acc);
3941     }
3942     Bind(&dispatch);
3943     Return(*res);
3944     Bind(&noNeedCheckException);
3945     Return(*res);
3946 }
3947 
3948 // GLUE, SP, NUM_ARGS, FIRST_ARG_REG_IDX
GenerateCircuit()3949 void BaselineNewobjrangeImm16Imm8V8StubBuilder::GenerateCircuit()
3950 {
3951     GateRef glue = PtrArgument(PARAM_INDEX(BaselineNewobjrangeImm16Imm8V8, GLUE));
3952     GateRef sp = PtrArgument(PARAM_INDEX(BaselineNewobjrangeImm16Imm8V8, SP));
3953     GateRef numArgs = Int32Argument(PARAM_INDEX(BaselineNewobjrangeImm16Imm8V8, NUM_ARGS));
3954     GateRef firstArgRegIdx = Int32Argument(PARAM_INDEX(BaselineNewobjrangeImm16Imm8V8, FIRST_ARG_REG_IDX));
3955     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineNewobjrangeImm16Imm8V8, SLOT_ID));
3956     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
3957 
3958     GateRef acc = GetAccFromFrame(frame);
3959     GateRef method = GetMethodFromFunction(curFunc);
3960     GateRef hotnessCounter = GetHotnessCounterFromMethod(method);
3961 
3962     DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
3963     DEFVARIABLE(thisObj, VariableType::JS_ANY(), Undefined());
3964     auto env = GetEnvironment();
3965     GateRef firstArgOffset = Int16(1);
3966     GateRef ctor = GetVregValue(sp, ZExtInt16ToPtr(firstArgRegIdx));
3967     GateRef actualNumArgs = ZExtInt16ToInt32(Int16Sub(numArgs, firstArgOffset));
3968 
3969     Label ctorIsHeapObject(env);
3970     Label ctorIsJSFunction(env);
3971     Label fastPath(env);
3972     Label slowPath(env);
3973     Label checkResult(env);
3974     Label threadCheck(env);
3975     Label dispatch(env);
3976     Label ctorIsBase(env);
3977     Label ctorNotBase(env);
3978     Label isException(env);
3979     Label noNeedCheckException(env);
3980     Label exit(env);
3981 
3982     Branch(TaggedIsHeapObject(ctor), &ctorIsHeapObject, &slowPath);
3983     Bind(&ctorIsHeapObject);
3984     Branch(IsJSFunction(ctor), &ctorIsJSFunction, &slowPath);
3985     Bind(&ctorIsJSFunction);
3986     Branch(IsConstructor(ctor), &fastPath, &slowPath);
3987     Bind(&fastPath);
3988     {
3989         Branch(IsBase(ctor), &ctorIsBase, &ctorNotBase);
3990         Bind(&ctorIsBase);
3991         {
3992             NewObjectStubBuilder newBuilder(this);
3993             thisObj = newBuilder.FastNewThisObject(glue, ctor);
3994             Branch(HasPendingException(glue), &isException, &ctorNotBase);
3995         }
3996         Bind(&ctorNotBase);
3997         {
3998             GateRef argv = PtrAdd(sp, PtrMul(
3999                 PtrAdd(firstArgRegIdx, firstArgOffset), IntPtr(8))); // 8: skip function
4000             GateRef jumpSize = IntPtr(-BytecodeInstruction::Size(BytecodeInstruction::Format::IMM16_IMM8_V8));
4001             METHOD_ENTRY_ENV_DEFINED(ctor);
4002             JSCallArgs callArgs(JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV);
4003             callArgs.callConstructorArgs = { ZExtInt32ToPtr(actualNumArgs), argv, *thisObj };
4004             CallStubBuilder callBuilder(this, glue, ctor, actualNumArgs, jumpSize, &res, hotnessCounter, callArgs,
4005                 callback);
4006             callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4007             Bind(&exit);
4008             Jump(&threadCheck);
4009         }
4010     }
4011     Bind(&slowPath);
4012     {
4013         GateRef firstArgIdx = Int16Add(firstArgRegIdx, firstArgOffset);
4014         GateRef length = Int16Sub(numArgs, firstArgOffset);
4015         res = CallRuntime(glue, RTSTUB_ID(NewObjRange),
4016                           { ctor, ctor, Int16ToTaggedInt(firstArgIdx), Int16ToTaggedInt(length) });
4017         Jump(&checkResult);
4018     }
4019     Bind(&checkResult);
4020     {
4021         Branch(TaggedIsException(*res), &isException, &dispatch);
4022     }
4023     Bind(&threadCheck);
4024     {
4025         Branch(HasPendingException(glue), &isException, &dispatch);
4026     }
4027     Bind(&isException);
4028     {
4029         DISPATCH_LAST();
4030         Return(acc);
4031     }
4032     Bind(&dispatch);
4033     Return(*res);
4034     Bind(&noNeedCheckException);
4035     Return(*res);
4036 }
4037 
4038 // GLUE, SP, ACC, ACTUAL_NUM_ARGS, VREG_ID, HOTNESS_COUNTER
GenerateCircuit()4039 void BaselineWideCallrangePrefImm16V8StubBuilder::GenerateCircuit()
4040 {
4041     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideCallrangePrefImm16V8, GLUE));
4042     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideCallrangePrefImm16V8, SP));
4043     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideCallrangePrefImm16V8, ACC));
4044     GateRef actualNumArgs = Int32Argument(PARAM_INDEX(BaselineWideCallrangePrefImm16V8, ACTUAL_NUM_ARGS));
4045     GateRef vregId = Int32Argument(PARAM_INDEX(BaselineWideCallrangePrefImm16V8, VREG_ID));
4046     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineWideCallrangePrefImm16V8, HOTNESS_COUNTER));
4047     ProfileOperation callback;
4048     GateRef argv = PtrAdd(sp, PtrMul(ZExtInt8ToPtr(vregId), IntPtr(8))); // 8: byteSize
4049 
4050     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4051     METHOD_ENTRY(acc);
4052     Label noNeedCheckException(env);
4053     Label exit(env);
4054     GateRef jumpSize = INT_PTR(WIDE_CALLRANGE_PREF_IMM16_V8);
4055     GateRef numArgs = ZExtInt32ToPtr(actualNumArgs);
4056     JSCallArgs callArgs(JSCallMode::CALL_WITH_ARGV);
4057     callArgs.callArgv = { numArgs, argv };
4058     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4059     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4060     Bind(&exit);
4061     CHECK_PENDING_EXCEPTION(*result);
4062     Bind(&noNeedCheckException);
4063     Return(*result);
4064 }
4065 
GenerateCircuit()4066 void BaselineThrowConstassignmentPrefV8StubBuilder::GenerateCircuit()
4067 {
4068     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowConstassignmentPrefV8, GLUE));
4069     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowConstassignmentPrefV8, SP));
4070     GateRef v0 = TaggedArgument(PARAM_INDEX(BaselineThrowConstassignmentPrefV8, V0));
4071 
4072     GateRef frame = GetFrame(sp);
4073     GateRef acc = GetAccFromFrame(frame);
4074     CallRuntime(glue, RTSTUB_ID(ThrowConstAssignment), { v0 });
4075     DISPATCH_LAST();
4076     Return();
4077 }
4078 
GenerateCircuit()4079 void BaselineDeprecatedTonumberPrefV8StubBuilder::GenerateCircuit()
4080 {
4081     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedTonumberPrefV8, GLUE));
4082     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedTonumberPrefV8, SP));
4083     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedTonumberPrefV8, V0));
4084     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0));
4085 
4086     auto env = GetEnvironment();
4087     Label valueIsNumber(env);
4088     Label valueNotNumber(env);
4089     Branch(TaggedIsNumber(value), &valueIsNumber, &valueNotNumber);
4090     Bind(&valueIsNumber);
4091     {
4092         Return(value);
4093     }
4094     Bind(&valueNotNumber);
4095     {
4096         GateRef result = CallRuntime(glue, RTSTUB_ID(ToNumber), { value });
4097         CHECK_EXCEPTION_RETURN(result);
4098     }
4099 }
4100 
GenerateCircuit()4101 void BaselineWideCallthisrangePrefImm16V8StubBuilder::GenerateCircuit()
4102 {
4103     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideCallthisrangePrefImm16V8, GLUE));
4104     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideCallthisrangePrefImm16V8, SP));
4105     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideCallthisrangePrefImm16V8, ACC));
4106     GateRef actualNumArgs = Int32Argument(PARAM_INDEX(BaselineWideCallthisrangePrefImm16V8, ACTUAL_NUM_ARGS));
4107     GateRef vregId = Int32Argument(PARAM_INDEX(BaselineWideCallthisrangePrefImm16V8, VREG_ID));
4108     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineWideCallthisrangePrefImm16V8, HOTNESS_COUNTER));
4109 
4110     GateRef thisReg = ZExtInt8ToPtr(vregId);
4111     GateRef thisValue = GetVregValue(sp, thisReg);
4112     GateRef argv = PtrAdd(sp, PtrMul(
4113         PtrAdd(thisReg, IntPtr(1)), IntPtr(8))); // 1: skip this
4114     ProfileOperation callback;
4115 
4116     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4117     METHOD_ENTRY(acc);
4118     Label noNeedCheckException(env);
4119     Label exit(env);
4120     GateRef jumpSize = INT_PTR(WIDE_CALLTHISRANGE_PREF_IMM16_V8);
4121     GateRef numArgs = ZExtInt32ToPtr(actualNumArgs);
4122     JSCallArgs callArgs(JSCallMode::CALL_THIS_WITH_ARGV);
4123     callArgs.callArgvWithThis = { numArgs, argv, thisValue };
4124     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4125     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4126     Bind(&exit);
4127     CHECK_PENDING_EXCEPTION(*result);
4128     Bind(&noNeedCheckException);
4129     Return(*result);
4130 }
4131 
GenerateCircuit()4132 void BaselineThrowIfnotobjectPrefV8StubBuilder::GenerateCircuit()
4133 {
4134     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowIfnotobjectPrefV8, GLUE));
4135     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowIfnotobjectPrefV8, SP));
4136     GateRef v0 = TaggedArgument(PARAM_INDEX(BaselineThrowIfnotobjectPrefV8, V0));
4137 
4138     auto env = GetEnvironment();
4139     GateRef frame = GetFrame(sp);
4140     GateRef acc = GetAccFromFrame(frame);
4141     Label isEcmaObject(env);
4142     Label notEcmaObject(env);
4143     Label isHeapObject(env);
4144     Branch(TaggedIsHeapObject(v0), &isHeapObject, &notEcmaObject);
4145     Bind(&isHeapObject);
4146     Branch(TaggedObjectIsEcmaObject(v0), &isEcmaObject, &notEcmaObject);
4147     Bind(&isEcmaObject);
4148     {
4149         Return();
4150     }
4151     Bind(&notEcmaObject);
4152     CallRuntime(glue, RTSTUB_ID(ThrowIfNotObject), {});
4153     DISPATCH_LAST();
4154     Return();
4155 }
4156 
GenerateCircuit()4157 void BaselineDeprecatedTonumericPrefV8StubBuilder::GenerateCircuit()
4158 {
4159     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedTonumericPrefV8, GLUE));
4160     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedTonumericPrefV8, SP));
4161     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedTonumericPrefV8, V0));
4162     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0));
4163 
4164     auto env = GetEnvironment();
4165     Label valueIsNumeric(env);
4166     Label valueNotNumeric(env);
4167     Branch(TaggedIsNumeric(value), &valueIsNumeric, &valueNotNumeric);
4168     Bind(&valueIsNumeric);
4169     {
4170         Return(value);
4171     }
4172     Bind(&valueNotNumeric);
4173     {
4174         GateRef result = CallRuntime(glue, RTSTUB_ID(ToNumeric), { value });
4175         CHECK_EXCEPTION_RETURN(result);
4176     }
4177 }
4178 
GenerateCircuit()4179 void BaselineWideSupercallthisrangePrefImm16V8StubBuilder::GenerateCircuit()
4180 {
4181     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideSupercallthisrangePrefImm16V8, GLUE));
4182     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideSupercallthisrangePrefImm16V8, SP));
4183     GateRef range = Int32Argument(PARAM_INDEX(BaselineWideSupercallthisrangePrefImm16V8, RANGE));
4184     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineWideSupercallthisrangePrefImm16V8, V0));
4185 
4186     GateRef frame = GetFrame(sp);
4187     GateRef acc = GetAccFromFrame(frame);
4188     GateRef currentFunc = GetFunctionFromFrame(frame);
4189     GateRef res = CallRuntime(glue, RTSTUB_ID(SuperCall),
4190         { currentFunc, Int16ToTaggedInt(v0), Int16ToTaggedInt(range) });
4191     CHECK_EXCEPTION_WITH_ACC(res);
4192 }
4193 
GenerateCircuit()4194 void BaselineThrowUndefinedifholePrefV8V8StubBuilder::GenerateCircuit()
4195 {
4196     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowUndefinedifholePrefV8V8, GLUE));
4197     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowUndefinedifholePrefV8V8, SP));
4198     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineThrowUndefinedifholePrefV8V8, V0));
4199     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineThrowUndefinedifholePrefV8V8, V1));
4200 
4201     GateRef hole = GetVregValue(sp, ZExtInt8ToPtr(v0));
4202     auto env = GetEnvironment();
4203     GateRef frame = GetFrame(sp);
4204     GateRef acc = GetAccFromFrame(frame);
4205     Label isHole(env);
4206     Label notHole(env);
4207     Branch(TaggedIsHole(hole), &isHole, &notHole);
4208     Bind(&notHole);
4209     {
4210         Return();
4211     }
4212     Bind(&isHole);
4213     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v1));
4214     CallRuntime(glue, RTSTUB_ID(ThrowUndefinedIfHole), { obj });
4215     DISPATCH_LAST();
4216     Return();
4217 }
4218 
GenerateCircuit()4219 void BaselineThrowUndefinedifholewithnamePrefId16StubBuilder::GenerateCircuit()
4220 {
4221     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowUndefinedifholewithnamePrefId16, GLUE));
4222     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowUndefinedifholewithnamePrefId16, SP));
4223     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineThrowUndefinedifholewithnamePrefId16, STRING_ID));
4224 
4225     GateRef frame = GetFrame(sp);
4226     GateRef acc = GetAccFromFrame(frame);
4227     GateRef func = GetFunctionFromFrame(frame);
4228     GateRef method = GetMethodFromFunction(func);
4229     GateRef constpool = GetConstpoolFromMethod(method);
4230     auto env = GetEnvironment();
4231     Label isHole(env);
4232     Label notHole(env);
4233     Branch(TaggedIsHole(acc), &isHole, &notHole);
4234     Bind(&notHole);
4235     {
4236         Return();
4237     }
4238     Bind(&isHole);
4239     GateRef str = GetStringFromConstPool(glue, constpool, stringId);
4240     CallRuntime(glue, RTSTUB_ID(ThrowUndefinedIfHole), { str });
4241     DISPATCH_LAST();
4242     Return();
4243 }
4244 
GenerateCircuit()4245 void BaselineDeprecatedNegPrefV8StubBuilder::GenerateCircuit()
4246 {
4247     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedNegPrefV8, GLUE));
4248     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedNegPrefV8, SP));
4249     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedNegPrefV8, V0));
4250     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0));
4251 
4252     GateRef frame = GetFrame(sp);
4253     GateRef acc = GetAccFromFrame(frame);
4254     OperationsStubBuilder builder(this);
4255     GateRef result = builder.Neg(glue, value);
4256     CHECK_EXCEPTION_WITH_ACC(result);
4257 }
4258 
GenerateCircuit()4259 void BaselineWideSupercallarrowrangePrefImm16V8StubBuilder::GenerateCircuit()
4260 {
4261     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideSupercallarrowrangePrefImm16V8, GLUE));
4262     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideSupercallarrowrangePrefImm16V8, SP));
4263     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideSupercallarrowrangePrefImm16V8, ACC));
4264     GateRef range = Int32Argument(PARAM_INDEX(BaselineWideSupercallarrowrangePrefImm16V8, RANGE));
4265     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineWideSupercallarrowrangePrefImm16V8, V0));
4266 
4267     GateRef res = CallRuntime(glue, RTSTUB_ID(SuperCall),
4268         { acc, Int16ToTaggedInt(v0), Int16ToTaggedInt(range) });
4269     CHECK_EXCEPTION_WITH_ACC(res);
4270 }
4271 
GenerateCircuit()4272 void BaselineThrowIfsupernotcorrectcallPrefImm8StubBuilder::GenerateCircuit()
4273 {
4274     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm8, GLUE));
4275     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm8, SP));
4276     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm8, ACC));
4277     GateRef imm = Int32Argument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm8, IMM));
4278 
4279     GateRef res = CallRuntime(glue, RTSTUB_ID(ThrowIfSuperNotCorrectCall),
4280         { Int8ToTaggedInt(imm), acc }); // acc is thisValue
4281     CHECK_EXCEPTION(res);
4282 }
4283 
GenerateCircuit()4284 void BaselineDeprecatedNotPrefV8StubBuilder::GenerateCircuit()
4285 {
4286     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedNotPrefV8, GLUE));
4287     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedNotPrefV8, SP));
4288     GateRef index = Int32Argument(PARAM_INDEX(BaselineDeprecatedNotPrefV8, INDEX));
4289     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(index));
4290 
4291     GateRef frame = GetFrame(sp);
4292     GateRef acc = GetAccFromFrame(frame);
4293     OperationsStubBuilder builder(this);
4294     GateRef result = builder.Not(glue, value);
4295     CHECK_EXCEPTION_WITH_ACC(result);
4296 }
4297 
GenerateCircuit()4298 void BaselineWideLdobjbyindexPrefImm32StubBuilder::GenerateCircuit()
4299 {
4300     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideLdobjbyindexPrefImm32, GLUE));
4301     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideLdobjbyindexPrefImm32, SP));
4302     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideLdobjbyindexPrefImm32, INDEX));
4303     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineWideLdobjbyindexPrefImm32, SLOT_ID));
4304     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
4305 
4306     auto env = GetEnvironment();
4307     GateRef acc = GetAccFromFrame(frame);
4308     Label fastPath(env);
4309     Label slowPath(env);
4310     Branch(TaggedIsHeapObject(acc), &fastPath, &slowPath);
4311     Bind(&fastPath);
4312     {
4313         GateRef result = GetPropertyByIndex(glue, acc, index, callback);
4314         Label notHole(env);
4315         Branch(TaggedIsHole(result), &slowPath, &notHole);
4316         Bind(&notHole);
4317         CHECK_EXCEPTION_WITH_ACC(result);
4318     }
4319     Bind(&slowPath);
4320     {
4321         GateRef result = CallRuntime(glue, RTSTUB_ID(LdObjByIndex),
4322                                      { acc, IntToTaggedInt(index), TaggedFalse(), Undefined() });
4323         CHECK_EXCEPTION_WITH_ACC(result);
4324     }
4325 }
4326 
GenerateCircuit()4327 void BaselineThrowIfsupernotcorrectcallPrefImm16StubBuilder::GenerateCircuit()
4328 {
4329     GateRef glue = PtrArgument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm16, GLUE));
4330     GateRef sp = PtrArgument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm16, SP));
4331     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm16, ACC));
4332     GateRef imm = Int32Argument(PARAM_INDEX(BaselineThrowIfsupernotcorrectcallPrefImm16, IMM));
4333 
4334     GateRef res = CallRuntime(glue, RTSTUB_ID(ThrowIfSuperNotCorrectCall),
4335         { Int16ToTaggedInt(imm), acc }); // acc is thisValue
4336     CHECK_EXCEPTION(res);
4337 }
4338 
GenerateCircuit()4339 void BaselineDeprecatedIncPrefV8StubBuilder::GenerateCircuit()
4340 {
4341     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedIncPrefV8, GLUE));
4342     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedIncPrefV8, SP));
4343     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedIncPrefV8, V0));
4344     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0));
4345 
4346     GateRef frame = GetFrame(sp);
4347     GateRef acc = GetAccFromFrame(frame);
4348     OperationsStubBuilder builder(this);
4349     GateRef result = builder.Inc(glue, value);
4350     CHECK_EXCEPTION_WITH_ACC(result);
4351 }
4352 
GenerateCircuit()4353 void BaselineWideStobjbyindexPrefV8Imm32StubBuilder::GenerateCircuit()
4354 {
4355     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideStobjbyindexPrefV8Imm32, GLUE));
4356     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideStobjbyindexPrefV8Imm32, SP));
4357     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineWideStobjbyindexPrefV8Imm32, V0));
4358     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideStobjbyindexPrefV8Imm32, INDEX));
4359     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineWideStobjbyindexPrefV8Imm32, SLOT_ID));
4360     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
4361 
4362     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(v0));
4363     GateRef acc = GetAccFromFrame(frame);
4364     auto env = GetEnvironment();
4365     Label fastPath(env);
4366     Label slowPath(env);
4367     Branch(TaggedIsHeapObject(receiver), &fastPath, &slowPath);
4368     Bind(&fastPath);
4369     {
4370         GateRef result = SetPropertyByIndex(glue, receiver, index, acc, false);
4371         Label notHole(env);
4372         Branch(TaggedIsHole(result), &slowPath, &notHole);
4373         Bind(&notHole);
4374         CHECK_EXCEPTION(result);
4375     }
4376     Bind(&slowPath);
4377     {
4378         GateRef result = CallRuntime(glue, RTSTUB_ID(StObjByIndex),
4379                                      { receiver, IntToTaggedInt(index), acc });
4380         CHECK_EXCEPTION(result);
4381     }
4382 }
4383 
GenerateCircuit()4384 void BaselineDeprecatedDecPrefV8StubBuilder::GenerateCircuit()
4385 {
4386     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedDecPrefV8, GLUE));
4387     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedDecPrefV8, SP));
4388     GateRef index = Int32Argument(PARAM_INDEX(BaselineDeprecatedDecPrefV8, INDEX));
4389     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(index));
4390 
4391     GateRef frame = GetFrame(sp);
4392     GateRef acc = GetAccFromFrame(frame);
4393     OperationsStubBuilder builder(this);
4394     GateRef result = builder.Dec(glue, value);
4395     CHECK_EXCEPTION_WITH_ACC(result);
4396 }
4397 
GenerateCircuit()4398 void BaselineWideStownbyindexPrefV8Imm32StubBuilder::GenerateCircuit()
4399 {
4400     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideStownbyindexPrefV8Imm32, GLUE));
4401     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideStownbyindexPrefV8Imm32, SP));
4402     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineWideStownbyindexPrefV8Imm32, V0));
4403     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideStownbyindexPrefV8Imm32, INDEX));
4404     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineWideStownbyindexPrefV8Imm32, SLOT_ID));
4405     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
4406     GateRef acc = GetAccFromFrame(frame);
4407     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(v0));
4408 
4409     auto env = GetEnvironment();
4410     Label isHeapObject(env);
4411     Label slowPath(env);
4412     Branch(TaggedIsHeapObject(receiver), &isHeapObject, &slowPath);
4413     Bind(&isHeapObject);
4414     Label notClassConstructor(env);
4415     Branch(IsClassConstructor(receiver), &slowPath, &notClassConstructor);
4416     Bind(&notClassConstructor);
4417     Label notClassPrototype(env);
4418     Branch(IsClassPrototype(receiver), &slowPath, &notClassPrototype);
4419     Bind(&notClassPrototype);
4420     {
4421         // fast path
4422         GateRef result = SetPropertyByIndex(glue, receiver, index, acc, true); // acc is value
4423         Label notHole(env);
4424         Branch(TaggedIsHole(result), &slowPath, &notHole);
4425         Bind(&notHole);
4426         CHECK_EXCEPTION(result);
4427     }
4428     Bind(&slowPath);
4429     {
4430         GateRef result = CallRuntime(glue, RTSTUB_ID(StOwnByIndex),
4431                                      { receiver, IntToTaggedInt(index), acc });
4432         CHECK_EXCEPTION(result);
4433     }
4434 }
4435 
GenerateCircuit()4436 void BaselineDeprecatedCallarg0PrefV8StubBuilder::GenerateCircuit()
4437 {
4438     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallarg0PrefV8, GLUE));
4439     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallarg0PrefV8, SP));
4440     GateRef funcReg = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallarg0PrefV8, FUNC_REG));
4441     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallarg0PrefV8, HOTNESS_COUNTER));
4442     ProfileOperation callback;
4443     GateRef func = GetVregValue(sp, ZExtInt8ToPtr(funcReg));
4444     GateRef acc = GetAccFromFrame(GetFrame(sp));
4445 
4446     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4447     auto env = GetEnvironment();
4448     Label noNeedCheckException(env);
4449     Label exit(env);
4450     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARG0);
4451     GateRef jumpSize = INT_PTR(DEPRECATED_CALLARG0_PREF_V8);
4452     JSCallArgs callArgs(JSCallMode::DEPRECATED_CALL_ARG0);
4453     callArgs.callArgs = { 0, 0, 0 };
4454     CallStubBuilder callBuilder(this, glue, func, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4455     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4456     Bind(&exit);
4457     CHECK_PENDING_EXCEPTION(*result);
4458     Bind(&noNeedCheckException);
4459     Return(*result);
4460 }
4461 
GenerateCircuit()4462 void BaselineWideCopyrestargsPrefImm16StubBuilder::GenerateCircuit()
4463 {
4464     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideCopyrestargsPrefImm16, GLUE));
4465     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideCopyrestargsPrefImm16, SP));
4466     GateRef restIdx = Int32Argument(PARAM_INDEX(BaselineWideCopyrestargsPrefImm16, INDEX));
4467 
4468     GateRef acc = GetAccFromFrame(GetFrame(sp));
4469     GateRef res = CallRuntime(glue, RTSTUB_ID(CopyRestArgs), { IntToTaggedInt(restIdx) });
4470     CHECK_EXCEPTION_WITH_ACC(res);
4471 }
4472 
GenerateCircuit()4473 void BaselineDeprecatedCallarg1PrefV8V8StubBuilder::GenerateCircuit()
4474 {
4475     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallarg1PrefV8V8, GLUE));
4476     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallarg1PrefV8V8, SP));
4477     GateRef funcReg = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallarg1PrefV8V8, FUNC_REG));
4478     GateRef a0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallarg1PrefV8V8, A0));
4479     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallarg1PrefV8V8, HOTNESS_COUNTER));
4480     ProfileOperation callback;
4481     GateRef a0Value = GetVregValue(sp, ZExtInt8ToPtr(a0));
4482     GateRef func = GetVregValue(sp, ZExtInt8ToPtr(funcReg));
4483     GateRef acc = GetAccFromFrame(GetFrame(sp));
4484 
4485     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4486     auto env = GetEnvironment();
4487     Label noNeedCheckException(env);
4488     Label exit(env);
4489     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARG1);
4490     GateRef jumpSize = INT_PTR(DEPRECATED_CALLARG1_PREF_V8_V8);
4491     JSCallArgs callArgs(JSCallMode::DEPRECATED_CALL_ARG1);
4492     callArgs.callArgs = { a0Value, 0, 0 };
4493     CallStubBuilder callBuilder(this, glue, func, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4494     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4495     Bind(&exit);
4496     CHECK_PENDING_EXCEPTION(*result);
4497     Bind(&noNeedCheckException);
4498     Return(*result);
4499 }
4500 
GenerateCircuit()4501 void BaselineWideLdlexvarPrefImm16Imm16StubBuilder::GenerateCircuit()
4502 {
4503     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideLdlexvarPrefImm16Imm16, SP));
4504     GateRef level = Int32Argument(PARAM_INDEX(BaselineWideLdlexvarPrefImm16Imm16, LEVEL));
4505     GateRef slot = Int32Argument(PARAM_INDEX(BaselineWideLdlexvarPrefImm16Imm16, SLOT));
4506 
4507     GateRef state = GetFrame(sp);
4508     auto env = GetEnvironment();
4509     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(state));
4510     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
4511 
4512     Label loopHead(env);
4513     Label loopEnd(env);
4514     Label afterLoop(env);
4515     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
4516     LoopBegin(&loopHead);
4517     currentEnv = GetParentEnv(*currentEnv);
4518     i = Int32Add(*i, Int32(1));
4519     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
4520     Bind(&loopEnd);
4521     LoopEnd(&loopHead);
4522     Bind(&afterLoop);
4523     GateRef variable = GetPropertiesFromLexicalEnv(*currentEnv, slot);
4524     Return(variable);
4525 }
4526 
GenerateCircuit()4527 void BaselineDeprecatedCallargs2PrefV8V8V8StubBuilder::GenerateCircuit()
4528 {
4529     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallargs2PrefV8V8V8, GLUE));
4530     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallargs2PrefV8V8V8, SP));
4531     GateRef funcReg = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs2PrefV8V8V8, FUNC_REG));
4532     GateRef a0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs2PrefV8V8V8, A0));
4533     GateRef a1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs2PrefV8V8V8, A1));
4534     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs2PrefV8V8V8, HOTNESS_COUNTER));
4535     ProfileOperation callback;
4536     GateRef func = GetVregValue(sp, ZExtInt8ToPtr(funcReg));
4537     GateRef a0Value = GetVregValue(sp, ZExtInt8ToPtr(a0));
4538     GateRef a1Value = GetVregValue(sp, ZExtInt8ToPtr(a1));
4539     GateRef acc = GetAccFromFrame(GetFrame(sp));
4540 
4541     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4542     auto env = GetEnvironment();
4543     Label noNeedCheckException(env);
4544     Label exit(env);
4545     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARGS2);
4546     GateRef jumpSize = INT_PTR(DEPRECATED_CALLARGS2_PREF_V8_V8_V8);
4547     JSCallArgs callArgs(JSCallMode::DEPRECATED_CALL_ARG2);
4548     callArgs.callArgs = { a0Value, a1Value, 0 };
4549     CallStubBuilder callBuilder(this, glue, func, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4550     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4551     Bind(&exit);
4552     CHECK_PENDING_EXCEPTION(*result);
4553     Bind(&noNeedCheckException);
4554     Return(*result);
4555 }
4556 
GenerateCircuit()4557 void BaselineWideStlexvarPrefImm16Imm16StubBuilder::GenerateCircuit()
4558 {
4559     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideStlexvarPrefImm16Imm16, GLUE));
4560     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideStlexvarPrefImm16Imm16, SP));
4561     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideStlexvarPrefImm16Imm16, ACC));
4562     GateRef level = Int32Argument(PARAM_INDEX(BaselineWideStlexvarPrefImm16Imm16, LEVEL));
4563     GateRef slot = Int32Argument(PARAM_INDEX(BaselineWideStlexvarPrefImm16Imm16, SLOT));
4564 
4565     GateRef state = GetFrame(sp);
4566     auto env = GetEnvironment();
4567     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(state));
4568     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
4569 
4570     Label loopHead(env);
4571     Label loopEnd(env);
4572     Label afterLoop(env);
4573     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
4574     LoopBegin(&loopHead);
4575     currentEnv = GetParentEnv(*currentEnv);
4576     i = Int32Add(*i, Int32(1));
4577     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
4578     Bind(&loopEnd);
4579     LoopEnd(&loopHead);
4580     Bind(&afterLoop);
4581     SetPropertiesToLexicalEnv(glue, *currentEnv, slot, acc);
4582     Return();
4583 }
4584 
GenerateCircuit()4585 void BaselineDeprecatedCallargs3PrefV8V8V8V8StubBuilder::GenerateCircuit()
4586 {
4587     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallargs3PrefV8V8V8V8, GLUE));
4588     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallargs3PrefV8V8V8V8, SP));
4589     GateRef funcReg = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs3PrefV8V8V8V8, FUNC_REG));
4590     GateRef a0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs3PrefV8V8V8V8, A0));
4591     GateRef a1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs3PrefV8V8V8V8, A1));
4592     GateRef a2 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallargs3PrefV8V8V8V8, A2));
4593     ProfileOperation callback;
4594     GateRef func = GetVregValue(sp, ZExtInt8ToPtr(funcReg));
4595     GateRef a0Value = GetVregValue(sp, ZExtInt8ToPtr(a0));
4596     GateRef a1Value = GetVregValue(sp, ZExtInt8ToPtr(a1));
4597     GateRef a2Value = GetVregValue(sp, ZExtInt8ToPtr(a2));
4598 
4599     GateRef method = GetMethodFromFunction(GetFunctionFromFrame(GetFrame(sp)));
4600     GateRef hotnessCounter = GetHotnessCounterFromMethod(method);
4601     GateRef acc = GetAccFromFrame(GetFrame(sp));
4602 
4603     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4604     auto env = GetEnvironment();
4605     Label noNeedCheckException(env);
4606     Label exit(env);
4607     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARGS3);
4608     GateRef jumpSize = INT_PTR(DEPRECATED_CALLARGS3_PREF_V8_V8_V8_V8);
4609     JSCallArgs callArgs(JSCallMode::DEPRECATED_CALL_ARG3);
4610     callArgs.callArgs = { a0Value, a1Value, a2Value };
4611     CallStubBuilder callBuilder(this, glue, func, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4612     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4613     Bind(&exit);
4614     CHECK_PENDING_EXCEPTION(*result);
4615     Bind(&noNeedCheckException);
4616     Return(*result);
4617 }
4618 
GenerateCircuit()4619 void BaselineWideGetmodulenamespacePrefImm16StubBuilder::GenerateCircuit()
4620 {
4621     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideGetmodulenamespacePrefImm16, GLUE));
4622     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideGetmodulenamespacePrefImm16, INDEX));
4623 
4624     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(GetModuleNamespaceByIndex), { Int16ToTaggedInt(index) });
4625     Return(moduleRef);
4626 }
4627 
GenerateCircuit()4628 void BaselineDeprecatedCallrangePrefImm16V8StubBuilder::GenerateCircuit()
4629 {
4630     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallrangePrefImm16V8, GLUE));
4631     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallrangePrefImm16V8, SP));
4632     GateRef actualNumArgs = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallrangePrefImm16V8, INDEX));
4633     GateRef funcReg = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallrangePrefImm16V8, FUNC_REG));
4634     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallrangePrefImm16V8, HOTNESS_COUNTER));
4635     ProfileOperation callback;
4636     GateRef func = GetVregValue(sp, ZExtInt8ToPtr(funcReg));
4637     GateRef argv = PtrAdd(sp, PtrMul(
4638         PtrAdd(ZExtInt8ToPtr(funcReg), IntPtr(1)), IntPtr(8))); // 1: skip function
4639     GateRef acc = GetAccFromFrame(GetFrame(sp));
4640 
4641     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4642     auto env = GetEnvironment();
4643     Label noNeedCheckException(env);
4644     Label exit(env);
4645     GateRef jumpSize = INT_PTR(DEPRECATED_CALLRANGE_PREF_IMM16_V8);
4646     GateRef numArgs = ZExtInt32ToPtr(actualNumArgs);
4647     JSCallArgs callArgs(JSCallMode::DEPRECATED_CALL_WITH_ARGV);
4648     callArgs.callArgv = { numArgs, argv };
4649     CallStubBuilder callBuilder(this, glue, func, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4650     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4651     Bind(&exit);
4652     CHECK_PENDING_EXCEPTION(*result);
4653     Bind(&noNeedCheckException);
4654     Return(*result);
4655 }
4656 
GenerateCircuit()4657 void BaselineWideStmodulevarPrefImm16StubBuilder::GenerateCircuit()
4658 {
4659     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideStmodulevarPrefImm16, GLUE));
4660     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideStmodulevarPrefImm16, ACC));
4661     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideStmodulevarPrefImm16, INDEX));
4662 
4663     CallRuntime(glue, RTSTUB_ID(StModuleVarByIndex), { Int16ToTaggedInt(index), acc });
4664     Return();
4665 }
4666 
GenerateCircuit()4667 void BaselineDeprecatedCallspreadPrefV8V8V8StubBuilder::GenerateCircuit()
4668 {
4669     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallspreadPrefV8V8V8, GLUE));
4670     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallspreadPrefV8V8V8, SP));
4671     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallspreadPrefV8V8V8, V0));
4672     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallspreadPrefV8V8V8, V1));
4673     GateRef v2 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallspreadPrefV8V8V8, V2));
4674 
4675     GateRef func = GetVregValue(sp, ZExtInt8ToPtr(v0));
4676     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v1));
4677     GateRef array = GetVregValue(sp, ZExtInt8ToPtr(v2));
4678 
4679     GateRef acc = GetAccFromFrame(GetFrame(sp));
4680     GateRef res = CallRuntime(glue, RTSTUB_ID(CallSpread), { func, obj, array });
4681     CHECK_PENDING_EXCEPTION(res);
4682 }
4683 
GenerateCircuit()4684 void BaselineWideLdlocalmodulevarPrefImm16StubBuilder::GenerateCircuit()
4685 {
4686     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideLdlocalmodulevarPrefImm16, GLUE));
4687     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideLdlocalmodulevarPrefImm16, INDEX));
4688 
4689     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(LdLocalModuleVarByIndex), { Int16ToTaggedInt(index) });
4690 
4691     Return(moduleRef);
4692 }
4693 
GenerateCircuit()4694 void BaselineDeprecatedCallthisrangePrefImm16V8StubBuilder::GenerateCircuit()
4695 {
4696     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallthisrangePrefImm16V8, GLUE));
4697     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCallthisrangePrefImm16V8, SP));
4698     GateRef index = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallthisrangePrefImm16V8, INDEX));
4699     GateRef funcReg = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallthisrangePrefImm16V8, FUNC_REG));
4700     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineDeprecatedCallthisrangePrefImm16V8, HOTNESS_COUNTER));
4701     ProfileOperation callback;
4702     funcReg = ZExtInt8ToPtr(funcReg);
4703     GateRef func = GetVregValue(sp, funcReg);
4704     GateRef thisValue = GetVregValue(sp, PtrAdd(funcReg, IntPtr(1)));
4705     GateRef argv = PtrAdd(sp, PtrMul(
4706         PtrAdd(funcReg, IntPtr(2)), IntPtr(8))); // 2: skip function&this
4707     GateRef acc = GetAccFromFrame(GetFrame(sp));
4708 
4709     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
4710     auto env = GetEnvironment();
4711     Label noNeedCheckException(env);
4712     Label exit(env);
4713     GateRef actualNumArgs = Int32Sub(index, Int32(1));  // 1: exclude this
4714     GateRef jumpSize = INT_PTR(DEPRECATED_CALLTHISRANGE_PREF_IMM16_V8);
4715     GateRef numArgs = ZExtInt32ToPtr(actualNumArgs);
4716     JSCallArgs callArgs(JSCallMode::DEPRECATED_CALL_THIS_WITH_ARGV);
4717     callArgs.callArgvWithThis = { numArgs, argv, thisValue };
4718     CallStubBuilder callBuilder(this, glue, func, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
4719     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
4720     Bind(&exit);
4721     CHECK_PENDING_EXCEPTION(*result);
4722     Bind(&noNeedCheckException);
4723     Return(*result);
4724 }
4725 
GenerateCircuit()4726 void BaselineWideLdexternalmodulevarPrefImm16StubBuilder::GenerateCircuit()
4727 {
4728     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideLdexternalmodulevarPrefImm16, GLUE));
4729     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideLdexternalmodulevarPrefImm16, INDEX));
4730 
4731     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(LdExternalModuleVarByIndex), { Int16ToTaggedInt(index) });
4732     Return(moduleRef);
4733 }
4734 
4735 // GLUE, SP, METHOD_ID, LITERAL_ID, LENGTH, VREG_IDS
GenerateCircuit()4736 void BaselineDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8StubBuilder::GenerateCircuit()
4737 {
4738     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8, GLUE));
4739     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8, SP));
4740     GateRef methodId = Int32Argument(
4741         PARAM_INDEX(BaselineDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8, METHOD_ID));
4742     GateRef literalId = Int32Argument(
4743         PARAM_INDEX(BaselineDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8, LITERAL_ID));
4744     GateRef length = Int32Argument(
4745         PARAM_INDEX(BaselineDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8, LENGTH));
4746     GateRef vregIds = Int32Argument(
4747         PARAM_INDEX(BaselineDeprecatedDefineclasswithbufferPrefId16Imm16Imm16V8V8, VREG_IDS));
4748 
4749     GateRef vRegId0 = Int32And(vregIds, Int32(ONE_BYTE_ALL_ONE));
4750     GateRef vregId1 = Int32And(Int32LSR(vregIds, Int32(ONE_BYTE_SIZE)), Int32(ONE_BYTE_ALL_ONE));
4751 
4752     GateRef frame = GetFrame(sp);
4753     GateRef currentFunc = GetFunctionFromFrame(frame);
4754     GateRef method = GetMethodFromFunction(currentFunc);
4755     GateRef constpool = GetConstpoolFromMethod(method);
4756     GateRef lexicalEnv = GetVregValue(sp, ZExtInt32ToPtr(vRegId0));
4757     GateRef proto = GetVregValue(sp, ZExtInt32ToPtr(vregId1));
4758 
4759     GateRef acc = GetAccFromFrame(frame);
4760     auto env = GetEnvironment();
4761     GateRef module = GetModuleFromFunction(currentFunc);
4762     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateClassWithBuffer),
4763                               { proto, lexicalEnv, constpool,
4764                                 IntToTaggedInt(methodId),
4765                                 IntToTaggedInt(literalId), module,
4766                                 IntToTaggedInt(length)});
4767 
4768     Label isException(env);
4769     Label isNotException(env);
4770     Branch(TaggedIsException(res), &isException, &isNotException);
4771     Bind(&isException);
4772     {
4773         DISPATCH_LAST_WITH_ACC();
4774         Return(res);
4775     }
4776     Bind(&isNotException);
4777     Return(res);
4778 }
4779 
GenerateCircuit()4780 void BaselineWideLdpatchvarPrefImm16StubBuilder::GenerateCircuit()
4781 {
4782     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideLdpatchvarPrefImm16, GLUE));
4783     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideLdpatchvarPrefImm16, SP));
4784     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideLdpatchvarPrefImm16, INDEX));
4785 
4786     GateRef result = CallRuntime(glue, RTSTUB_ID(LdPatchVar), { Int16ToTaggedInt(index) });
4787     CHECK_EXCEPTION_RETURN(result);
4788 }
4789 
GenerateCircuit()4790 void BaselineDeprecatedResumegeneratorPrefV8StubBuilder::GenerateCircuit()
4791 {
4792     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedResumegeneratorPrefV8, GLUE));
4793     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedResumegeneratorPrefV8, SP));
4794     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedResumegeneratorPrefV8, ACC));
4795     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedResumegeneratorPrefV8, V0));
4796     (void)glue;
4797     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v0));
4798 
4799     auto env = GetEnvironment();
4800     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
4801 #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
4802     GateRef curFunc = GetFunctionFromFrame(GetFrame(sp));
4803     CallNGCRuntime(glue, RTSTUB_ID(StartCallTimer), { glue, curFunc, False() });
4804 #endif
4805 
4806     Label isAsyncGeneratorObj(env);
4807     Label notAsyncGeneratorObj(env);
4808     Label dispatch(env);
4809     Branch(TaggedIsAsyncGeneratorObject(obj), &isAsyncGeneratorObj, &notAsyncGeneratorObj);
4810     Bind(&isAsyncGeneratorObj);
4811     {
4812         GateRef resumeResultOffset = IntPtr(JSAsyncGeneratorObject::GENERATOR_RESUME_RESULT_OFFSET);
4813         varAcc = Load(VariableType::JS_ANY(), obj, resumeResultOffset);
4814         Jump(&dispatch);
4815     }
4816     Bind(&notAsyncGeneratorObj);
4817     {
4818         GateRef resumeResultOffset = IntPtr(JSGeneratorObject::GENERATOR_RESUME_RESULT_OFFSET);
4819         varAcc = Load(VariableType::JS_ANY(), obj, resumeResultOffset);
4820         Jump(&dispatch);
4821     }
4822     Bind(&dispatch);
4823     Return(*varAcc);
4824 }
4825 
GenerateCircuit()4826 void BaselineWideStpatchvarPrefImm16StubBuilder::GenerateCircuit()
4827 {
4828     GateRef glue = PtrArgument(PARAM_INDEX(BaselineWideStpatchvarPrefImm16, GLUE));
4829     GateRef sp = PtrArgument(PARAM_INDEX(BaselineWideStpatchvarPrefImm16, SP));
4830     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineWideStpatchvarPrefImm16, ACC));
4831     GateRef index = Int32Argument(PARAM_INDEX(BaselineWideStpatchvarPrefImm16, INDEX));
4832 
4833     GateRef result = CallRuntime(glue, RTSTUB_ID(StPatchVar), { Int16ToTaggedInt(index), acc });
4834     CHECK_EXCEPTION(result);
4835 }
4836 
GenerateCircuit()4837 void BaselineDeprecatedGetresumemodePrefV8StubBuilder::GenerateCircuit()
4838 {
4839     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedGetresumemodePrefV8, SP));
4840     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedGetresumemodePrefV8, ACC));
4841     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedGetresumemodePrefV8, V0));
4842     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v0));
4843 
4844     auto env = GetEnvironment();
4845     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
4846 
4847     Label isAsyncGeneratorObj(env);
4848     Label notAsyncGeneratorObj(env);
4849     Label dispatch(env);
4850     Branch(TaggedIsAsyncGeneratorObject(obj), &isAsyncGeneratorObj, &notAsyncGeneratorObj);
4851     Bind(&isAsyncGeneratorObj);
4852     {
4853         varAcc = IntToTaggedPtr(GetResumeModeFromAsyncGeneratorObject(obj));
4854         Jump(&dispatch);
4855     }
4856     Bind(&notAsyncGeneratorObj);
4857     {
4858         varAcc = IntToTaggedPtr(GetResumeModeFromGeneratorObject(obj));
4859         Jump(&dispatch);
4860     }
4861     Bind(&dispatch);
4862     Return(*varAcc);
4863 }
4864 
GenerateCircuit()4865 void BaselineDeprecatedGettemplateobjectPrefV8StubBuilder::GenerateCircuit()
4866 {
4867     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedGettemplateobjectPrefV8, GLUE));
4868     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedGettemplateobjectPrefV8, SP));
4869     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedGettemplateobjectPrefV8, V0));
4870     GateRef literal = GetVregValue(sp, ZExtInt8ToPtr(v0));
4871 
4872     GateRef frame = GetFrame(sp);
4873     GateRef acc = GetAccFromFrame(frame);
4874     GateRef result = CallRuntime(glue, RTSTUB_ID(GetTemplateObject), { literal });
4875     CHECK_EXCEPTION_WITH_ACC(result);
4876 }
4877 
GenerateCircuit()4878 void BaselineDeprecatedDelobjpropPrefV8V8StubBuilder::GenerateCircuit()
4879 {
4880     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedDelobjpropPrefV8V8, GLUE));
4881     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedDelobjpropPrefV8V8, SP));
4882     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedDelobjpropPrefV8V8, V0));
4883     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedDelobjpropPrefV8V8, V1));
4884 
4885     GateRef frame = GetFrame(sp);
4886     GateRef acc = GetAccFromFrame(frame);
4887     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v0));
4888     GateRef prop = GetVregValue(sp, ZExtInt8ToPtr(v1));
4889 
4890     GateRef result = CallRuntime(glue, RTSTUB_ID(DelObjProp), { obj, prop });
4891     CHECK_EXCEPTION_WITH_ACC(result);
4892 }
4893 
4894 // GLUE, SP, PC, V0, V1
GenerateCircuit()4895 void BaselineDeprecatedSuspendgeneratorPrefV8V8StubBuilder::GenerateCircuit()
4896 {
4897     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedSuspendgeneratorPrefV8V8, GLUE));
4898     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedSuspendgeneratorPrefV8V8, SP));
4899     GateRef curPcOffset = Int32Argument(PARAM_INDEX(BaselineDeprecatedSuspendgeneratorPrefV8V8, OFFSET));
4900     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedSuspendgeneratorPrefV8V8, V0));
4901     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedSuspendgeneratorPrefV8V8, V1));
4902     ProfileOperation callback;
4903 
4904     GateRef frame = GetFrame(sp);
4905     GateRef func = GetFunctionFromFrame(frame);
4906     GateRef method = GetMethodFromFunction(func);
4907     GateRef constpool = GetConstpoolFromMethod(method);
4908     GateRef acc = GetAccFromFrame(frame);
4909     GateRef hotnessCounter = GetHotnessCounterFromMethod(method);
4910     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(func);
4911 
4912     auto env = GetEnvironment();
4913     DEFVARIABLE(varSp, VariableType::NATIVE_POINTER(), sp);
4914     DEFVARIABLE(prevState, VariableType::NATIVE_POINTER(), sp);
4915     DEFVARIABLE(varConstpool, VariableType::JS_POINTER(), constpool);
4916     DEFVARIABLE(varProfileTypeInfo, VariableType::JS_POINTER(), profileTypeInfo);
4917     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
4918     DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter);
4919     GateRef genObj = GetVregValue(sp, ZExtInt8ToPtr(v0));
4920     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v1));
4921 
4922     Label isBaselineBuiltinFrame(env);
4923     Label notBaselineBuiltinFrame(env);
4924     Label pcEqualNullptr(env);
4925     Label pcNotEqualNullptr(env);
4926     Label pcEqualBaseline(env);
4927     Label pcNotEqualBaseline(env);
4928     Label updateHotness(env);
4929     Label isStable(env);
4930     Label tryContinue(env);
4931     Label dispatch(env);
4932     Label slowPath(env);
4933 
4934     GateRef res = CallRuntime(glue, RTSTUB_ID(SuspendGenerator), { genObj, value });
4935     Label isException(env);
4936     Label notException(env);
4937     Branch(TaggedIsException(res), &isException, &notException);
4938     Bind(&isException);
4939     {
4940         DISPATCH_LAST();
4941         Return();
4942     }
4943     Bind(&notException);
4944     varAcc = res;
4945     Branch(TaggedIsUndefined(*varProfileTypeInfo), &updateHotness, &isStable);
4946     Bind(&isStable);
4947     {
4948         Branch(ProfilerStubBuilder(env).IsProfileTypeInfoDumped(*varProfileTypeInfo, callback), &tryContinue,
4949             &updateHotness);
4950     }
4951     Bind(&updateHotness);
4952     {
4953         GateRef offset = Int32Not(curPcOffset);
4954         UPDATE_HOTNESS(*varSp, callback);
4955         SetHotnessCounter(glue, method, *varHotnessCounter);
4956         Jump(&tryContinue);
4957     }
4958 
4959     Bind(&tryContinue);
4960 #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
4961     GateRef curFunc = GetFunctionFromFrame(frame);
4962     CallNGCRuntime(glue, RTSTUB_ID(EndCallTimer), { glue, curFunc });
4963 #endif
4964     GateRef currentSp = *varSp;
4965     varSp = Load(VariableType::NATIVE_POINTER(), frame,
4966         IntPtr(AsmInterpretedFrame::GetBaseOffset(env->IsArch32Bit())));
4967     GateRef typePos = PtrSub(*varSp, IntPtr(JSTaggedValue::TaggedTypeSize()));
4968     GateRef maybeFrameType = Load(VariableType::INT64(), typePos);
4969     BRANCH(Int64Equal(maybeFrameType, Int64(static_cast<int64_t>(FrameType::BASELINE_BUILTIN_FRAME))),
4970            &isBaselineBuiltinFrame, &notBaselineBuiltinFrame);
4971     Bind(&isBaselineBuiltinFrame);
4972     {
4973         varSp = Load(VariableType::NATIVE_POINTER(), *varSp);
4974         Jump(&notBaselineBuiltinFrame);
4975     }
4976     Bind(&notBaselineBuiltinFrame);
4977     prevState = GetFrame(*varSp);
4978     GateRef varPc = GetPcFromFrame(*prevState);
4979     Branch(IntPtrEqual(varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr);
4980     Bind(&pcEqualNullptr);
4981     {
4982         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { currentSp });
4983         Return();
4984     }
4985     Bind(&pcNotEqualNullptr);
4986     BRANCH(IntPtrEqual(varPc, IntPtr(BASELINEJIT_PC_FLAG)), &pcEqualBaseline, &pcNotEqualBaseline);
4987     Bind(&pcEqualBaseline);
4988     {
4989         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturnBaseline), { *varAcc, *varSp, currentSp });
4990         Return();
4991     }
4992     Bind(&pcNotEqualBaseline);
4993     {
4994         GateRef function = GetFunctionFromFrame(*prevState);
4995         GateRef prevMethod = Load(VariableType::JS_ANY(), function, IntPtr(JSFunctionBase::METHOD_OFFSET));
4996         varConstpool = GetConstpoolFromMethod(prevMethod);
4997         varProfileTypeInfo = GetProfileTypeInfoFromFunction(function);
4998         varHotnessCounter = GetHotnessCounterFromMethod(prevMethod);
4999         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
5000         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch),
5001             { glue, currentSp, varPc, *varConstpool, *varProfileTypeInfo,
5002             *varAcc, *varHotnessCounter, jumpSize });
5003         Return();
5004     }
5005 }
5006 
GenerateCircuit()5007 void BaselineDeprecatedAsyncfunctionawaituncaughtPrefV8V8StubBuilder::GenerateCircuit()
5008 {
5009     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionawaituncaughtPrefV8V8, GLUE));
5010     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionawaituncaughtPrefV8V8, SP));
5011     GateRef v0 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionawaituncaughtPrefV8V8, V0));
5012     GateRef v1 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionawaituncaughtPrefV8V8, V1));
5013     GateRef asyncFuncObj = GetVregValue(sp, ZExtInt8ToPtr(v0));
5014     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v1));
5015 
5016     GateRef frame = GetFrame(sp);
5017     GateRef acc = GetAccFromFrame(frame);
5018     GateRef result = CallRuntime(glue, RTSTUB_ID(AsyncFunctionAwaitUncaught), { asyncFuncObj, value });
5019     CHECK_EXCEPTION_WITH_ACC(result);
5020 }
5021 
GenerateCircuit()5022 void BaselineDeprecatedCopydatapropertiesPrefV8V8StubBuilder::GenerateCircuit()
5023 {
5024     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCopydatapropertiesPrefV8V8, GLUE));
5025     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCopydatapropertiesPrefV8V8, SP));
5026     GateRef v0 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedCopydatapropertiesPrefV8V8, V0));
5027     GateRef v1 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedCopydatapropertiesPrefV8V8, V1));
5028     GateRef dst = GetVregValue(sp, ZExtInt8ToPtr(v0));
5029     GateRef src = GetVregValue(sp, ZExtInt8ToPtr(v1));
5030 
5031     GateRef frame = GetFrame(sp);
5032     GateRef acc = GetAccFromFrame(frame);
5033     GateRef result = CallRuntime(glue, RTSTUB_ID(CopyDataProperties), { dst, src });
5034     CHECK_EXCEPTION_WITH_ACC(result);
5035 }
5036 
GenerateCircuit()5037 void BaselineDeprecatedSetobjectwithprotoPrefV8V8StubBuilder::GenerateCircuit()
5038 {
5039     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedSetobjectwithprotoPrefV8V8, GLUE));
5040     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedSetobjectwithprotoPrefV8V8, SP));
5041     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedSetobjectwithprotoPrefV8V8, ACC));
5042     GateRef v0 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedSetobjectwithprotoPrefV8V8, V0));
5043     GateRef v1 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedSetobjectwithprotoPrefV8V8, V1));
5044 
5045     GateRef proto = GetVregValue(sp, ZExtInt8ToPtr(v0));
5046     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v1));
5047 
5048     auto env = GetEnvironment();
5049     GateRef result = CallRuntime(glue, RTSTUB_ID(SetObjectWithProto), { proto, obj });
5050     Label notException(env);
5051     CHECK_EXCEPTION_WITH_JUMP_RETURN(result, &notException);
5052     Bind(&notException);
5053     Return(result);
5054 }
5055 
GenerateCircuit()5056 void BaselineDeprecatedLdobjbyvaluePrefV8V8StubBuilder::GenerateCircuit()
5057 {
5058     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdobjbyvaluePrefV8V8, GLUE));
5059     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdobjbyvaluePrefV8V8, SP));
5060     GateRef v0 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedLdobjbyvaluePrefV8V8, V0));
5061     GateRef v1 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedLdobjbyvaluePrefV8V8, V1));
5062     GateRef receiver = GetVregValue(sp, ZExtInt8ToPtr(v0));
5063     GateRef propKey = GetVregValue(sp, ZExtInt8ToPtr(v1));
5064 
5065     AccessObjectStubBuilder builder(this);
5066     GateRef result = builder.DeprecatedLoadObjByValue(glue, receiver, propKey);
5067     CHECK_EXCEPTION_RETURN(result);
5068 }
5069 
GenerateCircuit()5070 void BaselineDeprecatedLdsuperbyvaluePrefV8V8StubBuilder::GenerateCircuit()
5071 {
5072     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdsuperbyvaluePrefV8V8, GLUE));
5073     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdsuperbyvaluePrefV8V8, SP));
5074     GateRef v0 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedLdsuperbyvaluePrefV8V8, V0));
5075     GateRef v1 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedLdsuperbyvaluePrefV8V8, V1));
5076 
5077     GateRef frame = GetFrame(sp);
5078     GateRef acc = GetAccFromFrame(frame);
5079     GateRef receiver = GetVregValue(sp, ZExtInt8ToPtr(v0));
5080     GateRef propKey = GetVregValue(sp, ZExtInt8ToPtr(v1));
5081 
5082     GateRef result = CallRuntime(glue, RTSTUB_ID(LdSuperByValue), {  receiver, propKey }); // sp for thisFunc
5083     CHECK_EXCEPTION_WITH_ACC(result);
5084 }
5085 
GenerateCircuit()5086 void BaselineDeprecatedLdobjbyindexPrefV8Imm32StubBuilder::GenerateCircuit()
5087 {
5088     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdobjbyindexPrefV8Imm32, GLUE));
5089     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdobjbyindexPrefV8Imm32, SP));
5090     GateRef v0 =  Int32Argument(PARAM_INDEX(BaselineDeprecatedLdobjbyindexPrefV8Imm32, V0));
5091     GateRef index = Int32Argument(PARAM_INDEX(BaselineDeprecatedLdobjbyindexPrefV8Imm32, INDEX));
5092     GateRef receiver = GetVregValue(sp, ZExtInt8ToPtr(v0));
5093 
5094     GateRef frame = GetFrame(sp);
5095     GateRef acc = GetAccFromFrame(frame);
5096     auto env = GetEnvironment();
5097     Label fastPath(env);
5098     Label slowPath(env);
5099     Branch(TaggedIsHeapObject(receiver), &fastPath, &slowPath);
5100     Bind(&fastPath);
5101     {
5102         ProfileOperation callback;
5103         GateRef result = GetPropertyByIndex(glue, receiver, index, callback);
5104         Label notHole(env);
5105         Branch(TaggedIsHole(result), &slowPath, &notHole);
5106         Bind(&notHole);
5107         CHECK_EXCEPTION_WITH_ACC(result);
5108     }
5109     Bind(&slowPath);
5110     {
5111         GateRef result = CallRuntime(glue, RTSTUB_ID(LdObjByIndex),
5112                                      { receiver, IntToTaggedInt(index), TaggedFalse(), Undefined() });
5113         CHECK_EXCEPTION_WITH_ACC(result);
5114     }
5115 }
5116 
GenerateCircuit()5117 void BaselineDeprecatedAsyncfunctionresolvePrefV8V8V8StubBuilder::GenerateCircuit()
5118 {
5119     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionresolvePrefV8V8V8, GLUE));
5120     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionresolvePrefV8V8V8, SP));
5121     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionresolvePrefV8V8V8, V0));
5122     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionresolvePrefV8V8V8, V1));
5123 
5124     GateRef asyncFuncObj = GetVregValue(sp, ZExtInt8ToPtr(v0));
5125     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v1));
5126 
5127     GateRef frame = GetFrame(sp);
5128     GateRef acc = GetAccFromFrame(frame);
5129     GateRef res = CallRuntime(glue, RTSTUB_ID(AsyncFunctionResolveOrReject),
5130                               { asyncFuncObj, value, TaggedTrue() });
5131     CHECK_EXCEPTION_WITH_ACC(res);
5132 }
5133 
GenerateCircuit()5134 void BaselineDeprecatedAsyncfunctionrejectPrefV8V8V8StubBuilder::GenerateCircuit()
5135 {
5136     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionrejectPrefV8V8V8, GLUE));
5137     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionrejectPrefV8V8V8, SP));
5138     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionrejectPrefV8V8V8, V0));
5139     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineDeprecatedAsyncfunctionrejectPrefV8V8V8, V1));
5140 
5141     GateRef frame = GetFrame(sp);
5142     GateRef acc = GetAccFromFrame(frame);
5143     GateRef asyncFuncObj = GetVregValue(sp, ZExtInt8ToPtr(v0));
5144     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v1));
5145     GateRef res = CallRuntime(glue, RTSTUB_ID(AsyncFunctionResolveOrReject),
5146                               { asyncFuncObj, value, TaggedFalse() });
5147     CHECK_EXCEPTION_WITH_ACC(res);
5148 }
5149 
GenerateCircuit()5150 void BaselineDeprecatedStlexvarPrefImm4Imm4V8StubBuilder::GenerateCircuit()
5151 {
5152     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm4Imm4V8, GLUE));
5153     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm4Imm4V8, SP));
5154     GateRef level = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm4Imm4V8, LEVEL));
5155     GateRef slot = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm4Imm4V8, SLOT));
5156     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm4Imm4V8, V0));
5157 
5158     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0));
5159     GateRef state = GetFrame(sp);
5160 
5161     auto env = GetEnvironment();
5162     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(state));
5163     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
5164 
5165     Label loopHead(env);
5166     Label loopEnd(env);
5167     Label afterLoop(env);
5168     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
5169     LoopBegin(&loopHead);
5170     currentEnv = GetParentEnv(*currentEnv);
5171     i = Int32Add(*i, Int32(1));
5172     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
5173     Bind(&loopEnd);
5174     LoopEnd(&loopHead);
5175     Bind(&afterLoop);
5176     SetPropertiesToLexicalEnv(glue, *currentEnv, slot, value);
5177     Return();
5178 }
5179 
GenerateCircuit()5180 void BaselineDeprecatedStlexvarPrefImm8Imm8V8StubBuilder::GenerateCircuit()
5181 {
5182     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm8Imm8V8, GLUE));
5183     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm8Imm8V8, SP));
5184     GateRef level = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm8Imm8V8, LEVEL));
5185     GateRef slot = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm8Imm8V8, SLOT));
5186     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm8Imm8V8, V0));
5187 
5188     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0));
5189     GateRef state = GetFrame(sp);
5190 
5191     auto env = GetEnvironment();
5192     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(state));
5193     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
5194 
5195     Label loopHead(env);
5196     Label loopEnd(env);
5197     Label afterLoop(env);
5198     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
5199     LoopBegin(&loopHead);
5200     currentEnv = GetParentEnv(*currentEnv);
5201     i = Int32Add(*i, Int32(1));
5202     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
5203     Bind(&loopEnd);
5204     LoopEnd(&loopHead);
5205     Bind(&afterLoop);
5206     SetPropertiesToLexicalEnv(glue, *currentEnv, slot, value);
5207     Return();
5208 }
5209 
GenerateCircuit()5210 void BaselineDeprecatedStlexvarPrefImm16Imm16V8StubBuilder::GenerateCircuit()
5211 {
5212     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm16Imm16V8, GLUE));
5213     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm16Imm16V8, SP));
5214     GateRef level = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm16Imm16V8, LEVEL));
5215     GateRef slot = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm16Imm16V8, SLOT));
5216     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlexvarPrefImm16Imm16V8, V0));
5217 
5218     GateRef value = GetVregValue(sp, ZExtInt8ToPtr(v0));
5219     GateRef state = GetFrame(sp);
5220     auto env = GetEnvironment();
5221     DEFVARIABLE(currentEnv, VariableType::JS_ANY(), GetEnvFromFrame(state));
5222     DEFVARIABLE(i, VariableType::INT32(), Int32(0));
5223 
5224     Label loopHead(env);
5225     Label loopEnd(env);
5226     Label afterLoop(env);
5227     Branch(Int32LessThan(*i, level), &loopHead, &afterLoop);
5228     LoopBegin(&loopHead);
5229     currentEnv = GetParentEnv(*currentEnv);
5230     i = Int32Add(*i, Int32(1));
5231     Branch(Int32LessThan(*i, level), &loopEnd, &afterLoop);
5232     Bind(&loopEnd);
5233     LoopEnd(&loopHead);
5234     Bind(&afterLoop);
5235     SetPropertiesToLexicalEnv(glue, *currentEnv, slot, value);
5236     Return();
5237 }
5238 
GenerateCircuit()5239 void BaselineDeprecatedGetmodulenamespacePrefId32StubBuilder::GenerateCircuit()
5240 {
5241     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedGetmodulenamespacePrefId32, GLUE));
5242     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedGetmodulenamespacePrefId32, STRING_ID));
5243     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedGetmodulenamespacePrefId32, SP));
5244 
5245     GateRef func = GetFunctionFromFrame(GetFrame(sp));
5246     GateRef method = GetMethodFromFunction(func);
5247     GateRef constpool = GetConstpoolFromMethod(method);
5248     GateRef prop = GetStringFromConstPool(glue, constpool, stringId);
5249     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(GetModuleNamespace), { prop });
5250     Return(moduleRef);
5251 }
5252 
GenerateCircuit()5253 void BaselineDeprecatedStmodulevarPrefId32StubBuilder::GenerateCircuit()
5254 {
5255     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedStmodulevarPrefId32, GLUE));
5256     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedStmodulevarPrefId32, ACC));
5257     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedStmodulevarPrefId32, STRING_ID));
5258     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedStmodulevarPrefId32, SP));
5259 
5260     GateRef func = GetFunctionFromFrame(GetFrame(sp));
5261     GateRef method = GetMethodFromFunction(func);
5262     GateRef constpool = GetConstpoolFromMethod(method);
5263     GateRef prop = GetStringFromConstPool(glue, constpool, stringId);
5264 
5265     CallRuntime(glue, RTSTUB_ID(StModuleVar), { prop, acc });
5266     Return();
5267 }
5268 
GenerateCircuit()5269 void BaselineDeprecatedLdobjbynamePrefId32V8StubBuilder::GenerateCircuit()
5270 {
5271     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdobjbynamePrefId32V8, GLUE));
5272     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdobjbynamePrefId32V8, SP));
5273     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedLdobjbynamePrefId32V8, V0));
5274     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedLdobjbynamePrefId32V8, STRING_ID));
5275 
5276     GateRef frame = GetFrame(sp);
5277     GateRef func = GetFunctionFromFrame(frame);
5278     GateRef method = GetMethodFromFunction(func);
5279     GateRef constpool = GetConstpoolFromMethod(method);
5280     GateRef receiver = GetVregValue(sp, ZExtInt8ToPtr(v0));
5281     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
5282     AccessObjectStubBuilder builder(this);
5283     GateRef result = builder.DeprecatedLoadObjByName(glue, receiver, propKey);
5284     CHECK_EXCEPTION_RETURN(result);
5285 }
5286 
GenerateCircuit()5287 void BaselineDeprecatedLdsuperbynamePrefId32V8StubBuilder::GenerateCircuit()
5288 {
5289     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdsuperbynamePrefId32V8, GLUE));
5290     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdsuperbynamePrefId32V8, SP));
5291     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedLdsuperbynamePrefId32V8, STRING_ID));
5292     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDeprecatedLdsuperbynamePrefId32V8, V0));
5293 
5294     GateRef frame = GetFrame(sp);
5295     GateRef func = GetFunctionFromFrame(frame);
5296     GateRef method = GetMethodFromFunction(func);
5297     GateRef constpool = GetConstpoolFromMethod(method);
5298     GateRef receiver = GetVregValue(sp, ZExtInt8ToPtr(v0));
5299     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
5300     GateRef result = CallRuntime(glue, RTSTUB_ID(LdSuperByValue), { receiver, propKey });
5301     CHECK_EXCEPTION_RETURN(result);
5302 }
5303 
GenerateCircuit()5304 void BaselineDeprecatedLdmodulevarPrefId32Imm8StubBuilder::GenerateCircuit()
5305 {
5306     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdmodulevarPrefId32Imm8, GLUE));
5307     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedLdmodulevarPrefId32Imm8, STRING_ID));
5308     GateRef flagI8 = Int32Argument(PARAM_INDEX(BaselineDeprecatedLdmodulevarPrefId32Imm8, FLAG_I8));
5309     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdmodulevarPrefId32Imm8, SP));
5310     GateRef flag = ZExtInt8ToInt32(flagI8);
5311 
5312     GateRef func = GetFunctionFromFrame(GetFrame(sp));
5313     GateRef method = GetMethodFromFunction(func);
5314     GateRef constpool = GetConstpoolFromMethod(method);
5315     GateRef key = GetStringFromConstPool(glue, constpool, stringId);
5316     GateRef moduleRef = CallRuntime(glue, RTSTUB_ID(LdModuleVar), { key, IntToTaggedInt(flag) });
5317     Return(moduleRef);
5318 }
5319 
GenerateCircuit()5320 void BaselineDeprecatedStconsttoglobalrecordPrefId32StubBuilder::GenerateCircuit()
5321 {
5322     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedStconsttoglobalrecordPrefId32, GLUE));
5323     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedStconsttoglobalrecordPrefId32, ACC));
5324     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedStconsttoglobalrecordPrefId32, STRING_ID));
5325     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedStconsttoglobalrecordPrefId32, SP));
5326 
5327     GateRef frame = GetFrame(sp);
5328     GateRef func = GetFunctionFromFrame(frame);
5329     GateRef method = GetMethodFromFunction(func);
5330     GateRef constpool = GetConstpoolFromMethod(method);
5331     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
5332     GateRef result = CallRuntime(glue, RTSTUB_ID(StGlobalRecord),
5333                                  { propKey, acc, TaggedTrue() });
5334     CHECK_EXCEPTION_RETURN(result);
5335 }
5336 
GenerateCircuit()5337 void BaselineDeprecatedStlettoglobalrecordPrefId32StubBuilder::GenerateCircuit()
5338 {
5339     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlettoglobalrecordPrefId32, GLUE));
5340     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedStlettoglobalrecordPrefId32, ACC));
5341     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedStlettoglobalrecordPrefId32, STRING_ID));
5342     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedStlettoglobalrecordPrefId32, SP));
5343 
5344     GateRef frame = GetFrame(sp);
5345     GateRef func = GetFunctionFromFrame(frame);
5346     GateRef method = GetMethodFromFunction(func);
5347     GateRef constpool = GetConstpoolFromMethod(method);
5348     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
5349     GateRef result = CallRuntime(glue, RTSTUB_ID(StGlobalRecord),
5350                                  { propKey, acc, TaggedFalse() });
5351     CHECK_EXCEPTION_RETURN(result);
5352 }
5353 
GenerateCircuit()5354 void BaselineDeprecatedStclasstoglobalrecordPrefId32StubBuilder::GenerateCircuit()
5355 {
5356     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedStclasstoglobalrecordPrefId32, GLUE));
5357     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedStclasstoglobalrecordPrefId32, ACC));
5358     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDeprecatedStclasstoglobalrecordPrefId32, STRING_ID));
5359     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedStclasstoglobalrecordPrefId32, SP));
5360 
5361     GateRef frame = GetFrame(sp);
5362     GateRef func = GetFunctionFromFrame(frame);
5363     GateRef method = GetMethodFromFunction(func);
5364     GateRef constpool = GetConstpoolFromMethod(method);
5365     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
5366     GateRef result = CallRuntime(glue, RTSTUB_ID(StGlobalRecord),
5367                                  { propKey, acc, TaggedFalse() });
5368     CHECK_EXCEPTION_RETURN(result);
5369 }
5370 
5371 // SP
GenerateCircuit()5372 void BaselineDeprecatedLdhomeobjectPrefNoneStubBuilder::GenerateCircuit()
5373 {
5374     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedLdhomeobjectPrefNone, SP));
5375 
5376     GateRef state = GetFunctionFromFrame(GetFrame(sp));
5377     GateRef result = GetHomeObjectFromJSFunction(state);
5378     Return(result);
5379 }
5380 
GenerateCircuit()5381 void BaselineDeprecatedCreateobjecthavingmethodPrefImm16StubBuilder::GenerateCircuit()
5382 {
5383     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedCreateobjecthavingmethodPrefImm16, GLUE));
5384     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedCreateobjecthavingmethodPrefImm16, ACC));
5385     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedCreateobjecthavingmethodPrefImm16, SP));
5386     GateRef immI16 = Int32Argument(PARAM_INDEX(BaselineDeprecatedCreateobjecthavingmethodPrefImm16, IMM_I16));
5387     GateRef imm = ZExtInt16ToInt32(immI16);
5388 
5389     GateRef func = GetFunctionFromFrame(GetFrame(sp));
5390     GateRef method = GetMethodFromFunction(func);
5391     GateRef constpool = GetConstpoolFromMethod(method);
5392     GateRef module = GetModuleFromFunction(func);
5393     GateRef result = GetObjectLiteralFromConstPool(glue, constpool, imm, module);
5394     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateObjectHavingMethod), { result, acc });
5395     CHECK_EXCEPTION_WITH_ACC(res);
5396 }
5397 
GenerateCircuit()5398 void BaselineDeprecatedDynamicimportPrefV8StubBuilder::GenerateCircuit()
5399 {
5400     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDeprecatedDynamicimportPrefV8, GLUE));
5401     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDeprecatedDynamicimportPrefV8, SP));
5402     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineDeprecatedDynamicimportPrefV8, ACC));
5403     GateRef specifier = TaggedArgument(PARAM_INDEX(BaselineDeprecatedDynamicimportPrefV8, VREG));
5404 
5405     GateRef currentFunc = GetFunctionFromFrame(GetFrame(sp));
5406     GateRef res = CallRuntime(glue, RTSTUB_ID(DynamicImport), { specifier, currentFunc });
5407     CHECK_EXCEPTION_WITH_ACC(res);
5408 }
5409 
GenerateCircuit()5410 void BaselineCallRuntimeNotifyConcurrentResultPrefNoneStubBuilder::GenerateCircuit()
5411 {
5412     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeNotifyConcurrentResultPrefNone, GLUE));
5413     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeNotifyConcurrentResultPrefNone, SP));
5414     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeNotifyConcurrentResultPrefNone, ACC));
5415 
5416     GateRef funcObj = GetFunctionFromFrame(GetFrame(sp));
5417     CallRuntime(glue, RTSTUB_ID(NotifyConcurrentResult), {acc, funcObj});
5418     Return();
5419 }
5420 
5421 // GLUE, SP, SLOT_ID, STRING_ID, V0
GenerateCircuit()5422 void BaselineDefineFieldByNameImm8Id16V8StubBuilder::GenerateCircuit()
5423 {
5424     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefineFieldByNameImm8Id16V8, GLUE));
5425     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefineFieldByNameImm8Id16V8, SP));
5426     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineDefineFieldByNameImm8Id16V8, SLOT_ID));
5427     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDefineFieldByNameImm8Id16V8, STRING_ID));
5428     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDefineFieldByNameImm8Id16V8, V0));
5429 
5430     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
5431     GateRef acc = GetAccFromFrame(frame);
5432     GateRef method = GetMethodFromFunction(curFunc);
5433     GateRef constpool = GetConstpoolFromMethod(method);
5434     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(v0));
5435 
5436     auto env = GetEnvironment();
5437     GateRef propKey = GetStringFromConstPool(glue, constpool, stringId);
5438     DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
5439     DEFINE_BY_NAME(Boolean(false));
5440     CHECK_EXCEPTION_WITH_ACC(*result);
5441 }
5442 
5443 
5444 // GLUE, SP, SLOT_ID, STRING_ID, V0
GenerateCircuit()5445 void BaselineDefinePropertyByNameImm8Id16V8StubBuilder::GenerateCircuit()
5446 {
5447     GateRef glue = PtrArgument(PARAM_INDEX(BaselineDefinePropertyByNameImm8Id16V8, GLUE));
5448     GateRef sp = PtrArgument(PARAM_INDEX(BaselineDefinePropertyByNameImm8Id16V8, SP));
5449     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineDefinePropertyByNameImm8Id16V8, SLOT_ID));
5450     GateRef stringId = Int32Argument(PARAM_INDEX(BaselineDefinePropertyByNameImm8Id16V8, STRING_ID));
5451     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineDefinePropertyByNameImm8Id16V8, V0));
5452 
5453     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
5454     GateRef acc = GetAccFromFrame(frame);
5455     GateRef method = GetMethodFromFunction(curFunc);
5456     GateRef constpool = GetConstpoolFromMethod(method);
5457     GateRef receiver = GetVregValue(sp, ZExtInt32ToPtr(v0));
5458 
5459     auto env = GetEnvironment();
5460     GateRef propKey = GetStringFromConstPool(glue, constpool, ZExtInt16ToInt32(stringId));
5461     DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
5462     DEFINE_BY_NAME(Boolean(true));
5463     CHECK_EXCEPTION_WITH_ACC(*result);
5464 }
5465 
GenerateCircuit()5466 void BaselineCallRuntimeDefineFieldByValuePrefImm8V8V8StubBuilder::GenerateCircuit()
5467 {
5468     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByValuePrefImm8V8V8, GLUE));
5469     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByValuePrefImm8V8V8, SP));
5470     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByValuePrefImm8V8V8, ACC));
5471     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByValuePrefImm8V8V8, V0));
5472     GateRef v1 = Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByValuePrefImm8V8V8, V1));
5473     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v1));
5474     GateRef propKey = GetVregValue(sp, ZExtInt8ToPtr(v0));
5475 
5476     GateRef res = DefineField(glue, obj, propKey, acc);
5477     CHECK_EXCEPTION_WITH_ACC(res);
5478 }
5479 
GenerateCircuit()5480 void BaselineCallRuntimeDefineFieldByIndexPrefImm8Imm32V8StubBuilder::GenerateCircuit()
5481 {
5482     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByIndexPrefImm8Imm32V8, GLUE));
5483     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByIndexPrefImm8Imm32V8, SP));
5484     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByIndexPrefImm8Imm32V8, ACC));
5485     GateRef index = Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByIndexPrefImm8Imm32V8, INDEX));
5486     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefineFieldByIndexPrefImm8Imm32V8, V0));
5487 
5488     GateRef propKey = IntToTaggedInt(index);
5489     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v0));
5490     GateRef res = DefineField(glue, obj, propKey, acc);
5491     CHECK_EXCEPTION_WITH_ACC(res);
5492 }
5493 
GenerateCircuit()5494 void BaselineCallRuntimeToPropertyKeyPrefNoneStubBuilder::GenerateCircuit()
5495 {
5496     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeToPropertyKeyPrefNone, GLUE));
5497     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeToPropertyKeyPrefNone, SP));
5498     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeToPropertyKeyPrefNone, ACC));
5499 
5500     GateRef res = CallRuntime(glue, RTSTUB_ID(ToPropertyKey), { acc });
5501     CHECK_EXCEPTION_WITH_ACC(res);
5502 }
5503 
5504 // GLUE, SP, COUNT, LITERAL_ID
GenerateCircuit()5505 void BaselineCallRuntimeCreatePrivatePropertyPrefImm16Id16StubBuilder::GenerateCircuit()
5506 {
5507     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeCreatePrivatePropertyPrefImm16Id16, GLUE));
5508     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeCreatePrivatePropertyPrefImm16Id16, SP));
5509     GateRef count = Int32Argument(PARAM_INDEX(BaselineCallRuntimeCreatePrivatePropertyPrefImm16Id16, COUNT));
5510     GateRef literalId = Int32Argument(PARAM_INDEX(BaselineCallRuntimeCreatePrivatePropertyPrefImm16Id16, LITERAL_ID));
5511 
5512     GateRef frame = GetFrame(sp);
5513     GateRef acc = GetAccFromFrame(frame);
5514     GateRef func = GetFunctionFromFrame(frame);
5515     GateRef method = GetMethodFromFunction(func);
5516     GateRef constpool = GetConstpoolFromMethod(method);
5517     GateRef lexicalEnv = GetEnvFromFrame(frame);
5518     GateRef module = GetModuleFromFunction(func);
5519     GateRef res = CallRuntime(glue, RTSTUB_ID(CreatePrivateProperty), {lexicalEnv,
5520         IntToTaggedInt(count), constpool, IntToTaggedInt(literalId), module});
5521     CHECK_EXCEPTION_WITH_ACC(res);
5522 }
5523 
5524 // GLUE, SP, ACC, LEVEL_INDEX, SLOT_INDEX, V0
GenerateCircuit()5525 void BaselineCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8StubBuilder::GenerateCircuit()
5526 {
5527     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8, GLUE));
5528     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8, SP));
5529     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8, ACC));
5530     GateRef levelIndex =
5531         Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8, LEVEL_INDEX));
5532     GateRef slotIndex =
5533         Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8, SLOT_INDEX));
5534     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefinePrivatePropertyPrefImm8Imm16Imm16V8, V0));
5535 
5536     GateRef lexicalEnv = GetEnvFromFrame(GetFrame(sp));
5537     GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(v0));
5538 
5539     GateRef res = CallRuntime(glue, RTSTUB_ID(DefinePrivateProperty), {lexicalEnv,
5540         IntToTaggedInt(levelIndex), IntToTaggedInt(slotIndex), obj, acc});  // acc as value
5541     CHECK_EXCEPTION_WITH_ACC(res);
5542 }
5543 
GenerateCircuit()5544 void BaselineCallRuntimeCallInitPrefImm8V8StubBuilder::GenerateCircuit()
5545 {
5546     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeCallInitPrefImm8V8, GLUE));
5547     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeCallInitPrefImm8V8, SP));
5548     GateRef acc = TaggedArgument(PARAM_INDEX(BaselineCallRuntimeCallInitPrefImm8V8, ACC));
5549     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineCallRuntimeCallInitPrefImm8V8, V0));
5550     GateRef hotnessCounter = Int32Argument(PARAM_INDEX(BaselineCallRuntimeCallInitPrefImm8V8, HOTNESS_COUNTER));
5551     GateRef slotId = Int32Argument(PARAM_INDEX(BaselineCallRuntimeCallInitPrefImm8V8, SLOT_ID));
5552     GateRef thisValue = GetVregValue(sp, ZExtInt8ToPtr(v0));
5553 
5554     DEFINE_PROFILE_CALLBACK(glue, sp, slotId);
5555     DEFVARIABLE(result, VariableType::JS_ANY(), Undefined());
5556     // same as callthis0
5557     GateRef actualNumArgs = Int32(EcmaInterpreter::ActualNumArgsOfCall::CALLARG0);
5558     METHOD_ENTRY(acc);
5559     Label noNeedCheckException(env);
5560     Label exit(env);
5561     GateRef jumpSize = INT_PTR(CALLRUNTIME_CALLINIT_PREF_IMM8_V8);
5562     JSCallArgs callArgs(JSCallMode::CALL_THIS_ARG0);
5563     callArgs.callArgsWithThis = { 0, 0, 0, thisValue };
5564     CallStubBuilder callBuilder(this, glue, acc, actualNumArgs, jumpSize, &result, hotnessCounter, callArgs, callback);
5565     callBuilder.JSCallDispatchForBaseline(&exit, &noNeedCheckException);
5566     Bind(&exit);
5567     CHECK_PENDING_EXCEPTION(*result);
5568     Bind(&noNeedCheckException);
5569     Return(*result);
5570 }
5571 
5572 // GLUE, SP, METHOD_ID, LITERAL_ID, LENGTH, V0
GenerateCircuit()5573 void BaselineCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8StubBuilder::GenerateCircuit()
5574 {
5575     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8, GLUE));
5576     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8, SP));
5577     GateRef methodId = Int32Argument(
5578         PARAM_INDEX(BaselineCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8, METHOD_ID));
5579     GateRef literalId = Int32Argument(
5580         PARAM_INDEX(BaselineCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8, LITERAL_ID));
5581     GateRef length = Int32Argument(
5582         PARAM_INDEX(BaselineCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8, LENGTH));
5583     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineCallRuntimeDefineSendableClassPrefImm16Id16Id16Imm16V8, V0));
5584 
5585     GateRef proto = GetVregValue(sp, ZExtInt8ToPtr(v0));
5586     GateRef frame = GetFrame(sp);
5587     GateRef currentFunc = GetFunctionFromFrame(frame);
5588 
5589     auto env = GetEnvironment();
5590     GateRef module = GetModuleFromFunction(currentFunc);
5591     // remove constpool in args
5592     GateRef res = CallRuntime(glue, RTSTUB_ID(CreateSharedClass),
5593                               { proto,
5594                                 Int16ToTaggedInt(methodId),
5595                                 Int16ToTaggedInt(literalId),
5596                                 Int16ToTaggedInt(length), module });
5597 
5598     Label isException(env);
5599     Label isNotException(env);
5600     BRANCH(TaggedIsException(res), &isException, &isNotException);
5601     Bind(&isException);
5602     {
5603         GateRef acc = GetAccFromFrame(frame);
5604         DISPATCH_LAST_WITH_ACC();
5605         Return(res);
5606     }
5607     Bind(&isNotException);
5608     Return(res);
5609 }
5610 
GenerateCircuit()5611 void BaselineCallRuntimeLdSendableClassPrefImm16StubBuilder::GenerateCircuit()
5612 {
5613     GateRef glue = PtrArgument(PARAM_INDEX(BaselineCallRuntimeLdSendableClassPrefImm16, GLUE));
5614     GateRef sp = PtrArgument(PARAM_INDEX(BaselineCallRuntimeLdSendableClassPrefImm16, SP));
5615     GateRef level = Int32Argument(PARAM_INDEX(BaselineCallRuntimeLdSendableClassPrefImm16, LEVEL));
5616     GateRef lexEnv = GetEnvFromFrame(GetFrame(sp));
5617 
5618     GateRef result = CallRuntime(glue, RTSTUB_ID(LdSendableClass), { lexEnv, Int16ToTaggedInt(level) });
5619     Return(result);
5620 }
5621 
GenerateCircuit()5622 void BaselineReturnundefinedStubBuilder::GenerateCircuit()
5623 {
5624     GateRef glue = PtrArgument(PARAM_INDEX(BaselineReturnundefined, GLUE));
5625     GateRef sp = PtrArgument(PARAM_INDEX(BaselineReturnundefined, SP));
5626     GateRef curPcOffset = Int32Argument(PARAM_INDEX(BaselineReturnundefined, OFFSET));
5627 
5628     DEFVARIABLE(varSp, VariableType::NATIVE_POINTER(), sp);
5629     GateRef frame = GetFrame(sp);
5630     GateRef acc = GetAccFromFrame(frame);
5631 
5632     auto env = GetEnvironment();
5633     GateRef pc = GetPcFromFrame(frame);
5634     GateRef curFunction = GetFunctionFromFrame(frame);
5635     GateRef curMethod =
5636         Load(VariableType::JS_ANY(), curFunction, IntPtr(JSFunctionBase::METHOD_OFFSET));
5637     GateRef constpool =
5638         Load(VariableType::JS_POINTER(), curMethod, IntPtr(Method::CONSTANT_POOL_OFFSET));
5639     GateRef raw =
5640         Load(VariableType::JS_POINTER(), curFunction, IntPtr(JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET));
5641     GateRef profileTypeInfo =
5642         Load(VariableType::JS_POINTER(), raw, IntPtr(ProfileTypeInfoCell::VALUE_OFFSET));
5643     GateRef hotnessCounter =
5644         Load(VariableType::INT16(), curMethod, IntPtr(Method::LITERAL_INFO_OFFSET));
5645     ProfileOperation callback;
5646 
5647     DEFVARIABLE(varPc, VariableType::NATIVE_POINTER(), pc);
5648     DEFVARIABLE(prevState, VariableType::NATIVE_POINTER(), sp);
5649     DEFVARIABLE(varConstpool, VariableType::JS_POINTER(), constpool);
5650     DEFVARIABLE(varProfileTypeInfo, VariableType::JS_POINTER(), profileTypeInfo);
5651     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
5652     DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter);
5653 
5654     Label isBaselineBuiltinFrame(env);
5655     Label notBaselineBuiltinFrame(env);
5656     Label pcEqualNullptr(env);
5657     Label pcNotEqualNullptr(env);
5658     Label pcEqualBaseline(env);
5659     Label pcNotEqualBaseline(env);
5660     Label updateHotness(env);
5661     Label isStable(env);
5662     Label tryContinue(env);
5663     Label dispatch(env);
5664     Label slowPath(env);
5665 
5666     BRANCH(TaggedIsUndefined(*varProfileTypeInfo), &updateHotness, &isStable);
5667     Bind(&isStable);
5668     {
5669         GateRef varProfileTypeInfoVal = *varProfileTypeInfo;
5670         GateRef isProfileDumpedAndJitCompiled = LogicAndBuilder(env)
5671             .And(ProfilerStubBuilder(env).IsProfileTypeInfoDumped(varProfileTypeInfoVal, callback))
5672             .And(ProfilerStubBuilder(env).IsCompiledOrTryCompile(
5673                 glue, GetFunctionFromFrame(frame), varProfileTypeInfoVal, callback))
5674             .Done();
5675         BRANCH(isProfileDumpedAndJitCompiled, &tryContinue, &updateHotness);
5676     }
5677     Bind(&updateHotness);
5678     {
5679         GateRef offset = Int32Not(curPcOffset);
5680         UPDATE_HOTNESS(*varSp, callback);
5681         SetHotnessCounter(glue, curMethod, *varHotnessCounter);
5682         Jump(&tryContinue);
5683     }
5684     Bind(&tryContinue);
5685     GateRef currentSp = *varSp;
5686     varSp = Load(VariableType::NATIVE_POINTER(), frame,
5687                  IntPtr(AsmInterpretedFrame::GetBaseOffset(env->IsArch32Bit())));
5688 
5689     GateRef typePos = PtrSub(*varSp, IntPtr(JSTaggedValue::TaggedTypeSize()));
5690     GateRef maybeFrameType = Load(VariableType::INT64(), typePos);
5691     BRANCH(Int64Equal(maybeFrameType, Int64(static_cast<int64_t>(FrameType::BASELINE_BUILTIN_FRAME))),
5692            &isBaselineBuiltinFrame, &notBaselineBuiltinFrame);
5693     Bind(&isBaselineBuiltinFrame);
5694     {
5695         varSp = Load(VariableType::NATIVE_POINTER(), *varSp);
5696         Jump(&notBaselineBuiltinFrame);
5697     }
5698     Bind(&notBaselineBuiltinFrame);
5699     prevState = GetFrame(*varSp);
5700     varPc = GetPcFromFrame(*prevState);
5701     varAcc = Undefined();
5702     Branch(IntPtrEqual(*varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr);
5703     Bind(&pcEqualNullptr);
5704     {
5705         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc, *varSp, currentSp });
5706         Return();
5707     }
5708     Bind(&pcNotEqualNullptr);
5709     BRANCH(IntPtrEqual(*varPc, IntPtr(BASELINEJIT_PC_FLAG)), &pcEqualBaseline, &pcNotEqualBaseline);
5710     Bind(&pcEqualBaseline);
5711     {
5712         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
5713         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturnBaseline), { *varAcc, *varSp, currentSp, jumpSize });
5714         Return();
5715     }
5716     Bind(&pcNotEqualBaseline);
5717     {
5718         GateRef function = GetFunctionFromFrame(*prevState);
5719         GateRef method = Load(VariableType::JS_ANY(), function, IntPtr(JSFunctionBase::METHOD_OFFSET));
5720         varConstpool = GetConstpoolFromMethod(method);
5721         varProfileTypeInfo = GetProfileTypeInfoFromFunction(function);
5722         varHotnessCounter = GetHotnessCounterFromMethod(method);
5723         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
5724         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch),
5725                        { glue, currentSp, *varPc, *varConstpool, *varProfileTypeInfo,
5726                          *varAcc, *varHotnessCounter, jumpSize });
5727         Return();
5728     }
5729 }
5730 
GenerateCircuit()5731 void BaselineSuspendgeneratorV8StubBuilder::GenerateCircuit()
5732 {
5733     GateRef glue = PtrArgument(PARAM_INDEX(BaselineSuspendgeneratorV8, GLUE));
5734     GateRef sp = PtrArgument(PARAM_INDEX(BaselineSuspendgeneratorV8, SP));
5735     GateRef curPcOffset = PtrArgument(PARAM_INDEX(BaselineSuspendgeneratorV8, OFFSET));
5736     GateRef v0 = Int32Argument(PARAM_INDEX(BaselineSuspendgeneratorV8, V0));
5737     ProfileOperation callback;
5738 
5739     GateRef frame = GetFrame(sp);
5740     GateRef func = GetFunctionFromFrame(frame);
5741     GateRef method = GetMethodFromFunction(func);
5742     GateRef constpool = GetConstpoolFromMethod(method);
5743     GateRef acc = GetAccFromFrame(frame);
5744     GateRef hotnessCounter = GetHotnessCounterFromMethod(method);
5745     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(func);
5746 
5747     auto env = GetEnvironment();
5748     METHOD_EXIT();
5749     DEFVARIABLE(varSp, VariableType::NATIVE_POINTER(), sp);
5750     DEFVARIABLE(prevState, VariableType::NATIVE_POINTER(), sp);
5751     DEFVARIABLE(varConstpool, VariableType::JS_POINTER(), constpool);
5752     DEFVARIABLE(varProfileTypeInfo, VariableType::JS_POINTER(), profileTypeInfo);
5753     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
5754     DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter);
5755 
5756     Label isBaselineBuiltinFrame(env);
5757     Label notBaselineBuiltinFrame(env);
5758     Label pcEqualNullptr(env);
5759     Label pcNotEqualNullptr(env);
5760     Label pcEqualBaseline(env);
5761     Label pcNotEqualBaseline(env);
5762     Label updateHotness(env);
5763     Label isStable(env);
5764     Label tryContinue(env);
5765     Label dispatch(env);
5766     Label slowPath(env);
5767 
5768     GateRef genObj = GetVregValue(sp, ZExtInt32ToPtr(v0));
5769     GateRef value = *varAcc;
5770     GateRef res = CallRuntime(glue, RTSTUB_ID(SuspendGenerator), { genObj, value });
5771     Label isException(env);
5772     Label notException(env);
5773     BRANCH(TaggedIsException(res), &isException, &notException);
5774     Bind(&isException);
5775     {
5776         DISPATCH_LAST();
5777         Return();
5778     }
5779     Bind(&notException);
5780     varAcc = res;
5781     BRANCH(TaggedIsUndefined(*varProfileTypeInfo), &updateHotness, &isStable);
5782     Bind(&isStable);
5783     {
5784         BRANCH(ProfilerStubBuilder(env).IsProfileTypeInfoDumped(*varProfileTypeInfo, callback), &tryContinue,
5785             &updateHotness);
5786     }
5787     Bind(&updateHotness);
5788     {
5789         GateRef offset = Int32Not(curPcOffset);
5790         UPDATE_HOTNESS(*varSp, callback);
5791         SetHotnessCounter(glue, method, *varHotnessCounter);
5792         Jump(&tryContinue);
5793     }
5794 
5795     Bind(&tryContinue);
5796 #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
5797     GateRef curFunc = GetFunctionFromFrame(frame);
5798     CallNGCRuntime(glue, RTSTUB_ID(EndCallTimer), { glue, curFunc });
5799 #endif
5800     GateRef currentSp = *varSp;
5801     varSp = Load(VariableType::NATIVE_POINTER(), frame,
5802         IntPtr(AsmInterpretedFrame::GetBaseOffset(env->IsArch32Bit())));
5803 
5804     GateRef typePos = PtrSub(*varSp, IntPtr(JSTaggedValue::TaggedTypeSize()));
5805     GateRef maybeFrameType = Load(VariableType::INT64(), typePos);
5806     BRANCH(Int64Equal(maybeFrameType, Int64(static_cast<int64_t>(FrameType::BASELINE_BUILTIN_FRAME))),
5807            &isBaselineBuiltinFrame, &notBaselineBuiltinFrame);
5808     Bind(&isBaselineBuiltinFrame);
5809     {
5810         varSp = Load(VariableType::NATIVE_POINTER(), *varSp);
5811         Jump(&notBaselineBuiltinFrame);
5812     }
5813     Bind(&notBaselineBuiltinFrame);
5814     prevState = GetFrame(*varSp);
5815     GateRef varPc = GetPcFromFrame(*prevState);
5816     BRANCH(IntPtrEqual(varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr);
5817     Bind(&pcEqualNullptr);
5818     {
5819         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc, *varSp, currentSp });
5820         Return();
5821     }
5822     Bind(&pcNotEqualNullptr);
5823     BRANCH(IntPtrEqual(varPc, IntPtr(BASELINEJIT_PC_FLAG)), &pcEqualBaseline, &pcNotEqualBaseline);
5824     Bind(&pcEqualBaseline);
5825     {
5826         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
5827         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturnBaseline), { *varAcc, *varSp, currentSp, jumpSize });
5828         Return();
5829     }
5830     Bind(&pcNotEqualBaseline);
5831     {
5832         GateRef function = GetFunctionFromFrame(*prevState);
5833         GateRef prevMethod = Load(VariableType::JS_ANY(), function, IntPtr(JSFunctionBase::METHOD_OFFSET));
5834         varConstpool = GetConstpoolFromMethod(prevMethod);
5835         varProfileTypeInfo = GetProfileTypeInfoFromFunction(function);
5836         varHotnessCounter = GetHotnessCounterFromMethod(prevMethod);
5837         GateRef jumpSize = GetCallSizeFromFrame(*prevState);
5838         CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndDispatch),
5839             { glue, currentSp, varPc, *varConstpool, *varProfileTypeInfo,
5840             *varAcc, *varHotnessCounter, jumpSize });
5841         Return();
5842     }
5843 }
5844 
5845 // interpreter helper handler
GenerateCircuit()5846 void BaselineExceptionHandlerStubBuilder::GenerateCircuit()
5847 {
5848     GateRef glue = PtrArgument(PARAM_INDEX(BaselineExceptionHandler, GLUE));
5849     GateRef sp = PtrArgument(PARAM_INDEX(BaselineExceptionHandler, SP));
5850     GateRef acc = PtrArgument(PARAM_INDEX(BaselineExceptionHandler, ACC));
5851 
5852     GateRef frame = GetFrame(sp);
5853     GateRef func = GetFunctionFromFrame(frame);
5854     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(func);
5855     GateRef method = GetMethodFromFunction(func);
5856     GateRef hotnessCounter = GetHotnessCounterFromMethod(method);
5857     GateRef constpool = GetConstpoolFromMethod(method);
5858 
5859     auto env = GetEnvironment();
5860     DEFVARIABLE(varPc, VariableType::NATIVE_POINTER(), IntPtr(0));
5861     DEFVARIABLE(varSp, VariableType::NATIVE_POINTER(), sp);
5862     DEFVARIABLE(varConstpool, VariableType::JS_POINTER(), constpool);
5863     DEFVARIABLE(varProfileTypeInfo, VariableType::JS_POINTER(), profileTypeInfo);
5864     DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
5865     DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter);
5866 
5867     Label pcIsInvalid(env);
5868     Label pcNotInvalid(env);
5869     GateRef exceptionOffset = IntPtr(JSThread::GlueData::GetExceptionOffset(env->IsArch32Bit()));
5870     GateRef exception = Load(VariableType::JS_ANY(), glue, exceptionOffset);
5871     varPc = TaggedCastToIntPtr(CallRuntime(glue, RTSTUB_ID(UpFrame), {}));
5872     varSp = GetCurrentFrame(glue);
5873     Branch(IntPtrEqual(*varPc, IntPtr(0)), &pcIsInvalid, &pcNotInvalid);
5874     Bind(&pcIsInvalid);
5875     {
5876         CallNGCRuntime(glue, RTSTUB_ID(ResumeUncaughtFrameAndReturn), { glue, *varSp, *varAcc });
5877         Return();
5878     }
5879     Bind(&pcNotInvalid);
5880     {
5881         varAcc = exception;
5882         // clear exception
5883         Store(VariableType::INT64(), glue, glue, exceptionOffset, Hole());
5884         GateRef function = GetFunctionFromFrame(GetFrame(*varSp));
5885         GateRef thisMethod = Load(VariableType::JS_ANY(), function, IntPtr(JSFunctionBase::METHOD_OFFSET));
5886         varConstpool = GetConstpoolFromMethod(thisMethod);
5887         varProfileTypeInfo = GetProfileTypeInfoFromFunction(function);
5888         varHotnessCounter = GetHotnessCounterFromMethod(thisMethod);
5889         CallNGCRuntime(glue, RTSTUB_ID(ResumeCaughtFrameAndDispatch), {
5890             glue, *varSp, *varPc, *varConstpool,
5891             *varProfileTypeInfo, *varAcc, *varHotnessCounter});
5892         Return();
5893     }
5894 }
5895 
GenerateCircuit()5896 void BaselineUpdateHotnessStubBuilder::GenerateCircuit()
5897 {
5898     GateRef glue = PtrArgument(PARAM_INDEX(BaselineUpdateHotness, GLUE));
5899     GateRef sp = PtrArgument(PARAM_INDEX(BaselineUpdateHotness, SP));
5900     GateRef offset = Int32Argument(PARAM_INDEX(BaselineUpdateHotness, OFFSET));
5901 
5902     GateRef frame = GetFrame(sp);
5903     GateRef func = GetFunctionFromFrame(frame);
5904     GateRef method = GetMethodFromFunction(func);
5905     GateRef hotnessCounter = GetHotnessCounterFromMethod(method);
5906     GateRef profileTypeInfo = GetProfileTypeInfoFromFunction(func);
5907     GateRef acc = GetAccFromFrame(frame);
5908 
5909     auto env = GetEnvironment();
5910     DEFVARIABLE(varProfileTypeInfo, VariableType::JS_ANY(), profileTypeInfo);
5911     DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter);
5912 
5913     varHotnessCounter = Int32Add(offset, *varHotnessCounter);
5914     Label slowPath(env);
5915     Label exitLabel(env);
5916     BRANCH(Int32LessThan(*varHotnessCounter, Int32(0)), &slowPath, &exitLabel);
5917     Bind(&slowPath);
5918     {
5919         GateRef iVecOffset = IntPtr(JSThread::GlueData::GetInterruptVectorOffset(env->IsArch32Bit()));
5920         GateRef interruptsFlag = Load(VariableType::INT8(), glue, iVecOffset);
5921         varHotnessCounter = Int32(EcmaInterpreter::METHOD_HOTNESS_THRESHOLD);
5922         Label initialized(env);
5923         Label callRuntime(env);
5924         BRANCH(BitOr(TaggedIsUndefined(*varProfileTypeInfo),
5925                      Int8Equal(interruptsFlag, Int8(VmThreadControl::VM_NEED_SUSPENSION))),
5926             &callRuntime, &initialized);
5927         Bind(&callRuntime);
5928         varProfileTypeInfo = CallRuntime(glue, RTSTUB_ID(UpdateHotnessCounterWithProf), { func });
5929 
5930         Label handleException(env);
5931         BRANCH(HasPendingException(glue), &handleException, &exitLabel);
5932         Bind(&handleException);
5933         {
5934             DISPATCH_LAST();
5935             Return();
5936         }
5937         Bind(&initialized);
5938         ProfilerStubBuilder profiler(this);
5939         profiler.TryJitCompile(glue, { offset, 0, false }, func, profileTypeInfo);
5940         Jump(&exitLabel);
5941     }
5942     Bind(&exitLabel);
5943     SetHotnessCounter(glue, method, *varHotnessCounter);
5944     Return();
5945 }
5946 #undef UPDATE_HOTNESS
5947 #undef PARAM_INDEX
5948 #undef DISPATCH_LAST
5949 #undef DISPATCH_LAST_WITH_ACC
5950 }  // namespace panda::ecmascript::kungfu