Commit 936d7218 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Support lowering of ChangeFloat64ToTagged/ChangeTaggedToInt32.

Adds new ValueEffect operator to ensure proper scheduling of
AllocateHeapNumber call nodes.

Also includes some refactoring to reduce code duplication.

TEST=compiler-unittests
R=jarin@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23175 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 37ce51e0
......@@ -15,16 +15,19 @@ ChangeLowering::~ChangeLowering() {}
Reduction ChangeLowering::Reduce(Node* node) {
Node* control = graph()->start();
Node* effect = control;
switch (node->opcode()) {
case IrOpcode::kChangeBitToBool:
return ChangeBitToBool(node->InputAt(0), control);
case IrOpcode::kChangeBoolToBit:
return ChangeBoolToBit(node->InputAt(0));
case IrOpcode::kChangeFloat64ToTagged:
return ChangeFloat64ToTagged(node->InputAt(0), control);
case IrOpcode::kChangeInt32ToTagged:
return ChangeInt32ToTagged(node->InputAt(0), effect, control);
return ChangeInt32ToTagged(node->InputAt(0), control);
case IrOpcode::kChangeTaggedToFloat64:
return ChangeTaggedToFloat64(node->InputAt(0), effect, control);
return ChangeTaggedToFloat64(node->InputAt(0), control);
case IrOpcode::kChangeTaggedToInt32:
return ChangeTaggedToInt32(node->InputAt(0), control);
default:
return NoChange();
}
......@@ -77,49 +80,67 @@ Reduction ChangeLowering::ChangeBoolToBit(Node* val) {
}
Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* effect,
Node* control) {
Reduction ChangeLowering::ChangeFloat64ToTagged(Node* val, Node* control) {
return Replace(AllocateHeapNumberWithValue(val, control));
}
Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) {
if (machine()->is64()) {
return Replace(
graph()->NewNode(machine()->WordShl(), val, SmiShiftBitsConstant()));
}
Node* context = jsgraph()->SmiConstant(0);
Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val);
Node* ovf = graph()->NewNode(common()->Projection(1), add);
Node* branch = graph()->NewNode(common()->Branch(), ovf, control);
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), val);
const Runtime::Function* fn =
Runtime::FunctionForId(Runtime::kAllocateHeapNumber);
DCHECK_EQ(0, fn->nargs);
CallDescriptor* desc = linkage()->GetRuntimeCallDescriptor(
fn->function_id, 0, Operator::kNoProperties);
Node* heap_number = graph()->NewNode(
common()->Call(desc), jsgraph()->CEntryStubConstant(),
jsgraph()->ExternalConstant(ExternalReference(fn, isolate())),
jsgraph()->Int32Constant(fn->nargs), context, effect, if_true);
Node* store = graph()->NewNode(
machine()->Store(kMachFloat64, kNoWriteBarrier), heap_number,
HeapNumberValueIndexConstant(), number, heap_number, if_true);
Node* finish = graph()->NewNode(common()->Finish(1), heap_number, store);
Node* heap_number = AllocateHeapNumberWithValue(
graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), if_true);
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
Node* smi = graph()->NewNode(common()->Projection(0), add);
Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
Node* phi = graph()->NewNode(common()->Phi(2), finish, smi, merge);
Node* phi = graph()->NewNode(common()->Phi(2), heap_number, smi, merge);
return Replace(phi);
}
Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* effect,
Node* control) {
Reduction ChangeLowering::ChangeTaggedToInt32(Node* val, Node* control) {
STATIC_ASSERT(kSmiTag == 0);
STATIC_ASSERT(kSmiTagMask == 1);
Node* tag = graph()->NewNode(machine()->WordAnd(), val,
jsgraph()->Int32Constant(kSmiTagMask));
Node* branch = graph()->NewNode(common()->Branch(), tag, control);
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
Node* load = graph()->NewNode(
machine()->Load(kMachFloat64), val, HeapNumberValueIndexConstant(),
graph()->NewNode(common()->ControlEffect(), if_true));
Node* change = graph()->NewNode(machine()->ChangeFloat64ToInt32(), load);
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
Node* integer =
graph()->NewNode(machine()->WordSar(), val, SmiShiftBitsConstant());
Node* number =
machine()->is64()
? graph()->NewNode(machine()->ConvertInt64ToInt32(), integer)
: integer;
Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
Node* phi = graph()->NewNode(common()->Phi(2), change, number, merge);
return Replace(phi);
}
Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) {
STATIC_ASSERT(kSmiTag == 0);
STATIC_ASSERT(kSmiTagMask == 1);
Node* tag = graph()->NewNode(machine()->WordAnd(), val,
......@@ -157,6 +178,27 @@ CommonOperatorBuilder* ChangeLowering::common() const {
return jsgraph()->common();
}
Node* ChangeLowering::AllocateHeapNumberWithValue(Node* value, Node* control) {
// The AllocateHeapNumber() runtime function does not use the context, so we
// can safely pass in Smi zero here.
Node* context = jsgraph()->ZeroConstant();
Node* effect = graph()->NewNode(common()->ValueEffect(1), value);
const Runtime::Function* function =
Runtime::FunctionForId(Runtime::kAllocateHeapNumber);
DCHECK_EQ(0, function->nargs);
CallDescriptor* desc = linkage()->GetRuntimeCallDescriptor(
function->function_id, 0, Operator::kNoProperties);
Node* heap_number = graph()->NewNode(
common()->Call(desc), jsgraph()->CEntryStubConstant(),
jsgraph()->ExternalConstant(ExternalReference(function, isolate())),
jsgraph()->Int32Constant(function->nargs), context, effect, control);
Node* store = graph()->NewNode(
machine()->Store(kMachFloat64, kNoWriteBarrier), heap_number,
HeapNumberValueIndexConstant(), value, heap_number, control);
return graph()->NewNode(common()->Finish(1), heap_number, store);
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -32,8 +32,10 @@ class ChangeLowering V8_FINAL : public Reducer {
Reduction ChangeBitToBool(Node* val, Node* control);
Reduction ChangeBoolToBit(Node* val);
Reduction ChangeInt32ToTagged(Node* val, Node* effect, Node* control);
Reduction ChangeTaggedToFloat64(Node* val, Node* effect, Node* control);
Reduction ChangeFloat64ToTagged(Node* val, Node* control);
Reduction ChangeInt32ToTagged(Node* val, Node* control);
Reduction ChangeTaggedToFloat64(Node* val, Node* control);
Reduction ChangeTaggedToInt32(Node* val, Node* control);
Graph* graph() const;
Isolate* isolate() const;
......@@ -43,6 +45,8 @@ class ChangeLowering V8_FINAL : public Reducer {
MachineOperatorBuilder* machine() const { return machine_; }
private:
Node* AllocateHeapNumberWithValue(Node* value, Node* control);
JSGraph* jsgraph_;
Linkage* linkage_;
MachineOperatorBuilder* machine_;
......
......@@ -134,6 +134,11 @@ class CommonOperatorBuilder {
return new (zone_) SimpleOperator(IrOpcode::kControlEffect, Operator::kPure,
0, 0, "ControlEffect");
}
Operator* ValueEffect(int arguments) {
DCHECK(arguments > 0); // Disallow empty value effects.
return new (zone_) SimpleOperator(IrOpcode::kValueEffect, Operator::kPure,
arguments, 0, "ValueEffect");
}
Operator* Finish(int arguments) {
DCHECK(arguments > 0); // Disallow empty finishes.
return new (zone_) Operator1<int>(IrOpcode::kFinish, Operator::kPure, 1, 1,
......
......@@ -34,6 +34,7 @@
V(Phi) \
V(EffectPhi) \
V(ControlEffect) \
V(ValueEffect) \
V(Finish) \
V(FrameState) \
V(StateValues) \
......
......@@ -91,6 +91,7 @@ inline bool OperatorProperties::HasValueOutput(Operator* op) {
inline bool OperatorProperties::HasEffectOutput(Operator* op) {
return op->opcode() == IrOpcode::kStart ||
op->opcode() == IrOpcode::kControlEffect ||
op->opcode() == IrOpcode::kValueEffect ||
(op->opcode() != IrOpcode::kFinish && GetEffectInputCount(op) > 0);
}
......
......@@ -272,6 +272,11 @@ Bounds Typer::Visitor::TypeControlEffect(Node* node) {
}
Bounds Typer::Visitor::TypeValueEffect(Node* node) {
return Bounds(Type::None(zone()));
}
Bounds Typer::Visitor::TypeFinish(Node* node) { return OperandType(node, 0); }
......
......@@ -10,6 +10,9 @@ namespace v8 {
namespace internal {
namespace compiler {
static const int kArguments[] = {1, 5, 6, 42, 100, 10000, kMaxInt};
CommonOperatorTest::CommonOperatorTest() : common_(zone()) {}
......@@ -26,8 +29,19 @@ TEST_F(CommonOperatorTest, ControlEffect) {
}
TEST_F(CommonOperatorTest, ValueEffect) {
TRACED_FOREACH(int, arguments, kArguments) {
Operator* op = common()->ValueEffect(arguments);
EXPECT_EQ(arguments, OperatorProperties::GetValueInputCount(op));
EXPECT_EQ(arguments, OperatorProperties::GetTotalInputCount(op));
EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op));
EXPECT_EQ(1, OperatorProperties::GetEffectOutputCount(op));
EXPECT_EQ(0, OperatorProperties::GetValueOutputCount(op));
}
}
TEST_F(CommonOperatorTest, Finish) {
static const int kArguments[] = {1, 5, 6, 42, 100, 10000, kMaxInt};
TRACED_FOREACH(int, arguments, kArguments) {
Operator* op = common()->Finish(arguments);
EXPECT_EQ(1, OperatorProperties::GetValueInputCount(op));
......
......@@ -33,6 +33,16 @@ namespace compiler {
#endif
// The TARGET_TEST_P(Case, Name) macro works just like
// TEST_P(Case, Name), except that the test is disabled
// if the platform is not a supported TurboFan target.
#if V8_TURBOFAN_TARGET
#define TARGET_TEST_P(Case, Name) TEST_P(Case, Name)
#else
#define TARGET_TEST_P(Case, Name) TEST_P(Case, DISABLED_##Name)
#endif
// The TARGET_TYPED_TEST(Case, Name) macro works just like
// TYPED_TEST(Case, Name), except that the test is disabled
// if the platform is not a supported TurboFan target.
......
......@@ -8,6 +8,7 @@
#include "src/compiler/node-properties-inl.h"
using testing::_;
using testing::MakeMatcher;
using testing::MatcherInterface;
using testing::MatchResultListener;
......@@ -567,6 +568,11 @@ Matcher<Node*> IsControlEffect(const Matcher<Node*>& control_matcher) {
}
Matcher<Node*> IsValueEffect(const Matcher<Node*>& value_matcher) {
return MakeMatcher(new IsUnopMatcher(IrOpcode::kValueEffect, value_matcher));
}
Matcher<Node*> IsFinish(const Matcher<Node*>& value_matcher,
const Matcher<Node*>& effect_matcher) {
return MakeMatcher(new IsFinishMatcher(value_matcher, effect_matcher));
......@@ -671,6 +677,7 @@ IS_BINOP_MATCHER(Int32AddWithOverflow)
return MakeMatcher(new IsUnopMatcher(IrOpcode::k##Name, input_matcher)); \
}
IS_UNOP_MATCHER(ConvertInt64ToInt32)
IS_UNOP_MATCHER(ChangeFloat64ToInt32)
IS_UNOP_MATCHER(ChangeInt32ToFloat64)
#undef IS_UNOP_MATCHER
......
......@@ -35,6 +35,7 @@ class GraphTest : public CommonOperatorTest {
using ::testing::Matcher;
Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher,
const Matcher<Node*>& control_matcher);
Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
......@@ -42,6 +43,7 @@ Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
Matcher<Node*> IsIfTrue(const Matcher<Node*>& control_matcher);
Matcher<Node*> IsIfFalse(const Matcher<Node*>& control_matcher);
Matcher<Node*> IsControlEffect(const Matcher<Node*>& control_matcher);
Matcher<Node*> IsValueEffect(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsFinish(const Matcher<Node*>& value_matcher,
const Matcher<Node*>& effect_matcher);
Matcher<Node*> IsExternalConstant(
......@@ -93,6 +95,7 @@ Matcher<Node*> IsWord64Equal(const Matcher<Node*>& lhs_matcher,
Matcher<Node*> IsInt32AddWithOverflow(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsConvertInt64ToInt32(const Matcher<Node*>& input_matcher);
Matcher<Node*> IsChangeFloat64ToInt32(const Matcher<Node*>& input_matcher);
Matcher<Node*> IsChangeInt32ToFloat64(const Matcher<Node*>& input_matcher);
} // namespace compiler
......
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