[cleanup] Remove unneeded Printable wrappers

Remove PrintableInstructionSequence and friends, just overload
operator<< directly for the respective types.

R=herhut@chromium.org

Bug: v8:8238
Change-Id: I67713978ab06f7ec5309e52b4090256480f362b1
Reviewed-on: https://chromium-review.googlesource.com/c/1346113
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Stephan Herhut <herhut@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57722}
This commit is contained in:
Clemens Hammacher 2018-11-21 13:44:39 +01:00 committed by Commit Bot
parent 1f6d5a4362
commit b2a7292c96
9 changed files with 58 additions and 111 deletions

View File

@ -119,15 +119,9 @@ bool LocationOperand::IsCompatible(LocationOperand* op) {
} }
} }
void InstructionOperand::Print() const { void InstructionOperand::Print() const { StdoutStream{} << *this << std::endl; }
PrintableInstructionOperand wrapper;
wrapper.op_ = *this;
StdoutStream{} << wrapper << std::endl;
}
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const InstructionOperand& op) {
const PrintableInstructionOperand& printable) {
const InstructionOperand& op = printable.op_;
switch (op.kind()) { switch (op.kind()) {
case InstructionOperand::UNALLOCATED: { case InstructionOperand::UNALLOCATED: {
const UnallocatedOperand* unalloc = UnallocatedOperand::cast(&op); const UnallocatedOperand* unalloc = UnallocatedOperand::cast(&op);
@ -245,18 +239,13 @@ std::ostream& operator<<(std::ostream& os,
} }
void MoveOperands::Print() const { void MoveOperands::Print() const {
StdoutStream{} << PrintableInstructionOperand{destination()} << " = " StdoutStream{} << destination() << " = " << source() << std::endl;
<< PrintableInstructionOperand{source()} << std::endl;
} }
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const MoveOperands& mo) {
const PrintableMoveOperands& printable) { os << mo.destination();
const MoveOperands& mo = *printable.move_operands_;
PrintableInstructionOperand printable_op = {mo.destination()};
os << printable_op;
if (!mo.source().Equals(mo.destination())) { if (!mo.source().Equals(mo.destination())) {
printable_op.op_ = mo.source(); os << " = " << mo.source();
os << " = " << printable_op;
} }
return os << ";"; return os << ";";
} }
@ -352,19 +341,14 @@ bool Instruction::AreMovesRedundant() const {
return true; return true;
} }
void Instruction::Print() const { void Instruction::Print() const { StdoutStream{} << *this << std::endl; }
StdoutStream{} << PrintableInstruction{this} << std::endl;
}
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const ParallelMove& pm) {
const PrintableParallelMove& printable) { const char* space = "";
const ParallelMove& pm = *printable.parallel_move_;
bool first = true;
for (MoveOperands* move : pm) { for (MoveOperands* move : pm) {
if (move->IsEliminated()) continue; if (move->IsEliminated()) continue;
if (!first) os << " "; os << space << *move;
first = false; space = " ";
os << PrintableMoveOperands{move};
} }
return os; return os;
} }
@ -378,14 +362,10 @@ void ReferenceMap::RecordReference(const AllocatedOperand& op) {
std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm) { std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm) {
os << "{"; os << "{";
bool first = true; const char* separator = "";
for (const InstructionOperand& op : pm.reference_operands_) { for (const InstructionOperand& op : pm.reference_operands_) {
if (!first) { os << separator << op;
os << ";"; separator = ";";
} else {
first = false;
}
os << PrintableInstructionOperand{op};
} }
return os << "}"; return os << "}";
} }
@ -488,29 +468,28 @@ std::ostream& operator<<(std::ostream& os, const FlagsCondition& fc) {
UNREACHABLE(); UNREACHABLE();
} }
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const Instruction& instr) {
const PrintableInstruction& printable) {
const Instruction& instr = *printable.instr_;
os << "gap "; os << "gap ";
for (int i = Instruction::FIRST_GAP_POSITION; for (int i = Instruction::FIRST_GAP_POSITION;
i <= Instruction::LAST_GAP_POSITION; i++) { i <= Instruction::LAST_GAP_POSITION; i++) {
os << "("; os << "(";
if (instr.parallel_moves()[i] != nullptr) { if (instr.parallel_moves()[i] != nullptr) {
os << PrintableParallelMove{instr.parallel_moves()[i]}; os << *instr.parallel_moves()[i];
} }
os << ") "; os << ") ";
} }
os << "\n "; os << "\n ";
if (instr.OutputCount() > 1) os << "("; if (instr.OutputCount() == 1) {
for (size_t i = 0; i < instr.OutputCount(); i++) { os << *instr.OutputAt(0) << " = ";
if (i > 0) os << ", "; } else if (instr.OutputCount() > 1) {
os << PrintableInstructionOperand{*instr.OutputAt(i)}; os << "(" << *instr.OutputAt(0);
for (size_t i = 1; i < instr.OutputCount(); i++) {
os << ", " << *instr.OutputAt(i);
}
os << ") = ";
} }
if (instr.OutputCount() > 1) os << ") = ";
if (instr.OutputCount() == 1) os << " = ";
os << ArchOpcodeField::decode(instr.opcode()); os << ArchOpcodeField::decode(instr.opcode());
AddressingMode am = AddressingModeField::decode(instr.opcode()); AddressingMode am = AddressingModeField::decode(instr.opcode());
if (am != kMode_None) { if (am != kMode_None) {
@ -520,10 +499,8 @@ std::ostream& operator<<(std::ostream& os,
if (fm != kFlags_none) { if (fm != kFlags_none) {
os << " && " << fm << " if " << FlagsConditionField::decode(instr.opcode()); os << " && " << fm << " if " << FlagsConditionField::decode(instr.opcode());
} }
if (instr.InputCount() > 0) { for (size_t i = 0; i < instr.InputCount(); i++) {
for (size_t i = 0; i < instr.InputCount(); i++) { os << " " << *instr.InputAt(i);
os << " " << PrintableInstructionOperand{*instr.InputAt(i)};
}
} }
return os; return os;
} }
@ -678,7 +655,7 @@ std::ostream& operator<<(std::ostream& os,
os << std::endl; os << std::endl;
for (const PhiInstruction* phi : block->phis()) { for (const PhiInstruction* phi : block->phis()) {
os << " phi: " << PrintableInstructionOperand{phi->output()} << " ="; os << " phi: " << phi->output() << " =";
for (int input : phi->operands()) { for (int input : phi->operands()) {
os << " v" << input; os << " v" << input;
} }
@ -687,8 +664,8 @@ std::ostream& operator<<(std::ostream& os,
for (int j = block->first_instruction_index(); for (int j = block->first_instruction_index();
j <= block->last_instruction_index(); j++) { j <= block->last_instruction_index(); j++) {
os << " " << std::setw(5) << j << ": " os << " " << std::setw(5) << j << ": " << *code->InstructionAt(j)
<< PrintableInstruction{code->InstructionAt(j)} << std::endl; << std::endl;
} }
os << " successors:"; os << " successors:";
@ -975,7 +952,7 @@ void InstructionSequence::SetSourcePosition(const Instruction* instr,
} }
void InstructionSequence::Print() const { void InstructionSequence::Print() const {
StdoutStream{} << PrintableInstructionSequence{this} << std::endl; StdoutStream{} << *this << std::endl;
} }
void InstructionSequence::PrintBlock(int block_id) const { void InstructionSequence::PrintBlock(int block_id) const {
@ -1054,9 +1031,7 @@ std::ostream& operator<<(std::ostream& os, const RpoNumber& rpo) {
return os << rpo.ToSize(); return os << rpo.ToSize();
} }
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const InstructionSequence& code) {
const PrintableInstructionSequence& printable) {
const InstructionSequence& code = *printable.sequence_;
for (size_t i = 0; i < code.immediates_.size(); ++i) { for (size_t i = 0; i < code.immediates_.size(); ++i) {
Constant constant = code.immediates_[i]; Constant constant = code.immediates_[i];
os << "IMM#" << i << ": " << constant << "\n"; os << "IMM#" << i << ": " << constant << "\n";
@ -1066,10 +1041,9 @@ 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 = {nullptr, printable.sequence_};
for (int i = 0; i < code.InstructionBlockCount(); i++) { for (int i = 0; i < code.InstructionBlockCount(); i++) {
printable_block.block_ = code.InstructionBlockAt(RpoNumber::FromInt(i)); auto* block = code.InstructionBlockAt(RpoNumber::FromInt(i));
os << printable_block; os << PrintableInstructionBlock{block, &code};
} }
return os; return os;
} }

View File

@ -136,12 +136,7 @@ class V8_EXPORT_PRIVATE InstructionOperand {
typedef ZoneVector<InstructionOperand> InstructionOperandVector; typedef ZoneVector<InstructionOperand> InstructionOperandVector;
struct PrintableInstructionOperand { std::ostream& operator<<(std::ostream&, const InstructionOperand&);
InstructionOperand op_;
};
std::ostream& operator<<(std::ostream& os,
const PrintableInstructionOperand& op);
#define INSTRUCTION_OPERAND_CASTS(OperandType, OperandKind) \ #define INSTRUCTION_OPERAND_CASTS(OperandType, OperandKind) \
\ \
@ -703,11 +698,7 @@ class V8_EXPORT_PRIVATE MoveOperands final
DISALLOW_COPY_AND_ASSIGN(MoveOperands); DISALLOW_COPY_AND_ASSIGN(MoveOperands);
}; };
struct PrintableMoveOperands { std::ostream& operator<<(std::ostream&, const MoveOperands&);
const MoveOperands* move_operands_;
};
std::ostream& operator<<(std::ostream& os, const PrintableMoveOperands& mo);
class V8_EXPORT_PRIVATE ParallelMove final class V8_EXPORT_PRIVATE ParallelMove final
: public NON_EXPORTED_BASE(ZoneVector<MoveOperands*>), : public NON_EXPORTED_BASE(ZoneVector<MoveOperands*>),
@ -743,11 +734,7 @@ class V8_EXPORT_PRIVATE ParallelMove final
DISALLOW_COPY_AND_ASSIGN(ParallelMove); DISALLOW_COPY_AND_ASSIGN(ParallelMove);
}; };
struct PrintableParallelMove { std::ostream& operator<<(std::ostream&, const ParallelMove&);
const ParallelMove* parallel_move_;
};
std::ostream& operator<<(std::ostream& os, const PrintableParallelMove& pm);
class ReferenceMap final : public ZoneObject { class ReferenceMap final : public ZoneObject {
public: public:
@ -767,13 +754,13 @@ class ReferenceMap final : public ZoneObject {
void RecordReference(const AllocatedOperand& op); void RecordReference(const AllocatedOperand& op);
private: private:
friend std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm); friend std::ostream& operator<<(std::ostream&, const ReferenceMap&);
ZoneVector<InstructionOperand> reference_operands_; ZoneVector<InstructionOperand> reference_operands_;
int instruction_position_; int instruction_position_;
}; };
std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm); std::ostream& operator<<(std::ostream&, const ReferenceMap&);
class InstructionBlock; class InstructionBlock;
@ -963,10 +950,7 @@ class V8_EXPORT_PRIVATE Instruction final {
DISALLOW_COPY_AND_ASSIGN(Instruction); DISALLOW_COPY_AND_ASSIGN(Instruction);
}; };
struct PrintableInstruction { std::ostream& operator<<(std::ostream&, const Instruction&);
const Instruction* instr_;
};
std::ostream& operator<<(std::ostream& os, const PrintableInstruction& instr);
class RpoNumber final { class RpoNumber final {
public: public:
@ -1084,7 +1068,7 @@ class V8_EXPORT_PRIVATE Constant final {
int64_t value_; int64_t value_;
}; };
std::ostream& operator<<(std::ostream& os, const Constant& constant); std::ostream& operator<<(std::ostream&, const Constant&);
// Forward declarations. // Forward declarations.
class FrameStateDescriptor; class FrameStateDescriptor;
@ -1437,8 +1421,7 @@ struct PrintableInstructionBlock {
const InstructionSequence* code_; const InstructionSequence* code_;
}; };
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream&, const PrintableInstructionBlock&);
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>,
@ -1449,9 +1432,6 @@ typedef ZoneDeque<Instruction*> InstructionDeque;
typedef ZoneDeque<ReferenceMap*> ReferenceMapDeque; typedef ZoneDeque<ReferenceMap*> ReferenceMapDeque;
typedef ZoneVector<InstructionBlock*> InstructionBlocks; typedef ZoneVector<InstructionBlock*> InstructionBlocks;
// Forward declarations.
struct PrintableInstructionSequence;
// Represents architecture-specific generated code before, during, and after // Represents architecture-specific generated code before, during, and after
// register allocation. // register allocation.
class V8_EXPORT_PRIVATE InstructionSequence final class V8_EXPORT_PRIVATE InstructionSequence final
@ -1616,8 +1596,8 @@ class V8_EXPORT_PRIVATE InstructionSequence final
void RecomputeAssemblyOrderForTesting(); void RecomputeAssemblyOrderForTesting();
private: private:
friend V8_EXPORT_PRIVATE std::ostream& operator<<( friend V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&,
std::ostream& os, const PrintableInstructionSequence& code); const InstructionSequence&);
typedef ZoneMap<const Instruction*, SourcePosition> SourcePositionMap; typedef ZoneMap<const Instruction*, SourcePosition> SourcePositionMap;
@ -1647,12 +1627,8 @@ class V8_EXPORT_PRIVATE InstructionSequence final
DISALLOW_COPY_AND_ASSIGN(InstructionSequence); DISALLOW_COPY_AND_ASSIGN(InstructionSequence);
}; };
struct PrintableInstructionSequence { V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&,
const InstructionSequence* sequence_; const InstructionSequence&);
};
V8_EXPORT_PRIVATE std::ostream& operator<<(
std::ostream& os, const PrintableInstructionSequence& code);
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal

View File

@ -318,7 +318,7 @@ void BlockAssessments::Print() const {
const Assessment* assessment = pair.second; const Assessment* assessment = pair.second;
// Use operator<< so we can write the assessment on the same // Use operator<< so we can write the assessment on the same
// line. // line.
os << PrintableInstructionOperand{op} << " : "; os << op << " : ";
if (assessment->kind() == AssessmentKind::Final) { if (assessment->kind() == AssessmentKind::Final) {
os << "v" << FinalAssessment::cast(assessment)->virtual_register(); os << "v" << FinalAssessment::cast(assessment)->virtual_register();
} else { } else {

View File

@ -1137,8 +1137,7 @@ std::ostream& operator<<(std::ostream& os,
UsePosition* use_pos = range->first_pos(); UsePosition* use_pos = range->first_pos();
while (use_pos != nullptr) { while (use_pos != nullptr) {
if (use_pos->HasOperand()) { if (use_pos->HasOperand()) {
os << PrintableInstructionOperand{*use_pos->operand()} << use_pos->pos() os << *use_pos->operand() << use_pos->pos() << " ";
<< " ";
} }
use_pos = use_pos->next(); use_pos = use_pos->next();
} }

View File

@ -699,8 +699,7 @@ void GraphC1Visualizer::PrintSchedule(const char* phase,
for (int j = instruction_block->first_instruction_index(); for (int j = instruction_block->first_instruction_index();
j <= instruction_block->last_instruction_index(); j++) { j <= instruction_block->last_instruction_index(); j++) {
PrintIndent(); PrintIndent();
os_ << j << " " << PrintableInstruction{instructions->InstructionAt(j)} os_ << j << " " << *instructions->InstructionAt(j) << " <|@\n";
<< " <|@\n";
} }
} }
} }

View File

@ -2718,7 +2718,7 @@ void TraceSequence(OptimizedCompilationInfo* info, PipelineData* data,
CodeTracer::Scope tracing_scope(data->GetCodeTracer()); CodeTracer::Scope tracing_scope(data->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
os << "----- Instruction sequence " << phase_name << " -----\n" os << "----- Instruction sequence " << phase_name << " -----\n"
<< PrintableInstructionSequence{data->sequence()}; << *data->sequence();
} }
} }

View File

@ -165,13 +165,12 @@ class InterpreterState {
friend std::ostream& operator<<(std::ostream& os, friend std::ostream& operator<<(std::ostream& os,
const InterpreterState& is) { const InterpreterState& is) {
for (OperandMap::const_iterator it = is.values_.begin(); const char* space = "";
it != is.values_.end(); ++it) { for (auto& value : is.values_) {
if (it != is.values_.begin()) os << " "; InstructionOperand source = FromKey(value.second);
InstructionOperand source = FromKey(it->second); InstructionOperand destination = FromKey(value.first);
InstructionOperand destination = FromKey(it->first); os << space << MoveOperands{source, destination};
MoveOperands mo(source, destination); space = " ";
os << PrintableMoveOperands{&mo};
} }
return os; return os;
} }

View File

@ -49,7 +49,7 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
StdoutStream{} << "=== Code sequence after instruction selection ===" StdoutStream{} << "=== Code sequence after instruction selection ==="
<< std::endl << std::endl
<< PrintableInstructionSequence{&sequence}; << sequence;
} }
Stream s; Stream s;
s.virtual_registers_ = selector.GetVirtualRegistersForTesting(); s.virtual_registers_ = selector.GetVirtualRegistersForTesting();

View File

@ -55,14 +55,14 @@ class MoveOptimizerTest : public InstructionSequenceTest {
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
StdoutStream{} StdoutStream{}
<< "----- Instruction sequence before move optimization -----\n" << "----- Instruction sequence before move optimization -----\n"
<< PrintableInstructionSequence{sequence()}; << *sequence();
} }
MoveOptimizer move_optimizer(zone(), sequence()); MoveOptimizer move_optimizer(zone(), sequence());
move_optimizer.Run(); move_optimizer.Run();
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
StdoutStream{} StdoutStream{}
<< "----- Instruction sequence after move optimization -----\n" << "----- Instruction sequence after move optimization -----\n"
<< PrintableInstructionSequence{sequence()}; << *sequence();
} }
} }