Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / src / compiler / linkage.cc
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/code-stubs.h"
6 #include "src/compiler.h"
7 #include "src/compiler/linkage.h"
8 #include "src/compiler/node.h"
9 #include "src/compiler/pipeline.h"
10 #include "src/scopes.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16
17 std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k) {
18   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
33 std::ostream& operator<<(std::ostream& os, const CallDescriptor& d) {
34   // 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
41 CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) {
42   if (info->function() != NULL) {
43     // If we already have the function literal, use the number of parameters
44     // plus the receiver.
45     return GetJSCallDescriptor(1 + info->function()->parameter_count(), zone,
46                                CallDescriptor::kNoFlags);
47   }
48   if (!info->closure().is_null()) {
49     // If we are compiling a JS function, use a JS call descriptor,
50     // plus the receiver.
51     SharedFunctionInfo* shared = info->closure()->shared();
52     return GetJSCallDescriptor(1 + shared->formal_parameter_count(), zone,
53                                CallDescriptor::kNoFlags);
54   }
55   if (info->code_stub() != NULL) {
56     // Use the code stub interface descriptor.
57     CallInterfaceDescriptor descriptor =
58         info->code_stub()->GetCallInterfaceDescriptor();
59     return GetStubCallDescriptor(descriptor, 0, CallDescriptor::kNoFlags, zone);
60   }
61   return NULL;  // TODO(titzer): ?
62 }
63
64
65 FrameOffset Linkage::GetFrameOffset(int spill_slot, Frame* frame,
66                                     int extra) const {
67   if (frame->GetSpillSlotCount() > 0 || incoming_->IsJSFunctionCall() ||
68       incoming_->kind() == CallDescriptor::kCallAddress) {
69     int offset;
70     int register_save_area_size = frame->GetRegisterSaveAreaSize();
71     if (spill_slot >= 0) {
72       // Local or spill slot. Skip the frame pointer, function, and
73       // context in the fixed part of the frame.
74       offset =
75           -(spill_slot + 1) * kPointerSize - register_save_area_size + extra;
76     } else {
77       // Incoming parameter. Skip the return address.
78       offset = -(spill_slot + 1) * kPointerSize + kFPOnStackSize +
79                kPCOnStackSize + extra;
80     }
81     return FrameOffset::FromFramePointer(offset);
82   } else {
83     // No frame. Retrieve all parameters relative to stack pointer.
84     DCHECK(spill_slot < 0);  // Must be a parameter.
85     int register_save_area_size = frame->GetRegisterSaveAreaSize();
86     int offset = register_save_area_size - (spill_slot + 1) * kPointerSize +
87                  kPCOnStackSize + extra;
88     return FrameOffset::FromStackPointer(offset);
89   }
90 }
91
92
93 CallDescriptor* Linkage::GetJSCallDescriptor(
94     int parameter_count, CallDescriptor::Flags flags) const {
95   return GetJSCallDescriptor(parameter_count, zone_, flags);
96 }
97
98
99 CallDescriptor* Linkage::GetRuntimeCallDescriptor(
100     Runtime::FunctionId function, int parameter_count,
101     Operator::Properties properties) const {
102   return GetRuntimeCallDescriptor(function, parameter_count, properties, zone_);
103 }
104
105
106 CallDescriptor* Linkage::GetStubCallDescriptor(
107     const CallInterfaceDescriptor& descriptor, int stack_parameter_count,
108     CallDescriptor::Flags flags) const {
109   return GetStubCallDescriptor(descriptor, stack_parameter_count, flags, zone_);
110 }
111
112
113 // static
114 bool Linkage::NeedsFrameState(Runtime::FunctionId function) {
115   if (!FLAG_turbo_deoptimization) {
116     return false;
117   }
118   // TODO(jarin) At the moment, we only add frame state for
119   // few chosen runtime functions.
120   switch (function) {
121     case Runtime::kApply:
122     case Runtime::kArrayBufferNeuter:
123     case Runtime::kArrayConcat:
124     case Runtime::kBasicJSONStringify:
125     case Runtime::kCheckExecutionState:
126     case Runtime::kCollectStackTrace:
127     case Runtime::kCompileLazy:
128     case Runtime::kCompileOptimized:
129     case Runtime::kCompileString:
130     case Runtime::kCreateObjectLiteral:
131     case Runtime::kDebugBreak:
132     case Runtime::kDataViewSetInt8:
133     case Runtime::kDataViewSetUint8:
134     case Runtime::kDataViewSetInt16:
135     case Runtime::kDataViewSetUint16:
136     case Runtime::kDataViewSetInt32:
137     case Runtime::kDataViewSetUint32:
138     case Runtime::kDataViewSetFloat32:
139     case Runtime::kDataViewSetFloat64:
140     case Runtime::kDataViewGetInt8:
141     case Runtime::kDataViewGetUint8:
142     case Runtime::kDataViewGetInt16:
143     case Runtime::kDataViewGetUint16:
144     case Runtime::kDataViewGetInt32:
145     case Runtime::kDataViewGetUint32:
146     case Runtime::kDataViewGetFloat32:
147     case Runtime::kDataViewGetFloat64:
148     case Runtime::kDebugEvaluate:
149     case Runtime::kDebugEvaluateGlobal:
150     case Runtime::kDebugGetLoadedScripts:
151     case Runtime::kDebugGetPropertyDetails:
152     case Runtime::kDebugPromiseEvent:
153     case Runtime::kDefineAccessorPropertyUnchecked:
154     case Runtime::kDefineDataPropertyUnchecked:
155     case Runtime::kDeleteProperty:
156     case Runtime::kDeoptimizeFunction:
157     case Runtime::kFunctionBindArguments:
158     case Runtime::kGetDefaultReceiver:
159     case Runtime::kGetFrameCount:
160     case Runtime::kGetOwnProperty:
161     case Runtime::kGetOwnPropertyNames:
162     case Runtime::kGetPropertyNamesFast:
163     case Runtime::kGetPrototype:
164     case Runtime::kInlineArguments:
165     case Runtime::kInlineCallFunction:
166     case Runtime::kInlineDateField:
167     case Runtime::kInlineRegExpExec:
168     case Runtime::kInternalSetPrototype:
169     case Runtime::kInterrupt:
170     case Runtime::kIsPropertyEnumerable:
171     case Runtime::kIsSloppyModeFunction:
172     case Runtime::kLiveEditGatherCompileInfo:
173     case Runtime::kLoadLookupSlot:
174     case Runtime::kLoadLookupSlotNoReferenceError:
175     case Runtime::kMaterializeRegExpLiteral:
176     case Runtime::kNewObject:
177     case Runtime::kNewObjectFromBound:
178     case Runtime::kNewObjectWithAllocationSite:
179     case Runtime::kObjectFreeze:
180     case Runtime::kOwnKeys:
181     case Runtime::kParseJson:
182     case Runtime::kPrepareStep:
183     case Runtime::kPreventExtensions:
184     case Runtime::kPromiseRejectEvent:
185     case Runtime::kPromiseRevokeReject:
186     case Runtime::kRegExpCompile:
187     case Runtime::kRegExpExecMultiple:
188     case Runtime::kResolvePossiblyDirectEval:
189     case Runtime::kSetPrototype:
190     case Runtime::kSetScriptBreakPoint:
191     case Runtime::kSparseJoinWithSeparator:
192     case Runtime::kStackGuard:
193     case Runtime::kStoreKeyedToSuper_Sloppy:
194     case Runtime::kStoreKeyedToSuper_Strict:
195     case Runtime::kStoreToSuper_Sloppy:
196     case Runtime::kStoreToSuper_Strict:
197     case Runtime::kStoreLookupSlot:
198     case Runtime::kStringBuilderConcat:
199     case Runtime::kStringBuilderJoin:
200     case Runtime::kStringMatch:
201     case Runtime::kStringReplaceGlobalRegExpWithString:
202     case Runtime::kThrowNonMethodError:
203     case Runtime::kThrowNotDateError:
204     case Runtime::kThrowReferenceError:
205     case Runtime::kThrowUnsupportedSuperError:
206     case Runtime::kThrow:
207     case Runtime::kTypedArraySetFastCases:
208     case Runtime::kTypedArrayInitializeFromArrayLike:
209 #ifdef V8_I18N_SUPPORT
210     case Runtime::kGetImplFromInitializedIntlObject:
211 #endif
212       return true;
213     default:
214       return false;
215   }
216 }
217
218
219 //==============================================================================
220 // Provide unimplemented methods on unsupported architectures, to at least link.
221 //==============================================================================
222 #if !V8_TURBOFAN_BACKEND
223 CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone,
224                                              CallDescriptor::Flags flags) {
225   UNIMPLEMENTED();
226   return NULL;
227 }
228
229
230 CallDescriptor* Linkage::GetRuntimeCallDescriptor(
231     Runtime::FunctionId function, int parameter_count,
232     Operator::Properties properties, Zone* zone) {
233   UNIMPLEMENTED();
234   return NULL;
235 }
236
237
238 CallDescriptor* Linkage::GetStubCallDescriptor(
239     const CallInterfaceDescriptor& descriptor, int stack_parameter_count,
240     CallDescriptor::Flags flags, Zone* zone) {
241   UNIMPLEMENTED();
242   return NULL;
243 }
244
245
246 CallDescriptor* Linkage::GetSimplifiedCDescriptor(Zone* zone,
247                                                   MachineSignature* sig) {
248   UNIMPLEMENTED();
249   return NULL;
250 }
251 #endif  // !V8_TURBOFAN_BACKEND
252 }
253 }
254 }  // namespace v8::internal::compiler