Commit 817a60cc authored by mtrofin's avatar mtrofin Committed by Commit bot

[turbofan] Print APIs are for debugging.

The Print APIs on the instruction model are for debugging. At debug
time, we cannot (easily) synthesize an output stream, hence the choice
of directing to stdout in those APIs.

The concern in https://codereview.chromium.org/2293413004/ is
addressed by the changes in pipeline.cc, using the various operator<<,
and does not require the changes in instruction.{h|cc}, and the
generalization of the Print APIs.

BUG=

Review-Url: https://codereview.chromium.org/2304423002
Cr-Commit-Position: refs/heads/master@{#39190}
parent 82396efc
...@@ -68,17 +68,15 @@ bool InstructionOperand::InterferesWith(const InstructionOperand& that) const { ...@@ -68,17 +68,15 @@ bool InstructionOperand::InterferesWith(const InstructionOperand& that) const {
return EqualsCanonicalized(that); return EqualsCanonicalized(that);
} }
void InstructionOperand::Print(std::ostream& os, void InstructionOperand::Print(const RegisterConfiguration* config) const {
const RegisterConfiguration* config) const { OFStream os(stdout);
PrintableInstructionOperand wrapper; PrintableInstructionOperand wrapper;
wrapper.register_configuration_ = config; wrapper.register_configuration_ = config;
wrapper.op_ = *this; wrapper.op_ = *this;
os << wrapper << std::endl; os << wrapper << std::endl;
} }
void InstructionOperand::Print(std::ostream& os) const { void InstructionOperand::Print() const { Print(GetRegConfig()); }
Print(os, GetRegConfig());
}
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os,
const PrintableInstructionOperand& printable) { const PrintableInstructionOperand& printable) {
...@@ -201,8 +199,8 @@ std::ostream& operator<<(std::ostream& os, ...@@ -201,8 +199,8 @@ std::ostream& operator<<(std::ostream& os,
return os; return os;
} }
void MoveOperands::Print(std::ostream& os, void MoveOperands::Print(const RegisterConfiguration* config) const {
const RegisterConfiguration* config) const { OFStream os(stdout);
PrintableInstructionOperand wrapper; PrintableInstructionOperand wrapper;
wrapper.register_configuration_ = config; wrapper.register_configuration_ = config;
wrapper.op_ = destination(); wrapper.op_ = destination();
...@@ -211,7 +209,7 @@ void MoveOperands::Print(std::ostream& os, ...@@ -211,7 +209,7 @@ void MoveOperands::Print(std::ostream& os,
os << wrapper << std::endl; os << wrapper << std::endl;
} }
void MoveOperands::Print(std::ostream& os) const { Print(os, GetRegConfig()); } void MoveOperands::Print() const { Print(GetRegConfig()); }
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os,
const PrintableMoveOperands& printable) { const PrintableMoveOperands& printable) {
...@@ -316,15 +314,15 @@ bool Instruction::AreMovesRedundant() const { ...@@ -316,15 +314,15 @@ bool Instruction::AreMovesRedundant() const {
return true; return true;
} }
void Instruction::Print(std::ostream& os, void Instruction::Print(const RegisterConfiguration* config) const {
const RegisterConfiguration* config) const { OFStream os(stdout);
PrintableInstruction wrapper; PrintableInstruction wrapper;
wrapper.instr_ = this; wrapper.instr_ = this;
wrapper.register_configuration_ = config; wrapper.register_configuration_ = config;
os << wrapper << std::endl; os << wrapper << std::endl;
} }
void Instruction::Print(std::ostream& os) const { Print(os, GetRegConfig()); } void Instruction::Print() const { Print(GetRegConfig()); }
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os,
const PrintableParallelMove& printable) { const PrintableParallelMove& printable) {
...@@ -632,6 +630,58 @@ static InstructionBlock* InstructionBlockFor(Zone* zone, ...@@ -632,6 +630,58 @@ static InstructionBlock* InstructionBlockFor(Zone* zone,
return instr_block; return instr_block;
} }
std::ostream& operator<<(std::ostream& os,
PrintableInstructionBlock& printable_block) {
const InstructionBlock* block = printable_block.block_;
const RegisterConfiguration* config = printable_block.register_configuration_;
const InstructionSequence* code = printable_block.code_;
os << "B" << block->rpo_number();
os << ": AO#" << block->ao_number();
if (block->IsDeferred()) os << " (deferred)";
if (!block->needs_frame()) os << " (no frame)";
if (block->must_construct_frame()) os << " (construct frame)";
if (block->must_deconstruct_frame()) os << " (deconstruct frame)";
if (block->IsLoopHeader()) {
os << " loop blocks: [" << block->rpo_number() << ", " << block->loop_end()
<< ")";
}
os << " instructions: [" << block->code_start() << ", " << block->code_end()
<< ")" << std::endl
<< " predecessors:";
for (RpoNumber pred : block->predecessors()) {
os << " B" << pred.ToInt();
}
os << std::endl;
for (const PhiInstruction* phi : block->phis()) {
PrintableInstructionOperand printable_op = {config, phi->output()};
os << " phi: " << printable_op << " =";
for (int input : phi->operands()) {
os << " v" << input;
}
os << std::endl;
}
ScopedVector<char> buf(32);
PrintableInstruction printable_instr;
printable_instr.register_configuration_ = config;
for (int j = block->first_instruction_index();
j <= block->last_instruction_index(); j++) {
// TODO(svenpanne) Add some basic formatting to our streams.
SNPrintF(buf, "%5d", j);
printable_instr.instr_ = code->InstructionAt(j);
os << " " << buf.start() << ": " << printable_instr << std::endl;
}
for (RpoNumber succ : block->successors()) {
os << " B" << succ.ToInt();
}
os << std::endl;
return os;
}
InstructionBlocks* InstructionSequence::InstructionBlocksFor( InstructionBlocks* InstructionSequence::InstructionBlocksFor(
Zone* zone, const Schedule* schedule) { Zone* zone, const Schedule* schedule) {
InstructionBlocks* blocks = zone->NewArray<InstructionBlocks>(1); InstructionBlocks* blocks = zone->NewArray<InstructionBlocks>(1);
...@@ -875,71 +925,28 @@ void InstructionSequence::SetSourcePosition(const Instruction* instr, ...@@ -875,71 +925,28 @@ void InstructionSequence::SetSourcePosition(const Instruction* instr,
source_positions_.insert(std::make_pair(instr, value)); source_positions_.insert(std::make_pair(instr, value));
} }
void InstructionSequence::Print(std::ostream& os, void InstructionSequence::Print(const RegisterConfiguration* config) const {
const RegisterConfiguration* config) const { OFStream os(stdout);
PrintableInstructionSequence wrapper; PrintableInstructionSequence wrapper;
wrapper.register_configuration_ = config; wrapper.register_configuration_ = config;
wrapper.sequence_ = this; wrapper.sequence_ = this;
os << wrapper << std::endl; os << wrapper << std::endl;
} }
void InstructionSequence::Print(std::ostream& os) const { void InstructionSequence::Print() const { Print(GetRegConfig()); }
Print(os, GetRegConfig());
}
void InstructionSequence::PrintBlock(std::ostream& os, void InstructionSequence::PrintBlock(const RegisterConfiguration* config,
const RegisterConfiguration* config,
int block_id) const { int block_id) const {
OFStream os(stdout);
RpoNumber rpo = RpoNumber::FromInt(block_id); RpoNumber rpo = RpoNumber::FromInt(block_id);
const InstructionBlock* block = InstructionBlockAt(rpo); const InstructionBlock* block = InstructionBlockAt(rpo);
CHECK(block->rpo_number() == rpo); CHECK(block->rpo_number() == rpo);
PrintableInstructionBlock printable_block = {config, block, this};
os << "B" << block->rpo_number(); os << printable_block << std::endl;
os << ": AO#" << block->ao_number();
if (block->IsDeferred()) os << " (deferred)";
if (!block->needs_frame()) os << " (no frame)";
if (block->must_construct_frame()) os << " (construct frame)";
if (block->must_deconstruct_frame()) os << " (deconstruct frame)";
if (block->IsLoopHeader()) {
os << " loop blocks: [" << block->rpo_number() << ", " << block->loop_end()
<< ")";
}
os << " instructions: [" << block->code_start() << ", " << block->code_end()
<< ")\n predecessors:";
for (RpoNumber pred : block->predecessors()) {
os << " B" << pred.ToInt();
}
os << "\n";
for (const PhiInstruction* phi : block->phis()) {
PrintableInstructionOperand printable_op = {config, phi->output()};
os << " phi: " << printable_op << " =";
for (int input : phi->operands()) {
os << " v" << input;
}
os << "\n";
}
ScopedVector<char> buf(32);
PrintableInstruction printable_instr;
printable_instr.register_configuration_ = config;
for (int j = block->first_instruction_index();
j <= block->last_instruction_index(); j++) {
// TODO(svenpanne) Add some basic formatting to our streams.
SNPrintF(buf, "%5d", j);
printable_instr.instr_ = InstructionAt(j);
os << " " << buf.start() << ": " << printable_instr << "\n";
}
for (RpoNumber succ : block->successors()) {
os << " B" << succ.ToInt();
}
os << "\n";
} }
void InstructionSequence::PrintBlock(std::ostream& os, int block_id) const { void InstructionSequence::PrintBlock(int block_id) const {
PrintBlock(os, GetRegConfig(), block_id); PrintBlock(GetRegConfig(), block_id);
} }
FrameStateDescriptor::FrameStateDescriptor( FrameStateDescriptor::FrameStateDescriptor(
...@@ -1022,8 +1029,11 @@ std::ostream& operator<<(std::ostream& os, ...@@ -1022,8 +1029,11 @@ std::ostream& operator<<(std::ostream& os,
it != code.constants_.end(); ++i, ++it) { it != code.constants_.end(); ++i, ++it) {
os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n";
} }
PrintableInstructionBlock printable_block = {
printable.register_configuration_, nullptr, printable.sequence_};
for (int i = 0; i < code.InstructionBlockCount(); i++) { for (int i = 0; i < code.InstructionBlockCount(); i++) {
printable.sequence_->PrintBlock(os, printable.register_configuration_, i); printable_block.block_ = code.InstructionBlockAt(RpoNumber::FromInt(i));
os << printable_block;
} }
return os; return os;
} }
......
...@@ -105,8 +105,9 @@ class InstructionOperand { ...@@ -105,8 +105,9 @@ class InstructionOperand {
bool InterferesWith(const InstructionOperand& that) const; bool InterferesWith(const InstructionOperand& that) const;
void Print(std::ostream& os, const RegisterConfiguration* config) const; // APIs to aid debugging. For general-stream APIs, use operator<<
void Print(std::ostream& os) const; void Print(const RegisterConfiguration* config) const;
void Print() const;
protected: protected:
explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {} explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {}
...@@ -672,8 +673,9 @@ class MoveOperands final : public ZoneObject { ...@@ -672,8 +673,9 @@ class MoveOperands final : public ZoneObject {
return source_.IsInvalid(); return source_.IsInvalid();
} }
void Print(std::ostream& os, const RegisterConfiguration* config) const; // APIs to aid debugging. For general-stream APIs, use operator<<
void Print(std::ostream& os) const; void Print(const RegisterConfiguration* config) const;
void Print() const;
private: private:
InstructionOperand source_; InstructionOperand source_;
...@@ -912,8 +914,9 @@ class Instruction final { ...@@ -912,8 +914,9 @@ class Instruction final {
block_ = block; block_ = block;
} }
void Print(std::ostream& os, const RegisterConfiguration* config) const; // APIs to aid debugging. For general-stream APIs, use operator<<
void Print(std::ostream& os) const; void Print(const RegisterConfiguration* config) const;
void Print() const;
private: private:
explicit Instruction(InstructionCode opcode); explicit Instruction(InstructionCode opcode);
...@@ -1282,6 +1285,17 @@ class InstructionBlock final : public ZoneObject { ...@@ -1282,6 +1285,17 @@ class InstructionBlock final : public ZoneObject {
RpoNumber last_deferred_; RpoNumber last_deferred_;
}; };
class InstructionSequence;
struct PrintableInstructionBlock {
const RegisterConfiguration* register_configuration_;
const InstructionBlock* block_;
const InstructionSequence* code_;
};
std::ostream& operator<<(std::ostream& os,
const PrintableInstructionBlock& printable_block);
typedef ZoneDeque<Constant> ConstantDeque; typedef ZoneDeque<Constant> ConstantDeque;
typedef std::map<int, Constant, std::less<int>, typedef std::map<int, Constant, std::less<int>,
zone_allocator<std::pair<const int, Constant> > > ConstantMap; zone_allocator<std::pair<const int, Constant> > > ConstantMap;
...@@ -1441,12 +1455,13 @@ class InstructionSequence final : public ZoneObject { ...@@ -1441,12 +1455,13 @@ class InstructionSequence final : public ZoneObject {
} }
return false; return false;
} }
void Print(std::ostream& os, const RegisterConfiguration* config) const;
void Print(std::ostream& os) const;
void PrintBlock(std::ostream& os, const RegisterConfiguration* config, // APIs to aid debugging. For general-stream APIs, use operator<<
int block_id) const; void Print(const RegisterConfiguration* config) const;
void PrintBlock(std::ostream& os, int block_id) const; void Print() const;
void PrintBlock(const RegisterConfiguration* config, int block_id) const;
void PrintBlock(int block_id) const;
void ValidateEdgeSplitForm() const; void ValidateEdgeSplitForm() const;
void ValidateDeferredBlockExitPaths() const; void ValidateDeferredBlockExitPaths() const;
......
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