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.
|
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
#include "test/unittests/interpreter/interpreter-assembler-unittest.h"
|
2015-07-23 14:21:26 +00:00
|
|
|
|
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 {
|
2016-02-10 16:38:49 +00:00
|
|
|
|
|
|
|
using namespace compiler;
|
|
|
|
|
|
|
|
namespace interpreter {
|
2015-07-23 14:21:26 +00:00
|
|
|
|
|
|
|
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) {
|
2015-12-10 17:07:15 +00:00
|
|
|
return ::i::compiler::IsLoad(rep_matcher, base_matcher, index_matcher, _, _);
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2015-12-10 17:07:15 +00:00
|
|
|
value_matcher, _, _);
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedByteOperand(
|
2015-10-01 17:22:58 +00:00
|
|
|
int offset) {
|
2015-08-18 15:29:21 +00:00
|
|
|
return IsLoad(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::Uint8(),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrConstant(offset)));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedByteOperand(
|
|
|
|
int offset) {
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*> load_matcher = IsLoad(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::Int8(),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrConstant(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*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedShortOperand(
|
2015-10-01 17:22:58 +00:00
|
|
|
int offset) {
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
return IsLoad(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::Uint16(),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrConstant(offset)));
|
2015-10-01 17:22:58 +00:00
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = -1;
|
|
|
|
const int kMsbOffset = 1;
|
2015-10-01 17:22:58 +00:00
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = 1;
|
|
|
|
const int kMsbOffset = 0;
|
2015-10-01 17:22:58 +00:00
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*> bytes[2];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
MachineType::Uint8(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
|
|
|
IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
|
|
|
}
|
|
|
|
return IsWord32Or(IsWord32Shl(bytes[0], IsInt32Constant(kBitsPerByte)),
|
|
|
|
bytes[1]);
|
2015-10-01 17:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand(
|
|
|
|
int offset) {
|
2016-01-04 17:38:17 +00:00
|
|
|
Matcher<Node*> load_matcher;
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
load_matcher = IsLoad(
|
|
|
|
MachineType::Int16(),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrConstant(offset)));
|
2016-01-04 17:38:17 +00:00
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = -1;
|
|
|
|
const int kMsbOffset = 1;
|
2016-01-04 17:38:17 +00:00
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = 1;
|
|
|
|
const int kMsbOffset = 0;
|
2016-01-04 17:38:17 +00:00
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*> bytes[2];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
(i == 0) ? MachineType::Int8() : MachineType::Uint8(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
|
|
|
IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
|
|
|
}
|
|
|
|
load_matcher = IsWord32Or(
|
|
|
|
IsWord32Shl(bytes[0], IsInt32Constant(kBitsPerByte)), bytes[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kPointerSize == 8) {
|
|
|
|
load_matcher = IsChangeInt32ToInt64(load_matcher);
|
|
|
|
}
|
|
|
|
return load_matcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedQuadOperand(
|
|
|
|
int offset) {
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
return IsLoad(
|
|
|
|
MachineType::Uint32(),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-21 17:08:21 +00:00
|
|
|
IsIntPtrConstant(offset)));
|
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
|
|
|
const int kStep = -1;
|
|
|
|
const int kMsbOffset = 3;
|
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
|
|
|
const int kStep = 1;
|
|
|
|
const int kMsbOffset = 0;
|
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
|
|
|
Matcher<Node*> bytes[4];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
MachineType::Uint8(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
|
|
|
IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
|
|
|
}
|
|
|
|
return IsWord32Or(
|
|
|
|
IsWord32Shl(bytes[0], IsInt32Constant(3 * kBitsPerByte)),
|
|
|
|
IsWord32Or(
|
|
|
|
IsWord32Shl(bytes[1], IsInt32Constant(2 * kBitsPerByte)),
|
|
|
|
IsWord32Or(IsWord32Shl(bytes[2], IsInt32Constant(1 * kBitsPerByte)),
|
|
|
|
bytes[3])));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand(
|
|
|
|
int offset) {
|
|
|
|
Matcher<Node*> load_matcher;
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
load_matcher = IsLoad(
|
|
|
|
MachineType::Int32(),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-21 17:08:21 +00:00
|
|
|
IsIntPtrConstant(offset)));
|
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
|
|
|
const int kStep = -1;
|
|
|
|
int kMsbOffset = 3;
|
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
|
|
|
const int kStep = 1;
|
|
|
|
int kMsbOffset = 0;
|
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
|
|
|
Matcher<Node*> bytes[4];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
(i == 0) ? MachineType::Int8() : MachineType::Uint8(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsIntPtrAdd(
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
|
|
|
IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
|
|
|
}
|
|
|
|
load_matcher = IsWord32Or(
|
|
|
|
IsWord32Shl(bytes[0], IsInt32Constant(3 * kBitsPerByte)),
|
|
|
|
IsWord32Or(
|
|
|
|
IsWord32Shl(bytes[1], IsInt32Constant(2 * kBitsPerByte)),
|
|
|
|
IsWord32Or(IsWord32Shl(bytes[2], IsInt32Constant(1 * kBitsPerByte)),
|
|
|
|
bytes[3])));
|
2016-01-04 17:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (kPointerSize == 8) {
|
|
|
|
load_matcher = IsChangeInt32ToInt64(load_matcher);
|
|
|
|
}
|
|
|
|
return load_matcher;
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedOperand(
|
|
|
|
int offset, OperandSize operand_size) {
|
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
|
|
|
return IsSignedByteOperand(offset);
|
|
|
|
case OperandSize::kShort:
|
|
|
|
return IsSignedShortOperand(offset);
|
|
|
|
case OperandSize::kQuad:
|
|
|
|
return IsSignedQuadOperand(offset);
|
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedOperand(
|
|
|
|
int offset, OperandSize operand_size) {
|
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
|
|
|
return IsUnsignedByteOperand(offset);
|
|
|
|
case OperandSize::kShort:
|
|
|
|
return IsUnsignedShortOperand(offset);
|
|
|
|
case OperandSize::kQuad:
|
|
|
|
return IsUnsignedQuadOperand(offset);
|
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
OperandScale operand_scale = OperandScale::kSingle;
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> next_bytecode_offset_matcher = IsIntPtrAdd(
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-21 17:08:21 +00:00
|
|
|
IsIntPtrConstant(
|
|
|
|
interpreter::Bytecodes::Size(bytecode, operand_scale)));
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> target_bytecode_matcher = m.IsLoad(
|
|
|
|
MachineType::Uint8(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
next_bytecode_offset_matcher);
|
2016-03-01 07:08:20 +00:00
|
|
|
if (kPointerSize == 8) {
|
|
|
|
target_bytecode_matcher = IsChangeUint32ToUint64(target_bytecode_matcher);
|
|
|
|
}
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
MachineType::Pointer(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsWordShl(target_bytecode_matcher, IsIntPtrConstant(kPointerSizeLog2)));
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
tail_call_node,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsTailCall(
|
|
|
|
_, code_target_matcher,
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kAccumulatorParameter),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
|
|
|
|
next_bytecode_offset_matcher,
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kContextParameter), _,
|
|
|
|
_));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, Jump) {
|
2016-02-19 18:46:54 +00:00
|
|
|
// If debug code is enabled we emit extra code in Jump.
|
|
|
|
if (FLAG_debug_code) return;
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
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);
|
2016-03-01 07:08:20 +00:00
|
|
|
m.Jump(m.IntPtrConstant(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);
|
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> next_bytecode_offset_matcher = IsIntPtrAdd(
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrConstant(jump_offset));
|
2016-02-19 18:46:54 +00:00
|
|
|
Matcher<Node*> target_bytecode_matcher =
|
|
|
|
m.IsLoad(MachineType::Uint8(), _, next_bytecode_offset_matcher);
|
2016-03-01 07:08:20 +00:00
|
|
|
if (kPointerSize == 8) {
|
|
|
|
target_bytecode_matcher =
|
|
|
|
IsChangeUint32ToUint64(target_bytecode_matcher);
|
|
|
|
}
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
MachineType::Pointer(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsWordShl(target_bytecode_matcher,
|
|
|
|
IsIntPtrConstant(kPointerSizeLog2)));
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
tail_call_node,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsTailCall(
|
|
|
|
_, code_target_matcher,
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kAccumulatorParameter),
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kRegisterFileParameter),
|
2016-02-19 18:46:54 +00:00
|
|
|
next_bytecode_offset_matcher, _,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kDispatchTableParameter),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kContextParameter), _,
|
|
|
|
_));
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, JumpIfWordEqual) {
|
|
|
|
static const int kJumpIfTrueOffset = 73;
|
|
|
|
|
2016-02-19 18:46:54 +00:00
|
|
|
// If debug code is enabled we emit extra code in Jump.
|
|
|
|
if (FLAG_debug_code) return;
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
MachineOperatorBuilder machine(zone());
|
|
|
|
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* lhs = m.IntPtrConstant(0);
|
|
|
|
Node* rhs = m.IntPtrConstant(1);
|
2016-03-01 07:08:20 +00:00
|
|
|
m.JumpIfWordEqual(lhs, rhs, m.IntPtrConstant(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());
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
OperandScale operand_scale = OperandScale::kSingle;
|
|
|
|
int jump_offsets[] = {kJumpIfTrueOffset, interpreter::Bytecodes::Size(
|
|
|
|
bytecode, operand_scale)};
|
2015-09-24 15:20:47 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(jump_offsets)); i++) {
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> next_bytecode_offset_matcher = IsIntPtrAdd(
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrConstant(jump_offsets[i]));
|
2016-02-19 18:46:54 +00:00
|
|
|
Matcher<Node*> target_bytecode_matcher =
|
|
|
|
m.IsLoad(MachineType::Uint8(), _, next_bytecode_offset_matcher);
|
2016-03-01 07:08:20 +00:00
|
|
|
if (kPointerSize == 8) {
|
|
|
|
target_bytecode_matcher =
|
|
|
|
IsChangeUint32ToUint64(target_bytecode_matcher);
|
|
|
|
}
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
MachineType::Pointer(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsWordShl(target_bytecode_matcher,
|
|
|
|
IsIntPtrConstant(kPointerSizeLog2)));
|
2015-09-24 15:20:47 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
end->InputAt(i),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsTailCall(
|
|
|
|
_, code_target_matcher,
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kAccumulatorParameter),
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kRegisterFileParameter),
|
2016-02-19 18:46:54 +00:00
|
|
|
next_bytecode_offset_matcher, _,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kDispatchTableParameter),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kContextParameter), _,
|
|
|
|
_));
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(oth): test control flow paths.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, InterpreterReturn) {
|
2016-02-19 18:46:54 +00:00
|
|
|
// If debug code is enabled we emit extra code in InterpreterReturn.
|
|
|
|
if (FLAG_debug_code) return;
|
|
|
|
|
2015-07-30 11:36:26 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2016-02-10 16:38:49 +00:00
|
|
|
m.InterpreterReturn();
|
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-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,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsTailCall(
|
|
|
|
_, IsHeapConstant(exit_trampoline),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kAccumulatorParameter),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
|
|
|
|
IsParameter(
|
|
|
|
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
|
2016-02-19 18:46:54 +00:00
|
|
|
_,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kContextParameter), _,
|
|
|
|
_));
|
2015-07-30 11:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 13:56:47 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
|
2016-03-21 17:08:21 +00:00
|
|
|
static const OperandScale kOperandScales[] = {
|
|
|
|
OperandScale::kSingle, OperandScale::kDouble, OperandScale::kQuadruple};
|
2015-07-23 14:21:26 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-03-21 17:08:21 +00:00
|
|
|
TRACED_FOREACH(interpreter::OperandScale, operand_scale, kOperandScales) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode, operand_scale);
|
|
|
|
int number_of_operands =
|
|
|
|
interpreter::Bytecodes::NumberOfOperands(bytecode);
|
|
|
|
for (int i = 0; i < number_of_operands; i++) {
|
|
|
|
int offset = interpreter::Bytecodes::GetOperandOffset(bytecode, i,
|
|
|
|
operand_scale);
|
|
|
|
OperandType operand_type =
|
|
|
|
interpreter::Bytecodes::GetOperandType(bytecode, i);
|
|
|
|
OperandSize operand_size =
|
|
|
|
Bytecodes::SizeOfOperand(operand_type, operand_scale);
|
|
|
|
switch (interpreter::Bytecodes::GetOperandType(bytecode, i)) {
|
|
|
|
case interpreter::OperandType::kRegCount:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandCount(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kFlag8:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandFlag(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kIdx:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandIdx(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kImm: {
|
|
|
|
EXPECT_THAT(m.BytecodeOperandImm(i),
|
|
|
|
m.IsSignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case interpreter::OperandType::kMaybeReg:
|
|
|
|
case interpreter::OperandType::kReg:
|
|
|
|
case interpreter::OperandType::kRegOut:
|
|
|
|
case interpreter::OperandType::kRegOutPair:
|
|
|
|
case interpreter::OperandType::kRegOutTriple:
|
|
|
|
case interpreter::OperandType::kRegPair:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandReg(i),
|
|
|
|
m.IsSignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kRuntimeId:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandRuntimeId(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
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.
|
2016-02-10 16:38:49 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
m.GetAccumulator(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kAccumulatorParameter));
|
2015-08-18 12:41:41 +00:00
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
// Should be set by SetAccumulator.
|
2015-08-18 12:41:41 +00:00
|
|
|
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,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsTailCall(_, _, accumulator_value_2, _, _, _, _, _, _));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-23 00:07:21 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, GetSetContext) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Node* context_node = m.Int32Constant(100);
|
|
|
|
m.SetContext(context_node);
|
|
|
|
EXPECT_THAT(m.GetContext(), context_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, RegisterLocation) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* reg_index_node = m.IntPtrConstant(44);
|
2015-09-14 10:05:18 +00:00
|
|
|
Node* reg_location_node = m.RegisterLocation(reg_index_node);
|
|
|
|
EXPECT_THAT(
|
|
|
|
reg_location_node,
|
|
|
|
IsIntPtrAdd(
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsWordShl(reg_index_node, IsIntPtrConstant(kPointerSizeLog2))));
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* reg_index_node = m.IntPtrConstant(44);
|
2015-08-18 12:41:41 +00:00
|
|
|
Node* load_reg_node = m.LoadRegister(reg_index_node);
|
|
|
|
EXPECT_THAT(
|
|
|
|
load_reg_node,
|
2016-02-10 16:38:49 +00:00
|
|
|
m.IsLoad(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsWordShl(reg_index_node, IsIntPtrConstant(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);
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* reg_index_node = m.IntPtrConstant(44);
|
2015-07-23 14:21:26 +00:00
|
|
|
Node* store_reg_node = m.StoreRegister(store_value, reg_index_node);
|
|
|
|
EXPECT_THAT(
|
|
|
|
store_reg_node,
|
2016-02-10 16:38:49 +00:00
|
|
|
m.IsStore(
|
|
|
|
StoreRepresentation(MachineRepresentation::kTagged,
|
|
|
|
kNoWriteBarrier),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsWordShl(reg_index_node, IsIntPtrConstant(kPointerSizeLog2)),
|
2016-02-10 16:38:49 +00:00
|
|
|
store_value));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2016-03-01 07:08:20 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
m.SmiTag(value),
|
|
|
|
IsWordShl(value, IsIntPtrConstant(kSmiShiftSize + kSmiTagSize)));
|
|
|
|
EXPECT_THAT(
|
|
|
|
m.SmiUntag(value),
|
|
|
|
IsWordSar(value, IsIntPtrConstant(kSmiShiftSize + kSmiTagSize)));
|
2015-08-18 15:29:21 +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);
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* a = m.IntPtrConstant(0);
|
2015-09-14 10:05:18 +00:00
|
|
|
Node* add = m.WordShl(a, 10);
|
2016-03-01 07:08:20 +00:00
|
|
|
EXPECT_THAT(add, IsWordShl(a, IsIntPtrConstant(10)));
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:40:52 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* index = m.IntPtrConstant(2);
|
2015-08-28 15:40:52 +00:00
|
|
|
Node* load_constant = m.LoadConstantPoolEntry(index);
|
|
|
|
Matcher<Node*> constant_pool_matcher = m.IsLoad(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::AnyTagged(),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
|
2015-08-28 15:40:52 +00:00
|
|
|
IsIntPtrConstant(BytecodeArray::kConstantPoolOffset - kHeapObjectTag));
|
|
|
|
EXPECT_THAT(
|
|
|
|
load_constant,
|
2015-12-10 09:03:30 +00:00
|
|
|
m.IsLoad(MachineType::AnyTagged(), constant_pool_matcher,
|
2015-08-28 15:40:52 +00:00
|
|
|
IsIntPtrAdd(
|
|
|
|
IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
|
2016-03-01 07:08:20 +00:00
|
|
|
IsWordShl(index, IsIntPtrConstant(kPointerSizeLog2)))));
|
2015-10-29 12:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2015-12-10 09:03:30 +00:00
|
|
|
m.IsLoad(MachineType::AnyTagged(), object,
|
2015-10-29 12:06:00 +00:00
|
|
|
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);
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* context = m.IntPtrConstant(1);
|
|
|
|
Node* slot_index = m.IntPtrConstant(22);
|
2015-10-07 21:18:58 +00:00
|
|
|
Node* load_context_slot = m.LoadContextSlot(context, slot_index);
|
|
|
|
|
|
|
|
Matcher<Node*> offset =
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrAdd(IsWordShl(slot_index, IsIntPtrConstant(kPointerSizeLog2)),
|
|
|
|
IsIntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
2015-12-10 09:03:30 +00:00
|
|
|
EXPECT_THAT(load_context_slot,
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), context, offset));
|
2015-08-24 10:25:34 +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);
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* context = m.IntPtrConstant(1);
|
|
|
|
Node* slot_index = m.IntPtrConstant(22);
|
|
|
|
Node* value = m.SmiConstant(Smi::FromInt(100));
|
2015-10-16 15:29:07 +00:00
|
|
|
Node* store_context_slot = m.StoreContextSlot(context, slot_index, value);
|
|
|
|
|
|
|
|
Matcher<Node*> offset =
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrAdd(IsWordShl(slot_index, IsIntPtrConstant(kPointerSizeLog2)),
|
|
|
|
IsIntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
2015-12-10 09:03:30 +00:00
|
|
|
EXPECT_THAT(store_context_slot,
|
2015-12-11 15:34:00 +00:00
|
|
|
m.IsStore(StoreRepresentation(MachineRepresentation::kTagged,
|
2015-12-10 09:03:30 +00:00
|
|
|
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);
|
2016-02-10 16:38:49 +00:00
|
|
|
Node* context =
|
|
|
|
m.Parameter(InterpreterDispatchDescriptor::kContextParameter);
|
|
|
|
Node* call_runtime = m.CallRuntime(Runtime::kAdd, context, arg1, arg2);
|
2015-12-10 13:36:20 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
call_runtime,
|
|
|
|
IsCall(_, _, arg1, arg2, _, IsInt32Constant(2),
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kContextParameter), _,
|
|
|
|
_));
|
2015-09-02 13:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime) {
|
2016-01-08 15:15:52 +00:00
|
|
|
const int kResultSizes[] = {1, 2};
|
2015-10-02 18:13:41 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-01-08 15:15:52 +00:00
|
|
|
TRACED_FOREACH(int, result_size, kResultSizes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Callable builtin = CodeFactory::InterpreterCEntry(isolate(), result_size);
|
|
|
|
|
|
|
|
Node* function_id = m.Int32Constant(0);
|
|
|
|
Node* first_arg = m.Int32Constant(1);
|
|
|
|
Node* arg_count = m.Int32Constant(2);
|
2016-02-10 16:38:49 +00:00
|
|
|
Node* context =
|
|
|
|
m.Parameter(InterpreterDispatchDescriptor::kContextParameter);
|
2016-01-08 15:15:52 +00:00
|
|
|
|
|
|
|
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(MachineType::Pointer(), function,
|
2016-03-01 07:08:20 +00:00
|
|
|
IsIntPtrConstant(offsetof(Runtime::Function, entry)));
|
2016-01-08 15:15:52 +00:00
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
Node* call_runtime = m.CallRuntimeN(function_id, context, first_arg,
|
|
|
|
arg_count, result_size);
|
2016-01-08 15:15:52 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
call_runtime,
|
|
|
|
IsCall(_, IsHeapConstant(builtin.code()), arg_count, first_arg,
|
|
|
|
function_entry,
|
2016-02-10 16:38:49 +00:00
|
|
|
IsParameter(InterpreterDispatchDescriptor::kContextParameter),
|
|
|
|
_, _));
|
2016-01-08 15:15:52 +00:00
|
|
|
}
|
2015-10-02 18:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallJS) {
|
2016-02-17 15:19:02 +00:00
|
|
|
TailCallMode tail_call_modes[] = {TailCallMode::kDisallow,
|
|
|
|
TailCallMode::kAllow};
|
|
|
|
TRACED_FOREACH(TailCallMode, tail_call_mode, tail_call_modes) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
|
|
|
InterpreterAssemblerForTest m(this, bytecode);
|
|
|
|
Callable builtin =
|
|
|
|
CodeFactory::InterpreterPushArgsAndCall(isolate(), tail_call_mode);
|
|
|
|
Node* function = m.Int32Constant(0);
|
|
|
|
Node* first_arg = m.Int32Constant(1);
|
|
|
|
Node* arg_count = m.Int32Constant(2);
|
|
|
|
Node* context =
|
|
|
|
m.Parameter(InterpreterDispatchDescriptor::kContextParameter);
|
|
|
|
Node* call_js =
|
|
|
|
m.CallJS(function, context, first_arg, arg_count, tail_call_mode);
|
|
|
|
EXPECT_THAT(
|
|
|
|
call_js,
|
|
|
|
IsCall(_, IsHeapConstant(builtin.code()), arg_count, first_arg,
|
|
|
|
function,
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kContextParameter),
|
|
|
|
_, _));
|
|
|
|
}
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
Matcher<Node*> load_function_matcher = m.IsLoad(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
|
|
|
|
IsIntPtrConstant(
|
|
|
|
InterpreterFrameConstants::kFunctionFromRegisterPointer));
|
2016-02-05 10:48:27 +00:00
|
|
|
Matcher<Node*> load_shared_function_info_matcher =
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), load_function_matcher,
|
|
|
|
IsIntPtrConstant(JSFunction::kSharedFunctionInfoOffset -
|
|
|
|
kHeapObjectTag));
|
|
|
|
|
|
|
|
EXPECT_THAT(
|
|
|
|
feedback_vector,
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), load_shared_function_info_matcher,
|
|
|
|
IsIntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset -
|
|
|
|
kHeapObjectTag)));
|
2015-08-25 11:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
} // namespace interpreter
|
2015-07-23 14:21:26 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|