Skip to content

Commit 242d58e

Browse files
Milad FarazmandCommit Bot
authored andcommitted
PPC/s390: [wasm] Save FP & PC when calling C functions
Port 6cd28b5 Original Commit Message: Added implementations for ia32, arm, arm64. mips/mips64 will be committed in separate CL once the build is green again in order not to stall this CL with the supported architectures. compilation by using alternative temp register for x64. macro assemblers. R=ecmziegler@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com BUG= LOG=N Change-Id: Ib08e31dfa11f0254c7888ce17dd27e7d0154c752 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2078898 Reviewed-by: Junliang Yan <jyan@ca.ibm.com> Commit-Queue: Milad Farazmand <miladfar@ca.ibm.com> Cr-Commit-Position: refs/heads/master@{#66490}
1 parent af7bf14 commit 242d58e

8 files changed

Lines changed: 83 additions & 48 deletions

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

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,20 +1897,32 @@ void TurboAssembler::CallCFunctionHelper(Register function,
18971897

18981898
// Save the frame pointer and PC so that the stack layout remains iterable,
18991899
// even without an ExitFrame which normally exists between JS and C frames.
1900-
if (isolate() != nullptr) {
1901-
Register scratch1 = r7;
1902-
Register scratch2 = r8;
1903-
Push(scratch1, scratch2);
1900+
Register addr_scratch = r7;
1901+
Register scratch = r8;
1902+
Push(scratch);
1903+
mflr(scratch);
1904+
// See x64 code for reasoning about how to address the isolate data fields.
1905+
if (root_array_available()) {
1906+
LoadPC(r0);
1907+
StoreP(r0, MemOperand(kRootRegister,
1908+
IsolateData::fast_c_call_caller_pc_offset()));
1909+
StoreP(fp, MemOperand(kRootRegister,
1910+
IsolateData::fast_c_call_caller_fp_offset()));
1911+
} else {
1912+
DCHECK_NOT_NULL(isolate());
1913+
Push(addr_scratch);
19041914

1905-
mflr(scratch2);
1906-
Move(scratch1, ExternalReference::fast_c_call_caller_pc_address(isolate()));
1915+
Move(addr_scratch,
1916+
ExternalReference::fast_c_call_caller_pc_address(isolate()));
19071917
LoadPC(r0);
1908-
StoreP(r0, MemOperand(scratch1));
1909-
Move(scratch1, ExternalReference::fast_c_call_caller_fp_address(isolate()));
1910-
StoreP(fp, MemOperand(scratch1));
1911-
mtlr(scratch2);
1912-
Pop(scratch1, scratch2);
1918+
StoreP(r0, MemOperand(addr_scratch));
1919+
Move(addr_scratch,
1920+
ExternalReference::fast_c_call_caller_fp_address(isolate()));
1921+
StoreP(fp, MemOperand(addr_scratch));
1922+
Pop(addr_scratch);
19131923
}
1924+
mtlr(scratch);
1925+
Pop(scratch);
19141926

19151927
// Just call directly. The function called cannot cause a GC, or
19161928
// allow preemption, so the return address in the link register
@@ -1930,15 +1942,21 @@ void TurboAssembler::CallCFunctionHelper(Register function,
19301942

19311943
Call(dest);
19321944

1933-
if (isolate() != nullptr) {
1934-
// We don't unset the PC; the FP is the source of truth.
1935-
Register scratch1 = r7;
1936-
Register scratch2 = r8;
1937-
Push(scratch1, scratch2);
1938-
Move(scratch1, ExternalReference::fast_c_call_caller_fp_address(isolate()));
1939-
mov(scratch2, Operand::Zero());
1940-
StoreP(scratch2, MemOperand(scratch1));
1941-
Pop(scratch1, scratch2);
1945+
// We don't unset the PC; the FP is the source of truth.
1946+
Register zero_scratch = r0;
1947+
mov(zero_scratch, Operand::Zero());
1948+
1949+
if (root_array_available()) {
1950+
StoreP(
1951+
zero_scratch,
1952+
MemOperand(kRootRegister, IsolateData::fast_c_call_caller_fp_offset()));
1953+
} else {
1954+
DCHECK_NOT_NULL(isolate());
1955+
Push(addr_scratch);
1956+
Move(addr_scratch,
1957+
ExternalReference::fast_c_call_caller_fp_address(isolate()));
1958+
StoreP(zero_scratch, MemOperand(addr_scratch));
1959+
Pop(addr_scratch);
19421960
}
19431961

19441962
// Remove frame bought in PrepareCallCFunction

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,16 +1828,24 @@ void TurboAssembler::CallCFunctionHelper(Register function,
18281828

18291829
// Save the frame pointer and PC so that the stack layout remains iterable,
18301830
// even without an ExitFrame which normally exists between JS and C frames.
1831-
if (isolate() != nullptr) {
1832-
Register scratch = r6;
1833-
push(scratch);
1831+
Register addr_scratch = r1;
1832+
// See x64 code for reasoning about how to address the isolate data fields.
1833+
if (root_array_available()) {
1834+
LoadPC(r0);
1835+
StoreP(r0, MemOperand(kRootRegister,
1836+
IsolateData::fast_c_call_caller_pc_offset()));
1837+
StoreP(fp, MemOperand(kRootRegister,
1838+
IsolateData::fast_c_call_caller_fp_offset()));
1839+
} else {
1840+
DCHECK_NOT_NULL(isolate());
18341841

1835-
Move(scratch, ExternalReference::fast_c_call_caller_pc_address(isolate()));
1842+
Move(addr_scratch,
1843+
ExternalReference::fast_c_call_caller_pc_address(isolate()));
18361844
LoadPC(r0);
1837-
StoreP(r0, MemOperand(scratch));
1838-
Move(scratch, ExternalReference::fast_c_call_caller_fp_address(isolate()));
1839-
StoreP(fp, MemOperand(scratch));
1840-
pop(scratch);
1845+
StoreP(r0, MemOperand(addr_scratch));
1846+
Move(addr_scratch,
1847+
ExternalReference::fast_c_call_caller_fp_address(isolate()));
1848+
StoreP(fp, MemOperand(addr_scratch));
18411849
}
18421850

18431851
// Just call directly. The function called cannot cause a GC, or
@@ -1851,15 +1859,19 @@ void TurboAssembler::CallCFunctionHelper(Register function,
18511859

18521860
Call(dest);
18531861

1854-
if (isolate() != nullptr) {
1855-
// We don't unset the PC; the FP is the source of truth.
1856-
Register scratch1 = r6;
1857-
Register scratch2 = r7;
1858-
Push(scratch1, scratch2);
1859-
Move(scratch1, ExternalReference::fast_c_call_caller_fp_address(isolate()));
1860-
lghi(scratch2, Operand::Zero());
1861-
StoreP(scratch2, MemOperand(scratch1));
1862-
Pop(scratch1, scratch2);
1862+
// We don't unset the PC; the FP is the source of truth.
1863+
Register zero_scratch = r0;
1864+
lghi(zero_scratch, Operand::Zero());
1865+
1866+
if (root_array_available()) {
1867+
StoreP(
1868+
zero_scratch,
1869+
MemOperand(kRootRegister, IsolateData::fast_c_call_caller_fp_offset()));
1870+
} else {
1871+
DCHECK_NOT_NULL(isolate());
1872+
Move(addr_scratch,
1873+
ExternalReference::fast_c_call_caller_fp_address(isolate()));
1874+
StoreP(zero_scratch, MemOperand(addr_scratch));
18631875
}
18641876

18651877
int stack_passed_arguments =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ RegExpMacroAssemblerPPC::RegExpMacroAssemblerPPC(Isolate* isolate, Zone* zone,
102102
: NativeRegExpMacroAssembler(isolate, zone),
103103
masm_(new MacroAssembler(isolate, CodeObjectRequired::kYes,
104104
NewAssemblerBuffer(kRegExpCodeSize))),
105+
no_root_array_scope_(masm_),
105106
mode_(mode),
106107
num_registers_(registers_to_save),
107108
num_saved_registers_(registers_to_save),
@@ -123,7 +124,6 @@ RegExpMacroAssemblerPPC::RegExpMacroAssemblerPPC(Isolate* isolate, Zone* zone,
123124
__ bind(&start_label_); // And then continue from here.
124125
}
125126

126-
127127
RegExpMacroAssemblerPPC::~RegExpMacroAssemblerPPC() {
128128
delete masm_;
129129
// Unuse labels in case we throw away the assembler without calling GetCode.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerPPC
181181
Isolate* isolate() const { return masm_->isolate(); }
182182

183183
MacroAssembler* masm_;
184+
NoRootArrayScope no_root_array_scope_;
184185

185186
// Which mode to generate code for (Latin1 or UC16).
186187
Mode mode_;

src/regexp/s390/regexp-macro-assembler-s390.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ RegExpMacroAssemblerS390::RegExpMacroAssemblerS390(Isolate* isolate, Zone* zone,
104104
: NativeRegExpMacroAssembler(isolate, zone),
105105
masm_(new MacroAssembler(isolate, CodeObjectRequired::kYes,
106106
NewAssemblerBuffer(kRegExpCodeSize))),
107+
no_root_array_scope_(masm_),
107108
mode_(mode),
108109
num_registers_(registers_to_save),
109110
num_saved_registers_(registers_to_save),

src/regexp/s390/regexp-macro-assembler-s390.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerS390
183183
Isolate* isolate() const { return masm_->isolate(); }
184184

185185
MacroAssembler* masm_;
186+
NoRootArrayScope no_root_array_scope_;
186187

187188
// Which mode to generate code for (Latin1 or UC16).
188189
Mode mode_;

test/unittests/assembler/turbo-assembler-ppc-unittest.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class TurboAssemblerTest : public TestWithIsolate {};
2222

2323
TEST_F(TurboAssemblerTest, TestHardAbort) {
2424
auto buffer = AllocateAssemblerBuffer();
25-
TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
25+
TurboAssembler tasm(isolate(), AssemblerOptions{}, CodeObjectRequired::kNo,
2626
buffer->CreateView());
27-
27+
__ set_root_array_available(false);
2828
__ set_abort_hard(true);
2929

3030
__ Abort(AbortReason::kNoReason);
3131

3232
CodeDesc desc;
33-
tasm.GetCode(nullptr, &desc);
33+
tasm.GetCode(isolate(), &desc);
3434
buffer->MakeExecutable();
3535
// We need an isolate here to execute in the simulator.
3636
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer->start());
@@ -40,9 +40,9 @@ TEST_F(TurboAssemblerTest, TestHardAbort) {
4040

4141
TEST_F(TurboAssemblerTest, TestCheck) {
4242
auto buffer = AllocateAssemblerBuffer();
43-
TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
43+
TurboAssembler tasm(isolate(), AssemblerOptions{}, CodeObjectRequired::kNo,
4444
buffer->CreateView());
45-
45+
__ set_root_array_available(false);
4646
__ set_abort_hard(true);
4747

4848
// Fail if the first parameter is 17.
@@ -52,7 +52,7 @@ TEST_F(TurboAssemblerTest, TestCheck) {
5252
__ Ret();
5353

5454
CodeDesc desc;
55-
tasm.GetCode(nullptr, &desc);
55+
tasm.GetCode(isolate(), &desc);
5656
buffer->MakeExecutable();
5757
// We need an isolate here to execute in the simulator.
5858
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer->start());

test/unittests/assembler/turbo-assembler-s390-unittest.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ class TurboAssemblerTest : public TestWithIsolate {};
2222

2323
TEST_F(TurboAssemblerTest, TestHardAbort) {
2424
auto buffer = AllocateAssemblerBuffer();
25-
TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
25+
TurboAssembler tasm(isolate(), AssemblerOptions{}, CodeObjectRequired::kNo,
2626
buffer->CreateView());
27+
__ set_root_array_available(false);
2728
__ set_abort_hard(true);
2829

2930
__ Abort(AbortReason::kNoReason);
3031

3132
CodeDesc desc;
32-
tasm.GetCode(nullptr, &desc);
33+
tasm.GetCode(isolate(), &desc);
3334
buffer->MakeExecutable();
3435
// We need an isolate here to execute in the simulator.
3536
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer->start());
@@ -39,8 +40,9 @@ TEST_F(TurboAssemblerTest, TestHardAbort) {
3940

4041
TEST_F(TurboAssemblerTest, TestCheck) {
4142
auto buffer = AllocateAssemblerBuffer();
42-
TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
43+
TurboAssembler tasm(isolate(), AssemblerOptions{}, CodeObjectRequired::kNo,
4344
buffer->CreateView());
45+
__ set_root_array_available(false);
4446
__ set_abort_hard(true);
4547

4648
// Fail if the first parameter is 17.
@@ -50,7 +52,7 @@ TEST_F(TurboAssemblerTest, TestCheck) {
5052
__ Ret();
5153

5254
CodeDesc desc;
53-
tasm.GetCode(nullptr, &desc);
55+
tasm.GetCode(isolate(), &desc);
5456
buffer->MakeExecutable();
5557
// We need an isolate here to execute in the simulator.
5658
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer->start());

0 commit comments

Comments
 (0)