Commit fe7001ab authored by mtrofin's avatar mtrofin Committed by Commit bot

[turbofan] Print APIs for live ranges.

Decoupled the Print APIs from RegisterAllocationData, and placed them
on the various APIs. Way easier to use these at debug time even outside
the register allocation pipeline.

BUG=

Review URL: https://codereview.chromium.org/1528983005

Cr-Commit-Position: refs/heads/master@{#32930}
parent 5bd48324
......@@ -59,6 +59,22 @@ FlagsCondition CommuteFlagsCondition(FlagsCondition condition) {
}
void InstructionOperand::Print(const RegisterConfiguration* config) const {
OFStream os(stdout);
PrintableInstructionOperand wrapper;
wrapper.register_configuration_ = config;
wrapper.op_ = *this;
os << wrapper << std::endl;
}
void InstructionOperand::Print() const {
const RegisterConfiguration* config =
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN);
Print(config);
}
std::ostream& operator<<(std::ostream& os,
const PrintableInstructionOperand& printable) {
const InstructionOperand& op = printable.op_;
......@@ -152,6 +168,24 @@ std::ostream& operator<<(std::ostream& os,
}
void MoveOperands::Print(const RegisterConfiguration* config) const {
OFStream os(stdout);
PrintableInstructionOperand wrapper;
wrapper.register_configuration_ = config;
wrapper.op_ = destination();
os << wrapper << " = ";
wrapper.op_ = source();
os << wrapper << std::endl;
}
void MoveOperands::Print() const {
const RegisterConfiguration* config =
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN);
Print(config);
}
std::ostream& operator<<(std::ostream& os,
const PrintableMoveOperands& printable) {
const MoveOperands& mo = *printable.move_operands_;
......@@ -254,6 +288,22 @@ bool Instruction::AreMovesRedundant() const {
}
void Instruction::Print(const RegisterConfiguration* config) const {
OFStream os(stdout);
PrintableInstruction wrapper;
wrapper.instr_ = this;
wrapper.register_configuration_ = config;
os << wrapper << std::endl;
}
void Instruction::Print() const {
const RegisterConfiguration* config =
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN);
Print(config);
}
std::ostream& operator<<(std::ostream& os,
const PrintableParallelMove& printable) {
const ParallelMove& pm = *printable.parallel_move_;
......@@ -744,6 +794,22 @@ void InstructionSequence::SetSourcePosition(const Instruction* instr,
}
void InstructionSequence::Print(const RegisterConfiguration* config) const {
OFStream os(stdout);
PrintableInstructionSequence wrapper;
wrapper.register_configuration_ = config;
wrapper.sequence_ = this;
os << wrapper << std::endl;
}
void InstructionSequence::Print() const {
const RegisterConfiguration* config =
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN);
Print(config);
}
FrameStateDescriptor::FrameStateDescriptor(
Zone* zone, FrameStateType type, BailoutId bailout_id,
OutputFrameStateCombine state_combine, size_t parameters_count,
......
......@@ -94,6 +94,9 @@ class InstructionOperand {
return this->GetCanonicalizedValue() < that.GetCanonicalizedValue();
}
void Print(const RegisterConfiguration* config) const;
void Print() const;
protected:
explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {}
......@@ -588,6 +591,9 @@ class MoveOperands final : public ZoneObject {
return source_.IsInvalid();
}
void Print(const RegisterConfiguration* config) const;
void Print() const;
private:
InstructionOperand source_;
InstructionOperand destination_;
......@@ -791,6 +797,9 @@ class Instruction final {
ParallelMove* const* parallel_moves() const { return &parallel_moves_[0]; }
ParallelMove** parallel_moves() { return &parallel_moves_[0]; }
void Print(const RegisterConfiguration* config) const;
void Print() const;
private:
explicit Instruction(InstructionCode opcode);
......@@ -1246,6 +1255,8 @@ class InstructionSequence final : public ZoneObject {
}
return false;
}
void Print(const RegisterConfiguration* config) const;
void Print() const;
private:
friend std::ostream& operator<<(std::ostream& os,
......
......@@ -230,6 +230,12 @@ UseInterval* UseInterval::SplitAt(LifetimePosition pos, Zone* zone) {
}
void LifetimePosition::Print() const {
OFStream os(stdout);
os << *this << std::endl;
}
std::ostream& operator<<(std::ostream& os, const LifetimePosition pos) {
os << '@' << pos.ToInstructionIndex();
if (pos.IsGapPosition()) {
......@@ -664,6 +670,26 @@ unsigned LiveRange::GetSize() {
}
void LiveRange::Print(const RegisterConfiguration* config,
bool with_children) const {
OFStream os(stdout);
PrintableLiveRange wrapper;
wrapper.register_configuration_ = config;
for (const LiveRange* i = this; i != nullptr; i = i->next()) {
wrapper.range_ = i;
os << wrapper << std::endl;
if (!with_children) break;
}
}
void LiveRange::Print(bool with_children) const {
const RegisterConfiguration* config =
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN);
Print(config, with_children);
}
struct TopLevelLiveRange::SpillMoveInsertionList : ZoneObject {
SpillMoveInsertionList(int gap_index, InstructionOperand* operand,
SpillMoveInsertionList* next)
......@@ -1180,6 +1206,21 @@ void SpillRange::MergeDisjointIntervals(UseInterval* other) {
}
void SpillRange::Print() const {
OFStream os(stdout);
os << "{" << std::endl;
for (TopLevelLiveRange* range : live_ranges()) {
os << range->vreg() << " ";
}
os << std::endl;
for (UseInterval* i = interval(); i != nullptr; i = i->next()) {
os << '[' << i->start() << ", " << i->end() << ')' << std::endl;
}
os << "}" << std::endl;
}
RegisterAllocationData::PhiMapValue::PhiMapValue(PhiInstruction* phi,
const InstructionBlock* block,
Zone* zone)
......@@ -1422,74 +1463,6 @@ bool RegisterAllocationData::IsBlockBoundary(LifetimePosition pos) const {
}
void RegisterAllocationData::Print(
const InstructionSequence* instructionSequence) {
OFStream os(stdout);
PrintableInstructionSequence wrapper;
wrapper.register_configuration_ = config();
wrapper.sequence_ = instructionSequence;
os << wrapper << std::endl;
}
void RegisterAllocationData::Print(const Instruction* instruction) {
OFStream os(stdout);
PrintableInstruction wrapper;
wrapper.instr_ = instruction;
wrapper.register_configuration_ = config();
os << wrapper << std::endl;
}
void RegisterAllocationData::Print(const LiveRange* range, bool with_children) {
OFStream os(stdout);
PrintableLiveRange wrapper;
wrapper.register_configuration_ = config();
for (const LiveRange* i = range; i != nullptr; i = i->next()) {
wrapper.range_ = i;
os << wrapper << std::endl;
if (!with_children) break;
}
}
void RegisterAllocationData::Print(const InstructionOperand& op) {
OFStream os(stdout);
PrintableInstructionOperand wrapper;
wrapper.register_configuration_ = config();
wrapper.op_ = op;
os << wrapper << std::endl;
}
void RegisterAllocationData::Print(const MoveOperands* move) {
OFStream os(stdout);
PrintableInstructionOperand wrapper;
wrapper.register_configuration_ = config();
wrapper.op_ = move->destination();
os << wrapper << " = ";
wrapper.op_ = move->source();
os << wrapper << std::endl;
}
void RegisterAllocationData::Print(const SpillRange* spill_range) {
OFStream os(stdout);
os << "{" << std::endl;
for (TopLevelLiveRange* range : spill_range->live_ranges()) {
os << range->vreg() << " ";
}
os << std::endl;
for (UseInterval* interval = spill_range->interval(); interval != nullptr;
interval = interval->next()) {
os << '[' << interval->start() << ", " << interval->end() << ')'
<< std::endl;
}
os << "}" << std::endl;
}
ConstraintBuilder::ConstraintBuilder(RegisterAllocationData* data)
: data_(data) {}
......
......@@ -135,6 +135,8 @@ class LifetimePosition final {
return this->value_ >= that.value_;
}
void Print() const;
static inline LifetimePosition Invalid() { return LifetimePosition(); }
static inline LifetimePosition MaxPosition() {
......@@ -409,6 +411,8 @@ class LiveRange : public ZoneObject {
void set_weight(float weight) { weight_ = weight; }
LiveRangeGroup* group() const { return group_; }
void set_group(LiveRangeGroup* group) { group_ = group; }
void Print(const RegisterConfiguration* config, bool with_children) const;
void Print(bool with_children) const;
static const int kInvalidSize = -1;
static const float kInvalidWeight;
......@@ -688,6 +692,7 @@ class SpillRange final : public ZoneObject {
ZoneVector<TopLevelLiveRange*>& live_ranges() { return live_ranges_; }
int byte_width() const { return byte_width_; }
RegisterKind kind() const { return kind_; }
void Print() const;
private:
LifetimePosition End() const { return end_position_; }
......@@ -811,13 +816,6 @@ class RegisterAllocationData final : public ZoneObject {
return preassigned_slot_ranges_;
}
void Print(const InstructionSequence* instructionSequence);
void Print(const Instruction* instruction);
void Print(const LiveRange* range, bool with_children = false);
void Print(const InstructionOperand& op);
void Print(const MoveOperands* move);
void Print(const SpillRange* spill_range);
private:
int GetNextLiveRangeId();
......
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