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

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

Issue 1474543004: Implement Fast Accessor Builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove impl_ cleanup. Drop tests for --optimize-for-size. Also rebase. Created 5 years 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') | test/cctest/cctest.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/compiler/graph.h"
9 #include "src/compiler/linkage.h"
10 #include "src/compiler/pipeline.h"
11 #include "src/compiler/raw-machine-assembler.h"
12 #include "src/compiler/schedule.h"
13 #include "src/compiler/verifier.h"
14 #include "src/handles-inl.h"
15 #include "src/objects.h" // For FAA::GetInternalField impl.
16
17 namespace v8 {
18 namespace internal {
19 namespace compiler {
20
21 FastAccessorAssembler::FastAccessorAssembler(Isolate* isolate)
22 : zone_(),
23 assembler_(new RawMachineAssembler(
24 isolate, new (zone()) Graph(zone()),
25 Linkage::GetJSCallDescriptor(&zone_, false, 1,
26 CallDescriptor::kNoFlags))),
27 state_(kBuilding) {}
28
29
30 FastAccessorAssembler::~FastAccessorAssembler() {}
31
32
33 FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant(
34 int const_value) {
35 CHECK_EQ(kBuilding, state_);
36 return FromRaw(assembler_->NumberConstant(const_value));
37 }
38
39
40 FastAccessorAssembler::ValueId FastAccessorAssembler::GetReceiver() {
41 CHECK_EQ(kBuilding, state_);
42
43 // For JS call descriptor, the receiver is parameter 0. If we use other
44 // call descriptors, this may or may not hold. So let's check.
45 CHECK(assembler_->call_descriptor()->IsJSFunctionCall());
46 return FromRaw(assembler_->Parameter(0));
47 }
48
49
50 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadInternalField(
51 ValueId value, int field_no) {
52 CHECK_EQ(kBuilding, state_);
53 // Determine the 'value' object's instance type.
54 Node* object_map =
55 assembler_->Load(kMachPtr, FromId(value),
56 assembler_->IntPtrConstant(
57 Internals::kHeapObjectMapOffset - kHeapObjectTag));
58 Node* instance_type = assembler_->WordAnd(
59 assembler_->Load(
60 kMachUint16, object_map,
61 assembler_->IntPtrConstant(
62 Internals::kMapInstanceTypeAndBitFieldOffset - kHeapObjectTag)),
63 assembler_->IntPtrConstant(0xff));
64
65 // Check whether we have a proper JSObject.
66 RawMachineLabel is_jsobject, is_not_jsobject, merge;
67 assembler_->Branch(
68 assembler_->WordEqual(
69 instance_type, assembler_->IntPtrConstant(Internals::kJSObjectType)),
70 &is_jsobject, &is_not_jsobject);
71
72 // JSObject? Then load the internal field field_no.
73 assembler_->Bind(&is_jsobject);
74 Node* internal_field = assembler_->Load(
75 kMachPtr, FromId(value),
76 assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag +
77 kPointerSize * field_no));
78 assembler_->Goto(&merge);
79
80 // No JSObject? Return undefined.
81 // TODO(vogelheim): Check whether this is the appropriate action, or whether
82 // the method should take a label instead.
83 assembler_->Bind(&is_not_jsobject);
84 Node* fail_value = assembler_->UndefinedConstant();
85 assembler_->Goto(&merge);
86
87 // Return.
88 assembler_->Bind(&merge);
89 Node* phi = assembler_->Phi(kMachAnyTagged, internal_field, fail_value);
90 return FromRaw(phi);
91 }
92
93
94 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue(ValueId value,
95 int offset) {
96 CHECK_EQ(kBuilding, state_);
97 return FromRaw(assembler_->Load(kMachIntPtr, FromId(value),
98 assembler_->IntPtrConstant(offset)));
99 }
100
101
102 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject(ValueId value,
103 int offset) {
104 CHECK_EQ(kBuilding, state_);
105 return FromRaw(assembler_->Load(
106 kMachAnyTagged, assembler_->Load(kMachPtr, FromId(value),
107 assembler_->IntPtrConstant(offset))));
108 }
109
110
111 void FastAccessorAssembler::ReturnValue(ValueId value) {
112 CHECK_EQ(kBuilding, state_);
113 assembler_->Return(FromId(value));
114 }
115
116
117 void FastAccessorAssembler::CheckFlagSetOrReturnNull(ValueId value, int mask) {
118 CHECK_EQ(kBuilding, state_);
119 RawMachineLabel pass, fail;
120 assembler_->Branch(
121 assembler_->Word32Equal(
122 assembler_->Word32And(FromId(value), assembler_->Int32Constant(mask)),
123 assembler_->Int32Constant(0)),
124 &pass, &fail);
125 assembler_->Bind(&fail);
126 assembler_->Return(assembler_->NullConstant());
127 assembler_->Bind(&pass);
128 }
129
130
131 void FastAccessorAssembler::CheckNotZeroOrReturnNull(ValueId value) {
132 CHECK_EQ(kBuilding, state_);
133 RawMachineLabel is_null, not_null;
134 assembler_->Branch(
135 assembler_->IntPtrEqual(FromId(value), assembler_->IntPtrConstant(0)),
136 &is_null, &not_null);
137 assembler_->Bind(&is_null);
138 assembler_->Return(assembler_->NullConstant());
139 assembler_->Bind(&not_null);
140 }
141
142
143 FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() {
144 CHECK_EQ(kBuilding, state_);
145 RawMachineLabel* label =
146 new (zone()->New(sizeof(RawMachineLabel))) RawMachineLabel;
147 return FromRaw(label);
148 }
149
150
151 void FastAccessorAssembler::SetLabel(LabelId label_id) {
152 CHECK_EQ(kBuilding, state_);
153 assembler_->Bind(FromId(label_id));
154 }
155
156
157 void FastAccessorAssembler::CheckNotZeroOrJump(ValueId value_id,
158 LabelId label_id) {
159 CHECK_EQ(kBuilding, state_);
160 RawMachineLabel pass;
161 assembler_->Branch(
162 assembler_->IntPtrEqual(FromId(value_id), assembler_->IntPtrConstant(0)),
163 &pass, FromId(label_id));
164 assembler_->Bind(&pass);
165 }
166
167
168 MaybeHandle<Code> FastAccessorAssembler::Build() {
169 CHECK_EQ(kBuilding, state_);
170
171 // Cleanup: We no longer need this.
172 nodes_.clear();
173 labels_.clear();
174
175 // Export the schedule and call the compiler.
176 CompilationInfo info("FastAccessorAssembler", assembler_->isolate(), zone());
177 Schedule* schedule = assembler_->Export();
178
179 // TODO(vogelheim): Pipeline should have a dedicated entry point for this
180 // assembler.
181 MaybeHandle<Code> code = Pipeline::GenerateCodeForTesting(
182 &info, assembler_->call_descriptor(), assembler_->graph(), schedule);
183
184 // Update state & return.
185 state_ = !code.is_null() ? kBuilt : kError;
186 return code;
187 }
188
189
190 FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) {
191 nodes_.push_back(node);
192 ValueId value = {nodes_.size() - 1};
193 return value;
194 }
195
196
197 FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw(
198 RawMachineLabel* label) {
199 labels_.push_back(label);
200 LabelId label_id = {labels_.size() - 1};
201 return label_id;
202 }
203
204
205 Node* FastAccessorAssembler::FromId(ValueId value) const {
206 CHECK_LT(value.value_id, nodes_.size());
207 CHECK_NOT_NULL(nodes_.at(value.value_id));
208 return nodes_.at(value.value_id);
209 }
210
211
212 RawMachineLabel* FastAccessorAssembler::FromId(LabelId label) const {
213 CHECK_LT(label.label_id, labels_.size());
214 CHECK_NOT_NULL(labels_.at(label.label_id));
215 return labels_.at(label.label_id);
216 }
217
218
219 } // namespace compiler
220 } // namespace internal
221 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/fast-accessor-assembler.h ('k') | test/cctest/cctest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698