Commit 73b4af7a authored by Benedikt Meurer's avatar Benedikt Meurer

[turbofan] Narrow upper bounds during typed lowering.

This is a temporary solution, which optionally narrows upper bounds of
nodes when changing the operator of a node.

R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25658}
parent b98a3711
...@@ -114,7 +114,8 @@ class JSBinopReduction { ...@@ -114,7 +114,8 @@ class JSBinopReduction {
// Remove all effect and control inputs and outputs to this node and change // Remove all effect and control inputs and outputs to this node and change
// to the pure operator {op}, possibly inserting a boolean inversion. // to the pure operator {op}, possibly inserting a boolean inversion.
Reduction ChangeToPureOperator(const Operator* op, bool invert = false) { Reduction ChangeToPureOperator(const Operator* op, bool invert = false,
Type* type = Type::Any()) {
DCHECK_EQ(0, op->EffectInputCount()); DCHECK_EQ(0, op->EffectInputCount());
DCHECK_EQ(false, OperatorProperties::HasContextInput(op)); DCHECK_EQ(false, OperatorProperties::HasContextInput(op));
DCHECK_EQ(0, op->ControlInputCount()); DCHECK_EQ(0, op->ControlInputCount());
...@@ -129,6 +130,11 @@ class JSBinopReduction { ...@@ -129,6 +130,11 @@ class JSBinopReduction {
// Finally, update the operator to the new one. // Finally, update the operator to the new one.
node_->set_op(op); node_->set_op(op);
// TODO(jarin): Replace the explicit typing hack with a call to some method
// that encapsulates changing the operator and re-typing.
Bounds const bounds = NodeProperties::GetBounds(node_);
NodeProperties::SetBounds(node_, Bounds::NarrowUpper(bounds, type, zone()));
if (invert) { if (invert) {
// Insert an boolean not to invert the value. // Insert an boolean not to invert the value.
Node* value = graph()->NewNode(simplified()->BooleanNot(), node_); Node* value = graph()->NewNode(simplified()->BooleanNot(), node_);
...@@ -140,6 +146,10 @@ class JSBinopReduction { ...@@ -140,6 +146,10 @@ class JSBinopReduction {
return lowering_->Changed(node_); return lowering_->Changed(node_);
} }
Reduction ChangeToPureOperator(const Operator* op, Type* type) {
return ChangeToPureOperator(op, false, type);
}
bool OneInputIs(Type* t) { return left_type_->Is(t) || right_type_->Is(t); } bool OneInputIs(Type* t) { return left_type_->Is(t) || right_type_->Is(t); }
bool BothInputsAre(Type* t) { bool BothInputsAre(Type* t) {
...@@ -163,10 +173,11 @@ class JSBinopReduction { ...@@ -163,10 +173,11 @@ class JSBinopReduction {
Type* right_type() { return right_type_; } Type* right_type() { return right_type_; }
SimplifiedOperatorBuilder* simplified() { return lowering_->simplified(); } SimplifiedOperatorBuilder* simplified() { return lowering_->simplified(); }
Graph* graph() { return lowering_->graph(); } Graph* graph() const { return lowering_->graph(); }
JSGraph* jsgraph() { return lowering_->jsgraph(); } JSGraph* jsgraph() { return lowering_->jsgraph(); }
JSOperatorBuilder* javascript() { return lowering_->javascript(); } JSOperatorBuilder* javascript() { return lowering_->javascript(); }
MachineOperatorBuilder* machine() { return lowering_->machine(); } MachineOperatorBuilder* machine() { return lowering_->machine(); }
Zone* zone() const { return graph()->zone(); }
private: private:
JSTypedLowering* lowering_; // The containing lowering instance. JSTypedLowering* lowering_; // The containing lowering instance.
...@@ -218,13 +229,13 @@ Reduction JSTypedLowering::ReduceJSAdd(Node* node) { ...@@ -218,13 +229,13 @@ Reduction JSTypedLowering::ReduceJSAdd(Node* node) {
JSBinopReduction r(this, node); JSBinopReduction r(this, node);
if (r.BothInputsAre(Type::Number())) { if (r.BothInputsAre(Type::Number())) {
// JSAdd(x:number, y:number) => NumberAdd(x, y) // JSAdd(x:number, y:number) => NumberAdd(x, y)
return r.ChangeToPureOperator(simplified()->NumberAdd()); return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number());
} }
Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone()); Type* maybe_string = Type::Union(Type::String(), Type::Receiver(), zone());
if (r.BothInputsAre(Type::Primitive()) && r.NeitherInputCanBe(maybe_string)) { if (r.BothInputsAre(Type::Primitive()) && r.NeitherInputCanBe(maybe_string)) {
// JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y))
r.ConvertInputsToNumber(); r.ConvertInputsToNumber();
return r.ChangeToPureOperator(simplified()->NumberAdd()); return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number());
} }
#if 0 #if 0
// TODO(turbofan): General ToNumber disabled for now because: // TODO(turbofan): General ToNumber disabled for now because:
...@@ -263,7 +274,7 @@ Reduction JSTypedLowering::ReduceJSBitwiseOr(Node* node) { ...@@ -263,7 +274,7 @@ Reduction JSTypedLowering::ReduceJSBitwiseOr(Node* node) {
// on some platforms. // on some platforms.
// TODO(turbofan): make this heuristic configurable for code size. // TODO(turbofan): make this heuristic configurable for code size.
r.ConvertInputsToInt32(true, true); r.ConvertInputsToInt32(true, true);
return r.ChangeToPureOperator(machine()->Word32Or()); return r.ChangeToPureOperator(machine()->Word32Or(), Type::Integral32());
} }
return NoChange(); return NoChange();
} }
...@@ -275,7 +286,8 @@ Reduction JSTypedLowering::ReduceJSMultiply(Node* node) { ...@@ -275,7 +286,8 @@ Reduction JSTypedLowering::ReduceJSMultiply(Node* node) {
// TODO(jarin): Propagate frame state input from non-primitive input node to // TODO(jarin): Propagate frame state input from non-primitive input node to
// JSToNumber node. // JSToNumber node.
r.ConvertInputsToNumber(); r.ConvertInputsToNumber();
return r.ChangeToPureOperator(simplified()->NumberMultiply()); return r.ChangeToPureOperator(simplified()->NumberMultiply(),
Type::Number());
} }
// TODO(turbofan): relax/remove the effects of this operator in other cases. // TODO(turbofan): relax/remove the effects of this operator in other cases.
return NoChange(); return NoChange();
...@@ -287,7 +299,7 @@ Reduction JSTypedLowering::ReduceNumberBinop(Node* node, ...@@ -287,7 +299,7 @@ Reduction JSTypedLowering::ReduceNumberBinop(Node* node,
JSBinopReduction r(this, node); JSBinopReduction r(this, node);
if (r.BothInputsAre(Type::Primitive())) { if (r.BothInputsAre(Type::Primitive())) {
r.ConvertInputsToNumber(); r.ConvertInputsToNumber();
return r.ChangeToPureOperator(numberOp); return r.ChangeToPureOperator(numberOp, Type::Number());
} }
#if 0 #if 0
// TODO(turbofan): General ToNumber disabled for now because: // TODO(turbofan): General ToNumber disabled for now because:
...@@ -317,7 +329,7 @@ Reduction JSTypedLowering::ReduceI32Binop(Node* node, bool left_signed, ...@@ -317,7 +329,7 @@ Reduction JSTypedLowering::ReduceI32Binop(Node* node, bool left_signed,
// on some platforms. // on some platforms.
// TODO(turbofan): make this heuristic configurable for code size. // TODO(turbofan): make this heuristic configurable for code size.
r.ConvertInputsToInt32(left_signed, right_signed); r.ConvertInputsToInt32(left_signed, right_signed);
return r.ChangeToPureOperator(intOp); return r.ChangeToPureOperator(intOp, Type::Integral32());
} }
return NoChange(); return NoChange();
} }
...@@ -328,7 +340,7 @@ Reduction JSTypedLowering::ReduceI32Shift(Node* node, bool left_signed, ...@@ -328,7 +340,7 @@ Reduction JSTypedLowering::ReduceI32Shift(Node* node, bool left_signed,
JSBinopReduction r(this, node); JSBinopReduction r(this, node);
if (r.BothInputsAre(Type::Primitive())) { if (r.BothInputsAre(Type::Primitive())) {
r.ConvertInputsForShift(left_signed); r.ConvertInputsForShift(left_signed);
return r.ChangeToPureOperator(shift_op); return r.ChangeToPureOperator(shift_op, Type::Integral32());
} }
return NoChange(); return NoChange();
} }
......
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