Skip to content

Commit dba8629

Browse files
Milad FarazmandCommit Bot
authored andcommitted
PPC/s390: [builtins] Remove ParameterCount uses from InvokeFunction(Code)
Port 4664840 Original Commit Message: CallDebugOnFunctionCall was always using Registers and not Immediates. Then ParameterCount is not really needed. Since updating that, we could update other functions, e.g InvokeFunction, to only use registers too. Also removed now irrelevant variables, e.g definitely_mismatches. R=solanes@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com BUG= LOG=N Change-Id: Ie0348998503bf4f416440f056e4296d22d064d4d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1892171 Reviewed-by: Joran Siu <joransiu@ca.ibm.com> Commit-Queue: Milad Farazmand <miladfar@ca.ibm.com> Cr-Commit-Position: refs/heads/master@{#64665}
1 parent f27919c commit dba8629

8 files changed

Lines changed: 159 additions & 255 deletions

File tree

src/builtins/ppc/builtins-ppc.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ void Generate_JSBuiltinsConstructStubHelper(MacroAssembler* masm) {
144144
// r6: new target
145145
{
146146
ConstantPoolUnavailableScope constant_pool_unavailable(masm);
147-
ParameterCount actual(r3);
148-
__ InvokeFunction(r4, r6, actual, CALL_FUNCTION);
147+
__ InvokeFunctionWithNewTarget(r4, r6, r3, CALL_FUNCTION);
149148
}
150149

151150
// Restore context from the frame.
@@ -300,8 +299,7 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
300299
// Call the function.
301300
{
302301
ConstantPoolUnavailableScope constant_pool_unavailable(masm);
303-
ParameterCount actual(r3);
304-
__ InvokeFunction(r4, r6, actual, CALL_FUNCTION);
302+
__ InvokeFunctionWithNewTarget(r4, r6, r3, CALL_FUNCTION);
305303
}
306304

307305
// ----------- S t a t e -------------
@@ -2102,9 +2100,7 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
21022100

21032101
__ LoadHalfWord(
21042102
r5, FieldMemOperand(r5, SharedFunctionInfo::kFormalParameterCountOffset));
2105-
ParameterCount actual(r3);
2106-
ParameterCount expected(r5);
2107-
__ InvokeFunctionCode(r4, no_reg, expected, actual, JUMP_FUNCTION);
2103+
__ InvokeFunctionCode(r4, no_reg, r5, r3, JUMP_FUNCTION);
21082104

21092105
// The function is a "classConstructor", need to raise an exception.
21102106
__ bind(&class_constructor);

src/builtins/s390/builtins-s390.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ void Generate_JSBuiltinsConstructStubHelper(MacroAssembler* masm) {
139139
// r3: constructor function
140140
// r5: new target
141141

142-
ParameterCount actual(r2);
143-
__ InvokeFunction(r3, r5, actual, CALL_FUNCTION);
142+
__ InvokeFunctionWithNewTarget(r3, r5, r2, CALL_FUNCTION);
144143

145144
// Restore context from the frame.
146145
__ LoadP(cp, MemOperand(fp, ConstructFrameConstants::kContextOffset));
@@ -293,8 +292,7 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
293292
__ bind(&no_args);
294293

295294
// Call the function.
296-
ParameterCount actual(r2);
297-
__ InvokeFunction(r3, r5, actual, CALL_FUNCTION);
295+
__ InvokeFunctionWithNewTarget(r3, r5, r2, CALL_FUNCTION);
298296

299297
// ----------- S t a t e -------------
300298
// -- r0: constructor result
@@ -2160,9 +2158,7 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
21602158

21612159
__ LoadLogicalHalfWordP(
21622160
r4, FieldMemOperand(r4, SharedFunctionInfo::kFormalParameterCountOffset));
2163-
ParameterCount actual(r2);
2164-
ParameterCount expected(r4);
2165-
__ InvokeFunctionCode(r3, no_reg, expected, actual, JUMP_FUNCTION);
2161+
__ InvokeFunctionCode(r3, no_reg, r4, r2, JUMP_FUNCTION);
21662162

21672163
// The function is a "classConstructor", need to raise an exception.
21682164
__ bind(&class_constructor);

src/codegen/ppc/macro-assembler-ppc.cc

Lines changed: 64 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,9 @@ void TurboAssembler::PrepareForTailCall(const ParameterCount& callee_args_count,
12141214
mr(sp, dst_reg);
12151215
}
12161216

1217-
void MacroAssembler::InvokePrologue(const ParameterCount& expected,
1218-
const ParameterCount& actual, Label* done,
1219-
bool* definitely_mismatches,
1220-
InvokeFlag flag) {
1221-
bool definitely_matches = false;
1222-
*definitely_mismatches = false;
1217+
void MacroAssembler::InvokePrologue(Register expected_parameter_count,
1218+
Register actual_parameter_count,
1219+
Label* done, InvokeFlag flag) {
12231220
Label regular_invoke;
12241221

12251222
// Check whether the expected and actual arguments count match. If not,
@@ -1232,56 +1229,28 @@ void MacroAssembler::InvokePrologue(const ParameterCount& expected,
12321229
// up actual and expected registers according to the contract if values are
12331230
// passed in registers.
12341231

1232+
// The code below is made a lot easier because the calling code already sets
1233+
// up actual and expected registers according to the contract.
12351234
// ARM has some sanity checks as per below, considering add them for PPC
1236-
// DCHECK(actual.is_immediate() || actual.reg() == r3);
1237-
// DCHECK(expected.is_immediate() || expected.reg() == r5);
1238-
1239-
if (expected.is_immediate()) {
1240-
DCHECK(actual.is_immediate());
1241-
mov(r3, Operand(actual.immediate()));
1242-
if (expected.immediate() == actual.immediate()) {
1243-
definitely_matches = true;
1244-
} else {
1245-
const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
1246-
if (expected.immediate() == sentinel) {
1247-
// Don't worry about adapting arguments for builtins that
1248-
// don't want that done. Skip adaption code by making it look
1249-
// like we have a match between expected and actual number of
1250-
// arguments.
1251-
definitely_matches = true;
1252-
} else {
1253-
*definitely_mismatches = true;
1254-
mov(r5, Operand(expected.immediate()));
1255-
}
1256-
}
1235+
// DCHECK_EQ(actual_parameter_count, r3);
1236+
// DCHECK_EQ(expected_parameter_count, r5);
1237+
1238+
cmp(expected_parameter_count, actual_parameter_count);
1239+
beq(&regular_invoke);
1240+
1241+
Handle<Code> adaptor = BUILTIN_CODE(isolate(), ArgumentsAdaptorTrampoline);
1242+
if (flag == CALL_FUNCTION) {
1243+
Call(adaptor);
1244+
b(done);
12571245
} else {
1258-
if (actual.is_immediate()) {
1259-
mov(r3, Operand(actual.immediate()));
1260-
cmpi(expected.reg(), Operand(actual.immediate()));
1261-
beq(&regular_invoke);
1262-
} else {
1263-
cmp(expected.reg(), actual.reg());
1264-
beq(&regular_invoke);
1265-
}
1246+
Jump(adaptor, RelocInfo::CODE_TARGET);
12661247
}
1267-
1268-
if (!definitely_matches) {
1269-
Handle<Code> adaptor = BUILTIN_CODE(isolate(), ArgumentsAdaptorTrampoline);
1270-
if (flag == CALL_FUNCTION) {
1271-
Call(adaptor);
1272-
if (!*definitely_mismatches) {
1273-
b(done);
1274-
}
1275-
} else {
1276-
Jump(adaptor, RelocInfo::CODE_TARGET);
1277-
}
12781248
bind(&regular_invoke);
1279-
}
12801249
}
12811250

12821251
void MacroAssembler::CheckDebugHook(Register fun, Register new_target,
1283-
const ParameterCount& expected,
1284-
const ParameterCount& actual) {
1252+
Register expected_parameter_count,
1253+
Register actual_parameter_count) {
12851254
Label skip_hook;
12861255

12871256
ExternalReference debug_hook_active =
@@ -1294,22 +1263,17 @@ void MacroAssembler::CheckDebugHook(Register fun, Register new_target,
12941263

12951264
{
12961265
// Load receiver to pass it later to DebugOnFunctionCall hook.
1297-
if (actual.is_reg()) {
1298-
ShiftLeftImm(r7, actual.reg(), Operand(kPointerSizeLog2));
1299-
LoadPX(r7, MemOperand(sp, r7));
1300-
} else {
1301-
LoadP(r7, MemOperand(sp, actual.immediate() << kPointerSizeLog2), r0);
1302-
}
1266+
ShiftLeftImm(r7, actual_parameter_count, Operand(kPointerSizeLog2));
1267+
LoadPX(r7, MemOperand(sp, r7));
13031268
FrameScope frame(this,
13041269
has_frame() ? StackFrame::NONE : StackFrame::INTERNAL);
1305-
if (expected.is_reg()) {
1306-
SmiTag(expected.reg());
1307-
Push(expected.reg());
1308-
}
1309-
if (actual.is_reg()) {
1310-
SmiTag(actual.reg());
1311-
Push(actual.reg());
1312-
}
1270+
1271+
SmiTag(expected_parameter_count);
1272+
Push(expected_parameter_count);
1273+
1274+
SmiTag(actual_parameter_count);
1275+
Push(actual_parameter_count);
1276+
13131277
if (new_target.is_valid()) {
13141278
Push(new_target);
13151279
}
@@ -1319,65 +1283,61 @@ void MacroAssembler::CheckDebugHook(Register fun, Register new_target,
13191283
if (new_target.is_valid()) {
13201284
Pop(new_target);
13211285
}
1322-
if (actual.is_reg()) {
1323-
Pop(actual.reg());
1324-
SmiUntag(actual.reg());
1325-
}
1326-
if (expected.is_reg()) {
1327-
Pop(expected.reg());
1328-
SmiUntag(expected.reg());
1329-
}
1286+
1287+
Pop(actual_parameter_count);
1288+
SmiUntag(actual_parameter_count);
1289+
1290+
Pop(expected_parameter_count);
1291+
SmiUntag(expected_parameter_count);
13301292
}
13311293
bind(&skip_hook);
13321294
}
13331295

13341296
void MacroAssembler::InvokeFunctionCode(Register function, Register new_target,
1335-
const ParameterCount& expected,
1336-
const ParameterCount& actual,
1297+
Register expected_parameter_count,
1298+
Register actual_parameter_count,
13371299
InvokeFlag flag) {
13381300
// You can't call a function without a valid frame.
1339-
DCHECK(flag == JUMP_FUNCTION || has_frame());
1340-
DCHECK(function == r4);
1301+
DCHECK_IMPLIES(flag == CALL_FUNCTION, has_frame());
1302+
DCHECK_EQ(function, r4);
13411303
DCHECK_IMPLIES(new_target.is_valid(), new_target == r6);
13421304

13431305
// On function call, call into the debugger if necessary.
1344-
CheckDebugHook(function, new_target, expected, actual);
1306+
CheckDebugHook(function, new_target, expected_parameter_count,
1307+
actual_parameter_count);
13451308

13461309
// Clear the new.target register if not given.
13471310
if (!new_target.is_valid()) {
13481311
LoadRoot(r6, RootIndex::kUndefinedValue);
13491312
}
13501313

13511314
Label done;
1352-
bool definitely_mismatches = false;
1353-
InvokePrologue(expected, actual, &done, &definitely_mismatches, flag);
1354-
if (!definitely_mismatches) {
1355-
// We call indirectly through the code field in the function to
1356-
// allow recompilation to take effect without changing any of the
1357-
// call sites.
1358-
Register code = kJavaScriptCallCodeStartRegister;
1359-
LoadP(code, FieldMemOperand(function, JSFunction::kCodeOffset));
1360-
if (flag == CALL_FUNCTION) {
1361-
CallCodeObject(code);
1362-
} else {
1363-
DCHECK(flag == JUMP_FUNCTION);
1364-
JumpCodeObject(code);
1365-
}
1315+
InvokePrologue(expected_parameter_count, actual_parameter_count, &done, flag);
1316+
// We call indirectly through the code field in the function to
1317+
// allow recompilation to take effect without changing any of the
1318+
// call sites.
1319+
Register code = kJavaScriptCallCodeStartRegister;
1320+
LoadP(code, FieldMemOperand(function, JSFunction::kCodeOffset));
1321+
if (flag == CALL_FUNCTION) {
1322+
CallCodeObject(code);
1323+
} else {
1324+
DCHECK(flag == JUMP_FUNCTION);
1325+
JumpCodeObject(code);
1326+
}
13661327

13671328
// Continue here if InvokePrologue does handle the invocation due to
13681329
// mismatched parameter counts.
13691330
bind(&done);
1370-
}
13711331
}
13721332

1373-
void MacroAssembler::InvokeFunction(Register fun, Register new_target,
1374-
const ParameterCount& actual,
1375-
InvokeFlag flag) {
1333+
void MacroAssembler::InvokeFunctionWithNewTarget(
1334+
Register fun, Register new_target, Register actual_parameter_count,
1335+
InvokeFlag flag) {
13761336
// You can't call a function without a valid frame.
1377-
DCHECK(flag == JUMP_FUNCTION || has_frame());
1337+
DCHECK_IMPLIES(flag == CALL_FUNCTION, has_frame());
13781338

13791339
// Contract with called JS functions requires that function is passed in r4.
1380-
DCHECK(fun == r4);
1340+
DCHECK_EQ(fun, r4);
13811341

13821342
Register expected_reg = r5;
13831343
Register temp_reg = r7;
@@ -1388,24 +1348,25 @@ void MacroAssembler::InvokeFunction(Register fun, Register new_target,
13881348
FieldMemOperand(
13891349
temp_reg, SharedFunctionInfo::kFormalParameterCountOffset));
13901350

1391-
ParameterCount expected(expected_reg);
1392-
InvokeFunctionCode(fun, new_target, expected, actual, flag);
1351+
InvokeFunctionCode(fun, new_target, expected_reg, actual_parameter_count,
1352+
flag);
13931353
}
13941354

13951355
void MacroAssembler::InvokeFunction(Register function,
1396-
const ParameterCount& expected,
1397-
const ParameterCount& actual,
1356+
Register expected_parameter_count,
1357+
Register actual_parameter_count,
13981358
InvokeFlag flag) {
13991359
// You can't call a function without a valid frame.
1400-
DCHECK(flag == JUMP_FUNCTION || has_frame());
1360+
DCHECK_IMPLIES(flag == CALL_FUNCTION, has_frame());
14011361

14021362
// Contract with called JS functions requires that function is passed in r4.
1403-
DCHECK(function == r4);
1363+
DCHECK_EQ(function, r4);
14041364

14051365
// Get the function and setup the context.
14061366
LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
14071367

1408-
InvokeFunctionCode(r4, no_reg, expected, actual, flag);
1368+
InvokeFunctionCode(r4, no_reg, expected_parameter_count,
1369+
actual_parameter_count, flag);
14091370
}
14101371

14111372
void MacroAssembler::MaybeDropFrames() {

src/codegen/ppc/macro-assembler-ppc.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -749,21 +749,21 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
749749

750750
// Invoke the JavaScript function code by either calling or jumping.
751751
void InvokeFunctionCode(Register function, Register new_target,
752-
const ParameterCount& expected,
753-
const ParameterCount& actual, InvokeFlag flag);
752+
Register expected_parameter_count,
753+
Register actual_parameter_count, InvokeFlag flag);
754754

755755
// On function call, call into the debugger if necessary.
756756
void CheckDebugHook(Register fun, Register new_target,
757-
const ParameterCount& expected,
758-
const ParameterCount& actual);
757+
Register expected_parameter_count,
758+
Register actual_parameter_count);
759759

760760
// Invoke the JavaScript function in the given register. Changes the
761761
// current context to the context in the function before invoking.
762-
void InvokeFunction(Register function, Register new_target,
763-
const ParameterCount& actual, InvokeFlag flag);
764-
765-
void InvokeFunction(Register function, const ParameterCount& expected,
766-
const ParameterCount& actual, InvokeFlag flag);
762+
void InvokeFunctionWithNewTarget(Register function, Register new_target,
763+
Register actual_parameter_count,
764+
InvokeFlag flag);
765+
void InvokeFunction(Register function, Register expected_parameter_count,
766+
Register actual_parameter_count, InvokeFlag flag);
767767

768768
void DebugBreak();
769769
// Frame restart support
@@ -950,9 +950,9 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
950950
static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
951951

952952
// Helper functions for generating invokes.
953-
void InvokePrologue(const ParameterCount& expected,
954-
const ParameterCount& actual, Label* done,
955-
bool* definitely_mismatches, InvokeFlag flag);
953+
void InvokePrologue(Register expected_parameter_count,
954+
Register actual_parameter_count, Label* done,
955+
InvokeFlag flag);
956956

957957
// Compute memory operands for safepoint stack slots.
958958
static int SafepointRegisterStackIndex(int reg_code);

0 commit comments

Comments
 (0)