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

[turbofan] Flatten cons strings before embedding them into optimized code.

Flatten ConsString objects in JSGraph, to make sure we consistently
flatten all cons strings no matter which pass creates them.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#32878}
parent b68f7e4c
...@@ -77,9 +77,6 @@ Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) { ...@@ -77,9 +77,6 @@ Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) {
// Success. The context load can be replaced with the constant. // Success. The context load can be replaced with the constant.
// TODO(titzer): record the specialization for sharing code across multiple // TODO(titzer): record the specialization for sharing code across multiple
// contexts that have the same value in the corresponding context slot. // contexts that have the same value in the corresponding context slot.
if (value->IsConsString()) {
value = String::Flatten(Handle<String>::cast(value), TENURED);
}
Node* constant = jsgraph_->Constant(value); Node* constant = jsgraph_->Constant(value);
ReplaceWithValue(node, constant); ReplaceWithValue(node, constant);
return Replace(constant); return Replace(constant);
......
...@@ -27,42 +27,44 @@ Reduction JSFrameSpecialization::Reduce(Node* node) { ...@@ -27,42 +27,44 @@ Reduction JSFrameSpecialization::Reduce(Node* node) {
Reduction JSFrameSpecialization::ReduceOsrValue(Node* node) { Reduction JSFrameSpecialization::ReduceOsrValue(Node* node) {
DCHECK_EQ(IrOpcode::kOsrValue, node->opcode()); DCHECK_EQ(IrOpcode::kOsrValue, node->opcode());
DisallowHeapAllocation no_gc; Handle<Object> value;
Object* object;
int const index = OpParameter<int>(node); int const index = OpParameter<int>(node);
int const parameters_count = frame()->ComputeParametersCount() + 1; int const parameters_count = frame()->ComputeParametersCount() + 1;
if (index == Linkage::kOsrContextSpillSlotIndex) { if (index == Linkage::kOsrContextSpillSlotIndex) {
object = frame()->context(); value = handle(frame()->context(), isolate());
} else if (index >= parameters_count) { } else if (index >= parameters_count) {
object = frame()->GetExpression(index - parameters_count); value = handle(frame()->GetExpression(index - parameters_count), isolate());
} else { } else {
// The OsrValue index 0 is the receiver. // The OsrValue index 0 is the receiver.
object = index ? frame()->GetParameter(index - 1) : frame()->receiver(); value =
handle(index ? frame()->GetParameter(index - 1) : frame()->receiver(),
isolate());
} }
return Replace(jsgraph()->Constant(handle(object, isolate()))); return Replace(jsgraph()->Constant(value));
} }
Reduction JSFrameSpecialization::ReduceParameter(Node* node) { Reduction JSFrameSpecialization::ReduceParameter(Node* node) {
DCHECK_EQ(IrOpcode::kParameter, node->opcode()); DCHECK_EQ(IrOpcode::kParameter, node->opcode());
DisallowHeapAllocation no_gc; Handle<Object> value;
Object* object;
int const index = ParameterIndexOf(node->op()); int const index = ParameterIndexOf(node->op());
int const parameters_count = frame()->ComputeParametersCount() + 1; int const parameters_count = frame()->ComputeParametersCount() + 1;
if (index == Linkage::kJSCallClosureParamIndex) { if (index == Linkage::kJSCallClosureParamIndex) {
// The Parameter index references the closure. // The Parameter index references the closure.
object = frame()->function(); value = handle(frame()->function(), isolate());
} else if (index == Linkage::GetJSCallArgCountParamIndex(parameters_count)) { } else if (index == Linkage::GetJSCallArgCountParamIndex(parameters_count)) {
// The Parameter index references the parameter count. // The Parameter index references the parameter count.
object = Smi::FromInt(parameters_count - 1); value = handle(Smi::FromInt(parameters_count - 1), isolate());
} else if (index == Linkage::GetJSCallContextParamIndex(parameters_count)) { } else if (index == Linkage::GetJSCallContextParamIndex(parameters_count)) {
// The Parameter index references the context. // The Parameter index references the context.
object = frame()->context(); value = handle(frame()->context(), isolate());
} else { } else {
// The Parameter index 0 is the receiver. // The Parameter index 0 is the receiver.
object = index ? frame()->GetParameter(index - 1) : frame()->receiver(); value =
handle(index ? frame()->GetParameter(index - 1) : frame()->receiver(),
isolate());
} }
return Replace(jsgraph()->Constant(handle(object, isolate()))); return Replace(jsgraph()->Constant(value));
} }
......
...@@ -72,7 +72,9 @@ Node* JSGraph::NaNConstant() { ...@@ -72,7 +72,9 @@ Node* JSGraph::NaNConstant() {
Node* JSGraph::HeapConstant(Handle<HeapObject> value) { Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
// TODO(bmeurer): Flatten cons strings here before we canonicalize them? if (value->IsConsString()) {
value = String::Flatten(Handle<String>::cast(value), TENURED);
}
Node** loc = cache_.FindHeapConstant(value); Node** loc = cache_.FindHeapConstant(value);
if (*loc == nullptr) { if (*loc == nullptr) {
*loc = graph()->NewNode(common()->HeapConstant(value)); *loc = graph()->NewNode(common()->HeapConstant(value));
......
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