Commit 5bf4c830 authored by titzer@chromium.org's avatar titzer@chromium.org

Remove old changes lowering code and convert test to use new changes lowering code.

R=bmeurer@chromium.org
BUG=

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23449 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ef565ef9
......@@ -726,10 +726,6 @@ void SimplifiedLowering::LowerAllNodes() {
graph()->zone()->isolate());
RepresentationSelector selector(jsgraph(), zone(), &changer);
selector.Run(this);
GraphReducer graph_reducer(graph());
graph_reducer.AddReducer(this);
graph_reducer.ReduceGraph();
}
......@@ -752,157 +748,6 @@ Node* SimplifiedLowering::OffsetMinusTagConstant(int32_t offset) {
}
static void UpdateControlSuccessors(Node* before, Node* node) {
DCHECK(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[kMachFloat64](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(kMachFloat64), val,
OffsetMinusTagConstant(HeapNumber::kValueOffset), effect);
Operator* op = is_signed ? machine()->ChangeFloat64ToInt32()
: machine()->ChangeFloat64ToUint32();
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) {
// if (IsTagged(input)) Load[kMachFloat64](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(kMachFloat64), val,
OffsetMinusTagConstant(HeapNumber::kValueOffset), effect);
// false branch.
Node* fbranch = graph()->NewNode(common()->IfFalse(), branch);
Node* untagged = Untag(val);
Node* converted =
graph()->NewNode(machine()->ChangeInt32ToFloat64(), 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);
}
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.
DCHECK(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
}
void SimplifiedLowering::DoChangeBoolToBit(Node* node, Node* effect,
Node* control) {
Node* cmp = graph()->NewNode(machine()->WordEqual(), node->InputAt(0),
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);
// 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);
}
static WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged,
MachineType representation,
Type* type) {
......@@ -964,41 +809,6 @@ void SimplifiedLowering::DoStoreElement(Node* node) {
}
Reduction SimplifiedLowering::Reduce(Node* node) { return NoChange(); }
void SimplifiedLowering::LowerChange(Node* node, Node* effect, Node* control) {
switch (node->opcode()) {
case IrOpcode::kChangeTaggedToInt32:
DoChangeTaggedToUI32(node, effect, control, true);
break;
case IrOpcode::kChangeTaggedToUint32:
DoChangeTaggedToUI32(node, effect, control, false);
break;
case IrOpcode::kChangeTaggedToFloat64:
DoChangeTaggedToFloat64(node, effect, control);
break;
case IrOpcode::kChangeInt32ToTagged:
DoChangeUI32ToTagged(node, effect, control, true);
break;
case IrOpcode::kChangeUint32ToTagged:
DoChangeUI32ToTagged(node, effect, control, false);
break;
case IrOpcode::kChangeFloat64ToTagged:
DoChangeFloat64ToTagged(node, effect, control);
break;
case IrOpcode::kChangeBoolToBit:
DoChangeBoolToBit(node, effect, control);
break;
case IrOpcode::kChangeBitToBool:
DoChangeBitToBool(node, effect, control);
break;
default:
UNREACHABLE();
break;
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -5,7 +5,6 @@
#ifndef V8_COMPILER_SIMPLIFIED_LOWERING_H_
#define V8_COMPILER_SIMPLIFIED_LOWERING_H_
#include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node.h"
......@@ -15,7 +14,7 @@ namespace v8 {
namespace internal {
namespace compiler {
class SimplifiedLowering : public Reducer {
class SimplifiedLowering {
public:
explicit SimplifiedLowering(JSGraph* jsgraph)
: jsgraph_(jsgraph), machine_(jsgraph->zone()) {}
......@@ -23,9 +22,6 @@ class SimplifiedLowering : public Reducer {
void LowerAllNodes();
virtual Reduction Reduce(Node* node);
void LowerChange(Node* node, Node* effect, Node* control);
// TODO(titzer): These are exposed for direct testing. Use a friend class.
void DoLoadField(Node* node);
void DoStoreField(Node* node);
......@@ -42,15 +38,6 @@ class SimplifiedLowering : public Reducer {
Node* OffsetMinusTagConstant(int32_t offset);
Node* ComputeIndex(const ElementAccess& access, Node* index);
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);
friend class RepresentationSelector;
Zone* zone() { return jsgraph_->zone(); }
......
......@@ -4,11 +4,12 @@
#include <limits>
#include "src/compiler/change-lowering.h"
#include "src/compiler/control-builders.h"
#include "src/compiler/generic-node-inl.h"
#include "src/compiler/js-graph.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"
......@@ -31,12 +32,10 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
: GraphBuilderTester<ReturnType>(p0),
typer(this->zone()),
jsgraph(this->graph(), this->common(), &typer),
lowering(&jsgraph),
function(Handle<JSFunction>::null()) {}
Typer typer;
JSGraph jsgraph;
SimplifiedLowering lowering;
Handle<JSFunction> function;
Node* start() { return this->graph()->start(); }
......@@ -109,8 +108,7 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
this->start(), this->start());
Node* end = this->graph()->NewNode(this->common()->End(), ret);
this->graph()->SetEnd(end);
this->lowering.LowerChange(change, this->start(), this->start());
Verifier::Run(this->graph());
LowerChange(change);
}
void BuildStoreAndLower(Operator* op, Operator* store_op, void* location) {
......@@ -125,8 +123,7 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
this->common()->Return(), this->Int32Constant(0), store, this->start());
Node* end = this->graph()->NewNode(this->common()->End(), ret);
this->graph()->SetEnd(end);
this->lowering.LowerChange(change, this->start(), this->start());
Verifier::Run(this->graph());
LowerChange(change);
}
void BuildLoadAndLower(Operator* op, Operator* load_op, void* location) {
......@@ -140,7 +137,17 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
this->start(), this->start());
Node* end = this->graph()->NewNode(this->common()->End(), ret);
this->graph()->SetEnd(end);
this->lowering.LowerChange(change, this->start(), this->start());
LowerChange(change);
}
void LowerChange(Node* change) {
// Run the graph reducer with changes lowering on a single node.
CompilationInfo info(this->isolate(), this->zone());
Linkage linkage(&info);
ChangeLowering lowering(&jsgraph, &linkage, this->machine());
GraphReducer reducer(this->graph());
reducer.AddReducer(&lowering);
reducer.ReduceNode(change);
Verifier::Run(this->graph());
}
......@@ -295,20 +302,6 @@ TEST(RunChangeBitToBool) {
}
bool TODO_INT32_TO_TAGGED_WILL_WORK(int32_t v) {
// TODO(titzer): enable all UI32 -> Tagged checking when inline allocation
// works.
return Smi::IsValid(v);
}
bool TODO_UINT32_TO_TAGGED_WILL_WORK(uint32_t v) {
// TODO(titzer): enable all UI32 -> Tagged checking when inline allocation
// works.
return v <= static_cast<uint32_t>(Smi::kMaxValue);
}
TEST(RunChangeInt32ToTagged) {
ChangesLoweringTester<Object*> t;
int32_t input;
......@@ -319,20 +312,16 @@ TEST(RunChangeInt32ToTagged) {
FOR_INT32_INPUTS(i) {
input = *i;
Object* result = t.CallWithPotentialGC<Object>();
if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) {
t.CheckNumber(static_cast<double>(input), result);
}
t.CheckNumber(static_cast<double>(input), result);
}
}
if (Pipeline::SupportedTarget()) {
FOR_INT32_INPUTS(i) {
input = *i;
SimulateFullSpace(CcTest::heap()->new_space());
CcTest::heap()->DisableInlineAllocation();
Object* result = t.CallWithPotentialGC<Object>();
if (TODO_INT32_TO_TAGGED_WILL_WORK(input)) {
t.CheckNumber(static_cast<double>(input), result);
}
t.CheckNumber(static_cast<double>(input), result);
}
}
}
......@@ -349,37 +338,29 @@ TEST(RunChangeUint32ToTagged) {
input = *i;
Object* result = t.CallWithPotentialGC<Object>();
double expected = static_cast<double>(input);
if (TODO_UINT32_TO_TAGGED_WILL_WORK(input)) {
t.CheckNumber(expected, result);
}
t.CheckNumber(expected, result);
}
}
if (Pipeline::SupportedTarget()) {
FOR_UINT32_INPUTS(i) {
input = *i;
SimulateFullSpace(CcTest::heap()->new_space());
CcTest::heap()->DisableInlineAllocation();
Object* result = t.CallWithPotentialGC<Object>();
double expected = static_cast<double>(static_cast<uint32_t>(input));
if (TODO_UINT32_TO_TAGGED_WILL_WORK(input)) {
t.CheckNumber(expected, result);
}
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(kMachFloat64), &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>();
......@@ -387,10 +368,10 @@ TEST(RunChangeFloat64ToTagged) {
}
}
if (TODO_FLOAT64_TO_TAGGED && Pipeline::SupportedTarget()) {
{
FOR_FLOAT64_INPUTS(i) {
input = *i;
SimulateFullSpace(CcTest::heap()->new_space());
CcTest::heap()->DisableInlineAllocation();
Object* result = t.CallWithPotentialGC<Object>();
t.CheckNumber(input, result);
}
......
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