summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mca/llvm-mca.cpp
diff options
context:
space:
mode:
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>2018-10-29 13:29:22 +0000
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>2018-10-29 13:29:22 +0000
commitdf4d65dda19e79b364bfbb4afa33e837fb51ece2 (patch)
treeabd4b949ddd26ef65c272ae91c6053fbd3a4ee0b /llvm/tools/llvm-mca/llvm-mca.cpp
parent38a538960b8a2d9c979d66acf898189560b86260 (diff)
downloadbcm5719-llvm-df4d65dda19e79b364bfbb4afa33e837fb51ece2.tar.gz
bcm5719-llvm-df4d65dda19e79b364bfbb4afa33e837fb51ece2.zip
[llvm-mca] Lower to mca::Instructon before the pipeline is run.
Before this change, the lowering of instructions from llvm::MCInst to mca::Instruction was done as part of the first stage of the pipeline (i.e. the FetchStage). In particular, FetchStage was responsible for picking the next instruction from the source sequence, and lower it to an mca::Instruction with the help of an object of class InstrBuilder. The dependency on InstrBuilder was problematic for a number of reasons. Class InstrBuilder only knows how to lower from llvm::MCInst to mca::Instruction. That means, it is hard to support a different scenario where instructions in input are not instances of class llvm::MCInst. Even if we managed to specialize InstrBuilder, and generalize most of its internal logic, the dependency on InstrBuilder in FetchStage would have caused more troubles (other than complicating the pipeline logic). With this patch, the lowering step is done before the pipeline is run. The pipeline is no longer responsible for lowering from MCInst to mca::Instruction. As a consequence of this, the FetchStage no longer needs to interact with an InstrBuilder. The mca::SourceMgr class now simply wraps a reference to a sequence of mca::Instruction objects. This simplifies the logic of FetchStage, and increases the usability of it. As a result, on a debug build, we see a 7-9% speedup; on a release build, the speedup is around 3-4%. llvm-svn: 345500
Diffstat (limited to 'llvm/tools/llvm-mca/llvm-mca.cpp')
-rw-r--r--llvm/tools/llvm-mca/llvm-mca.cpp49
1 files changed, 29 insertions, 20 deletions
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index b89e4bd9551..8f4e0717bd2 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -328,26 +328,12 @@ static void processViewOptions() {
}
// Returns true on success.
-static bool runPipeline(mca::Pipeline &P, MCInstPrinter &MCIP,
- const MCSubtargetInfo &STI) {
+static bool runPipeline(mca::Pipeline &P) {
// Handle pipeline errors here.
if (auto Err = P.run()) {
- if (auto NewE = handleErrors(
- std::move(Err),
- [&MCIP, &STI](const mca::InstructionError<MCInst> &IE) {
- std::string InstructionStr;
- raw_string_ostream SS(InstructionStr);
- WithColor::error() << IE.Message << '\n';
- MCIP.printInst(&IE.Inst, SS, "", STI);
- SS.flush();
- WithColor::note() << "instruction: " << InstructionStr << '\n';
- })) {
- // Default case.
- WithColor::error() << toString(std::move(NewE));
- }
+ WithColor::error() << toString(std::move(Err));
return false;
}
-
return true;
}
@@ -513,14 +499,37 @@ int main(int argc, char **argv) {
TOF->os() << "\n\n";
}
+ // Lower the MCInst sequence into an mca::Instruction sequence.
ArrayRef<MCInst> Insts = Region->getInstructions();
- mca::SourceMgr S(Region->getInstructions(),
+ std::vector<std::unique_ptr<mca::Instruction>> LoweredSequence;
+ for (const MCInst &MCI : Insts) {
+ llvm::Expected<std::unique_ptr<mca::Instruction>> Inst = IB.createInstruction(MCI);
+ if (!Inst) {
+ if (auto NewE = handleErrors(Inst.takeError(),
+ [&IP, &STI](const mca::InstructionError<MCInst> &IE) {
+ std::string InstructionStr;
+ raw_string_ostream SS(InstructionStr);
+ WithColor::error() << IE.Message << '\n';
+ IP->printInst(&IE.Inst, SS, "", *STI);
+ SS.flush();
+ WithColor::note() << "instruction: " << InstructionStr << '\n';
+ })) {
+ // Default case.
+ WithColor::error() << toString(std::move(NewE));
+ }
+ return 1;
+ }
+
+ LoweredSequence.emplace_back(std::move(Inst.get()));
+ }
+
+ mca::SourceMgr S(LoweredSequence,
PrintInstructionTables ? 1 : Iterations);
if (PrintInstructionTables) {
// 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::FetchStage>(S));
P->appendStage(llvm::make_unique<mca::InstructionTables>(SM));
mca::PipelinePrinter Printer(*P);
@@ -532,7 +541,7 @@ int main(int argc, char **argv) {
Printer.addView(
llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
- if (!runPipeline(*P, *IP, *STI))
+ if (!runPipeline(*P))
return 1;
Printer.printReport(TOF->os());
@@ -574,7 +583,7 @@ int main(int argc, char **argv) {
TimelineMaxCycles));
}
- if (!runPipeline(*P, *IP, *STI))
+ if (!runPipeline(*P))
return 1;
Printer.printReport(TOF->os());
OpenPOWER on IntegriCloud