Commit 30ef6b7a authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Clean up cctest "framework" for dealing with native calls.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1164603002

Cr-Commit-Position: refs/heads/master@{#28703}
parent 43638cd4
...@@ -302,15 +302,6 @@ class RawMachineAssembler : public GraphBuilder { ...@@ -302,15 +302,6 @@ class RawMachineAssembler : public GraphBuilder {
return NewNode(machine()->Uint64Mod(), a, b); return NewNode(machine()->Uint64Mod(), a, b);
} }
// TODO(turbofan): What is this used for?
Node* ConvertIntPtrToInt32(Node* a) {
return kPointerSize == 8 ? NewNode(machine()->TruncateInt64ToInt32(), a)
: a;
}
Node* ConvertInt32ToIntPtr(Node* a) {
return kPointerSize == 8 ? NewNode(machine()->ChangeInt32ToInt64(), a) : a;
}
#define INTPTR_BINOP(prefix, name) \ #define INTPTR_BINOP(prefix, name) \
Node* IntPtr##name(Node* a, Node* b) { \ Node* IntPtr##name(Node* a, Node* b) { \
return kPointerSize == 8 ? prefix##64##name(a, b) \ return kPointerSize == 8 ? prefix##64##name(a, b) \
...@@ -454,6 +445,17 @@ class RawMachineAssembler : public GraphBuilder { ...@@ -454,6 +445,17 @@ class RawMachineAssembler : public GraphBuilder {
// Parameters. // Parameters.
Node* Parameter(size_t index); Node* Parameter(size_t index);
// Pointer utilities.
Node* LoadFromPointer(void* address, MachineType rep, int32_t offset = 0) {
return Load(rep, PointerConstant(address), Int32Constant(offset));
}
void StoreToPointer(void* address, MachineType rep, Node* node) {
Store(rep, PointerConstant(address), node);
}
Node* StringConstant(const char* string) {
return HeapConstant(isolate()->factory()->InternalizeUtf8String(string));
}
// Control flow. // Control flow.
Label* Exit(); Label* Exit();
void Goto(Label* label); void Goto(Label* label);
......
This diff is collapsed.
...@@ -17,38 +17,28 @@ namespace v8 { ...@@ -17,38 +17,28 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
template <typename MachineAssembler> template <typename ReturnType>
class MachineAssemblerTester : public HandleAndZoneScope, class RawMachineAssemblerTester : public HandleAndZoneScope,
public CallHelper, public CallHelper<ReturnType>,
public MachineAssembler { public RawMachineAssembler {
public: public:
MachineAssemblerTester(MachineType return_type, MachineType p0, RawMachineAssemblerTester(MachineType p0 = kMachNone,
MachineType p1, MachineType p2, MachineType p3, MachineType p1 = kMachNone,
MachineType p4, MachineType p2 = kMachNone,
MachineOperatorBuilder::Flags flags = MachineType p3 = kMachNone,
MachineOperatorBuilder::Flag::kNoFlags) MachineType p4 = kMachNone)
: HandleAndZoneScope(), : HandleAndZoneScope(),
CallHelper( CallHelper<ReturnType>(
main_isolate(), main_isolate(),
MakeMachineSignature(main_zone(), return_type, p0, p1, p2, p3, p4)), MakeMachineSignature(
MachineAssembler( main_zone(), ReturnValueTraits<ReturnType>::Representation(),
p0, p1, p2, p3, p4)),
RawMachineAssembler(
main_isolate(), new (main_zone()) Graph(main_zone()), main_isolate(), new (main_zone()) Graph(main_zone()),
MakeMachineSignature(main_zone(), return_type, p0, p1, p2, p3, p4), MakeMachineSignature(
kMachPtr, flags) {} main_zone(), ReturnValueTraits<ReturnType>::Representation(),
p0, p1, p2, p3, p4),
Node* LoadFromPointer(void* address, MachineType rep, int32_t offset = 0) { kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()) {}
return this->Load(rep, this->PointerConstant(address),
this->Int32Constant(offset));
}
void StoreToPointer(void* address, MachineType rep, Node* node) {
this->Store(rep, this->PointerConstant(address), node);
}
Node* StringConstant(const char* string) {
return this->HeapConstant(
this->isolate()->factory()->InternalizeUtf8String(string));
}
void CheckNumber(double expected, Object* number) { void CheckNumber(double expected, Object* number) {
CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number)); CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number));
...@@ -76,40 +66,26 @@ class MachineAssemblerTester : public HandleAndZoneScope, ...@@ -76,40 +66,26 @@ class MachineAssemblerTester : public HandleAndZoneScope,
private: private:
MaybeHandle<Code> code_; MaybeHandle<Code> code_;
};
template <typename ReturnType>
class RawMachineAssemblerTester
: public MachineAssemblerTester<RawMachineAssembler>,
public CallHelper2<ReturnType, RawMachineAssemblerTester<ReturnType> > {
public:
RawMachineAssemblerTester(MachineType p0 = kMachNone,
MachineType p1 = kMachNone,
MachineType p2 = kMachNone,
MachineType p3 = kMachNone,
MachineType p4 = kMachNone)
: MachineAssemblerTester<RawMachineAssembler>(
ReturnValueTraits<ReturnType>::Representation(), p0, p1, p2, p3, p4,
InstructionSelector::SupportedMachineOperatorFlags()) {}
template <typename Ci, typename Fn> // TODO(titzer): factor me elsewhere.
void Run(const Ci& ci, const Fn& fn) { static MachineSignature* MakeMachineSignature(
typename Ci::const_iterator i; Zone* zone, MachineType return_type, MachineType p0 = kMachNone,
for (i = ci.begin(); i != ci.end(); ++i) { MachineType p1 = kMachNone, MachineType p2 = kMachNone,
CHECK_EQ(fn(*i), this->Call(*i)); MachineType p3 = kMachNone, MachineType p4 = kMachNone) {
} // Count the number of parameters.
} size_t param_count = 5;
MachineType types[] = {p0, p1, p2, p3, p4};
template <typename Ci, typename Cj, typename Fn> while (param_count > 0 && types[param_count - 1] == kMachNone)
void Run(const Ci& ci, const Cj& cj, const Fn& fn) { param_count--;
typename Ci::const_iterator i; size_t return_count = return_type == kMachNone ? 0 : 1;
typename Cj::const_iterator j;
for (i = ci.begin(); i != ci.end(); ++i) { // Build the machine signature.
for (j = cj.begin(); j != cj.end(); ++j) { MachineSignature::Builder builder(zone, return_count, param_count);
CHECK_EQ(fn(*i, *j), this->Call(*i, *j)); if (return_count > 0) builder.AddReturn(return_type);
} for (size_t i = 0; i < param_count; i++) {
builder.AddParam(types[i]);
} }
return builder.Build();
} }
}; };
......
...@@ -39,12 +39,10 @@ class GraphAndBuilders { ...@@ -39,12 +39,10 @@ class GraphAndBuilders {
template <typename ReturnType> template <typename ReturnType>
class GraphBuilderTester class GraphBuilderTester : public HandleAndZoneScope,
: public HandleAndZoneScope, private GraphAndBuilders,
private GraphAndBuilders, public CallHelper<ReturnType>,
public CallHelper, public SimplifiedGraphBuilder {
public SimplifiedGraphBuilder,
public CallHelper2<ReturnType, GraphBuilderTester<ReturnType> > {
public: public:
explicit GraphBuilderTester(MachineType p0 = kMachNone, explicit GraphBuilderTester(MachineType p0 = kMachNone,
MachineType p1 = kMachNone, MachineType p1 = kMachNone,
...@@ -52,7 +50,7 @@ class GraphBuilderTester ...@@ -52,7 +50,7 @@ class GraphBuilderTester
MachineType p3 = kMachNone, MachineType p3 = kMachNone,
MachineType p4 = kMachNone) MachineType p4 = kMachNone)
: GraphAndBuilders(main_zone()), : GraphAndBuilders(main_zone()),
CallHelper( CallHelper<ReturnType>(
main_isolate(), main_isolate(),
MakeMachineSignature( MakeMachineSignature(
main_zone(), ReturnValueTraits<ReturnType>::Representation(), main_zone(), ReturnValueTraits<ReturnType>::Representation(),
...@@ -79,7 +77,7 @@ class GraphBuilderTester ...@@ -79,7 +77,7 @@ class GraphBuilderTester
if (code_.is_null()) { if (code_.is_null()) {
Zone* zone = graph()->zone(); Zone* zone = graph()->zone();
CallDescriptor* desc = CallDescriptor* desc =
Linkage::GetSimplifiedCDescriptor(zone, machine_sig_); Linkage::GetSimplifiedCDescriptor(zone, this->machine_sig_);
code_ = Pipeline::GenerateCodeForTesting(main_isolate(), desc, graph()); code_ = Pipeline::GenerateCodeForTesting(main_isolate(), desc, graph());
} }
return code_.ToHandleChecked()->entry(); return code_.ToHandleChecked()->entry();
...@@ -92,11 +90,34 @@ class GraphBuilderTester ...@@ -92,11 +90,34 @@ class GraphBuilderTester
} }
} }
size_t parameter_count() const { return machine_sig_->parameter_count(); } size_t parameter_count() const {
return this->machine_sig_->parameter_count();
}
private: private:
Node** parameters_; Node** parameters_;
MaybeHandle<Code> code_; MaybeHandle<Code> code_;
// TODO(titzer): factor me elsewhere.
static MachineSignature* MakeMachineSignature(
Zone* zone, MachineType return_type, MachineType p0 = kMachNone,
MachineType p1 = kMachNone, MachineType p2 = kMachNone,
MachineType p3 = kMachNone, MachineType p4 = kMachNone) {
// Count the number of parameters.
size_t param_count = 5;
MachineType types[] = {p0, p1, p2, p3, p4};
while (param_count > 0 && types[param_count - 1] == kMachNone)
param_count--;
size_t return_count = return_type == kMachNone ? 0 : 1;
// Build the machine signature.
MachineSignature::Builder builder(zone, return_count, param_count);
if (return_count > 0) builder.AddReturn(return_type);
for (size_t i = 0; i < param_count; i++) {
builder.AddParam(types[i]);
}
return builder.Build();
}
}; };
} // namespace compiler } // namespace compiler
......
...@@ -4395,7 +4395,7 @@ TEST(RunTestIntPtrArithmetic) { ...@@ -4395,7 +4395,7 @@ TEST(RunTestIntPtrArithmetic) {
RawMachineAssemblerTester<int32_t*> m; RawMachineAssemblerTester<int32_t*> m;
Node* input = m.PointerConstant(&inputs[0]); Node* input = m.PointerConstant(&inputs[0]);
Node* output = m.PointerConstant(&outputs[kInputSize - 1]); Node* output = m.PointerConstant(&outputs[kInputSize - 1]);
Node* elem_size = m.ConvertInt32ToIntPtr(m.Int32Constant(sizeof(inputs[0]))); Node* elem_size = m.IntPtrConstant(sizeof(inputs[0]));
for (int i = 0; i < kInputSize; i++) { for (int i = 0; i < kInputSize; i++) {
m.Store(kMachInt32, output, m.Load(kMachInt32, input)); m.Store(kMachInt32, output, m.Load(kMachInt32, input));
input = m.IntPtrAdd(input, elem_size); input = m.IntPtrAdd(input, elem_size);
......
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