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

Side by Side Diff: src/compiler/js-intrinsic-builder.cc

Issue 872363002: [turbofan] Add new JSIntrinsicsLowering reducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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-intrinsic-builder.h ('k') | src/compiler/js-intrinsic-lowering.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/compiler/access-builder.h"
6 #include "src/compiler/common-operator.h"
7 #include "src/compiler/diamond.h"
8 #include "src/compiler/js-intrinsic-builder.h"
9 #include "src/compiler/js-operator.h"
10 #include "src/compiler/simplified-operator.h"
11
12
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16
17 ResultAndEffect JSIntrinsicBuilder::BuildGraphFor(Runtime::FunctionId id,
18 const NodeVector& arguments) {
19 switch (id) {
20 case Runtime::kInlineIsSmi:
21 return BuildGraphFor_IsSmi(arguments);
22 case Runtime::kInlineIsNonNegativeSmi:
23 return BuildGraphFor_IsNonNegativeSmi(arguments);
24 case Runtime::kInlineIsArray:
25 return BuildMapCheck(arguments[0], arguments[2], JS_ARRAY_TYPE);
26 case Runtime::kInlineIsRegExp:
27 return BuildMapCheck(arguments[0], arguments[2], JS_REGEXP_TYPE);
28 case Runtime::kInlineIsFunction:
29 return BuildMapCheck(arguments[0], arguments[2], JS_FUNCTION_TYPE);
30 case Runtime::kInlineValueOf:
31 return BuildGraphFor_ValueOf(arguments);
32 default:
33 break;
34 }
35 return ResultAndEffect();
36 }
37
38 ResultAndEffect JSIntrinsicBuilder::BuildGraphFor_IsSmi(
39 const NodeVector& arguments) {
40 Node* object = arguments[0];
41 SimplifiedOperatorBuilder simplified(jsgraph_->zone());
42 Node* condition = graph()->NewNode(simplified.ObjectIsSmi(), object);
43
44 return ResultAndEffect(condition, arguments[2]);
45 }
46
47
48 ResultAndEffect JSIntrinsicBuilder::BuildGraphFor_IsNonNegativeSmi(
49 const NodeVector& arguments) {
50 Node* object = arguments[0];
51 SimplifiedOperatorBuilder simplified(jsgraph_->zone());
52 Node* condition =
53 graph()->NewNode(simplified.ObjectIsNonNegativeSmi(), object);
54
55 return ResultAndEffect(condition, arguments[2]);
56 }
57
58
59 /*
60 * if (_isSmi(object)) {
61 * return false
62 * } else {
63 * return %_GetMapInstanceType(object) == map_type
64 * }
65 */
66 ResultAndEffect JSIntrinsicBuilder::BuildMapCheck(Node* object, Node* effect,
67 InstanceType map_type) {
68 SimplifiedOperatorBuilder simplified(jsgraph_->zone());
69
70 Node* is_smi = graph()->NewNode(simplified.ObjectIsSmi(), object);
71 Diamond d(graph(), common(), is_smi);
72
73 Node* map = graph()->NewNode(simplified.LoadField(AccessBuilder::ForMap()),
74 object, effect, d.if_false);
75
76 Node* instance_type = graph()->NewNode(
77 simplified.LoadField(AccessBuilder::ForMapInstanceType()), map, map,
78 d.if_false);
79
80 Node* has_map_type =
81 graph()->NewNode(jsgraph_->machine()->Word32Equal(), instance_type,
82 jsgraph_->Int32Constant(map_type));
83
84 Node* phi = d.Phi(static_cast<MachineType>(kTypeBool | kRepTagged),
85 jsgraph_->FalseConstant(), has_map_type);
86
87 Node* ephi = d.EffectPhi(effect, instance_type);
88
89 return ResultAndEffect(phi, ephi);
90 }
91
92
93 /*
94 * if (%_isSmi(object)) {
95 * return object;
96 * } else if (%_GetMapInstanceType(object) == JS_VALUE_TYPE) {
97 * return %_LoadValueField(object);
98 * } else {
99 * return object;
100 * }
101 */
102 ResultAndEffect JSIntrinsicBuilder::BuildGraphFor_ValueOf(
103 const NodeVector& arguments) {
104 Node* object = arguments[0];
105 Node* effect = arguments[2];
106 SimplifiedOperatorBuilder simplified(jsgraph_->zone());
107
108 Node* is_smi = graph()->NewNode(simplified.ObjectIsSmi(), object);
109
110 Diamond if_is_smi(graph(), common(), is_smi);
111
112 Node* map = graph()->NewNode(simplified.LoadField(AccessBuilder::ForMap()),
113 object, effect, if_is_smi.if_false);
114
115 Node* instance_type = graph()->NewNode(
116 simplified.LoadField(AccessBuilder::ForMapInstanceType()), map, map,
117 if_is_smi.if_false);
118
119 Node* is_value =
120 graph()->NewNode(jsgraph_->machine()->Word32Equal(), instance_type,
121 jsgraph_->Constant(JS_VALUE_TYPE));
122
123 Diamond if_is_value(graph(), common(), is_value);
124 if_is_value.Nest(if_is_smi, false);
125
126 Node* value =
127 graph()->NewNode(simplified.LoadField(AccessBuilder::ForValue()), object,
128 instance_type, if_is_value.if_true);
129
130 Node* phi_is_value = if_is_value.Phi(kTypeAny, value, object);
131
132 Node* phi = if_is_smi.Phi(kTypeAny, object, phi_is_value);
133
134 Node* ephi = if_is_smi.EffectPhi(effect, instance_type);
135
136 return ResultAndEffect(phi, ephi);
137 }
138 }
139 }
140 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/js-intrinsic-builder.h ('k') | src/compiler/js-intrinsic-lowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698