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

View File

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

View File

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

View File

@ -1137,8 +1137,7 @@ std::ostream& operator<<(std::ostream& os,
UsePosition* use_pos = range->first_pos();
while (use_pos != nullptr) {
if (use_pos->HasOperand()) {
os << PrintableInstructionOperand{*use_pos->operand()} << use_pos->pos()
<< " ";
os << *use_pos->operand() << use_pos->pos() << " ";
}
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();
j <= instruction_block->last_instruction_index(); j++) {
PrintIndent();
os_ << j << " " << PrintableInstruction{instructions->InstructionAt(j)}
<< " <|@\n";
os_ << j << " " << *instructions->InstructionAt(j) << " <|@\n";
}
}
}

View File

@ -2718,7 +2718,7 @@ void TraceSequence(OptimizedCompilationInfo* info, PipelineData* data,
CodeTracer::Scope tracing_scope(data->GetCodeTracer());
OFStream os(tracing_scope.file());
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,
const InterpreterState& is) {
for (OperandMap::const_iterator it = is.values_.begin();
it != is.values_.end(); ++it) {
if (it != is.values_.begin()) os << " ";
InstructionOperand source = FromKey(it->second);
InstructionOperand destination = FromKey(it->first);
MoveOperands mo(source, destination);
os << PrintableMoveOperands{&mo};
const char* space = "";
for (auto& value : is.values_) {
InstructionOperand source = FromKey(value.second);
InstructionOperand destination = FromKey(value.first);
os << space << MoveOperands{source, destination};
space = " ";
}
return os;
}

View File

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

View File

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