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/compiler/js-graph.h"
6 :
7 : #include "src/code-factory.h"
8 : #include "src/compiler/node-properties.h"
9 : #include "src/compiler/typer.h"
10 : #include "src/objects-inl.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 : namespace compiler {
15 :
16 : #define GET_CACHED_FIELD(ptr, expr) (*(ptr)) ? *(ptr) : (*(ptr) = (expr))
17 :
18 : #define DEFINE_GETTER(name, expr) \
19 : Node* JSGraph::name() { return GET_CACHED_FIELD(&name##_, expr); }
20 :
21 882305 : Node* JSGraph::CEntryStubConstant(int result_size, SaveFPRegsMode save_doubles,
22 : ArgvMode argv_mode, bool builtin_exit_frame) {
23 882305 : if (save_doubles == kDontSaveFPRegs && argv_mode == kArgvOnStack) {
24 : DCHECK(result_size >= 1 && result_size <= 3);
25 882305 : if (!builtin_exit_frame) {
26 : Node** ptr = nullptr;
27 879347 : if (result_size == 1) {
28 878407 : ptr = &CEntryStub1Constant_;
29 940 : } else if (result_size == 2) {
30 940 : ptr = &CEntryStub2Constant_;
31 : } else {
32 : DCHECK_EQ(3, result_size);
33 0 : ptr = &CEntryStub3Constant_;
34 : }
35 1343706 : return GET_CACHED_FIELD(ptr, HeapConstant(CodeFactory::CEntry(
36 : isolate(), result_size, save_doubles,
37 : argv_mode, builtin_exit_frame)));
38 : }
39 : Node** ptr = builtin_exit_frame ? &CEntryStub1WithBuiltinExitFrameConstant_
40 2958 : : &CEntryStub1Constant_;
41 5260 : return GET_CACHED_FIELD(ptr, HeapConstant(CodeFactory::CEntry(
42 : isolate(), result_size, save_doubles,
43 : argv_mode, builtin_exit_frame)));
44 : }
45 0 : return HeapConstant(CodeFactory::CEntry(isolate(), result_size, save_doubles,
46 0 : argv_mode, builtin_exit_frame));
47 : }
48 :
49 893142 : Node* JSGraph::Constant(Handle<Object> value) {
50 : // Dereference the handle to determine if a number constant or other
51 : // canonicalized node can be used.
52 893142 : if (value->IsNumber()) {
53 81323 : return Constant(value->Number());
54 811819 : } else if (value->IsUndefined(isolate())) {
55 1535 : return UndefinedConstant();
56 810284 : } else if (value->IsTrue(isolate())) {
57 19 : return TrueConstant();
58 810265 : } else if (value->IsFalse(isolate())) {
59 85 : return FalseConstant();
60 810180 : } else if (value->IsNull(isolate())) {
61 90 : return NullConstant();
62 810090 : } else if (value->IsTheHole(isolate())) {
63 5 : return TheHoleConstant();
64 : } else {
65 810085 : return HeapConstant(Handle<HeapObject>::cast(value));
66 : }
67 : }
68 :
69 1015363 : Node* JSGraph::Constant(const ObjectRef& ref) {
70 1015363 : if (ref.IsSmi()) return Constant(ref.AsSmi());
71 : OddballType oddball_type =
72 1001645 : ref.AsHeapObject().GetHeapObjectType().oddball_type();
73 1001646 : if (ref.IsHeapNumber()) {
74 4435 : return Constant(ref.AsHeapNumber().value());
75 997211 : } else if (oddball_type == OddballType::kUndefined) {
76 : DCHECK(ref.object().equals(isolate()->factory()->undefined_value()));
77 2497 : return UndefinedConstant();
78 994714 : } else if (oddball_type == OddballType::kNull) {
79 : DCHECK(ref.object().equals(isolate()->factory()->null_value()));
80 197 : return NullConstant();
81 994517 : } else if (oddball_type == OddballType::kHole) {
82 : DCHECK(ref.object().equals(isolate()->factory()->the_hole_value()));
83 2509 : return TheHoleConstant();
84 992008 : } else if (oddball_type == OddballType::kBoolean) {
85 191549 : if (ref.object().equals(isolate()->factory()->true_value())) {
86 63896 : return TrueConstant();
87 : } else {
88 : DCHECK(ref.object().equals(isolate()->factory()->false_value()));
89 127653 : return FalseConstant();
90 : }
91 : } else {
92 800459 : return HeapConstant(ref.AsHeapObject().object());
93 : }
94 : }
95 :
96 3210815 : Node* JSGraph::Constant(double value) {
97 3912784 : if (bit_cast<int64_t>(value) == bit_cast<int64_t>(0.0)) return ZeroConstant();
98 2744541 : if (bit_cast<int64_t>(value) == bit_cast<int64_t>(1.0)) return OneConstant();
99 2273151 : return NumberConstant(value);
100 : }
101 :
102 3353815 : Node* JSGraph::NumberConstant(double value) {
103 : Node** loc = cache_.FindNumberConstant(value);
104 3353813 : if (*loc == nullptr) {
105 5240793 : *loc = graph()->NewNode(common()->NumberConstant(value));
106 : }
107 3353820 : return *loc;
108 : }
109 :
110 12968493 : Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
111 12968493 : Node** loc = cache_.FindHeapConstant(value);
112 12968471 : if (*loc == nullptr) {
113 14397487 : *loc = graph()->NewNode(common()->HeapConstant(value));
114 : }
115 12968504 : return *loc;
116 : }
117 :
118 4720452 : void JSGraph::GetCachedNodes(NodeVector* nodes) {
119 4720452 : cache_.GetCachedNodes(nodes);
120 : #define DO_CACHED_FIELD(name) \
121 : if (name##_) nodes->push_back(name##_);
122 :
123 4720465 : CACHED_GLOBAL_LIST(DO_CACHED_FIELD)
124 4720458 : CACHED_CENTRY_LIST(DO_CACHED_FIELD)
125 : #undef DO_CACHED_FIELD
126 4720461 : }
127 :
128 418508 : DEFINE_GETTER(AllocateInYoungGenerationStubConstant,
129 : HeapConstant(BUILTIN_CODE(isolate(), AllocateInYoungGeneration)))
130 :
131 1254 : DEFINE_GETTER(AllocateInOldGenerationStubConstant,
132 : HeapConstant(BUILTIN_CODE(isolate(), AllocateInOldGeneration)))
133 :
134 433 : DEFINE_GETTER(ArrayConstructorStubConstant,
135 : HeapConstant(BUILTIN_CODE(isolate(), ArrayConstructorImpl)))
136 :
137 72905 : DEFINE_GETTER(BigIntMapConstant, HeapConstant(factory()->bigint_map()))
138 :
139 122 : DEFINE_GETTER(BooleanMapConstant, HeapConstant(factory()->boolean_map()))
140 :
141 87 : DEFINE_GETTER(ToNumberBuiltinConstant,
142 : HeapConstant(BUILTIN_CODE(isolate(), ToNumber)))
143 :
144 158209 : DEFINE_GETTER(EmptyFixedArrayConstant,
145 : HeapConstant(factory()->empty_fixed_array()))
146 :
147 75990 : DEFINE_GETTER(EmptyStringConstant, HeapConstant(factory()->empty_string()))
148 :
149 3291 : DEFINE_GETTER(FixedArrayMapConstant, HeapConstant(factory()->fixed_array_map()))
150 :
151 2491 : DEFINE_GETTER(PropertyArrayMapConstant,
152 : HeapConstant(factory()->property_array_map()))
153 :
154 56 : DEFINE_GETTER(FixedDoubleArrayMapConstant,
155 : HeapConstant(factory()->fixed_double_array_map()))
156 :
157 245563 : DEFINE_GETTER(HeapNumberMapConstant, HeapConstant(factory()->heap_number_map()))
158 :
159 17506570 : DEFINE_GETTER(OptimizedOutConstant, HeapConstant(factory()->optimized_out()))
160 :
161 16475 : DEFINE_GETTER(StaleRegisterConstant, HeapConstant(factory()->stale_register()))
162 :
163 2208389 : DEFINE_GETTER(UndefinedConstant, HeapConstant(factory()->undefined_value()))
164 :
165 515543 : DEFINE_GETTER(TheHoleConstant, HeapConstant(factory()->the_hole_value()))
166 :
167 1505993 : DEFINE_GETTER(TrueConstant, HeapConstant(factory()->true_value()))
168 :
169 1592565 : DEFINE_GETTER(FalseConstant, HeapConstant(factory()->false_value()))
170 :
171 43584 : DEFINE_GETTER(NullConstant, HeapConstant(factory()->null_value()))
172 :
173 1828270 : DEFINE_GETTER(ZeroConstant, NumberConstant(0.0))
174 :
175 418248 : DEFINE_GETTER(OneConstant, NumberConstant(1.0))
176 :
177 281 : DEFINE_GETTER(MinusOneConstant, NumberConstant(-1.0))
178 :
179 1493 : DEFINE_GETTER(NaNConstant,
180 : NumberConstant(std::numeric_limits<double>::quiet_NaN()))
181 :
182 23107 : DEFINE_GETTER(EmptyStateValues,
183 : graph()->NewNode(common()->StateValues(0,
184 : SparseInputMask::Dense())))
185 :
186 5783226 : DEFINE_GETTER(SingleDeadTypedStateValues,
187 : graph()->NewNode(common()->TypedStateValues(
188 : new (graph()->zone()->New(sizeof(ZoneVector<MachineType>)))
189 : ZoneVector<MachineType>(0, graph()->zone()),
190 : SparseInputMask(SparseInputMask::kEndMarker << 1))))
191 :
192 : #undef DEFINE_GETTER
193 : #undef GET_CACHED_FIELD
194 :
195 : } // namespace compiler
196 : } // namespace internal
197 122036 : } // namespace v8
|