Revision: 22781
Author: [email protected]
Date: Fri Aug 1 08:16:19 2014 UTC
Log: 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.
[email protected], [email protected]
BUG=
Review URL: https://codereview.chromium.org/437583002
http://code.google.com/p/v8/source/detail?r=22781
Added:
/branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
Modified:
/branches/bleeding_edge/src/compiler/simplified-lowering.cc
/branches/bleeding_edge/src/compiler/simplified-lowering.h
/branches/bleeding_edge/test/cctest/cctest.gyp
/branches/bleeding_edge/test/cctest/compiler/graph-builder-tester.h
/branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
Fri Aug 1 08:16:19 2014 UTC
@@ -0,0 +1,386 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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"
+#include "src/compiler/simplified-node-factory.h"
+#include "src/compiler/typer.h"
+#include "src/compiler/verifier.h"
+#include "src/execution.h"
+#include "src/parser.h"
+#include "src/rewriter.h"
+#include "src/scopes.h"
+#include "test/cctest/cctest.h"
+#include "test/cctest/compiler/codegen-tester.h"
+#include "test/cctest/compiler/graph-builder-tester.h"
+#include "test/cctest/compiler/value-helper.h"
+
+using namespace v8::internal;
+using namespace v8::internal::compiler;
+
+template <typename ReturnType>
+class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
+ public:
+ explicit ChangesLoweringTester(MachineRepresentation p0 = kMachineLast)
+ : GraphBuilderTester<ReturnType>(p0),
+ typer(this->zone()),
+ source_positions(this->graph()),
+ jsgraph(this->graph(), this->common(), &typer),
+ lowering(&jsgraph, &source_positions),
+ function(Handle<JSFunction>::null()) {}
+
+ Typer typer;
+ SourcePositionTable source_positions;
+ JSGraph jsgraph;
+ SimplifiedLowering lowering;
+ Handle<JSFunction> function;
+
+ Node* start() { return this->graph()->start(); }
+
+ template <typename T>
+ T* CallWithPotentialGC() {
+ // TODO(titzer): we need to wrap the code in a JSFunction and call it
via
+ // Execution::Call() so that the GC knows about the frame, can walk it,
+ // relocate the code object if necessary, etc.
+ // This is pretty ugly and at the least should be moved up to helpers.
+ if (function.is_null()) {
+ function =
+ v8::Utils::OpenHandle(*v8::Handle<v8::Function>::Cast(CompileRun(
+ "(function() { 'use strict'; return 2.7123; })")));
+ CompilationInfoWithZone info(function);
+ CHECK(Parser::Parse(&info));
+ StrictMode strict_mode = info.function()->strict_mode();
+ info.SetStrictMode(strict_mode);
+ info.SetOptimizing(BailoutId::None(),
Handle<Code>(function->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, this->graph());
+ CHECK(!code.is_null());
+ function->ReplaceCode(*code);
+ }
+ Handle<Object>* args = NULL;
+ MaybeHandle<Object> result =
+ Execution::Call(this->isolate(), function,
factory()->undefined_value(),
+ 0, args, false);
+ return T::cast(*result.ToHandleChecked());
+ }
+
+ void StoreFloat64(Node* node, double* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ this->Store(kMachineFloat64, ptr_node, node);
+ }
+
+ Node* LoadInt32(int32_t* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ return this->Load(kMachineWord32, ptr_node);
+ }
+
+ Node* LoadUint32(uint32_t* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ return this->Load(kMachineWord32, ptr_node);
+ }
+
+ Node* LoadFloat64(double* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ return this->Load(kMachineFloat64, ptr_node);
+ }
+
+ void CheckNumber(double expected, Object* number) {
+
CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number));
+ }
+
+ void BuildAndLower(Operator* op) {
+ // We build a graph by hand here, because the raw machine assembler
+ // does not add the correct control and effect nodes.
+ Node* p0 = this->Parameter(0);
+ Node* change = this->graph()->NewNode(op, p0);
+ Node* ret = this->graph()->NewNode(this->common()->Return(), change,
+ this->start(), this->start());
+ Node* end = this->graph()->NewNode(this->common()->End(), ret);
+ this->graph()->SetEnd(end);
+ this->lowering.Lower(change);
+ Verifier::Run(this->graph());
+ }
+
+ void BuildStoreAndLower(Operator* op, Operator* store_op, void*
location) {
+ // We build a graph by hand here, because the raw machine assembler
+ // does not add the correct control and effect nodes.
+ Node* p0 = this->Parameter(0);
+ Node* change = this->graph()->NewNode(op, p0);
+ Node* store = this->graph()->NewNode(
+ store_op, this->PointerConstant(location), this->Int32Constant(0),
+ change, this->start(), this->start());
+ Node* ret = this->graph()->NewNode(
+ this->common()->Return(), this->Int32Constant(0), store,
this->start());
+ Node* end = this->graph()->NewNode(this->common()->End(), ret);
+ this->graph()->SetEnd(end);
+ this->lowering.Lower(change);
+ Verifier::Run(this->graph());
+ }
+
+ void BuildLoadAndLower(Operator* op, Operator* load_op, void* location) {
+ // We build a graph by hand here, because the raw machine assembler
+ // does not add the correct control and effect nodes.
+ Node* load =
+ this->graph()->NewNode(load_op, this->PointerConstant(location),
+ this->Int32Constant(0), this->start());
+ Node* change = this->graph()->NewNode(op, load);
+ Node* ret = this->graph()->NewNode(this->common()->Return(), change,
+ this->start(), this->start());
+ Node* end = this->graph()->NewNode(this->common()->End(), ret);
+ this->graph()->SetEnd(end);
+ this->lowering.Lower(change);
+ Verifier::Run(this->graph());
+ }
+
+ Factory* factory() { return this->isolate()->factory(); }
+ Heap* heap() { return this->isolate()->heap(); }
+};
+
+
+TEST(RunChangeTaggedToInt32) {
+ // Build and lower a graph by hand.
+ ChangesLoweringTester<int32_t> t(kMachineTagged);
+ t.BuildAndLower(t.simplified()->ChangeTaggedToInt32());
+
+ if (Pipeline::SupportedTarget()) {
+ 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) {
+ // Build and lower a graph by hand.
+ ChangesLoweringTester<uint32_t> t(kMachineTagged);
+ t.BuildAndLower(t.simplified()->ChangeTaggedToUint32());
+
+ if (Pipeline::SupportedTarget()) {
+ FOR_UINT32_INPUTS(i) {
+ uint32_t input = *i;
+
+ if (Smi::IsValid(input)) {
+ uint32_t result = t.Call(Smi::FromInt(input));
+ CHECK_EQ(static_cast<int32_t>(input),
static_cast<int32_t>(result));
+ }
+
+ {
+ Handle<Object> number = t.factory()->NewNumber(input);
+ uint32_t result = t.Call(*number);
+ CHECK_EQ(static_cast<int32_t>(input),
static_cast<int32_t>(result));
+ }
+
+ {
+ Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
+ uint32_t result = t.Call(*number);
+ CHECK_EQ(static_cast<int32_t>(input),
static_cast<int32_t>(result));
+ }
+ }
+ }
+}
+
+
+TEST(RunChangeTaggedToFloat64) {
+ ChangesLoweringTester<int32_t> t(kMachineTagged);
+ double result;
+
+ t.BuildStoreAndLower(t.simplified()->ChangeTaggedToFloat64(),
+ t.machine()->Store(kMachineFloat64), &result);
+
+ if (Pipeline::SupportedTarget()) {
+ 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));
+ }
+ }
+ }
+
+ if (Pipeline::SupportedTarget()) {
+ 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) {
+ ChangesLoweringTester<int32_t> t(kMachineTagged);
+ t.BuildAndLower(t.simplified()->ChangeBoolToBit());
+
+ if (Pipeline::SupportedTarget()) {
+ Object* true_obj = t.heap()->true_value();
+ int32_t result = t.Call(true_obj);
+ CHECK_EQ(1, result);
+ }
+
+ if (Pipeline::SupportedTarget()) {
+ Object* false_obj = t.heap()->false_value();
+ int32_t result = t.Call(false_obj);
+ CHECK_EQ(0, result);
+ }
+}
+
+
+TEST(RunChangeBitToBool) {
+ ChangesLoweringTester<Object*> t(kMachineWord32);
+ t.BuildAndLower(t.simplified()->ChangeBitToBool());
+
+ if (Pipeline::SupportedTarget()) {
+ Object* result = t.Call(1);
+ Object* true_obj = t.heap()->true_value();
+ CHECK_EQ(true_obj, result);
+ }
+
+ if (Pipeline::SupportedTarget()) {
+ Object* result = t.Call(0);
+ Object* false_obj = t.heap()->false_value();
+ CHECK_EQ(false_obj, result);
+ }
+}
+
+
+// TODO(titzer): enable all UI32 -> Tagged checking when inline allocation
+// works.
+#define TODO_UI32_TO_TAGGED_WILL_WORK(v)
Smi::IsValid(static_cast<double>(v))
+
+TEST(RunChangeInt32ToTagged) {
+ ChangesLoweringTester<Object*> t;
+ int32_t input;
+ t.BuildLoadAndLower(t.simplified()->ChangeInt32ToTagged(),
+ t.machine()->Load(kMachineWord32), &input);
+
+ if (Pipeline::SupportedTarget()) {
+ FOR_INT32_INPUTS(i) {
+ input = *i;
+ Object* result = t.CallWithPotentialGC<Object>();
+ if (TODO_UI32_TO_TAGGED_WILL_WORK(input)) {
+ t.CheckNumber(static_cast<double>(input), result);
+ }
+ }
+ }
+
+ if (Pipeline::SupportedTarget()) {
+ FOR_INT32_INPUTS(i) {
+ input = *i;
+ SimulateFullSpace(CcTest::heap()->new_space());
+ Object* result = t.CallWithPotentialGC<Object>();
+ if (TODO_UI32_TO_TAGGED_WILL_WORK(input)) {
+ t.CheckNumber(static_cast<double>(input), result);
+ }
+ }
+ }
+}
+
+
+TEST(RunChangeUint32ToTagged) {
+ ChangesLoweringTester<Object*> t;
+ uint32_t input;
+ t.BuildLoadAndLower(t.simplified()->ChangeUint32ToTagged(),
+ t.machine()->Load(kMachineWord32), &input);
+
+ if (Pipeline::SupportedTarget()) {
+ FOR_UINT32_INPUTS(i) {
+ input = *i;
+ Object* result = t.CallWithPotentialGC<Object>();
+ double expected = static_cast<double>(input);
+ if (TODO_UI32_TO_TAGGED_WILL_WORK(input)) {
+ t.CheckNumber(expected, result);
+ }
+ }
+ }
+
+ if (Pipeline::SupportedTarget()) {
+ FOR_UINT32_INPUTS(i) {
+ input = *i;
+ SimulateFullSpace(CcTest::heap()->new_space());
+ Object* result = t.CallWithPotentialGC<Object>();
+ double expected = static_cast<double>(static_cast<uint32_t>(input));
+ if (TODO_UI32_TO_TAGGED_WILL_WORK(input)) {
+ t.CheckNumber(expected, result);
+ }
+ }
+ }
+}
+
+
+// TODO(titzer): lowering of Float64->Tagged needs inline allocation.
+#define TODO_FLOAT64_TO_TAGGED false
+
+TEST(RunChangeFloat64ToTagged) {
+ ChangesLoweringTester<Object*> t;
+ double input;
+ t.BuildLoadAndLower(t.simplified()->ChangeFloat64ToTagged(),
+ t.machine()->Load(kMachineFloat64), &input);
+
+ // TODO(titzer): need inline allocation to change float to tagged.
+ if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) {
+ FOR_FLOAT64_INPUTS(i) {
+ input = *i;
+ Object* result = t.CallWithPotentialGC<Object>();
+ t.CheckNumber(input, result);
+ }
+ }
+
+ if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) {
+ FOR_FLOAT64_INPUTS(i) {
+ input = *i;
+ SimulateFullSpace(CcTest::heap()->new_space());
+ Object* result = t.CallWithPotentialGC<Object>();
+ t.CheckNumber(input, result);
+ }
+ }
+}
=======================================
--- /branches/bleeding_edge/src/compiler/simplified-lowering.cc Wed Jul 30
13:54:45 2014 UTC
+++ /branches/bleeding_edge/src/compiler/simplified-lowering.cc Fri Aug 1
08:16:19 2014 UTC
@@ -5,59 +5,190 @@
#include "src/compiler/simplified-lowering.h"
#include "src/compiler/graph-inl.h"
+#include "src/compiler/node-properties-inl.h"
#include "src/objects.h"
namespace v8 {
namespace internal {
namespace compiler {
-Node* SimplifiedLowering::DoChangeTaggedToInt32(Node* node, Node* effect,
- Node* control) {
- return node;
+Node* SimplifiedLowering::IsTagged(Node* node) {
+ // TODO(titzer): factor this out to a TaggingScheme abstraction.
+ STATIC_ASSERT(kSmiTagMask == 1); // Only works if tag is the low bit.
+ return graph()->NewNode(machine()->WordAnd(), node,
+ jsgraph()->Int32Constant(kSmiTagMask));
}
-Node* SimplifiedLowering::DoChangeTaggedToUint32(Node* node, Node* effect,
- Node* control) {
- return node;
+Node* SimplifiedLowering::Untag(Node* node) {
+ // TODO(titzer): factor this out to a TaggingScheme abstraction.
+ Node* shift_amount = jsgraph()->Int32Constant(kSmiTagSize +
kSmiShiftSize);
+ return graph()->NewNode(machine()->WordSar(), node, shift_amount);
}
-Node* SimplifiedLowering::DoChangeTaggedToFloat64(Node* node, Node* effect,
- Node* control) {
- return node;
+Node* SimplifiedLowering::SmiTag(Node* node) {
+ // TODO(titzer): factor this out to a TaggingScheme abstraction.
+ Node* shift_amount = jsgraph()->Int32Constant(kSmiTagSize +
kSmiShiftSize);
+ return graph()->NewNode(machine()->WordShl(), node, shift_amount);
}
-Node* SimplifiedLowering::DoChangeInt32ToTagged(Node* node, Node* effect,
- Node* control) {
- return node;
+Node* SimplifiedLowering::OffsetMinusTagConstant(int32_t offset) {
+ return jsgraph()->Int32Constant(offset - kHeapObjectTag);
}
-Node* SimplifiedLowering::DoChangeUint32ToTagged(Node* node, Node* effect,
+static void UpdateControlSuccessors(Node* before, Node* node) {
+ ASSERT(IrOpcode::IsControlOpcode(before->opcode()));
+ UseIter iter = before->uses().begin();
+ while (iter != before->uses().end()) {
+ if (IrOpcode::IsControlOpcode((*iter)->opcode()) &&
+ NodeProperties::IsControlEdge(iter.edge())) {
+ iter = iter.UpdateToAndIncrement(node);
+ continue;
+ }
+ ++iter;
+ }
+}
+
+
+void SimplifiedLowering::DoChangeTaggedToUI32(Node* node, Node* effect,
+ Node* control, bool
is_signed) {
+ // if (IsTagged(val))
+ // ConvertFloat64To(Int32|Uint32)(Load[kMachineFloat64](input,
#value_offset))
+ // else Untag(val)
+ Node* val = node->InputAt(0);
+ Node* branch = graph()->NewNode(common()->Branch(), IsTagged(val),
control);
+
+ // true branch.
+ Node* tbranch = graph()->NewNode(common()->IfTrue(), branch);
+ Node* loaded = graph()->NewNode(
+ machine()->Load(kMachineFloat64), val,
+ OffsetMinusTagConstant(HeapNumber::kValueOffset), effect);
+ Operator* op = is_signed ? machine()->ConvertFloat64ToInt32()
+ : machine()->ConvertFloat64ToUint32();
+ Node* converted = graph()->NewNode(op, loaded);
+
+ // false branch.
+ Node* fbranch = graph()->NewNode(common()->IfFalse(), branch);
+ Node* untagged = Untag(val);
+
+ // merge.
+ Node* merge = graph()->NewNode(common()->Merge(2), tbranch, fbranch);
+ Node* phi = graph()->NewNode(common()->Phi(2), converted, untagged,
merge);
+ UpdateControlSuccessors(control, merge);
+ branch->ReplaceInput(1, control);
+ node->ReplaceUses(phi);
+}
+
+
+void SimplifiedLowering::DoChangeTaggedToFloat64(Node* node, Node* effect,
Node* control) {
- return node;
+ // if (IsTagged(input)) Load[kMachineFloat64](input, #value_offset)
+ // else ConvertFloat64(Untag(input))
+ Node* val = node->InputAt(0);
+ Node* branch = graph()->NewNode(common()->Branch(), IsTagged(val),
control);
+
+ // true branch.
+ Node* tbranch = graph()->NewNode(common()->IfTrue(), branch);
+ Node* loaded = graph()->NewNode(
+ machine()->Load(kMachineFloat64), val,
+ OffsetMinusTagConstant(HeapNumber::kValueOffset), effect);
+
+ // false branch.
+ Node* fbranch = graph()->NewNode(common()->IfFalse(), branch);
+ Node* untagged = Untag(val);
+ Node* converted =
+ graph()->NewNode(machine()->ConvertInt32ToFloat64(), untagged);
+
+ // merge.
+ Node* merge = graph()->NewNode(common()->Merge(2), tbranch, fbranch);
+ Node* phi = graph()->NewNode(common()->Phi(2), loaded, converted, merge);
+ UpdateControlSuccessors(control, merge);
+ branch->ReplaceInput(1, control);
+ node->ReplaceUses(phi);
}
-Node* SimplifiedLowering::DoChangeFloat64ToTagged(Node* node, Node* effect,
- Node* control) {
- return node;
+void SimplifiedLowering::DoChangeUI32ToTagged(Node* node, Node* effect,
+ Node* control, bool
is_signed) {
+ Node* val = node->InputAt(0);
+ Node* is_smi = NULL;
+ if (is_signed) {
+ if (SmiValuesAre32Bits()) {
+ // All int32s fit in this case.
+ ASSERT(kPointerSize == 8);
+ return node->ReplaceUses(SmiTag(val));
+ } else {
+ // TODO(turbofan): use an Int32AddWithOverflow to tag and check here.
+ Node* lt = graph()->NewNode(machine()->Int32LessThanOrEqual(), val,
+
jsgraph()->Int32Constant(Smi::kMaxValue));
+ Node* gt =
+ graph()->NewNode(machine()->Int32LessThanOrEqual(),
+ jsgraph()->Int32Constant(Smi::kMinValue), val);
+ is_smi = graph()->NewNode(machine()->Word32And(), lt, gt);
+ }
+ } else {
+ // Check if Uint32 value is in the smi range.
+ is_smi = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val,
+ jsgraph()->Int32Constant(Smi::kMaxValue));
+ }
+
+ // TODO(turbofan): fold smi test branch eagerly.
+ // if (IsSmi(input)) SmiTag(input);
+ // else InlineAllocAndInitHeapNumber(ConvertToFloat64(input)))
+ Node* branch = graph()->NewNode(common()->Branch(), is_smi, control);
+
+ // true branch.
+ Node* tbranch = graph()->NewNode(common()->IfTrue(), branch);
+ Node* smi_tagged = SmiTag(val);
+
+ // false branch.
+ Node* fbranch = graph()->NewNode(common()->IfFalse(), branch);
+ Node* heap_num = jsgraph()->Constant(0.0); // TODO(titzer): alloc and
init
+
+ // merge.
+ Node* merge = graph()->NewNode(common()->Merge(2), tbranch, fbranch);
+ Node* phi = graph()->NewNode(common()->Phi(2), smi_tagged, heap_num,
merge);
+ UpdateControlSuccessors(control, merge);
+ branch->ReplaceInput(1, control);
+ node->ReplaceUses(phi);
+}
+
+
+void SimplifiedLowering::DoChangeFloat64ToTagged(Node* node, Node* effect,
+ Node* control) {
+ return; // TODO(titzer): need to call runtime to allocate in one branch
}
-Node* SimplifiedLowering::DoChangeBoolToBit(Node* node, Node* effect,
- Node* control) {
+void SimplifiedLowering::DoChangeBoolToBit(Node* node, Node* effect,
+ Node* control) {
Node* val = node->InputAt(0);
- Operator* op = machine()->WordEqual();
- return graph()->NewNode(op, val, jsgraph()->TrueConstant());
+ Operator* op =
+ kPointerSize == 8 ? machine()->Word64Equal() :
machine()->Word32Equal();
+ Node* cmp = graph()->NewNode(op, val, jsgraph()->TrueConstant());
+ node->ReplaceUses(cmp);
}
+
+void SimplifiedLowering::DoChangeBitToBool(Node* node, Node* effect,
+ Node* control) {
+ Node* val = node->InputAt(0);
+ Node* branch = graph()->NewNode(common()->Branch(), val, control);
-Node* SimplifiedLowering::DoChangeBitToBool(Node* node, Node* effect,
- Node* control) {
- return node;
+ // true branch.
+ Node* tbranch = graph()->NewNode(common()->IfTrue(), branch);
+ // false branch.
+ Node* fbranch = graph()->NewNode(common()->IfFalse(), branch);
+ // merge.
+ Node* merge = graph()->NewNode(common()->Merge(2), tbranch, fbranch);
+ Node* phi = graph()->NewNode(common()->Phi(2), jsgraph()->TrueConstant(),
+ jsgraph()->FalseConstant(), merge);
+ UpdateControlSuccessors(control, merge);
+ branch->ReplaceInput(1, control);
+ node->ReplaceUses(phi);
}
@@ -71,18 +202,16 @@
}
-Node* SimplifiedLowering::DoLoadField(Node* node, Node* effect, Node*
control) {
+void SimplifiedLowering::DoLoadField(Node* node, Node* effect, Node*
control) {
const FieldAccess& access = FieldAccessOf(node->op());
node->set_op(machine_.Load(access.representation));
Node* offset =
graph()->NewNode(common()->Int32Constant(access.offset -
kHeapObjectTag));
node->InsertInput(zone(), 1, offset);
- return node;
}
-Node* SimplifiedLowering::DoStoreField(Node* node, Node* effect,
- Node* control) {
+void SimplifiedLowering::DoStoreField(Node* node, Node* effect, Node*
control) {
const FieldAccess& access = FieldAccessOf(node->op());
WriteBarrierKind kind =
ComputeWriteBarrierKind(access.representation, access.type);
@@ -90,7 +219,6 @@
Node* offset =
graph()->NewNode(common()->Int32Constant(access.offset -
kHeapObjectTag));
node->InsertInput(zone(), 1, offset);
- return node;
}
@@ -131,23 +259,21 @@
}
-Node* SimplifiedLowering::DoLoadElement(Node* node, Node* effect,
- Node* control) {
+void SimplifiedLowering::DoLoadElement(Node* node, Node* effect,
+ Node* control) {
const ElementAccess& access = ElementAccessOf(node->op());
node->set_op(machine_.Load(access.representation));
node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1)));
- return node;
}
-Node* SimplifiedLowering::DoStoreElement(Node* node, Node* effect,
- Node* control) {
+void SimplifiedLowering::DoStoreElement(Node* node, Node* effect,
+ Node* control) {
const ElementAccess& access = ElementAccessOf(node->op());
WriteBarrierKind kind =
ComputeWriteBarrierKind(access.representation, access.type);
node->set_op(machine_.Store(access.representation, kind));
node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1)));
- return node;
}
@@ -172,25 +298,25 @@
case IrOpcode::kStringAdd:
break;
case IrOpcode::kChangeTaggedToInt32:
- DoChangeTaggedToInt32(node, start, start);
+ DoChangeTaggedToUI32(node, start, start, true);
break;
case IrOpcode::kChangeTaggedToUint32:
- DoChangeTaggedToUint32(node, start, start);
+ DoChangeTaggedToUI32(node, start, start, false);
break;
case IrOpcode::kChangeTaggedToFloat64:
DoChangeTaggedToFloat64(node, start, start);
break;
case IrOpcode::kChangeInt32ToTagged:
- DoChangeInt32ToTagged(node, start, start);
+ DoChangeUI32ToTagged(node, start, start, true);
break;
case IrOpcode::kChangeUint32ToTagged:
- DoChangeUint32ToTagged(node, start, start);
+ DoChangeUI32ToTagged(node, start, start, false);
break;
case IrOpcode::kChangeFloat64ToTagged:
DoChangeFloat64ToTagged(node, start, start);
break;
case IrOpcode::kChangeBoolToBit:
- node->ReplaceUses(DoChangeBoolToBit(node, start, start));
+ DoChangeBoolToBit(node, start, start);
break;
case IrOpcode::kChangeBitToBool:
DoChangeBitToBool(node, start, start);
=======================================
--- /branches/bleeding_edge/src/compiler/simplified-lowering.h Wed Jul 30
13:54:45 2014 UTC
+++ /branches/bleeding_edge/src/compiler/simplified-lowering.h Fri Aug 1
08:16:19 2014 UTC
@@ -27,22 +27,28 @@
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);
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.gyp Wed Jul 30 13:54:45 2014
UTC
+++ /branches/bleeding_edge/test/cctest/cctest.gyp Fri Aug 1 08:16:19 2014
UTC
@@ -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',
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/graph-builder-tester.h Wed
Jul 30 13:54:45 2014 UTC
+++ /branches/bleeding_edge/test/cctest/compiler/graph-builder-tester.h Fri
Aug 1 08:16:19 2014 UTC
@@ -84,11 +84,11 @@
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(),
=======================================
---
/branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc
Wed Jul 30 13:54:45 2014 UTC
+++
/branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc
Fri Aug 1 08:16:19 2014 UTC
@@ -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 @@
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 {
@@ -74,313 +80,6 @@
Factory* factory() { return this->isolate()->factory(); }
Heap* heap() { return this->isolate()->heap(); }
};
-
-
-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.
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.