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

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

Issue 1218873005: [turbofan] Context specialization is the job of the JSContextSpecialization. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix mini-nit. Created 5 years, 5 months 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-context-specialization.h ('k') | src/compiler/js-inlining.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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-context-specialization.h" 5 #include "src/compiler/js-context-specialization.h"
6 6
7 #include "src/compiler/common-operator.h" 7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/js-graph.h" 8 #include "src/compiler/js-graph.h"
9 #include "src/compiler/js-operator.h" 9 #include "src/compiler/js-operator.h"
10 #include "src/compiler/node-matchers.h" 10 #include "src/compiler/node-matchers.h"
11 #include "src/compiler/node-properties.h" 11 #include "src/compiler/node-properties.h"
12 #include "src/contexts.h" 12 #include "src/contexts.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 namespace compiler { 16 namespace compiler {
17 17
18 Reduction JSContextSpecializer::Reduce(Node* node) { 18 Reduction JSContextSpecialization::Reduce(Node* node) {
19 if (node->opcode() == IrOpcode::kJSLoadContext) { 19 switch (node->opcode()) {
20 return ReduceJSLoadContext(node); 20 case IrOpcode::kParameter:
21 } 21 return ReduceParameter(node);
22 if (node->opcode() == IrOpcode::kJSStoreContext) { 22 case IrOpcode::kJSLoadContext:
23 return ReduceJSStoreContext(node); 23 return ReduceJSLoadContext(node);
24 case IrOpcode::kJSStoreContext:
25 return ReduceJSStoreContext(node);
26 default:
27 break;
24 } 28 }
25 return NoChange(); 29 return NoChange();
26 } 30 }
27 31
28 32
29 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { 33 Reduction JSContextSpecialization::ReduceParameter(Node* node) {
34 DCHECK_EQ(IrOpcode::kParameter, node->opcode());
35 Node* const start = NodeProperties::GetValueInput(node, 0);
36 DCHECK_EQ(IrOpcode::kStart, start->opcode());
37 int const index = ParameterIndexOf(node->op());
38 // The context is always the last parameter to a JavaScript function, and
39 // {Parameter} indices start at -1, so value outputs of {Start} look like
40 // this: closure, receiver, param0, ..., paramN, context.
41 if (index == start->op()->ValueOutputCount() - 2) {
42 Handle<Context> context_constant;
43 if (context().ToHandle(&context_constant)) {
44 return Replace(jsgraph()->Constant(context_constant));
45 }
46 }
47 return NoChange();
48 }
49
50
51 Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) {
30 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); 52 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode());
31 53
32 HeapObjectMatcher m(NodeProperties::GetValueInput(node, 0)); 54 HeapObjectMatcher m(NodeProperties::GetValueInput(node, 0));
33 // If the context is not constant, no reduction can occur. 55 // If the context is not constant, no reduction can occur.
34 if (!m.HasValue()) { 56 if (!m.HasValue()) {
35 return NoChange(); 57 return NoChange();
36 } 58 }
37 59
38 const ContextAccess& access = ContextAccessOf(node->op()); 60 const ContextAccess& access = ContextAccessOf(node->op());
39 61
(...skipping 28 matching lines...) Expand all
68 90
69 // Success. The context load can be replaced with the constant. 91 // Success. The context load can be replaced with the constant.
70 // TODO(titzer): record the specialization for sharing code across multiple 92 // TODO(titzer): record the specialization for sharing code across multiple
71 // contexts that have the same value in the corresponding context slot. 93 // contexts that have the same value in the corresponding context slot.
72 Node* constant = jsgraph_->Constant(value); 94 Node* constant = jsgraph_->Constant(value);
73 ReplaceWithValue(node, constant); 95 ReplaceWithValue(node, constant);
74 return Replace(constant); 96 return Replace(constant);
75 } 97 }
76 98
77 99
78 Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) { 100 Reduction JSContextSpecialization::ReduceJSStoreContext(Node* node) {
79 DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode()); 101 DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode());
80 102
81 HeapObjectMatcher m(NodeProperties::GetValueInput(node, 0)); 103 HeapObjectMatcher m(NodeProperties::GetValueInput(node, 0));
82 // If the context is not constant, no reduction can occur. 104 // If the context is not constant, no reduction can occur.
83 if (!m.HasValue()) { 105 if (!m.HasValue()) {
84 return NoChange(); 106 return NoChange();
85 } 107 }
86 108
87 const ContextAccess& access = ContextAccessOf(node->op()); 109 const ContextAccess& access = ContextAccessOf(node->op());
88 110
89 // The access does not have to look up a parent, nothing to fold. 111 // The access does not have to look up a parent, nothing to fold.
90 if (access.depth() == 0) { 112 if (access.depth() == 0) {
91 return NoChange(); 113 return NoChange();
92 } 114 }
93 115
94 // Find the right parent context. 116 // Find the right parent context.
95 Handle<Context> context = Handle<Context>::cast(m.Value().handle()); 117 Handle<Context> context = Handle<Context>::cast(m.Value().handle());
96 for (size_t i = access.depth(); i > 0; --i) { 118 for (size_t i = access.depth(); i > 0; --i) {
97 context = handle(context->previous(), isolate()); 119 context = handle(context->previous(), isolate());
98 } 120 }
99 121
100 node->set_op(javascript()->StoreContext(0, access.index())); 122 node->set_op(javascript()->StoreContext(0, access.index()));
101 node->ReplaceInput(0, jsgraph_->Constant(context)); 123 node->ReplaceInput(0, jsgraph_->Constant(context));
102 return Changed(node); 124 return Changed(node);
103 } 125 }
104 126
105 127
106 Isolate* JSContextSpecializer::isolate() const { return jsgraph()->isolate(); } 128 Isolate* JSContextSpecialization::isolate() const {
129 return jsgraph()->isolate();
130 }
107 131
108 132
109 JSOperatorBuilder* JSContextSpecializer::javascript() const { 133 JSOperatorBuilder* JSContextSpecialization::javascript() const {
110 return jsgraph()->javascript(); 134 return jsgraph()->javascript();
111 } 135 }
112 136
113 } // namespace compiler 137 } // namespace compiler
114 } // namespace internal 138 } // namespace internal
115 } // namespace v8 139 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-context-specialization.h ('k') | src/compiler/js-inlining.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698