Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include "src/crankshaft/hydrogen-types.h"
6 :
7 : #include "src/field-type.h"
8 : #include "src/handles-inl.h"
9 : #include "src/objects-inl.h"
10 : #include "src/ostreams.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : // static
16 34878 : HType HType::FromType(AstType* type) {
17 34878 : if (AstType::Any()->Is(type)) return HType::Any();
18 34022 : if (!type->IsInhabited()) return HType::None();
19 32310 : if (type->Is(AstType::SignedSmall())) return HType::Smi();
20 30384 : if (type->Is(AstType::Number())) return HType::TaggedNumber();
21 27816 : if (type->Is(AstType::Null())) return HType::Null();
22 27602 : if (type->Is(AstType::String())) return HType::String();
23 26960 : if (type->Is(AstType::Boolean())) return HType::Boolean();
24 26746 : if (type->Is(AstType::Undefined())) return HType::Undefined();
25 26532 : if (type->Is(AstType::Object())) return HType::JSObject();
26 11770 : if (type->Is(AstType::DetectableReceiver())) return HType::JSReceiver();
27 : return HType::Tagged();
28 : }
29 :
30 :
31 : // static
32 11980 : HType HType::FromFieldType(Handle<FieldType> type, Zone* temp_zone) {
33 11980 : return FromType(type->Convert(temp_zone));
34 : }
35 :
36 : // static
37 4622177 : HType HType::FromValue(Handle<Object> value) {
38 : Object* raw_value = *value;
39 4622177 : if (raw_value->IsSmi()) return HType::Smi();
40 : DCHECK(raw_value->IsHeapObject());
41 : Isolate* isolate = HeapObject::cast(*value)->GetIsolate();
42 4080982 : if (raw_value->IsNull(isolate)) return HType::Null();
43 4073400 : if (raw_value->IsHeapNumber()) {
44 : double n = Handle<v8::internal::HeapNumber>::cast(value)->value();
45 55916 : return IsSmiDouble(n) ? HType::Smi() : HType::HeapNumber();
46 : }
47 4017484 : if (raw_value->IsString()) return HType::String();
48 3284392 : if (raw_value->IsBoolean()) return HType::Boolean();
49 3073918 : if (raw_value->IsUndefined(isolate)) return HType::Undefined();
50 3037357 : if (raw_value->IsJSArray()) {
51 : DCHECK(!raw_value->IsUndetectable());
52 : return HType::JSArray();
53 : }
54 3805659 : if (raw_value->IsJSObject() && !raw_value->IsUndetectable()) {
55 : return HType::JSObject();
56 : }
57 : return HType::HeapObject();
58 : }
59 :
60 :
61 0 : std::ostream& operator<<(std::ostream& os, const HType& t) {
62 : // Note: The c1visualizer syntax for locals allows only a sequence of the
63 : // following characters: A-Za-z0-9_-|:
64 0 : switch (t.kind_) {
65 : #define DEFINE_CASE(Name, mask) \
66 : case HType::k##Name: \
67 : return os << #Name;
68 0 : HTYPE_LIST(DEFINE_CASE)
69 : #undef DEFINE_CASE
70 : }
71 0 : UNREACHABLE();
72 : return os;
73 : }
74 :
75 : } // namespace internal
76 : } // namespace v8
|