Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include "src/compiler/graph-assembler.h"
6 :
7 : #include "src/code-factory.h"
8 : #include "src/compiler/linkage.h"
9 :
10 : namespace v8 {
11 : namespace internal {
12 : namespace compiler {
13 :
14 886712 : GraphAssembler::GraphAssembler(JSGraph* jsgraph, Node* effect, Node* control,
15 : Zone* zone)
16 : : temp_zone_(zone),
17 : jsgraph_(jsgraph),
18 : current_effect_(effect),
19 886712 : current_control_(control) {}
20 :
21 1718503 : Node* GraphAssembler::IntPtrConstant(intptr_t value) {
22 1718503 : return jsgraph()->IntPtrConstant(value);
23 : }
24 :
25 389556 : Node* GraphAssembler::Int32Constant(int32_t value) {
26 389556 : return jsgraph()->Int32Constant(value);
27 : }
28 :
29 235432 : Node* GraphAssembler::UniqueInt32Constant(int32_t value) {
30 235432 : return graph()->NewNode(common()->Int32Constant(value));
31 : }
32 :
33 31764 : Node* GraphAssembler::SmiConstant(int32_t value) {
34 31764 : return jsgraph()->SmiConstant(value);
35 : }
36 :
37 29728 : Node* GraphAssembler::Uint32Constant(int32_t value) {
38 29728 : return jsgraph()->Uint32Constant(value);
39 : }
40 :
41 55285 : Node* GraphAssembler::Float64Constant(double value) {
42 55285 : return jsgraph()->Float64Constant(value);
43 : }
44 :
45 115647 : Node* GraphAssembler::HeapConstant(Handle<HeapObject> object) {
46 115647 : return jsgraph()->HeapConstant(object);
47 : }
48 :
49 :
50 278760 : Node* GraphAssembler::ExternalConstant(ExternalReference ref) {
51 278760 : return jsgraph()->ExternalConstant(ref);
52 : }
53 :
54 3158 : Node* GraphAssembler::CEntryStubConstant(int result_size) {
55 3158 : return jsgraph()->CEntryStubConstant(result_size);
56 : }
57 :
58 63362 : Node* GraphAssembler::LoadFramePointer() {
59 63362 : return graph()->NewNode(machine()->LoadFramePointer());
60 : }
61 :
62 : #define SINGLETON_CONST_DEF(Name) \
63 : Node* GraphAssembler::Name() { return jsgraph()->Name(); }
64 639326 : JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_DEF)
65 : #undef SINGLETON_CONST_DEF
66 :
67 : #define PURE_UNOP_DEF(Name) \
68 : Node* GraphAssembler::Name(Node* input) { \
69 : return graph()->NewNode(machine()->Name(), input); \
70 : }
71 2319912 : PURE_ASSEMBLER_MACH_UNOP_LIST(PURE_UNOP_DEF)
72 : #undef PURE_UNOP_DEF
73 :
74 : #define PURE_BINOP_DEF(Name) \
75 : Node* GraphAssembler::Name(Node* left, Node* right) { \
76 : return graph()->NewNode(machine()->Name(), left, right); \
77 : }
78 7311641 : PURE_ASSEMBLER_MACH_BINOP_LIST(PURE_BINOP_DEF)
79 : #undef PURE_BINOP_DEF
80 :
81 : #define CHECKED_BINOP_DEF(Name) \
82 : Node* GraphAssembler::Name(Node* left, Node* right) { \
83 : return graph()->NewNode(machine()->Name(), left, right, current_control_); \
84 : }
85 256673 : CHECKED_ASSEMBLER_MACH_BINOP_LIST(CHECKED_BINOP_DEF)
86 : #undef CHECKED_BINOP_DEF
87 :
88 0 : Node* GraphAssembler::Float64RoundDown(Node* value) {
89 0 : if (machine()->Float64RoundDown().IsSupported()) {
90 0 : return graph()->NewNode(machine()->Float64RoundDown().op(), value);
91 : }
92 : return nullptr;
93 : }
94 :
95 332833 : Node* GraphAssembler::Projection(int index, Node* value) {
96 499246 : return graph()->NewNode(common()->Projection(index), value, current_control_);
97 : }
98 :
99 86426 : Node* GraphAssembler::Allocate(PretenureFlag pretenure, Node* size) {
100 : return current_effect_ =
101 : graph()->NewNode(simplified()->Allocate(Type::Any(), NOT_TENURED),
102 129639 : size, current_effect_, current_control_);
103 : }
104 :
105 903094 : Node* GraphAssembler::LoadField(FieldAccess const& access, Node* object) {
106 : return current_effect_ =
107 : graph()->NewNode(simplified()->LoadField(access), object,
108 1354637 : current_effect_, current_control_);
109 : }
110 :
111 7221 : Node* GraphAssembler::LoadElement(ElementAccess const& access, Node* object,
112 7221 : Node* index) {
113 : return current_effect_ =
114 : graph()->NewNode(simplified()->LoadElement(access), object, index,
115 21663 : current_effect_, current_control_);
116 : }
117 :
118 86824 : Node* GraphAssembler::StoreField(FieldAccess const& access, Node* object,
119 86824 : Node* value) {
120 : return current_effect_ =
121 : graph()->NewNode(simplified()->StoreField(access), object, value,
122 260472 : current_effect_, current_control_);
123 : }
124 :
125 6430 : Node* GraphAssembler::StoreElement(ElementAccess const& access, Node* object,
126 6430 : Node* index, Node* value) {
127 : return current_effect_ =
128 : graph()->NewNode(simplified()->StoreElement(access), object, index,
129 19290 : value, current_effect_, current_control_);
130 : }
131 :
132 40 : Node* GraphAssembler::DebugBreak() {
133 : return current_effect_ = graph()->NewNode(machine()->DebugBreak(),
134 60 : current_effect_, current_control_);
135 : }
136 :
137 138221 : Node* GraphAssembler::Store(StoreRepresentation rep, Node* object, Node* offset,
138 138221 : Node* value) {
139 : return current_effect_ =
140 : graph()->NewNode(machine()->Store(rep), object, offset, value,
141 414663 : current_effect_, current_control_);
142 : }
143 :
144 584246 : Node* GraphAssembler::Load(MachineType rep, Node* object, Node* offset) {
145 : return current_effect_ =
146 : graph()->NewNode(machine()->Load(rep), object, offset,
147 876369 : current_effect_, current_control_);
148 : }
149 :
150 24384 : Node* GraphAssembler::Retain(Node* buffer) {
151 : return current_effect_ =
152 36576 : graph()->NewNode(common()->Retain(), buffer, current_effect_);
153 : }
154 :
155 13174 : Node* GraphAssembler::UnsafePointerAdd(Node* base, Node* external) {
156 : return current_effect_ =
157 : graph()->NewNode(machine()->UnsafePointerAdd(), base, external,
158 19761 : current_effect_, current_control_);
159 : }
160 :
161 18636 : Node* GraphAssembler::ToNumber(Node* value) {
162 : return current_effect_ =
163 : graph()->NewNode(ToNumberOperator(), ToNumberBuiltinConstant(),
164 27954 : value, NoContextConstant(), current_effect_);
165 : }
166 :
167 127051 : Node* GraphAssembler::DeoptimizeIf(DeoptimizeReason reason, Node* condition,
168 127051 : Node* frame_state) {
169 : return current_control_ = current_effect_ = graph()->NewNode(
170 : common()->DeoptimizeIf(DeoptimizeKind::kEager, reason), condition,
171 381152 : frame_state, current_effect_, current_control_);
172 : }
173 :
174 198382 : Node* GraphAssembler::DeoptimizeIfNot(DeoptimizeKind kind,
175 : DeoptimizeReason reason, Node* condition,
176 198381 : Node* frame_state) {
177 : return current_control_ = current_effect_ = graph()->NewNode(
178 : common()->DeoptimizeUnless(kind, reason), condition, frame_state,
179 595152 : current_effect_, current_control_);
180 : }
181 :
182 169391 : Node* GraphAssembler::DeoptimizeIfNot(DeoptimizeReason reason, Node* condition,
183 : Node* frame_state) {
184 : return DeoptimizeIfNot(DeoptimizeKind::kEager, reason, condition,
185 169391 : frame_state);
186 : }
187 :
188 204 : void GraphAssembler::Branch(Node* condition, GraphAssemblerLabel<0u>* if_true,
189 816 : GraphAssemblerLabel<0u>* if_false) {
190 : DCHECK_NOT_NULL(current_control_);
191 :
192 : BranchHint hint = BranchHint::kNone;
193 204 : if (if_true->IsDeferred() != if_false->IsDeferred()) {
194 102 : hint = if_false->IsDeferred() ? BranchHint::kTrue : BranchHint::kFalse;
195 : }
196 :
197 : Node* branch =
198 408 : graph()->NewNode(common()->Branch(hint), condition, current_control_);
199 :
200 408 : current_control_ = graph()->NewNode(common()->IfTrue(), branch);
201 204 : MergeState(if_true);
202 :
203 408 : current_control_ = graph()->NewNode(common()->IfFalse(), branch);
204 204 : MergeState(if_false);
205 :
206 204 : current_control_ = nullptr;
207 204 : current_effect_ = nullptr;
208 204 : }
209 :
210 : // Extractors (should be only used when destructing the assembler.
211 1016177 : Node* GraphAssembler::ExtractCurrentControl() {
212 1016177 : Node* result = current_control_;
213 1016177 : current_control_ = nullptr;
214 1016177 : return result;
215 : }
216 :
217 1016173 : Node* GraphAssembler::ExtractCurrentEffect() {
218 1016173 : Node* result = current_effect_;
219 1016173 : current_effect_ = nullptr;
220 1016173 : return result;
221 : }
222 :
223 34270520 : void GraphAssembler::Reset(Node* effect, Node* control) {
224 34270520 : current_effect_ = effect;
225 34270520 : current_control_ = control;
226 34270520 : }
227 :
228 11352 : Operator const* GraphAssembler::ToNumberOperator() {
229 9318 : if (!to_number_operator_.is_set()) {
230 : Callable callable =
231 1017 : Builtins::CallableFor(jsgraph()->isolate(), Builtins::kToNumber);
232 : CallDescriptor::Flags flags = CallDescriptor::kNoFlags;
233 : CallDescriptor* desc = Linkage::GetStubCallDescriptor(
234 : jsgraph()->isolate(), graph()->zone(), callable.descriptor(), 0, flags,
235 2034 : Operator::kEliminatable);
236 1017 : to_number_operator_.set(common()->Call(desc));
237 : }
238 9318 : return to_number_operator_.get();
239 : }
240 :
241 : } // namespace compiler
242 : } // namespace internal
243 : } // namespace v8
|