blob: 5427bdb1cd83bcd8589cfaf860df8004e6c498f7 [file] [log] [blame]
Ben Murdoch014dc512016-03-22 12:00:34 +00001// 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
3// found in the LICENSE file.
4
5#include "src/compiler/representation-change.h"
6
7#include <sstream>
8
9#include "src/base/bits.h"
10#include "src/code-factory.h"
11#include "src/compiler/machine-operator.h"
12
13namespace v8 {
14namespace internal {
15namespace compiler {
16
17const char* Truncation::description() const {
18 switch (kind()) {
19 case TruncationKind::kNone:
20 return "no-value-use";
21 case TruncationKind::kBool:
22 return "truncate-to-bool";
23 case TruncationKind::kWord32:
24 return "truncate-to-word32";
25 case TruncationKind::kWord64:
26 return "truncate-to-word64";
27 case TruncationKind::kFloat32:
28 return "truncate-to-float32";
29 case TruncationKind::kFloat64:
30 return "truncate-to-float64";
31 case TruncationKind::kAny:
32 return "no-truncation";
33 }
34 UNREACHABLE();
35 return nullptr;
36}
37
38
39// Partial order for truncations:
40//
41// kWord64 kAny
42// ^ ^
43// \ |
44// \ kFloat64 <--+
45// \ ^ ^ |
46// \ / | |
47// kWord32 kFloat32 kBool
48// ^ ^ ^
49// \ | /
50// \ | /
51// \ | /
52// \ | /
53// \ | /
54// kNone
55
56// static
57Truncation::TruncationKind Truncation::Generalize(TruncationKind rep1,
58 TruncationKind rep2) {
59 if (LessGeneral(rep1, rep2)) return rep2;
60 if (LessGeneral(rep2, rep1)) return rep1;
61 // Handle the generalization of float64-representable values.
62 if (LessGeneral(rep1, TruncationKind::kFloat64) &&
63 LessGeneral(rep2, TruncationKind::kFloat64)) {
64 return TruncationKind::kFloat64;
65 }
Ben Murdochf91f0612016-11-29 16:50:11 +000066 // Handle the generalization of any-representable values.
67 if (LessGeneral(rep1, TruncationKind::kAny) &&
68 LessGeneral(rep2, TruncationKind::kAny)) {
69 return TruncationKind::kAny;
70 }
Ben Murdoch014dc512016-03-22 12:00:34 +000071 // All other combinations are illegal.
72 FATAL("Tried to combine incompatible truncations");
73 return TruncationKind::kNone;
74}
75
76
77// static
78bool Truncation::LessGeneral(TruncationKind rep1, TruncationKind rep2) {
79 switch (rep1) {
80 case TruncationKind::kNone:
81 return true;
82 case TruncationKind::kBool:
83 return rep2 == TruncationKind::kBool || rep2 == TruncationKind::kAny;
84 case TruncationKind::kWord32:
85 return rep2 == TruncationKind::kWord32 ||
86 rep2 == TruncationKind::kWord64 ||
87 rep2 == TruncationKind::kFloat64 || rep2 == TruncationKind::kAny;
88 case TruncationKind::kWord64:
89 return rep2 == TruncationKind::kWord64;
90 case TruncationKind::kFloat32:
91 return rep2 == TruncationKind::kFloat32 ||
92 rep2 == TruncationKind::kFloat64 || rep2 == TruncationKind::kAny;
93 case TruncationKind::kFloat64:
94 return rep2 == TruncationKind::kFloat64 || rep2 == TruncationKind::kAny;
95 case TruncationKind::kAny:
96 return rep2 == TruncationKind::kAny;
97 }
98 UNREACHABLE();
99 return false;
100}
101
102
103namespace {
104
Ben Murdoch014dc512016-03-22 12:00:34 +0000105bool IsWord(MachineRepresentation rep) {
106 return rep == MachineRepresentation::kWord8 ||
107 rep == MachineRepresentation::kWord16 ||
108 rep == MachineRepresentation::kWord32;
109}
110
111} // namespace
112
Ben Murdoch014dc512016-03-22 12:00:34 +0000113// Changes representation from {output_rep} to {use_rep}. The {truncation}
114// parameter is only used for sanity checking - if the changer cannot figure
115// out signedness for the word32->float64 conversion, then we check that the
116// uses truncate to word32 (so they do not care about signedness).
117Node* RepresentationChanger::GetRepresentationFor(
118 Node* node, MachineRepresentation output_rep, Type* output_type,
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100119 Node* use_node, UseInfo use_info) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000120 if (output_rep == MachineRepresentation::kNone &&
121 output_type->IsInhabited()) {
122 // The output representation should be set if the type is inhabited (i.e.,
123 // if the value is possible).
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100124 return TypeError(node, output_rep, output_type, use_info.representation());
Ben Murdoch014dc512016-03-22 12:00:34 +0000125 }
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100126
127 // Handle the no-op shortcuts when no checking is necessary.
128 if (use_info.type_check() == TypeCheckKind::kNone ||
129 output_rep != MachineRepresentation::kWord32) {
130 if (use_info.representation() == output_rep) {
131 // Representations are the same. That's a no-op.
132 return node;
133 }
134 if (IsWord(use_info.representation()) && IsWord(output_rep)) {
135 // Both are words less than or equal to 32-bits.
136 // Since loads of integers from memory implicitly sign or zero extend the
137 // value to the full machine word size and stores implicitly truncate,
138 // no representation change is necessary.
139 return node;
140 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000141 }
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100142
143 switch (use_info.representation()) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000144 case MachineRepresentation::kTaggedSigned:
145 case MachineRepresentation::kTaggedPointer:
Ben Murdoch014dc512016-03-22 12:00:34 +0000146 case MachineRepresentation::kTagged:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100147 DCHECK(use_info.type_check() == TypeCheckKind::kNone);
Ben Murdoch014dc512016-03-22 12:00:34 +0000148 return GetTaggedRepresentationFor(node, output_rep, output_type);
149 case MachineRepresentation::kFloat32:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100150 DCHECK(use_info.type_check() == TypeCheckKind::kNone);
Ben Murdoch014dc512016-03-22 12:00:34 +0000151 return GetFloat32RepresentationFor(node, output_rep, output_type,
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100152 use_info.truncation());
Ben Murdoch014dc512016-03-22 12:00:34 +0000153 case MachineRepresentation::kFloat64:
154 return GetFloat64RepresentationFor(node, output_rep, output_type,
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100155 use_node, use_info);
Ben Murdoch014dc512016-03-22 12:00:34 +0000156 case MachineRepresentation::kBit:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100157 DCHECK(use_info.type_check() == TypeCheckKind::kNone);
Ben Murdoch014dc512016-03-22 12:00:34 +0000158 return GetBitRepresentationFor(node, output_rep, output_type);
159 case MachineRepresentation::kWord8:
160 case MachineRepresentation::kWord16:
161 case MachineRepresentation::kWord32:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100162 return GetWord32RepresentationFor(node, output_rep, output_type, use_node,
163 use_info);
Ben Murdoch014dc512016-03-22 12:00:34 +0000164 case MachineRepresentation::kWord64:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100165 DCHECK(use_info.type_check() == TypeCheckKind::kNone);
Ben Murdoch014dc512016-03-22 12:00:34 +0000166 return GetWord64RepresentationFor(node, output_rep, output_type);
Ben Murdoch109988c2016-05-18 11:27:45 +0100167 case MachineRepresentation::kSimd128: // Fall through.
168 // TODO(bbudge) Handle conversions between tagged and untagged.
169 break;
Ben Murdoch014dc512016-03-22 12:00:34 +0000170 case MachineRepresentation::kNone:
171 return node;
172 }
173 UNREACHABLE();
174 return nullptr;
175}
176
Ben Murdoch014dc512016-03-22 12:00:34 +0000177Node* RepresentationChanger::GetTaggedRepresentationFor(
178 Node* node, MachineRepresentation output_rep, Type* output_type) {
179 // Eagerly fold representation changes for constants.
180 switch (node->opcode()) {
181 case IrOpcode::kNumberConstant:
182 case IrOpcode::kHeapConstant:
183 return node; // No change necessary.
184 case IrOpcode::kInt32Constant:
185 if (output_type->Is(Type::Signed32())) {
186 int32_t value = OpParameter<int32_t>(node);
187 return jsgraph()->Constant(value);
188 } else if (output_type->Is(Type::Unsigned32())) {
189 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node));
190 return jsgraph()->Constant(static_cast<double>(value));
Ben Murdochf91f0612016-11-29 16:50:11 +0000191 } else if (output_type->Is(Type::Boolean())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000192 return OpParameter<int32_t>(node) == 0 ? jsgraph()->FalseConstant()
193 : jsgraph()->TrueConstant();
194 } else {
195 return TypeError(node, output_rep, output_type,
196 MachineRepresentation::kTagged);
197 }
198 case IrOpcode::kFloat64Constant:
199 return jsgraph()->Constant(OpParameter<double>(node));
200 case IrOpcode::kFloat32Constant:
201 return jsgraph()->Constant(OpParameter<float>(node));
202 default:
203 break;
204 }
205 // Select the correct X -> Tagged operator.
206 const Operator* op;
Ben Murdochf91f0612016-11-29 16:50:11 +0000207 if (output_rep == MachineRepresentation::kNone) {
208 // We should only asisgn this representation if the type is empty.
209 CHECK(!output_type->IsInhabited());
210 op = machine()->ImpossibleToTagged();
211 } else if (output_rep == MachineRepresentation::kBit) {
212 if (output_type->Is(Type::Boolean())) {
213 op = simplified()->ChangeBitToTagged();
214 } else {
215 return TypeError(node, output_rep, output_type,
216 MachineRepresentation::kTagged);
217 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000218 } else if (IsWord(output_rep)) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100219 if (output_type->Is(Type::Signed31())) {
220 op = simplified()->ChangeInt31ToTaggedSigned();
Ben Murdoch014dc512016-03-22 12:00:34 +0000221 } else if (output_type->Is(Type::Signed32())) {
222 op = simplified()->ChangeInt32ToTagged();
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100223 } else if (output_type->Is(Type::Unsigned32())) {
224 op = simplified()->ChangeUint32ToTagged();
Ben Murdoch014dc512016-03-22 12:00:34 +0000225 } else {
226 return TypeError(node, output_rep, output_type,
227 MachineRepresentation::kTagged);
228 }
229 } else if (output_rep ==
230 MachineRepresentation::kFloat32) { // float32 -> float64 -> tagged
231 node = InsertChangeFloat32ToFloat64(node);
Ben Murdochf91f0612016-11-29 16:50:11 +0000232 op = simplified()->ChangeFloat64ToTagged(
233 output_type->Maybe(Type::MinusZero())
234 ? CheckForMinusZeroMode::kCheckForMinusZero
235 : CheckForMinusZeroMode::kDontCheckForMinusZero);
Ben Murdoch014dc512016-03-22 12:00:34 +0000236 } else if (output_rep == MachineRepresentation::kFloat64) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100237 if (output_type->Is(Type::Signed31())) { // float64 -> int32 -> tagged
238 node = InsertChangeFloat64ToInt32(node);
239 op = simplified()->ChangeInt31ToTaggedSigned();
240 } else if (output_type->Is(
241 Type::Signed32())) { // float64 -> int32 -> tagged
242 node = InsertChangeFloat64ToInt32(node);
243 op = simplified()->ChangeInt32ToTagged();
244 } else if (output_type->Is(
245 Type::Unsigned32())) { // float64 -> uint32 -> tagged
246 node = InsertChangeFloat64ToUint32(node);
247 op = simplified()->ChangeUint32ToTagged();
248 } else {
Ben Murdochf91f0612016-11-29 16:50:11 +0000249 op = simplified()->ChangeFloat64ToTagged(
250 output_type->Maybe(Type::MinusZero())
251 ? CheckForMinusZeroMode::kCheckForMinusZero
252 : CheckForMinusZeroMode::kDontCheckForMinusZero);
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100253 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000254 } else {
255 return TypeError(node, output_rep, output_type,
256 MachineRepresentation::kTagged);
257 }
258 return jsgraph()->graph()->NewNode(op, node);
259}
260
261
262Node* RepresentationChanger::GetFloat32RepresentationFor(
263 Node* node, MachineRepresentation output_rep, Type* output_type,
264 Truncation truncation) {
265 // Eagerly fold representation changes for constants.
266 switch (node->opcode()) {
267 case IrOpcode::kFloat64Constant:
268 case IrOpcode::kNumberConstant:
269 return jsgraph()->Float32Constant(
270 DoubleToFloat32(OpParameter<double>(node)));
271 case IrOpcode::kInt32Constant:
272 if (output_type->Is(Type::Unsigned32())) {
273 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node));
274 return jsgraph()->Float32Constant(static_cast<float>(value));
275 } else {
276 int32_t value = OpParameter<int32_t>(node);
277 return jsgraph()->Float32Constant(static_cast<float>(value));
278 }
279 case IrOpcode::kFloat32Constant:
280 return node; // No change necessary.
281 default:
282 break;
283 }
284 // Select the correct X -> Float32 operator.
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100285 const Operator* op = nullptr;
Ben Murdochf91f0612016-11-29 16:50:11 +0000286 if (output_rep == MachineRepresentation::kNone) {
287 // We should only use kNone representation if the type is empty.
288 CHECK(!output_type->IsInhabited());
289 op = machine()->ImpossibleToFloat32();
290 } else if (IsWord(output_rep)) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000291 if (output_type->Is(Type::Signed32())) {
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100292 // int32 -> float64 -> float32
Ben Murdoch014dc512016-03-22 12:00:34 +0000293 op = machine()->ChangeInt32ToFloat64();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100294 node = jsgraph()->graph()->NewNode(op, node);
295 op = machine()->TruncateFloat64ToFloat32();
296 } else if (output_type->Is(Type::Unsigned32()) ||
Ben Murdochf91f0612016-11-29 16:50:11 +0000297 truncation.IsUsedAsWord32()) {
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100298 // Either the output is uint32 or the uses only care about the
299 // low 32 bits (so we can pick uint32 safely).
300
301 // uint32 -> float64 -> float32
Ben Murdoch014dc512016-03-22 12:00:34 +0000302 op = machine()->ChangeUint32ToFloat64();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100303 node = jsgraph()->graph()->NewNode(op, node);
304 op = machine()->TruncateFloat64ToFloat32();
Ben Murdoch014dc512016-03-22 12:00:34 +0000305 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000306 } else if (output_rep == MachineRepresentation::kTagged) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000307 if (output_type->Is(Type::NumberOrOddball())) {
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100308 // tagged -> float64 -> float32
309 if (output_type->Is(Type::Number())) {
310 op = simplified()->ChangeTaggedToFloat64();
311 } else {
312 op = simplified()->TruncateTaggedToFloat64();
313 }
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100314 node = jsgraph()->graph()->NewNode(op, node);
315 op = machine()->TruncateFloat64ToFloat32();
316 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000317 } else if (output_rep == MachineRepresentation::kFloat64) {
318 op = machine()->TruncateFloat64ToFloat32();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100319 }
320 if (op == nullptr) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000321 return TypeError(node, output_rep, output_type,
322 MachineRepresentation::kFloat32);
323 }
324 return jsgraph()->graph()->NewNode(op, node);
325}
326
Ben Murdoch014dc512016-03-22 12:00:34 +0000327Node* RepresentationChanger::GetFloat64RepresentationFor(
328 Node* node, MachineRepresentation output_rep, Type* output_type,
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100329 Node* use_node, UseInfo use_info) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000330 // Eagerly fold representation changes for constants.
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100331 if ((use_info.type_check() == TypeCheckKind::kNone)) {
332 // TODO(jarin) Handle checked constant conversions.
333 switch (node->opcode()) {
334 case IrOpcode::kNumberConstant:
335 return jsgraph()->Float64Constant(OpParameter<double>(node));
336 case IrOpcode::kInt32Constant:
337 if (output_type->Is(Type::Signed32())) {
338 int32_t value = OpParameter<int32_t>(node);
339 return jsgraph()->Float64Constant(value);
340 } else {
341 DCHECK(output_type->Is(Type::Unsigned32()));
342 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node));
343 return jsgraph()->Float64Constant(static_cast<double>(value));
344 }
345 case IrOpcode::kFloat64Constant:
346 return node; // No change necessary.
347 case IrOpcode::kFloat32Constant:
348 return jsgraph()->Float64Constant(OpParameter<float>(node));
349 default:
350 break;
351 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000352 }
353 // Select the correct X -> Float64 operator.
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100354 const Operator* op = nullptr;
Ben Murdochf91f0612016-11-29 16:50:11 +0000355 if (output_rep == MachineRepresentation::kNone) {
356 // We should only use kNone representation if the type is empty.
357 CHECK(!output_type->IsInhabited());
358 op = machine()->ImpossibleToFloat64();
359 } else if (IsWord(output_rep)) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000360 if (output_type->Is(Type::Signed32())) {
361 op = machine()->ChangeInt32ToFloat64();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100362 } else if (output_type->Is(Type::Unsigned32()) ||
Ben Murdochf91f0612016-11-29 16:50:11 +0000363 use_info.truncation().IsUsedAsWord32()) {
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100364 // Either the output is uint32 or the uses only care about the
365 // low 32 bits (so we can pick uint32 safely).
Ben Murdoch014dc512016-03-22 12:00:34 +0000366 op = machine()->ChangeUint32ToFloat64();
367 }
Ben Murdochf91f0612016-11-29 16:50:11 +0000368 } else if (output_rep == MachineRepresentation::kBit) {
369 op = machine()->ChangeUint32ToFloat64();
Ben Murdoch014dc512016-03-22 12:00:34 +0000370 } else if (output_rep == MachineRepresentation::kTagged) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100371 if (output_type->Is(Type::Undefined())) {
372 return jsgraph()->Float64Constant(
373 std::numeric_limits<double>::quiet_NaN());
374 } else if (output_type->Is(Type::TaggedSigned())) {
375 node = InsertChangeTaggedSignedToInt32(node);
376 op = machine()->ChangeInt32ToFloat64();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100377 } else if (output_type->Is(Type::Number())) {
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100378 op = simplified()->ChangeTaggedToFloat64();
Ben Murdochf91f0612016-11-29 16:50:11 +0000379 } else if (output_type->Is(Type::NumberOrOddball())) {
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100380 // TODO(jarin) Here we should check that truncation is Number.
381 op = simplified()->TruncateTaggedToFloat64();
Ben Murdochf91f0612016-11-29 16:50:11 +0000382 } else if (use_info.type_check() == TypeCheckKind::kNumber ||
383 (use_info.type_check() == TypeCheckKind::kNumberOrOddball &&
384 !output_type->Maybe(Type::BooleanOrNullOrNumber()))) {
385 op = simplified()->CheckedTaggedToFloat64(CheckTaggedInputMode::kNumber);
386 } else if (use_info.type_check() == TypeCheckKind::kNumberOrOddball) {
387 op = simplified()->CheckedTaggedToFloat64(
388 CheckTaggedInputMode::kNumberOrOddball);
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100389 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000390 } else if (output_rep == MachineRepresentation::kFloat32) {
391 op = machine()->ChangeFloat32ToFloat64();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100392 }
393 if (op == nullptr) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000394 return TypeError(node, output_rep, output_type,
395 MachineRepresentation::kFloat64);
396 }
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100397 return InsertConversion(node, op, use_node);
Ben Murdoch014dc512016-03-22 12:00:34 +0000398}
399
Ben Murdoch014dc512016-03-22 12:00:34 +0000400Node* RepresentationChanger::MakeTruncatedInt32Constant(double value) {
401 return jsgraph()->Int32Constant(DoubleToInt32(value));
402}
403
Ben Murdoch014dc512016-03-22 12:00:34 +0000404Node* RepresentationChanger::GetWord32RepresentationFor(
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100405 Node* node, MachineRepresentation output_rep, Type* output_type,
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100406 Node* use_node, UseInfo use_info) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000407 // Eagerly fold representation changes for constants.
408 switch (node->opcode()) {
409 case IrOpcode::kInt32Constant:
410 return node; // No change necessary.
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100411 case IrOpcode::kFloat32Constant: {
412 float const fv = OpParameter<float>(node);
413 if (use_info.type_check() == TypeCheckKind::kNone ||
Ben Murdochf91f0612016-11-29 16:50:11 +0000414 ((use_info.type_check() == TypeCheckKind::kSignedSmall ||
415 use_info.type_check() == TypeCheckKind::kSigned32) &&
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100416 IsInt32Double(fv))) {
417 return MakeTruncatedInt32Constant(fv);
418 }
419 break;
420 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000421 case IrOpcode::kNumberConstant:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100422 case IrOpcode::kFloat64Constant: {
423 double const fv = OpParameter<double>(node);
424 if (use_info.type_check() == TypeCheckKind::kNone ||
Ben Murdochf91f0612016-11-29 16:50:11 +0000425 ((use_info.type_check() == TypeCheckKind::kSignedSmall ||
426 use_info.type_check() == TypeCheckKind::kSigned32) &&
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100427 IsInt32Double(fv))) {
428 return MakeTruncatedInt32Constant(fv);
429 }
430 break;
431 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000432 default:
433 break;
434 }
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100435
Ben Murdoch014dc512016-03-22 12:00:34 +0000436 // Select the correct X -> Word32 operator.
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100437 const Operator* op = nullptr;
Ben Murdochf91f0612016-11-29 16:50:11 +0000438 if (output_rep == MachineRepresentation::kNone) {
439 // We should only use kNone representation if the type is empty.
440 CHECK(!output_type->IsInhabited());
441 op = machine()->ImpossibleToWord32();
442 } else if (output_rep == MachineRepresentation::kBit) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000443 return node; // Sloppy comparison -> word32
444 } else if (output_rep == MachineRepresentation::kFloat64) {
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100445 if (output_type->Is(Type::Unsigned32())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000446 op = machine()->ChangeFloat64ToUint32();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100447 } else if (output_type->Is(Type::Signed32())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000448 op = machine()->ChangeFloat64ToInt32();
Ben Murdochf91f0612016-11-29 16:50:11 +0000449 } else if (use_info.truncation().IsUsedAsWord32()) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100450 op = machine()->TruncateFloat64ToWord32();
Ben Murdochf91f0612016-11-29 16:50:11 +0000451 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
452 use_info.type_check() == TypeCheckKind::kSigned32) {
453 op = simplified()->CheckedFloat64ToInt32(
454 output_type->Maybe(Type::MinusZero())
455 ? CheckForMinusZeroMode::kCheckForMinusZero
456 : CheckForMinusZeroMode::kDontCheckForMinusZero);
Ben Murdoch014dc512016-03-22 12:00:34 +0000457 }
458 } else if (output_rep == MachineRepresentation::kFloat32) {
459 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100460 if (output_type->Is(Type::Unsigned32())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000461 op = machine()->ChangeFloat64ToUint32();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100462 } else if (output_type->Is(Type::Signed32())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000463 op = machine()->ChangeFloat64ToInt32();
Ben Murdochf91f0612016-11-29 16:50:11 +0000464 } else if (use_info.truncation().IsUsedAsWord32()) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100465 op = machine()->TruncateFloat64ToWord32();
Ben Murdochf91f0612016-11-29 16:50:11 +0000466 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
467 use_info.type_check() == TypeCheckKind::kSigned32) {
468 op = simplified()->CheckedFloat64ToInt32(
469 output_type->Maybe(Type::MinusZero())
470 ? CheckForMinusZeroMode::kCheckForMinusZero
471 : CheckForMinusZeroMode::kDontCheckForMinusZero);
Ben Murdoch014dc512016-03-22 12:00:34 +0000472 }
473 } else if (output_rep == MachineRepresentation::kTagged) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100474 if (output_type->Is(Type::TaggedSigned())) {
475 op = simplified()->ChangeTaggedSignedToInt32();
476 } else if (output_type->Is(Type::Unsigned32())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000477 op = simplified()->ChangeTaggedToUint32();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100478 } else if (output_type->Is(Type::Signed32())) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000479 op = simplified()->ChangeTaggedToInt32();
Ben Murdochf91f0612016-11-29 16:50:11 +0000480 } else if (use_info.truncation().IsUsedAsWord32()) {
481 if (use_info.type_check() != TypeCheckKind::kNone) {
482 op = simplified()->CheckedTruncateTaggedToWord32();
483 } else {
484 op = simplified()->TruncateTaggedToWord32();
485 }
486 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
487 op = simplified()->CheckedTaggedSignedToInt32();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100488 } else if (use_info.type_check() == TypeCheckKind::kSigned32) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000489 op = simplified()->CheckedTaggedToInt32(
490 output_type->Maybe(Type::MinusZero())
491 ? CheckForMinusZeroMode::kCheckForMinusZero
492 : CheckForMinusZeroMode::kDontCheckForMinusZero);
Ben Murdoch014dc512016-03-22 12:00:34 +0000493 }
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100494 } else if (output_rep == MachineRepresentation::kWord32) {
495 // Only the checked case should get here, the non-checked case is
496 // handled in GetRepresentationFor.
Ben Murdochf91f0612016-11-29 16:50:11 +0000497 if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
498 use_info.type_check() == TypeCheckKind::kSigned32) {
499 if (output_type->Is(Type::Signed32())) {
500 return node;
501 } else if (output_type->Is(Type::Unsigned32())) {
502 op = simplified()->CheckedUint32ToInt32();
503 }
504 } else {
505 DCHECK_EQ(TypeCheckKind::kNumberOrOddball, use_info.type_check());
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100506 return node;
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100507 }
508 } else if (output_rep == MachineRepresentation::kWord8 ||
509 output_rep == MachineRepresentation::kWord16) {
510 DCHECK(use_info.representation() == MachineRepresentation::kWord32);
Ben Murdochf91f0612016-11-29 16:50:11 +0000511 DCHECK(use_info.type_check() == TypeCheckKind::kSignedSmall ||
512 use_info.type_check() == TypeCheckKind::kSigned32);
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100513 return node;
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100514 }
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100515
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100516 if (op == nullptr) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000517 return TypeError(node, output_rep, output_type,
518 MachineRepresentation::kWord32);
519 }
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100520 return InsertConversion(node, op, use_node);
521}
522
523Node* RepresentationChanger::InsertConversion(Node* node, const Operator* op,
524 Node* use_node) {
525 if (op->ControlInputCount() > 0) {
526 // If the operator can deoptimize (which means it has control
527 // input), we need to connect it to the effect and control chains.
528 Node* effect = NodeProperties::GetEffectInput(use_node);
529 Node* control = NodeProperties::GetControlInput(use_node);
530 Node* conversion = jsgraph()->graph()->NewNode(op, node, effect, control);
531 NodeProperties::ReplaceEffectInput(use_node, conversion);
532 return conversion;
533 }
Ben Murdoch014dc512016-03-22 12:00:34 +0000534 return jsgraph()->graph()->NewNode(op, node);
535}
536
537
538Node* RepresentationChanger::GetBitRepresentationFor(
539 Node* node, MachineRepresentation output_rep, Type* output_type) {
540 // Eagerly fold representation changes for constants.
541 switch (node->opcode()) {
542 case IrOpcode::kHeapConstant: {
543 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node);
544 DCHECK(value.is_identical_to(factory()->true_value()) ||
545 value.is_identical_to(factory()->false_value()));
546 return jsgraph()->Int32Constant(
547 value.is_identical_to(factory()->true_value()) ? 1 : 0);
548 }
549 default:
550 break;
551 }
552 // Select the correct X -> Bit operator.
553 const Operator* op;
Ben Murdochf91f0612016-11-29 16:50:11 +0000554 if (output_rep == MachineRepresentation::kNone) {
555 // We should only use kNone representation if the type is empty.
556 CHECK(!output_type->IsInhabited());
557 op = machine()->ImpossibleToBit();
558 } else if (output_rep == MachineRepresentation::kTagged) {
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100559 op = simplified()->ChangeTaggedToBit();
Ben Murdoch014dc512016-03-22 12:00:34 +0000560 } else {
561 return TypeError(node, output_rep, output_type,
562 MachineRepresentation::kBit);
563 }
564 return jsgraph()->graph()->NewNode(op, node);
565}
566
Ben Murdoch014dc512016-03-22 12:00:34 +0000567Node* RepresentationChanger::GetWord64RepresentationFor(
568 Node* node, MachineRepresentation output_rep, Type* output_type) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000569 if (output_rep == MachineRepresentation::kNone) {
570 // We should only use kNone representation if the type is empty.
571 CHECK(!output_type->IsInhabited());
572 return jsgraph()->graph()->NewNode(machine()->ImpossibleToFloat64(), node);
573 } else if (output_rep == MachineRepresentation::kBit) {
Ben Murdoch014dc512016-03-22 12:00:34 +0000574 return node; // Sloppy comparison -> word64
575 }
576 // Can't really convert Word64 to anything else. Purported to be internal.
577 return TypeError(node, output_rep, output_type,
578 MachineRepresentation::kWord64);
579}
580
Ben Murdoch014dc512016-03-22 12:00:34 +0000581const Operator* RepresentationChanger::Int32OperatorFor(
582 IrOpcode::Value opcode) {
583 switch (opcode) {
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100584 case IrOpcode::kSpeculativeNumberAdd: // Fall through.
Ben Murdoch014dc512016-03-22 12:00:34 +0000585 case IrOpcode::kNumberAdd:
586 return machine()->Int32Add();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100587 case IrOpcode::kSpeculativeNumberSubtract: // Fall through.
Ben Murdoch014dc512016-03-22 12:00:34 +0000588 case IrOpcode::kNumberSubtract:
589 return machine()->Int32Sub();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100590 case IrOpcode::kSpeculativeNumberMultiply:
Ben Murdoch014dc512016-03-22 12:00:34 +0000591 case IrOpcode::kNumberMultiply:
592 return machine()->Int32Mul();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100593 case IrOpcode::kSpeculativeNumberDivide:
Ben Murdoch014dc512016-03-22 12:00:34 +0000594 case IrOpcode::kNumberDivide:
595 return machine()->Int32Div();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100596 case IrOpcode::kSpeculativeNumberModulus:
Ben Murdoch014dc512016-03-22 12:00:34 +0000597 case IrOpcode::kNumberModulus:
598 return machine()->Int32Mod();
Ben Murdochf91f0612016-11-29 16:50:11 +0000599 case IrOpcode::kSpeculativeNumberBitwiseOr: // Fall through.
Ben Murdoch014dc512016-03-22 12:00:34 +0000600 case IrOpcode::kNumberBitwiseOr:
601 return machine()->Word32Or();
Ben Murdochf91f0612016-11-29 16:50:11 +0000602 case IrOpcode::kSpeculativeNumberBitwiseXor: // Fall through.
Ben Murdoch014dc512016-03-22 12:00:34 +0000603 case IrOpcode::kNumberBitwiseXor:
604 return machine()->Word32Xor();
Ben Murdochf91f0612016-11-29 16:50:11 +0000605 case IrOpcode::kSpeculativeNumberBitwiseAnd: // Fall through.
Ben Murdoch014dc512016-03-22 12:00:34 +0000606 case IrOpcode::kNumberBitwiseAnd:
607 return machine()->Word32And();
608 case IrOpcode::kNumberEqual:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100609 case IrOpcode::kSpeculativeNumberEqual:
Ben Murdoch014dc512016-03-22 12:00:34 +0000610 return machine()->Word32Equal();
611 case IrOpcode::kNumberLessThan:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100612 case IrOpcode::kSpeculativeNumberLessThan:
Ben Murdoch014dc512016-03-22 12:00:34 +0000613 return machine()->Int32LessThan();
614 case IrOpcode::kNumberLessThanOrEqual:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100615 case IrOpcode::kSpeculativeNumberLessThanOrEqual:
Ben Murdoch014dc512016-03-22 12:00:34 +0000616 return machine()->Int32LessThanOrEqual();
617 default:
618 UNREACHABLE();
619 return nullptr;
620 }
621}
622
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100623const Operator* RepresentationChanger::Int32OverflowOperatorFor(
624 IrOpcode::Value opcode) {
625 switch (opcode) {
Ben Murdochf91f0612016-11-29 16:50:11 +0000626 case IrOpcode::kSpeculativeNumberAdd:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100627 return simplified()->CheckedInt32Add();
Ben Murdochf91f0612016-11-29 16:50:11 +0000628 case IrOpcode::kSpeculativeNumberSubtract:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100629 return simplified()->CheckedInt32Sub();
Ben Murdochf91f0612016-11-29 16:50:11 +0000630 case IrOpcode::kSpeculativeNumberDivide:
631 return simplified()->CheckedInt32Div();
632 case IrOpcode::kSpeculativeNumberModulus:
633 return simplified()->CheckedInt32Mod();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100634 default:
635 UNREACHABLE();
636 return nullptr;
637 }
638}
Ben Murdoch014dc512016-03-22 12:00:34 +0000639
640const Operator* RepresentationChanger::Uint32OperatorFor(
641 IrOpcode::Value opcode) {
642 switch (opcode) {
643 case IrOpcode::kNumberAdd:
644 return machine()->Int32Add();
645 case IrOpcode::kNumberSubtract:
646 return machine()->Int32Sub();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100647 case IrOpcode::kSpeculativeNumberMultiply:
Ben Murdoch014dc512016-03-22 12:00:34 +0000648 case IrOpcode::kNumberMultiply:
649 return machine()->Int32Mul();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100650 case IrOpcode::kSpeculativeNumberDivide:
Ben Murdoch014dc512016-03-22 12:00:34 +0000651 case IrOpcode::kNumberDivide:
652 return machine()->Uint32Div();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100653 case IrOpcode::kSpeculativeNumberModulus:
Ben Murdoch014dc512016-03-22 12:00:34 +0000654 case IrOpcode::kNumberModulus:
655 return machine()->Uint32Mod();
656 case IrOpcode::kNumberEqual:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100657 case IrOpcode::kSpeculativeNumberEqual:
Ben Murdoch014dc512016-03-22 12:00:34 +0000658 return machine()->Word32Equal();
659 case IrOpcode::kNumberLessThan:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100660 case IrOpcode::kSpeculativeNumberLessThan:
Ben Murdoch014dc512016-03-22 12:00:34 +0000661 return machine()->Uint32LessThan();
662 case IrOpcode::kNumberLessThanOrEqual:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100663 case IrOpcode::kSpeculativeNumberLessThanOrEqual:
Ben Murdoch014dc512016-03-22 12:00:34 +0000664 return machine()->Uint32LessThanOrEqual();
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100665 case IrOpcode::kNumberClz32:
666 return machine()->Word32Clz();
667 case IrOpcode::kNumberImul:
668 return machine()->Int32Mul();
Ben Murdoch014dc512016-03-22 12:00:34 +0000669 default:
670 UNREACHABLE();
671 return nullptr;
672 }
673}
674
Ben Murdochf91f0612016-11-29 16:50:11 +0000675const Operator* RepresentationChanger::Uint32OverflowOperatorFor(
676 IrOpcode::Value opcode) {
677 switch (opcode) {
678 case IrOpcode::kSpeculativeNumberDivide:
679 return simplified()->CheckedUint32Div();
680 case IrOpcode::kSpeculativeNumberModulus:
681 return simplified()->CheckedUint32Mod();
682 default:
683 UNREACHABLE();
684 return nullptr;
685 }
686}
Ben Murdoch014dc512016-03-22 12:00:34 +0000687
688const Operator* RepresentationChanger::Float64OperatorFor(
689 IrOpcode::Value opcode) {
690 switch (opcode) {
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100691 case IrOpcode::kSpeculativeNumberAdd:
Ben Murdoch014dc512016-03-22 12:00:34 +0000692 case IrOpcode::kNumberAdd:
693 return machine()->Float64Add();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100694 case IrOpcode::kSpeculativeNumberSubtract:
Ben Murdoch014dc512016-03-22 12:00:34 +0000695 case IrOpcode::kNumberSubtract:
696 return machine()->Float64Sub();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100697 case IrOpcode::kSpeculativeNumberMultiply:
Ben Murdoch014dc512016-03-22 12:00:34 +0000698 case IrOpcode::kNumberMultiply:
699 return machine()->Float64Mul();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100700 case IrOpcode::kSpeculativeNumberDivide:
Ben Murdoch014dc512016-03-22 12:00:34 +0000701 case IrOpcode::kNumberDivide:
702 return machine()->Float64Div();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100703 case IrOpcode::kSpeculativeNumberModulus:
Ben Murdoch014dc512016-03-22 12:00:34 +0000704 case IrOpcode::kNumberModulus:
705 return machine()->Float64Mod();
706 case IrOpcode::kNumberEqual:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100707 case IrOpcode::kSpeculativeNumberEqual:
Ben Murdoch014dc512016-03-22 12:00:34 +0000708 return machine()->Float64Equal();
709 case IrOpcode::kNumberLessThan:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100710 case IrOpcode::kSpeculativeNumberLessThan:
Ben Murdoch014dc512016-03-22 12:00:34 +0000711 return machine()->Float64LessThan();
712 case IrOpcode::kNumberLessThanOrEqual:
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100713 case IrOpcode::kSpeculativeNumberLessThanOrEqual:
Ben Murdoch014dc512016-03-22 12:00:34 +0000714 return machine()->Float64LessThanOrEqual();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100715 case IrOpcode::kNumberAbs:
716 return machine()->Float64Abs();
Ben Murdochf91f0612016-11-29 16:50:11 +0000717 case IrOpcode::kNumberAcos:
718 return machine()->Float64Acos();
719 case IrOpcode::kNumberAcosh:
720 return machine()->Float64Acosh();
721 case IrOpcode::kNumberAsin:
722 return machine()->Float64Asin();
723 case IrOpcode::kNumberAsinh:
724 return machine()->Float64Asinh();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100725 case IrOpcode::kNumberAtan:
726 return machine()->Float64Atan();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100727 case IrOpcode::kNumberAtanh:
728 return machine()->Float64Atanh();
Ben Murdochf91f0612016-11-29 16:50:11 +0000729 case IrOpcode::kNumberAtan2:
730 return machine()->Float64Atan2();
731 case IrOpcode::kNumberCbrt:
732 return machine()->Float64Cbrt();
733 case IrOpcode::kNumberCeil:
734 return machine()->Float64RoundUp().placeholder();
735 case IrOpcode::kNumberCos:
736 return machine()->Float64Cos();
737 case IrOpcode::kNumberCosh:
738 return machine()->Float64Cosh();
739 case IrOpcode::kNumberExp:
740 return machine()->Float64Exp();
741 case IrOpcode::kNumberExpm1:
742 return machine()->Float64Expm1();
743 case IrOpcode::kNumberFloor:
744 return machine()->Float64RoundDown().placeholder();
745 case IrOpcode::kNumberFround:
746 return machine()->TruncateFloat64ToFloat32();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100747 case IrOpcode::kNumberLog:
748 return machine()->Float64Log();
749 case IrOpcode::kNumberLog1p:
750 return machine()->Float64Log1p();
751 case IrOpcode::kNumberLog2:
752 return machine()->Float64Log2();
753 case IrOpcode::kNumberLog10:
754 return machine()->Float64Log10();
Ben Murdochf91f0612016-11-29 16:50:11 +0000755 case IrOpcode::kNumberMax:
756 return machine()->Float64Max();
757 case IrOpcode::kNumberMin:
758 return machine()->Float64Min();
759 case IrOpcode::kNumberPow:
760 return machine()->Float64Pow();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100761 case IrOpcode::kNumberSin:
762 return machine()->Float64Sin();
Ben Murdochf91f0612016-11-29 16:50:11 +0000763 case IrOpcode::kNumberSinh:
764 return machine()->Float64Sinh();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100765 case IrOpcode::kNumberSqrt:
766 return machine()->Float64Sqrt();
Ben Murdochf91f0612016-11-29 16:50:11 +0000767 case IrOpcode::kNumberTan:
768 return machine()->Float64Tan();
769 case IrOpcode::kNumberTanh:
770 return machine()->Float64Tanh();
771 case IrOpcode::kNumberTrunc:
772 return machine()->Float64RoundTruncate().placeholder();
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100773 case IrOpcode::kNumberSilenceNaN:
774 return machine()->Float64SilenceNaN();
Ben Murdoch014dc512016-03-22 12:00:34 +0000775 default:
776 UNREACHABLE();
777 return nullptr;
778 }
779}
780
781
782Node* RepresentationChanger::TypeError(Node* node,
783 MachineRepresentation output_rep,
784 Type* output_type,
785 MachineRepresentation use) {
786 type_error_ = true;
787 if (!testing_type_errors_) {
788 std::ostringstream out_str;
789 out_str << output_rep << " (";
790 output_type->PrintTo(out_str, Type::SEMANTIC_DIM);
791 out_str << ")";
792
793 std::ostringstream use_str;
794 use_str << use;
795
796 V8_Fatal(__FILE__, __LINE__,
797 "RepresentationChangerError: node #%d:%s of "
798 "%s cannot be changed to %s",
799 node->id(), node->op()->mnemonic(), out_str.str().c_str(),
800 use_str.str().c_str());
801 }
802 return node;
803}
804
805
806Node* RepresentationChanger::InsertChangeFloat32ToFloat64(Node* node) {
807 return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), node);
808}
809
Ben Murdochbcf72ee2016-08-08 18:44:38 +0100810Node* RepresentationChanger::InsertChangeFloat64ToUint32(Node* node) {
811 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToUint32(), node);
812}
813
814Node* RepresentationChanger::InsertChangeFloat64ToInt32(Node* node) {
815 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToInt32(), node);
816}
817
818Node* RepresentationChanger::InsertChangeTaggedSignedToInt32(Node* node) {
819 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedSignedToInt32(),
820 node);
821}
Ben Murdoch014dc512016-03-22 12:00:34 +0000822
823Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) {
824 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
825 node);
826}
827
828} // namespace compiler
829} // namespace internal
830} // namespace v8