blob: fc6b19e714b834b9361e588886c839b75f473f58 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#include "src/code-stubs.h"
6#include "src/compiler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007#include "src/compiler/linkage.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/compiler/node.h"
9#include "src/compiler/pipeline.h"
10#include "src/scopes.h"
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
16
Emily Bernierd0a1eb72015-03-24 16:35:39 -040017std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000018 switch (k) {
19 case CallDescriptor::kCallCodeObject:
20 os << "Code";
21 break;
22 case CallDescriptor::kCallJSFunction:
23 os << "JS";
24 break;
25 case CallDescriptor::kCallAddress:
26 os << "Addr";
27 break;
28 }
29 return os;
30}
31
32
Emily Bernierd0a1eb72015-03-24 16:35:39 -040033std::ostream& operator<<(std::ostream& os, const CallDescriptor& d) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034 // TODO(svenpanne) Output properties etc. and be less cryptic.
35 return os << d.kind() << ":" << d.debug_name() << ":r" << d.ReturnCount()
36 << "j" << d.JSParameterCount() << "i" << d.InputCount() << "f"
37 << d.FrameStateCount();
38}
39
40
Emily Bernierd0a1eb72015-03-24 16:35:39 -040041CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 if (info->function() != NULL) {
43 // If we already have the function literal, use the number of parameters
44 // plus the receiver.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040045 return GetJSCallDescriptor(1 + info->function()->parameter_count(), zone,
46 CallDescriptor::kNoFlags);
47 }
48 if (!info->closure().is_null()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049 // If we are compiling a JS function, use a JS call descriptor,
50 // plus the receiver.
51 SharedFunctionInfo* shared = info->closure()->shared();
Emily Bernierd0a1eb72015-03-24 16:35:39 -040052 return GetJSCallDescriptor(1 + shared->formal_parameter_count(), zone,
53 CallDescriptor::kNoFlags);
54 }
55 if (info->code_stub() != NULL) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 // Use the code stub interface descriptor.
57 CallInterfaceDescriptor descriptor =
58 info->code_stub()->GetCallInterfaceDescriptor();
Emily Bernierd0a1eb72015-03-24 16:35:39 -040059 return GetStubCallDescriptor(descriptor, 0, CallDescriptor::kNoFlags,
60 Operator::kNoProperties, zone);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040062 return NULL; // TODO(titzer): ?
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063}
64
65
Emily Bernierd0a1eb72015-03-24 16:35:39 -040066FrameOffset Linkage::GetFrameOffset(int spill_slot, Frame* frame,
67 int extra) const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068 if (frame->GetSpillSlotCount() > 0 || incoming_->IsJSFunctionCall() ||
69 incoming_->kind() == CallDescriptor::kCallAddress) {
70 int offset;
71 int register_save_area_size = frame->GetRegisterSaveAreaSize();
72 if (spill_slot >= 0) {
73 // Local or spill slot. Skip the frame pointer, function, and
74 // context in the fixed part of the frame.
75 offset =
76 -(spill_slot + 1) * kPointerSize - register_save_area_size + extra;
77 } else {
78 // Incoming parameter. Skip the return address.
79 offset = -(spill_slot + 1) * kPointerSize + kFPOnStackSize +
80 kPCOnStackSize + extra;
81 }
82 return FrameOffset::FromFramePointer(offset);
83 } else {
84 // No frame. Retrieve all parameters relative to stack pointer.
85 DCHECK(spill_slot < 0); // Must be a parameter.
86 int register_save_area_size = frame->GetRegisterSaveAreaSize();
87 int offset = register_save_area_size - (spill_slot + 1) * kPointerSize +
88 kPCOnStackSize + extra;
89 return FrameOffset::FromStackPointer(offset);
90 }
91}
92
93
Emily Bernierd0a1eb72015-03-24 16:35:39 -040094CallDescriptor* Linkage::GetJSCallDescriptor(
95 int parameter_count, CallDescriptor::Flags flags) const {
96 return GetJSCallDescriptor(parameter_count, zone_, flags);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097}
98
99
100CallDescriptor* Linkage::GetRuntimeCallDescriptor(
101 Runtime::FunctionId function, int parameter_count,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400102 Operator::Properties properties) const {
103 return GetRuntimeCallDescriptor(function, parameter_count, properties, zone_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000104}
105
106
107CallDescriptor* Linkage::GetStubCallDescriptor(
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400108 const CallInterfaceDescriptor& descriptor, int stack_parameter_count,
109 CallDescriptor::Flags flags, Operator::Properties properties) const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000110 return GetStubCallDescriptor(descriptor, stack_parameter_count, flags,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400111 properties, zone_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112}
113
114
115// static
116bool Linkage::NeedsFrameState(Runtime::FunctionId function) {
117 if (!FLAG_turbo_deoptimization) {
118 return false;
119 }
120 // TODO(jarin) At the moment, we only add frame state for
121 // few chosen runtime functions.
122 switch (function) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400123 case Runtime::kApply:
124 case Runtime::kArrayBufferNeuter:
125 case Runtime::kArrayConcat:
126 case Runtime::kBasicJSONStringify:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000127 case Runtime::kCheckExecutionState:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 case Runtime::kCollectStackTrace:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400129 case Runtime::kCompileLazy:
130 case Runtime::kCompileOptimized:
131 case Runtime::kCompileString:
132 case Runtime::kCreateObjectLiteral:
133 case Runtime::kDebugBreak:
134 case Runtime::kDataViewSetInt8:
135 case Runtime::kDataViewSetUint8:
136 case Runtime::kDataViewSetInt16:
137 case Runtime::kDataViewSetUint16:
138 case Runtime::kDataViewSetInt32:
139 case Runtime::kDataViewSetUint32:
140 case Runtime::kDataViewSetFloat32:
141 case Runtime::kDataViewSetFloat64:
142 case Runtime::kDataViewGetInt8:
143 case Runtime::kDataViewGetUint8:
144 case Runtime::kDataViewGetInt16:
145 case Runtime::kDataViewGetUint16:
146 case Runtime::kDataViewGetInt32:
147 case Runtime::kDataViewGetUint32:
148 case Runtime::kDataViewGetFloat32:
149 case Runtime::kDataViewGetFloat64:
150 case Runtime::kDebugEvaluate:
151 case Runtime::kDebugEvaluateGlobal:
152 case Runtime::kDebugGetLoadedScripts:
153 case Runtime::kDebugGetPropertyDetails:
154 case Runtime::kDebugPromiseEvent:
155 case Runtime::kDefineAccessorPropertyUnchecked:
156 case Runtime::kDefineDataPropertyUnchecked:
157 case Runtime::kDeleteProperty:
158 case Runtime::kDeoptimizeFunction:
159 case Runtime::kFunctionBindArguments:
160 case Runtime::kGetDefaultReceiver:
161 case Runtime::kGetFrameCount:
162 case Runtime::kGetOwnProperty:
163 case Runtime::kGetOwnPropertyNames:
164 case Runtime::kGetPropertyNamesFast:
165 case Runtime::kGetPrototype:
166 case Runtime::kInlineArguments:
167 case Runtime::kInlineCallFunction:
168 case Runtime::kInlineDateField:
169 case Runtime::kInlineRegExpExec:
170 case Runtime::kInternalSetPrototype:
171 case Runtime::kInterrupt:
172 case Runtime::kIsPropertyEnumerable:
173 case Runtime::kIsSloppyModeFunction:
174 case Runtime::kLiveEditGatherCompileInfo:
175 case Runtime::kLoadLookupSlot:
176 case Runtime::kLoadLookupSlotNoReferenceError:
177 case Runtime::kMaterializeRegExpLiteral:
178 case Runtime::kNewObject:
179 case Runtime::kNewObjectFromBound:
180 case Runtime::kNewObjectWithAllocationSite:
181 case Runtime::kObjectFreeze:
182 case Runtime::kOwnKeys:
183 case Runtime::kParseJson:
184 case Runtime::kPrepareStep:
185 case Runtime::kPreventExtensions:
186 case Runtime::kPromiseRejectEvent:
187 case Runtime::kPromiseRevokeReject:
188 case Runtime::kRegExpInitializeAndCompile:
189 case Runtime::kRegExpExecMultiple:
190 case Runtime::kResolvePossiblyDirectEval:
191 case Runtime::kRunMicrotasks:
192 case Runtime::kSetPrototype:
193 case Runtime::kSetScriptBreakPoint:
194 case Runtime::kSparseJoinWithSeparator:
195 case Runtime::kStackGuard:
196 case Runtime::kStoreKeyedToSuper_Sloppy:
197 case Runtime::kStoreKeyedToSuper_Strict:
198 case Runtime::kStoreToSuper_Sloppy:
199 case Runtime::kStoreToSuper_Strict:
200 case Runtime::kStoreLookupSlot:
201 case Runtime::kStringBuilderConcat:
202 case Runtime::kStringBuilderJoin:
203 case Runtime::kStringMatch:
204 case Runtime::kStringReplaceGlobalRegExpWithString:
205 case Runtime::kThrowNonMethodError:
206 case Runtime::kThrowNotDateError:
207 case Runtime::kThrowReferenceError:
208 case Runtime::kThrowUnsupportedSuperError:
209 case Runtime::kThrow:
210 case Runtime::kTypedArraySetFastCases:
211 case Runtime::kTypedArrayInitializeFromArrayLike:
212#ifdef V8_I18N_SUPPORT
213 case Runtime::kGetImplFromInitializedIntlObject:
214#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000215 return true;
216 default:
217 return false;
218 }
219}
220
221
222//==============================================================================
223// Provide unimplemented methods on unsupported architectures, to at least link.
224//==============================================================================
225#if !V8_TURBOFAN_BACKEND
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400226CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone,
227 CallDescriptor::Flags flags) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000228 UNIMPLEMENTED();
229 return NULL;
230}
231
232
233CallDescriptor* Linkage::GetRuntimeCallDescriptor(
234 Runtime::FunctionId function, int parameter_count,
235 Operator::Properties properties, Zone* zone) {
236 UNIMPLEMENTED();
237 return NULL;
238}
239
240
241CallDescriptor* Linkage::GetStubCallDescriptor(
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400242 const CallInterfaceDescriptor& descriptor, int stack_parameter_count,
243 CallDescriptor::Flags flags, Operator::Properties properties,
244 Zone* zone) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000245 UNIMPLEMENTED();
246 return NULL;
247}
248
249
250CallDescriptor* Linkage::GetSimplifiedCDescriptor(Zone* zone,
251 MachineSignature* sig) {
252 UNIMPLEMENTED();
253 return NULL;
254}
255#endif // !V8_TURBOFAN_BACKEND
256}
257}
258} // namespace v8::internal::compiler