Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Side by Side Diff: src/compiler/fast-accessor-assembler.cc

Issue 1674633002: Move FastAccessorAssembler from RawMachineAssembler to CodeStubAssembler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove CodeStubAssembler::ContextParameter. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/fast-accessor-assembler.h ('k') | src/fast-accessor-assembler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 #include "src/compiler/fast-accessor-assembler.h"
6
7 #include "src/base/logging.h"
8 #include "src/code-stubs.h" // For CallApiCallbackStub.
9 #include "src/compiler/graph.h"
10 #include "src/compiler/linkage.h"
11 #include "src/compiler/pipeline.h"
12 #include "src/compiler/raw-machine-assembler.h"
13 #include "src/compiler/schedule.h"
14 #include "src/compiler/verifier.h"
15 #include "src/handles-inl.h"
16 #include "src/objects.h" // For FAA::GetInternalField impl.
17
18 namespace v8 {
19 namespace internal {
20 namespace compiler {
21
22 FastAccessorAssembler::FastAccessorAssembler(Isolate* isolate)
23 : zone_(),
24 assembler_(new RawMachineAssembler(
25 isolate, new (zone()) Graph(zone()),
26 Linkage::GetJSCallDescriptor(&zone_, false, 1,
27 CallDescriptor::kNoFlags))),
28 state_(kBuilding) {}
29
30
31 FastAccessorAssembler::~FastAccessorAssembler() {}
32
33
34 FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant(
35 int const_value) {
36 CHECK_EQ(kBuilding, state_);
37 return FromRaw(assembler_->NumberConstant(const_value));
38 }
39
40
41 FastAccessorAssembler::ValueId FastAccessorAssembler::GetReceiver() {
42 CHECK_EQ(kBuilding, state_);
43
44 // For JS call descriptor, the receiver is parameter 0. If we use other
45 // call descriptors, this may or may not hold. So let's check.
46 CHECK(assembler_->call_descriptor()->IsJSFunctionCall());
47 return FromRaw(assembler_->Parameter(0));
48 }
49
50
51 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadInternalField(
52 ValueId value, int field_no) {
53 CHECK_EQ(kBuilding, state_);
54 // Determine the 'value' object's instance type.
55 Node* object_map =
56 assembler_->Load(MachineType::Pointer(), FromId(value),
57 assembler_->IntPtrConstant(
58 Internals::kHeapObjectMapOffset - kHeapObjectTag));
59 Node* instance_type = assembler_->WordAnd(
60 assembler_->Load(
61 MachineType::Uint16(), object_map,
62 assembler_->IntPtrConstant(
63 Internals::kMapInstanceTypeAndBitFieldOffset - kHeapObjectTag)),
64 assembler_->IntPtrConstant(0xff));
65
66 // Check whether we have a proper JSObject.
67 RawMachineLabel is_jsobject, is_not_jsobject, merge;
68 assembler_->Branch(
69 assembler_->WordEqual(
70 instance_type, assembler_->IntPtrConstant(Internals::kJSObjectType)),
71 &is_jsobject, &is_not_jsobject);
72
73 // JSObject? Then load the internal field field_no.
74 assembler_->Bind(&is_jsobject);
75 Node* internal_field = assembler_->Load(
76 MachineType::Pointer(), FromId(value),
77 assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag +
78 kPointerSize * field_no));
79 assembler_->Goto(&merge);
80
81 // No JSObject? Return undefined.
82 // TODO(vogelheim): Check whether this is the appropriate action, or whether
83 // the method should take a label instead.
84 assembler_->Bind(&is_not_jsobject);
85 Node* fail_value = assembler_->UndefinedConstant();
86 assembler_->Goto(&merge);
87
88 // Return.
89 assembler_->Bind(&merge);
90 Node* phi = assembler_->Phi(MachineRepresentation::kTagged, internal_field,
91 fail_value);
92 return FromRaw(phi);
93 }
94
95
96 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue(ValueId value,
97 int offset) {
98 CHECK_EQ(kBuilding, state_);
99 return FromRaw(assembler_->Load(MachineType::IntPtr(), FromId(value),
100 assembler_->IntPtrConstant(offset)));
101 }
102
103
104 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject(ValueId value,
105 int offset) {
106 CHECK_EQ(kBuilding, state_);
107 return FromRaw(
108 assembler_->Load(MachineType::AnyTagged(),
109 assembler_->Load(MachineType::Pointer(), FromId(value),
110 assembler_->IntPtrConstant(offset))));
111 }
112
113
114 void FastAccessorAssembler::ReturnValue(ValueId value) {
115 CHECK_EQ(kBuilding, state_);
116 assembler_->Return(FromId(value));
117 }
118
119
120 void FastAccessorAssembler::CheckFlagSetOrReturnNull(ValueId value, int mask) {
121 CHECK_EQ(kBuilding, state_);
122 RawMachineLabel pass, fail;
123 assembler_->Branch(
124 assembler_->Word32Equal(
125 assembler_->Word32And(FromId(value), assembler_->Int32Constant(mask)),
126 assembler_->Int32Constant(0)),
127 &pass, &fail);
128 assembler_->Bind(&fail);
129 assembler_->Return(assembler_->NullConstant());
130 assembler_->Bind(&pass);
131 }
132
133
134 void FastAccessorAssembler::CheckNotZeroOrReturnNull(ValueId value) {
135 CHECK_EQ(kBuilding, state_);
136 RawMachineLabel is_null, not_null;
137 assembler_->Branch(
138 assembler_->IntPtrEqual(FromId(value), assembler_->IntPtrConstant(0)),
139 &is_null, &not_null);
140 assembler_->Bind(&is_null);
141 assembler_->Return(assembler_->NullConstant());
142 assembler_->Bind(&not_null);
143 }
144
145
146 FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() {
147 CHECK_EQ(kBuilding, state_);
148 RawMachineLabel* label =
149 new (zone()->New(sizeof(RawMachineLabel))) RawMachineLabel;
150 return FromRaw(label);
151 }
152
153
154 void FastAccessorAssembler::SetLabel(LabelId label_id) {
155 CHECK_EQ(kBuilding, state_);
156 assembler_->Bind(FromId(label_id));
157 }
158
159
160 void FastAccessorAssembler::CheckNotZeroOrJump(ValueId value_id,
161 LabelId label_id) {
162 CHECK_EQ(kBuilding, state_);
163 RawMachineLabel pass;
164 assembler_->Branch(
165 assembler_->IntPtrEqual(FromId(value_id), assembler_->IntPtrConstant(0)),
166 &pass, FromId(label_id));
167 assembler_->Bind(&pass);
168 }
169
170 FastAccessorAssembler::ValueId FastAccessorAssembler::Call(
171 FunctionCallback callback_function, ValueId arg) {
172 CHECK_EQ(kBuilding, state_);
173
174 // Create API function stub.
175 CallApiCallbackStub stub(assembler_->isolate(), 1, true);
176 DCHECK_EQ(1, stub.GetCallInterfaceDescriptor().GetStackParameterCount());
177
178 // Wrap the FunctionCallback in an ExternalReference.
179 ApiFunction callback_api_function(FUNCTION_ADDR(callback_function));
180 ExternalReference callback(&callback_api_function,
181 ExternalReference::DIRECT_API_CALL,
182 assembler_->isolate());
183
184 // The stub has 6 parameters.
185 // See: ApiCallbackDescriptorBase::BuildCallInterfaceDescriptorFunctionType
186 Node* args[] = {
187 // Stub/register parameters:
188 assembler_->Parameter(0), /* receiver (use accessor's) */
189 assembler_->UndefinedConstant(), /* call_data (undefined) */
190 assembler_->NullConstant(), /* holder (null) */
191 assembler_->ExternalConstant(callback), /* API callback function */
192
193 // JS arguments, on stack:
194 FromId(arg),
195
196 // Context parameter. (See Linkage::GetStubCallDescriptor.)
197 assembler_->UndefinedConstant()};
198 DCHECK_EQ(arraysize(args),
199 1 + stub.GetCallInterfaceDescriptor().GetParameterCount());
200
201 Node* call = assembler_->CallN(
202 Linkage::GetStubCallDescriptor(
203 assembler_->isolate(), zone(), stub.GetCallInterfaceDescriptor(),
204 stub.GetStackParameterCount(), CallDescriptor::kNoFlags),
205 assembler_->HeapConstant(stub.GetCode()), args);
206 return FromRaw(call);
207 }
208
209 MaybeHandle<Code> FastAccessorAssembler::Build() {
210 CHECK_EQ(kBuilding, state_);
211
212 // Cleanup: We no longer need this.
213 nodes_.clear();
214 labels_.clear();
215
216 // Export the schedule and call the compiler.
217 Schedule* schedule = assembler_->Export();
218 Code::Flags flags = Code::ComputeFlags(Code::STUB);
219 MaybeHandle<Code> code = Pipeline::GenerateCodeForCodeStub(
220 assembler_->isolate(), assembler_->call_descriptor(), assembler_->graph(),
221 schedule, flags, "FastAccessorAssembler");
222
223 // Update state & return.
224 state_ = !code.is_null() ? kBuilt : kError;
225 return code;
226 }
227
228
229 FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) {
230 nodes_.push_back(node);
231 ValueId value = {nodes_.size() - 1};
232 return value;
233 }
234
235
236 FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw(
237 RawMachineLabel* label) {
238 labels_.push_back(label);
239 LabelId label_id = {labels_.size() - 1};
240 return label_id;
241 }
242
243
244 Node* FastAccessorAssembler::FromId(ValueId value) const {
245 CHECK_LT(value.value_id, nodes_.size());
246 CHECK_NOT_NULL(nodes_.at(value.value_id));
247 return nodes_.at(value.value_id);
248 }
249
250
251 RawMachineLabel* FastAccessorAssembler::FromId(LabelId label) const {
252 CHECK_LT(label.label_id, labels_.size());
253 CHECK_NOT_NULL(labels_.at(label.label_id));
254 return labels_.at(label.label_id);
255 }
256
257
258 } // namespace compiler
259 } // namespace internal
260 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/fast-accessor-assembler.h ('k') | src/fast-accessor-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698