Index: src/compiler/ppc/instruction-selector-ppc.cc |
diff --git a/src/compiler/ppc/instruction-selector-ppc.cc b/src/compiler/ppc/instruction-selector-ppc.cc |
index 0f45647865df3ae57cdeb762c66f5a2f66797ccc..300e27fe6f07aca3be7d0981566000132a3e55d7 100644 |
--- a/src/compiler/ppc/instruction-selector-ppc.cc |
+++ b/src/compiler/ppc/instruction-selector-ppc.cc |
@@ -1442,12 +1442,35 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) { |
// TODO(turbofan): on PPC it's probably better to use the code object in a |
// register if there are multiple uses of it. Improve constant pool and the |
// heuristics in the register allocator for where to emit constants. |
- InitializeCallBuffer(node, &buffer, true, false); |
- |
- // Push any stack arguments. |
- // TODO(mbrandy): reverse order and use push only for first |
- for (Node* node : base::Reversed(buffer.pushed_nodes)) { |
- Emit(kPPC_Push, g.NoOutput(), g.UseRegister(node)); |
+ InitializeCallBuffer(node, &buffer, true, true); |
+ |
+ // Prepare for C function call. |
+ if (descriptor->IsCFunctionCall()) { |
+ Emit(kArchPrepareCallCFunction | |
+ MiscField::encode(static_cast<int>(descriptor->CParameterCount())), |
+ 0, nullptr, 0, nullptr); |
+ |
+ // Poke any stack arguments. |
+ int slot = kStackFrameExtraParamSlot; |
+ for (Node* node : buffer.pushed_nodes) { |
+ Emit(kPPC_StoreToStackSlot, g.NoOutput(), g.UseRegister(node), |
+ g.TempImmediate(slot)); |
+ ++slot; |
+ } |
+ } else { |
+ // Push any stack arguments. |
+ int num_slots = buffer.pushed_nodes.size(); |
+ int slot = 0; |
+ for (Node* node : buffer.pushed_nodes) { |
+ if (slot == 0) { |
+ Emit(kPPC_PushFrame, g.NoOutput(), g.UseRegister(node), |
+ g.TempImmediate(num_slots)); |
+ } else { |
+ Emit(kPPC_StoreToStackSlot, g.NoOutput(), g.UseRegister(node), |
+ g.TempImmediate(slot)); |
+ } |
+ ++slot; |
+ } |
} |
// Pass label of exception handler block. |
@@ -1465,18 +1488,21 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) { |
// Select the appropriate opcode based on the call type. |
InstructionCode opcode; |
switch (descriptor->kind()) { |
- case CallDescriptor::kCallCodeObject: { |
- opcode = kArchCallCodeObject; |
+ case CallDescriptor::kCallAddress: |
+ opcode = |
+ kArchCallCFunction | |
+ MiscField::encode(static_cast<int>(descriptor->CParameterCount())); |
+ break; |
+ case CallDescriptor::kCallCodeObject: |
+ opcode = kArchCallCodeObject | MiscField::encode(flags); |
break; |
- } |
case CallDescriptor::kCallJSFunction: |
- opcode = kArchCallJSFunction; |
+ opcode = kArchCallJSFunction | MiscField::encode(flags); |
break; |
default: |
UNREACHABLE(); |
return; |
} |
- opcode |= MiscField::encode(flags); |
// Emit the call instruction. |
size_t const output_count = buffer.outputs.size(); |