Commit 4418b486 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[cleanup] Refactor codegen-tester

The implementation can be greatly simplified by using variadic
templates.

R=mstarzinger@chromium.org

Change-Id: Ifbda09bc536c9660a83d1888b395e92367c9b03e
Reviewed-on: https://chromium-review.googlesource.com/860458Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50603}
parent 3bcc6b3e
...@@ -22,22 +22,18 @@ class RawMachineAssemblerTester : public HandleAndZoneScope, ...@@ -22,22 +22,18 @@ class RawMachineAssemblerTester : public HandleAndZoneScope,
public CallHelper<ReturnType>, public CallHelper<ReturnType>,
public RawMachineAssembler { public RawMachineAssembler {
public: public:
RawMachineAssemblerTester(MachineType p0 = MachineType::None(), template <typename... ParamMachTypes>
MachineType p1 = MachineType::None(), explicit RawMachineAssemblerTester(ParamMachTypes... p)
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None(),
MachineType p4 = MachineType::None())
: HandleAndZoneScope(), : HandleAndZoneScope(),
CallHelper<ReturnType>( CallHelper<ReturnType>(
main_isolate(), main_isolate(),
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1, CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p...)),
p2, p3, p4)),
RawMachineAssembler( RawMachineAssembler(
main_isolate(), new (main_zone()) Graph(main_zone()), main_isolate(), new (main_zone()) Graph(main_zone()),
Linkage::GetSimplifiedCDescriptor( Linkage::GetSimplifiedCDescriptor(
main_zone(), main_zone(),
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, CSignature::New(main_zone(), MachineTypeForC<ReturnType>(),
p1, p2, p3, p4), p...),
true), true),
MachineType::PointerRepresentation(), MachineType::PointerRepresentation(),
InstructionSelector::SupportedMachineOperatorFlags(), InstructionSelector::SupportedMachineOperatorFlags(),
...@@ -79,17 +75,24 @@ class RawMachineAssemblerTester : public HandleAndZoneScope, ...@@ -79,17 +75,24 @@ class RawMachineAssemblerTester : public HandleAndZoneScope,
MaybeHandle<Code> code_; MaybeHandle<Code> code_;
}; };
template <typename ReturnType> template <typename ReturnType>
class BufferedRawMachineAssemblerTester class BufferedRawMachineAssemblerTester
: public RawMachineAssemblerTester<int32_t> { : public RawMachineAssemblerTester<int32_t> {
public: public:
BufferedRawMachineAssemblerTester(MachineType p0 = MachineType::None(), template <typename... ParamMachTypes>
MachineType p1 = MachineType::None(), explicit BufferedRawMachineAssemblerTester(ParamMachTypes... p)
MachineType p2 = MachineType::None(), : RawMachineAssemblerTester<int32_t>(
MachineType p3 = MachineType::None()) MachineType::Pointer(), ((void)p, MachineType::Pointer())...),
: BufferedRawMachineAssemblerTester(ComputeParameterCount(p0, p1, p2, p3), test_graph_signature_(
p0, p1, p2, p3) {} CSignature::New(this->main_zone(), MachineType::Int32(), p...)),
return_parameter_index_(sizeof...(p)) {
static_assert(sizeof...(p) <= arraysize(parameter_nodes_),
"increase parameter_nodes_ array");
std::array<MachineType, sizeof...(p)> p_arr{p...};
for (size_t i = 0; i < p_arr.size(); ++i) {
parameter_nodes_[i] = Load(p_arr[i], RawMachineAssembler::Parameter(i));
}
}
virtual byte* Generate() { return RawMachineAssemblerTester::Generate(); } virtual byte* Generate() { return RawMachineAssemblerTester::Generate(); }
...@@ -99,7 +102,7 @@ class BufferedRawMachineAssemblerTester ...@@ -99,7 +102,7 @@ class BufferedRawMachineAssemblerTester
// parameters from memory. Thereby it is possible to pass 64 bit parameters // parameters from memory. Thereby it is possible to pass 64 bit parameters
// to the IR graph. // to the IR graph.
Node* Parameter(size_t index) { Node* Parameter(size_t index) {
CHECK_GT(4, index); CHECK_GT(arraysize(parameter_nodes_), index);
return parameter_nodes_[index]; return parameter_nodes_[index];
} }
...@@ -114,141 +117,37 @@ class BufferedRawMachineAssemblerTester ...@@ -114,141 +117,37 @@ class BufferedRawMachineAssemblerTester
RawMachineAssembler::Return(Int32Constant(1234)); RawMachineAssembler::Return(Int32Constant(1234));
} }
ReturnType Call() { template <typename... Params>
ReturnType return_value; ReturnType Call(Params... p) {
CSignature::VerifyParams(test_graph_signature_);
CallHelper<int32_t>::Call(reinterpret_cast<void*>(&return_value));
return return_value;
}
template <typename P0>
ReturnType Call(P0 p0) {
ReturnType return_value; ReturnType return_value;
CSignature::VerifyParams<P0>(test_graph_signature_); CSignature::VerifyParams<Params...>(test_graph_signature_);
CallHelper<int32_t>::Call(reinterpret_cast<void*>(&p0), CallHelper<int32_t>::Call(reinterpret_cast<void*>(&p)...,
reinterpret_cast<void*>(&return_value)); reinterpret_cast<void*>(&return_value));
return return_value; return return_value;
} }
template <typename P0, typename P1>
ReturnType Call(P0 p0, P1 p1) {
ReturnType return_value;
CSignature::VerifyParams<P0, P1>(test_graph_signature_);
CallHelper<int32_t>::Call(reinterpret_cast<void*>(&p0),
reinterpret_cast<void*>(&p1),
reinterpret_cast<void*>(&return_value));
return return_value;
}
template <typename P0, typename P1, typename P2>
ReturnType Call(P0 p0, P1 p1, P2 p2) {
ReturnType return_value;
CSignature::VerifyParams<P0, P1, P2>(test_graph_signature_);
CallHelper<int32_t>::Call(
reinterpret_cast<void*>(&p0), reinterpret_cast<void*>(&p1),
reinterpret_cast<void*>(&p2), reinterpret_cast<void*>(&return_value));
return return_value;
}
template <typename P0, typename P1, typename P2, typename P3>
ReturnType Call(P0 p0, P1 p1, P2 p2, P3 p3) {
ReturnType return_value;
CSignature::VerifyParams<P0, P1, P2, P3>(test_graph_signature_);
CallHelper<int32_t>::Call(
reinterpret_cast<void*>(&p0), reinterpret_cast<void*>(&p1),
reinterpret_cast<void*>(&p2), reinterpret_cast<void*>(&p3),
reinterpret_cast<void*>(&return_value));
return return_value;
}
private: private:
BufferedRawMachineAssemblerTester(uint32_t return_parameter_index,
MachineType p0, MachineType p1,
MachineType p2, MachineType p3)
: RawMachineAssemblerTester<int32_t>(
MachineType::Pointer(),
p0 == MachineType::None() ? MachineType::None()
: MachineType::Pointer(),
p1 == MachineType::None() ? MachineType::None()
: MachineType::Pointer(),
p2 == MachineType::None() ? MachineType::None()
: MachineType::Pointer(),
p3 == MachineType::None() ? MachineType::None()
: MachineType::Pointer()),
test_graph_signature_(
CSignature::New(main_zone(), MachineType::Int32(), p0, p1, p2, p3)),
return_parameter_index_(return_parameter_index) {
parameter_nodes_[0] = p0 == MachineType::None()
? nullptr
: Load(p0, RawMachineAssembler::Parameter(0));
parameter_nodes_[1] = p1 == MachineType::None()
? nullptr
: Load(p1, RawMachineAssembler::Parameter(1));
parameter_nodes_[2] = p2 == MachineType::None()
? nullptr
: Load(p2, RawMachineAssembler::Parameter(2));
parameter_nodes_[3] = p3 == MachineType::None()
? nullptr
: Load(p3, RawMachineAssembler::Parameter(3));
}
static uint32_t ComputeParameterCount(MachineType p0, MachineType p1,
MachineType p2, MachineType p3) {
if (p0 == MachineType::None()) {
return 0;
}
if (p1 == MachineType::None()) {
return 1;
}
if (p2 == MachineType::None()) {
return 2;
}
if (p3 == MachineType::None()) {
return 3;
}
return 4;
}
CSignature* test_graph_signature_; CSignature* test_graph_signature_;
Node* parameter_nodes_[4]; Node* parameter_nodes_[4];
uint32_t return_parameter_index_; uint32_t return_parameter_index_;
}; };
template <> template <>
class BufferedRawMachineAssemblerTester<void> class BufferedRawMachineAssemblerTester<void>
: public RawMachineAssemblerTester<void> { : public RawMachineAssemblerTester<void> {
public: public:
BufferedRawMachineAssemblerTester(MachineType p0 = MachineType::None(), template <typename... ParamMachTypes>
MachineType p1 = MachineType::None(), explicit BufferedRawMachineAssemblerTester(ParamMachTypes... p)
MachineType p2 = MachineType::None(), : RawMachineAssemblerTester<void>(((void)p, MachineType::Pointer())...),
MachineType p3 = MachineType::None())
: RawMachineAssemblerTester<void>(
p0 == MachineType::None() ? MachineType::None()
: MachineType::Pointer(),
p1 == MachineType::None() ? MachineType::None()
: MachineType::Pointer(),
p2 == MachineType::None() ? MachineType::None()
: MachineType::Pointer(),
p3 == MachineType::None() ? MachineType::None()
: MachineType::Pointer()),
test_graph_signature_( test_graph_signature_(
CSignature::New(RawMachineAssemblerTester<void>::main_zone(), CSignature::New(RawMachineAssemblerTester<void>::main_zone(),
MachineType::None(), p0, p1, p2, p3)) { MachineType::None(), p...)) {
parameter_nodes_[0] = p0 == MachineType::None() static_assert(sizeof...(p) <= arraysize(parameter_nodes_),
? nullptr "increase parameter_nodes_ array");
: Load(p0, RawMachineAssembler::Parameter(0)); std::array<MachineType, sizeof...(p)> p_arr{p...};
parameter_nodes_[1] = p1 == MachineType::None() for (size_t i = 0; i < p_arr.size(); ++i) {
? nullptr parameter_nodes_[i] = Load(p_arr[i], RawMachineAssembler::Parameter(i));
: Load(p1, RawMachineAssembler::Parameter(1)); }
parameter_nodes_[2] = p2 == MachineType::None()
? nullptr
: Load(p2, RawMachineAssembler::Parameter(2));
parameter_nodes_[3] = p3 == MachineType::None()
? nullptr
: Load(p3, RawMachineAssembler::Parameter(3));
} }
virtual byte* Generate() { return RawMachineAssemblerTester::Generate(); } virtual byte* Generate() { return RawMachineAssemblerTester::Generate(); }
...@@ -259,49 +158,21 @@ class BufferedRawMachineAssemblerTester<void> ...@@ -259,49 +158,21 @@ class BufferedRawMachineAssemblerTester<void>
// parameters from memory. Thereby it is possible to pass 64 bit parameters // parameters from memory. Thereby it is possible to pass 64 bit parameters
// to the IR graph. // to the IR graph.
Node* Parameter(size_t index) { Node* Parameter(size_t index) {
CHECK_GT(4, index); CHECK_GT(arraysize(parameter_nodes_), index);
return parameter_nodes_[index]; return parameter_nodes_[index];
} }
template <typename... Params>
void Call() { void Call(Params... p) {
CSignature::VerifyParams(test_graph_signature_); CSignature::VerifyParams<Params...>(test_graph_signature_);
CallHelper<void>::Call(); CallHelper<void>::Call(reinterpret_cast<void*>(&p)...);
}
template <typename P0>
void Call(P0 p0) {
CSignature::VerifyParams<P0>(test_graph_signature_);
CallHelper<void>::Call(reinterpret_cast<void*>(&p0));
}
template <typename P0, typename P1>
void Call(P0 p0, P1 p1) {
CSignature::VerifyParams<P0, P1>(test_graph_signature_);
CallHelper<void>::Call(reinterpret_cast<void*>(&p0),
reinterpret_cast<void*>(&p1));
}
template <typename P0, typename P1, typename P2>
void Call(P0 p0, P1 p1, P2 p2) {
CSignature::VerifyParams<P0, P1, P2>(test_graph_signature_);
CallHelper<void>::Call(reinterpret_cast<void*>(&p0),
reinterpret_cast<void*>(&p1),
reinterpret_cast<void*>(&p2));
}
template <typename P0, typename P1, typename P2, typename P3>
void Call(P0 p0, P1 p1, P2 p2, P3 p3) {
CSignature::VerifyParams<P0, P1, P2, P3>(test_graph_signature_);
CallHelper<void>::Call(
reinterpret_cast<void*>(&p0), reinterpret_cast<void*>(&p1),
reinterpret_cast<void*>(&p2), reinterpret_cast<void*>(&p3));
} }
private: private:
CSignature* test_graph_signature_; CSignature* test_graph_signature_;
Node* parameter_nodes_[4]; Node* parameter_nodes_[4];
}; };
static const bool USE_RESULT_BUFFER = true; static const bool USE_RESULT_BUFFER = true;
static const bool USE_RETURN_REGISTER = false; static const bool USE_RETURN_REGISTER = false;
static const int32_t CHECK_VALUE = 0x99BEEDCE; static const int32_t CHECK_VALUE = 0x99BEEDCE;
......
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