Commit b98e3949 authored by ishell's avatar ishell Committed by Commit bot

[test] Move CodeAssembler tests to a separate file.

Review-Url: https://codereview.chromium.org/2072813003
Cr-Commit-Position: refs/heads/master@{#37069}
parent e4fba99b
...@@ -366,8 +366,6 @@ class CodeAssembler { ...@@ -366,8 +366,6 @@ class CodeAssembler {
virtual void CallEpilogue(); virtual void CallEpilogue();
private: private:
friend class CodeAssemblerTester;
CodeAssembler(Isolate* isolate, Zone* zone, CallDescriptor* call_descriptor, CodeAssembler(Isolate* isolate, Zone* zone, CallDescriptor* call_descriptor,
Code::Flags flags, const char* name); Code::Flags flags, const char* name);
......
...@@ -13,12 +13,14 @@ v8_executable("cctest") { ...@@ -13,12 +13,14 @@ v8_executable("cctest") {
"$target_gen_dir/resources.cc", "$target_gen_dir/resources.cc",
"cctest.cc", "cctest.cc",
"compiler/c-signature.h", "compiler/c-signature.h",
"compiler/code-assembler-tester.h",
"compiler/codegen-tester.cc", "compiler/codegen-tester.cc",
"compiler/codegen-tester.h", "compiler/codegen-tester.h",
"compiler/function-tester.h", "compiler/function-tester.h",
"compiler/graph-builder-tester.h", "compiler/graph-builder-tester.h",
"compiler/test-basic-block-profiler.cc", "compiler/test-basic-block-profiler.cc",
"compiler/test-branch-combine.cc", "compiler/test-branch-combine.cc",
"compiler/test-code-assembler.cc",
"compiler/test-gap-resolver.cc", "compiler/test-gap-resolver.cc",
"compiler/test-graph-visualizer.cc", "compiler/test-graph-visualizer.cc",
"compiler/test-instruction.cc", "compiler/test-instruction.cc",
......
...@@ -49,12 +49,14 @@ ...@@ -49,12 +49,14 @@
'compiler/c-signature.h', 'compiler/c-signature.h',
'compiler/codegen-tester.cc', 'compiler/codegen-tester.cc',
'compiler/codegen-tester.h', 'compiler/codegen-tester.h',
'compiler/code-assembler-tester.h',
'compiler/function-tester.h', 'compiler/function-tester.h',
'compiler/graph-builder-tester.h', 'compiler/graph-builder-tester.h',
'compiler/test-basic-block-profiler.cc', 'compiler/test-basic-block-profiler.cc',
'compiler/test-branch-combine.cc', 'compiler/test-branch-combine.cc',
'compiler/test-gap-resolver.cc', 'compiler/test-gap-resolver.cc',
'compiler/test-graph-visualizer.cc', 'compiler/test-graph-visualizer.cc',
'compiler/test-code-assembler.cc',
'compiler/test-instruction.cc', 'compiler/test-instruction.cc',
'compiler/test-js-context-specialization.cc', 'compiler/test-js-context-specialization.cc',
'compiler/test-js-constant-cache.cc', 'compiler/test-js-constant-cache.cc',
......
// Copyright 2016 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/handles.h"
#include "src/interface-descriptors.h"
#include "src/isolate.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
class ZoneHolder {
public:
explicit ZoneHolder(Isolate* isolate) : zone_(isolate->allocator()) {}
Zone* zone() { return &zone_; }
private:
Zone zone_;
};
// Inherit from ZoneHolder in order to create a zone that can be passed to
// CodeAssembler base class constructor.
template <typename CodeAssemblerT>
class CodeAssemblerTesterImpl : private ZoneHolder, public CodeAssemblerT {
public:
// Test generating code for a stub.
CodeAssemblerTesterImpl(Isolate* isolate,
const CallInterfaceDescriptor& descriptor)
: ZoneHolder(isolate),
CodeAssemblerT(isolate, ZoneHolder::zone(), descriptor,
Code::ComputeFlags(Code::STUB), "test"),
scope_(isolate) {}
// Test generating code for a JS function (e.g. builtins).
CodeAssemblerTesterImpl(Isolate* isolate, int parameter_count)
: ZoneHolder(isolate),
CodeAssemblerT(isolate, ZoneHolder::zone(), parameter_count,
Code::ComputeFlags(Code::FUNCTION), "test"),
scope_(isolate) {}
// This constructor is intended to be used for creating code objects with
// specific flags.
CodeAssemblerTesterImpl(Isolate* isolate, Code::Flags flags)
: ZoneHolder(isolate),
CodeAssemblerT(isolate, ZoneHolder::zone(), 0, flags, "test"),
scope_(isolate) {}
Handle<Code> GenerateCodeCloseAndEscape() {
return scope_.CloseAndEscape(CodeAssemblerT::GenerateCode());
}
// Expose some internal methods.
Node* SmiShiftBitsConstant() {
return CodeAssemblerT::SmiShiftBitsConstant();
}
private:
HandleScope scope_;
LocalContext context_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
// 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/compiler/code-assembler.h"
#include "src/isolate.h"
#include "test/cctest/compiler/code-assembler-tester.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
typedef CodeAssemblerTesterImpl<CodeAssembler> CodeAssemblerTester;
namespace {
Node* SmiTag(CodeAssemblerTester& m, Node* value) {
int32_t constant_value;
if (m.ToInt32Constant(value, constant_value) &&
Smi::IsValid(constant_value)) {
return m.SmiConstant(Smi::FromInt(constant_value));
}
return m.WordShl(value, m.SmiShiftBitsConstant());
}
Node* UndefinedConstant(CodeAssemblerTester& m) {
return m.LoadRoot(Heap::kUndefinedValueRootIndex);
}
Node* LoadObjectField(CodeAssemblerTester& m, Node* object, int offset,
MachineType rep = MachineType::AnyTagged()) {
return m.Load(rep, object, m.IntPtrConstant(offset - kHeapObjectTag));
}
} // namespace
TEST(SimpleSmiReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
m.Return(SmiTag(m, m.Int32Constant(37)));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(37, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleIntPtrReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
int test;
m.Return(m.IntPtrConstant(reinterpret_cast<intptr_t>(&test)));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(reinterpret_cast<intptr_t>(&test),
reinterpret_cast<intptr_t>(*result.ToHandleChecked()));
}
TEST(SimpleDoubleReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
m.Return(m.NumberConstant(0.5));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0.5, Handle<HeapNumber>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* b = SmiTag(m, m.Int32Constant(0));
m.Return(m.CallRuntime(Runtime::kNumberToSmi, context, b));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* b = SmiTag(m, m.Int32Constant(0));
m.TailCallRuntime(Runtime::kNumberToSmi, context, b);
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* a = SmiTag(m, m.Int32Constant(2));
Node* b = SmiTag(m, m.Int32Constant(4));
m.Return(m.CallRuntime(Runtime::kMathPow, context, a, b));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* a = SmiTag(m, m.Int32Constant(2));
Node* b = SmiTag(m, m.Int32Constant(4));
m.TailCallRuntime(Runtime::kMathPow, context, a, b);
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(VariableMerge1) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&merge);
CHECK_EQ(var1.value(), temp);
}
TEST(VariableMerge2) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&merge);
CHECK_NE(var1.value(), temp);
}
TEST(VariableMerge3) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Variable var2(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
var2.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&merge);
CHECK_NE(var1.value(), temp);
CHECK_NE(var1.value(), temp2);
CHECK_EQ(var2.value(), temp);
}
TEST(VariableMergeBindFirst) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m, &var1), end(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&merge);
CHECK(var1.value() != temp);
CHECK(var1.value() != nullptr);
m.Goto(&end);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&end);
CHECK(var1.value() != temp);
CHECK(var1.value() != nullptr);
}
TEST(VariableMergeSwitch) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
m.Bind(&l1);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
m.Bind(&l2);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
m.Bind(&default_label);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
}
TEST(SplitEdgeBranchMerge) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Label l1(&m), merge(&m);
m.Branch(m.Int32Constant(1), &l1, &merge);
m.Bind(&l1);
m.Goto(&merge);
m.Bind(&merge);
USE(m.GenerateCode());
}
TEST(SplitEdgeSwitchMerge) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Label l1(&m), l2(&m), l3(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
m.Branch(m.Int32Constant(1), &l3, &l1);
m.Bind(&l3);
m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
m.Bind(&l1);
m.Goto(&l2);
m.Bind(&l2);
m.Goto(&default_label);
m.Bind(&default_label);
USE(m.GenerateCode());
}
TEST(TestToConstant) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
int32_t value32;
int64_t value64;
Node* a = m.Int32Constant(5);
CHECK(m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.Int64Constant(static_cast<int64_t>(1) << 32);
CHECK(!m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.Int64Constant(13);
CHECK(m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = UndefinedConstant(m);
CHECK(!m.ToInt32Constant(a, value32));
CHECK(!m.ToInt64Constant(a, value64));
a = UndefinedConstant(m);
CHECK(!m.ToInt32Constant(a, value32));
CHECK(!m.ToInt64Constant(a, value64));
}
TEST(DeferredCodePhiHints) {
typedef compiler::Node Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
Label block1(&m, Label::kDeferred);
m.Goto(&block1);
m.Bind(&block1);
{
Variable var_object(&m, MachineRepresentation::kTagged);
Label loop(&m, &var_object);
var_object.Bind(m.IntPtrConstant(0));
m.Goto(&loop);
m.Bind(&loop);
{
Node* map = LoadObjectField(m, var_object.value(), JSObject::kMapOffset);
var_object.Bind(map);
m.Goto(&loop);
}
}
CHECK(!m.GenerateCode().is_null());
}
TEST(TestOutOfScopeVariable) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeAssemblerTester m(isolate, descriptor);
Label block1(&m);
Label block2(&m);
Label block3(&m);
Label block4(&m);
m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block1, &block4);
m.Bind(&block4);
{
Variable var_object(&m, MachineRepresentation::kTagged);
m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block2,
&block3);
m.Bind(&block2);
var_object.Bind(m.IntPtrConstant(55));
m.Goto(&block1);
m.Bind(&block3);
var_object.Bind(m.IntPtrConstant(66));
m.Goto(&block1);
}
m.Bind(&block1);
CHECK(!m.GenerateCode().is_null());
}
} // namespace compiler
} // namespace internal
} // namespace v8
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "src/base/utils/random-number-generator.h" #include "src/base/utils/random-number-generator.h"
#include "src/ic/stub-cache.h" #include "src/ic/stub-cache.h"
#include "src/interface-descriptors.h"
#include "src/isolate.h" #include "src/isolate.h"
#include "test/cctest/compiler/code-assembler-tester.h"
#include "test/cctest/compiler/function-tester.h" #include "test/cctest/compiler/function-tester.h"
namespace v8 { namespace v8 {
...@@ -14,251 +14,8 @@ namespace internal { ...@@ -14,251 +14,8 @@ namespace internal {
using compiler::FunctionTester; using compiler::FunctionTester;
using compiler::Node; using compiler::Node;
class ZoneHolder { typedef compiler::CodeAssemblerTesterImpl<CodeStubAssembler>
public: CodeStubAssemblerTester;
explicit ZoneHolder(Isolate* isolate) : zone_(isolate->allocator()) {}
Zone* zone() { return &zone_; }
private:
Zone zone_;
};
// Inherit from ZoneHolder in order to create a zone that can be passed to
// CodeStubAssembler base class constructor.
class CodeStubAssemblerTester : private ZoneHolder, public CodeStubAssembler {
public:
// Test generating code for a stub.
CodeStubAssemblerTester(Isolate* isolate,
const CallInterfaceDescriptor& descriptor)
: ZoneHolder(isolate),
CodeStubAssembler(isolate, ZoneHolder::zone(), descriptor,
Code::ComputeFlags(Code::STUB), "test"),
scope_(isolate) {}
// Test generating code for a JS function (e.g. builtins).
CodeStubAssemblerTester(Isolate* isolate, int parameter_count)
: ZoneHolder(isolate),
CodeStubAssembler(isolate, ZoneHolder::zone(), parameter_count,
Code::ComputeFlags(Code::FUNCTION), "test"),
scope_(isolate) {}
// This constructor is intended to be used for creating code objects with
// specific flags.
CodeStubAssemblerTester(Isolate* isolate, Code::Flags flags)
: ZoneHolder(isolate),
CodeStubAssembler(isolate, ZoneHolder::zone(), 0, flags, "test"),
scope_(isolate) {}
Handle<Code> GenerateCodeCloseAndEscape() {
return scope_.CloseAndEscape(GenerateCode());
}
private:
HandleScope scope_;
LocalContext context_;
};
TEST(SimpleSmiReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
m.Return(m.SmiTag(m.Int32Constant(37)));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(37, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleIntPtrReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
int test;
m.Return(m.IntPtrConstant(reinterpret_cast<intptr_t>(&test)));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(reinterpret_cast<intptr_t>(&test),
reinterpret_cast<intptr_t>(*result.ToHandleChecked()));
}
TEST(SimpleDoubleReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
m.Return(m.NumberConstant(0.5));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0.5, Handle<HeapNumber>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* b = m.SmiTag(m.Int32Constant(0));
m.Return(m.CallRuntime(Runtime::kNumberToSmi, context, b));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* b = m.SmiTag(m.Int32Constant(0));
m.TailCallRuntime(Runtime::kNumberToSmi, context, b);
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* a = m.SmiTag(m.Int32Constant(2));
Node* b = m.SmiTag(m.Int32Constant(4));
m.Return(m.CallRuntime(Runtime::kMathPow, context, a, b));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* a = m.SmiTag(m.Int32Constant(2));
Node* b = m.SmiTag(m.Int32Constant(4));
m.TailCallRuntime(Runtime::kMathPow, context, a, b);
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(VariableMerge1) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&merge);
CHECK_EQ(var1.value(), temp);
}
TEST(VariableMerge2) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&merge);
CHECK_NE(var1.value(), temp);
}
TEST(VariableMerge3) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Variable var2(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
var2.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&merge);
CHECK_NE(var1.value(), temp);
CHECK_NE(var1.value(), temp2);
CHECK_EQ(var2.value(), temp);
}
TEST(VariableMergeBindFirst) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m, &var1), end(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&merge);
CHECK(var1.value() != temp);
CHECK(var1.value() != nullptr);
m.Goto(&end);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&end);
CHECK(var1.value() != temp);
CHECK(var1.value() != nullptr);
}
TEST(VariableMergeSwitch) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
m.Bind(&l1);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
m.Bind(&l2);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
m.Bind(&default_label);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
}
TEST(FixedArrayAccessSmiIndex) { TEST(FixedArrayAccessSmiIndex) {
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
...@@ -301,16 +58,12 @@ TEST(LoadInstanceType) { ...@@ -301,16 +58,12 @@ TEST(LoadInstanceType) {
Handle<Smi>::cast(result.ToHandleChecked())->value()); Handle<Smi>::cast(result.ToHandleChecked())->value());
} }
namespace {
class TestBitField : public BitField<unsigned, 3, 3> {};
} // namespace
TEST(BitFieldDecode) { TEST(BitFieldDecode) {
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate); VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor); CodeStubAssemblerTester m(isolate, descriptor);
class TestBitField : public BitField<unsigned, 3, 3> {};
m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f)))); m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f))));
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code); FunctionTester ft(descriptor, code);
...@@ -321,103 +74,31 @@ TEST(BitFieldDecode) { ...@@ -321,103 +74,31 @@ TEST(BitFieldDecode) {
CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value()); CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value());
} }
namespace {
Handle<JSFunction> CreateFunctionFromCode(int parameter_count_with_receiver,
Handle<Code> code) {
Isolate* isolate = code->GetIsolate();
Handle<String> name = isolate->factory()->InternalizeUtf8String("test");
Handle<JSFunction> function =
isolate->factory()->NewFunctionWithoutPrototype(name, code);
function->shared()->set_internal_formal_parameter_count(
parameter_count_with_receiver - 1); // Implicit undefined receiver.
return function;
}
} // namespace
TEST(JSFunction) { TEST(JSFunction) {
const int kNumParams = 3; // Receiver, left, right. const int kNumParams = 3; // Receiver, left, right.
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
CodeStubAssemblerTester m(isolate, kNumParams); CodeStubAssemblerTester m(isolate, kNumParams);
m.Return(m.SmiTag(m.Int32Add(m.SmiToWord32(m.Parameter(1)), m.Return(m.SmiFromWord32(m.Int32Add(m.SmiToWord32(m.Parameter(1)),
m.SmiToWord32(m.Parameter(2))))); m.SmiToWord32(m.Parameter(2)))));
Handle<Code> code = m.GenerateCode();
Handle<JSFunction> function = CreateFunctionFromCode(kNumParams, code);
Handle<Object> args[] = {Handle<Smi>(Smi::FromInt(23), isolate),
Handle<Smi>(Smi::FromInt(34), isolate)};
MaybeHandle<Object> result =
Execution::Call(isolate, function, isolate->factory()->undefined_value(),
arraysize(args), args);
CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SplitEdgeBranchMerge) { Handle<Code> code = m.GenerateCode();
Isolate* isolate(CcTest::InitIsolateOnce()); FunctionTester ft(code, kNumParams);
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Label l1(&m), merge(&m);
m.Branch(m.Int32Constant(1), &l1, &merge);
m.Bind(&l1);
m.Goto(&merge);
m.Bind(&merge);
USE(m.GenerateCode());
}
TEST(SplitEdgeSwitchMerge) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Label l1(&m), l2(&m), l3(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
m.Branch(m.Int32Constant(1), &l3, &l1);
m.Bind(&l3);
m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
m.Bind(&l1);
m.Goto(&l2);
m.Bind(&l2);
m.Goto(&default_label);
m.Bind(&default_label);
USE(m.GenerateCode());
}
TEST(TestToConstant) { MaybeHandle<Object> result = ft.Call(isolate->factory()->undefined_value(),
Isolate* isolate(CcTest::InitIsolateOnce()); handle(Smi::FromInt(23), isolate),
VoidDescriptor descriptor(isolate); handle(Smi::FromInt(34), isolate));
CodeStubAssemblerTester m(isolate, descriptor); CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
int32_t value32;
int64_t value64;
Node* a = m.Int32Constant(5);
CHECK(m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.Int64Constant(static_cast<int64_t>(1) << 32);
CHECK(!m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.Int64Constant(13);
CHECK(m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.UndefinedConstant();
CHECK(!m.ToInt32Constant(a, value32));
CHECK(!m.ToInt64Constant(a, value64));
a = m.UndefinedConstant();
CHECK(!m.ToInt32Constant(a, value32));
CHECK(!m.ToInt64Constant(a, value64));
} }
TEST(ComputeIntegerHash) { TEST(ComputeIntegerHash) {
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 2; const int kNumParams = 2;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
m.Return(m.SmiFromWord32(m.ComputeIntegerHash( m.Return(m.SmiFromWord32(m.ComputeIntegerHash(
m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1))))); m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1)))));
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
Handle<Smi> hash_seed = isolate->factory()->hash_seed(); Handle<Smi> hash_seed = isolate->factory()->hash_seed();
...@@ -440,8 +121,8 @@ TEST(TryToName) { ...@@ -440,8 +121,8 @@ TEST(TryToName) {
typedef CodeStubAssembler::Variable Variable; typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 3; const int kNumParams = 3;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
{ {
...@@ -481,7 +162,7 @@ TEST(TryToName) { ...@@ -481,7 +162,7 @@ TEST(TryToName) {
} }
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate); Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate);
Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate); Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate);
...@@ -539,8 +220,8 @@ void TestNameDictionaryLookup() { ...@@ -539,8 +220,8 @@ void TestNameDictionaryLookup() {
typedef CodeStubAssembler::Variable Variable; typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4; const int kNumParams = 4;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound }; enum Result { kFound, kNotFound };
{ {
...@@ -575,7 +256,7 @@ void TestNameDictionaryLookup() { ...@@ -575,7 +256,7 @@ void TestNameDictionaryLookup() {
} }
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate); Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
...@@ -643,8 +324,8 @@ void TestNumberDictionaryLookup() { ...@@ -643,8 +324,8 @@ void TestNumberDictionaryLookup() {
typedef CodeStubAssembler::Variable Variable; typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4; const int kNumParams = 4;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound }; enum Result { kFound, kNotFound };
{ {
...@@ -679,7 +360,7 @@ void TestNumberDictionaryLookup() { ...@@ -679,7 +360,7 @@ void TestNumberDictionaryLookup() {
} }
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate); Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
...@@ -749,8 +430,8 @@ TEST(TryLookupProperty) { ...@@ -749,8 +430,8 @@ TEST(TryLookupProperty) {
typedef CodeStubAssembler::Label Label; typedef CodeStubAssembler::Label Label;
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4; const int kNumParams = 4;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound, kBailout }; enum Result { kFound, kNotFound, kBailout };
{ {
...@@ -789,7 +470,7 @@ TEST(TryLookupProperty) { ...@@ -789,7 +470,7 @@ TEST(TryLookupProperty) {
} }
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate); Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
...@@ -896,8 +577,8 @@ TEST(TryLookupElement) { ...@@ -896,8 +577,8 @@ TEST(TryLookupElement) {
typedef CodeStubAssembler::Label Label; typedef CodeStubAssembler::Label Label;
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4; const int kNumParams = 4;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound, kBailout }; enum Result { kFound, kNotFound, kBailout };
{ {
...@@ -936,7 +617,7 @@ TEST(TryLookupElement) { ...@@ -936,7 +617,7 @@ TEST(TryLookupElement) {
} }
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<Object> smi0(Smi::FromInt(0), isolate); Handle<Object> smi0(Smi::FromInt(0), isolate);
...@@ -1137,8 +818,8 @@ namespace { ...@@ -1137,8 +818,8 @@ namespace {
void TestStubCacheOffsetCalculation(StubCache::Table table, void TestStubCacheOffsetCalculation(StubCache::Table table,
Code::Kind handler_kind) { Code::Kind handler_kind) {
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 2; const int kNumParams = 2;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
Code::Flags code_flags = Code::Flags code_flags =
Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(handler_kind)); Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(handler_kind));
...@@ -1157,7 +838,7 @@ void TestStubCacheOffsetCalculation(StubCache::Table table, ...@@ -1157,7 +838,7 @@ void TestStubCacheOffsetCalculation(StubCache::Table table,
} }
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<Name> names[] = { Handle<Name> names[] = {
...@@ -1244,8 +925,8 @@ TEST(TryProbeStubCache) { ...@@ -1244,8 +925,8 @@ TEST(TryProbeStubCache) {
typedef CodeStubAssembler::Label Label; typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable; typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 3; const int kNumParams = 3;
CodeStubAssemblerTester m(isolate, param_count); CodeStubAssemblerTester m(isolate, kNumParams);
Code::Flags flags_to_query = Code::Flags flags_to_query =
Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC)); Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC));
...@@ -1281,7 +962,7 @@ TEST(TryProbeStubCache) { ...@@ -1281,7 +962,7 @@ TEST(TryProbeStubCache) {
} }
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count); FunctionTester ft(code, kNumParams);
std::vector<Handle<Name>> names; std::vector<Handle<Name>> names;
std::vector<Handle<JSObject>> receivers; std::vector<Handle<JSObject>> receivers;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment