[llvm] r337113 - [llvm-mca] Turn InstructionTables into a Stage.
Matt Davis via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 14 16:52:50 PDT 2018
Author: mattd
Date: Sat Jul 14 16:52:50 2018
New Revision: 337113
URL: http://llvm.org/viewvc/llvm-project?rev=337113&view=rev
Log:
[llvm-mca] Turn InstructionTables into a Stage.
Summary:
This patch converts the InstructionTables class into a subclass of mca::Stage. This change allows us to use the Stage's inherited Listeners for event notifications. This also allows us to create a simple pipeline for viewing the InstructionTables report.
I have been working on a follow on patch that should cleanup addView in InstructionTables. Right now, addView adds the view to both the Listener list and Views list. The follow-on patch addresses the fact that we don't really need two lists in this case. That change is not specific to just InstructionTables, so it will be a separate patch.
Reviewers: andreadb, courbet, RKSimon
Reviewed By: andreadb
Subscribers: tschuett, gbedwell, llvm-commits
Differential Revision: https://reviews.llvm.org/D49329
Modified:
llvm/trunk/tools/llvm-mca/InstructionTables.cpp
llvm/trunk/tools/llvm-mca/InstructionTables.h
llvm/trunk/tools/llvm-mca/PipelinePrinter.cpp
llvm/trunk/tools/llvm-mca/llvm-mca.cpp
Modified: llvm/trunk/tools/llvm-mca/InstructionTables.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/InstructionTables.cpp?rev=337113&r1=337112&r2=337113&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/InstructionTables.cpp (original)
+++ llvm/trunk/tools/llvm-mca/InstructionTables.cpp Sat Jul 14 16:52:50 2018
@@ -8,9 +8,9 @@
//===----------------------------------------------------------------------===//
/// \file
///
-/// This file implements method InstructionTables::run().
-/// Method run() prints a theoretical resource pressure distribution based on
-/// the information available in the scheduling model, and without running
+/// This file implements the method InstructionTables::execute().
+/// Method execute() prints a theoretical resource pressure distribution based
+/// on the information available in the scheduling model, and without running
/// the pipeline.
///
//===----------------------------------------------------------------------===//
@@ -21,65 +21,50 @@ namespace mca {
using namespace llvm;
-using ResourceRef = std::pair<uint64_t, uint64_t>;
-
-void InstructionTables::run() {
+bool InstructionTables::execute(InstRef &IR) {
ArrayRef<uint64_t> Masks = IB.getProcResourceMasks();
- SmallVector<std::pair<ResourceRef, double>, 4> UsedResources;
+ const InstrDesc &Desc = IR.getInstruction()->getDesc();
+ UsedResources.clear();
- // Create an instruction descriptor for every instruction in the sequence.
- while (S.hasNext()) {
- UsedResources.clear();
- SourceRef SR = S.peekNext();
- std::unique_ptr<Instruction> Inst = IB.createInstruction(*SR.second);
- const InstrDesc &Desc = Inst->getDesc();
- // Now identify the resources consumed by this instruction.
- for (const std::pair<uint64_t, ResourceUsage> Resource : Desc.Resources) {
- // Skip zero-cycle resources (i.e. unused resources).
- if (!Resource.second.size())
- continue;
- double Cycles = static_cast<double>(Resource.second.size());
- unsigned Index = std::distance(
- Masks.begin(), std::find(Masks.begin(), Masks.end(), Resource.first));
- const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index);
- unsigned NumUnits = ProcResource.NumUnits;
- if (!ProcResource.SubUnitsIdxBegin) {
- // The number of cycles consumed by each unit.
- Cycles /= NumUnits;
- for (unsigned I = 0, E = NumUnits; I < E; ++I) {
- ResourceRef ResourceUnit = std::make_pair(Index, 1U << I);
- UsedResources.emplace_back(std::make_pair(ResourceUnit, Cycles));
- }
- continue;
+ // Identify the resources consumed by this instruction.
+ for (const std::pair<uint64_t, ResourceUsage> Resource : Desc.Resources) {
+ // Skip zero-cycle resources (i.e., unused resources).
+ if (!Resource.second.size())
+ continue;
+ double Cycles = static_cast<double>(Resource.second.size());
+ unsigned Index = std::distance(
+ Masks.begin(), std::find(Masks.begin(), Masks.end(), Resource.first));
+ const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index);
+ unsigned NumUnits = ProcResource.NumUnits;
+ if (!ProcResource.SubUnitsIdxBegin) {
+ // The number of cycles consumed by each unit.
+ Cycles /= NumUnits;
+ for (unsigned I = 0, E = NumUnits; I < E; ++I) {
+ ResourceRef ResourceUnit = std::make_pair(Index, 1U << I);
+ UsedResources.emplace_back(std::make_pair(ResourceUnit, Cycles));
}
+ continue;
+ }
- // This is a group. Obtain the set of resources contained in this
- // group. Some of these resources may implement multiple units.
- // Uniformly distribute Cycles across all of the units.
- for (unsigned I1 = 0; I1 < NumUnits; ++I1) {
- unsigned SubUnitIdx = ProcResource.SubUnitsIdxBegin[I1];
- const MCProcResourceDesc &SubUnit = *SM.getProcResource(SubUnitIdx);
- // Compute the number of cycles consumed by each resource unit.
- double RUCycles = Cycles / (NumUnits * SubUnit.NumUnits);
- for (unsigned I2 = 0, E2 = SubUnit.NumUnits; I2 < E2; ++I2) {
- ResourceRef ResourceUnit = std::make_pair(SubUnitIdx, 1U << I2);
- UsedResources.emplace_back(std::make_pair(ResourceUnit, RUCycles));
- }
+ // This is a group. Obtain the set of resources contained in this
+ // group. Some of these resources may implement multiple units.
+ // Uniformly distribute Cycles across all of the units.
+ for (unsigned I1 = 0; I1 < NumUnits; ++I1) {
+ unsigned SubUnitIdx = ProcResource.SubUnitsIdxBegin[I1];
+ const MCProcResourceDesc &SubUnit = *SM.getProcResource(SubUnitIdx);
+ // Compute the number of cycles consumed by each resource unit.
+ double RUCycles = Cycles / (NumUnits * SubUnit.NumUnits);
+ for (unsigned I2 = 0, E2 = SubUnit.NumUnits; I2 < E2; ++I2) {
+ ResourceRef ResourceUnit = std::make_pair(SubUnitIdx, 1U << I2);
+ UsedResources.emplace_back(std::make_pair(ResourceUnit, RUCycles));
}
}
-
- // Now send a fake instruction issued event to all the views.
- InstRef IR(SR.first, Inst.get());
- HWInstructionIssuedEvent Event(IR, UsedResources);
- for (std::unique_ptr<View> &Listener : Views)
- Listener->onEvent(Event);
- S.updateNext();
}
-}
-void InstructionTables::printReport(llvm::raw_ostream &OS) const {
- for (const std::unique_ptr<View> &V : Views)
- V->printView(OS);
+ // Send a fake instruction issued event to all the views.
+ HWInstructionIssuedEvent Event(IR, UsedResources);
+ notifyEvent<HWInstructionIssuedEvent>(Event);
+ return true;
}
} // namespace mca
Modified: llvm/trunk/tools/llvm-mca/InstructionTables.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/InstructionTables.h?rev=337113&r1=337112&r2=337113&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/InstructionTables.h (original)
+++ llvm/trunk/tools/llvm-mca/InstructionTables.h Sat Jul 14 16:52:50 2018
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
/// \file
///
-/// This file implements a custom driver to generate instruction tables.
+/// This file implements a custom stage to generate instruction tables.
/// See the description of command-line flag -instruction-tables in
/// docs/CommandGuide/lvm-mca.rst
///
@@ -17,32 +17,26 @@
#ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONTABLES_H
#define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONTABLES_H
-#include "View.h"
#include "InstrBuilder.h"
-#include "SourceMgr.h"
+#include "Scheduler.h"
+#include "Stage.h"
+#include "View.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/MC/MCSchedule.h"
namespace mca {
-class InstructionTables {
+class InstructionTables : public Stage {
const llvm::MCSchedModel &SM;
InstrBuilder &IB;
- SourceMgr &S;
- llvm::SmallVector<std::unique_ptr<View>, 8> Views;
+ llvm::SmallVector<std::pair<ResourceRef, double>, 4> UsedResources;
public:
- InstructionTables(const llvm::MCSchedModel &Model, InstrBuilder &Builder,
- SourceMgr &Source)
- : SM(Model), IB(Builder), S(Source) {}
-
- void addView(std::unique_ptr<View> V) {
- Views.emplace_back(std::move(V));
- }
-
- void run();
-
- void printReport(llvm::raw_ostream &OS) const;
+ InstructionTables(const llvm::MCSchedModel &Model, InstrBuilder &Builder)
+ : Stage(), SM(Model), IB(Builder) {}
+
+ bool hasWorkToComplete() const override final { return false; }
+ bool execute(InstRef &IR) override final;
};
} // namespace mca
Modified: llvm/trunk/tools/llvm-mca/PipelinePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/PipelinePrinter.cpp?rev=337113&r1=337112&r2=337113&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/PipelinePrinter.cpp (original)
+++ llvm/trunk/tools/llvm-mca/PipelinePrinter.cpp Sat Jul 14 16:52:50 2018
@@ -14,7 +14,6 @@
#include "PipelinePrinter.h"
#include "View.h"
-#include "llvm/CodeGen/TargetSchedule.h"
namespace mca {
Modified: llvm/trunk/tools/llvm-mca/llvm-mca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/llvm-mca.cpp?rev=337113&r1=337112&r2=337113&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/llvm-mca.cpp (original)
+++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp Sat Jul 14 16:52:50 2018
@@ -24,6 +24,7 @@
#include "CodeRegion.h"
#include "Context.h"
#include "DispatchStatistics.h"
+#include "FetchStage.h"
#include "InstructionInfoView.h"
#include "InstructionTables.h"
#include "Pipeline.h"
@@ -489,16 +490,21 @@ int main(int argc, char **argv) {
PrintInstructionTables ? 1 : Iterations);
if (PrintInstructionTables) {
- mca::InstructionTables IT(SM, IB, S);
+ // Create a pipeline, stages, and a printer.
+ auto P = llvm::make_unique<mca::Pipeline>();
+ P->appendStage(llvm::make_unique<mca::FetchStage>(IB, S));
+ P->appendStage(llvm::make_unique<mca::InstructionTables>(SM, IB));
+ mca::PipelinePrinter Printer(*P);
+ // Create the views for this pipeline, execute, and emit a report.
if (PrintInstructionInfoView) {
- IT.addView(
+ Printer.addView(
llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, S, *IP));
}
-
- IT.addView(llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S));
- IT.run();
- IT.printReport(TOF->os());
+ Printer.addView(
+ llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S));
+ P->run();
+ Printer.printReport(TOF->os());
continue;
}
More information about the llvm-commits
mailing list