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