| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // 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 | 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/representation-change.h" | 5 #include "src/compiler/representation-change.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
| 11 #include "src/compiler/machine-operator.h" | 11 #include "src/compiler/machine-operator.h" |
| 12 #include "src/compiler/node-matchers.h" | 12 #include "src/compiler/node-matchers.h" |
| 13 #include "src/objects-inl.h" | 13 #include "src/objects-inl.h" |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 namespace internal { | 16 namespace internal { |
| 17 namespace compiler { | 17 namespace compiler { |
| 18 | 18 |
| 19 const char* Truncation::description() const { | 19 const char* Truncation::description() const { |
| 20 switch (kind()) { | 20 switch (kind()) { |
| 21 case TruncationKind::kNone: | 21 case TruncationKind::kNone: |
| 22 return "no-value-use"; | 22 return "no-value-use"; |
| 23 case TruncationKind::kBool: | 23 case TruncationKind::kBool: |
| 24 return "truncate-to-bool"; | 24 return "truncate-to-bool"; |
| 25 case TruncationKind::kWord32: | 25 case TruncationKind::kWord32: |
| 26 return "truncate-to-word32"; | 26 return "truncate-to-word32"; |
| 27 case TruncationKind::kWord64: | 27 case TruncationKind::kWord64: |
| 28 return "truncate-to-word64"; | 28 return "truncate-to-word64"; |
| 29 case TruncationKind::kFloat64: | 29 case TruncationKind::kFloat64: |
| 30 return "truncate-to-float64"; | 30 switch (identify_zeros()) { |
| 31 case kIdentifyZeros: |
| 32 return "truncate-to-float64 (identify zeros)"; |
| 33 case kDistinguishZeros: |
| 34 return "truncate-to-float64 (distinguish zeros)"; |
| 35 } |
| 31 case TruncationKind::kAny: | 36 case TruncationKind::kAny: |
| 32 return "no-truncation"; | 37 switch (identify_zeros()) { |
| 38 case kIdentifyZeros: |
| 39 return "no-truncation (but identify zeros)"; |
| 40 case kDistinguishZeros: |
| 41 return "no-truncation (but distinguish zeros)"; |
| 42 } |
| 33 } | 43 } |
| 34 UNREACHABLE(); | 44 UNREACHABLE(); |
| 35 return nullptr; | 45 return nullptr; |
| 36 } | 46 } |
| 37 | 47 |
| 38 | 48 |
| 39 // Partial order for truncations: | 49 // Partial order for truncations: |
| 40 // | 50 // |
| 41 // kWord64 kAny | 51 // kWord64 kAny <-------+ |
| 42 // ^ ^ | 52 // ^ ^ | |
| 43 // \ | | 53 // \ | | |
| 44 // \ kFloat64 <--+ | 54 // \ kFloat64 | |
| 45 // \ ^ | | 55 // \ ^ | |
| 46 // \ / | | 56 // \ / | |
| 47 // kWord32 kBool | 57 // kWord32 kBool |
| 48 // ^ ^ | 58 // ^ ^ |
| 49 // \ / | 59 // \ / |
| 50 // \ / | 60 // \ / |
| 51 // \ / | 61 // \ / |
| 52 // \ / | 62 // \ / |
| 53 // \ / | 63 // \ / |
| 54 // kNone | 64 // kNone |
| 65 // |
| 66 // TODO(jarin) We might consider making kBool < kFloat64. |
| 55 | 67 |
| 56 // static | 68 // static |
| 57 Truncation::TruncationKind Truncation::Generalize(TruncationKind rep1, | 69 Truncation::TruncationKind Truncation::Generalize(TruncationKind rep1, |
| 58 TruncationKind rep2) { | 70 TruncationKind rep2) { |
| 59 if (LessGeneral(rep1, rep2)) return rep2; | 71 if (LessGeneral(rep1, rep2)) return rep2; |
| 60 if (LessGeneral(rep2, rep1)) return rep1; | 72 if (LessGeneral(rep2, rep1)) return rep1; |
| 61 // Handle the generalization of float64-representable values. | 73 // Handle the generalization of float64-representable values. |
| 62 if (LessGeneral(rep1, TruncationKind::kFloat64) && | 74 if (LessGeneral(rep1, TruncationKind::kFloat64) && |
| 63 LessGeneral(rep2, TruncationKind::kFloat64)) { | 75 LessGeneral(rep2, TruncationKind::kFloat64)) { |
| 64 return TruncationKind::kFloat64; | 76 return TruncationKind::kFloat64; |
| 65 } | 77 } |
| 66 // Handle the generalization of any-representable values. | 78 // Handle the generalization of any-representable values. |
| 67 if (LessGeneral(rep1, TruncationKind::kAny) && | 79 if (LessGeneral(rep1, TruncationKind::kAny) && |
| 68 LessGeneral(rep2, TruncationKind::kAny)) { | 80 LessGeneral(rep2, TruncationKind::kAny)) { |
| 69 return TruncationKind::kAny; | 81 return TruncationKind::kAny; |
| 70 } | 82 } |
| 71 // All other combinations are illegal. | 83 // All other combinations are illegal. |
| 72 FATAL("Tried to combine incompatible truncations"); | 84 FATAL("Tried to combine incompatible truncations"); |
| 73 return TruncationKind::kNone; | 85 return TruncationKind::kNone; |
| 74 } | 86 } |
| 75 | 87 |
| 88 // static |
| 89 IdentifyZeros Truncation::GeneralizeIdentifyZeros(IdentifyZeros i1, |
| 90 IdentifyZeros i2) { |
| 91 if (i1 == i2) { |
| 92 return i1; |
| 93 } else { |
| 94 return kDistinguishZeros; |
| 95 } |
| 96 } |
| 76 | 97 |
| 77 // static | 98 // static |
| 78 bool Truncation::LessGeneral(TruncationKind rep1, TruncationKind rep2) { | 99 bool Truncation::LessGeneral(TruncationKind rep1, TruncationKind rep2) { |
| 79 switch (rep1) { | 100 switch (rep1) { |
| 80 case TruncationKind::kNone: | 101 case TruncationKind::kNone: |
| 81 return true; | 102 return true; |
| 82 case TruncationKind::kBool: | 103 case TruncationKind::kBool: |
| 83 return rep2 == TruncationKind::kBool || rep2 == TruncationKind::kAny; | 104 return rep2 == TruncationKind::kBool || rep2 == TruncationKind::kAny; |
| 84 case TruncationKind::kWord32: | 105 case TruncationKind::kWord32: |
| 85 return rep2 == TruncationKind::kWord32 || | 106 return rep2 == TruncationKind::kWord32 || |
| 86 rep2 == TruncationKind::kWord64 || | 107 rep2 == TruncationKind::kWord64 || |
| 87 rep2 == TruncationKind::kFloat64 || rep2 == TruncationKind::kAny; | 108 rep2 == TruncationKind::kFloat64 || rep2 == TruncationKind::kAny; |
| 88 case TruncationKind::kWord64: | 109 case TruncationKind::kWord64: |
| 89 return rep2 == TruncationKind::kWord64; | 110 return rep2 == TruncationKind::kWord64; |
| 90 case TruncationKind::kFloat64: | 111 case TruncationKind::kFloat64: |
| 91 return rep2 == TruncationKind::kFloat64 || rep2 == TruncationKind::kAny; | 112 return rep2 == TruncationKind::kFloat64 || rep2 == TruncationKind::kAny; |
| 92 case TruncationKind::kAny: | 113 case TruncationKind::kAny: |
| 93 return rep2 == TruncationKind::kAny; | 114 return rep2 == TruncationKind::kAny; |
| 94 } | 115 } |
| 95 UNREACHABLE(); | 116 UNREACHABLE(); |
| 96 return false; | 117 return false; |
| 97 } | 118 } |
| 98 | 119 |
| 120 // static |
| 121 bool Truncation::LessGeneralIdentifyZeros(IdentifyZeros i1, IdentifyZeros i2) { |
| 122 return i1 == i2 || i1 == kIdentifyZeros; |
| 123 } |
| 99 | 124 |
| 100 namespace { | 125 namespace { |
| 101 | 126 |
| 102 bool IsWord(MachineRepresentation rep) { | 127 bool IsWord(MachineRepresentation rep) { |
| 103 return rep == MachineRepresentation::kWord8 || | 128 return rep == MachineRepresentation::kWord8 || |
| 104 rep == MachineRepresentation::kWord16 || | 129 rep == MachineRepresentation::kWord16 || |
| 105 rep == MachineRepresentation::kWord32; | 130 rep == MachineRepresentation::kWord32; |
| 106 } | 131 } |
| 107 | 132 |
| 108 } // namespace | 133 } // namespace |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 node); | 1070 node); |
| 1046 } | 1071 } |
| 1047 | 1072 |
| 1048 Node* RepresentationChanger::InsertChangeUint32ToFloat64(Node* node) { | 1073 Node* RepresentationChanger::InsertChangeUint32ToFloat64(Node* node) { |
| 1049 return jsgraph()->graph()->NewNode(machine()->ChangeUint32ToFloat64(), node); | 1074 return jsgraph()->graph()->NewNode(machine()->ChangeUint32ToFloat64(), node); |
| 1050 } | 1075 } |
| 1051 | 1076 |
| 1052 } // namespace compiler | 1077 } // namespace compiler |
| 1053 } // namespace internal | 1078 } // namespace internal |
| 1054 } // namespace v8 | 1079 } // namespace v8 |
| OLD | NEW |