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

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: Review feedback: Seperate types for value + label ids. 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
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,
Michael Starzinger 2015/11/27 09:15:52 Not sure if a JavaScript call descriptor is what w
epertoso 2015/11/27 10:04:56 Currently we just tail-call these accessors, and i
vogelheim 2015/11/27 16:24:50 Ack to both comments. As long as we haven't agreed
Michael Starzinger 2015/11/27 16:39:49 Acknowledged. Whatever allows you to make forward
26 CallDescriptor::kNoFlags))),
27 state_(BUILDING) {}
28
29
30 FastAccessorAssembler::~FastAccessorAssembler() {}
31
32
33 FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant(
34 int const_value) {
35 CHECK_EQ(BUILDING, state_);
36 return FromRaw(assembler_->NumberConstant(const_value));
37 }
38
39
40 FastAccessorAssembler::ValueId FastAccessorAssembler::GetCallTarget() {
41 return GetParameter(0);
42 }
43
44 FastAccessorAssembler::ValueId FastAccessorAssembler::GetParameter(
45 size_t parameter_no) {
46 CHECK_EQ(BUILDING, state_);
47 return FromRaw(assembler_->Parameter(parameter_no));
48 }
49
50
51 FastAccessorAssembler::ValueId FastAccessorAssembler::GetInternalField(
52 ValueId value, int field_no) {
53 CHECK_EQ(BUILDING, state_);
54 return FromRaw(assembler_->Load(
55 kMachPtr, FromId(value),
56 assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag +
57 kPointerSize * field_no)));
58 }
59
60
61 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue(
62 FastAccessorAssembler::ValueId value, int offset) {
63 CHECK_EQ(BUILDING, state_);
64 return FromRaw(assembler_->Load(kMachIntPtr, FromId(value),
65 assembler_->IntPtrConstant(offset)));
66 }
67
68
69 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject(
70 FastAccessorAssembler::ValueId value, int offset) {
71 CHECK_EQ(BUILDING, state_);
72 return FromRaw(assembler_->Load(kMachAnyTagged, FromId(value),
73 assembler_->IntPtrConstant(offset)));
74 }
75
76
77 void FastAccessorAssembler::ReturnValue(ValueId value) {
78 CHECK_EQ(BUILDING, state_);
79 assembler_->Return(FromId(value));
80 }
81
82
83 void FastAccessorAssembler::CheckFlagSetOrReturnNull(
84 FastAccessorAssembler::ValueId value, int mask) {
85 CHECK_EQ(BUILDING, state_);
86 RawMachineAssembler::Label pass, fail;
87 assembler_->Branch(
88 assembler_->Word32Equal(
89 assembler_->Word32And(assembler_->Load(kMachUint32, FromId(value)),
90 assembler_->Int32Constant(mask)),
91 assembler_->Int32Constant(0)),
92 &pass, &fail);
93 assembler_->Bind(&fail);
94 assembler_->Return(assembler_->NullConstant());
95 assembler_->Bind(&pass);
96 }
97
98
99 void FastAccessorAssembler::CheckNotNullOrReturnNull(ValueId value) {
100 CHECK_EQ(BUILDING, state_);
101 RawMachineAssembler::Label pass, fail;
102 assembler_->Branch(
103 assembler_->IntPtrEqual(assembler_->Load(kMachIntPtr, FromId(value)),
104 assembler_->IntPtrConstant(0)),
105 &pass, &fail);
106 assembler_->Bind(&fail);
107 assembler_->Return(assembler_->NullConstant());
108 assembler_->Bind(&pass);
109 }
110
111
112 FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() {
113 CHECK_EQ(BUILDING, state_);
114 RawMachineAssembler::Label* label = new (zone()) RawMachineAssembler::Label;
115 return FromRaw(label);
116 }
117
118
119 void FastAccessorAssembler::SetLabel(LabelId label_id) {
120 CHECK_EQ(BUILDING, state_);
121 assembler_->Bind(FromId(label_id));
122 }
123
124
125 void FastAccessorAssembler::CheckNotNullOrJump(ValueId value_id,
126 LabelId label_id) {
127 CHECK_EQ(BUILDING, state_);
128 RawMachineAssembler::Label pass;
129 assembler_->Branch(
130 assembler_->IntPtrEqual(assembler_->Load(kMachIntPtr, FromId(value_id)),
131 assembler_->IntPtrConstant(0)),
132 &pass, FromId(label_id));
133 assembler_->Bind(&pass);
134 }
135
136
137 Handle<Code> FastAccessorAssembler::Build() {
138 CHECK_EQ(BUILDING, state_);
139
140 // Cleanup: We no longer need this.
141 nodes_.clear();
142 labels_.clear();
143
144 // Export the schedule and call the compiler.
145 CompilationInfo info("FastAccessorAssembler", assembler_->isolate(), zone());
146 Schedule* schedule = assembler_->Export();
147 Handle<Code> code = Pipeline::GenerateCodeForTesting(
148 &info, assembler_->call_descriptor(), assembler_->graph(), schedule);
149
150 // Update state & return.
151 state_ = !code.is_null() ? BUILT : ERROR;
152 return code;
153 }
154
155
156 FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) {
157 nodes_.push_back(node);
158 ValueId value = {nodes_.size() - 1};
159 return value;
160 }
161
162
163 FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw(
164 RawMachineAssembler::Label* label) {
165 labels_.push_back(label);
166 LabelId label_id = {labels_.size() - 1};
167 return label_id;
168 }
169
170
171 Node* FastAccessorAssembler::FromId(
172 FastAccessorAssembler::ValueId value) const {
173 CHECK_LT(value.value_id, nodes_.size());
174 CHECK_NOT_NULL(nodes_.at(value.value_id));
175 return nodes_.at(value.value_id);
176 }
177
178
179 RawMachineAssembler::Label* FastAccessorAssembler::FromId(
180 FastAccessorAssembler::LabelId label) const {
181 CHECK_LT(label.label_id, labels_.size());
182 CHECK_NOT_NULL(labels_.at(label.label_id));
183 return labels_.at(label.label_id);
184 }
185
186
187 } // namespace compiler
188 } // namespace internal
189 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698