Commit f1db38ca authored by bmeurer's avatar bmeurer Committed by Commit bot

[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}
parent 3161cb55
......@@ -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);
}
......
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