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/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"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/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::_;
|
2017-09-04 10:47:27 +00:00
|
|
|
using v8::internal::compiler::Node;
|
|
|
|
|
|
|
|
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{},
|
2017-09-29 14:59:24 +00:00
|
|
|
Code::BYTECODE_HANDLER, Bytecodes::ToString(bytecode),
|
2018-06-21 08:47:48 +00:00
|
|
|
PoisoningMitigationLevel::kPoisonCriticalOnly) {}
|
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())) {
|
|
|
|
SetAccumulator(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoad(
|
2017-09-04 10:47:27 +00:00
|
|
|
const Matcher<c::LoadRepresentation>& rep_matcher,
|
2018-03-26 15:44:44 +00:00
|
|
|
const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher,
|
|
|
|
LoadSensitivity needs_poisoning) {
|
2018-04-30 12:13:54 +00:00
|
|
|
CHECK_NE(LoadSensitivity::kUnsafe, needs_poisoning);
|
|
|
|
CHECK_NE(PoisoningMitigationLevel::kPoisonAll, poisoning_level());
|
|
|
|
if (poisoning_level() == PoisoningMitigationLevel::kPoisonCriticalOnly &&
|
|
|
|
needs_poisoning == LoadSensitivity::kCritical) {
|
2018-03-26 15:44:44 +00:00
|
|
|
return ::i::compiler::IsPoisonedLoad(rep_matcher, base_matcher,
|
|
|
|
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(
|
2017-09-04 10:47:27 +00:00
|
|
|
const Matcher<c::StoreRepresentation>& rep_matcher,
|
2015-07-23 14:21:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-29 12:16:32 +00:00
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsWordNot(
|
|
|
|
const Matcher<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
|
|
|
}
|
|
|
|
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedByteOperand(
|
2018-03-26 15:44:44 +00:00
|
|
|
int offset, LoadSensitivity needs_poisoning) {
|
2017-09-11 13:44:42 +00:00
|
|
|
return IsLoad(
|
|
|
|
MachineType::Uint8(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset)),
|
|
|
|
needs_poisoning);
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedByteOperand(
|
2018-03-26 15:44:44 +00:00
|
|
|
int offset, LoadSensitivity needs_poisoning) {
|
2017-09-11 13:44:42 +00:00
|
|
|
return IsLoad(
|
|
|
|
MachineType::Int8(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset)),
|
|
|
|
needs_poisoning);
|
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(
|
2018-03-26 15:44:44 +00:00
|
|
|
int offset, LoadSensitivity needs_poisoning) {
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset)),
|
|
|
|
needs_poisoning);
|
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(),
|
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),
|
2018-04-19 10:28:53 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
|
|
|
|
needs_poisoning);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand(
|
2018-03-26 15:44:44 +00:00
|
|
|
int offset, LoadSensitivity needs_poisoning) {
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset)),
|
|
|
|
needs_poisoning);
|
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(),
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
|
|
|
|
needs_poisoning);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedQuadOperand(
|
2018-03-26 15:44:44 +00:00
|
|
|
int offset, LoadSensitivity needs_poisoning) {
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset)),
|
|
|
|
needs_poisoning);
|
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
|
|
|
|
Matcher<Node*> bytes[4];
|
|
|
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
|
|
|
|
needs_poisoning);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand(
|
2018-03-26 15:44:44 +00:00
|
|
|
int offset, LoadSensitivity needs_poisoning) {
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset)),
|
|
|
|
needs_poisoning);
|
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
|
|
|
|
Matcher<Node*> bytes[4];
|
|
|
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
|
|
|
|
needs_poisoning);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-26 15:44:44 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedOperand(
|
|
|
|
int offset, OperandSize operand_size, LoadSensitivity needs_poisoning) {
|
2016-03-21 17:08:21 +00:00
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
2018-03-26 15:44:44 +00:00
|
|
|
return IsSignedByteOperand(offset, needs_poisoning);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kShort:
|
2018-03-26 15:44:44 +00:00
|
|
|
return IsSignedShortOperand(offset, needs_poisoning);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kQuad:
|
2018-03-26 15:44:44 +00:00
|
|
|
return IsSignedQuadOperand(offset, needs_poisoning);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-26 15:44:44 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedOperand(
|
|
|
|
int offset, OperandSize operand_size, LoadSensitivity needs_poisoning) {
|
2016-03-21 17:08:21 +00:00
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
2018-03-26 15:44:44 +00:00
|
|
|
return IsUnsignedByteOperand(offset, needs_poisoning);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kShort:
|
2018-03-26 15:44:44 +00:00
|
|
|
return IsUnsignedShortOperand(offset, needs_poisoning);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kQuad:
|
2018-03-26 15:44:44 +00:00
|
|
|
return IsUnsignedQuadOperand(offset, needs_poisoning);
|
2016-03-21 17:08:21 +00:00
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-29 12:16:32 +00:00
|
|
|
Matcher<compiler::Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoadRegisterOperand(
|
|
|
|
int offset, OperandSize operand_size) {
|
2018-03-26 15:44:44 +00:00
|
|
|
Matcher<compiler::Node*> reg_operand = IsChangeInt32ToIntPtr(
|
|
|
|
IsSignedOperand(offset, operand_size, LoadSensitivity::kSafe));
|
2019-02-08 16:31:34 +00:00
|
|
|
return IsBitcastWordToTagged(IsLoad(
|
|
|
|
MachineType::Pointer(), c::IsLoadParentFramePointer(),
|
|
|
|
c::IsWordShl(reg_operand, c::IsIntPtrConstant(kSystemPointerSizeLog2)),
|
|
|
|
LoadSensitivity::kCritical));
|
2018-01-29 12:16:32 +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) {
|
2016-07-20 12:51:11 +00:00
|
|
|
if (!interpreter::Bytecodes::IsJump(bytecode)) return;
|
|
|
|
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2016-04-22 13:55:53 +00:00
|
|
|
Node* tail_call_node = m.Jump(m.IntPtrConstant(jump_offset));
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2017-09-11 13:44:42 +00:00
|
|
|
Matcher<Node*> next_bytecode_offset_matcher = c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(jump_offset));
|
2016-02-19 18:46:54 +00:00
|
|
|
Matcher<Node*> target_bytecode_matcher =
|
|
|
|
m.IsLoad(MachineType::Uint8(), _, next_bytecode_offset_matcher);
|
2017-09-11 13:44:42 +00:00
|
|
|
target_bytecode_matcher =
|
|
|
|
c::IsChangeUint32ToWord(target_bytecode_matcher);
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
MachineType::Pointer(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kDispatchTable),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsWordShl(target_bytecode_matcher,
|
2019-02-14 13:01:52 +00:00
|
|
|
c::IsIntPtrConstant(kSystemPointerSizeLog2)));
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
tail_call_node,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsTailCall(
|
2017-09-04 10:47:27 +00:00
|
|
|
_, code_target_matcher,
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kAccumulator),
|
|
|
|
next_bytecode_offset_matcher, _,
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kDispatchTable), _,
|
|
|
|
_));
|
2015-09-24 15:20:47 +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),
|
2018-03-26 15:44:44 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size,
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kFlag8:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandFlag(i),
|
2018-03-26 15:44:44 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size,
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kIdx:
|
2018-04-30 12:13:54 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandIdx(i),
|
|
|
|
c::IsChangeUint32ToWord(m.IsUnsignedOperand(
|
|
|
|
offset, operand_size, LoadSensitivity::kCritical)));
|
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),
|
|
|
|
c::IsChangeUint32ToWord(m.IsUnsignedOperand(
|
|
|
|
offset, operand_size, LoadSensitivity::kCritical)));
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size,
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
m.IsSignedOperand(offset, operand_size,
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case interpreter::OperandType::kRuntimeId:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandRuntimeId(i),
|
2018-03-26 15:44:44 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size,
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
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),
|
2018-03-26 15:44:44 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size,
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
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();
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
Node* index = m.IntPtrConstant(2);
|
|
|
|
Node* load_constant = m.LoadConstantPoolEntry(index);
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> constant_pool_matcher = m.IsLoad(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
|
|
|
|
kHeapObjectTag));
|
2018-03-26 15:44:44 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
load_constant,
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), constant_pool_matcher,
|
|
|
|
c::IsIntPtrConstant(FixedArray::OffsetOfElementAt(2) -
|
|
|
|
kHeapObjectTag),
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
2016-12-12 14:52:30 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
Node* index = m.Parameter(2);
|
|
|
|
Node* load_constant = m.LoadConstantPoolEntry(index);
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> constant_pool_matcher = m.IsLoad(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
|
|
|
|
kHeapObjectTag));
|
2016-12-12 14:52:30 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
load_constant,
|
2018-03-26 15:44:44 +00:00
|
|
|
m.IsLoad(
|
2016-12-12 14:52:30 +00:00
|
|
|
MachineType::AnyTagged(), constant_pool_matcher,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
|
2019-02-14 13:01:52 +00:00
|
|
|
c::IsWordShl(index,
|
|
|
|
c::IsIntPtrConstant(kSystemPointerSizeLog2))),
|
2018-04-30 12:13:54 +00:00
|
|
|
LoadSensitivity::kCritical));
|
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);
|
2017-12-02 00:30:37 +00:00
|
|
|
Node* object = m.IntPtrConstant(0xDEADBEEF);
|
2015-10-29 12:06:00 +00:00
|
|
|
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,
|
2017-09-11 13:44:42 +00:00
|
|
|
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);
|
2015-09-10 13:04:15 +00:00
|
|
|
Node* arg1 = m.Int32Constant(2);
|
|
|
|
Node* arg2 = m.Int32Constant(3);
|
2016-04-19 12:47:25 +00:00
|
|
|
Node* context = m.Int32Constant(4);
|
2016-02-10 16:38:49 +00:00
|
|
|
Node* call_runtime = m.CallRuntime(Runtime::kAdd, context, arg1, arg2);
|
2017-09-11 13:44:42 +00:00
|
|
|
EXPECT_THAT(call_runtime, c::IsCall(_, _, arg1, arg2, _,
|
|
|
|
c::IsInt32Constant(2), 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);
|
|
|
|
|
|
|
|
Node* function_id = m.Int32Constant(0);
|
2018-01-26 10:53:27 +00:00
|
|
|
InterpreterAssembler::RegListNodePair registers(m.IntPtrConstant(1),
|
|
|
|
m.Int32Constant(2));
|
2017-02-16 16:54:02 +00:00
|
|
|
Node* context = m.IntPtrConstant(4);
|
|
|
|
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> function_table = c::IsExternalConstant(
|
2018-03-09 15:59:20 +00:00
|
|
|
ExternalReference::runtime_function_table_address_for_unittests(
|
|
|
|
isolate()));
|
2017-09-11 13:44:42 +00:00
|
|
|
Matcher<Node*> function = c::IsIntPtrAdd(
|
2017-02-16 16:54:02 +00:00
|
|
|
function_table,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsChangeUint32ToWord(c::IsInt32Mul(
|
2017-09-04 10:47:27 +00:00
|
|
|
function_id, c::IsInt32Constant(sizeof(Runtime::Function)))));
|
2017-02-16 16:54:02 +00:00
|
|
|
Matcher<Node*> function_entry =
|
|
|
|
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
|
|
|
|
2018-01-26 10:53:27 +00:00
|
|
|
Node* call_runtime =
|
|
|
|
m.CallRuntimeN(function_id, context, registers, result_size);
|
|
|
|
EXPECT_THAT(
|
|
|
|
call_runtime,
|
|
|
|
c::IsCall(_, c::IsHeapConstant(builtin.code()),
|
|
|
|
registers.reg_count(), registers.base_reg_location(),
|
|
|
|
function_entry, 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);
|
2017-02-07 14:05:02 +00:00
|
|
|
Node* feedback_vector = m.LoadFeedbackVector();
|
2015-09-02 13:03:06 +00:00
|
|
|
|
2019-02-08 16:31:34 +00:00
|
|
|
Matcher<Node*> load_function_matcher = IsBitcastWordToTagged(
|
|
|
|
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)));
|
2018-02-22 12:04:01 +00:00
|
|
|
Matcher<Node*> load_vector_cell_matcher = m.IsLoad(
|
|
|
|
MachineType::AnyTagged(), load_function_matcher,
|
|
|
|
c::IsIntPtrConstant(JSFunction::kFeedbackCellOffset - kHeapObjectTag));
|
2017-02-06 10:18:05 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
feedback_vector,
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), load_vector_cell_matcher,
|
2017-09-11 13:44:42 +00:00
|
|
|
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
|