2014-07-30 13:54:45 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/code-factory.h"
|
|
|
|
#include "src/codegen/compiler.h"
|
|
|
|
#include "src/codegen/optimized-compilation-info.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/common-operator.h"
|
|
|
|
#include "src/compiler/graph.h"
|
|
|
|
#include "src/compiler/linkage.h"
|
|
|
|
#include "src/compiler/machine-operator.h"
|
|
|
|
#include "src/compiler/node.h"
|
|
|
|
#include "src/compiler/operator.h"
|
|
|
|
#include "src/compiler/pipeline.h"
|
|
|
|
#include "src/compiler/schedule.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/parsing/parse-info.h"
|
|
|
|
#include "src/zone/zone.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-10-29 14:40:47 +00:00
|
|
|
static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
|
|
|
|
"dummy", 0, 0, 0, 0, 0, 0);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2020-06-15 09:35:25 +00:00
|
|
|
static constexpr bool kNativeContextDependent = false;
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// So we can get a real JS function.
|
|
|
|
static Handle<JSFunction> Compile(const char* source) {
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Handle<String> source_code = isolate->factory()
|
|
|
|
->NewStringFromUtf8(CStrVector(source))
|
|
|
|
.ToHandleChecked();
|
2017-10-04 22:48:12 +00:00
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
Compiler::GetSharedFunctionInfoForScript(
|
2018-07-17 15:08:58 +00:00
|
|
|
isolate, source_code, Compiler::ScriptDetails(),
|
|
|
|
v8::ScriptOriginOptions(), nullptr, nullptr,
|
|
|
|
v8::ScriptCompiler::kNoCompileOptions,
|
2018-02-21 14:35:23 +00:00
|
|
|
ScriptCompiler::kNoCacheNoReason, NOT_NATIVES_CODE)
|
2017-10-04 22:48:12 +00:00
|
|
|
.ToHandleChecked();
|
2014-07-30 13:54:45 +00:00
|
|
|
return isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
2016-03-08 12:07:27 +00:00
|
|
|
shared, isolate->native_context());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageCreate) {
|
2015-03-24 14:17:05 +00:00
|
|
|
HandleAndZoneScope handles;
|
2014-07-30 13:54:45 +00:00
|
|
|
Handle<JSFunction> function = Compile("a + b");
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared(), handles.main_isolate());
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
|
2020-06-15 09:35:25 +00:00
|
|
|
shared, function, kNativeContextDependent);
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::ComputeIncoming(info.zone(), &info);
|
|
|
|
CHECK(call_descriptor);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageJSFunctionIncoming) {
|
|
|
|
const char* sources[] = {"(function() { })", "(function(a) { })",
|
|
|
|
"(function(a,b) { })", "(function(a,b,c) { })"};
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2015-03-24 14:17:05 +00:00
|
|
|
HandleAndZoneScope handles;
|
2015-10-23 12:26:49 +00:00
|
|
|
Handle<JSFunction> function =
|
|
|
|
Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
2015-10-28 13:09:46 +00:00
|
|
|
*v8::Local<v8::Function>::Cast(CompileRun(sources[i]))));
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared(),
|
|
|
|
handles.main_isolate());
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
|
2020-06-15 09:35:25 +00:00
|
|
|
shared, function, kNativeContextDependent);
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::ComputeIncoming(info.zone(), &info);
|
|
|
|
CHECK(call_descriptor);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2018-02-09 19:19:25 +00:00
|
|
|
CHECK_EQ(1 + i, static_cast<int>(call_descriptor->JSParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, call_descriptor->properties());
|
|
|
|
CHECK_EQ(true, call_descriptor->IsJSFunctionCall());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageJSCall) {
|
|
|
|
HandleAndZoneScope handles;
|
|
|
|
Handle<JSFunction> function = Compile("a + c");
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared(), handles.main_isolate());
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
|
2020-06-15 09:35:25 +00:00
|
|
|
shared, function, kNativeContextDependent);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 32; i++) {
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::GetJSCallDescriptor(
|
2015-02-11 14:12:03 +00:00
|
|
|
info.zone(), false, i, CallDescriptor::kNoFlags);
|
2018-02-09 19:19:25 +00:00
|
|
|
CHECK(call_descriptor);
|
|
|
|
CHECK_EQ(i, static_cast<int>(call_descriptor->JSParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, call_descriptor->properties());
|
|
|
|
CHECK_EQ(true, call_descriptor->IsJSFunctionCall());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageRuntimeCall) {
|
|
|
|
// TODO(titzer): test linkage creation for outgoing runtime calls.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageStubCall) {
|
2020-03-24 18:08:23 +00:00
|
|
|
// TODO(bbudge) Add tests for FP registers.
|
2016-01-20 15:17:39 +00:00
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone zone(isolate->allocator(), ZONE_NAME);
|
2017-06-12 06:27:15 +00:00
|
|
|
Callable callable = Builtins::CallableFor(isolate, Builtins::kToNumber);
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(ArrayVector("test"), &zone, Code::STUB);
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::GetStubCallDescriptor(
|
2018-06-18 15:14:29 +00:00
|
|
|
&zone, callable.descriptor(), 0, CallDescriptor::kNoFlags,
|
2016-06-09 15:36:12 +00:00
|
|
|
Operator::kNoProperties);
|
2018-02-09 19:19:25 +00:00
|
|
|
CHECK(call_descriptor);
|
|
|
|
CHECK_EQ(0, static_cast<int>(call_descriptor->StackParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, call_descriptor->properties());
|
|
|
|
CHECK_EQ(false, call_descriptor->IsJSFunctionCall());
|
2020-04-21 18:39:11 +00:00
|
|
|
|
|
|
|
CHECK_EQ(call_descriptor->GetParameterType(0), MachineType::AnyTagged());
|
|
|
|
CHECK_EQ(call_descriptor->GetReturnType(0), MachineType::AnyTagged());
|
2014-07-30 13:54:45 +00:00
|
|
|
// TODO(titzer): test linkage creation for outgoing stub calls.
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
2020-04-21 18:39:11 +00:00
|
|
|
TEST(TestFPLinkageStubCall) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
Zone zone(isolate->allocator(), ZONE_NAME);
|
|
|
|
Callable callable =
|
|
|
|
Builtins::CallableFor(isolate, Builtins::kWasmFloat64ToNumber);
|
|
|
|
OptimizedCompilationInfo info(ArrayVector("test"), &zone, Code::STUB);
|
|
|
|
auto call_descriptor = Linkage::GetStubCallDescriptor(
|
|
|
|
&zone, callable.descriptor(), 0, CallDescriptor::kNoFlags,
|
|
|
|
Operator::kNoProperties);
|
|
|
|
CHECK(call_descriptor);
|
|
|
|
CHECK_EQ(0, static_cast<int>(call_descriptor->StackParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, call_descriptor->properties());
|
|
|
|
CHECK_EQ(false, call_descriptor->IsJSFunctionCall());
|
|
|
|
|
|
|
|
CHECK_EQ(call_descriptor->GetInputType(1), MachineType::Float64());
|
|
|
|
CHECK(call_descriptor->GetInputLocation(1).IsRegister());
|
|
|
|
CHECK_EQ(call_descriptor->GetReturnType(0), MachineType::AnyTagged());
|
|
|
|
CHECK(call_descriptor->GetReturnLocation(0).IsRegister());
|
|
|
|
CHECK_EQ(call_descriptor->GetReturnLocation(0).GetLocation(),
|
|
|
|
kReturnRegister0.code());
|
|
|
|
}
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|