}
-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);
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);
InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id,
- BasicBlock::RpoNumber ao_number,
BasicBlock::RpoNumber rpo_number,
BasicBlock::RpoNumber loop_header,
BasicBlock::RpoNumber loop_end,
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),
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();
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),
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);
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);
namespace compiler {
BasicBlock::BasicBlock(Zone* zone, Id id)
- : ao_number_(-1),
+ : loop_number_(-1),
rpo_number_(-1),
deferred_(false),
dominator_depth_(-1),
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_; }
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.
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() {
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
// 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()));
BasicBlockVector* Scheduler::ComputeSpecialRPO(Zone* zone, Schedule* schedule) {
SpecialRPONumberer numberer(zone, schedule);
numberer.ComputeSpecialRPO();
- numberer.SerializeAOIntoSchedule();
numberer.SerializeRPOIntoSchedule();
numberer.PrintAndVerifySpecialRPO();
return schedule->rpo_order();
Trace("--- SEAL FINAL SCHEDULE ------------------------------------\n");
// Serialize the assembly order and reverse-post-order numbering.
- special_rpo_->SerializeAOIntoSchedule();
special_rpo_->SerializeRPOIntoSchedule();
special_rpo_->PrintAndVerifySpecialRPO();
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_);
}
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;
- }
}
}
}
// 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);