v8/test/cctest/compiler/test-run-stubs.cc
danno fe552636be [turbofan] Support variable size argument removal in TF-generated functions
This is preparation for using TF to create builtins that handle variable number of
arguments and have to remove these arguments dynamically from the stack upon
return.

The gist of the changes:
- Added a second argument to the Return node which specifies the number of stack
  slots to pop upon return in addition to those specified by the Linkage of the
  compiled function.
- Removed Tail -> Non-Tail fallback in the instruction selector. Since TF now should
  handles all tail-call cases except where the return value type differs, this fallback
  was not really useful and in fact caused unexpected behavior with variable
  sized argument popping, since it wasn't possible to materialize a Return node
  with the right pop count from the TailCall without additional context.
- Modified existing Return generation to pass a constant zero as the additional
  pop argument since the variable pop functionality

LOG=N

Review-Url: https://codereview.chromium.org/2446543002
Cr-Commit-Position: refs/heads/master@{#40699}
2016-11-02 13:15:57 +00:00

76 lines
2.9 KiB
C++

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/compilation-info.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/js-operator.h"
#include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/pipeline.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
TEST(RunStringLengthStub) {
HandleAndZoneScope scope;
Isolate* isolate = scope.main_isolate();
Zone* zone = scope.main_zone();
// Create code and an accompanying descriptor.
StringLengthStub stub(isolate);
Handle<Code> code = stub.GenerateCode();
CompilationInfo info(ArrayVector("test"), isolate, zone,
Code::ComputeFlags(Code::HANDLER));
CallInterfaceDescriptor interface_descriptor =
stub.GetCallInterfaceDescriptor();
CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
isolate, zone, interface_descriptor, stub.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties);
// Create a function to call the code using the descriptor.
Graph graph(zone);
CommonOperatorBuilder common(zone);
// FunctionTester (ab)uses a 4-argument function
Node* start = graph.NewNode(common.Start(6));
// Parameter 0 is the receiver
Node* receiverParam = graph.NewNode(common.Parameter(1), start);
Node* nameParam = graph.NewNode(common.Parameter(2), start);
Node* slotParam = graph.NewNode(common.Parameter(3), start);
Node* vectorParam = graph.NewNode(common.Parameter(4), start);
Node* theCode = graph.NewNode(common.HeapConstant(code));
Node* dummyContext = graph.NewNode(common.NumberConstant(0.0));
Node* zero = graph.NewNode(common.Int32Constant(0));
Node* call =
graph.NewNode(common.Call(descriptor), theCode, receiverParam, nameParam,
slotParam, vectorParam, dummyContext, start, start);
Node* ret = graph.NewNode(common.Return(), zero, call, call, start);
Node* end = graph.NewNode(common.End(1), ret);
graph.SetStart(start);
graph.SetEnd(end);
FunctionTester ft(&graph, 4);
// Actuall call through to the stub, verifying its result.
const char* testString = "Und das Lamm schrie HURZ!";
Handle<JSReceiver> receiverArg =
Object::ToObject(isolate, ft.Val(testString)).ToHandleChecked();
Handle<String> nameArg = ft.Val("length");
Handle<Object> slot = ft.Val(0.0);
Handle<Object> vector = ft.Val(0.0);
Handle<Object> result =
ft.Call(receiverArg, nameArg, slot, vector).ToHandleChecked();
CHECK_EQ(static_cast<int>(strlen(testString)), Smi::cast(*result)->value());
}
} // namespace compiler
} // namespace internal
} // namespace v8