blob: efabd3387c0ad3c71daffb63b11f7c71a14fa6e7 [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
5#ifndef V8_IC_CALL_OPTIMIZATION_H_
6#define V8_IC_CALL_OPTIMIZATION_H_
7
8#include "src/code-stubs.h"
9#include "src/ic/access-compiler.h"
10#include "src/macro-assembler.h"
11#include "src/objects.h"
12
13namespace v8 {
14namespace internal {
15// Holds information about possible function call optimizations.
16class CallOptimization BASE_EMBEDDED {
17 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +010018 explicit CallOptimization(Handle<Object> function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019
20 bool is_constant_call() const { return !constant_function_.is_null(); }
21
22 Handle<JSFunction> constant_function() const {
23 DCHECK(is_constant_call());
24 return constant_function_;
25 }
26
27 bool is_simple_api_call() const { return is_simple_api_call_; }
28
29 Handle<FunctionTemplateInfo> expected_receiver_type() const {
30 DCHECK(is_simple_api_call());
31 return expected_receiver_type_;
32 }
33
34 Handle<CallHandlerInfo> api_call_info() const {
35 DCHECK(is_simple_api_call());
36 return api_call_info_;
37 }
38
39 enum HolderLookup { kHolderNotFound, kHolderIsReceiver, kHolderFound };
40 Handle<JSObject> LookupHolderOfExpectedType(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041 Handle<Map> receiver_map, HolderLookup* holder_lookup,
42 int* holder_depth_in_prototype_chain = NULL) const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043
44 // Check if the api holder is between the receiver and the holder.
45 bool IsCompatibleReceiver(Handle<Object> receiver,
46 Handle<JSObject> holder) const;
47
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000048 // Check if the api holder is between the receiver and the holder.
49 bool IsCompatibleReceiverMap(Handle<Map> receiver_map,
50 Handle<JSObject> holder) const;
51
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052 private:
53 void Initialize(Handle<JSFunction> function);
Ben Murdoch097c5b22016-05-18 11:27:45 +010054 void Initialize(Handle<FunctionTemplateInfo> function_template_info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055
56 // Determines whether the given function can be called using the
57 // fast api call builtin.
58 void AnalyzePossibleApiFunction(Handle<JSFunction> function);
59
60 Handle<JSFunction> constant_function_;
61 bool is_simple_api_call_;
62 Handle<FunctionTemplateInfo> expected_receiver_type_;
63 Handle<CallHandlerInfo> api_call_info_;
64};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000065} // namespace internal
66} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067
68#endif // V8_IC_CALL_OPTIMIZATION_H_