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

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

Issue 1705073005: CodeStubAssembler can generate code for builtins (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add SmiUntag32 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
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"
(...skipping 21 matching lines...) Expand all
32 isolate, new (zone) Graph(zone), 32 isolate, new (zone) Graph(zone),
33 Linkage::GetStubCallDescriptor( 33 Linkage::GetStubCallDescriptor(
34 isolate, zone, descriptor, descriptor.GetStackParameterCount(), 34 isolate, zone, descriptor, descriptor.GetStackParameterCount(),
35 CallDescriptor::kNoFlags, Operator::kNoProperties, 35 CallDescriptor::kNoFlags, Operator::kNoProperties,
36 MachineType::AnyTagged(), result_size))), 36 MachineType::AnyTagged(), result_size))),
37 flags_(flags), 37 flags_(flags),
38 name_(name), 38 name_(name),
39 code_generated_(false), 39 code_generated_(false),
40 variables_(zone) {} 40 variables_(zone) {}
41 41
42 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
43 int parameter_count, Code::Flags flags,
44 const char* name)
45 : raw_assembler_(new RawMachineAssembler(
46 isolate, new (zone) Graph(zone),
47 Linkage::GetJSCallDescriptor(zone, false, parameter_count,
48 CallDescriptor::kNoFlags))),
49 flags_(flags),
50 name_(name),
51 code_generated_(false),
52 variables_(zone) {}
53
42 CodeStubAssembler::~CodeStubAssembler() {} 54 CodeStubAssembler::~CodeStubAssembler() {}
43 55
44 void CodeStubAssembler::CallPrologue() {} 56 void CodeStubAssembler::CallPrologue() {}
45 57
46 void CodeStubAssembler::CallEpilogue() {} 58 void CodeStubAssembler::CallEpilogue() {}
47 59
48 Handle<Code> CodeStubAssembler::GenerateCode() { 60 Handle<Code> CodeStubAssembler::GenerateCode() {
49 DCHECK(!code_generated_); 61 DCHECK(!code_generated_);
50 62
51 Schedule* schedule = raw_assembler_->Export(); 63 Schedule* schedule = raw_assembler_->Export();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 137
126 Node* CodeStubAssembler::SmiTag(Node* value) { 138 Node* CodeStubAssembler::SmiTag(Node* value) {
127 return raw_assembler_->WordShl(value, SmiShiftBitsConstant()); 139 return raw_assembler_->WordShl(value, SmiShiftBitsConstant());
128 } 140 }
129 141
130 142
131 Node* CodeStubAssembler::SmiUntag(Node* value) { 143 Node* CodeStubAssembler::SmiUntag(Node* value) {
132 return raw_assembler_->WordSar(value, SmiShiftBitsConstant()); 144 return raw_assembler_->WordSar(value, SmiShiftBitsConstant());
133 } 145 }
134 146
147 Node* CodeStubAssembler::SmiUntag32(Node* value) {
148 Node* result = raw_assembler_->WordSar(value, SmiShiftBitsConstant());
149 if (raw_assembler_->machine()->Is64()) {
150 result = raw_assembler_->TruncateInt64ToInt32(result);
151 }
152 return result;
153 }
154
135 Node* CodeStubAssembler::SmiAdd(Node* a, Node* b) { return IntPtrAdd(a, b); } 155 Node* CodeStubAssembler::SmiAdd(Node* a, Node* b) { return IntPtrAdd(a, b); }
136 156
137 Node* CodeStubAssembler::SmiEqual(Node* a, Node* b) { return WordEqual(a, b); } 157 Node* CodeStubAssembler::SmiEqual(Node* a, Node* b) { return WordEqual(a, b); }
138 158
139 #define DEFINE_CODE_STUB_ASSEMBER_BINARY_OP(name) \ 159 #define DEFINE_CODE_STUB_ASSEMBER_BINARY_OP(name) \
140 Node* CodeStubAssembler::name(Node* a, Node* b) { \ 160 Node* CodeStubAssembler::name(Node* a, Node* b) { \
141 return raw_assembler_->name(a, b); \ 161 return raw_assembler_->name(a, b); \
142 } 162 }
143 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_STUB_ASSEMBER_BINARY_OP) 163 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_STUB_ASSEMBER_BINARY_OP)
144 #undef DEFINE_CODE_STUB_ASSEMBER_BINARY_OP 164 #undef DEFINE_CODE_STUB_ASSEMBER_BINARY_OP
145 165
146 Node* CodeStubAssembler::ChangeInt32ToInt64(Node* value) {
147 return raw_assembler_->ChangeInt32ToInt64(value);
148 }
149
150 Node* CodeStubAssembler::WordShl(Node* value, int shift) { 166 Node* CodeStubAssembler::WordShl(Node* value, int shift) {
151 return raw_assembler_->WordShl(value, Int32Constant(shift)); 167 return raw_assembler_->WordShl(value, Int32Constant(shift));
152 } 168 }
153 169
170 #define DEFINE_CODE_STUB_ASSEMBER_UNARY_OP(name) \
171 Node* CodeStubAssembler::name(Node* a) { return raw_assembler_->name(a); }
172 CODE_STUB_ASSEMBLER_UNARY_OP_LIST(DEFINE_CODE_STUB_ASSEMBER_UNARY_OP)
173 #undef DEFINE_CODE_STUB_ASSEMBER_UNARY_OP
174
154 Node* CodeStubAssembler::WordIsSmi(Node* a) { 175 Node* CodeStubAssembler::WordIsSmi(Node* a) {
155 return WordEqual(raw_assembler_->WordAnd(a, Int32Constant(kSmiTagMask)), 176 return WordEqual(raw_assembler_->WordAnd(a, Int32Constant(kSmiTagMask)),
156 Int32Constant(0)); 177 Int32Constant(0));
157 } 178 }
158 179
159 Node* CodeStubAssembler::LoadBufferObject(Node* buffer, int offset) { 180 Node* CodeStubAssembler::LoadBufferObject(Node* buffer, int offset) {
160 return raw_assembler_->Load(MachineType::AnyTagged(), buffer, 181 return raw_assembler_->Load(MachineType::AnyTagged(), buffer,
161 IntPtrConstant(offset)); 182 IntPtrConstant(offset));
162 } 183 }
163 184
164 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) { 185 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) {
165 return raw_assembler_->Load(MachineType::AnyTagged(), object, 186 return raw_assembler_->Load(MachineType::AnyTagged(), object,
166 IntPtrConstant(offset - kHeapObjectTag)); 187 IntPtrConstant(offset - kHeapObjectTag));
167 } 188 }
168 189
190 Node* CodeStubAssembler::LoadHeapNumber(Node* object) {
191 return raw_assembler_->Load(
192 MachineType::Float64(), object,
193 IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag));
194 }
195
169 Node* CodeStubAssembler::LoadFixedArrayElementSmiIndex(Node* object, 196 Node* CodeStubAssembler::LoadFixedArrayElementSmiIndex(Node* object,
170 Node* smi_index, 197 Node* smi_index,
171 int additional_offset) { 198 int additional_offset) {
172 Node* header_size = raw_assembler_->Int32Constant( 199 Node* header_size = raw_assembler_->Int32Constant(
173 additional_offset + FixedArray::kHeaderSize - kHeapObjectTag); 200 additional_offset + FixedArray::kHeaderSize - kHeapObjectTag);
174 Node* scaled_index = 201 Node* scaled_index =
175 (kSmiShiftSize == 0) 202 (kSmiShiftSize == 0)
176 ? raw_assembler_->Word32Shl( 203 ? raw_assembler_->Word32Shl(
177 smi_index, Int32Constant(kPointerSizeLog2 - kSmiTagSize)) 204 smi_index, Int32Constant(kPointerSizeLog2 - kSmiTagSize))
178 : raw_assembler_->Word32Shl(SmiUntag(smi_index), 205 : raw_assembler_->Word32Shl(SmiUntag(smi_index),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 Node* CodeStubAssembler::StoreNoWriteBarrier(MachineRepresentation rep, 261 Node* CodeStubAssembler::StoreNoWriteBarrier(MachineRepresentation rep,
235 Node* base, Node* index, 262 Node* base, Node* index,
236 Node* value) { 263 Node* value) {
237 return raw_assembler_->Store(rep, base, index, value, kNoWriteBarrier); 264 return raw_assembler_->Store(rep, base, index, value, kNoWriteBarrier);
238 } 265 }
239 266
240 Node* CodeStubAssembler::Projection(int index, Node* value) { 267 Node* CodeStubAssembler::Projection(int index, Node* value) {
241 return raw_assembler_->Projection(index, value); 268 return raw_assembler_->Projection(index, value);
242 } 269 }
243 270
271 Node* CodeStubAssembler::InstanceType(Node* object) {
272 return raw_assembler_->Word32And(
273 LoadObjectField(LoadObjectField(object, HeapObject::kMapOffset),
274 Map::kInstanceTypeOffset),
275 raw_assembler_->Int32Constant(255));
276 }
277
278 Node* CodeStubAssembler::BitFieldValue(Node* word32, uint32_t shift,
279 uint32_t mask) {
280 return raw_assembler_->Word32Shr(
281 raw_assembler_->Word32And(word32, raw_assembler_->Int32Constant(mask)),
282 raw_assembler_->Int32Constant(shift));
283 }
284
244 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target, 285 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target,
245 Node** args) { 286 Node** args) {
246 CallPrologue(); 287 CallPrologue();
247 Node* return_value = raw_assembler_->CallN(descriptor, code_target, args); 288 Node* return_value = raw_assembler_->CallN(descriptor, code_target, args);
248 CallEpilogue(); 289 CallEpilogue();
249 return return_value; 290 return return_value;
250 } 291 }
251 292
252 293
253 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor, 294 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 Node* context, Node* arg1, Node* arg2, 335 Node* context, Node* arg1, Node* arg2,
295 Node* arg3, Node* arg4) { 336 Node* arg3, Node* arg4) {
296 CallPrologue(); 337 CallPrologue();
297 Node* return_value = raw_assembler_->CallRuntime4(function_id, arg1, arg2, 338 Node* return_value = raw_assembler_->CallRuntime4(function_id, arg1, arg2,
298 arg3, arg4, context); 339 arg3, arg4, context);
299 CallEpilogue(); 340 CallEpilogue();
300 return return_value; 341 return return_value;
301 } 342 }
302 343
303 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 344 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
345 Node* context) {
346 return raw_assembler_->TailCallRuntime0(function_id, context);
347 }
348
349 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
304 Node* context, Node* arg1) { 350 Node* context, Node* arg1) {
305 return raw_assembler_->TailCallRuntime1(function_id, arg1, context); 351 return raw_assembler_->TailCallRuntime1(function_id, arg1, context);
306 } 352 }
307 353
308 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 354 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
309 Node* context, Node* arg1, 355 Node* context, Node* arg1,
310 Node* arg2) { 356 Node* arg2) {
311 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, context); 357 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, context);
312 } 358 }
313 359
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 } 663 }
618 } 664 }
619 } 665 }
620 666
621 bound_ = true; 667 bound_ = true;
622 } 668 }
623 669
624 } // namespace compiler 670 } // namespace compiler
625 } // namespace internal 671 } // namespace internal
626 } // namespace v8 672 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698