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/codegen/code-factory.h"
|
2015-09-02 13:03:06 +00:00
|
|
|
#include "src/codegen/interface-descriptors.h"
|
2019-03-12 11:43:06 +00:00
|
|
|
#include "src/compiler/node-properties.h"
|
2015-07-23 14:21:26 +00:00
|
|
|
#include "src/compiler/node.h"
|
2015-09-01 10:30:40 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects/objects-inl.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::_;
|
2019-08-22 09:56:32 +00:00
|
|
|
using ::testing::Eq;
|
2017-09-04 10:47:27 +00:00
|
|
|
|
|
|
|
namespace c = v8::internal::compiler;
|
2015-08-18 12:41:41 +00:00
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2016-02-10 16:38:49 +00:00
|
|
|
namespace interpreter {
|
2017-10-18 17:01:45 +00:00
|
|
|
namespace interpreter_assembler_unittest {
|
2015-07-23 14:21:26 +00:00
|
|
|
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState::InterpreterAssemblerTestState(
|
|
|
|
InterpreterAssemblerTest* test, Bytecode bytecode)
|
|
|
|
: compiler::CodeAssemblerState(
|
2018-06-18 15:14:29 +00:00
|
|
|
test->isolate(), test->zone(), InterpreterDispatchDescriptor{},
|
2021-08-12 11:17:00 +00:00
|
|
|
CodeKind::BYTECODE_HANDLER, Bytecodes::ToString(bytecode)) {}
|
2016-11-16 11:48:07 +00:00
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2016-12-12 14:52:30 +00:00
|
|
|
|
2016-04-06 07:57:35 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::
|
|
|
|
~InterpreterAssemblerForTest() {
|
|
|
|
// Tests don't necessarily read and write accumulator but
|
|
|
|
// InterpreterAssembler checks accumulator uses.
|
|
|
|
if (Bytecodes::ReadsAccumulator(bytecode())) {
|
|
|
|
GetAccumulator();
|
|
|
|
}
|
|
|
|
if (Bytecodes::WritesAccumulator(bytecode())) {
|
2019-11-13 15:09:10 +00:00
|
|
|
SetAccumulator(NullConstant());
|
2016-04-06 07:57:35 +00:00
|
|
|
}
|
2021-02-17 14:36:58 +00:00
|
|
|
if (Bytecodes::WritesImplicitRegister(bytecode())) {
|
|
|
|
StoreRegisterForShortStar(NullConstant(), IntPtrConstant(2));
|
|
|
|
}
|
2016-04-06 07:57:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoad(
|
2017-09-04 10:47:27 +00:00
|
|
|
const Matcher<c::LoadRepresentation>& rep_matcher,
|
2021-03-03 09:46:21 +00:00
|
|
|
const Matcher<c::Node*>& base_matcher,
|
2021-08-12 11:17:00 +00:00
|
|
|
const Matcher<c::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
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2019-06-17 08:18:27 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoadFromObject(
|
|
|
|
const Matcher<c::LoadRepresentation>& rep_matcher,
|
2021-03-03 09:46:21 +00:00
|
|
|
const Matcher<c::Node*>& base_matcher,
|
|
|
|
const Matcher<c::Node*>& index_matcher) {
|
2019-06-17 08:18:27 +00:00
|
|
|
return ::i::compiler::IsLoadFromObject(rep_matcher, base_matcher,
|
|
|
|
index_matcher, _, _);
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsStore(
|
2017-09-04 10:47:27 +00:00
|
|
|
const Matcher<c::StoreRepresentation>& rep_matcher,
|
2021-03-03 09:46:21 +00:00
|
|
|
const Matcher<c::Node*>& base_matcher,
|
|
|
|
const Matcher<c::Node*>& index_matcher,
|
|
|
|
const Matcher<c::Node*>& value_matcher) {
|
2015-07-23 14:21:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsWordNot(
|
|
|
|
const Matcher<c::Node*>& value_matcher) {
|
2019-02-14 13:01:52 +00:00
|
|
|
return kSystemPointerSize == 8
|
|
|
|
? IsWord64Xor(value_matcher, c::IsInt64Constant(-1))
|
|
|
|
: IsWord32Xor(value_matcher, c::IsInt32Constant(-1));
|
2018-01-29 12:16:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedByteOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset) {
|
2017-09-11 13:44:42 +00:00
|
|
|
return IsLoad(
|
|
|
|
MachineType::Uint8(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedByteOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset) {
|
2017-09-11 13:44:42 +00:00
|
|
|
return IsLoad(
|
|
|
|
MachineType::Int8(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2015-07-30 11:36:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedShortOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset) {
|
2015-10-01 17:22:58 +00:00
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
return IsLoad(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::Uint16(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::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
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> bytes[2];
|
2016-03-21 17:08:21 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(kBitsPerByte)), bytes[1]);
|
2015-10-01 17:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset) {
|
2016-01-04 17:38:17 +00:00
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
2016-12-12 14:52:30 +00:00
|
|
|
return IsLoad(
|
2016-01-04 17:38:17 +00:00
|
|
|
MachineType::Int16(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::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
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> bytes[2];
|
2016-03-21 17:08:21 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
(i == 0) ? MachineType::Int8() : MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(kBitsPerByte)), bytes[1]);
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedQuadOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset) {
|
2016-03-21 17:08:21 +00:00
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
return IsLoad(
|
|
|
|
MachineType::Uint32(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2016-03-21 17:08:21 +00:00
|
|
|
} 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
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> bytes[4];
|
2016-03-21 17:08:21 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(3 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[1], c::IsInt32Constant(2 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[2], c::IsInt32Constant(1 * kBitsPerByte)),
|
|
|
|
bytes[3])));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset) {
|
2016-03-21 17:08:21 +00:00
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
2016-12-12 14:52:30 +00:00
|
|
|
return IsLoad(
|
2016-03-21 17:08:21 +00:00
|
|
|
MachineType::Int32(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2016-03-21 17:08:21 +00:00
|
|
|
} 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
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> bytes[4];
|
2016-03-21 17:08:21 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
(i == 0) ? MachineType::Int8() : MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(3 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[1], c::IsInt32Constant(2 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[2], c::IsInt32Constant(1 * kBitsPerByte)),
|
|
|
|
bytes[3])));
|
2016-01-04 17:38:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2018-03-26 15:44:44 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset, OperandSize operand_size) {
|
2016-03-21 17:08:21 +00:00
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
2021-08-12 11:17:00 +00:00
|
|
|
return IsSignedByteOperand(offset);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kShort:
|
2021-08-12 11:17:00 +00:00
|
|
|
return IsSignedShortOperand(offset);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kQuad:
|
2021-08-12 11:17:00 +00:00
|
|
|
return IsSignedQuadOperand(offset);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2018-03-26 15:44:44 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedOperand(
|
2021-08-12 11:17:00 +00:00
|
|
|
int offset, OperandSize operand_size) {
|
2016-03-21 17:08:21 +00:00
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
2021-08-12 11:17:00 +00:00
|
|
|
return IsUnsignedByteOperand(offset);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kShort:
|
2021-08-12 11:17:00 +00:00
|
|
|
return IsUnsignedShortOperand(offset);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kQuad:
|
2021-08-12 11:17:00 +00:00
|
|
|
return IsUnsignedQuadOperand(offset);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*>
|
2018-01-29 12:16:32 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoadRegisterOperand(
|
|
|
|
int offset, OperandSize operand_size) {
|
2021-08-12 11:17:00 +00:00
|
|
|
Matcher<c::Node*> reg_operand =
|
|
|
|
IsChangeInt32ToIntPtr(IsSignedOperand(offset, operand_size));
|
2019-02-08 16:31:34 +00:00
|
|
|
return IsBitcastWordToTagged(IsLoad(
|
|
|
|
MachineType::Pointer(), c::IsLoadParentFramePointer(),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsWordShl(reg_operand, c::IsIntPtrConstant(kSystemPointerSizeLog2))));
|
2018-01-29 12:16:32 +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) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode, operand_scale);
|
2016-03-21 17:08:21 +00:00
|
|
|
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),
|
2021-08-12 11:17:00 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kFlag8:
|
2022-08-31 13:47:21 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandFlag8(i),
|
2021-08-12 11:17:00 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
2022-08-31 09:48:07 +00:00
|
|
|
case interpreter::OperandType::kFlag16:
|
2022-08-31 13:47:21 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandFlag16(i),
|
2022-08-31 09:48:07 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
2016-03-21 17:08:21 +00:00
|
|
|
case interpreter::OperandType::kIdx:
|
2018-04-30 12:13:54 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandIdx(i),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsChangeUint32ToWord(
|
|
|
|
m.IsUnsignedOperand(offset, operand_size)));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
2017-09-05 11:23:26 +00:00
|
|
|
case interpreter::OperandType::kNativeContextIndex:
|
2018-04-30 12:13:54 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandNativeContextIndex(i),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsChangeUint32ToWord(
|
|
|
|
m.IsUnsignedOperand(offset, operand_size)));
|
2017-09-05 11:23:26 +00:00
|
|
|
break;
|
2016-09-13 14:48:39 +00:00
|
|
|
case interpreter::OperandType::kUImm:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandUImm(i),
|
2021-08-12 11:17:00 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
2016-09-13 14:48:39 +00:00
|
|
|
break;
|
2016-03-21 17:08:21 +00:00
|
|
|
case interpreter::OperandType::kImm: {
|
|
|
|
EXPECT_THAT(m.BytecodeOperandImm(i),
|
2021-08-12 11:17:00 +00:00
|
|
|
m.IsSignedOperand(offset, operand_size));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case interpreter::OperandType::kRuntimeId:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandRuntimeId(i),
|
2021-08-12 11:17:00 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
2016-06-21 14:37:16 +00:00
|
|
|
case interpreter::OperandType::kIntrinsicId:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandIntrinsicId(i),
|
2021-08-12 11:17:00 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
2016-06-21 14:37:16 +00:00
|
|
|
break;
|
2018-01-29 12:16:32 +00:00
|
|
|
case interpreter::OperandType::kRegList:
|
|
|
|
case interpreter::OperandType::kReg:
|
|
|
|
case interpreter::OperandType::kRegPair:
|
|
|
|
case interpreter::OperandType::kRegOut:
|
|
|
|
case interpreter::OperandType::kRegOutList:
|
|
|
|
case interpreter::OperandType::kRegOutPair:
|
|
|
|
case interpreter::OperandType::kRegOutTriple:
|
|
|
|
EXPECT_THAT(m.LoadRegisterAtOperandIndex(i),
|
|
|
|
m.IsLoadRegisterOperand(offset, operand_size));
|
|
|
|
break;
|
2016-03-21 17:08:21 +00:00
|
|
|
case interpreter::OperandType::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2015-08-18 12:41:41 +00:00
|
|
|
}
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 09:33:21 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, GetContext) {
|
2016-01-23 00:07:21 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2016-04-15 09:33:21 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
m.GetContext(),
|
2019-02-08 16:31:34 +00:00
|
|
|
IsBitcastWordToTagged(m.IsLoad(
|
|
|
|
MachineType::Pointer(), c::IsLoadParentFramePointer(),
|
|
|
|
c::IsIntPtrConstant(Register::current_context().ToOperand() *
|
|
|
|
kSystemPointerSize))));
|
2016-01-23 00:07:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:40:52 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2016-12-12 14:52:30 +00:00
|
|
|
{
|
2019-08-22 09:56:32 +00:00
|
|
|
TNode<IntPtrT> index = m.IntPtrConstant(2);
|
2019-09-04 15:36:52 +00:00
|
|
|
TNode<Object> load_constant = m.LoadConstantPoolEntry(index);
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> constant_pool_matcher = m.IsLoadFromObject(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
|
|
|
|
kHeapObjectTag));
|
2021-08-12 11:17:00 +00:00
|
|
|
EXPECT_THAT(load_constant,
|
|
|
|
m.IsLoadFromObject(
|
|
|
|
MachineType::AnyTagged(), constant_pool_matcher,
|
|
|
|
c::IsIntPtrConstant(FixedArray::OffsetOfElementAt(2) -
|
|
|
|
kHeapObjectTag)));
|
2016-12-12 14:52:30 +00:00
|
|
|
}
|
|
|
|
{
|
2021-03-03 09:46:21 +00:00
|
|
|
c::Node* index = m.UntypedParameter(2);
|
2019-09-04 15:36:52 +00:00
|
|
|
TNode<Object> load_constant =
|
|
|
|
m.LoadConstantPoolEntry(m.ReinterpretCast<IntPtrT>(index));
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> constant_pool_matcher = m.IsLoadFromObject(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
|
|
|
|
kHeapObjectTag));
|
|
|
|
EXPECT_THAT(
|
|
|
|
load_constant,
|
2021-08-12 11:17:00 +00:00
|
|
|
m.IsLoadFromObject(
|
2021-03-03 09:46:21 +00:00
|
|
|
MachineType::AnyTagged(), constant_pool_matcher,
|
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
|
2021-08-12 11:17:00 +00:00
|
|
|
c::IsWordShl(index, c::IsIntPtrConstant(kTaggedSizeLog2)))));
|
2016-12-12 14:52:30 +00:00
|
|
|
}
|
2015-10-29 12:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadObjectField) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2019-08-22 09:56:32 +00:00
|
|
|
TNode<HeapObject> object =
|
|
|
|
m.ReinterpretCast<HeapObject>(m.IntPtrConstant(0xDEADBEEF));
|
2015-10-29 12:06:00 +00:00
|
|
|
int offset = 16;
|
2019-08-22 09:56:32 +00:00
|
|
|
TNode<Object> load_field = m.LoadObjectField(object, offset);
|
2019-10-07 14:27:55 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
load_field,
|
|
|
|
m.IsLoadFromObject(MachineType::AnyTagged(), Eq(object),
|
|
|
|
c::IsIntPtrConstant(offset - kHeapObjectTag)));
|
2015-10-29 12:06:00 +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) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2019-08-22 09:56:32 +00:00
|
|
|
TNode<Object> arg1 = m.ReinterpretCast<Object>(m.Int32Constant(2));
|
|
|
|
TNode<Object> arg2 = m.ReinterpretCast<Object>(m.Int32Constant(3));
|
|
|
|
TNode<Object> context = m.ReinterpretCast<Object>(m.Int32Constant(4));
|
|
|
|
TNode<Object> call_runtime =
|
|
|
|
m.CallRuntime(Runtime::kAdd, context, arg1, arg2);
|
|
|
|
EXPECT_THAT(call_runtime,
|
|
|
|
c::IsCall(_, _, Eq(arg1), Eq(arg2), _, c::IsInt32Constant(2),
|
|
|
|
Eq(context), _, _));
|
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) {
|
2017-02-16 16:54:02 +00:00
|
|
|
if (Bytecodes::IsCallRuntime(bytecode)) {
|
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
|
|
|
Callable builtin =
|
|
|
|
CodeFactory::InterpreterCEntry(isolate(), result_size);
|
|
|
|
|
2019-09-09 10:14:48 +00:00
|
|
|
TNode<Uint32T> function_id = m.Uint32Constant(0);
|
2018-01-26 10:53:27 +00:00
|
|
|
InterpreterAssembler::RegListNodePair registers(m.IntPtrConstant(1),
|
|
|
|
m.Int32Constant(2));
|
2019-09-09 10:14:48 +00:00
|
|
|
TNode<Context> context = m.ReinterpretCast<Context>(m.Int32Constant(4));
|
2017-02-16 16:54:02 +00:00
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> function_table = c::IsExternalConstant(
|
2018-03-09 15:59:20 +00:00
|
|
|
ExternalReference::runtime_function_table_address_for_unittests(
|
|
|
|
isolate()));
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> function =
|
2019-08-22 09:56:32 +00:00
|
|
|
c::IsIntPtrAdd(function_table,
|
|
|
|
c::IsChangeUint32ToWord(c::IsInt32Mul(
|
|
|
|
Eq(function_id),
|
|
|
|
c::IsInt32Constant(sizeof(Runtime::Function)))));
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> function_entry =
|
2017-02-16 16:54:02 +00:00
|
|
|
m.IsLoad(MachineType::Pointer(), function,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offsetof(Runtime::Function, entry)));
|
2017-02-16 16:54:02 +00:00
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
c::Node* call_runtime =
|
2018-01-26 10:53:27 +00:00
|
|
|
m.CallRuntimeN(function_id, context, registers, result_size);
|
2019-08-23 12:40:12 +00:00
|
|
|
EXPECT_THAT(call_runtime,
|
|
|
|
c::IsCall(_, c::IsHeapConstant(builtin.code()),
|
|
|
|
Eq(registers.reg_count()),
|
|
|
|
Eq(registers.base_reg_location()), function_entry,
|
|
|
|
Eq(context), _, _));
|
2017-02-16 16:54:02 +00:00
|
|
|
}
|
2016-01-08 15:15:52 +00:00
|
|
|
}
|
2015-10-02 18:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 14:05:02 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadFeedbackVector) {
|
2015-09-02 13:03:06 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2019-08-22 09:56:32 +00:00
|
|
|
TNode<HeapObject> feedback_vector = m.LoadFeedbackVector();
|
2015-09-02 13:03:06 +00:00
|
|
|
|
2019-03-12 11:43:06 +00:00
|
|
|
// Feedback vector is a phi node with two inputs. One of them is loading the
|
|
|
|
// feedback vector and the other is undefined constant (when feedback
|
|
|
|
// vectors aren't allocated). Find the input that loads feedback vector.
|
2021-03-03 09:46:21 +00:00
|
|
|
CHECK_EQ(static_cast<c::Node*>(feedback_vector)->opcode(),
|
2019-08-22 09:56:32 +00:00
|
|
|
i::compiler::IrOpcode::kPhi);
|
2021-03-03 09:46:21 +00:00
|
|
|
c::Node* value0 =
|
2019-03-12 11:43:06 +00:00
|
|
|
i::compiler::NodeProperties::GetValueInput(feedback_vector, 0);
|
2021-03-03 09:46:21 +00:00
|
|
|
c::Node* value1 =
|
2019-03-12 11:43:06 +00:00
|
|
|
i::compiler::NodeProperties::GetValueInput(feedback_vector, 1);
|
2021-03-03 09:46:21 +00:00
|
|
|
c::Node* load_feedback_vector = value0;
|
2019-03-12 11:43:06 +00:00
|
|
|
if (value0->opcode() == i::compiler::IrOpcode::kHeapConstant) {
|
|
|
|
load_feedback_vector = value1;
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> load_function_matcher = IsBitcastWordToTagged(
|
2019-02-08 16:31:34 +00:00
|
|
|
m.IsLoad(MachineType::Pointer(), c::IsLoadParentFramePointer(),
|
2019-01-25 00:33:28 +00:00
|
|
|
c::IsIntPtrConstant(Register::function_closure().ToOperand() *
|
2019-02-08 16:31:34 +00:00
|
|
|
kSystemPointerSize)));
|
2021-03-03 09:46:21 +00:00
|
|
|
Matcher<c::Node*> load_vector_cell_matcher = m.IsLoadFromObject(
|
|
|
|
MachineType::TaggedPointer(), load_function_matcher,
|
|
|
|
c::IsIntPtrConstant(JSFunction::kFeedbackCellOffset - kHeapObjectTag));
|
|
|
|
EXPECT_THAT(load_feedback_vector,
|
|
|
|
m.IsLoadFromObject(
|
|
|
|
MachineType::TaggedPointer(), load_vector_cell_matcher,
|
|
|
|
c::IsIntPtrConstant(Cell::kValueOffset - kHeapObjectTag)));
|
2015-08-25 11:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-18 17:01:45 +00:00
|
|
|
} // namespace interpreter_assembler_unittest
|
2016-02-10 16:38:49 +00:00
|
|
|
} // namespace interpreter
|
2015-07-23 14:21:26 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|