aboutsummaryrefslogtreecommitdiff
path: root/src/ic/handler-configuration-inl.h
blob: 505d67cf42bac03dc17dbfe7ac6c2f20c2c82535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2016 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_HANDLER_CONFIGURATION_INL_H_
#define V8_IC_HANDLER_CONFIGURATION_INL_H_

#include "src/ic/handler-configuration.h"

#include "src/field-index-inl.h"
#include "src/objects-inl.h"

namespace v8 {
namespace internal {

Handle<Object> LoadHandler::LoadField(Isolate* isolate,
                                      FieldIndex field_index) {
  int config = KindBits::encode(kForFields) |
               IsInobjectBits::encode(field_index.is_inobject()) |
               IsDoubleBits::encode(field_index.is_double()) |
               FieldOffsetBits::encode(field_index.offset());
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> LoadHandler::LoadConstant(Isolate* isolate, int descriptor) {
  int config = KindBits::encode(kForConstants) |
               IsAccessorInfoBits::encode(false) |
               DescriptorValueIndexBits::encode(
                   DescriptorArray::ToValueIndex(descriptor));
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> LoadHandler::LoadApiGetter(Isolate* isolate, int descriptor) {
  int config = KindBits::encode(kForConstants) |
               IsAccessorInfoBits::encode(true) |
               DescriptorValueIndexBits::encode(
                   DescriptorArray::ToValueIndex(descriptor));
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> LoadHandler::EnableAccessCheckOnReceiver(
    Isolate* isolate, Handle<Object> smi_handler) {
  int config = Smi::cast(*smi_handler)->value();
#ifdef DEBUG
  Kind kind = KindBits::decode(config);
  DCHECK_NE(kForElements, kind);
#endif
  config = DoAccessCheckOnReceiverBits::update(config, true);
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> LoadHandler::EnableNegativeLookupOnReceiver(
    Isolate* isolate, Handle<Object> smi_handler) {
  int config = Smi::cast(*smi_handler)->value();
#ifdef DEBUG
  Kind kind = KindBits::decode(config);
  DCHECK_NE(kForElements, kind);
#endif
  config = DoNegativeLookupOnReceiverBits::update(config, true);
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> LoadHandler::LoadNonExistent(
    Isolate* isolate, bool do_negative_lookup_on_receiver) {
  int config =
      KindBits::encode(kForNonExistent) |
      DoNegativeLookupOnReceiverBits::encode(do_negative_lookup_on_receiver);
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> LoadHandler::LoadElement(Isolate* isolate,
                                        ElementsKind elements_kind,
                                        bool convert_hole_to_undefined,
                                        bool is_js_array) {
  int config = KindBits::encode(kForElements) |
               ElementsKindBits::encode(elements_kind) |
               ConvertHoleBits::encode(convert_hole_to_undefined) |
               IsJsArrayBits::encode(is_js_array);
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> StoreHandler::StoreField(Isolate* isolate, Kind kind,
                                        int descriptor, FieldIndex field_index,
                                        Representation representation,
                                        bool extend_storage) {
  StoreHandler::FieldRepresentation field_rep;
  switch (representation.kind()) {
    case Representation::kSmi:
      field_rep = StoreHandler::kSmi;
      break;
    case Representation::kDouble:
      field_rep = StoreHandler::kDouble;
      break;
    case Representation::kHeapObject:
      field_rep = StoreHandler::kHeapObject;
      break;
    case Representation::kTagged:
      field_rep = StoreHandler::kTagged;
      break;
    default:
      UNREACHABLE();
      return Handle<Object>::null();
  }
  int value_index = DescriptorArray::ToValueIndex(descriptor);

  DCHECK(kind == kStoreField || kind == kTransitionToField);
  DCHECK_IMPLIES(kind == kStoreField, !extend_storage);

  int config = StoreHandler::KindBits::encode(kind) |
               StoreHandler::ExtendStorageBits::encode(extend_storage) |
               StoreHandler::IsInobjectBits::encode(field_index.is_inobject()) |
               StoreHandler::FieldRepresentationBits::encode(field_rep) |
               StoreHandler::DescriptorValueIndexBits::encode(value_index) |
               StoreHandler::FieldOffsetBits::encode(field_index.offset());
  return handle(Smi::FromInt(config), isolate);
}

Handle<Object> StoreHandler::StoreField(Isolate* isolate, int descriptor,
                                        FieldIndex field_index,
                                        Representation representation) {
  return StoreField(isolate, kStoreField, descriptor, field_index,
                    representation, false);
}

Handle<Object> StoreHandler::TransitionToField(Isolate* isolate, int descriptor,
                                               FieldIndex field_index,
                                               Representation representation,
                                               bool extend_storage) {
  return StoreField(isolate, kTransitionToField, descriptor, field_index,
                    representation, extend_storage);
}

Handle<Object> StoreHandler::TransitionToConstant(Isolate* isolate,
                                                  int descriptor) {
  int value_index = DescriptorArray::ToValueIndex(descriptor);
  int config =
      StoreHandler::KindBits::encode(StoreHandler::kTransitionToConstant) |
      StoreHandler::DescriptorValueIndexBits::encode(value_index);
  return handle(Smi::FromInt(config), isolate);
}

}  // namespace internal
}  // namespace v8

#endif  // V8_IC_HANDLER_CONFIGURATION_INL_H_