[turbofan] The AstGraphBuilder does not need to care about types.

AstGraphBuilder::BuildToBoolean() can be optimized easily without types,
especially since the types are only present on some nodes during graph
building. So this optimization is both more efficient and more effective
at the same time. We will probably refactor this code into a separate
optimization method/class later.

R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#29062}
This commit is contained in:
bmeurer 2015-06-16 22:43:17 -07:00 committed by Commit bot
parent 3161cb550c
commit f1db38cae0

View File

@ -3582,26 +3582,32 @@ Node* AstGraphBuilder::BuildStoreExternal(ExternalReference reference,
Node* AstGraphBuilder::BuildToBoolean(Node* input) {
// TODO(titzer): This should be in a JSOperatorReducer.
// TODO(bmeurer, mstarzinger): Refactor this into a separate optimization
// method.
switch (input->opcode()) {
case IrOpcode::kInt32Constant:
return jsgraph_->BooleanConstant(!Int32Matcher(input).Is(0));
case IrOpcode::kFloat64Constant:
return jsgraph_->BooleanConstant(!Float64Matcher(input).Is(0));
case IrOpcode::kNumberConstant:
return jsgraph_->BooleanConstant(!NumberMatcher(input).Is(0));
case IrOpcode::kHeapConstant: {
Handle<Object> object = HeapObjectMatcher<Object>(input).Value().handle();
return jsgraph_->BooleanConstant(object->BooleanValue());
}
case IrOpcode::kJSEqual:
case IrOpcode::kJSNotEqual:
case IrOpcode::kJSStrictEqual:
case IrOpcode::kJSStrictNotEqual:
case IrOpcode::kJSLessThan:
case IrOpcode::kJSLessThanOrEqual:
case IrOpcode::kJSGreaterThan:
case IrOpcode::kJSGreaterThanOrEqual:
case IrOpcode::kJSUnaryNot:
case IrOpcode::kJSToBoolean:
case IrOpcode::kJSDeleteProperty:
case IrOpcode::kJSHasProperty:
case IrOpcode::kJSInstanceOf:
return input;
default:
break;
}
if (NodeProperties::IsTyped(input)) {
Type* upper = NodeProperties::GetBounds(input).upper;
if (upper->Is(Type::Boolean())) return input;
}
return NewNode(javascript()->ToBoolean(), input);
}