2015-07-23 14:21:26 +00:00
|
|
|
// 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 "test/unittests/compiler/interpreter-assembler-unittest.h"
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
#include "src/code-factory.h"
|
2015-07-23 14:21:26 +00:00
|
|
|
#include "src/compiler/graph.h"
|
|
|
|
#include "src/compiler/node.h"
|
2015-09-02 13:03:06 +00:00
|
|
|
#include "src/interface-descriptors.h"
|
2015-09-01 10:30:40 +00:00
|
|
|
#include "src/isolate.h"
|
2015-07-23 14:21:26 +00:00
|
|
|
#include "test/unittests/compiler/compiler-test-utils.h"
|
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
|
|
|
|
2015-08-18 12:41:41 +00:00
|
|
|
using ::testing::_;
|
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
|
|
|
const interpreter::Bytecode kBytecodes[] = {
|
2015-07-30 13:56:47 +00:00
|
|
|
#define DEFINE_BYTECODE(Name, ...) interpreter::Bytecode::k##Name,
|
2015-07-23 14:21:26 +00:00
|
|
|
BYTECODE_LIST(DEFINE_BYTECODE)
|
|
|
|
#undef DEFINE_BYTECODE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-08-24 10:25:34 +00:00
|
|
|
Matcher<Node*> IsIntPtrConstant(const intptr_t value) {
|
|
|
|
return kPointerSize == 8 ? IsInt64Constant(static_cast<int64_t>(value))
|
|
|
|
: IsInt32Constant(static_cast<int32_t>(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*> IsIntPtrAdd(const Matcher<Node*>& lhs_matcher,
|
|
|
|
const Matcher<Node*>& rhs_matcher) {
|
|
|
|
return kPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher)
|
|
|
|
: IsInt32Add(lhs_matcher, rhs_matcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Matcher<Node*> IsIntPtrSub(const Matcher<Node*>& lhs_matcher,
|
|
|
|
const Matcher<Node*>& rhs_matcher) {
|
|
|
|
return kPointerSize == 8 ? IsInt64Sub(lhs_matcher, rhs_matcher)
|
|
|
|
: IsInt32Sub(lhs_matcher, rhs_matcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Matcher<Node*> IsWordShl(const Matcher<Node*>& lhs_matcher,
|
|
|
|
const Matcher<Node*>& rhs_matcher) {
|
|
|
|
return kPointerSize == 8 ? IsWord64Shl(lhs_matcher, rhs_matcher)
|
|
|
|
: IsWord32Shl(lhs_matcher, rhs_matcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Matcher<Node*> IsWordSar(const Matcher<Node*>& lhs_matcher,
|
|
|
|
const Matcher<Node*>& rhs_matcher) {
|
|
|
|
return kPointerSize == 8 ? IsWord64Sar(lhs_matcher, rhs_matcher)
|
|
|
|
: IsWord32Sar(lhs_matcher, rhs_matcher);
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 17:22:58 +00:00
|
|
|
Matcher<Node*> IsWordOr(const Matcher<Node*>& lhs_matcher,
|
|
|
|
const Matcher<Node*>& rhs_matcher) {
|
|
|
|
return kPointerSize == 8 ? IsWord64Or(lhs_matcher, rhs_matcher)
|
|
|
|
: IsWord32Or(lhs_matcher, rhs_matcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoad(
|
|
|
|
const Matcher<LoadRepresentation>& rep_matcher,
|
|
|
|
const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher) {
|
|
|
|
return ::i::compiler::IsLoad(rep_matcher, base_matcher, index_matcher,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsStore(
|
|
|
|
const Matcher<StoreRepresentation>& rep_matcher,
|
|
|
|
const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher,
|
|
|
|
const Matcher<Node*>& value_matcher) {
|
|
|
|
return ::i::compiler::IsStore(rep_matcher, base_matcher, index_matcher,
|
|
|
|
value_matcher, graph()->start(),
|
|
|
|
graph()->start());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-02 13:03:06 +00:00
|
|
|
template <class... A>
|
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsCall(
|
|
|
|
const Matcher<const CallDescriptor*>& descriptor_matcher, A... args) {
|
|
|
|
return ::i::compiler::IsCall(descriptor_matcher, args..., graph()->start(),
|
|
|
|
graph()->start());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsBytecodeOperand(
|
2015-10-01 17:22:58 +00:00
|
|
|
int offset) {
|
2015-08-18 15:29:21 +00:00
|
|
|
return IsLoad(
|
|
|
|
kMachUint8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
2015-10-01 17:22:58 +00:00
|
|
|
IsInt32Constant(offset)));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::
|
2015-10-01 17:22:58 +00:00
|
|
|
IsBytecodeOperandSignExtended(int offset) {
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*> load_matcher = IsLoad(
|
|
|
|
kMachInt8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
2015-10-01 17:22:58 +00:00
|
|
|
IsInt32Constant(offset)));
|
2015-08-18 15:29:21 +00:00
|
|
|
if (kPointerSize == 8) {
|
|
|
|
load_matcher = IsChangeInt32ToInt64(load_matcher);
|
|
|
|
}
|
|
|
|
return load_matcher;
|
2015-07-30 11:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 17:22:58 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsBytecodeOperandShort(
|
|
|
|
int offset) {
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
return IsLoad(
|
|
|
|
kMachUint16, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
|
|
|
IsInt32Constant(offset)));
|
|
|
|
} else {
|
|
|
|
Matcher<Node*> first_byte = IsLoad(
|
|
|
|
kMachUint8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
|
|
|
IsInt32Constant(offset)));
|
|
|
|
Matcher<Node*> second_byte = IsLoad(
|
|
|
|
kMachUint8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
|
|
|
IsInt32Constant(offset + 1)));
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
|
|
|
return IsWordOr(IsWordShl(second_byte, IsInt32Constant(kBitsPerByte)),
|
|
|
|
first_byte);
|
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
|
|
|
return IsWordOr(IsWordShl(first_byte, IsInt32Constant(kBitsPerByte)),
|
|
|
|
second_byte);
|
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, Dispatch) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
m.Dispatch();
|
2015-12-03 13:29:27 +00:00
|
|
|
Graph* graph = m.graph();
|
2015-07-23 14:21:26 +00:00
|
|
|
|
|
|
|
Node* end = graph->end();
|
|
|
|
EXPECT_EQ(1, end->InputCount());
|
|
|
|
Node* tail_call_node = end->InputAt(0);
|
|
|
|
|
2015-07-30 08:18:23 +00:00
|
|
|
Matcher<Node*> next_bytecode_offset_matcher =
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
2015-07-23 14:21:26 +00:00
|
|
|
IsInt32Constant(interpreter::Bytecodes::Size(bytecode)));
|
2015-07-30 08:18:23 +00:00
|
|
|
Matcher<Node*> target_bytecode_matcher = m.IsLoad(
|
|
|
|
kMachUint8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
next_bytecode_offset_matcher);
|
2015-07-23 14:21:26 +00:00
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
kMachPtr, IsParameter(Linkage::kInterpreterDispatchTableParameter),
|
|
|
|
IsWord32Shl(target_bytecode_matcher,
|
|
|
|
IsInt32Constant(kPointerSizeLog2)));
|
|
|
|
|
2015-08-07 11:46:07 +00:00
|
|
|
EXPECT_EQ(CallDescriptor::kCallCodeObject, m.call_descriptor()->kind());
|
|
|
|
EXPECT_TRUE(m.call_descriptor()->flags() & CallDescriptor::kCanUseRoots);
|
2015-07-23 14:21:26 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
tail_call_node,
|
|
|
|
IsTailCall(m.call_descriptor(), code_target_matcher,
|
2015-08-18 12:41:41 +00:00
|
|
|
IsParameter(Linkage::kInterpreterAccumulatorParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
2015-07-30 08:18:23 +00:00
|
|
|
next_bytecode_offset_matcher,
|
|
|
|
IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
2015-07-23 14:21:26 +00:00
|
|
|
IsParameter(Linkage::kInterpreterDispatchTableParameter),
|
2015-08-24 10:25:34 +00:00
|
|
|
IsParameter(Linkage::kInterpreterContextParameter),
|
2015-07-23 14:21:26 +00:00
|
|
|
graph->start(), graph->start()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, Jump) {
|
|
|
|
int jump_offsets[] = {-9710, -77, 0, +3, +97109};
|
|
|
|
TRACED_FOREACH(int, jump_offset, jump_offsets) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
m.Jump(m.Int32Constant(jump_offset));
|
2015-12-03 13:29:27 +00:00
|
|
|
Graph* graph = m.graph();
|
2015-09-24 15:20:47 +00:00
|
|
|
Node* end = graph->end();
|
|
|
|
EXPECT_EQ(1, end->InputCount());
|
|
|
|
Node* tail_call_node = end->InputAt(0);
|
|
|
|
|
|
|
|
Matcher<Node*> next_bytecode_offset_matcher =
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
|
|
|
IsInt32Constant(jump_offset));
|
|
|
|
Matcher<Node*> target_bytecode_matcher = m.IsLoad(
|
|
|
|
kMachUint8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
next_bytecode_offset_matcher);
|
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
kMachPtr, IsParameter(Linkage::kInterpreterDispatchTableParameter),
|
|
|
|
IsWord32Shl(target_bytecode_matcher,
|
|
|
|
IsInt32Constant(kPointerSizeLog2)));
|
|
|
|
|
|
|
|
EXPECT_EQ(CallDescriptor::kCallCodeObject, m.call_descriptor()->kind());
|
|
|
|
EXPECT_TRUE(m.call_descriptor()->flags() & CallDescriptor::kCanUseRoots);
|
|
|
|
EXPECT_THAT(
|
|
|
|
tail_call_node,
|
|
|
|
IsTailCall(m.call_descriptor(), code_target_matcher,
|
|
|
|
IsParameter(Linkage::kInterpreterAccumulatorParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
|
|
|
next_bytecode_offset_matcher,
|
|
|
|
IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterDispatchTableParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterContextParameter),
|
|
|
|
graph->start(), graph->start()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, JumpIfWordEqual) {
|
|
|
|
static const int kJumpIfTrueOffset = 73;
|
|
|
|
|
|
|
|
MachineOperatorBuilder machine(zone());
|
|
|
|
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* lhs = m.IntPtrConstant(0);
|
|
|
|
Node* rhs = m.IntPtrConstant(1);
|
|
|
|
m.JumpIfWordEqual(lhs, rhs, m.Int32Constant(kJumpIfTrueOffset));
|
2015-12-03 13:29:27 +00:00
|
|
|
Graph* graph = m.graph();
|
2015-09-24 15:20:47 +00:00
|
|
|
Node* end = graph->end();
|
|
|
|
EXPECT_EQ(2, end->InputCount());
|
|
|
|
|
|
|
|
int jump_offsets[] = {kJumpIfTrueOffset,
|
|
|
|
interpreter::Bytecodes::Size(bytecode)};
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(jump_offsets)); i++) {
|
|
|
|
Matcher<Node*> next_bytecode_offset_matcher =
|
|
|
|
IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
|
|
|
IsInt32Constant(jump_offsets[i]));
|
|
|
|
Matcher<Node*> target_bytecode_matcher = m.IsLoad(
|
|
|
|
kMachUint8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
next_bytecode_offset_matcher);
|
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
kMachPtr, IsParameter(Linkage::kInterpreterDispatchTableParameter),
|
|
|
|
IsWord32Shl(target_bytecode_matcher,
|
|
|
|
IsInt32Constant(kPointerSizeLog2)));
|
|
|
|
EXPECT_THAT(
|
|
|
|
end->InputAt(i),
|
|
|
|
IsTailCall(m.call_descriptor(), code_target_matcher,
|
|
|
|
IsParameter(Linkage::kInterpreterAccumulatorParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
|
|
|
next_bytecode_offset_matcher,
|
|
|
|
IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterDispatchTableParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterContextParameter),
|
|
|
|
graph->start(), graph->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(oth): test control flow paths.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-30 11:36:26 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, Return) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
m.Return();
|
2015-12-03 13:29:27 +00:00
|
|
|
Graph* graph = m.graph();
|
2015-07-30 11:36:26 +00:00
|
|
|
|
|
|
|
Node* end = graph->end();
|
|
|
|
EXPECT_EQ(1, end->InputCount());
|
|
|
|
Node* tail_call_node = end->InputAt(0);
|
|
|
|
|
2015-08-07 11:46:07 +00:00
|
|
|
EXPECT_EQ(CallDescriptor::kCallCodeObject, m.call_descriptor()->kind());
|
|
|
|
EXPECT_TRUE(m.call_descriptor()->flags() & CallDescriptor::kCanUseRoots);
|
2015-08-31 08:24:52 +00:00
|
|
|
Handle<HeapObject> exit_trampoline =
|
|
|
|
isolate()->builtins()->InterpreterExitTrampoline();
|
2015-07-30 11:36:26 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
tail_call_node,
|
|
|
|
IsTailCall(m.call_descriptor(), IsHeapConstant(exit_trampoline),
|
2015-08-18 12:41:41 +00:00
|
|
|
IsParameter(Linkage::kInterpreterAccumulatorParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
2015-07-30 11:36:26 +00:00
|
|
|
IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsParameter(Linkage::kInterpreterDispatchTableParameter),
|
2015-08-24 10:25:34 +00:00
|
|
|
IsParameter(Linkage::kInterpreterContextParameter),
|
2015-07-30 11:36:26 +00:00
|
|
|
graph->start(), graph->start()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-30 13:56:47 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
|
2015-07-23 14:21:26 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2015-07-30 13:56:47 +00:00
|
|
|
int number_of_operands = interpreter::Bytecodes::NumberOfOperands(bytecode);
|
|
|
|
for (int i = 0; i < number_of_operands; i++) {
|
2015-10-01 17:22:58 +00:00
|
|
|
int offset = interpreter::Bytecodes::GetOperandOffset(bytecode, i);
|
2015-08-18 15:29:21 +00:00
|
|
|
switch (interpreter::Bytecodes::GetOperandType(bytecode, i)) {
|
2015-10-01 17:22:58 +00:00
|
|
|
case interpreter::OperandType::kCount8:
|
2015-10-30 11:17:07 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandCount(i), m.IsBytecodeOperand(offset));
|
2015-09-14 10:05:18 +00:00
|
|
|
break;
|
2015-10-01 17:22:58 +00:00
|
|
|
case interpreter::OperandType::kIdx8:
|
2015-10-30 11:17:07 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandIdx(i), m.IsBytecodeOperand(offset));
|
2015-08-28 15:40:52 +00:00
|
|
|
break;
|
2015-08-18 15:29:21 +00:00
|
|
|
case interpreter::OperandType::kImm8:
|
2015-10-30 11:17:07 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandImm(i),
|
2015-10-01 17:22:58 +00:00
|
|
|
m.IsBytecodeOperandSignExtended(offset));
|
|
|
|
break;
|
2015-11-04 09:21:26 +00:00
|
|
|
case interpreter::OperandType::kMaybeReg8:
|
2015-10-01 17:22:58 +00:00
|
|
|
case interpreter::OperandType::kReg8:
|
2015-10-30 11:17:07 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandReg(i),
|
2015-10-01 17:22:58 +00:00
|
|
|
m.IsBytecodeOperandSignExtended(offset));
|
2015-08-18 15:29:21 +00:00
|
|
|
break;
|
2015-11-17 12:18:25 +00:00
|
|
|
case interpreter::OperandType::kCount16:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandCount(i),
|
|
|
|
m.IsBytecodeOperandShort(offset));
|
|
|
|
break;
|
2015-10-01 17:22:58 +00:00
|
|
|
case interpreter::OperandType::kIdx16:
|
2015-10-30 11:17:07 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandIdx(i),
|
2015-10-01 17:22:58 +00:00
|
|
|
m.IsBytecodeOperandShort(offset));
|
2015-08-18 15:29:21 +00:00
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
2015-08-18 12:41:41 +00:00
|
|
|
}
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-18 12:41:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, GetSetAccumulator) {
|
2015-07-23 14:21:26 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2015-08-18 12:41:41 +00:00
|
|
|
// Should be incoming accumulator if not set.
|
|
|
|
EXPECT_THAT(m.GetAccumulator(),
|
|
|
|
IsParameter(Linkage::kInterpreterAccumulatorParameter));
|
|
|
|
|
|
|
|
// Should be set by SedtAccumulator.
|
|
|
|
Node* accumulator_value_1 = m.Int32Constant(0xdeadbeef);
|
|
|
|
m.SetAccumulator(accumulator_value_1);
|
|
|
|
EXPECT_THAT(m.GetAccumulator(), accumulator_value_1);
|
|
|
|
Node* accumulator_value_2 = m.Int32Constant(42);
|
|
|
|
m.SetAccumulator(accumulator_value_2);
|
|
|
|
EXPECT_THAT(m.GetAccumulator(), accumulator_value_2);
|
|
|
|
|
|
|
|
// Should be passed to next bytecode handler on dispatch.
|
|
|
|
m.Dispatch();
|
2015-12-03 13:29:27 +00:00
|
|
|
Graph* graph = m.graph();
|
2015-08-18 12:41:41 +00:00
|
|
|
|
|
|
|
Node* end = graph->end();
|
|
|
|
EXPECT_EQ(1, end->InputCount());
|
|
|
|
Node* tail_call_node = end->InputAt(0);
|
|
|
|
|
|
|
|
EXPECT_THAT(tail_call_node,
|
|
|
|
IsTailCall(m.call_descriptor(), _, accumulator_value_2, _, _, _,
|
|
|
|
_, graph->start(), graph->start()));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, RegisterLocation) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* reg_index_node = m.Int32Constant(44);
|
|
|
|
Node* reg_location_node = m.RegisterLocation(reg_index_node);
|
|
|
|
EXPECT_THAT(
|
|
|
|
reg_location_node,
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
|
|
|
IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-18 12:41:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) {
|
2015-07-23 14:21:26 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2015-08-18 12:41:41 +00:00
|
|
|
Node* reg_index_node = m.Int32Constant(44);
|
|
|
|
Node* load_reg_node = m.LoadRegister(reg_index_node);
|
|
|
|
EXPECT_THAT(
|
|
|
|
load_reg_node,
|
2015-08-24 10:25:34 +00:00
|
|
|
m.IsLoad(kMachAnyTagged,
|
2015-08-18 12:41:41 +00:00
|
|
|
IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
|
|
|
IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2))));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, StoreRegister) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* store_value = m.Int32Constant(0xdeadbeef);
|
|
|
|
Node* reg_index_node = m.Int32Constant(44);
|
|
|
|
Node* store_reg_node = m.StoreRegister(store_value, reg_index_node);
|
|
|
|
EXPECT_THAT(
|
|
|
|
store_reg_node,
|
2015-08-24 10:25:34 +00:00
|
|
|
m.IsStore(StoreRepresentation(kMachAnyTagged, kNoWriteBarrier),
|
2015-08-18 12:41:41 +00:00
|
|
|
IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
|
|
|
IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2)),
|
2015-07-23 14:21:26 +00:00
|
|
|
store_value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 15:29:21 +00:00
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, SmiTag) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* value = m.Int32Constant(44);
|
|
|
|
EXPECT_THAT(m.SmiTag(value),
|
|
|
|
IsWordShl(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize)));
|
|
|
|
EXPECT_THAT(m.SmiUntag(value),
|
|
|
|
IsWordSar(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-24 10:25:34 +00:00
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, IntPtrAdd) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* a = m.Int32Constant(0);
|
|
|
|
Node* b = m.Int32Constant(1);
|
|
|
|
Node* add = m.IntPtrAdd(a, b);
|
|
|
|
EXPECT_THAT(add, IsIntPtrAdd(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, IntPtrSub) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* a = m.Int32Constant(0);
|
|
|
|
Node* b = m.Int32Constant(1);
|
|
|
|
Node* add = m.IntPtrSub(a, b);
|
|
|
|
EXPECT_THAT(add, IsIntPtrSub(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, WordShl) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* a = m.Int32Constant(0);
|
|
|
|
Node* add = m.WordShl(a, 10);
|
|
|
|
EXPECT_THAT(add, IsWordShl(a, IsInt32Constant(10)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-28 15:40:52 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* index = m.Int32Constant(2);
|
|
|
|
Node* load_constant = m.LoadConstantPoolEntry(index);
|
|
|
|
Matcher<Node*> constant_pool_matcher = m.IsLoad(
|
|
|
|
kMachAnyTagged,
|
|
|
|
IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
|
|
|
|
IsIntPtrConstant(BytecodeArray::kConstantPoolOffset - kHeapObjectTag));
|
|
|
|
EXPECT_THAT(
|
|
|
|
load_constant,
|
|
|
|
m.IsLoad(kMachAnyTagged, constant_pool_matcher,
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
|
|
|
|
IsWordShl(index, IsInt32Constant(kPointerSizeLog2)))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-29 12:06:00 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadFixedArrayElement) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
int index = 3;
|
|
|
|
Node* fixed_array = m.IntPtrConstant(0xdeadbeef);
|
|
|
|
Node* load_element = m.LoadFixedArrayElement(fixed_array, index);
|
|
|
|
EXPECT_THAT(
|
|
|
|
load_element,
|
|
|
|
m.IsLoad(kMachAnyTagged, fixed_array,
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
|
|
|
|
IsWordShl(IsInt32Constant(index),
|
|
|
|
IsInt32Constant(kPointerSizeLog2)))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadObjectField) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* object = m.IntPtrConstant(0xdeadbeef);
|
|
|
|
int offset = 16;
|
|
|
|
Node* load_field = m.LoadObjectField(object, offset);
|
|
|
|
EXPECT_THAT(load_field,
|
|
|
|
m.IsLoad(kMachAnyTagged, object,
|
|
|
|
IsIntPtrConstant(offset - kHeapObjectTag)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-24 10:25:34 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadContextSlot) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2015-10-07 21:18:58 +00:00
|
|
|
Node* context = m.Int32Constant(1);
|
|
|
|
Node* slot_index = m.Int32Constant(22);
|
|
|
|
Node* load_context_slot = m.LoadContextSlot(context, slot_index);
|
|
|
|
|
|
|
|
Matcher<Node*> offset =
|
|
|
|
IsIntPtrAdd(IsWordShl(slot_index, IsInt32Constant(kPointerSizeLog2)),
|
|
|
|
IsInt32Constant(Context::kHeaderSize - kHeapObjectTag));
|
|
|
|
EXPECT_THAT(load_context_slot, m.IsLoad(kMachAnyTagged, context, offset));
|
2015-08-24 10:25:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 11:31:09 +00:00
|
|
|
|
2015-10-16 15:29:07 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, StoreContextSlot) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* context = m.Int32Constant(1);
|
|
|
|
Node* slot_index = m.Int32Constant(22);
|
|
|
|
Node* value = m.Int32Constant(100);
|
|
|
|
Node* store_context_slot = m.StoreContextSlot(context, slot_index, value);
|
|
|
|
|
|
|
|
Matcher<Node*> offset =
|
|
|
|
IsIntPtrAdd(IsWordShl(slot_index, IsInt32Constant(kPointerSizeLog2)),
|
|
|
|
IsInt32Constant(Context::kHeaderSize - kHeapObjectTag));
|
2015-10-26 18:11:23 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
store_context_slot,
|
|
|
|
m.IsStore(StoreRepresentation(kMachAnyTagged, kFullWriteBarrier),
|
|
|
|
context, offset, value));
|
2015-10-16 15:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime2) {
|
2015-08-25 11:31:09 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2015-09-10 13:04:15 +00:00
|
|
|
Node* arg1 = m.Int32Constant(2);
|
|
|
|
Node* arg2 = m.Int32Constant(3);
|
|
|
|
Node* call_runtime = m.CallRuntime(Runtime::kAdd, arg1, arg2);
|
|
|
|
EXPECT_THAT(call_runtime,
|
|
|
|
m.IsCall(_, _, arg1, arg2, _, IsInt32Constant(2),
|
|
|
|
IsParameter(Linkage::kInterpreterContextParameter)));
|
2015-09-02 13:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Callable builtin = CodeFactory::InterpreterCEntry(isolate());
|
|
|
|
|
|
|
|
Node* function_id = m.Int32Constant(0);
|
|
|
|
Node* first_arg = m.Int32Constant(1);
|
|
|
|
Node* arg_count = m.Int32Constant(2);
|
|
|
|
|
|
|
|
Matcher<Node*> function_table = IsExternalConstant(
|
|
|
|
ExternalReference::runtime_function_table_address(isolate()));
|
|
|
|
Matcher<Node*> function = IsIntPtrAdd(
|
|
|
|
function_table,
|
|
|
|
IsInt32Mul(function_id, IsInt32Constant(sizeof(Runtime::Function))));
|
|
|
|
Matcher<Node*> function_entry =
|
|
|
|
m.IsLoad(kMachPtr, function,
|
|
|
|
IsInt32Constant(offsetof(Runtime::Function, entry)));
|
|
|
|
|
|
|
|
Node* call_runtime = m.CallRuntime(function_id, first_arg, arg_count);
|
|
|
|
EXPECT_THAT(call_runtime,
|
|
|
|
m.IsCall(_, IsHeapConstant(builtin.code()), arg_count,
|
|
|
|
first_arg, function_entry,
|
|
|
|
IsParameter(Linkage::kInterpreterContextParameter)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-02 13:03:06 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallIC) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
LoadWithVectorDescriptor descriptor(isolate());
|
|
|
|
Node* target = m.Int32Constant(1);
|
|
|
|
Node* arg1 = m.Int32Constant(2);
|
|
|
|
Node* arg2 = m.Int32Constant(3);
|
|
|
|
Node* arg3 = m.Int32Constant(4);
|
|
|
|
Node* arg4 = m.Int32Constant(5);
|
|
|
|
Node* call_ic = m.CallIC(descriptor, target, arg1, arg2, arg3, arg4);
|
|
|
|
EXPECT_THAT(call_ic,
|
|
|
|
m.IsCall(_, target, arg1, arg2, arg3, arg4,
|
|
|
|
IsParameter(Linkage::kInterpreterContextParameter)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallJS) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2015-10-02 18:13:41 +00:00
|
|
|
Callable builtin = CodeFactory::InterpreterPushArgsAndCall(isolate());
|
2015-09-14 10:05:18 +00:00
|
|
|
Node* function = m.Int32Constant(0);
|
|
|
|
Node* first_arg = m.Int32Constant(1);
|
|
|
|
Node* arg_count = m.Int32Constant(2);
|
|
|
|
Node* call_js = m.CallJS(function, first_arg, arg_count);
|
|
|
|
EXPECT_THAT(
|
|
|
|
call_js,
|
|
|
|
m.IsCall(_, IsHeapConstant(builtin.code()), arg_count, first_arg,
|
|
|
|
function, IsParameter(Linkage::kInterpreterContextParameter)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-02 13:03:06 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadTypeFeedbackVector) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* feedback_vector = m.LoadTypeFeedbackVector();
|
|
|
|
|
|
|
|
Matcher<Node*> load_function_matcher = m.IsLoad(
|
|
|
|
kMachAnyTagged, IsParameter(Linkage::kInterpreterRegisterFileParameter),
|
|
|
|
IsIntPtrConstant(
|
|
|
|
InterpreterFrameConstants::kFunctionFromRegisterPointer));
|
|
|
|
Matcher<Node*> load_shared_function_info_matcher =
|
|
|
|
m.IsLoad(kMachAnyTagged, load_function_matcher,
|
|
|
|
IsIntPtrConstant(JSFunction::kSharedFunctionInfoOffset -
|
|
|
|
kHeapObjectTag));
|
|
|
|
|
|
|
|
EXPECT_THAT(
|
|
|
|
feedback_vector,
|
|
|
|
m.IsLoad(kMachAnyTagged, load_shared_function_info_matcher,
|
|
|
|
IsIntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset -
|
|
|
|
kHeapObjectTag)));
|
2015-08-25 11:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|