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

Unified Diff: src/compiler/instruction-selector.cc

Issue 1114163005: [turbofan] Fix tail call optimization. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/compiler/instruction-selector.cc
diff --git a/src/compiler/instruction-selector.cc b/src/compiler/instruction-selector.cc
index ff162e9c77b531c783945a555c2045a049367a19..b53b31e7bed9ee2ae6c52f470fa5724cc832ffb1 100644
--- a/src/compiler/instruction-selector.cc
+++ b/src/compiler/instruction-selector.cc
@@ -9,7 +9,6 @@
#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
-#include "src/compiler/node-properties.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/schedule.h"
#include "src/compiler/state-values-utils.h"
@@ -278,7 +277,7 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
bool call_code_immediate,
bool call_address_immediate) {
OperandGenerator g(this);
- DCHECK_EQ(call->op()->ValueOutputCount(),
+ DCHECK_LE(call->op()->ValueOutputCount(),
static_cast<int>(buffer->descriptor->ReturnCount()));
DCHECK_EQ(
call->op()->ValueInputCount(),
@@ -464,7 +463,11 @@ void InstructionSelector::VisitControl(BasicBlock* block) {
DCHECK_EQ(IrOpcode::kCall, input->opcode());
BasicBlock* success = block->SuccessorAt(0);
BasicBlock* exception = block->SuccessorAt(1);
- return VisitCall(input, exception, NORMAL_CALL), VisitGoto(success);
+ return VisitCall(input, exception), VisitGoto(success);
+ }
+ case BasicBlock::kTailCall: {
+ DCHECK_EQ(IrOpcode::kTailCall, input->opcode());
+ return VisitTailCall(input);
}
case BasicBlock::kBranch: {
DCHECK_EQ(IrOpcode::kBranch, input->opcode());
@@ -507,7 +510,7 @@ void InstructionSelector::VisitControl(BasicBlock* block) {
}
case BasicBlock::kReturn: {
DCHECK_EQ(IrOpcode::kReturn, input->opcode());
- return VisitReturn(input);
+ return VisitReturn(input->InputAt(0));
}
case BasicBlock::kDeoptimize: {
// If the result itself is a return, return its input.
@@ -584,7 +587,7 @@ void InstructionSelector::VisitNode(Node* node) {
return VisitConstant(node);
}
case IrOpcode::kCall:
- return VisitCall(node, nullptr, NORMAL_CALL);
+ return VisitCall(node);
case IrOpcode::kFrameState:
case IrOpcode::kStateValues:
return;
@@ -989,46 +992,7 @@ void InstructionSelector::VisitGoto(BasicBlock* target) {
}
-namespace {
-
-// Returns the call node if the given return node is part of a tail call,
-// nullptr otherwise.
-Node* TryMatchTailCall(Node* ret) {
- // The value which is returned must be the result of a potential tail call,
- // there must be no try/catch/finally around the call, and there must be no
- // effects between the call and the return.
- Node* call = NodeProperties::GetValueInput(ret, 0);
- if (call->opcode() != IrOpcode::kCall ||
- !OpParameter<const CallDescriptor*>(call)->SupportsTailCalls() ||
- NodeProperties::IsExceptionalCall(call) ||
- NodeProperties::GetEffectInput(ret, 0) != call) {
- return nullptr;
- }
- // Furthermore, control has to flow via an IfSuccess from the call (for calls
- // which can throw), or the return and the call have to use the same control
- // input (for calls which can't throw).
- Node* control = NodeProperties::GetControlInput(ret, 0);
- bool found = (control->opcode() == IrOpcode::kIfSuccess)
- ? (NodeProperties::GetControlInput(control, 0) == call)
- : (control == NodeProperties::GetControlInput(call, 0));
- return found ? call : nullptr;
-}
-
-} // namespace
-
-
-void InstructionSelector::VisitReturn(Node* node) {
- if (FLAG_turbo_tail_calls) {
- Node* call = TryMatchTailCall(node);
- if (call != nullptr) {
- const CallDescriptor* desc = OpParameter<const CallDescriptor*>(call);
- if (desc->UsesOnlyRegisters() &&
- desc->HasSameReturnLocationsAs(linkage()->GetIncomingDescriptor())) {
- return VisitCall(call, nullptr, TAIL_CALL);
- }
- }
- }
- Node* value = NodeProperties::GetValueInput(node, 0);
+void InstructionSelector::VisitReturn(Node* value) {
DCHECK_NOT_NULL(value);
OperandGenerator g(this);
Emit(kArchRet, g.NoOutput(),
@@ -1159,12 +1123,14 @@ MACHINE_OP_LIST(DECLARE_UNIMPLEMENTED_SELECTOR)
#undef DECLARE_UNIMPLEMENTED_SELECTOR
-void InstructionSelector::VisitCall(Node* node, BasicBlock* handler,
- CallMode call_mode) {
+void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
UNIMPLEMENTED();
}
+void InstructionSelector::VisitTailCall(Node* node) { UNIMPLEMENTED(); }
+
+
void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
BasicBlock* fbranch) {
UNIMPLEMENTED();

Powered by Google App Engine
This is Rietveld 408576698