call-optimization.h 2.6 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_IC_CALL_OPTIMIZATION_H_
#define V8_IC_CALL_OPTIMIZATION_H_

8
#include "src/api/api-arguments.h"
9
#include "src/objects/objects.h"
10 11 12

namespace v8 {
namespace internal {
13

14
// Holds information about possible function call optimizations.
15
class CallOptimization {
16
 public:
17 18
  template <class IsolateT>
  CallOptimization(IsolateT* isolate, Handle<Object> function);
19

20 21
  Context GetAccessorContext(Map holder_map) const;
  bool IsCrossContextLazyAccessorPair(Context native_context,
22
                                      Map holder_map) const;
23

24
  bool is_constant_call() const { return !constant_function_.is_null(); }
25 26 27 28
  bool accept_any_receiver() const { return accept_any_receiver_; }
  bool requires_signature_check() const {
    return !expected_receiver_type_.is_null();
  }
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

  Handle<JSFunction> constant_function() const {
    DCHECK(is_constant_call());
    return constant_function_;
  }

  bool is_simple_api_call() const { return is_simple_api_call_; }

  Handle<FunctionTemplateInfo> expected_receiver_type() const {
    DCHECK(is_simple_api_call());
    return expected_receiver_type_;
  }

  Handle<CallHandlerInfo> api_call_info() const {
    DCHECK(is_simple_api_call());
    return api_call_info_;
  }

  enum HolderLookup { kHolderNotFound, kHolderIsReceiver, kHolderFound };
48

49
  template <class IsolateT>
50
  Handle<JSObject> LookupHolderOfExpectedType(
51
      IsolateT* isolate, Handle<Map> receiver_map,
52
      HolderLookup* holder_lookup) const;
53

54 55
  bool IsCompatibleReceiverMap(Handle<JSObject> api_holder,
                               Handle<JSObject> holder, HolderLookup) const;
56

57
 private:
58 59 60 61
  template <class IsolateT>
  void Initialize(IsolateT* isolate, Handle<JSFunction> function);
  template <class IsolateT>
  void Initialize(IsolateT* isolate,
62
                  Handle<FunctionTemplateInfo> function_template_info);
63 64 65

  // Determines whether the given function can be called using the
  // fast api call builtin.
66 67
  template <class IsolateT>
  void AnalyzePossibleApiFunction(IsolateT* isolate,
68
                                  Handle<JSFunction> function);
69 70 71 72

  Handle<JSFunction> constant_function_;
  Handle<FunctionTemplateInfo> expected_receiver_type_;
  Handle<CallHandlerInfo> api_call_info_;
73 74 75

  // TODO(gsathya): Change these to be a bitfield and do a single fast check
  // rather than two checks.
76 77
  bool is_simple_api_call_ = false;
  bool accept_any_receiver_ = false;
78
};
79

80 81
}  // namespace internal
}  // namespace v8
82 83

#endif  // V8_IC_CALL_OPTIMIZATION_H_