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

Side by Side Diff: src/compiler/simplified-operator-reducer.cc

Issue 999173003: [turbofan] Remove indirection in JSToBoolean/JSUnaryNot lowering. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add comment. Created 5 years, 9 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/simplified-operator-reducer.h ('k') | src/compiler/typer.cc » ('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/simplified-operator-reducer.h" 5 #include "src/compiler/simplified-operator-reducer.h"
6 6
7 #include "src/compiler/access-builder.h"
8 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
9 #include "src/compiler/machine-operator.h" 8 #include "src/compiler/machine-operator.h"
10 #include "src/compiler/node-matchers.h" 9 #include "src/compiler/node-matchers.h"
11 #include "src/compiler/node-properties.h"
12 #include "src/compiler/operator-properties.h" 10 #include "src/compiler/operator-properties.h"
13 11
14 namespace v8 { 12 namespace v8 {
15 namespace internal { 13 namespace internal {
16 namespace compiler { 14 namespace compiler {
17 15
18 SimplifiedOperatorReducer::SimplifiedOperatorReducer(JSGraph* jsgraph) 16 SimplifiedOperatorReducer::SimplifiedOperatorReducer(JSGraph* jsgraph)
19 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} 17 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
20 18
21 19
22 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} 20 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {}
23 21
24 22
25 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { 23 Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
26 switch (node->opcode()) { 24 switch (node->opcode()) {
27 case IrOpcode::kAnyToBoolean:
28 return ReduceAnyToBoolean(node);
29 case IrOpcode::kBooleanNot: { 25 case IrOpcode::kBooleanNot: {
30 HeapObjectMatcher<HeapObject> m(node->InputAt(0)); 26 HeapObjectMatcher<HeapObject> m(node->InputAt(0));
31 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { 27 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) {
32 return Replace(jsgraph()->TrueConstant()); 28 return Replace(jsgraph()->TrueConstant());
33 } 29 }
34 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) { 30 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) {
35 return Replace(jsgraph()->FalseConstant()); 31 return Replace(jsgraph()->FalseConstant());
36 } 32 }
37 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0)); 33 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0));
38 break; 34 break;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value())); 100 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value()));
105 break; 101 break;
106 } 102 }
107 default: 103 default:
108 break; 104 break;
109 } 105 }
110 return NoChange(); 106 return NoChange();
111 } 107 }
112 108
113 109
114 Reduction SimplifiedOperatorReducer::ReduceAnyToBoolean(Node* node) {
115 Node* const input = NodeProperties::GetValueInput(node, 0);
116 Type* const input_type = NodeProperties::GetBounds(input).upper;
117 if (input_type->Is(Type::Boolean())) {
118 // AnyToBoolean(x:boolean) => x
119 return Replace(input);
120 }
121 if (input_type->Is(Type::OrderedNumber())) {
122 // AnyToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x, #0))
123 Node* compare = graph()->NewNode(simplified()->NumberEqual(), input,
124 jsgraph()->ZeroConstant());
125 return Change(node, simplified()->BooleanNot(), compare);
126 }
127 if (input_type->Is(Type::String())) {
128 // AnyToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0))
129 FieldAccess const access = AccessBuilder::ForStringLength();
130 Node* length = graph()->NewNode(simplified()->LoadField(access), input,
131 graph()->start(), graph()->start());
132 Node* compare = graph()->NewNode(simplified()->NumberEqual(), length,
133 jsgraph()->ZeroConstant());
134 return Change(node, simplified()->BooleanNot(), compare);
135 }
136 return NoChange();
137 }
138
139
140 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, 110 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op,
141 Node* a) { 111 Node* a) {
142 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op)); 112 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op));
143 DCHECK_LE(1, node->InputCount()); 113 DCHECK_LE(1, node->InputCount());
144 node->set_op(op); 114 node->set_op(op);
145 node->ReplaceInput(0, a); 115 node->ReplaceInput(0, a);
146 return Changed(node); 116 return Changed(node);
147 } 117 }
148 118
149 119
(...skipping 18 matching lines...) Expand all
168 138
169 139
170 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } 140 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); }
171 141
172 142
173 Factory* SimplifiedOperatorReducer::factory() const { 143 Factory* SimplifiedOperatorReducer::factory() const {
174 return jsgraph()->isolate()->factory(); 144 return jsgraph()->isolate()->factory();
175 } 145 }
176 146
177 147
178 CommonOperatorBuilder* SimplifiedOperatorReducer::common() const {
179 return jsgraph()->common();
180 }
181
182
183 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { 148 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const {
184 return jsgraph()->machine(); 149 return jsgraph()->machine();
185 } 150 }
186 151
187 } // namespace compiler 152 } // namespace compiler
188 } // namespace internal 153 } // namespace internal
189 } // namespace v8 154 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simplified-operator-reducer.h ('k') | src/compiler/typer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698