diff --git a/llvm/tools/llvm-mca/InstructionInfoView.cpp b/llvm/tools/llvm-mca/InstructionInfoView.cpp index 289ca03da5da..76d63d21cb22 100644 --- a/llvm/tools/llvm-mca/InstructionInfoView.cpp +++ b/llvm/tools/llvm-mca/InstructionInfoView.cpp @@ -25,11 +25,14 @@ void InstructionInfoView::printView(raw_ostream &OS) const { const MCSchedModel &SM = STI.getSchedModel(); unsigned Instructions = Source.size(); + std::string Instruction; + raw_string_ostream InstrStream(Instruction); + TempStream << "\n\nInstruction Info:\n"; TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n" << "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects\n\n"; - TempStream << "[1] [2] [3] [4] [5] [6]\tInstructions:\n"; + TempStream << "[1] [2] [3] [4] [5] [6] Instructions:\n"; for (unsigned I = 0, E = Instructions; I < E; ++I) { const MCInst &Inst = Source.getMCInstFromIndex(I); const MCInstrDesc &MCDesc = MCII.get(Inst.getOpcode()); @@ -65,8 +68,15 @@ void InstructionInfoView::printView(raw_ostream &OS) const { TempStream << (MCDesc.mayLoad() ? " * " : " "); TempStream << (MCDesc.mayStore() ? " * " : " "); TempStream << (MCDesc.hasUnmodeledSideEffects() ? " * " : " "); - MCIP.printInst(&Inst, TempStream, "", STI); - TempStream << '\n'; + + MCIP.printInst(&Inst, InstrStream, "", STI); + InstrStream.flush(); + + // Consume any tabs or spaces at the beginning of the string. + StringRef Str(Instruction); + Str = Str.ltrim(); + TempStream << " " << Str << '\n'; + Instruction = ""; } TempStream.flush(); diff --git a/llvm/tools/llvm-mca/ResourcePressureView.cpp b/llvm/tools/llvm-mca/ResourcePressureView.cpp index 6fd23ccf346f..874aa6d15cdb 100644 --- a/llvm/tools/llvm-mca/ResourcePressureView.cpp +++ b/llvm/tools/llvm-mca/ResourcePressureView.cpp @@ -144,7 +144,10 @@ void ResourcePressureView::printResourcePressurePerInstruction( TempStream << "\n\nResource pressure by instruction:\n"; printColumnNames(TempStream, STI.getSchedModel()); - TempStream << "\tInstructions:\n"; + TempStream << "Instructions:\n"; + + std::string Instruction; + raw_string_ostream InstrStream(Instruction); for (unsigned I = 0, E = Source.size(); I < E; ++I) { for (unsigned J = 0; J < NumResourceUnits; ++J) { @@ -152,8 +155,16 @@ void ResourcePressureView::printResourcePressurePerInstruction( printResourcePressure(TempStream, Usage / Executions); } - MCIP.printInst(&Source.getMCInstFromIndex(I), TempStream, "", STI); - TempStream << '\n'; + MCIP.printInst(&Source.getMCInstFromIndex(I), InstrStream, "", STI); + InstrStream.flush(); + StringRef Str(Instruction); + + // Remove any tabs or spaces at the beginning of the instruction. + Str = Str.ltrim(); + + TempStream << Str << '\n'; + Instruction = ""; + TempStream.flush(); OS << Buffer; Buffer = ""; diff --git a/llvm/tools/llvm-mca/TimelineView.cpp b/llvm/tools/llvm-mca/TimelineView.cpp index 952b5bd6e7b8..71ebb44116d1 100644 --- a/llvm/tools/llvm-mca/TimelineView.cpp +++ b/llvm/tools/llvm-mca/TimelineView.cpp @@ -98,7 +98,7 @@ void TimelineView::printWaitTimeEntry(raw_string_ostream &OS, OS << ' '; if (Entry.Executions == 0) { - OS << " - - - - "; + OS << " - - - - "; } else { double AverageTime1, AverageTime2, AverageTime3; unsigned Executions = Entry.Executions; @@ -133,13 +133,25 @@ void TimelineView::printAverageWaitTimes(raw_ostream &OS) const { << "[3]: Average time elapsed from WB until retire stage\n\n"; TempStream << " [0] [1] [2] [3]\n"; + // Use a different string stream for the instruction. + std::string Instruction; + raw_string_ostream InstrStream(Instruction); + for (unsigned I = 0, E = WaitTime.size(); I < E; ++I) { printWaitTimeEntry(TempStream, WaitTime[I], I); // Append the instruction info at the end of the line. const MCInst &Inst = AsmSequence.getMCInstFromIndex(I); - MCIP.printInst(&Inst, TempStream, "", STI); - TempStream << '\n'; + + MCIP.printInst(&Inst, InstrStream, "", STI); + InstrStream.flush(); + + // Consume any tabs or spaces at the beginning of the string. + StringRef Str(Instruction); + Str = Str.ltrim(); + TempStream << " " << Str << '\n'; TempStream.flush(); + Instruction = ""; + OS << Buffer; Buffer = ""; } @@ -210,6 +222,10 @@ void TimelineView::printTimeline(raw_ostream &OS) const { TempStream.flush(); OS << Buffer; + // Use a different string stream for the instruction. + std::string Instruction; + raw_string_ostream InstrStream(Instruction); + for (unsigned I = 0, E = Timeline.size(); I < E; ++I) { Buffer = ""; const TimelineViewEntry &Entry = Timeline[I]; @@ -221,9 +237,15 @@ void TimelineView::printTimeline(raw_ostream &OS) const { printTimelineViewEntry(TempStream, Entry, Iteration, SourceIndex); // Append the instruction info at the end of the line. const MCInst &Inst = AsmSequence.getMCInstFromIndex(I); - MCIP.printInst(&Inst, TempStream, "", STI); - TempStream << '\n'; + MCIP.printInst(&Inst, InstrStream, "", STI); + InstrStream.flush(); + + // Consume any tabs or spaces at the beginning of the string. + StringRef Str(Instruction); + Str = Str.ltrim(); + TempStream << " " << Str << '\n'; TempStream.flush(); + Instruction = ""; OS << Buffer; } }