| OLD | NEW |
| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 ? 0 | 367 ? 0 |
| 368 : (frame_state_descriptor->GetTotalSize() + | 368 : (frame_state_descriptor->GetTotalSize() + |
| 369 1); // Include deopt id. | 369 1); // Include deopt id. |
| 370 } | 370 } |
| 371 }; | 371 }; |
| 372 | 372 |
| 373 | 373 |
| 374 // TODO(bmeurer): Get rid of the CallBuffer business and make | 374 // TODO(bmeurer): Get rid of the CallBuffer business and make |
| 375 // InstructionSelector::VisitCall platform independent instead. | 375 // InstructionSelector::VisitCall platform independent instead. |
| 376 void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer, | 376 void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer, |
| 377 bool call_code_immediate, | 377 CallBufferFlags flags, |
| 378 bool call_address_immediate) { | 378 int stack_param_delta) { |
| 379 OperandGenerator g(this); | 379 OperandGenerator g(this); |
| 380 DCHECK_LE(call->op()->ValueOutputCount(), | 380 DCHECK_LE(call->op()->ValueOutputCount(), |
| 381 static_cast<int>(buffer->descriptor->ReturnCount())); | 381 static_cast<int>(buffer->descriptor->ReturnCount())); |
| 382 DCHECK_EQ( | 382 DCHECK_EQ( |
| 383 call->op()->ValueInputCount(), | 383 call->op()->ValueInputCount(), |
| 384 static_cast<int>(buffer->input_count() + buffer->frame_state_count())); | 384 static_cast<int>(buffer->input_count() + buffer->frame_state_count())); |
| 385 | 385 |
| 386 if (buffer->descriptor->ReturnCount() > 0) { | 386 if (buffer->descriptor->ReturnCount() > 0) { |
| 387 // Collect the projections that represent multiple outputs from this call. | 387 // Collect the projections that represent multiple outputs from this call. |
| 388 if (buffer->descriptor->ReturnCount() == 1) { | 388 if (buffer->descriptor->ReturnCount() == 1) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 419 : g.DefineAsLocation(output, location, type); | 419 : g.DefineAsLocation(output, location, type); |
| 420 MarkAsRepresentation(type, op); | 420 MarkAsRepresentation(type, op); |
| 421 | 421 |
| 422 buffer->outputs.push_back(op); | 422 buffer->outputs.push_back(op); |
| 423 } | 423 } |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 // The first argument is always the callee code. | 427 // The first argument is always the callee code. |
| 428 Node* callee = call->InputAt(0); | 428 Node* callee = call->InputAt(0); |
| 429 bool call_code_immediate = (flags & kCallCodeImmediate) != 0; |
| 430 bool call_address_immediate = (flags & kCallAddressImmediate) != 0; |
| 429 switch (buffer->descriptor->kind()) { | 431 switch (buffer->descriptor->kind()) { |
| 430 case CallDescriptor::kCallCodeObject: | 432 case CallDescriptor::kCallCodeObject: |
| 431 buffer->instruction_args.push_back( | 433 buffer->instruction_args.push_back( |
| 432 (call_code_immediate && callee->opcode() == IrOpcode::kHeapConstant) | 434 (call_code_immediate && callee->opcode() == IrOpcode::kHeapConstant) |
| 433 ? g.UseImmediate(callee) | 435 ? g.UseImmediate(callee) |
| 434 : g.UseRegister(callee)); | 436 : g.UseRegister(callee)); |
| 435 break; | 437 break; |
| 436 case CallDescriptor::kCallAddress: | 438 case CallDescriptor::kCallAddress: |
| 437 buffer->instruction_args.push_back( | 439 buffer->instruction_args.push_back( |
| 438 (call_address_immediate && | 440 (call_address_immediate && |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 buffer->instruction_args.size()); | 473 buffer->instruction_args.size()); |
| 472 | 474 |
| 473 size_t input_count = static_cast<size_t>(buffer->input_count()); | 475 size_t input_count = static_cast<size_t>(buffer->input_count()); |
| 474 | 476 |
| 475 // Split the arguments into pushed_nodes and instruction_args. Pushed | 477 // Split the arguments into pushed_nodes and instruction_args. Pushed |
| 476 // arguments require an explicit push instruction before the call and do | 478 // arguments require an explicit push instruction before the call and do |
| 477 // not appear as arguments to the call. Everything else ends up | 479 // not appear as arguments to the call. Everything else ends up |
| 478 // as an InstructionOperand argument to the call. | 480 // as an InstructionOperand argument to the call. |
| 479 auto iter(call->inputs().begin()); | 481 auto iter(call->inputs().begin()); |
| 480 size_t pushed_count = 0; | 482 size_t pushed_count = 0; |
| 483 bool call_tail = (flags & kCallTail) != 0; |
| 481 for (size_t index = 0; index < input_count; ++iter, ++index) { | 484 for (size_t index = 0; index < input_count; ++iter, ++index) { |
| 482 DCHECK(iter != call->inputs().end()); | 485 DCHECK(iter != call->inputs().end()); |
| 483 DCHECK((*iter)->op()->opcode() != IrOpcode::kFrameState); | 486 DCHECK((*iter)->op()->opcode() != IrOpcode::kFrameState); |
| 484 if (index == 0) continue; // The first argument (callee) is already done. | 487 if (index == 0) continue; // The first argument (callee) is already done. |
| 488 |
| 489 LinkageLocation location = buffer->descriptor->GetInputLocation(index); |
| 490 if (call_tail) { |
| 491 location = LinkageLocation::ConvertToTailCallerLocation( |
| 492 location, stack_param_delta); |
| 493 } |
| 485 InstructionOperand op = | 494 InstructionOperand op = |
| 486 g.UseLocation(*iter, buffer->descriptor->GetInputLocation(index), | 495 g.UseLocation(*iter, location, buffer->descriptor->GetInputType(index)); |
| 487 buffer->descriptor->GetInputType(index)); | 496 if (UnallocatedOperand::cast(op).HasFixedSlotPolicy() && !call_tail) { |
| 488 if (UnallocatedOperand::cast(op).HasFixedSlotPolicy()) { | |
| 489 int stack_index = -UnallocatedOperand::cast(op).fixed_slot_index() - 1; | 497 int stack_index = -UnallocatedOperand::cast(op).fixed_slot_index() - 1; |
| 490 if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) { | 498 if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) { |
| 491 buffer->pushed_nodes.resize(stack_index + 1, NULL); | 499 buffer->pushed_nodes.resize(stack_index + 1, NULL); |
| 492 } | 500 } |
| 493 DCHECK(!buffer->pushed_nodes[stack_index]); | 501 DCHECK(!buffer->pushed_nodes[stack_index]); |
| 494 buffer->pushed_nodes[stack_index] = *iter; | 502 buffer->pushed_nodes[stack_index] = *iter; |
| 495 pushed_count++; | 503 pushed_count++; |
| 496 } else { | 504 } else { |
| 497 buffer->instruction_args.push_back(op); | 505 buffer->instruction_args.push_back(op); |
| 498 } | 506 } |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 node->InputAt(static_cast<int>(descriptor->InputCount()))); | 1174 node->InputAt(static_cast<int>(descriptor->InputCount()))); |
| 1167 } | 1175 } |
| 1168 | 1176 |
| 1169 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); | 1177 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); |
| 1170 | 1178 |
| 1171 // Compute InstructionOperands for inputs and outputs. | 1179 // Compute InstructionOperands for inputs and outputs. |
| 1172 // TODO(turbofan): on some architectures it's probably better to use | 1180 // TODO(turbofan): on some architectures it's probably better to use |
| 1173 // the code object in a register if there are multiple uses of it. | 1181 // the code object in a register if there are multiple uses of it. |
| 1174 // Improve constant pool and the heuristics in the register allocator | 1182 // Improve constant pool and the heuristics in the register allocator |
| 1175 // for where to emit constants. | 1183 // for where to emit constants. |
| 1176 InitializeCallBuffer(node, &buffer, true, true); | 1184 CallBufferFlags call_buffer_flags(kCallCodeImmediate | kCallAddressImmediate); |
| 1185 InitializeCallBuffer(node, &buffer, call_buffer_flags); |
| 1177 | 1186 |
| 1178 EmitPrepareArguments(&(buffer.pushed_nodes), descriptor, node); | 1187 EmitPrepareArguments(&(buffer.pushed_nodes), descriptor, node); |
| 1179 | 1188 |
| 1180 // Pass label of exception handler block. | 1189 // Pass label of exception handler block. |
| 1181 CallDescriptor::Flags flags = descriptor->flags(); | 1190 CallDescriptor::Flags flags = descriptor->flags(); |
| 1182 if (handler) { | 1191 if (handler) { |
| 1183 DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode()); | 1192 DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode()); |
| 1184 IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front()); | 1193 IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front()); |
| 1185 if (hint == IfExceptionHint::kLocallyCaught) { | 1194 if (hint == IfExceptionHint::kLocallyCaught) { |
| 1186 flags |= CallDescriptor::kHasLocalCatchHandler; | 1195 flags |= CallDescriptor::kHasLocalCatchHandler; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 | 1228 |
| 1220 void InstructionSelector::VisitTailCall(Node* node) { | 1229 void InstructionSelector::VisitTailCall(Node* node) { |
| 1221 OperandGenerator g(this); | 1230 OperandGenerator g(this); |
| 1222 CallDescriptor const* descriptor = OpParameter<CallDescriptor const*>(node); | 1231 CallDescriptor const* descriptor = OpParameter<CallDescriptor const*>(node); |
| 1223 DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls); | 1232 DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls); |
| 1224 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite); | 1233 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite); |
| 1225 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall); | 1234 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall); |
| 1226 | 1235 |
| 1227 // TODO(turbofan): Relax restriction for stack parameters. | 1236 // TODO(turbofan): Relax restriction for stack parameters. |
| 1228 | 1237 |
| 1229 if (linkage()->GetIncomingDescriptor()->CanTailCall(node)) { | 1238 int stack_param_delta = 0; |
| 1239 if (linkage()->GetIncomingDescriptor()->CanTailCall(node, |
| 1240 &stack_param_delta)) { |
| 1230 CallBuffer buffer(zone(), descriptor, nullptr); | 1241 CallBuffer buffer(zone(), descriptor, nullptr); |
| 1231 | 1242 |
| 1232 // Compute InstructionOperands for inputs and outputs. | 1243 // Compute InstructionOperands for inputs and outputs. |
| 1233 InitializeCallBuffer(node, &buffer, true, IsTailCallAddressImmediate()); | 1244 CallBufferFlags flags(kCallCodeImmediate | kCallTail); |
| 1245 if (IsTailCallAddressImmediate()) { |
| 1246 flags |= kCallAddressImmediate; |
| 1247 } |
| 1248 InitializeCallBuffer(node, &buffer, flags, stack_param_delta); |
| 1234 | 1249 |
| 1235 // Select the appropriate opcode based on the call type. | 1250 // Select the appropriate opcode based on the call type. |
| 1236 InstructionCode opcode; | 1251 InstructionCode opcode; |
| 1237 switch (descriptor->kind()) { | 1252 switch (descriptor->kind()) { |
| 1238 case CallDescriptor::kCallCodeObject: | 1253 case CallDescriptor::kCallCodeObject: |
| 1239 opcode = kArchTailCallCodeObject; | 1254 opcode = kArchTailCallCodeObject; |
| 1240 break; | 1255 break; |
| 1241 case CallDescriptor::kCallJSFunction: | 1256 case CallDescriptor::kCallJSFunction: |
| 1242 opcode = kArchTailCallJSFunction; | 1257 opcode = kArchTailCallJSFunction; |
| 1243 break; | 1258 break; |
| 1244 default: | 1259 default: |
| 1245 UNREACHABLE(); | 1260 UNREACHABLE(); |
| 1246 return; | 1261 return; |
| 1247 } | 1262 } |
| 1248 opcode |= MiscField::encode(descriptor->flags()); | 1263 opcode |= MiscField::encode(descriptor->flags()); |
| 1249 | 1264 |
| 1265 buffer.instruction_args.push_back(g.TempImmediate(stack_param_delta)); |
| 1266 |
| 1250 // Emit the tailcall instruction. | 1267 // Emit the tailcall instruction. |
| 1251 Emit(opcode, 0, nullptr, buffer.instruction_args.size(), | 1268 Emit(opcode, 0, nullptr, buffer.instruction_args.size(), |
| 1252 &buffer.instruction_args.front()); | 1269 &buffer.instruction_args.front()); |
| 1253 } else { | 1270 } else { |
| 1254 FrameStateDescriptor* frame_state_descriptor = | 1271 FrameStateDescriptor* frame_state_descriptor = |
| 1255 descriptor->NeedsFrameState() | 1272 descriptor->NeedsFrameState() |
| 1256 ? GetFrameStateDescriptor( | 1273 ? GetFrameStateDescriptor( |
| 1257 node->InputAt(static_cast<int>(descriptor->InputCount()))) | 1274 node->InputAt(static_cast<int>(descriptor->InputCount()))) |
| 1258 : nullptr; | 1275 : nullptr; |
| 1259 | 1276 |
| 1260 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); | 1277 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); |
| 1261 | 1278 |
| 1262 // Compute InstructionOperands for inputs and outputs. | 1279 // Compute InstructionOperands for inputs and outputs. |
| 1263 InitializeCallBuffer(node, &buffer, true, IsTailCallAddressImmediate()); | 1280 CallBufferFlags flags = kCallCodeImmediate; |
| 1281 if (IsTailCallAddressImmediate()) { |
| 1282 flags |= kCallAddressImmediate; |
| 1283 } |
| 1284 InitializeCallBuffer(node, &buffer, flags); |
| 1264 | 1285 |
| 1265 EmitPrepareArguments(&(buffer.pushed_nodes), descriptor, node); | 1286 EmitPrepareArguments(&(buffer.pushed_nodes), descriptor, node); |
| 1266 | 1287 |
| 1267 // Select the appropriate opcode based on the call type. | 1288 // Select the appropriate opcode based on the call type. |
| 1268 InstructionCode opcode; | 1289 InstructionCode opcode; |
| 1269 switch (descriptor->kind()) { | 1290 switch (descriptor->kind()) { |
| 1270 case CallDescriptor::kCallCodeObject: | 1291 case CallDescriptor::kCallCodeObject: |
| 1271 opcode = kArchCallCodeObject; | 1292 opcode = kArchCallCodeObject; |
| 1272 break; | 1293 break; |
| 1273 case CallDescriptor::kCallJSFunction: | 1294 case CallDescriptor::kCallJSFunction: |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 return new (instruction_zone()) FrameStateDescriptor( | 1388 return new (instruction_zone()) FrameStateDescriptor( |
| 1368 instruction_zone(), state_info.type(), state_info.bailout_id(), | 1389 instruction_zone(), state_info.type(), state_info.bailout_id(), |
| 1369 state_info.state_combine(), parameters, locals, stack, | 1390 state_info.state_combine(), parameters, locals, stack, |
| 1370 state_info.shared_info(), outer_state); | 1391 state_info.shared_info(), outer_state); |
| 1371 } | 1392 } |
| 1372 | 1393 |
| 1373 | 1394 |
| 1374 } // namespace compiler | 1395 } // namespace compiler |
| 1375 } // namespace internal | 1396 } // namespace internal |
| 1376 } // namespace v8 | 1397 } // namespace v8 |
| OLD | NEW |