2014-11-26 12:41:46 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/source-position.h"
|
2018-11-12 14:12:52 +00:00
|
|
|
#include "src/compiler/backend/instruction-codes.h"
|
|
|
|
#include "src/compiler/backend/instruction.h"
|
|
|
|
#include "src/compiler/backend/jump-threading.h"
|
2015-10-28 13:32:17 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
|
|
|
class TestCode : public HandleAndZoneScope {
|
|
|
|
public:
|
2021-03-25 20:22:21 +00:00
|
|
|
explicit TestCode(size_t block_count)
|
2014-11-26 12:41:46 +00:00
|
|
|
: HandleAndZoneScope(),
|
|
|
|
blocks_(main_zone()),
|
2015-01-23 15:19:34 +00:00
|
|
|
sequence_(main_isolate(), main_zone(), &blocks_),
|
2014-11-26 12:41:46 +00:00
|
|
|
rpo_number_(RpoNumber::FromInt(0)),
|
2021-03-25 20:22:21 +00:00
|
|
|
current_(nullptr) {
|
|
|
|
sequence_.IncreaseRpoForTesting(block_count);
|
|
|
|
}
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
ZoneVector<InstructionBlock*> blocks_;
|
|
|
|
InstructionSequence sequence_;
|
|
|
|
RpoNumber rpo_number_;
|
|
|
|
InstructionBlock* current_;
|
|
|
|
|
|
|
|
int Jump(int target) {
|
|
|
|
Start();
|
2015-02-04 12:38:47 +00:00
|
|
|
InstructionOperand ops[] = {UseRpo(target)};
|
2017-10-13 16:33:03 +00:00
|
|
|
sequence_.AddInstruction(Instruction::New(main_zone(), kArchJmp, 0, nullptr,
|
|
|
|
1, ops, 0, nullptr));
|
2014-11-26 12:41:46 +00:00
|
|
|
int pos = static_cast<int>(sequence_.instructions().size() - 1);
|
|
|
|
End();
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
void Fallthru() {
|
|
|
|
Start();
|
|
|
|
End();
|
|
|
|
}
|
|
|
|
int Branch(int ttarget, int ftarget) {
|
|
|
|
Start();
|
2015-02-04 12:38:47 +00:00
|
|
|
InstructionOperand ops[] = {UseRpo(ttarget), UseRpo(ftarget)};
|
2014-11-26 12:41:46 +00:00
|
|
|
InstructionCode code = 119 | FlagsModeField::encode(kFlags_branch) |
|
|
|
|
FlagsConditionField::encode(kEqual);
|
2015-03-24 14:05:21 +00:00
|
|
|
sequence_.AddInstruction(
|
2017-10-13 16:33:03 +00:00
|
|
|
Instruction::New(main_zone(), code, 0, nullptr, 2, ops, 0, nullptr));
|
2014-11-26 12:41:46 +00:00
|
|
|
int pos = static_cast<int>(sequence_.instructions().size() - 1);
|
|
|
|
End();
|
|
|
|
return pos;
|
|
|
|
}
|
2020-07-29 14:23:58 +00:00
|
|
|
int Return(int size, bool defer = false, bool deconstruct_frame = false) {
|
|
|
|
Start(defer, deconstruct_frame);
|
|
|
|
InstructionOperand ops[] = {Immediate(size)};
|
|
|
|
sequence_.AddInstruction(Instruction::New(main_zone(), kArchRet, 0, nullptr,
|
|
|
|
1, ops, 0, nullptr));
|
|
|
|
int pos = static_cast<int>(sequence_.instructions().size() - 1);
|
|
|
|
End();
|
|
|
|
return pos;
|
|
|
|
}
|
2014-11-26 12:41:46 +00:00
|
|
|
void Nop() {
|
|
|
|
Start();
|
|
|
|
sequence_.AddInstruction(Instruction::New(main_zone(), kArchNop));
|
|
|
|
}
|
|
|
|
void RedundantMoves() {
|
|
|
|
Start();
|
|
|
|
sequence_.AddInstruction(Instruction::New(main_zone(), kArchNop));
|
2015-03-31 13:06:37 +00:00
|
|
|
int index = static_cast<int>(sequence_.instructions().size()) - 1;
|
2015-12-10 09:03:30 +00:00
|
|
|
AddGapMove(index, AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kWord32, 13),
|
|
|
|
AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kWord32, 13));
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
void NonRedundantMoves() {
|
|
|
|
Start();
|
|
|
|
sequence_.AddInstruction(Instruction::New(main_zone(), kArchNop));
|
2015-03-31 13:06:37 +00:00
|
|
|
int index = static_cast<int>(sequence_.instructions().size()) - 1;
|
[turbofan] Create ExplicitOperands to specify operands without virtual registers
Up until now, if one wanted to specify an explicit stack location or register as an operand for an instruction, it had to also be
explicitly associated with a virtual register as a so-called
FixedRegister or FixedStackSlot.
For the implementation of tail calls, the plan is to use the gap
resolver needs to shuffle stack locations from the caller to the
tail-called callee. In order to do this, it must be possible to
explicitly address operand locations on the stack that are not
associated with virtual registers.
This CL introduces ExplictOperands, which can specify a specific
register or stack location that is not associated with virtual
register. This will allow tail calls to specify the target
locations for the necessary stack moves in the gap for the tail
call without the core register allocation having to know about
the target of the stack moves at all.
In the process this CL:
* creates a new Operand kind, ExplicitOperand, with which
instructions can specify register and stack slots without an
associated virtual register.
* creates a LocationOperand class from which AllocatedOperand and
ExplicitOperand are derived and provides a common interface to
get Register, DoubleRegister and spill slot information.
* removes RegisterOperand, DoubleRegisterOperand,
StackSlotOperand and DoubleStackSlotOperand, they are subsumed
by LocationOperand.
* addresses a cleanup TODO in AllocatedOperand to reduce the
redundancy of AllocatedOperand::Kind by using machine_type() to
determine if an operand corresponds to a general purpose or
double register.
BUG=v8:4076
LOG=n
Review URL: https://codereview.chromium.org/1389373002
Cr-Commit-Position: refs/heads/master@{#31603}
2015-10-27 13:26:35 +00:00
|
|
|
AddGapMove(index, ConstantOperand(11),
|
2015-12-10 09:03:30 +00:00
|
|
|
AllocatedOperand(LocationOperand::REGISTER,
|
|
|
|
MachineRepresentation::kWord32, 11));
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
void Other() {
|
|
|
|
Start();
|
|
|
|
sequence_.AddInstruction(Instruction::New(main_zone(), 155));
|
|
|
|
}
|
|
|
|
void End() {
|
|
|
|
Start();
|
2018-06-12 14:31:03 +00:00
|
|
|
int end = static_cast<int>(sequence_.instructions().size());
|
|
|
|
if (current_->code_start() == end) { // Empty block. Insert a nop.
|
|
|
|
sequence_.AddInstruction(Instruction::New(main_zone(), kArchNop));
|
|
|
|
}
|
2014-11-26 12:41:46 +00:00
|
|
|
sequence_.EndBlock(current_->rpo_number());
|
2017-10-13 16:33:03 +00:00
|
|
|
current_ = nullptr;
|
2014-11-26 12:41:46 +00:00
|
|
|
rpo_number_ = RpoNumber::FromInt(rpo_number_.ToInt() + 1);
|
|
|
|
}
|
2015-02-04 12:38:47 +00:00
|
|
|
InstructionOperand UseRpo(int num) {
|
2015-04-09 14:06:19 +00:00
|
|
|
return sequence_.AddImmediate(Constant(RpoNumber::FromInt(num)));
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
2020-07-29 14:23:58 +00:00
|
|
|
InstructionOperand Immediate(int num) {
|
|
|
|
return sequence_.AddImmediate(Constant(num));
|
|
|
|
}
|
|
|
|
void Start(bool deferred = false, bool deconstruct_frame = false) {
|
2017-10-13 16:33:03 +00:00
|
|
|
if (current_ == nullptr) {
|
2020-07-09 10:43:44 +00:00
|
|
|
current_ = main_zone()->New<InstructionBlock>(
|
|
|
|
main_zone(), rpo_number_, RpoNumber::Invalid(), RpoNumber::Invalid(),
|
2020-07-27 20:01:22 +00:00
|
|
|
RpoNumber::Invalid(), deferred, false);
|
2020-07-29 14:23:58 +00:00
|
|
|
if (deconstruct_frame) {
|
|
|
|
current_->mark_must_deconstruct_frame();
|
|
|
|
}
|
2014-11-26 12:41:46 +00:00
|
|
|
blocks_.push_back(current_);
|
|
|
|
sequence_.StartBlock(rpo_number_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Defer() {
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_NULL(current_);
|
2014-11-26 12:41:46 +00:00
|
|
|
Start(true);
|
|
|
|
}
|
2015-04-15 12:36:36 +00:00
|
|
|
void AddGapMove(int index, const InstructionOperand& from,
|
|
|
|
const InstructionOperand& to) {
|
2015-03-31 13:06:37 +00:00
|
|
|
sequence_.InstructionAt(index)
|
|
|
|
->GetOrCreateParallelMove(Instruction::START, main_zone())
|
2015-04-15 12:36:36 +00:00
|
|
|
->AddMove(from, to);
|
2015-03-31 13:06:37 +00:00
|
|
|
}
|
2014-11-26 12:41:46 +00:00
|
|
|
};
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void VerifyForwarding(TestCode* code, int count, int* expected) {
|
2016-09-20 16:07:25 +00:00
|
|
|
v8::internal::AccountingAllocator allocator;
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone local_zone(&allocator, ZONE_NAME);
|
2014-11-26 12:41:46 +00:00
|
|
|
ZoneVector<RpoNumber> result(&local_zone);
|
2019-09-11 11:48:18 +00:00
|
|
|
JumpThreading::ComputeForwarding(&local_zone, &result, &code->sequence_,
|
|
|
|
true);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
CHECK(count == static_cast<int>(result.size()));
|
|
|
|
for (int i = 0; i < count; i++) {
|
2019-09-11 11:48:18 +00:00
|
|
|
CHECK_EQ(expected[i], result[i].ToInt());
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FwEmpty1) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 3;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Jump(1);
|
|
|
|
// B1
|
|
|
|
code.Jump(2);
|
|
|
|
// B2
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {2, 2, 2};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwEmptyN) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 3;
|
2014-11-26 12:41:46 +00:00
|
|
|
for (int i = 0; i < 9; i++) {
|
2021-03-25 20:22:21 +00:00
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Jump(1);
|
|
|
|
// B1
|
|
|
|
for (int j = 0; j < i; j++) code.Nop();
|
|
|
|
code.Jump(2);
|
|
|
|
// B2
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {2, 2, 2};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwNone1) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 1;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {0};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwMoves1) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 1;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.RedundantMoves();
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {0};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwMoves2) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.RedundantMoves();
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwMoves2b) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.NonRedundantMoves();
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {0, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwOther2) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Other();
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {0, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwNone2a) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwNone2b) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Jump(1);
|
|
|
|
// B1
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int expected[] = {1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop1) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 1;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Jump(0);
|
|
|
|
|
|
|
|
static int expected[] = {0};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop2) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Jump(0);
|
|
|
|
|
|
|
|
static int expected[] = {0, 0};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop3) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 3;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Jump(0);
|
|
|
|
|
|
|
|
static int expected[] = {0, 0, 0};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop1b) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Jump(1);
|
|
|
|
|
|
|
|
static int expected[] = {1, 1};
|
2019-09-10 01:19:59 +00:00
|
|
|
VerifyForwarding(&code, 2, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop2b) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 3;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Jump(1);
|
|
|
|
|
|
|
|
static int expected[] = {1, 1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop3b) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Fallthru();
|
|
|
|
// B3
|
|
|
|
code.Jump(1);
|
|
|
|
|
|
|
|
static int expected[] = {1, 1, 1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop2_1a) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 5;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Fallthru();
|
|
|
|
// B3
|
|
|
|
code.Jump(1);
|
|
|
|
// B4
|
|
|
|
code.Jump(2);
|
|
|
|
|
|
|
|
static int expected[] = {1, 1, 1, 1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop2_1b) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 5;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Jump(4);
|
|
|
|
// B3
|
|
|
|
code.Jump(1);
|
|
|
|
// B4
|
|
|
|
code.Jump(2);
|
|
|
|
|
|
|
|
static int expected[] = {2, 2, 2, 2, 2};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop2_1c) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 5;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Jump(4);
|
|
|
|
// B3
|
|
|
|
code.Jump(2);
|
|
|
|
// B4
|
|
|
|
code.Jump(1);
|
|
|
|
|
|
|
|
static int expected[] = {1, 1, 1, 1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop2_1d) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 5;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Jump(1);
|
|
|
|
// B3
|
|
|
|
code.Jump(1);
|
|
|
|
// B4
|
|
|
|
code.Jump(1);
|
|
|
|
|
|
|
|
static int expected[] = {1, 1, 1, 1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwLoop3_1a) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 6;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Fallthru();
|
|
|
|
// B1
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Fallthru();
|
|
|
|
// B3
|
|
|
|
code.Jump(2);
|
|
|
|
// B4
|
|
|
|
code.Jump(1);
|
|
|
|
// B5
|
|
|
|
code.Jump(0);
|
|
|
|
|
|
|
|
static int expected[] = {2, 2, 2, 2, 2, 2};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwDiamonds) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
2014-11-26 12:41:46 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2021-03-25 20:22:21 +00:00
|
|
|
TestCode code(kBlockCount);
|
|
|
|
|
2014-11-26 12:41:46 +00:00
|
|
|
// B0
|
|
|
|
code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
if (i) code.Other();
|
|
|
|
code.Jump(3);
|
|
|
|
// B2
|
|
|
|
if (j) code.Other();
|
|
|
|
code.Jump(3);
|
|
|
|
// B3
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int expected[] = {0, i ? 1 : 3, j ? 2 : 3, 3};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwDiamonds2) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 5;
|
2014-11-26 12:41:46 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
for (int k = 0; k < 2; k++) {
|
2021-03-25 20:22:21 +00:00
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
// B0
|
|
|
|
code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
if (i) code.Other();
|
|
|
|
code.Jump(3);
|
|
|
|
// B2
|
|
|
|
if (j) code.Other();
|
|
|
|
code.Jump(3);
|
|
|
|
// B3
|
|
|
|
if (k) code.NonRedundantMoves();
|
|
|
|
code.Jump(4);
|
|
|
|
// B4
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int merge = k ? 3 : 4;
|
|
|
|
int expected[] = {0, i ? 1 : merge, j ? 2 : merge, merge, 4};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwDoubleDiamonds) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 7;
|
2014-11-26 12:41:46 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
for (int x = 0; x < 2; x++) {
|
|
|
|
for (int y = 0; y < 2; y++) {
|
2021-03-25 20:22:21 +00:00
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
// B0
|
|
|
|
code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
if (i) code.Other();
|
|
|
|
code.Jump(3);
|
|
|
|
// B2
|
|
|
|
if (j) code.Other();
|
|
|
|
code.Jump(3);
|
|
|
|
// B3
|
|
|
|
code.Branch(4, 5);
|
|
|
|
// B4
|
|
|
|
if (x) code.Other();
|
|
|
|
code.Jump(6);
|
|
|
|
// B5
|
|
|
|
if (y) code.Other();
|
|
|
|
code.Jump(6);
|
|
|
|
// B6
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int expected[] = {0, i ? 1 : 3, j ? 2 : 3, 3,
|
|
|
|
x ? 4 : 6, y ? 5 : 6, 6};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <int kSize>
|
|
|
|
void RunPermutationsRecursive(int outer[kSize], int start,
|
|
|
|
void (*run)(int*, int)) {
|
|
|
|
int permutation[kSize];
|
|
|
|
|
|
|
|
for (int i = 0; i < kSize; i++) permutation[i] = outer[i];
|
|
|
|
|
|
|
|
int count = kSize - start;
|
|
|
|
if (count == 0) return run(permutation, kSize);
|
|
|
|
for (int i = start; i < kSize; i++) {
|
|
|
|
permutation[start] = outer[i];
|
|
|
|
permutation[i] = outer[start];
|
|
|
|
RunPermutationsRecursive<kSize>(permutation, start + 1, run);
|
|
|
|
permutation[i] = outer[i];
|
|
|
|
permutation[start] = outer[start];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <int kSize>
|
|
|
|
void RunAllPermutations(void (*run)(int*, int)) {
|
|
|
|
int permutation[kSize];
|
|
|
|
for (int i = 0; i < kSize; i++) permutation[i] = i;
|
|
|
|
RunPermutationsRecursive<kSize>(permutation, 0, run);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrintPermutation(int* permutation, int size) {
|
|
|
|
printf("{ ");
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
if (i > 0) printf(", ");
|
|
|
|
printf("%d", permutation[i]);
|
|
|
|
}
|
|
|
|
printf(" }\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int find(int x, int* permutation, int size) {
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
if (permutation[i] == x) return i;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RunPermutedChain(int* permutation, int size) {
|
2021-03-25 20:22:21 +00:00
|
|
|
const int kBlockCount = size + 2;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
int cur = -1;
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
code.Jump(find(cur + 1, permutation, size) + 1);
|
|
|
|
cur = permutation[i];
|
|
|
|
}
|
|
|
|
code.Jump(find(cur + 1, permutation, size) + 1);
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int expected[] = {size + 1, size + 1, size + 1, size + 1,
|
|
|
|
size + 1, size + 1, size + 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwPermuted_chain) {
|
|
|
|
RunAllPermutations<3>(RunPermutedChain);
|
|
|
|
RunAllPermutations<4>(RunPermutedChain);
|
|
|
|
RunAllPermutations<5>(RunPermutedChain);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RunPermutedDiamond(int* permutation, int size) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 6;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
int br = 1 + find(0, permutation, size);
|
|
|
|
code.Jump(br);
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
switch (permutation[i]) {
|
|
|
|
case 0:
|
|
|
|
code.Branch(1 + find(1, permutation, size),
|
|
|
|
1 + find(2, permutation, size));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
code.Jump(1 + find(3, permutation, size));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
code.Jump(1 + find(3, permutation, size));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
code.Jump(5);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int expected[] = {br, 5, 5, 5, 5, 5};
|
|
|
|
expected[br] = br;
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, expected);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FwPermuted_diamond) { RunAllPermutations<4>(RunPermutedDiamond); }
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void ApplyForwarding(TestCode* code, int size, int* forward) {
|
|
|
|
code->sequence_.RecomputeAssemblyOrderForTesting();
|
|
|
|
ZoneVector<RpoNumber> vector(code->main_zone());
|
2014-11-26 12:41:46 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
vector.push_back(RpoNumber::FromInt(forward[i]));
|
|
|
|
}
|
2019-09-10 01:19:59 +00:00
|
|
|
JumpThreading::ApplyForwarding(code->main_zone(), vector, &code->sequence_);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void CheckJump(TestCode* code, int pos, int target) {
|
|
|
|
Instruction* instr = code->sequence_.InstructionAt(pos);
|
2014-11-26 12:41:46 +00:00
|
|
|
CHECK_EQ(kArchJmp, instr->arch_opcode());
|
|
|
|
CHECK_EQ(1, static_cast<int>(instr->InputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->OutputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->TempCount()));
|
2019-09-10 01:19:59 +00:00
|
|
|
CHECK_EQ(target, code->sequence_.InputRpo(instr, 0).ToInt());
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 14:23:58 +00:00
|
|
|
void CheckRet(TestCode* code, int pos) {
|
|
|
|
Instruction* instr = code->sequence_.InstructionAt(pos);
|
|
|
|
CHECK_EQ(kArchRet, instr->arch_opcode());
|
|
|
|
CHECK_EQ(1, static_cast<int>(instr->InputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->OutputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->TempCount()));
|
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void CheckNop(TestCode* code, int pos) {
|
|
|
|
Instruction* instr = code->sequence_.InstructionAt(pos);
|
2014-11-26 12:41:46 +00:00
|
|
|
CHECK_EQ(kArchNop, instr->arch_opcode());
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->InputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->OutputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->TempCount()));
|
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void CheckBranch(TestCode* code, int pos, int t1, int t2) {
|
|
|
|
Instruction* instr = code->sequence_.InstructionAt(pos);
|
2014-11-26 12:41:46 +00:00
|
|
|
CHECK_EQ(2, static_cast<int>(instr->InputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->OutputCount()));
|
|
|
|
CHECK_EQ(0, static_cast<int>(instr->TempCount()));
|
2019-09-10 01:19:59 +00:00
|
|
|
CHECK_EQ(t1, code->sequence_.InputRpo(instr, 0).ToInt());
|
|
|
|
CHECK_EQ(t2, code->sequence_.InputRpo(instr, 1).ToInt());
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void CheckAssemblyOrder(TestCode* code, int size, int* expected) {
|
2014-11-26 12:41:46 +00:00
|
|
|
int i = 0;
|
2019-09-10 01:19:59 +00:00
|
|
|
for (auto const block : code->sequence_.instruction_blocks()) {
|
2014-11-26 12:41:46 +00:00
|
|
|
CHECK_EQ(expected[i++], block->ao_number().ToInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Rewire1) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 3;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
int j1 = code.Jump(1);
|
|
|
|
// B1
|
|
|
|
int j2 = code.Jump(2);
|
|
|
|
// B2
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int forward[] = {2, 2, 2};
|
2021-03-25 20:22:21 +00:00
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckJump(&code, j1, 2);
|
|
|
|
CheckNop(&code, j2);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
static int assembly[] = {0, 1, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
CheckAssemblyOrder(&code, kBlockCount, assembly);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Rewire1_deferred) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
int j1 = code.Jump(1);
|
|
|
|
// B1
|
|
|
|
int j2 = code.Jump(2);
|
|
|
|
// B2
|
|
|
|
code.Defer();
|
|
|
|
int j3 = code.Jump(3);
|
|
|
|
// B3
|
2021-08-03 16:38:52 +00:00
|
|
|
code.Return(0);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
static int forward[] = {3, 3, 3, 3};
|
2021-03-25 20:22:21 +00:00
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckJump(&code, j1, 3);
|
|
|
|
CheckNop(&code, j2);
|
|
|
|
CheckNop(&code, j3);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
static int assembly[] = {0, 1, 2, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
CheckAssemblyOrder(&code, kBlockCount, assembly);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Rewire2_deferred) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Other();
|
|
|
|
int j1 = code.Jump(1);
|
|
|
|
// B1
|
|
|
|
code.Defer();
|
|
|
|
code.Fallthru();
|
|
|
|
// B2
|
|
|
|
code.Defer();
|
|
|
|
int j2 = code.Jump(3);
|
|
|
|
// B3
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
static int forward[] = {0, 1, 2, 3};
|
2021-03-25 20:22:21 +00:00
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckJump(&code, j1, 1);
|
|
|
|
CheckJump(&code, j2, 3);
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
static int assembly[] = {0, 2, 3, 1};
|
2021-03-25 20:22:21 +00:00
|
|
|
CheckAssemblyOrder(&code, kBlockCount, assembly);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 16:38:52 +00:00
|
|
|
TEST(Rewire_deferred_diamond) {
|
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
|
|
|
|
|
|
|
// B0
|
|
|
|
int b1 = code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
code.Fallthru(); // To B3
|
|
|
|
// B2
|
|
|
|
code.Defer();
|
|
|
|
int j1 = code.Jump(3);
|
|
|
|
// B3
|
|
|
|
code.Return(0);
|
|
|
|
|
|
|
|
static int forward[] = {0, 3, 3, 3};
|
|
|
|
VerifyForwarding(&code, kBlockCount, forward);
|
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
|
|
|
CheckBranch(&code, b1, 3, 3);
|
|
|
|
CheckNop(&code, j1);
|
|
|
|
|
|
|
|
static int assembly[] = {0, 1, 2, 1};
|
|
|
|
CheckAssemblyOrder(&code, kBlockCount, assembly);
|
|
|
|
}
|
2014-11-26 12:41:46 +00:00
|
|
|
|
|
|
|
TEST(Rewire_diamond) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 5;
|
2014-11-26 12:41:46 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2021-03-25 20:22:21 +00:00
|
|
|
TestCode code(kBlockCount);
|
2014-11-26 12:41:46 +00:00
|
|
|
// B0
|
|
|
|
int j1 = code.Jump(1);
|
|
|
|
// B1
|
|
|
|
int b1 = code.Branch(2, 3);
|
|
|
|
// B2
|
|
|
|
int j2 = code.Jump(4);
|
|
|
|
// B3
|
|
|
|
int j3 = code.Jump(4);
|
|
|
|
// B5
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int forward[] = {0, 1, i ? 4 : 2, j ? 4 : 3, 4};
|
2021-03-25 20:22:21 +00:00
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckJump(&code, j1, 1);
|
|
|
|
CheckBranch(&code, b1, i ? 4 : 2, j ? 4 : 3);
|
2014-11-26 12:41:46 +00:00
|
|
|
if (i) {
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckNop(&code, j2);
|
2014-11-26 12:41:46 +00:00
|
|
|
} else {
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckJump(&code, j2, 4);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
if (j) {
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckNop(&code, j3);
|
2014-11-26 12:41:46 +00:00
|
|
|
} else {
|
2019-09-10 01:19:59 +00:00
|
|
|
CheckJump(&code, j3, 4);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int assembly[] = {0, 1, 2, 3, 4};
|
|
|
|
if (i) {
|
|
|
|
for (int k = 3; k < 5; k++) assembly[k]--;
|
|
|
|
}
|
|
|
|
if (j) {
|
|
|
|
for (int k = 4; k < 5; k++) assembly[k]--;
|
|
|
|
}
|
2021-03-25 20:22:21 +00:00
|
|
|
CheckAssemblyOrder(&code, kBlockCount, assembly);
|
2014-11-26 12:41:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-29 14:23:58 +00:00
|
|
|
TEST(RewireRet) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
2020-07-29 14:23:58 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
int j1 = code.Return(0);
|
|
|
|
// B2
|
|
|
|
int j2 = code.Return(0);
|
|
|
|
// B3
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int forward[] = {0, 1, 1, 3};
|
|
|
|
VerifyForwarding(&code, 4, forward);
|
|
|
|
ApplyForwarding(&code, 4, forward);
|
|
|
|
|
|
|
|
CheckRet(&code, j1);
|
|
|
|
CheckNop(&code, j2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(RewireRet1) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
2020-07-29 14:23:58 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
int j1 = code.Return(0);
|
|
|
|
// B2
|
|
|
|
int j2 = code.Return(0, true, true);
|
|
|
|
// B3
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int forward[] = {0, 1, 2, 3};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, forward);
|
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
2020-07-29 14:23:58 +00:00
|
|
|
|
|
|
|
CheckRet(&code, j1);
|
|
|
|
CheckRet(&code, j2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(RewireRet2) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
2020-07-29 14:23:58 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
int j1 = code.Return(0, true, true);
|
|
|
|
// B2
|
|
|
|
int j2 = code.Return(0, true, true);
|
|
|
|
// B3
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int forward[] = {0, 1, 1, 3};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, forward);
|
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
2020-07-29 14:23:58 +00:00
|
|
|
|
|
|
|
CheckRet(&code, j1);
|
|
|
|
CheckNop(&code, j2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DifferentSizeRet) {
|
2021-03-25 20:22:21 +00:00
|
|
|
constexpr size_t kBlockCount = 4;
|
|
|
|
TestCode code(kBlockCount);
|
2020-07-29 14:23:58 +00:00
|
|
|
|
|
|
|
// B0
|
|
|
|
code.Branch(1, 2);
|
|
|
|
// B1
|
|
|
|
int j1 = code.Return(0);
|
|
|
|
// B2
|
|
|
|
int j2 = code.Return(1);
|
|
|
|
// B3
|
|
|
|
code.End();
|
|
|
|
|
|
|
|
int forward[] = {0, 1, 2, 3};
|
2021-03-25 20:22:21 +00:00
|
|
|
VerifyForwarding(&code, kBlockCount, forward);
|
|
|
|
ApplyForwarding(&code, kBlockCount, forward);
|
2020-07-29 14:23:58 +00:00
|
|
|
|
|
|
|
CheckRet(&code, j1);
|
|
|
|
CheckRet(&code, j2);
|
|
|
|
}
|
|
|
|
|
2014-11-26 12:41:46 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|