xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-mca/PipelinePrinter.h (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
10b57cec5SDimitry Andric //===--------------------- PipelinePrinter.h --------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric ///
100b57cec5SDimitry Andric /// This file implements class PipelinePrinter.
110b57cec5SDimitry Andric ///
120b57cec5SDimitry Andric /// PipelinePrinter allows the customization of the performance report.
130b57cec5SDimitry Andric ///
140b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #ifndef LLVM_TOOLS_LLVM_MCA_PIPELINEPRINTER_H
170b57cec5SDimitry Andric #define LLVM_TOOLS_LLVM_MCA_PIPELINEPRINTER_H
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h"
20fe6060f1SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
21fe6060f1SDimitry Andric #include "llvm/MCA/Context.h"
220b57cec5SDimitry Andric #include "llvm/MCA/Pipeline.h"
23349cc55cSDimitry Andric #include "llvm/MCA/View.h"
240b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric #define DEBUG_TYPE "llvm-mca"
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric namespace llvm {
290b57cec5SDimitry Andric namespace mca {
300b57cec5SDimitry Andric 
31fe6060f1SDimitry Andric class CodeRegion;
32fe6060f1SDimitry Andric 
330b57cec5SDimitry Andric /// A printer class that knows how to collects statistics on the
340b57cec5SDimitry Andric /// code analyzed by the llvm-mca tool.
350b57cec5SDimitry Andric ///
360b57cec5SDimitry Andric /// This class knows how to print out the analysis information collected
370b57cec5SDimitry Andric /// during the execution of the code. Internally, it delegates to other
380b57cec5SDimitry Andric /// classes the task of printing out timeline information as well as
390b57cec5SDimitry Andric /// resource pressure.
400b57cec5SDimitry Andric class PipelinePrinter {
410b57cec5SDimitry Andric   Pipeline &P;
42fe6060f1SDimitry Andric   const CodeRegion &Region;
43fe6060f1SDimitry Andric   unsigned RegionIdx;
44fe6060f1SDimitry Andric   const MCSubtargetInfo &STI;
45fe6060f1SDimitry Andric   const PipelineOptions &PO;
460b57cec5SDimitry Andric   llvm::SmallVector<std::unique_ptr<View>, 8> Views;
47fe6060f1SDimitry Andric 
48fe6060f1SDimitry Andric   void printRegionHeader(llvm::raw_ostream &OS) const;
49fe6060f1SDimitry Andric   json::Object getJSONReportRegion() const;
50fe6060f1SDimitry Andric   json::Object getJSONTargetInfo() const;
51fe6060f1SDimitry Andric   json::Object getJSONSimulationParameters() const;
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric public:
PipelinePrinter(Pipeline & Pipe,const CodeRegion & R,unsigned Idx,const MCSubtargetInfo & STI,const PipelineOptions & PO)54fe6060f1SDimitry Andric   PipelinePrinter(Pipeline &Pipe, const CodeRegion &R, unsigned Idx,
55fe6060f1SDimitry Andric                   const MCSubtargetInfo &STI, const PipelineOptions &PO)
56*04eeddc0SDimitry Andric       : P(Pipe), Region(R), RegionIdx(Idx), STI(STI), PO(PO) {}
570b57cec5SDimitry Andric 
addView(std::unique_ptr<View> V)580b57cec5SDimitry Andric   void addView(std::unique_ptr<View> V) {
590b57cec5SDimitry Andric     P.addEventListener(V.get());
600b57cec5SDimitry Andric     Views.emplace_back(std::move(V));
610b57cec5SDimitry Andric   }
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric   void printReport(llvm::raw_ostream &OS) const;
64fe6060f1SDimitry Andric   void printReport(json::Object &JO) const;
650b57cec5SDimitry Andric };
660b57cec5SDimitry Andric } // namespace mca
670b57cec5SDimitry Andric } // namespace llvm
680b57cec5SDimitry Andric 
690b57cec5SDimitry Andric #endif // LLVM_TOOLS_LLVM_MCA_PIPELINEPRINTER_H
70