call-optimization.h 2.35 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 13

namespace v8 {
namespace internal {
// Holds information about possible function call optimizations.
14
class CallOptimization {
15
 public:
16
  CallOptimization(Isolate* isolate, Handle<Object> function);
17

18 19
  Context GetAccessorContext(Map holder_map) const;
  bool IsCrossContextLazyAccessorPair(Context native_context,
20
                                      Map holder_map) const;
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  bool is_constant_call() const { return !constant_function_.is_null(); }

  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 };
  Handle<JSObject> LookupHolderOfExpectedType(
43
      Handle<Map> receiver_map, HolderLookup* holder_lookup) const;
44 45 46 47 48

  // Check if the api holder is between the receiver and the holder.
  bool IsCompatibleReceiver(Handle<Object> receiver,
                            Handle<JSObject> holder) const;

49
  // Check if the api holder is between the receiver and the holder.
50 51
  bool IsCompatibleReceiverMap(Handle<Map> receiver_map,
                               Handle<JSObject> holder) const;
52

53
 private:
54 55 56
  void Initialize(Isolate* isolate, Handle<JSFunction> function);
  void Initialize(Isolate* isolate,
                  Handle<FunctionTemplateInfo> function_template_info);
57 58 59

  // Determines whether the given function can be called using the
  // fast api call builtin.
60 61
  void AnalyzePossibleApiFunction(Isolate* isolate,
                                  Handle<JSFunction> function);
62 63 64 65 66 67

  Handle<JSFunction> constant_function_;
  bool is_simple_api_call_;
  Handle<FunctionTemplateInfo> expected_receiver_type_;
  Handle<CallHandlerInfo> api_call_info_;
};
68 69
}  // namespace internal
}  // namespace v8
70 71

#endif  // V8_IC_CALL_OPTIMIZATION_H_