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

Side by Side Diff: src/compiler/instruction-selector.cc

Issue 1205023002: [turbofan] Add basic support for calling to (a subset of) C functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix argument slots. Created 5 years, 6 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/instruction-selector.h" 5 #include "src/compiler/instruction-selector.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/base/adapters.h" 9 #include "src/base/adapters.h"
10 #include "src/compiler/instruction-selector-impl.h" 10 #include "src/compiler/instruction-selector-impl.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 switch (buffer->descriptor->kind()) { 329 switch (buffer->descriptor->kind()) {
330 case CallDescriptor::kCallCodeObject: 330 case CallDescriptor::kCallCodeObject:
331 buffer->instruction_args.push_back( 331 buffer->instruction_args.push_back(
332 (call_code_immediate && callee->opcode() == IrOpcode::kHeapConstant) 332 (call_code_immediate && callee->opcode() == IrOpcode::kHeapConstant)
333 ? g.UseImmediate(callee) 333 ? g.UseImmediate(callee)
334 : g.UseRegister(callee)); 334 : g.UseRegister(callee));
335 break; 335 break;
336 case CallDescriptor::kCallAddress: 336 case CallDescriptor::kCallAddress:
337 buffer->instruction_args.push_back( 337 buffer->instruction_args.push_back(
338 (call_address_immediate && 338 (call_address_immediate &&
339 (callee->opcode() == IrOpcode::kInt32Constant || 339 callee->opcode() == IrOpcode::kExternalConstant)
340 callee->opcode() == IrOpcode::kInt64Constant))
341 ? g.UseImmediate(callee) 340 ? g.UseImmediate(callee)
342 : g.UseRegister(callee)); 341 : g.UseRegister(callee));
343 break; 342 break;
344 case CallDescriptor::kCallJSFunction: 343 case CallDescriptor::kCallJSFunction:
345 buffer->instruction_args.push_back( 344 buffer->instruction_args.push_back(
346 g.UseLocation(callee, buffer->descriptor->GetInputLocation(0), 345 g.UseLocation(callee, buffer->descriptor->GetInputLocation(0),
347 buffer->descriptor->GetInputType(0))); 346 buffer->descriptor->GetInputType(0)));
348 break; 347 break;
349 } 348 }
350 DCHECK_EQ(1u, buffer->instruction_args.size()); 349 DCHECK_EQ(1u, buffer->instruction_args.size());
(...skipping 15 matching lines...) Expand all
366 DCHECK(1 + buffer->frame_state_value_count() == 365 DCHECK(1 + buffer->frame_state_value_count() ==
367 buffer->instruction_args.size()); 366 buffer->instruction_args.size());
368 367
369 size_t input_count = static_cast<size_t>(buffer->input_count()); 368 size_t input_count = static_cast<size_t>(buffer->input_count());
370 369
371 // Split the arguments into pushed_nodes and instruction_args. Pushed 370 // Split the arguments into pushed_nodes and instruction_args. Pushed
372 // arguments require an explicit push instruction before the call and do 371 // arguments require an explicit push instruction before the call and do
373 // not appear as arguments to the call. Everything else ends up 372 // not appear as arguments to the call. Everything else ends up
374 // as an InstructionOperand argument to the call. 373 // as an InstructionOperand argument to the call.
375 auto iter(call->inputs().begin()); 374 auto iter(call->inputs().begin());
376 int pushed_count = 0; 375 size_t pushed_count = 0;
377 for (size_t index = 0; index < input_count; ++iter, ++index) { 376 for (size_t index = 0; index < input_count; ++iter, ++index) {
378 DCHECK(iter != call->inputs().end()); 377 DCHECK(iter != call->inputs().end());
379 DCHECK((*iter)->op()->opcode() != IrOpcode::kFrameState); 378 DCHECK((*iter)->op()->opcode() != IrOpcode::kFrameState);
380 if (index == 0) continue; // The first argument (callee) is already done. 379 if (index == 0) continue; // The first argument (callee) is already done.
381 InstructionOperand op = 380 InstructionOperand op =
382 g.UseLocation(*iter, buffer->descriptor->GetInputLocation(index), 381 g.UseLocation(*iter, buffer->descriptor->GetInputLocation(index),
383 buffer->descriptor->GetInputType(index)); 382 buffer->descriptor->GetInputType(index));
384 if (UnallocatedOperand::cast(op).HasFixedSlotPolicy()) { 383 if (UnallocatedOperand::cast(op).HasFixedSlotPolicy()) {
385 int stack_index = -UnallocatedOperand::cast(op).fixed_slot_index() - 1; 384 int stack_index = -UnallocatedOperand::cast(op).fixed_slot_index() - 1;
386 if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) { 385 if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) {
387 buffer->pushed_nodes.resize(stack_index + 1, NULL); 386 buffer->pushed_nodes.resize(stack_index + 1, NULL);
388 } 387 }
389 DCHECK(!buffer->pushed_nodes[stack_index]); 388 DCHECK(!buffer->pushed_nodes[stack_index]);
390 buffer->pushed_nodes[stack_index] = *iter; 389 buffer->pushed_nodes[stack_index] = *iter;
391 pushed_count++; 390 pushed_count++;
392 } else { 391 } else {
393 buffer->instruction_args.push_back(op); 392 buffer->instruction_args.push_back(op);
394 } 393 }
395 } 394 }
396 CHECK_EQ(pushed_count, static_cast<int>(buffer->pushed_nodes.size())); 395 DCHECK_EQ(input_count, buffer->instruction_args.size() + pushed_count -
397 DCHECK(static_cast<size_t>(input_count) == 396 buffer->frame_state_value_count());
398 (buffer->instruction_args.size() + buffer->pushed_nodes.size() -
399 buffer->frame_state_value_count()));
400 } 397 }
401 398
402 399
403 void InstructionSelector::VisitBlock(BasicBlock* block) { 400 void InstructionSelector::VisitBlock(BasicBlock* block) {
404 DCHECK(!current_block_); 401 DCHECK(!current_block_);
405 current_block_ = block; 402 current_block_ = block;
406 int current_block_end = static_cast<int>(instructions_.size()); 403 int current_block_end = static_cast<int>(instructions_.size());
407 404
408 // Generate code for the block control "top down", but schedule the code 405 // Generate code for the block control "top down", but schedule the code
409 // "bottom up". 406 // "bottom up".
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 MachineOperatorBuilder::Flags 1152 MachineOperatorBuilder::Flags
1156 InstructionSelector::SupportedMachineOperatorFlags() { 1153 InstructionSelector::SupportedMachineOperatorFlags() {
1157 return MachineOperatorBuilder::Flag::kNoFlags; 1154 return MachineOperatorBuilder::Flag::kNoFlags;
1158 } 1155 }
1159 1156
1160 #endif // !V8_TURBOFAN_BACKEND 1157 #endif // !V8_TURBOFAN_BACKEND
1161 1158
1162 } // namespace compiler 1159 } // namespace compiler
1163 } // namespace internal 1160 } // namespace internal
1164 } // namespace v8 1161 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698