Commit 7cb600f2 authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

PPC: Replace CALL_GENERATED_CODE by GeneratedCode wrapper

Port 30fabc4c

Original Commit Message:

    This ensures that there is only one entrance point from C++ to
    generated code, hence only one method has to be excluded from CFI.
    It also introduces type safety by only allowing the code to be called
    with the right arguments.
    This CL includes minor drive-by fixes in the tests, like removing
    unused dummy variables.

R=clemensh@chromium.org, joransiu@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=
LOG=N

Change-Id: Idb21a7b8103a8fb833c963c182463006d9dd6288
Reviewed-on: https://chromium-review.googlesource.com/857425Reviewed-by: 's avatarJoran Siu <joransiu@ca.ibm.com>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#50490}
parent 814577e3
......@@ -36,12 +36,13 @@
namespace v8 {
namespace internal {
// Define these function prototypes to match JSEntryFunction in execution.cc.
typedef Object* (*F1)(int x, int p1, int p2, int p3, int p4);
typedef Object* (*F2)(int x, int y, int p2, int p3, int p4);
typedef Object* (*F3)(void* p0, int p1, int p2, int p3, int p4);
typedef Object* (*F4)(void* p0, void* p1, int p2, int p3, int p4);
// TODO(ppc): Refine these signatures per test case, they can have arbitrary
// return and argument types and arbitrary number of arguments.
using F_iiiii = Object*(int x, int p1, int p2, int p3, int p4);
using F_piiii = Object*(void* p0, int p1, int p2, int p3, int p4);
using F_ppiii = Object*(void* p0, void* p1, int p2, int p3, int p4);
using F_pppii = Object*(void* p0, void* p1, void* p2, int p3, int p4);
using F_ippii = Object*(int p0, void* p1, void* p2, int p3, int p4);
#define __ assm.
......@@ -65,9 +66,8 @@ TEST(0) {
#ifdef DEBUG
code->Print();
#endif
F2 f = FUNCTION_CAST<F2>(code->entry());
intptr_t res = reinterpret_cast<intptr_t>(
CALL_GENERATED_CODE(isolate, f, 3, 4, 0, 0, 0));
auto f = GeneratedCode<F_iiiii>::FromCode(*code);
intptr_t res = reinterpret_cast<intptr_t>(f.Call(3, 4, 0, 0, 0));
::printf("f() = %" V8PRIdPTR "\n", res);
CHECK_EQ(7, static_cast<int>(res));
}
......@@ -104,9 +104,8 @@ TEST(1) {
#ifdef DEBUG
code->Print();
#endif
F1 f = FUNCTION_CAST<F1>(code->entry());
intptr_t res = reinterpret_cast<intptr_t>(
CALL_GENERATED_CODE(isolate, f, 100, 0, 0, 0, 0));
auto f = GeneratedCode<F_iiiii>::FromCode(*code);
intptr_t res = reinterpret_cast<intptr_t>(f.Call(100, 0, 0, 0, 0));
::printf("f() = %" V8PRIdPTR "\n", res);
CHECK_EQ(5050, static_cast<int>(res));
}
......@@ -155,9 +154,8 @@ TEST(2) {
#ifdef DEBUG
code->Print();
#endif
F1 f = FUNCTION_CAST<F1>(code->entry());
intptr_t res = reinterpret_cast<intptr_t>(
CALL_GENERATED_CODE(isolate, f, 10, 0, 0, 0, 0));
auto f = GeneratedCode<F_iiiii>::FromCode(*code);
intptr_t res = reinterpret_cast<intptr_t>(f.Call(10, 0, 0, 0, 0));
::printf("f() = %" V8PRIdPTR "\n", res);
CHECK_EQ(3628800, static_cast<int>(res));
}
......@@ -228,12 +226,11 @@ TEST(3) {
#ifdef DEBUG
code->Print();
#endif
F3 f = FUNCTION_CAST<F3>(code->entry());
auto f = GeneratedCode<F_piiii>::FromCode(*code);
t.i = 100000;
t.c = 10;
t.s = 1000;
intptr_t res = reinterpret_cast<intptr_t>(
CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0));
intptr_t res = reinterpret_cast<intptr_t>(f.Call(&t, 0, 0, 0, 0));
::printf("f() = %" V8PRIdPTR "\n", res);
CHECK_EQ(101010, static_cast<int>(res));
CHECK_EQ(100000 / 2, t.i);
......@@ -344,7 +341,7 @@ TEST(4) {
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F3 f = FUNCTION_CAST<F3>(Code::cast(code)->entry());
auto f = GeneratedCode<F_piiii>::FromCode(*code);
t.a = 1.5;
t.b = 2.75;
t.c = 17.17;
......@@ -358,8 +355,7 @@ TEST(4) {
t.n = 123.456;
t.x = 4.5;
t.y = 9.0;
Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0);
USE(dummy);
f.Call(&t, 0, 0, 0, 0);
CHECK_EQ(4.5, t.y);
CHECK_EQ(9.0, t.x);
CHECK_EQ(-123.456, t.n);
......@@ -405,9 +401,8 @@ TEST(5) {
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry());
int res = reinterpret_cast<int>(
CALL_GENERATED_CODE(isolate, f, 0xAAAAAAAA, 0, 0, 0, 0));
auto f = GeneratedCode<F_iiiii>::FromCode(*code);
int res = reinterpret_cast<int>(f.Call(0xAAAAAAAA, 0, 0, 0, 0));
::printf("f() = %d\n", res);
CHECK_EQ(-7, res);
}
......@@ -441,9 +436,8 @@ TEST(6) {
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry());
int res = reinterpret_cast<int>(
CALL_GENERATED_CODE(isolate, f, 0xFFFF, 0, 0, 0, 0));
auto f = GeneratedCode<F_iiiii>::FromCode(*code);
int res = reinterpret_cast<int>(f.Call(0xFFFF, 0, 0, 0, 0));
::printf("f() = %d\n", res);
CHECK_EQ(382, res);
}
......@@ -517,9 +511,8 @@ static void TestRoundingMode(VCVTTypes types,
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry());
int res = reinterpret_cast<int>(
CALL_GENERATED_CODE(isolate, f, 0, 0, 0, 0, 0));
auto f = GeneratedCode<F_iiiii>::FromCode(*code);
int res = reinterpret_cast<int>(f.Call(0, 0, 0, 0, 0));
::printf("res = %d\n", res);
CHECK_EQ(expected, res);
}
......@@ -705,7 +698,7 @@ TEST(8) {
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F4 fn = FUNCTION_CAST<F4>(Code::cast(code)->entry());
auto fn = GeneratedCode<F_ppiii>::FromCode(*code);
d.a = 1.1;
d.b = 2.2;
d.c = 3.3;
......@@ -724,8 +717,7 @@ TEST(8) {
f.g = 7.0;
f.h = 8.0;
Object* dummy = CALL_GENERATED_CODE(isolate, fn, &d, &f, 0, 0, 0);
USE(dummy);
fn.Call(&d, &f, 0, 0, 0);
CHECK_EQ(7.7, d.a);
CHECK_EQ(8.8, d.b);
......@@ -821,7 +813,7 @@ TEST(9) {
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F4 fn = FUNCTION_CAST<F4>(Code::cast(code)->entry());
auto fn = GeneratedCode<F_ppiii>::FromCode(*code);
d.a = 1.1;
d.b = 2.2;
d.c = 3.3;
......@@ -840,8 +832,7 @@ TEST(9) {
f.g = 7.0;
f.h = 8.0;
Object* dummy = CALL_GENERATED_CODE(isolate, fn, &d, &f, 0, 0, 0);
USE(dummy);
fn.Call(&d, &f, 0, 0, 0);
CHECK_EQ(7.7, d.a);
CHECK_EQ(8.8, d.b);
......@@ -933,7 +924,7 @@ TEST(10) {
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F4 fn = FUNCTION_CAST<F4>(Code::cast(code)->entry());
auto fn = GeneratedCode<F_ppiii>::FromCode(*code);
d.a = 1.1;
d.b = 2.2;
d.c = 3.3;
......@@ -952,8 +943,7 @@ TEST(10) {
f.g = 7.0;
f.h = 8.0;
Object* dummy = CALL_GENERATED_CODE(isolate, fn, &d, &f, 0, 0, 0);
USE(dummy);
fn.Call(&d, &f, 0, 0, 0);
CHECK_EQ(7.7, d.a);
CHECK_EQ(8.8, d.b);
......@@ -1031,9 +1021,8 @@ TEST(11) {
#ifdef DEBUG
Code::cast(code)->Print();
#endif
F3 f = FUNCTION_CAST<F3>(Code::cast(code)->entry());
Object* dummy = CALL_GENERATED_CODE(isolate, f, &i, 0, 0, 0, 0);
USE(dummy);
auto f = GeneratedCode<F_piiii>::FromCode(*code);
f.Call(&i, 0, 0, 0, 0);
CHECK_EQ(0xABCD0001, i.a);
CHECK_EQ(static_cast<int32_t>(0xABCD0000) >> 1, i.b);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment