[turbofan] move assembly order to InstructionBlock
R=titzer@chromium.org BUG= Review URL: https://codereview.chromium.org/805263003 Cr-Commit-Position: refs/heads/master@{#25867}
This commit is contained in:
parent
7b9cb2eb37
commit
44e2dd535e
@ -173,11 +173,6 @@ Instruction* InstructionSelector::Emit(Instruction* instr) {
|
||||
}
|
||||
|
||||
|
||||
bool InstructionSelector::IsNextInAssemblyOrder(const BasicBlock* block) const {
|
||||
return current_block_->GetAoNumber().IsNext(block->GetAoNumber());
|
||||
}
|
||||
|
||||
|
||||
bool InstructionSelector::CanCover(Node* user, Node* node) const {
|
||||
return node->OwnedBy(user) &&
|
||||
schedule()->block(node) == schedule()->block(user);
|
||||
|
@ -133,10 +133,6 @@ class InstructionSelector FINAL {
|
||||
private:
|
||||
friend class OperandGenerator;
|
||||
|
||||
// Checks if {block} will appear directly after {current_block_} when
|
||||
// assembling code, in which case, a fall-through can be used.
|
||||
bool IsNextInAssemblyOrder(const BasicBlock* block) const;
|
||||
|
||||
// Inform the instruction selection that {node} was just defined.
|
||||
void MarkAsDefined(Node* node);
|
||||
|
||||
|
@ -348,7 +348,6 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant) {
|
||||
|
||||
|
||||
InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id,
|
||||
BasicBlock::RpoNumber ao_number,
|
||||
BasicBlock::RpoNumber rpo_number,
|
||||
BasicBlock::RpoNumber loop_header,
|
||||
BasicBlock::RpoNumber loop_end,
|
||||
@ -357,7 +356,7 @@ InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id,
|
||||
predecessors_(zone),
|
||||
phis_(zone),
|
||||
id_(id),
|
||||
ao_number_(ao_number),
|
||||
ao_number_(rpo_number),
|
||||
rpo_number_(rpo_number),
|
||||
loop_header_(loop_header),
|
||||
loop_end_(loop_end),
|
||||
@ -392,8 +391,8 @@ static BasicBlock::RpoNumber GetLoopEndRpo(const BasicBlock* block) {
|
||||
static InstructionBlock* InstructionBlockFor(Zone* zone,
|
||||
const BasicBlock* block) {
|
||||
InstructionBlock* instr_block = new (zone) InstructionBlock(
|
||||
zone, block->id(), block->GetAoNumber(), block->GetRpoNumber(),
|
||||
GetRpo(block->loop_header()), GetLoopEndRpo(block), block->deferred());
|
||||
zone, block->id(), block->GetRpoNumber(), GetRpo(block->loop_header()),
|
||||
GetLoopEndRpo(block), block->deferred());
|
||||
// Map successors and precessors
|
||||
instr_block->successors().reserve(block->SuccessorCount());
|
||||
for (auto it = block->successors_begin(); it != block->successors_end();
|
||||
@ -421,10 +420,26 @@ InstructionBlocks* InstructionSequence::InstructionBlocksFor(
|
||||
DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number);
|
||||
(*blocks)[rpo_number] = InstructionBlockFor(zone, *it);
|
||||
}
|
||||
ComputeAssemblyOrder(blocks);
|
||||
return blocks;
|
||||
}
|
||||
|
||||
|
||||
void InstructionSequence::ComputeAssemblyOrder(InstructionBlocks* blocks) {
|
||||
int ao = 0;
|
||||
for (auto const block : *blocks) {
|
||||
if (!block->IsDeferred()) {
|
||||
block->set_ao_number(BasicBlock::RpoNumber::FromInt(ao++));
|
||||
}
|
||||
}
|
||||
for (auto const block : *blocks) {
|
||||
if (block->IsDeferred()) {
|
||||
block->set_ao_number(BasicBlock::RpoNumber::FromInt(ao++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
InstructionSequence::InstructionSequence(Zone* instruction_zone,
|
||||
InstructionBlocks* instruction_blocks)
|
||||
: zone_(instruction_zone),
|
||||
|
@ -816,7 +816,6 @@ class PhiInstruction FINAL : public ZoneObject {
|
||||
class InstructionBlock FINAL : public ZoneObject {
|
||||
public:
|
||||
InstructionBlock(Zone* zone, BasicBlock::Id id,
|
||||
BasicBlock::RpoNumber ao_number,
|
||||
BasicBlock::RpoNumber rpo_number,
|
||||
BasicBlock::RpoNumber loop_header,
|
||||
BasicBlock::RpoNumber loop_end, bool deferred);
|
||||
@ -905,6 +904,8 @@ class InstructionSequence FINAL : public ZoneObject {
|
||||
public:
|
||||
static InstructionBlocks* InstructionBlocksFor(Zone* zone,
|
||||
const Schedule* schedule);
|
||||
// Puts the deferred blocks last.
|
||||
static void ComputeAssemblyOrder(InstructionBlocks* blocks);
|
||||
|
||||
InstructionSequence(Zone* zone, InstructionBlocks* instruction_blocks);
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace internal {
|
||||
namespace compiler {
|
||||
|
||||
BasicBlock::BasicBlock(Zone* zone, Id id)
|
||||
: ao_number_(-1),
|
||||
: loop_number_(-1),
|
||||
rpo_number_(-1),
|
||||
deferred_(false),
|
||||
dominator_depth_(-1),
|
||||
|
@ -163,9 +163,8 @@ class BasicBlock FINAL : public ZoneObject {
|
||||
int32_t loop_depth() const { return loop_depth_; }
|
||||
void set_loop_depth(int32_t loop_depth);
|
||||
|
||||
RpoNumber GetAoNumber() const { return RpoNumber::FromInt(ao_number_); }
|
||||
int32_t ao_number() const { return ao_number_; }
|
||||
void set_ao_number(int32_t ao_number) { ao_number_ = ao_number; }
|
||||
int32_t loop_number() const { return loop_number_; }
|
||||
void set_loop_number(int32_t loop_number) { loop_number_ = loop_number; }
|
||||
|
||||
RpoNumber GetRpoNumber() const { return RpoNumber::FromInt(rpo_number_); }
|
||||
int32_t rpo_number() const { return rpo_number_; }
|
||||
@ -176,7 +175,7 @@ class BasicBlock FINAL : public ZoneObject {
|
||||
bool LoopContains(BasicBlock* block) const;
|
||||
|
||||
private:
|
||||
int32_t ao_number_; // assembly order number of the block.
|
||||
int32_t loop_number_; // loop number of the block.
|
||||
int32_t rpo_number_; // special RPO number of the block.
|
||||
bool deferred_; // true if the block contains deferred code.
|
||||
int32_t dominator_depth_; // Depth within the dominator tree.
|
||||
|
@ -568,20 +568,6 @@ class SpecialRPONumberer : public ZoneObject {
|
||||
ComputeAndInsertSpecialRPO(entry, end);
|
||||
}
|
||||
|
||||
// Serialize the previously computed order as an assembly order (non-deferred
|
||||
// code first, deferred code afterwards) into the final schedule.
|
||||
void SerializeAOIntoSchedule() {
|
||||
int32_t number = 0;
|
||||
for (BasicBlock* b = order_; b != NULL; b = b->rpo_next()) {
|
||||
if (b->deferred()) continue;
|
||||
b->set_ao_number(number++);
|
||||
}
|
||||
for (BasicBlock* b = order_; b != NULL; b = b->rpo_next()) {
|
||||
if (!b->deferred()) continue;
|
||||
b->set_ao_number(number++);
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize the previously computed order as a special reverse-post-order
|
||||
// numbering for basic blocks into the final schedule.
|
||||
void SerializeRPOIntoSchedule() {
|
||||
@ -648,14 +634,12 @@ class SpecialRPONumberer : public ZoneObject {
|
||||
return block;
|
||||
}
|
||||
|
||||
// We are hijacking the {ao_number} to enumerate loops temporarily. Note that
|
||||
// these numbers are only valid within this class.
|
||||
static int GetLoopNumber(BasicBlock* block) { return block->ao_number(); }
|
||||
static int GetLoopNumber(BasicBlock* block) { return block->loop_number(); }
|
||||
static void SetLoopNumber(BasicBlock* block, int loop_number) {
|
||||
return block->set_ao_number(loop_number);
|
||||
return block->set_loop_number(loop_number);
|
||||
}
|
||||
static bool HasLoopNumber(BasicBlock* block) {
|
||||
return block->ao_number() >= 0;
|
||||
return block->loop_number() >= 0;
|
||||
}
|
||||
|
||||
// TODO(mstarzinger): We only need this special sentinel because some tests
|
||||
@ -673,7 +657,7 @@ class SpecialRPONumberer : public ZoneObject {
|
||||
// mutating any existing order so that the result is still valid.
|
||||
void ComputeAndInsertSpecialRPO(BasicBlock* entry, BasicBlock* end) {
|
||||
// RPO should not have been serialized for this schedule yet.
|
||||
CHECK_EQ(kBlockUnvisited1, schedule_->start()->ao_number());
|
||||
CHECK_EQ(kBlockUnvisited1, schedule_->start()->loop_number());
|
||||
CHECK_EQ(kBlockUnvisited1, schedule_->start()->rpo_number());
|
||||
CHECK_EQ(0, static_cast<int>(schedule_->rpo_order()->size()));
|
||||
|
||||
@ -1031,7 +1015,6 @@ class SpecialRPONumberer : public ZoneObject {
|
||||
BasicBlockVector* Scheduler::ComputeSpecialRPO(Zone* zone, Schedule* schedule) {
|
||||
SpecialRPONumberer numberer(zone, schedule);
|
||||
numberer.ComputeSpecialRPO();
|
||||
numberer.SerializeAOIntoSchedule();
|
||||
numberer.SerializeRPOIntoSchedule();
|
||||
numberer.PrintAndVerifySpecialRPO();
|
||||
return schedule->rpo_order();
|
||||
@ -1412,7 +1395,6 @@ void Scheduler::SealFinalSchedule() {
|
||||
Trace("--- SEAL FINAL SCHEDULE ------------------------------------\n");
|
||||
|
||||
// Serialize the assembly order and reverse-post-order numbering.
|
||||
special_rpo_->SerializeAOIntoSchedule();
|
||||
special_rpo_->SerializeRPOIntoSchedule();
|
||||
special_rpo_->PrintAndVerifySpecialRPO();
|
||||
|
||||
|
@ -89,8 +89,7 @@ class TestCode : public HandleAndZoneScope {
|
||||
if (current_ == NULL) {
|
||||
current_ = new (main_zone()) InstructionBlock(
|
||||
main_zone(), BasicBlock::Id::FromInt(rpo_number_.ToInt()),
|
||||
rpo_number_, rpo_number_, RpoNumber::Invalid(), RpoNumber::Invalid(),
|
||||
deferred);
|
||||
rpo_number_, RpoNumber::Invalid(), RpoNumber::Invalid(), deferred);
|
||||
blocks_.push_back(current_);
|
||||
sequence_.StartBlock(rpo_number_);
|
||||
}
|
||||
|
@ -35,17 +35,6 @@ static void CheckRPONumbers(BasicBlockVector* order, size_t expected,
|
||||
CHECK_EQ(NULL, order->at(i)->loop_header());
|
||||
}
|
||||
}
|
||||
int number = 0;
|
||||
for (auto const block : *order) {
|
||||
if (block->deferred()) continue;
|
||||
CHECK_EQ(number, block->ao_number());
|
||||
++number;
|
||||
}
|
||||
for (auto const block : *order) {
|
||||
if (!block->deferred()) continue;
|
||||
CHECK_EQ(number, block->ao_number());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -406,8 +406,8 @@ InstructionBlock* InstructionSequenceTest::NewBlock() {
|
||||
}
|
||||
}
|
||||
// Construct instruction block.
|
||||
auto instruction_block = new (zone()) InstructionBlock(
|
||||
zone(), block_id, rpo, rpo, loop_header, loop_end, false);
|
||||
auto instruction_block = new (zone())
|
||||
InstructionBlock(zone(), block_id, rpo, loop_header, loop_end, false);
|
||||
instruction_blocks_.push_back(instruction_block);
|
||||
current_block_ = instruction_block;
|
||||
sequence()->StartBlock(rpo);
|
||||
|
Loading…
Reference in New Issue
Block a user