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

Side by Side Diff: src/compiler/code-stub-assembler.cc

Issue 1617503003: [Atomics] code stubs for atomic operations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: more WIP on using CodeStubAssembler Created 4 years, 10 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/code-stub-assembler.h" 5 #include "src/compiler/code-stub-assembler.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/compiler/graph.h" 10 #include "src/compiler/graph.h"
11 #include "src/compiler/instruction-selector.h" 11 #include "src/compiler/instruction-selector.h"
12 #include "src/compiler/linkage.h" 12 #include "src/compiler/linkage.h"
13 #include "src/compiler/pipeline.h" 13 #include "src/compiler/pipeline.h"
14 #include "src/compiler/raw-machine-assembler.h" 14 #include "src/compiler/raw-machine-assembler.h"
15 #include "src/compiler/schedule.h" 15 #include "src/compiler/schedule.h"
16 #include "src/frames.h" 16 #include "src/frames.h"
17 #include "src/interface-descriptors.h" 17 #include "src/interface-descriptors.h"
18 #include "src/interpreter/bytecodes.h" 18 #include "src/interpreter/bytecodes.h"
19 #include "src/machine-type.h" 19 #include "src/machine-type.h"
20 #include "src/macro-assembler.h" 20 #include "src/macro-assembler.h"
21 #include "src/zone.h" 21 #include "src/zone.h"
22 22
23 namespace v8 { 23 namespace v8 {
24 namespace internal { 24 namespace internal {
25 namespace compiler { 25 namespace compiler {
26 26
27
28 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone, 27 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
29 const CallInterfaceDescriptor& descriptor, 28 const CallInterfaceDescriptor& descriptor,
30 Code::Flags flags, const char* name) 29 Code::Flags flags, const char* name)
31 : raw_assembler_(new RawMachineAssembler( 30 : raw_assembler_(new RawMachineAssembler(
32 isolate, new (zone) Graph(zone), 31 isolate, new (zone) Graph(zone),
33 Linkage::GetStubCallDescriptor(isolate, zone, descriptor, 0, 32 Linkage::GetStubCallDescriptor(isolate, zone, descriptor, 0,
34 CallDescriptor::kNoFlags))), 33 CallDescriptor::kNoFlags))),
35 flags_(flags), 34 flags_(flags),
36 name_(name), 35 name_(name),
37 code_generated_(false) {} 36 code_generated_(false),
37 linkage_type_(LinkageDescriptorType::kStubCall),
38 parameter_count_(descriptor.GetParameterCount()) {}
38 39
39 40
40 CodeStubAssembler::~CodeStubAssembler() {} 41 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
42 int parameter_count, Code::Flags flags,
43 const char* name)
44 : raw_assembler_(new RawMachineAssembler(
45 isolate, new (zone) Graph(zone),
46 Linkage::GetJSCallDescriptor(zone, false, parameter_count,
47 CallDescriptor::kNoFlags))),
48 flags_(flags),
49 name_(name),
50 code_generated_(false),
51 linkage_type_(LinkageDescriptorType::kJSCall),
52 parameter_count_(parameter_count) {}
53
54
55 CodeStubAssembler::~CodeStubAssembler() {
56 for (auto label : labels_) {
57 delete label;
Jarin 2016/02/08 10:25:04 We don't normally do new/delete dances and use zon
58 }
59 }
41 60
42 61
43 Handle<Code> CodeStubAssembler::GenerateCode() { 62 Handle<Code> CodeStubAssembler::GenerateCode() {
44 DCHECK(!code_generated_); 63 DCHECK(!code_generated_);
45 64
46 Schedule* schedule = raw_assembler_->Export(); 65 Schedule* schedule = raw_assembler_->Export();
47 Handle<Code> code = Pipeline::GenerateCodeForCodeStub( 66 Handle<Code> code = Pipeline::GenerateCodeForCodeStub(
48 isolate(), raw_assembler_->call_descriptor(), graph(), schedule, flags_, 67 isolate(), raw_assembler_->call_descriptor(), graph(), schedule, flags_,
49 name_); 68 name_);
50 69
(...skipping 15 matching lines...) Expand all
66 Node* CodeStubAssembler::NumberConstant(double value) { 85 Node* CodeStubAssembler::NumberConstant(double value) {
67 return raw_assembler_->NumberConstant(value); 86 return raw_assembler_->NumberConstant(value);
68 } 87 }
69 88
70 89
71 Node* CodeStubAssembler::HeapConstant(Handle<HeapObject> object) { 90 Node* CodeStubAssembler::HeapConstant(Handle<HeapObject> object) {
72 return raw_assembler_->HeapConstant(object); 91 return raw_assembler_->HeapConstant(object);
73 } 92 }
74 93
75 94
95 Node* CodeStubAssembler::UndefinedConstant() {
96 return raw_assembler_->UndefinedConstant();
97 }
98
99
76 Node* CodeStubAssembler::BooleanConstant(bool value) { 100 Node* CodeStubAssembler::BooleanConstant(bool value) {
77 return raw_assembler_->BooleanConstant(value); 101 return raw_assembler_->BooleanConstant(value);
78 } 102 }
79 103
80 104
105 Node* CodeStubAssembler::Load(MachineType type, Node* base) {
106 return raw_assembler_->Load(type, base);
107 }
108
109
110 Node* CodeStubAssembler::Load(MachineType type, Node* base, Node* index) {
111 return raw_assembler_->Load(type, base, index);
112 }
113
114
81 Node* CodeStubAssembler::Parameter(int value) { 115 Node* CodeStubAssembler::Parameter(int value) {
82 return raw_assembler_->Parameter(value); 116 return raw_assembler_->Parameter(value);
83 } 117 }
84 118
85 119
86 void CodeStubAssembler::Return(Node* value) {
87 return raw_assembler_->Return(value);
88 }
89
90
91 Node* CodeStubAssembler::SmiShiftBitsConstant() { 120 Node* CodeStubAssembler::SmiShiftBitsConstant() {
92 return Int32Constant(kSmiShiftSize + kSmiTagSize); 121 return Int32Constant(kSmiShiftSize + kSmiTagSize);
93 } 122 }
94 123
95 124
96 Node* CodeStubAssembler::SmiTag(Node* value) { 125 Node* CodeStubAssembler::SmiTag(Node* value) {
97 return raw_assembler_->WordShl(value, SmiShiftBitsConstant()); 126 return raw_assembler_->WordShl(value, SmiShiftBitsConstant());
98 } 127 }
99 128
100 129
(...skipping 10 matching lines...) Expand all
111 Node* CodeStubAssembler::IntPtrSub(Node* a, Node* b) { 140 Node* CodeStubAssembler::IntPtrSub(Node* a, Node* b) {
112 return raw_assembler_->IntPtrSub(a, b); 141 return raw_assembler_->IntPtrSub(a, b);
113 } 142 }
114 143
115 144
116 Node* CodeStubAssembler::WordShl(Node* value, int shift) { 145 Node* CodeStubAssembler::WordShl(Node* value, int shift) {
117 return raw_assembler_->WordShl(value, Int32Constant(shift)); 146 return raw_assembler_->WordShl(value, Int32Constant(shift));
118 } 147 }
119 148
120 149
150 Node* CodeStubAssembler::WordEqual(Node* a, Node* b) {
151 return raw_assembler_->WordEqual(a, b);
152 }
153
154
155 Node* CodeStubAssembler::WordOr(Node* a, Node* b) {
156 return raw_assembler_->WordOr(a, b);
157 }
158
159
160 Node* CodeStubAssembler::WordAnd(Node* a, Node* b) {
161 return raw_assembler_->WordAnd(a, b);
162 }
163
164
165 Node* CodeStubAssembler::Int32GreaterThanOrEqual(Node* a, Node* b) {
166 return raw_assembler_->Int32GreaterThanOrEqual(a, b);
167 }
168
169
170 Node* CodeStubAssembler::Int32LessThan(Node* a, Node* b) {
171 return raw_assembler_->Int32LessThan(a, b);
172 }
173
174
121 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) { 175 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) {
122 return raw_assembler_->Load(MachineType::AnyTagged(), object, 176 return raw_assembler_->Load(MachineType::AnyTagged(), object,
123 IntPtrConstant(offset - kHeapObjectTag)); 177 IntPtrConstant(offset - kHeapObjectTag));
124 } 178 }
125 179
126 180
181 Node* CodeStubAssembler::IsHeapObject(Node* object) {
182 RawMachineAssembler* rma = raw_assembler_.get();
183 return rma->WordEqual(
184 rma->WordAnd(object, rma->IntPtrConstant(kHeapObjectTagMask)),
185 rma->IntPtrConstant(kHeapObjectTag));
186 }
187
188
189 Node* CodeStubAssembler::InstanceType(Node* object) {
190 return raw_assembler_->WordAnd(
191 LoadObjectField(LoadObjectField(object, HeapObject::kMapOffset),
192 Map::kInstanceTypeOffset),
193 raw_assembler_->Int32Constant(255));
194 }
195
196
197 Node* CodeStubAssembler::BitFieldValue(Node* word32, uint32_t shift,
198 uint32_t mask) {
199 return raw_assembler_->Word32Shr(
200 raw_assembler_->Word32And(word32, raw_assembler_->Int32Constant(mask)),
201 raw_assembler_->Int32Constant(shift));
202 }
203
204
205 Node* CodeStubAssembler::Context() {
206 switch (linkage_type_) {
207 case LinkageDescriptorType::kStubCall:
208 return Parameter(Linkage::GetStubCallContextParamIndex(parameter_count_));
209
210 case LinkageDescriptorType::kJSCall:
211 return Parameter(Linkage::GetJSCallContextParamIndex(parameter_count_));
212 }
213 }
214
215
127 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target, 216 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target,
128 Node** args) { 217 Node** args) {
129 return raw_assembler_->CallN(descriptor, code_target, args); 218 return raw_assembler_->CallN(descriptor, code_target, args);
130 } 219 }
131 220
132 221
133 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor, 222 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor,
134 Node* code_target, Node** args) { 223 Node* code_target, Node** args) {
135 return raw_assembler_->TailCallN(descriptor, code_target, args); 224 return raw_assembler_->TailCallN(descriptor, code_target, args);
136 } 225 }
137 226
138 227
139 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id, 228 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
140 Node* context, Node* arg1) { 229 Node* arg1) {
141 return raw_assembler_->CallRuntime1(function_id, arg1, context); 230 return raw_assembler_->CallRuntime1(function_id, arg1, Context());
142 } 231 }
143 232
144 233
145 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id, 234 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
146 Node* context, Node* arg1, Node* arg2) { 235 Node* arg1, Node* arg2) {
147 return raw_assembler_->CallRuntime2(function_id, arg1, arg2, context); 236 return raw_assembler_->CallRuntime2(function_id, arg1, arg2, Context());
148 } 237 }
149 238
150 239
151 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 240 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
152 Node* context, Node* arg1) { 241 Node* arg1) {
153 return raw_assembler_->TailCallRuntime1(function_id, arg1, context); 242 return raw_assembler_->TailCallRuntime1(function_id, arg1, Context());
154 } 243 }
155 244
156 245
157 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 246 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
158 Node* context, Node* arg1, 247 Node* arg1, Node* arg2) {
159 Node* arg2) { 248 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, Context());
160 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, context);
161 } 249 }
162 250
163 251
252 RawMachineLabel* CodeStubAssembler::GetOrCreateRawMachineLabel(Label* label) {
253 if (!label->raw_label_) {
254 RawMachineLabel* result = new RawMachineLabel();
Jarin 2016/02/08 10:25:04 As noted above, we do not normally allocate on the
255 label->raw_label_ = result;
256 labels_.push_back(result);
257 return result;
258 }
259
260 return label->raw_label_;
261 }
262
263
264 void CodeStubAssembler::Goto(Label* label) {
265 raw_assembler_->Goto(GetOrCreateRawMachineLabel(label));
266 }
267
268 void CodeStubAssembler::Branch(Node* cond, Label* true_label,
269 Label* false_label) {
270 raw_assembler_->Branch(cond, GetOrCreateRawMachineLabel(true_label),
271 GetOrCreateRawMachineLabel(false_label));
272 }
273
274
275 void CodeStubAssembler::Bind(Label* label) {
276 raw_assembler_->Bind(GetOrCreateRawMachineLabel(label));
277 }
278
279
280 void CodeStubAssembler::Return(Node* value) {
281 return raw_assembler_->Return(value);
282 }
283
284
285 Node* CodeStubAssembler::Phi(MachineRepresentation rep, Node* n1, Node* n2) {
286 return raw_assembler_->Phi(rep, n1, n2);
287 }
288
289
164 // RawMachineAssembler delegate helpers: 290 // RawMachineAssembler delegate helpers:
165 Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); } 291 Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); }
166 292
167 293
168 Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); } 294 Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); }
169 295
170 296
171 Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); } 297 Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); }
172 298
173
174 } // namespace compiler 299 } // namespace compiler
175 } // namespace internal 300 } // namespace internal
176 } // namespace v8 301 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698