Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: src/compiler/js-native-context-specialization.cc

Issue 2522543008: Merged: Squashed multiple commits. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/js-native-context-specialization.h ('k') | src/compiler/js-operator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/js-native-context-specialization.h" 5 #include "src/compiler/js-native-context-specialization.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/compilation-dependencies.h" 9 #include "src/compilation-dependencies.h"
10 #include "src/compiler/access-builder.h" 10 #include "src/compiler/access-builder.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 jsgraph_(jsgraph), 63 jsgraph_(jsgraph),
64 flags_(flags), 64 flags_(flags),
65 native_context_(native_context), 65 native_context_(native_context),
66 dependencies_(dependencies), 66 dependencies_(dependencies),
67 zone_(zone), 67 zone_(zone),
68 type_cache_(TypeCache::Get()) {} 68 type_cache_(TypeCache::Get()) {}
69 69
70 70
71 Reduction JSNativeContextSpecialization::Reduce(Node* node) { 71 Reduction JSNativeContextSpecialization::Reduce(Node* node) {
72 switch (node->opcode()) { 72 switch (node->opcode()) {
73 case IrOpcode::kJSInstanceOf:
74 return ReduceJSInstanceOf(node);
73 case IrOpcode::kJSLoadContext: 75 case IrOpcode::kJSLoadContext:
74 return ReduceJSLoadContext(node); 76 return ReduceJSLoadContext(node);
75 case IrOpcode::kJSLoadNamed: 77 case IrOpcode::kJSLoadNamed:
76 return ReduceJSLoadNamed(node); 78 return ReduceJSLoadNamed(node);
77 case IrOpcode::kJSStoreNamed: 79 case IrOpcode::kJSStoreNamed:
78 return ReduceJSStoreNamed(node); 80 return ReduceJSStoreNamed(node);
79 case IrOpcode::kJSLoadProperty: 81 case IrOpcode::kJSLoadProperty:
80 return ReduceJSLoadProperty(node); 82 return ReduceJSLoadProperty(node);
81 case IrOpcode::kJSStoreProperty: 83 case IrOpcode::kJSStoreProperty:
82 return ReduceJSStoreProperty(node); 84 return ReduceJSStoreProperty(node);
83 default: 85 default:
84 break; 86 break;
85 } 87 }
86 return NoChange(); 88 return NoChange();
87 } 89 }
88 90
91 Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) {
92 DCHECK_EQ(IrOpcode::kJSInstanceOf, node->opcode());
93 Node* object = NodeProperties::GetValueInput(node, 0);
94 Node* constructor = NodeProperties::GetValueInput(node, 1);
95 Node* context = NodeProperties::GetContextInput(node);
96 Node* effect = NodeProperties::GetEffectInput(node);
97 Node* control = NodeProperties::GetControlInput(node);
98
99 // Retrieve the native context from the given {node}.
100 Handle<Context> native_context;
101 if (!GetNativeContext(node).ToHandle(&native_context)) return NoChange();
102
103 // If deoptimization is disabled, we cannot optimize.
104 if (!(flags() & kDeoptimizationEnabled)) return NoChange();
105
106 // Check if the right hand side is a known {receiver}.
107 HeapObjectMatcher m(constructor);
108 if (!m.HasValue() || !m.Value()->IsJSObject()) return NoChange();
109 Handle<JSObject> receiver = Handle<JSObject>::cast(m.Value());
110 Handle<Map> receiver_map(receiver->map(), isolate());
111
112 // Compute property access info for @@hasInstance on {receiver}.
113 PropertyAccessInfo access_info;
114 AccessInfoFactory access_info_factory(dependencies(), native_context,
115 graph()->zone());
116 if (!access_info_factory.ComputePropertyAccessInfo(
117 receiver_map, factory()->has_instance_symbol(), AccessMode::kLoad,
118 &access_info)) {
119 return NoChange();
120 }
121
122 if (access_info.IsNotFound()) {
123 // If there's no @@hasInstance handler, the OrdinaryHasInstance operation
124 // takes over, but that requires the {receiver} to be callable.
125 if (receiver->IsCallable()) {
126 // Determine actual holder and perform prototype chain checks.
127 Handle<JSObject> holder;
128 if (access_info.holder().ToHandle(&holder)) {
129 AssumePrototypesStable(access_info.receiver_maps(), native_context,
130 holder);
131 }
132
133 // Monomorphic property access.
134 effect =
135 BuildCheckMaps(constructor, effect, control, MapList{receiver_map});
136
137 // Lower to OrdinaryHasInstance(C, O).
138 NodeProperties::ReplaceValueInput(node, constructor, 0);
139 NodeProperties::ReplaceValueInput(node, object, 1);
140 NodeProperties::ReplaceEffectInput(node, effect);
141 NodeProperties::ChangeOp(node, javascript()->OrdinaryHasInstance());
142 return Changed(node);
143 }
144 } else if (access_info.IsDataConstant()) {
145 DCHECK(access_info.constant()->IsCallable());
146
147 // Determine actual holder and perform prototype chain checks.
148 Handle<JSObject> holder;
149 if (access_info.holder().ToHandle(&holder)) {
150 AssumePrototypesStable(access_info.receiver_maps(), native_context,
151 holder);
152 }
153
154 // Monomorphic property access.
155 effect =
156 BuildCheckMaps(constructor, effect, control, MapList{receiver_map});
157
158 // Call the @@hasInstance handler.
159 Node* target = jsgraph()->Constant(access_info.constant());
160 node->InsertInput(graph()->zone(), 0, target);
161 node->ReplaceInput(1, constructor);
162 node->ReplaceInput(2, object);
163 node->ReplaceInput(5, effect);
164 NodeProperties::ChangeOp(
165 node,
166 javascript()->CallFunction(3, 0.0f, VectorSlotPair(),
167 ConvertReceiverMode::kNotNullOrUndefined));
168
169 // Rewire the value uses of {node} to ToBoolean conversion of the result.
170 Node* value = graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
171 node, context);
172 for (Edge edge : node->use_edges()) {
173 if (NodeProperties::IsValueEdge(edge) && edge.from() != value) {
174 edge.UpdateTo(value);
175 Revisit(edge.from());
176 }
177 }
178 return Changed(node);
179 }
180
181 return NoChange();
182 }
183
89 Reduction JSNativeContextSpecialization::ReduceJSLoadContext(Node* node) { 184 Reduction JSNativeContextSpecialization::ReduceJSLoadContext(Node* node) {
90 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); 185 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode());
91 ContextAccess const& access = ContextAccessOf(node->op()); 186 ContextAccess const& access = ContextAccessOf(node->op());
92 Handle<Context> native_context; 187 Handle<Context> native_context;
93 // Specialize JSLoadContext(NATIVE_CONTEXT_INDEX) to the known native 188 // Specialize JSLoadContext(NATIVE_CONTEXT_INDEX) to the known native
94 // context (if any), so we can constant-fold those fields, which is 189 // context (if any), so we can constant-fold those fields, which is
95 // safe, since the NATIVE_CONTEXT_INDEX slot is always immutable. 190 // safe, since the NATIVE_CONTEXT_INDEX slot is always immutable.
96 if (access.index() == Context::NATIVE_CONTEXT_INDEX && 191 if (access.index() == Context::NATIVE_CONTEXT_INDEX &&
97 GetNativeContext(node).ToHandle(&native_context)) { 192 GetNativeContext(node).ToHandle(&native_context)) {
98 Node* value = jsgraph()->HeapConstant(native_context); 193 Node* value = jsgraph()->HeapConstant(native_context);
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 } 1625 }
1531 1626
1532 1627
1533 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { 1628 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const {
1534 return jsgraph()->simplified(); 1629 return jsgraph()->simplified();
1535 } 1630 }
1536 1631
1537 } // namespace compiler 1632 } // namespace compiler
1538 } // namespace internal 1633 } // namespace internal
1539 } // namespace v8 1634 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-native-context-specialization.h ('k') | src/compiler/js-operator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698