5 #ifndef V8_COMPILER_REPRESENTATION_CHANGE_H_ 6 #define V8_COMPILER_REPRESENTATION_CHANGE_H_ 8 #include "src/compiler/js-graph.h" 9 #include "src/compiler/simplified-operator.h" 18 enum IdentifyZeros { kIdentifyZeros, kDistinguishZeros };
24 return Truncation(TruncationKind::kNone, kIdentifyZeros);
27 return Truncation(TruncationKind::kBool, kIdentifyZeros);
30 return Truncation(TruncationKind::kWord32, kIdentifyZeros);
33 return Truncation(TruncationKind::kFloat64, identify_zeros);
35 static Truncation Any(IdentifyZeros identify_zeros = kDistinguishZeros) {
36 return Truncation(TruncationKind::kAny, identify_zeros);
41 Generalize(t1.kind(), t2.kind()),
42 GeneralizeIdentifyZeros(t1.identify_zeros(), t2.identify_zeros()));
46 bool IsUnused()
const {
return kind_ == TruncationKind::kNone; }
47 bool IsUsedAsBool()
const {
48 return LessGeneral(kind_, TruncationKind::kBool);
50 bool IsUsedAsWord32()
const {
51 return LessGeneral(kind_, TruncationKind::kWord32);
53 bool IsUsedAsFloat64()
const {
54 return LessGeneral(kind_, TruncationKind::kFloat64);
56 bool IdentifiesUndefinedAndZero() {
57 return LessGeneral(kind_, TruncationKind::kWord32) ||
58 LessGeneral(kind_, TruncationKind::kBool);
60 bool IdentifiesZeroAndMinusZero()
const {
61 return identify_zeros() == kIdentifyZeros;
66 return kind() == other.kind() && identify_zeros() == other.identify_zeros();
68 bool operator!=(
Truncation other)
const {
return !(*
this == other); }
71 const char* description()
const;
73 return LessGeneral(kind(), other.kind()) &&
74 LessGeneralIdentifyZeros(identify_zeros(), other.identify_zeros());
77 IdentifyZeros identify_zeros()
const {
return identify_zeros_; }
80 enum class TruncationKind : uint8_t {
88 explicit Truncation(TruncationKind kind, IdentifyZeros identify_zeros)
89 : kind_(kind), identify_zeros_(identify_zeros) {
90 DCHECK(kind == TruncationKind::kAny || kind == TruncationKind::kFloat64 ||
91 identify_zeros == kIdentifyZeros);
93 TruncationKind kind()
const {
return kind_; }
96 IdentifyZeros identify_zeros_;
98 static TruncationKind Generalize(TruncationKind rep1, TruncationKind rep2);
99 static IdentifyZeros GeneralizeIdentifyZeros(IdentifyZeros i1,
101 static bool LessGeneral(TruncationKind rep1, TruncationKind rep2);
102 static bool LessGeneralIdentifyZeros(IdentifyZeros u1, IdentifyZeros u2);
105 enum class TypeCheckKind : uint8_t {
115 inline std::ostream& operator<<(std::ostream& os, TypeCheckKind type_check) {
116 switch (type_check) {
117 case TypeCheckKind::kNone:
119 case TypeCheckKind::kSignedSmall:
120 return os <<
"SignedSmall";
121 case TypeCheckKind::kSigned32:
122 return os <<
"Signed32";
123 case TypeCheckKind::kSigned64:
124 return os <<
"Signed64";
125 case TypeCheckKind::kNumber:
126 return os <<
"Number";
127 case TypeCheckKind::kNumberOrOddball:
128 return os <<
"NumberOrOddball";
129 case TypeCheckKind::kHeapObject:
130 return os <<
"HeapObject";
154 TypeCheckKind type_check = TypeCheckKind::kNone,
156 : representation_(representation),
157 truncation_(truncation),
158 type_check_(type_check),
159 feedback_(feedback) {}
160 static UseInfo TruncatingWord32() {
161 return UseInfo(MachineRepresentation::kWord32, Truncation::Word32());
164 return UseInfo(MachineRepresentation::kWord64, Truncation::Any());
167 return UseInfo(MachineType::PointerRepresentation(), Truncation::Any());
170 return UseInfo(MachineRepresentation::kBit, Truncation::Bool());
173 return UseInfo(MachineRepresentation::kFloat32, Truncation::Any());
175 static UseInfo TruncatingFloat64(
176 IdentifyZeros identify_zeros = kDistinguishZeros) {
177 return UseInfo(MachineRepresentation::kFloat64,
178 Truncation::Float64(identify_zeros));
181 return UseInfo(MachineRepresentation::kTagged, Truncation::Any());
183 static UseInfo TaggedSigned() {
184 return UseInfo(MachineRepresentation::kTaggedSigned, Truncation::Any());
186 static UseInfo TaggedPointer() {
187 return UseInfo(MachineRepresentation::kTaggedPointer, Truncation::Any());
191 static UseInfo CheckedHeapObjectAsTaggedPointer() {
192 return UseInfo(MachineRepresentation::kTaggedPointer, Truncation::Any(),
193 TypeCheckKind::kHeapObject);
195 static UseInfo CheckedSignedSmallAsTaggedSigned(
197 IdentifyZeros identify_zeros = kDistinguishZeros) {
198 return UseInfo(MachineRepresentation::kTaggedSigned,
199 Truncation::Any(identify_zeros), TypeCheckKind::kSignedSmall,
202 static UseInfo CheckedSignedSmallAsWord32(IdentifyZeros identify_zeros,
204 return UseInfo(MachineRepresentation::kWord32,
205 Truncation::Any(identify_zeros), TypeCheckKind::kSignedSmall,
208 static UseInfo CheckedSigned32AsWord32(IdentifyZeros identify_zeros,
210 return UseInfo(MachineRepresentation::kWord32,
211 Truncation::Any(identify_zeros), TypeCheckKind::kSigned32,
214 static UseInfo CheckedSigned64AsWord64(IdentifyZeros identify_zeros,
216 return UseInfo(MachineRepresentation::kWord64,
217 Truncation::Any(identify_zeros), TypeCheckKind::kSigned64,
220 static UseInfo CheckedNumberAsFloat64(IdentifyZeros identify_zeros,
222 return UseInfo(MachineRepresentation::kFloat64,
223 Truncation::Any(identify_zeros), TypeCheckKind::kNumber,
227 return UseInfo(MachineRepresentation::kWord32, Truncation::Word32(),
228 TypeCheckKind::kNumber, feedback);
230 static UseInfo CheckedNumberOrOddballAsFloat64(
232 return UseInfo(MachineRepresentation::kFloat64,
233 Truncation::Any(identify_zeros),
234 TypeCheckKind::kNumberOrOddball, feedback);
236 static UseInfo CheckedNumberOrOddballAsWord32(
238 return UseInfo(MachineRepresentation::kWord32, Truncation::Word32(),
239 TypeCheckKind::kNumberOrOddball, feedback);
244 return UseInfo(MachineRepresentation::kNone, Truncation::Any());
246 static UseInfo AnyTruncatingToBool() {
247 return UseInfo(MachineRepresentation::kNone, Truncation::Bool());
252 return UseInfo(MachineRepresentation::kNone, Truncation::None());
255 MachineRepresentation representation()
const {
return representation_; }
256 Truncation truncation()
const {
return truncation_; }
257 TypeCheckKind type_check()
const {
return type_check_; }
258 CheckForMinusZeroMode minus_zero_check()
const {
259 return truncation().IdentifiesZeroAndMinusZero()
260 ? CheckForMinusZeroMode::kDontCheckForMinusZero
261 : CheckForMinusZeroMode::kCheckForMinusZero;
266 MachineRepresentation representation_;
268 TypeCheckKind type_check_;
283 Node* GetRepresentationFor(
Node* node, MachineRepresentation output_rep,
286 const Operator* Int32OperatorFor(IrOpcode::Value opcode);
287 const Operator* Int32OverflowOperatorFor(IrOpcode::Value opcode);
288 const Operator* Int64OperatorFor(IrOpcode::Value opcode);
289 const Operator* TaggedSignedOperatorFor(IrOpcode::Value opcode);
290 const Operator* Uint32OperatorFor(IrOpcode::Value opcode);
291 const Operator* Uint32OverflowOperatorFor(IrOpcode::Value opcode);
292 const Operator* Float64OperatorFor(IrOpcode::Value opcode);
295 return access.tag() != 0 ? MachineType::AnyTagged()
296 : MachineType::Pointer();
300 return access.tag() != 0 ? MachineType::AnyTagged()
301 : MachineType::Pointer();
309 friend class RepresentationChangerTester;
311 bool testing_type_errors_;
314 Node* GetTaggedSignedRepresentationFor(
Node* node,
315 MachineRepresentation output_rep,
318 Node* GetTaggedPointerRepresentationFor(
Node* node,
319 MachineRepresentation output_rep,
322 Node* GetTaggedRepresentationFor(
Node* node, MachineRepresentation output_rep,
324 Node* GetFloat32RepresentationFor(
Node* node,
325 MachineRepresentation output_rep,
327 Node* GetFloat64RepresentationFor(
Node* node,
328 MachineRepresentation output_rep,
331 Node* GetWord32RepresentationFor(
Node* node, MachineRepresentation output_rep,
334 Node* GetBitRepresentationFor(
Node* node, MachineRepresentation output_rep,
336 Node* GetWord64RepresentationFor(
Node* node, MachineRepresentation output_rep,
339 Node* TypeError(
Node* node, MachineRepresentation output_rep,
340 Type output_type, MachineRepresentation use);
341 Node* MakeTruncatedInt32Constant(
double value);
342 Node* InsertChangeBitToTagged(
Node* node);
343 Node* InsertChangeFloat32ToFloat64(
Node* node);
344 Node* InsertChangeFloat64ToInt32(
Node* node);
345 Node* InsertChangeFloat64ToUint32(
Node* node);
346 Node* InsertChangeInt32ToFloat64(
Node* node);
347 Node* InsertChangeTaggedSignedToInt32(
Node* node);
348 Node* InsertChangeTaggedToFloat64(
Node* node);
349 Node* InsertChangeUint32ToFloat64(
Node* node);
351 Node* InsertTruncateInt64ToInt32(
Node* node);
352 Node* InsertUnconditionalDeopt(
Node* node, DeoptimizeReason reason);
354 JSGraph* jsgraph()
const {
return jsgraph_; }
355 Isolate* isolate()
const {
return isolate_; }
356 Factory* factory()
const {
return isolate()->factory(); }
365 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_