aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-mca
diff options
context:
space:
mode:
authorMichael Maitland <michaeltmaitland@gmail.com>2023-05-12 09:56:43 -0700
committerMichael Maitland <michaeltmaitland@gmail.com>2023-05-22 16:41:19 -0700
commitc1fe1474d27f6fe7b8e5bfedcc9066e9a90ad85e (patch)
treebf3b3013d86d775cbab98ba190ab5d3e07c42bcc /llvm/tools/llvm-mca
parentabba5de724665362db707d4cfab598cfbf5a475e (diff)
downloadllvm-c1fe1474d27f6fe7b8e5bfedcc9066e9a90ad85e.zip
llvm-c1fe1474d27f6fe7b8e5bfedcc9066e9a90ad85e.tar.gz
llvm-c1fe1474d27f6fe7b8e5bfedcc9066e9a90ad85e.tar.bz2
[llvm-mca] Print InstructionInfoView using Instrument information.
Previous reports calculated the overall report using Instrument information but did not print out per-instruction data using Instrument information. This patch fixes that. Differential Revision: https://reviews.llvm.org/D150459
Diffstat (limited to 'llvm/tools/llvm-mca')
-rw-r--r--llvm/tools/llvm-mca/Views/InstructionInfoView.cpp9
-rw-r--r--llvm/tools/llvm-mca/Views/InstructionInfoView.h11
-rw-r--r--llvm/tools/llvm-mca/llvm-mca.cpp7
3 files changed, 21 insertions, 6 deletions
diff --git a/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp b/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp
index 3262de4..fea0c9b 100644
--- a/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp
+++ b/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp
@@ -117,8 +117,13 @@ void InstructionInfoView::collectData(
InstructionInfoViewData &IIVDEntry = std::get<1>(I);
const MCInstrDesc &MCDesc = MCII.get(Inst.getOpcode());
- // Obtain the scheduling class information from the instruction.
- unsigned SchedClassID = MCDesc.getSchedClass();
+ // Obtain the scheduling class information from the instruction
+ // and instruments.
+ auto IVecIt = InstToInstruments.find(&Inst);
+ unsigned SchedClassID =
+ IVecIt == InstToInstruments.end()
+ ? MCDesc.getSchedClass()
+ : IM.getSchedClassID(MCII, Inst, IVecIt->second);
unsigned CPUID = SM.getProcessorID();
// Try to solve variant scheduling classes.
diff --git a/llvm/tools/llvm-mca/Views/InstructionInfoView.h b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
index bddd01a..3befafd 100644
--- a/llvm/tools/llvm-mca/Views/InstructionInfoView.h
+++ b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
@@ -42,6 +42,7 @@
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MCA/CodeEmitter.h"
+#include "llvm/MCA/CustomBehaviour.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUG_TYPE "llvm-mca"
@@ -57,6 +58,10 @@ class InstructionInfoView : public InstructionView {
bool PrintBarriers;
using UniqueInst = std::unique_ptr<Instruction>;
ArrayRef<UniqueInst> LoweredInsts;
+ const InstrumentManager &IM;
+ using InstToInstrumentsT =
+ DenseMap<const MCInst *, SmallVector<mca::Instrument *>>;
+ const InstToInstrumentsT &InstToInstruments;
struct InstructionInfoViewData {
unsigned NumMicroOpcodes = 0;
@@ -77,10 +82,12 @@ public:
bool ShouldPrintEncodings, llvm::ArrayRef<llvm::MCInst> S,
llvm::MCInstPrinter &IP,
ArrayRef<UniqueInst> LoweredInsts,
- bool ShouldPrintBarriers)
+ bool ShouldPrintBarriers, const InstrumentManager &IM,
+ const InstToInstrumentsT &InstToInstruments)
: InstructionView(ST, IP, S), MCII(II), CE(C),
PrintEncodings(ShouldPrintEncodings),
- PrintBarriers(ShouldPrintBarriers), LoweredInsts(LoweredInsts) {}
+ PrintBarriers(ShouldPrintBarriers), LoweredInsts(LoweredInsts), IM(IM),
+ InstToInstruments(InstToInstruments) {}
void printView(llvm::raw_ostream &OS) const override;
StringRef getNameAsString() const override { return "InstructionInfoView"; }
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index 23b537e..eb71cff 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -571,11 +571,14 @@ int main(int argc, char **argv) {
IPP->resetState();
+ DenseMap<const MCInst *, SmallVector<mca::Instrument *>>
+ InstToInstruments;
SmallVector<std::unique_ptr<mca::Instruction>> LoweredSequence;
for (const MCInst &MCI : Insts) {
SMLoc Loc = MCI.getLoc();
const SmallVector<mca::Instrument *> Instruments =
InstrumentRegions.getActiveInstruments(Loc);
+ InstToInstruments.insert({&MCI, Instruments});
Expected<std::unique_ptr<mca::Instruction>> Inst =
IB.createInstruction(MCI, Instruments);
@@ -621,7 +624,7 @@ int main(int argc, char **argv) {
if (PrintInstructionInfoView) {
Printer.addView(std::make_unique<mca::InstructionInfoView>(
*STI, *MCII, CE, ShowEncoding, Insts, *IP, LoweredSequence,
- ShowBarriers));
+ ShowBarriers, *IM, InstToInstruments));
}
Printer.addView(
std::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
@@ -698,7 +701,7 @@ int main(int argc, char **argv) {
if (PrintInstructionInfoView)
Printer.addView(std::make_unique<mca::InstructionInfoView>(
*STI, *MCII, CE, ShowEncoding, Insts, *IP, LoweredSequence,
- ShowBarriers));
+ ShowBarriers, *IM, InstToInstruments));
// Fetch custom Views that are to be placed after the InstructionInfoView.
// Refer to the comment paired with the CB->getStartViews(*IP, Insts); line