summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/tools/llvm-mca/Views/InstructionInfoView.h9
-rw-r--r--llvm/tools/llvm-mca/Views/ResourcePressureView.cpp16
-rw-r--r--llvm/tools/llvm-mca/Views/ResourcePressureView.h10
-rw-r--r--llvm/tools/llvm-mca/Views/SummaryView.cpp10
-rw-r--r--llvm/tools/llvm-mca/Views/SummaryView.h6
-rw-r--r--llvm/tools/llvm-mca/Views/TimelineView.cpp25
-rw-r--r--llvm/tools/llvm-mca/Views/TimelineView.h7
-rw-r--r--llvm/tools/llvm-mca/include/SourceMgr.h3
-rw-r--r--llvm/tools/llvm-mca/llvm-mca.cpp19
9 files changed, 61 insertions, 44 deletions
diff --git a/llvm/tools/llvm-mca/Views/InstructionInfoView.h b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
index 435c058d824..f7bbe6147d7 100644
--- a/llvm/tools/llvm-mca/Views/InstructionInfoView.h
+++ b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
@@ -35,8 +35,9 @@
#ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
#define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
-#include "SourceMgr.h"
#include "Views/View.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
@@ -50,13 +51,13 @@ namespace mca {
class InstructionInfoView : public View {
const llvm::MCSubtargetInfo &STI;
const llvm::MCInstrInfo &MCII;
- const SourceMgr &Source;
+ llvm::ArrayRef<llvm::MCInst> Source;
llvm::MCInstPrinter &MCIP;
public:
InstructionInfoView(const llvm::MCSubtargetInfo &sti,
- const llvm::MCInstrInfo &mcii, const SourceMgr &S,
- llvm::MCInstPrinter &IP)
+ const llvm::MCInstrInfo &mcii,
+ llvm::ArrayRef<llvm::MCInst> S, llvm::MCInstPrinter &IP)
: STI(sti), MCII(mcii), Source(S), MCIP(IP) {}
void printView(llvm::raw_ostream &OS) const override;
diff --git a/llvm/tools/llvm-mca/Views/ResourcePressureView.cpp b/llvm/tools/llvm-mca/Views/ResourcePressureView.cpp
index e71825b07c7..e7943252206 100644
--- a/llvm/tools/llvm-mca/Views/ResourcePressureView.cpp
+++ b/llvm/tools/llvm-mca/Views/ResourcePressureView.cpp
@@ -21,9 +21,9 @@ namespace mca {
using namespace llvm;
ResourcePressureView::ResourcePressureView(const llvm::MCSubtargetInfo &sti,
- llvm::MCInstPrinter &Printer,
- const SourceMgr &Sequence)
- : STI(sti), MCIP(Printer), Source(Sequence) {
+ MCInstPrinter &Printer,
+ ArrayRef<MCInst> S)
+ : STI(sti), MCIP(Printer), Source(S), LastInstructionIdx(0) {
// Populate the map of resource descriptors.
unsigned R2VIndex = 0;
const MCSchedModel &SM = STI.getSchedModel();
@@ -44,9 +44,15 @@ ResourcePressureView::ResourcePressureView(const llvm::MCSubtargetInfo &sti,
}
void ResourcePressureView::onEvent(const HWInstructionEvent &Event) {
+ if (Event.Type == HWInstructionEvent::Dispatched) {
+ LastInstructionIdx = Event.IR.getSourceIndex();
+ return;
+ }
+
// We're only interested in Issue events.
if (Event.Type != HWInstructionEvent::Issued)
return;
+
const auto &IssueEvent = static_cast<const HWInstructionIssuedEvent &>(Event);
const unsigned SourceIdx = Event.IR.getSourceIndex() % Source.size();
for (const std::pair<ResourceRef, ResourceCycles> &Use :
@@ -128,7 +134,7 @@ void ResourcePressureView::printResourcePressurePerIter(raw_ostream &OS) const {
FOS << '\n';
FOS.flush();
- const unsigned Executions = Source.getNumIterations();
+ const unsigned Executions = LastInstructionIdx / Source.size() + 1;
for (unsigned I = 0, E = NumResourceUnits; I < E; ++I) {
double Usage = ResourceUsage[I + Source.size() * E];
printResourcePressure(FOS, Usage / Executions, (I + 1) * 7);
@@ -151,7 +157,7 @@ void ResourcePressureView::printResourcePressurePerInst(raw_ostream &OS) const {
raw_string_ostream InstrStream(Instruction);
unsigned InstrIndex = 0;
- const unsigned Executions = Source.getNumIterations();
+ const unsigned Executions = LastInstructionIdx / Source.size() + 1;
for (const MCInst &MCI : Source) {
unsigned BaseEltIdx = InstrIndex * NumResourceUnits;
for (unsigned J = 0; J < NumResourceUnits; ++J) {
diff --git a/llvm/tools/llvm-mca/Views/ResourcePressureView.h b/llvm/tools/llvm-mca/Views/ResourcePressureView.h
index d413bcd80fd..5ee86df424b 100644
--- a/llvm/tools/llvm-mca/Views/ResourcePressureView.h
+++ b/llvm/tools/llvm-mca/Views/ResourcePressureView.h
@@ -58,12 +58,12 @@
#ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
#define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
-#include "SourceMgr.h"
#include "Views/View.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCSubtargetInfo.h"
-#include <map>
namespace mca {
@@ -72,7 +72,8 @@ namespace mca {
class ResourcePressureView : public View {
const llvm::MCSubtargetInfo &STI;
llvm::MCInstPrinter &MCIP;
- const SourceMgr &Source;
+ llvm::ArrayRef<llvm::MCInst> Source;
+ unsigned LastInstructionIdx;
// Map to quickly obtain the ResourceUsage column index from a processor
// resource ID.
@@ -87,7 +88,8 @@ class ResourcePressureView : public View {
public:
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 printView(llvm::raw_ostream &OS) const override {
diff --git a/llvm/tools/llvm-mca/Views/SummaryView.cpp b/llvm/tools/llvm-mca/Views/SummaryView.cpp
index 8d529ba1549..a509818e6d7 100644
--- a/llvm/tools/llvm-mca/Views/SummaryView.cpp
+++ b/llvm/tools/llvm-mca/Views/SummaryView.cpp
@@ -24,14 +24,18 @@ namespace mca {
using namespace llvm;
-SummaryView::SummaryView(const MCSchedModel &Model, const SourceMgr &S,
+SummaryView::SummaryView(const MCSchedModel &Model, ArrayRef<MCInst> S,
unsigned Width)
: 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);
}
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
// the retire stage for instructions that are part of iteration #0.
if (Event.Type != HWInstructionEvent::Retired ||
@@ -57,8 +61,8 @@ void SummaryView::onEvent(const HWInstructionEvent &Event) {
}
void SummaryView::printView(raw_ostream &OS) const {
- unsigned Iterations = Source.getNumIterations();
unsigned Instructions = Source.size();
+ unsigned Iterations = (LastInstructionIdx / Instructions) + 1;
unsigned TotalInstructions = Instructions * Iterations;
unsigned TotalUOps = NumMicroOps * Iterations;
double IPC = (double)TotalInstructions / TotalCycles;
diff --git a/llvm/tools/llvm-mca/Views/SummaryView.h b/llvm/tools/llvm-mca/Views/SummaryView.h
index 3d4585e1d5a..8c330f28f39 100644
--- a/llvm/tools/llvm-mca/Views/SummaryView.h
+++ b/llvm/tools/llvm-mca/Views/SummaryView.h
@@ -29,7 +29,6 @@
#ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
#define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
-#include "SourceMgr.h"
#include "Views/View.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/MC/MCSchedule.h"
@@ -40,8 +39,9 @@ namespace mca {
/// A view that collects and prints a few performance numbers.
class SummaryView : public View {
const llvm::MCSchedModel &SM;
- const SourceMgr &Source;
+ llvm::ArrayRef<llvm::MCInst> Source;
const unsigned DispatchWidth;
+ unsigned LastInstructionIdx;
unsigned TotalCycles;
// The total number of micro opcodes contributed by a block of instructions.
unsigned NumMicroOps;
@@ -62,7 +62,7 @@ class SummaryView : public View {
double getBlockRThroughput() const;
public:
- SummaryView(const llvm::MCSchedModel &Model, const SourceMgr &S,
+ SummaryView(const llvm::MCSchedModel &Model, llvm::ArrayRef<llvm::MCInst> S,
unsigned Width);
void onCycleEnd() override { ++TotalCycles; }
diff --git a/llvm/tools/llvm-mca/Views/TimelineView.cpp b/llvm/tools/llvm-mca/Views/TimelineView.cpp
index d802d42352d..de347b54bd9 100644
--- a/llvm/tools/llvm-mca/Views/TimelineView.cpp
+++ b/llvm/tools/llvm-mca/Views/TimelineView.cpp
@@ -19,15 +19,14 @@ using namespace llvm;
namespace mca {
TimelineView::TimelineView(const MCSubtargetInfo &sti, MCInstPrinter &Printer,
- const SourceMgr &S, unsigned MaxIterations,
+ llvm::ArrayRef<llvm::MCInst> S, unsigned Iterations,
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()),
UsedBuffer(S.size()) {
- unsigned NumInstructions = AsmSequence.size();
- if (!MaxIterations)
- MaxIterations = DEFAULT_ITERATIONS;
- NumInstructions *= std::min(MaxIterations, AsmSequence.getNumIterations());
+ unsigned NumInstructions = Source.size();
+ assert(Iterations && "Invalid number of iterations specified!");
+ NumInstructions *= Iterations;
Timeline.resize(NumInstructions);
TimelineViewEntry InvalidTVEntry = {-1, 0, 0, 0, 0};
std::fill(Timeline.begin(), Timeline.end(), InvalidTVEntry);
@@ -42,7 +41,7 @@ TimelineView::TimelineView(const MCSubtargetInfo &sti, MCInstPrinter &Printer,
void TimelineView::onReservedBuffers(const InstRef &IR,
ArrayRef<unsigned> Buffers) {
- if (IR.getSourceIndex() >= AsmSequence.size())
+ if (IR.getSourceIndex() >= Source.size())
return;
const MCSchedModel &SM = STI.getSchedModel();
@@ -72,7 +71,7 @@ void TimelineView::onEvent(const HWInstructionEvent &Event) {
// Update the WaitTime entry which corresponds to this Index.
assert(TVEntry.CycleDispatched >= 0 && "Invalid TVEntry found!");
unsigned CycleDispatched = static_cast<unsigned>(TVEntry.CycleDispatched);
- WaitTimeEntry &WTEntry = WaitTime[Index % AsmSequence.size()];
+ WaitTimeEntry &WTEntry = WaitTime[Index % Source.size()];
WTEntry.CyclesSpentInSchedulerQueue +=
TVEntry.CycleIssued - CycleDispatched;
assert(CycleDispatched <= TVEntry.CycleReady &&
@@ -176,9 +175,9 @@ void TimelineView::printAverageWaitTimes(raw_ostream &OS) const {
raw_string_ostream InstrStream(Instruction);
formatted_raw_ostream FOS(OS);
- unsigned Executions = Timeline.size() / AsmSequence.size();
+ unsigned Executions = Timeline.size() / Source.size();
unsigned IID = 0;
- for (const MCInst &Inst : AsmSequence) {
+ for (const MCInst &Inst : Source) {
printWaitTimeEntry(FOS, WaitTime[IID], IID, Executions);
// Append the instruction info at the end of the line.
MCIP.printInst(&Inst, InstrStream, "", STI);
@@ -268,14 +267,14 @@ void TimelineView::printTimeline(raw_ostream &OS) const {
raw_string_ostream InstrStream(Instruction);
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 (const MCInst &Inst : AsmSequence) {
+ for (const MCInst &Inst : Source) {
const TimelineViewEntry &Entry = Timeline[IID];
if (Entry.CycleRetired == 0)
return;
- unsigned SourceIndex = IID % AsmSequence.size();
+ unsigned SourceIndex = IID % Source.size();
printTimelineViewEntry(FOS, Entry, Iteration, SourceIndex);
// Append the instruction info at the end of the line.
MCIP.printInst(&Inst, InstrStream, "", STI);
diff --git a/llvm/tools/llvm-mca/Views/TimelineView.h b/llvm/tools/llvm-mca/Views/TimelineView.h
index 361e37ac625..244d254b7f5 100644
--- a/llvm/tools/llvm-mca/Views/TimelineView.h
+++ b/llvm/tools/llvm-mca/Views/TimelineView.h
@@ -100,8 +100,9 @@
#ifndef LLVM_TOOLS_LLVM_MCA_TIMELINEVIEW_H
#define LLVM_TOOLS_LLVM_MCA_TIMELINEVIEW_H
-#include "SourceMgr.h"
#include "Views/View.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/FormattedStream.h"
@@ -119,7 +120,7 @@ namespace mca {
class TimelineView : public View {
const llvm::MCSubtargetInfo &STI;
llvm::MCInstPrinter &MCIP;
- const SourceMgr &AsmSequence;
+ llvm::ArrayRef<llvm::MCInst> Source;
unsigned CurrentCycle;
unsigned MaxCycle;
@@ -166,7 +167,7 @@ class TimelineView : public View {
public:
TimelineView(const llvm::MCSubtargetInfo &sti, llvm::MCInstPrinter &Printer,
- const SourceMgr &Sequence, unsigned MaxIterations,
+ llvm::ArrayRef<llvm::MCInst> S, unsigned Iterations,
unsigned Cycles);
// Event handlers.
diff --git a/llvm/tools/llvm-mca/include/SourceMgr.h b/llvm/tools/llvm-mca/include/SourceMgr.h
index e7cd358afd4..12713588246 100644
--- a/llvm/tools/llvm-mca/include/SourceMgr.h
+++ b/llvm/tools/llvm-mca/include/SourceMgr.h
@@ -48,9 +48,8 @@ public:
using const_iterator = llvm::ArrayRef<llvm::MCInst>::const_iterator;
const_iterator begin() const { return Sequence.begin(); }
const_iterator end() const { return Sequence.end(); }
-
- bool isEmpty() const { return size() == 0; }
};
+
} // namespace mca
#endif
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index 9992395fb6e..b89e4bd9551 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -497,6 +497,7 @@ int main(int argc, char **argv) {
// Number each region in the sequence.
unsigned RegionIdx = 0;
+
for (const std::unique_ptr<mca::CodeRegion> &Region : Regions) {
// Skip empty code regions.
if (Region->empty())
@@ -512,6 +513,7 @@ int main(int argc, char **argv) {
TOF->os() << "\n\n";
}
+ ArrayRef<MCInst> Insts = Region->getInstructions();
mca::SourceMgr S(Region->getInstructions(),
PrintInstructionTables ? 1 : Iterations);
@@ -524,11 +526,11 @@ int main(int argc, char **argv) {
// Create the views for this pipeline, execute, and emit a report.
if (PrintInstructionInfoView) {
- Printer.addView(
- llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, S, *IP));
+ Printer.addView(llvm::make_unique<mca::InstructionInfoView>(
+ *STI, *MCII, Insts, *IP));
}
Printer.addView(
- llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S));
+ llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
if (!runPipeline(*P, *IP, *STI))
return 1;
@@ -542,11 +544,11 @@ int main(int argc, char **argv) {
mca::PipelinePrinter Printer(*P);
if (PrintSummaryView)
- Printer.addView(llvm::make_unique<mca::SummaryView>(SM, S, Width));
+ Printer.addView(llvm::make_unique<mca::SummaryView>(SM, Insts, Width));
if (PrintInstructionInfoView)
Printer.addView(
- llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, S, *IP));
+ llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, Insts, *IP));
if (PrintDispatchStats)
Printer.addView(llvm::make_unique<mca::DispatchStatistics>());
@@ -562,11 +564,14 @@ int main(int argc, char **argv) {
if (PrintResourcePressureView)
Printer.addView(
- llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S));
+ llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
if (PrintTimelineView) {
+ unsigned TimelineIterations =
+ TimelineMaxIterations ? TimelineMaxIterations : 10;
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))
OpenPOWER on IntegriCloud