Commit 42fa2718 authored by titzer@chromium.org's avatar titzer@chromium.org

TF: Lowering representation changes to machine operators (WIP: need inline...

TF: Lowering representation changes to machine operators (WIP: need inline allocation for some). Move tests related to lowering representation changes into test-changes-lowering.cc.

R=bmeurer@chromium.org, bmeuer@chromium.org
BUG=

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22781 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 956cd1c7
This diff is collapsed.
......@@ -27,22 +27,28 @@ class SimplifiedLowering : public LoweringBuilder {
virtual void Lower(Node* node);
// TODO(titzer): These are exposed for direct testing. Use a friend class.
void DoChangeTaggedToUI32(Node* node, Node* effect, Node* control,
bool is_signed);
void DoChangeUI32ToTagged(Node* node, Node* effect, Node* control,
bool is_signed);
void DoChangeTaggedToFloat64(Node* node, Node* effect, Node* control);
void DoChangeFloat64ToTagged(Node* node, Node* effect, Node* control);
void DoChangeBoolToBit(Node* node, Node* effect, Node* control);
void DoChangeBitToBool(Node* node, Node* effect, Node* control);
void DoLoadField(Node* node, Node* effect, Node* control);
void DoStoreField(Node* node, Node* effect, Node* control);
void DoLoadElement(Node* node, Node* effect, Node* control);
void DoStoreElement(Node* node, Node* effect, Node* control);
private:
JSGraph* jsgraph_;
MachineOperatorBuilder machine_;
Node* DoChangeTaggedToInt32(Node* node, Node* effect, Node* control);
Node* DoChangeTaggedToUint32(Node* node, Node* effect, Node* control);
Node* DoChangeTaggedToFloat64(Node* node, Node* effect, Node* control);
Node* DoChangeInt32ToTagged(Node* node, Node* effect, Node* control);
Node* DoChangeUint32ToTagged(Node* node, Node* effect, Node* control);
Node* DoChangeFloat64ToTagged(Node* node, Node* effect, Node* control);
Node* DoChangeBoolToBit(Node* node, Node* effect, Node* control);
Node* DoChangeBitToBool(Node* node, Node* effect, Node* control);
Node* DoLoadField(Node* node, Node* effect, Node* control);
Node* DoStoreField(Node* node, Node* effect, Node* control);
Node* DoLoadElement(Node* node, Node* effect, Node* control);
Node* DoStoreElement(Node* node, Node* effect, Node* control);
Node* SmiTag(Node* node);
Node* IsTagged(Node* node);
Node* Untag(Node* node);
Node* OffsetMinusTagConstant(int32_t offset);
Node* ComputeIndex(const ElementAccess& access, Node* index);
......
......@@ -53,6 +53,7 @@
'compiler/simplified-graph-builder.cc',
'compiler/simplified-graph-builder.h',
'compiler/test-branch-combine.cc',
'compiler/test-changes-lowering.cc',
'compiler/test-codegen-deopt.cc',
'compiler/test-gap-resolver.cc',
'compiler/test-graph-reducer.cc',
......
......@@ -84,11 +84,11 @@ class GraphBuilderTester
public SimplifiedGraphBuilder,
public CallHelper2<ReturnType, GraphBuilderTester<ReturnType> > {
public:
explicit GraphBuilderTester(MachineRepresentation p0,
MachineRepresentation p1,
MachineRepresentation p2,
MachineRepresentation p3,
MachineRepresentation p4)
explicit GraphBuilderTester(MachineRepresentation p0 = kMachineLast,
MachineRepresentation p1 = kMachineLast,
MachineRepresentation p2 = kMachineLast,
MachineRepresentation p3 = kMachineLast,
MachineRepresentation p4 = kMachineLast)
: GraphAndBuilders(main_zone()),
MachineCallHelper(
main_zone(),
......
This diff is collapsed.
......@@ -5,6 +5,7 @@
#include <limits>
#include "src/compiler/control-builders.h"
#include "src/compiler/generic-node-inl.h"
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/simplified-lowering.h"
......@@ -23,6 +24,7 @@
using namespace v8::internal;
using namespace v8::internal::compiler;
// TODO(titzer): rename this to VMLoweringTester
template <typename ReturnType>
class SimplifiedGraphBuilderTester : public GraphBuilderTester<ReturnType> {
public:
......@@ -31,16 +33,20 @@ class SimplifiedGraphBuilderTester : public GraphBuilderTester<ReturnType> {
MachineRepresentation p2 = kMachineLast,
MachineRepresentation p3 = kMachineLast,
MachineRepresentation p4 = kMachineLast)
: GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4) {}
: GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4),
typer(this->zone()),
source_positions(this->graph()),
jsgraph(this->graph(), this->common(), &typer),
lowering(&jsgraph, &source_positions) {}
Typer typer;
SourcePositionTable source_positions;
JSGraph jsgraph;
SimplifiedLowering lowering;
// Close graph and lower one node.
void Lower(Node* node) {
this->End();
Typer typer(this->zone());
CommonOperatorBuilder common(this->zone());
SourcePositionTable source_positions(this->graph());
JSGraph jsgraph(this->graph(), &common, &typer);
SimplifiedLowering lowering(&jsgraph, &source_positions);
if (node == NULL) {
lowering.LowerAllNodes();
} else {
......@@ -76,313 +82,6 @@ class SimplifiedGraphBuilderTester : public GraphBuilderTester<ReturnType> {
};
class SimplifiedGraphBuilderJSTester
: public SimplifiedGraphBuilderTester<Object*> {
public:
SimplifiedGraphBuilderJSTester()
: SimplifiedGraphBuilderTester<Object*>(),
f_(v8::Utils::OpenHandle(*v8::Handle<v8::Function>::Cast(CompileRun(
"(function() { 'use strict'; return 2.7123; })")))),
swapped_(false) {
set_current_context(HeapConstant(handle(f_->context())));
}
template <typename T>
T* CallJS() {
if (!swapped_) {
Compile();
}
Handle<Object>* args = NULL;
MaybeHandle<Object> result = Execution::Call(
isolate(), f_, factory()->undefined_value(), 0, args, false);
return T::cast(*result.ToHandleChecked());
}
private:
void Compile() {
CompilationInfoWithZone info(f_);
CHECK(Parser::Parse(&info));
StrictMode strict_mode = info.function()->strict_mode();
info.SetStrictMode(strict_mode);
info.SetOptimizing(BailoutId::None(), Handle<Code>(f_->code()));
CHECK(Rewriter::Rewrite(&info));
CHECK(Scope::Analyze(&info));
CHECK_NE(NULL, info.scope());
Pipeline pipeline(&info);
Linkage linkage(&info);
Handle<Code> code = pipeline.GenerateCodeForMachineGraph(&linkage, graph());
CHECK(!code.is_null());
f_->ReplaceCode(*code);
swapped_ = true;
}
Handle<JSFunction> f_;
bool swapped_;
};
TEST(RunChangeTaggedToInt32) {
SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged);
Node* x = t.ChangeTaggedToInt32(t.Parameter(0));
t.Return(x);
t.Lower(x);
// TODO(titzer): remove me.
return;
FOR_INT32_INPUTS(i) {
int32_t input = *i;
if (Smi::IsValid(input)) {
int32_t result = t.Call(Smi::FromInt(input));
CHECK_EQ(input, result);
}
{
Handle<Object> number = t.factory()->NewNumber(input);
int32_t result = t.Call(*number);
CHECK_EQ(input, result);
}
{
Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
int32_t result = t.Call(*number);
CHECK_EQ(input, result);
}
}
}
TEST(RunChangeTaggedToUint32) {
SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged);
Node* x = t.ChangeTaggedToUint32(t.Parameter(0));
t.Return(x);
t.Lower(x);
// TODO(titzer): remove me.
return;
FOR_UINT32_INPUTS(i) {
uint32_t input = *i;
if (Smi::IsValid(input)) {
int32_t result = t.Call(Smi::FromInt(input));
CHECK_EQ(static_cast<int32_t>(input), result);
}
{
Handle<Object> number = t.factory()->NewNumber(input);
int32_t result = t.Call(*number);
CHECK_EQ(static_cast<int32_t>(input), result);
}
{
Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
int32_t result = t.Call(*number);
CHECK_EQ(static_cast<int32_t>(input), result);
}
}
}
TEST(RunChangeTaggedToFloat64) {
SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged);
double result;
Node* x = t.ChangeTaggedToFloat64(t.Parameter(0));
t.StoreFloat64(x, &result);
t.Return(t.Int32Constant(0));
t.Lower(x);
// TODO(titzer): remove me.
return;
{
FOR_INT32_INPUTS(i) {
int32_t input = *i;
if (Smi::IsValid(input)) {
t.Call(Smi::FromInt(input));
CHECK_EQ(input, static_cast<int32_t>(result));
}
{
Handle<Object> number = t.factory()->NewNumber(input);
t.Call(*number);
CHECK_EQ(input, static_cast<int32_t>(result));
}
{
Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
t.Call(*number);
CHECK_EQ(input, static_cast<int32_t>(result));
}
}
}
{
FOR_FLOAT64_INPUTS(i) {
double input = *i;
{
Handle<Object> number = t.factory()->NewNumber(input);
t.Call(*number);
CHECK_EQ(input, result);
}
{
Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
t.Call(*number);
CHECK_EQ(input, result);
}
}
}
}
TEST(RunChangeBoolToBit) {
SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged);
Node* x = t.ChangeBoolToBit(t.Parameter(0));
t.Return(x);
t.Lower(x);
if (!Pipeline::SupportedTarget()) return;
{
Object* true_obj = t.heap()->true_value();
int32_t result = t.Call(true_obj);
CHECK_EQ(1, result);
}
{
Object* false_obj = t.heap()->false_value();
int32_t result = t.Call(false_obj);
CHECK_EQ(0, result);
}
}
TEST(RunChangeBitToBool) {
SimplifiedGraphBuilderTester<Object*> t(kMachineTagged);
Node* x = t.ChangeBitToBool(t.Parameter(0));
t.Return(x);
t.Lower(x);
// TODO(titzer): remove me.
return;
{
Object* result = t.Call(1);
Object* true_obj = t.heap()->true_value();
CHECK_EQ(true_obj, result);
}
{
Object* result = t.Call(0);
Object* false_obj = t.heap()->false_value();
CHECK_EQ(false_obj, result);
}
}
TEST(RunChangeInt32ToTagged) {
SimplifiedGraphBuilderJSTester t;
int32_t input;
Node* load = t.LoadInt32(&input);
Node* x = t.ChangeInt32ToTagged(load);
t.Return(x);
t.Lower(x);
// TODO(titzer): remove me.
return;
{
FOR_INT32_INPUTS(i) {
input = *i;
HeapNumber* result = t.CallJS<HeapNumber>();
CHECK_EQ(static_cast<double>(input), result->value());
}
}
{
FOR_INT32_INPUTS(i) {
input = *i;
SimulateFullSpace(CcTest::heap()->new_space());
HeapNumber* result = t.CallJS<HeapNumber>();
CHECK_EQ(static_cast<double>(input), result->value());
}
}
}
TEST(RunChangeUint32ToTagged) {
SimplifiedGraphBuilderJSTester t;
uint32_t input;
Node* load = t.LoadUint32(&input);
Node* x = t.ChangeUint32ToTagged(load);
t.Return(x);
t.Lower(x);
// TODO(titzer): remove me.
return;
{
FOR_UINT32_INPUTS(i) {
input = *i;
HeapNumber* result = t.CallJS<HeapNumber>();
double expected = static_cast<double>(input);
CHECK_EQ(expected, result->value());
}
}
{
FOR_UINT32_INPUTS(i) {
input = *i;
SimulateFullSpace(CcTest::heap()->new_space());
HeapNumber* result = t.CallJS<HeapNumber>();
double expected = static_cast<double>(static_cast<uint32_t>(input));
CHECK_EQ(expected, result->value());
}
}
}
TEST(RunChangeFloat64ToTagged) {
SimplifiedGraphBuilderJSTester t;
double input;
Node* load = t.LoadFloat64(&input);
Node* x = t.ChangeFloat64ToTagged(load);
t.Return(x);
t.Lower(x);
// TODO(titzer): remove me.
return;
{
FOR_FLOAT64_INPUTS(i) {
input = *i;
HeapNumber* result = t.CallJS<HeapNumber>();
CHECK_EQ(input, result->value());
}
}
{
FOR_FLOAT64_INPUTS(i) {
input = *i;
SimulateFullSpace(CcTest::heap()->new_space());
HeapNumber* result = t.CallJS<HeapNumber>();
CHECK_EQ(input, result->value());
}
}
}
// TODO(dcarney): find a home for these functions.
namespace {
......
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