Commit 44e2dd53 authored by dcarney's avatar dcarney Committed by Commit bot

[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}
parent 7b9cb2eb
...@@ -173,11 +173,6 @@ Instruction* InstructionSelector::Emit(Instruction* instr) { ...@@ -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 { bool InstructionSelector::CanCover(Node* user, Node* node) const {
return node->OwnedBy(user) && return node->OwnedBy(user) &&
schedule()->block(node) == schedule()->block(user); schedule()->block(node) == schedule()->block(user);
......
...@@ -133,10 +133,6 @@ class InstructionSelector FINAL { ...@@ -133,10 +133,6 @@ class InstructionSelector FINAL {
private: private:
friend class OperandGenerator; 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. // Inform the instruction selection that {node} was just defined.
void MarkAsDefined(Node* node); void MarkAsDefined(Node* node);
......
...@@ -348,7 +348,6 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant) { ...@@ -348,7 +348,6 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant) {
InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id, InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id,
BasicBlock::RpoNumber ao_number,
BasicBlock::RpoNumber rpo_number, BasicBlock::RpoNumber rpo_number,
BasicBlock::RpoNumber loop_header, BasicBlock::RpoNumber loop_header,
BasicBlock::RpoNumber loop_end, BasicBlock::RpoNumber loop_end,
...@@ -357,7 +356,7 @@ InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id, ...@@ -357,7 +356,7 @@ InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id,
predecessors_(zone), predecessors_(zone),
phis_(zone), phis_(zone),
id_(id), id_(id),
ao_number_(ao_number), ao_number_(rpo_number),
rpo_number_(rpo_number), rpo_number_(rpo_number),
loop_header_(loop_header), loop_header_(loop_header),
loop_end_(loop_end), loop_end_(loop_end),
...@@ -392,8 +391,8 @@ static BasicBlock::RpoNumber GetLoopEndRpo(const BasicBlock* block) { ...@@ -392,8 +391,8 @@ static BasicBlock::RpoNumber GetLoopEndRpo(const BasicBlock* block) {
static InstructionBlock* InstructionBlockFor(Zone* zone, static InstructionBlock* InstructionBlockFor(Zone* zone,
const BasicBlock* block) { const BasicBlock* block) {
InstructionBlock* instr_block = new (zone) InstructionBlock( InstructionBlock* instr_block = new (zone) InstructionBlock(
zone, block->id(), block->GetAoNumber(), block->GetRpoNumber(), zone, block->id(), block->GetRpoNumber(), GetRpo(block->loop_header()),
GetRpo(block->loop_header()), GetLoopEndRpo(block), block->deferred()); GetLoopEndRpo(block), block->deferred());
// Map successors and precessors // Map successors and precessors
instr_block->successors().reserve(block->SuccessorCount()); instr_block->successors().reserve(block->SuccessorCount());
for (auto it = block->successors_begin(); it != block->successors_end(); for (auto it = block->successors_begin(); it != block->successors_end();
...@@ -421,10 +420,26 @@ InstructionBlocks* InstructionSequence::InstructionBlocksFor( ...@@ -421,10 +420,26 @@ InstructionBlocks* InstructionSequence::InstructionBlocksFor(
DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number); DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number);
(*blocks)[rpo_number] = InstructionBlockFor(zone, *it); (*blocks)[rpo_number] = InstructionBlockFor(zone, *it);
} }
ComputeAssemblyOrder(blocks);
return 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, InstructionSequence::InstructionSequence(Zone* instruction_zone,
InstructionBlocks* instruction_blocks) InstructionBlocks* instruction_blocks)
: zone_(instruction_zone), : zone_(instruction_zone),
......
...@@ -816,7 +816,6 @@ class PhiInstruction FINAL : public ZoneObject { ...@@ -816,7 +816,6 @@ class PhiInstruction FINAL : public ZoneObject {
class InstructionBlock FINAL : public ZoneObject { class InstructionBlock FINAL : public ZoneObject {
public: public:
InstructionBlock(Zone* zone, BasicBlock::Id id, InstructionBlock(Zone* zone, BasicBlock::Id id,
BasicBlock::RpoNumber ao_number,
BasicBlock::RpoNumber rpo_number, BasicBlock::RpoNumber rpo_number,
BasicBlock::RpoNumber loop_header, BasicBlock::RpoNumber loop_header,
BasicBlock::RpoNumber loop_end, bool deferred); BasicBlock::RpoNumber loop_end, bool deferred);
...@@ -905,6 +904,8 @@ class InstructionSequence FINAL : public ZoneObject { ...@@ -905,6 +904,8 @@ class InstructionSequence FINAL : public ZoneObject {
public: public:
static InstructionBlocks* InstructionBlocksFor(Zone* zone, static InstructionBlocks* InstructionBlocksFor(Zone* zone,
const Schedule* schedule); const Schedule* schedule);
// Puts the deferred blocks last.
static void ComputeAssemblyOrder(InstructionBlocks* blocks);
InstructionSequence(Zone* zone, InstructionBlocks* instruction_blocks); InstructionSequence(Zone* zone, InstructionBlocks* instruction_blocks);
......
...@@ -13,7 +13,7 @@ namespace internal { ...@@ -13,7 +13,7 @@ namespace internal {
namespace compiler { namespace compiler {
BasicBlock::BasicBlock(Zone* zone, Id id) BasicBlock::BasicBlock(Zone* zone, Id id)
: ao_number_(-1), : loop_number_(-1),
rpo_number_(-1), rpo_number_(-1),
deferred_(false), deferred_(false),
dominator_depth_(-1), dominator_depth_(-1),
......
...@@ -163,9 +163,8 @@ class BasicBlock FINAL : public ZoneObject { ...@@ -163,9 +163,8 @@ class BasicBlock FINAL : public ZoneObject {
int32_t loop_depth() const { return loop_depth_; } int32_t loop_depth() const { return loop_depth_; }
void set_loop_depth(int32_t loop_depth); void set_loop_depth(int32_t loop_depth);
RpoNumber GetAoNumber() const { return RpoNumber::FromInt(ao_number_); } int32_t loop_number() const { return loop_number_; }
int32_t ao_number() const { return ao_number_; } void set_loop_number(int32_t loop_number) { loop_number_ = loop_number; }
void set_ao_number(int32_t ao_number) { ao_number_ = ao_number; }
RpoNumber GetRpoNumber() const { return RpoNumber::FromInt(rpo_number_); } RpoNumber GetRpoNumber() const { return RpoNumber::FromInt(rpo_number_); }
int32_t rpo_number() const { return rpo_number_; } int32_t rpo_number() const { return rpo_number_; }
...@@ -176,7 +175,7 @@ class BasicBlock FINAL : public ZoneObject { ...@@ -176,7 +175,7 @@ class BasicBlock FINAL : public ZoneObject {
bool LoopContains(BasicBlock* block) const; bool LoopContains(BasicBlock* block) const;
private: 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. int32_t rpo_number_; // special RPO number of the block.
bool deferred_; // true if the block contains deferred code. bool deferred_; // true if the block contains deferred code.
int32_t dominator_depth_; // Depth within the dominator tree. int32_t dominator_depth_; // Depth within the dominator tree.
......
...@@ -568,20 +568,6 @@ class SpecialRPONumberer : public ZoneObject { ...@@ -568,20 +568,6 @@ class SpecialRPONumberer : public ZoneObject {
ComputeAndInsertSpecialRPO(entry, end); 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 // Serialize the previously computed order as a special reverse-post-order
// numbering for basic blocks into the final schedule. // numbering for basic blocks into the final schedule.
void SerializeRPOIntoSchedule() { void SerializeRPOIntoSchedule() {
...@@ -648,14 +634,12 @@ class SpecialRPONumberer : public ZoneObject { ...@@ -648,14 +634,12 @@ class SpecialRPONumberer : public ZoneObject {
return block; return block;
} }
// We are hijacking the {ao_number} to enumerate loops temporarily. Note that static int GetLoopNumber(BasicBlock* block) { return block->loop_number(); }
// these numbers are only valid within this class.
static int GetLoopNumber(BasicBlock* block) { return block->ao_number(); }
static void SetLoopNumber(BasicBlock* block, int 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) { 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 // TODO(mstarzinger): We only need this special sentinel because some tests
...@@ -673,7 +657,7 @@ class SpecialRPONumberer : public ZoneObject { ...@@ -673,7 +657,7 @@ class SpecialRPONumberer : public ZoneObject {
// mutating any existing order so that the result is still valid. // mutating any existing order so that the result is still valid.
void ComputeAndInsertSpecialRPO(BasicBlock* entry, BasicBlock* end) { void ComputeAndInsertSpecialRPO(BasicBlock* entry, BasicBlock* end) {
// RPO should not have been serialized for this schedule yet. // 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(kBlockUnvisited1, schedule_->start()->rpo_number());
CHECK_EQ(0, static_cast<int>(schedule_->rpo_order()->size())); CHECK_EQ(0, static_cast<int>(schedule_->rpo_order()->size()));
...@@ -1031,7 +1015,6 @@ class SpecialRPONumberer : public ZoneObject { ...@@ -1031,7 +1015,6 @@ class SpecialRPONumberer : public ZoneObject {
BasicBlockVector* Scheduler::ComputeSpecialRPO(Zone* zone, Schedule* schedule) { BasicBlockVector* Scheduler::ComputeSpecialRPO(Zone* zone, Schedule* schedule) {
SpecialRPONumberer numberer(zone, schedule); SpecialRPONumberer numberer(zone, schedule);
numberer.ComputeSpecialRPO(); numberer.ComputeSpecialRPO();
numberer.SerializeAOIntoSchedule();
numberer.SerializeRPOIntoSchedule(); numberer.SerializeRPOIntoSchedule();
numberer.PrintAndVerifySpecialRPO(); numberer.PrintAndVerifySpecialRPO();
return schedule->rpo_order(); return schedule->rpo_order();
...@@ -1412,7 +1395,6 @@ void Scheduler::SealFinalSchedule() { ...@@ -1412,7 +1395,6 @@ void Scheduler::SealFinalSchedule() {
Trace("--- SEAL FINAL SCHEDULE ------------------------------------\n"); Trace("--- SEAL FINAL SCHEDULE ------------------------------------\n");
// Serialize the assembly order and reverse-post-order numbering. // Serialize the assembly order and reverse-post-order numbering.
special_rpo_->SerializeAOIntoSchedule();
special_rpo_->SerializeRPOIntoSchedule(); special_rpo_->SerializeRPOIntoSchedule();
special_rpo_->PrintAndVerifySpecialRPO(); special_rpo_->PrintAndVerifySpecialRPO();
......
...@@ -89,8 +89,7 @@ class TestCode : public HandleAndZoneScope { ...@@ -89,8 +89,7 @@ class TestCode : public HandleAndZoneScope {
if (current_ == NULL) { if (current_ == NULL) {
current_ = new (main_zone()) InstructionBlock( current_ = new (main_zone()) InstructionBlock(
main_zone(), BasicBlock::Id::FromInt(rpo_number_.ToInt()), main_zone(), BasicBlock::Id::FromInt(rpo_number_.ToInt()),
rpo_number_, rpo_number_, RpoNumber::Invalid(), RpoNumber::Invalid(), rpo_number_, RpoNumber::Invalid(), RpoNumber::Invalid(), deferred);
deferred);
blocks_.push_back(current_); blocks_.push_back(current_);
sequence_.StartBlock(rpo_number_); sequence_.StartBlock(rpo_number_);
} }
......
...@@ -35,17 +35,6 @@ static void CheckRPONumbers(BasicBlockVector* order, size_t expected, ...@@ -35,17 +35,6 @@ static void CheckRPONumbers(BasicBlockVector* order, size_t expected,
CHECK_EQ(NULL, order->at(i)->loop_header()); 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() { ...@@ -406,8 +406,8 @@ InstructionBlock* InstructionSequenceTest::NewBlock() {
} }
} }
// Construct instruction block. // Construct instruction block.
auto instruction_block = new (zone()) InstructionBlock( auto instruction_block = new (zone())
zone(), block_id, rpo, rpo, loop_header, loop_end, false); InstructionBlock(zone(), block_id, rpo, loop_header, loop_end, false);
instruction_blocks_.push_back(instruction_block); instruction_blocks_.push_back(instruction_block);
current_block_ = instruction_block; current_block_ = instruction_block;
sequence()->StartBlock(rpo); sequence()->StartBlock(rpo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment