1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2014 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file. 4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifndef V8_IC_CALL_OPTIMIZATION_H_ 6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define V8_IC_CALL_OPTIMIZATION_H_ 7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/code-stubs.h" 9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/ic/access-compiler.h" 10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/macro-assembler.h" 11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/objects.h" 12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace v8 { 14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace internal { 15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Holds information about possible function call optimizations. 16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass CallOptimization BASE_EMBEDDED { 17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public: 18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch explicit CallOptimization(Handle<JSFunction> function); 19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool is_constant_call() const { return !constant_function_.is_null(); } 21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<JSFunction> constant_function() const { 23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DCHECK(is_constant_call()); 24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return constant_function_; 25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool is_simple_api_call() const { return is_simple_api_call_; } 28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<FunctionTemplateInfo> expected_receiver_type() const { 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DCHECK(is_simple_api_call()); 31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return expected_receiver_type_; 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<CallHandlerInfo> api_call_info() const { 35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DCHECK(is_simple_api_call()); 36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return api_call_info_; 37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch enum HolderLookup { kHolderNotFound, kHolderIsReceiver, kHolderFound }; 40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<JSObject> LookupHolderOfExpectedType( 41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch Handle<Map> receiver_map, HolderLookup* holder_lookup, 42014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch int* holder_depth_in_prototype_chain = NULL) const; 43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch // Check if the api holder is between the receiver and the holder. 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool IsCompatibleReceiver(Handle<Object> receiver, 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<JSObject> holder) const; 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 48014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch // Check if the api holder is between the receiver and the holder. 49014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch bool IsCompatibleReceiverMap(Handle<Map> receiver_map, 50014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch Handle<JSObject> holder) const; 51014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch private: 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void Initialize(Handle<JSFunction> function); 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch // Determines whether the given function can be called using the 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch // fast api call builtin. 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void AnalyzePossibleApiFunction(Handle<JSFunction> function); 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<JSFunction> constant_function_; 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool is_simple_api_call_; 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<FunctionTemplateInfo> expected_receiver_type_; 62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Handle<CallHandlerInfo> api_call_info_; 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 64014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace internal 65014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace v8 66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif // V8_IC_CALL_OPTIMIZATION_H_ 68