[llvm-mca] Removed dependency on mca::SourcMgr in some Views. NFC

llvm-svn: 345376
This commit is contained in:
Andrea Di Biagio 2018-10-26 10:48:04 +00:00
parent bde31000b1
commit 84d0051310
9 changed files with 61 additions and 44 deletions

View File

@ -35,8 +35,9 @@
#ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
#define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
#include "SourceMgr.h"
#include "Views/View.h" #include "Views/View.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSubtargetInfo.h"
@ -50,13 +51,13 @@ namespace mca {
class InstructionInfoView : public View { class InstructionInfoView : public View {
const llvm::MCSubtargetInfo &STI; const llvm::MCSubtargetInfo &STI;
const llvm::MCInstrInfo &MCII; const llvm::MCInstrInfo &MCII;
const SourceMgr &Source; llvm::ArrayRef<llvm::MCInst> Source;
llvm::MCInstPrinter &MCIP; llvm::MCInstPrinter &MCIP;
public: public:
InstructionInfoView(const llvm::MCSubtargetInfo &sti, InstructionInfoView(const llvm::MCSubtargetInfo &sti,
const llvm::MCInstrInfo &mcii, const SourceMgr &S, const llvm::MCInstrInfo &mcii,
llvm::MCInstPrinter &IP) llvm::ArrayRef<llvm::MCInst> S, llvm::MCInstPrinter &IP)
: STI(sti), MCII(mcii), Source(S), MCIP(IP) {} : STI(sti), MCII(mcii), Source(S), MCIP(IP) {}
void printView(llvm::raw_ostream &OS) const override; void printView(llvm::raw_ostream &OS) const override;

View File

@ -21,9 +21,9 @@ namespace mca {
using namespace llvm; using namespace llvm;
ResourcePressureView::ResourcePressureView(const llvm::MCSubtargetInfo &sti, ResourcePressureView::ResourcePressureView(const llvm::MCSubtargetInfo &sti,
llvm::MCInstPrinter &Printer, MCInstPrinter &Printer,
const SourceMgr &Sequence) ArrayRef<MCInst> S)
: STI(sti), MCIP(Printer), Source(Sequence) { : STI(sti), MCIP(Printer), Source(S), LastInstructionIdx(0) {
// Populate the map of resource descriptors. // Populate the map of resource descriptors.
unsigned R2VIndex = 0; unsigned R2VIndex = 0;
const MCSchedModel &SM = STI.getSchedModel(); const MCSchedModel &SM = STI.getSchedModel();
@ -44,9 +44,15 @@ ResourcePressureView::ResourcePressureView(const llvm::MCSubtargetInfo &sti,
} }
void ResourcePressureView::onEvent(const HWInstructionEvent &Event) { void ResourcePressureView::onEvent(const HWInstructionEvent &Event) {
if (Event.Type == HWInstructionEvent::Dispatched) {
LastInstructionIdx = Event.IR.getSourceIndex();
return;
}
// We're only interested in Issue events. // We're only interested in Issue events.
if (Event.Type != HWInstructionEvent::Issued) if (Event.Type != HWInstructionEvent::Issued)
return; return;
const auto &IssueEvent = static_cast<const HWInstructionIssuedEvent &>(Event); const auto &IssueEvent = static_cast<const HWInstructionIssuedEvent &>(Event);
const unsigned SourceIdx = Event.IR.getSourceIndex() % Source.size(); const unsigned SourceIdx = Event.IR.getSourceIndex() % Source.size();
for (const std::pair<ResourceRef, ResourceCycles> &Use : for (const std::pair<ResourceRef, ResourceCycles> &Use :
@ -128,7 +134,7 @@ void ResourcePressureView::printResourcePressurePerIter(raw_ostream &OS) const {
FOS << '\n'; FOS << '\n';
FOS.flush(); FOS.flush();
const unsigned Executions = Source.getNumIterations(); const unsigned Executions = LastInstructionIdx / Source.size() + 1;
for (unsigned I = 0, E = NumResourceUnits; I < E; ++I) { for (unsigned I = 0, E = NumResourceUnits; I < E; ++I) {
double Usage = ResourceUsage[I + Source.size() * E]; double Usage = ResourceUsage[I + Source.size() * E];
printResourcePressure(FOS, Usage / Executions, (I + 1) * 7); printResourcePressure(FOS, Usage / Executions, (I + 1) * 7);
@ -151,7 +157,7 @@ void ResourcePressureView::printResourcePressurePerInst(raw_ostream &OS) const {
raw_string_ostream InstrStream(Instruction); raw_string_ostream InstrStream(Instruction);
unsigned InstrIndex = 0; unsigned InstrIndex = 0;
const unsigned Executions = Source.getNumIterations(); const unsigned Executions = LastInstructionIdx / Source.size() + 1;
for (const MCInst &MCI : Source) { for (const MCInst &MCI : Source) {
unsigned BaseEltIdx = InstrIndex * NumResourceUnits; unsigned BaseEltIdx = InstrIndex * NumResourceUnits;
for (unsigned J = 0; J < NumResourceUnits; ++J) { for (unsigned J = 0; J < NumResourceUnits; ++J) {

View File

@ -58,12 +58,12 @@
#ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H #ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
#define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H #define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
#include "SourceMgr.h"
#include "Views/View.h" #include "Views/View.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSubtargetInfo.h"
#include <map>
namespace mca { namespace mca {
@ -72,7 +72,8 @@ namespace mca {
class ResourcePressureView : public View { class ResourcePressureView : public View {
const llvm::MCSubtargetInfo &STI; const llvm::MCSubtargetInfo &STI;
llvm::MCInstPrinter &MCIP; llvm::MCInstPrinter &MCIP;
const SourceMgr &Source; llvm::ArrayRef<llvm::MCInst> Source;
unsigned LastInstructionIdx;
// Map to quickly obtain the ResourceUsage column index from a processor // Map to quickly obtain the ResourceUsage column index from a processor
// resource ID. // resource ID.
@ -87,7 +88,8 @@ class ResourcePressureView : public View {
public: public:
ResourcePressureView(const llvm::MCSubtargetInfo &sti, ResourcePressureView(const llvm::MCSubtargetInfo &sti,
llvm::MCInstPrinter &Printer, const SourceMgr &SM); llvm::MCInstPrinter &Printer,
llvm::ArrayRef<llvm::MCInst> S);
void onEvent(const HWInstructionEvent &Event) override; void onEvent(const HWInstructionEvent &Event) override;
void printView(llvm::raw_ostream &OS) const override { void printView(llvm::raw_ostream &OS) const override {

View File

@ -24,14 +24,18 @@ namespace mca {
using namespace llvm; using namespace llvm;
SummaryView::SummaryView(const MCSchedModel &Model, const SourceMgr &S, SummaryView::SummaryView(const MCSchedModel &Model, ArrayRef<MCInst> S,
unsigned Width) unsigned Width)
: SM(Model), Source(S), DispatchWidth(Width), TotalCycles(0), : SM(Model), Source(S), DispatchWidth(Width), TotalCycles(0),
NumMicroOps(0), ProcResourceUsage(Model.getNumProcResourceKinds(), 0) { LastInstructionIdx(0), NumMicroOps(0),
ProcResourceUsage(Model.getNumProcResourceKinds(), 0) {
computeProcResourceMasks(SM, ProcResourceMasks); computeProcResourceMasks(SM, ProcResourceMasks);
} }
void SummaryView::onEvent(const HWInstructionEvent &Event) { void SummaryView::onEvent(const HWInstructionEvent &Event) {
if (Event.Type == HWInstructionEvent::Dispatched)
LastInstructionIdx = Event.IR.getSourceIndex();
// We are only interested in the "instruction retired" events generated by // We are only interested in the "instruction retired" events generated by
// the retire stage for instructions that are part of iteration #0. // the retire stage for instructions that are part of iteration #0.
if (Event.Type != HWInstructionEvent::Retired || if (Event.Type != HWInstructionEvent::Retired ||
@ -57,8 +61,8 @@ void SummaryView::onEvent(const HWInstructionEvent &Event) {
} }
void SummaryView::printView(raw_ostream &OS) const { void SummaryView::printView(raw_ostream &OS) const {
unsigned Iterations = Source.getNumIterations();
unsigned Instructions = Source.size(); unsigned Instructions = Source.size();
unsigned Iterations = (LastInstructionIdx / Instructions) + 1;
unsigned TotalInstructions = Instructions * Iterations; unsigned TotalInstructions = Instructions * Iterations;
unsigned TotalUOps = NumMicroOps * Iterations; unsigned TotalUOps = NumMicroOps * Iterations;
double IPC = (double)TotalInstructions / TotalCycles; double IPC = (double)TotalInstructions / TotalCycles;

View File

@ -29,7 +29,6 @@
#ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H #ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
#define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H #define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
#include "SourceMgr.h"
#include "Views/View.h" #include "Views/View.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/MC/MCSchedule.h" #include "llvm/MC/MCSchedule.h"
@ -40,8 +39,9 @@ namespace mca {
/// A view that collects and prints a few performance numbers. /// A view that collects and prints a few performance numbers.
class SummaryView : public View { class SummaryView : public View {
const llvm::MCSchedModel &SM; const llvm::MCSchedModel &SM;
const SourceMgr &Source; llvm::ArrayRef<llvm::MCInst> Source;
const unsigned DispatchWidth; const unsigned DispatchWidth;
unsigned LastInstructionIdx;
unsigned TotalCycles; unsigned TotalCycles;
// The total number of micro opcodes contributed by a block of instructions. // The total number of micro opcodes contributed by a block of instructions.
unsigned NumMicroOps; unsigned NumMicroOps;
@ -62,7 +62,7 @@ class SummaryView : public View {
double getBlockRThroughput() const; double getBlockRThroughput() const;
public: public:
SummaryView(const llvm::MCSchedModel &Model, const SourceMgr &S, SummaryView(const llvm::MCSchedModel &Model, llvm::ArrayRef<llvm::MCInst> S,
unsigned Width); unsigned Width);
void onCycleEnd() override { ++TotalCycles; } void onCycleEnd() override { ++TotalCycles; }

View File

@ -19,15 +19,14 @@ using namespace llvm;
namespace mca { namespace mca {
TimelineView::TimelineView(const MCSubtargetInfo &sti, MCInstPrinter &Printer, TimelineView::TimelineView(const MCSubtargetInfo &sti, MCInstPrinter &Printer,
const SourceMgr &S, unsigned MaxIterations, llvm::ArrayRef<llvm::MCInst> S, unsigned Iterations,
unsigned Cycles) unsigned Cycles)
: STI(sti), MCIP(Printer), AsmSequence(S), CurrentCycle(0), : STI(sti), MCIP(Printer), Source(S), CurrentCycle(0),
MaxCycle(Cycles == 0 ? 80 : Cycles), LastCycle(0), WaitTime(S.size()), MaxCycle(Cycles == 0 ? 80 : Cycles), LastCycle(0), WaitTime(S.size()),
UsedBuffer(S.size()) { UsedBuffer(S.size()) {
unsigned NumInstructions = AsmSequence.size(); unsigned NumInstructions = Source.size();
if (!MaxIterations) assert(Iterations && "Invalid number of iterations specified!");
MaxIterations = DEFAULT_ITERATIONS; NumInstructions *= Iterations;
NumInstructions *= std::min(MaxIterations, AsmSequence.getNumIterations());
Timeline.resize(NumInstructions); Timeline.resize(NumInstructions);
TimelineViewEntry InvalidTVEntry = {-1, 0, 0, 0, 0}; TimelineViewEntry InvalidTVEntry = {-1, 0, 0, 0, 0};
std::fill(Timeline.begin(), Timeline.end(), InvalidTVEntry); std::fill(Timeline.begin(), Timeline.end(), InvalidTVEntry);
@ -42,7 +41,7 @@ TimelineView::TimelineView(const MCSubtargetInfo &sti, MCInstPrinter &Printer,
void TimelineView::onReservedBuffers(const InstRef &IR, void TimelineView::onReservedBuffers(const InstRef &IR,
ArrayRef<unsigned> Buffers) { ArrayRef<unsigned> Buffers) {
if (IR.getSourceIndex() >= AsmSequence.size()) if (IR.getSourceIndex() >= Source.size())
return; return;
const MCSchedModel &SM = STI.getSchedModel(); const MCSchedModel &SM = STI.getSchedModel();
@ -72,7 +71,7 @@ void TimelineView::onEvent(const HWInstructionEvent &Event) {
// Update the WaitTime entry which corresponds to this Index. // Update the WaitTime entry which corresponds to this Index.
assert(TVEntry.CycleDispatched >= 0 && "Invalid TVEntry found!"); assert(TVEntry.CycleDispatched >= 0 && "Invalid TVEntry found!");
unsigned CycleDispatched = static_cast<unsigned>(TVEntry.CycleDispatched); unsigned CycleDispatched = static_cast<unsigned>(TVEntry.CycleDispatched);
WaitTimeEntry &WTEntry = WaitTime[Index % AsmSequence.size()]; WaitTimeEntry &WTEntry = WaitTime[Index % Source.size()];
WTEntry.CyclesSpentInSchedulerQueue += WTEntry.CyclesSpentInSchedulerQueue +=
TVEntry.CycleIssued - CycleDispatched; TVEntry.CycleIssued - CycleDispatched;
assert(CycleDispatched <= TVEntry.CycleReady && assert(CycleDispatched <= TVEntry.CycleReady &&
@ -176,9 +175,9 @@ void TimelineView::printAverageWaitTimes(raw_ostream &OS) const {
raw_string_ostream InstrStream(Instruction); raw_string_ostream InstrStream(Instruction);
formatted_raw_ostream FOS(OS); formatted_raw_ostream FOS(OS);
unsigned Executions = Timeline.size() / AsmSequence.size(); unsigned Executions = Timeline.size() / Source.size();
unsigned IID = 0; unsigned IID = 0;
for (const MCInst &Inst : AsmSequence) { for (const MCInst &Inst : Source) {
printWaitTimeEntry(FOS, WaitTime[IID], IID, Executions); printWaitTimeEntry(FOS, WaitTime[IID], IID, Executions);
// Append the instruction info at the end of the line. // Append the instruction info at the end of the line.
MCIP.printInst(&Inst, InstrStream, "", STI); MCIP.printInst(&Inst, InstrStream, "", STI);
@ -268,14 +267,14 @@ void TimelineView::printTimeline(raw_ostream &OS) const {
raw_string_ostream InstrStream(Instruction); raw_string_ostream InstrStream(Instruction);
unsigned IID = 0; unsigned IID = 0;
const unsigned Iterations = Timeline.size() / AsmSequence.size(); const unsigned Iterations = Timeline.size() / Source.size();
for (unsigned Iteration = 0; Iteration < Iterations; ++Iteration) { for (unsigned Iteration = 0; Iteration < Iterations; ++Iteration) {
for (const MCInst &Inst : AsmSequence) { for (const MCInst &Inst : Source) {
const TimelineViewEntry &Entry = Timeline[IID]; const TimelineViewEntry &Entry = Timeline[IID];
if (Entry.CycleRetired == 0) if (Entry.CycleRetired == 0)
return; return;
unsigned SourceIndex = IID % AsmSequence.size(); unsigned SourceIndex = IID % Source.size();
printTimelineViewEntry(FOS, Entry, Iteration, SourceIndex); printTimelineViewEntry(FOS, Entry, Iteration, SourceIndex);
// Append the instruction info at the end of the line. // Append the instruction info at the end of the line.
MCIP.printInst(&Inst, InstrStream, "", STI); MCIP.printInst(&Inst, InstrStream, "", STI);

View File

@ -100,8 +100,9 @@
#ifndef LLVM_TOOLS_LLVM_MCA_TIMELINEVIEW_H #ifndef LLVM_TOOLS_LLVM_MCA_TIMELINEVIEW_H
#define LLVM_TOOLS_LLVM_MCA_TIMELINEVIEW_H #define LLVM_TOOLS_LLVM_MCA_TIMELINEVIEW_H
#include "SourceMgr.h"
#include "Views/View.h" #include "Views/View.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
@ -119,7 +120,7 @@ namespace mca {
class TimelineView : public View { class TimelineView : public View {
const llvm::MCSubtargetInfo &STI; const llvm::MCSubtargetInfo &STI;
llvm::MCInstPrinter &MCIP; llvm::MCInstPrinter &MCIP;
const SourceMgr &AsmSequence; llvm::ArrayRef<llvm::MCInst> Source;
unsigned CurrentCycle; unsigned CurrentCycle;
unsigned MaxCycle; unsigned MaxCycle;
@ -166,7 +167,7 @@ class TimelineView : public View {
public: public:
TimelineView(const llvm::MCSubtargetInfo &sti, llvm::MCInstPrinter &Printer, TimelineView(const llvm::MCSubtargetInfo &sti, llvm::MCInstPrinter &Printer,
const SourceMgr &Sequence, unsigned MaxIterations, llvm::ArrayRef<llvm::MCInst> S, unsigned Iterations,
unsigned Cycles); unsigned Cycles);
// Event handlers. // Event handlers.

View File

@ -48,9 +48,8 @@ public:
using const_iterator = llvm::ArrayRef<llvm::MCInst>::const_iterator; using const_iterator = llvm::ArrayRef<llvm::MCInst>::const_iterator;
const_iterator begin() const { return Sequence.begin(); } const_iterator begin() const { return Sequence.begin(); }
const_iterator end() const { return Sequence.end(); } const_iterator end() const { return Sequence.end(); }
bool isEmpty() const { return size() == 0; }
}; };
} // namespace mca } // namespace mca
#endif #endif

View File

@ -497,6 +497,7 @@ int main(int argc, char **argv) {
// Number each region in the sequence. // Number each region in the sequence.
unsigned RegionIdx = 0; unsigned RegionIdx = 0;
for (const std::unique_ptr<mca::CodeRegion> &Region : Regions) { for (const std::unique_ptr<mca::CodeRegion> &Region : Regions) {
// Skip empty code regions. // Skip empty code regions.
if (Region->empty()) if (Region->empty())
@ -512,6 +513,7 @@ int main(int argc, char **argv) {
TOF->os() << "\n\n"; TOF->os() << "\n\n";
} }
ArrayRef<MCInst> Insts = Region->getInstructions();
mca::SourceMgr S(Region->getInstructions(), mca::SourceMgr S(Region->getInstructions(),
PrintInstructionTables ? 1 : Iterations); PrintInstructionTables ? 1 : Iterations);
@ -524,11 +526,11 @@ int main(int argc, char **argv) {
// Create the views for this pipeline, execute, and emit a report. // Create the views for this pipeline, execute, and emit a report.
if (PrintInstructionInfoView) { if (PrintInstructionInfoView) {
Printer.addView( Printer.addView(llvm::make_unique<mca::InstructionInfoView>(
llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, S, *IP)); *STI, *MCII, Insts, *IP));
} }
Printer.addView( Printer.addView(
llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S)); llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
if (!runPipeline(*P, *IP, *STI)) if (!runPipeline(*P, *IP, *STI))
return 1; return 1;
@ -542,11 +544,11 @@ int main(int argc, char **argv) {
mca::PipelinePrinter Printer(*P); mca::PipelinePrinter Printer(*P);
if (PrintSummaryView) if (PrintSummaryView)
Printer.addView(llvm::make_unique<mca::SummaryView>(SM, S, Width)); Printer.addView(llvm::make_unique<mca::SummaryView>(SM, Insts, Width));
if (PrintInstructionInfoView) if (PrintInstructionInfoView)
Printer.addView( Printer.addView(
llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, S, *IP)); llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, Insts, *IP));
if (PrintDispatchStats) if (PrintDispatchStats)
Printer.addView(llvm::make_unique<mca::DispatchStatistics>()); Printer.addView(llvm::make_unique<mca::DispatchStatistics>());
@ -562,11 +564,14 @@ int main(int argc, char **argv) {
if (PrintResourcePressureView) if (PrintResourcePressureView)
Printer.addView( Printer.addView(
llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S)); llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
if (PrintTimelineView) { if (PrintTimelineView) {
unsigned TimelineIterations =
TimelineMaxIterations ? TimelineMaxIterations : 10;
Printer.addView(llvm::make_unique<mca::TimelineView>( Printer.addView(llvm::make_unique<mca::TimelineView>(
*STI, *IP, S, TimelineMaxIterations, TimelineMaxCycles)); *STI, *IP, Insts, std::min(TimelineIterations, S.getNumIterations()),
TimelineMaxCycles));
} }
if (!runPipeline(*P, *IP, *STI)) if (!runPipeline(*P, *IP, *STI))