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

Side by Side Diff: src/compiler/change-lowering.cc

Issue 694063005: Introduce Diamond, a helper for building diamond-shaped control patterns. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
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/change-lowering.h" 5 #include "src/compiler/change-lowering.h"
6 6
7 #include "src/compiler/diamond.h"
7 #include "src/compiler/js-graph.h" 8 #include "src/compiler/js-graph.h"
8 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
9 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
10 11
11 namespace v8 { 12 namespace v8 {
12 namespace internal { 13 namespace internal {
13 namespace compiler { 14 namespace compiler {
14 15
15 ChangeLowering::~ChangeLowering() {} 16 ChangeLowering::~ChangeLowering() {}
16 17
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 97
97 98
98 Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) { 99 Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) {
99 return graph()->NewNode(machine()->Load(kMachFloat64), value, 100 return graph()->NewNode(machine()->Load(kMachFloat64), value,
100 HeapNumberValueIndexConstant(), graph()->start(), 101 HeapNumberValueIndexConstant(), graph()->start(),
101 control); 102 control);
102 } 103 }
103 104
104 105
105 Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) { 106 Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) {
106 Node* branch = graph()->NewNode(common()->Branch(), val, control); 107 Diamond d(graph(), common(), val);
107 108 d.Chain(control);
108 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); 109 MachineType machine_type = static_cast<MachineType>(kTypeBool | kRepTagged);
109 Node* true_value = jsgraph()->TrueConstant(); 110 return Replace(d.Phi(machine_type, jsgraph()->TrueConstant(),
110 111 jsgraph()->FalseConstant()));
111 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
112 Node* false_value = jsgraph()->FalseConstant();
113
114 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
115 Node* phi = graph()->NewNode(
116 common()->Phi(static_cast<MachineType>(kTypeBool | kRepTagged), 2),
117 true_value, false_value, merge);
118
119 return Replace(phi);
120 } 112 }
121 113
122 114
123 Reduction ChangeLowering::ChangeBoolToBit(Node* val) { 115 Reduction ChangeLowering::ChangeBoolToBit(Node* val) {
124 return Replace( 116 return Replace(
125 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant())); 117 graph()->NewNode(machine()->WordEqual(), val, jsgraph()->TrueConstant()));
126 } 118 }
127 119
128 120
129 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* val, Node* control) { 121 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* val, Node* control) {
130 return Replace(AllocateHeapNumberWithValue(val, control)); 122 return Replace(AllocateHeapNumberWithValue(val, control));
131 } 123 }
132 124
133 125
134 Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) { 126 Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) {
135 if (machine()->Is64()) { 127 if (machine()->Is64()) {
136 return Replace( 128 return Replace(
137 graph()->NewNode(machine()->Word64Shl(), 129 graph()->NewNode(machine()->Word64Shl(),
138 graph()->NewNode(machine()->ChangeInt32ToInt64(), val), 130 graph()->NewNode(machine()->ChangeInt32ToInt64(), val),
139 SmiShiftBitsConstant())); 131 SmiShiftBitsConstant()));
140 } 132 }
141 133
142 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val); 134 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val);
143 Node* ovf = graph()->NewNode(common()->Projection(1), add); 135 Node* ovf = graph()->NewNode(common()->Projection(1), add);
144 136
145 Node* branch = 137 Diamond d(graph(), common(), ovf, BranchHint::kFalse);
146 graph()->NewNode(common()->Branch(BranchHint::kTrue), ovf, control); 138 d.Chain(control);
147
148 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
149 Node* heap_number = AllocateHeapNumberWithValue( 139 Node* heap_number = AllocateHeapNumberWithValue(
150 graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), if_true); 140 graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), d.if_true);
151
152 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
153 Node* smi = graph()->NewNode(common()->Projection(0), add); 141 Node* smi = graph()->NewNode(common()->Projection(0), add);
154 142 return Replace(d.Phi(kMachAnyTagged, heap_number, smi));
155 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
156 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), heap_number,
157 smi, merge);
158
159 return Replace(phi);
160 } 143 }
161 144
162 145
163 Reduction ChangeLowering::ChangeTaggedToUI32(Node* val, Node* control, 146 Reduction ChangeLowering::ChangeTaggedToUI32(Node* val, Node* control,
164 Signedness signedness) { 147 Signedness signedness) {
165 STATIC_ASSERT(kSmiTag == 0); 148 STATIC_ASSERT(kSmiTag == 0);
166 STATIC_ASSERT(kSmiTagMask == 1); 149 STATIC_ASSERT(kSmiTagMask == 1);
167 150
168 Node* tag = graph()->NewNode(machine()->WordAnd(), val, 151 Node* tag = graph()->NewNode(machine()->WordAnd(), val,
169 jsgraph()->IntPtrConstant(kSmiTagMask)); 152 jsgraph()->IntPtrConstant(kSmiTagMask));
170 Node* branch = graph()->NewNode(common()->Branch(), tag, control);
171 153
172 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); 154 Diamond d(graph(), common(), tag, BranchHint::kFalse);
155 d.Chain(control);
173 const Operator* op = (signedness == kSigned) 156 const Operator* op = (signedness == kSigned)
174 ? machine()->ChangeFloat64ToInt32() 157 ? machine()->ChangeFloat64ToInt32()
175 : machine()->ChangeFloat64ToUint32(); 158 : machine()->ChangeFloat64ToUint32();
176 Node* change = graph()->NewNode(op, LoadHeapNumberValue(val, if_true)); 159 Node* load = graph()->NewNode(op, LoadHeapNumberValue(val, d.if_true));
177
178 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
179 Node* number = ChangeSmiToInt32(val); 160 Node* number = ChangeSmiToInt32(val);
180 161
181 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); 162 return Replace(
182 Node* phi = graph()->NewNode( 163 d.Phi((signedness == kSigned) ? kMachInt32 : kMachUint32, load, number));
183 common()->Phi((signedness == kSigned) ? kMachInt32 : kMachUint32, 2),
184 change, number, merge);
185
186 return Replace(phi);
187 } 164 }
188 165
189 166
190 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) { 167 Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) {
191 STATIC_ASSERT(kSmiTag == 0); 168 STATIC_ASSERT(kSmiTag == 0);
192 STATIC_ASSERT(kSmiTagMask == 1); 169 STATIC_ASSERT(kSmiTagMask == 1);
193 170
194 Node* tag = graph()->NewNode(machine()->WordAnd(), val, 171 Node* tag = graph()->NewNode(machine()->WordAnd(), val,
195 jsgraph()->IntPtrConstant(kSmiTagMask)); 172 jsgraph()->IntPtrConstant(kSmiTagMask));
196 Node* branch = graph()->NewNode(common()->Branch(), tag, control); 173 Diamond d(graph(), common(), tag, BranchHint::kFalse);
197 174 d.Chain(control);
198 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); 175 Node* load = LoadHeapNumberValue(val, d.if_true);
199 Node* load = LoadHeapNumberValue(val, if_true);
200
201 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
202 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(), 176 Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(),
203 ChangeSmiToInt32(val)); 177 ChangeSmiToInt32(val));
204 178
205 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); 179 return Replace(d.Phi(kMachFloat64, load, number));
206 Node* phi =
207 graph()->NewNode(common()->Phi(kMachFloat64, 2), load, number, merge);
208
209 return Replace(phi);
210 } 180 }
211 181
212 182
213 Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) { 183 Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) {
214 STATIC_ASSERT(kSmiTag == 0); 184 STATIC_ASSERT(kSmiTag == 0);
215 STATIC_ASSERT(kSmiTagMask == 1); 185 STATIC_ASSERT(kSmiTagMask == 1);
216 186
217 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val, 187 Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val,
218 SmiMaxValueConstant()); 188 SmiMaxValueConstant());
219 Node* branch = 189 Diamond d(graph(), common(), cmp, BranchHint::kTrue);
220 graph()->NewNode(common()->Branch(BranchHint::kTrue), cmp, control); 190 d.Chain(control);
221
222 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
223 Node* smi = graph()->NewNode( 191 Node* smi = graph()->NewNode(
224 machine()->WordShl(), 192 machine()->WordShl(),
225 machine()->Is64() 193 machine()->Is64()
226 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val) 194 ? graph()->NewNode(machine()->ChangeUint32ToUint64(), val)
227 : val, 195 : val,
228 SmiShiftBitsConstant()); 196 SmiShiftBitsConstant());
229 197
230 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
231 Node* heap_number = AllocateHeapNumberWithValue( 198 Node* heap_number = AllocateHeapNumberWithValue(
232 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false); 199 graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), d.if_false);
233 200
234 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); 201 return Replace(d.Phi(kMachAnyTagged, smi, heap_number));
235 Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), smi,
236 heap_number, merge);
237
238 return Replace(phi);
239 } 202 }
240 203
241 204
242 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } 205 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); }
243 206
244 207
245 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } 208 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); }
246 209
247 210
248 CommonOperatorBuilder* ChangeLowering::common() const { 211 CommonOperatorBuilder* ChangeLowering::common() const {
249 return jsgraph()->common(); 212 return jsgraph()->common();
250 } 213 }
251 214
252 215
253 MachineOperatorBuilder* ChangeLowering::machine() const { 216 MachineOperatorBuilder* ChangeLowering::machine() const {
254 return jsgraph()->machine(); 217 return jsgraph()->machine();
255 } 218 }
256 219
257 } // namespace compiler 220 } // namespace compiler
258 } // namespace internal 221 } // namespace internal
259 } // namespace v8 222 } // namespace v8
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/compiler/diamond.h » ('j') | src/compiler/simplified-lowering.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698