1 //===----------------------- InstructionView.h ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file defines the main interface for Views that examine and reference
11 /// a sequence of machine instructions.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H
16 #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H
18 #include "llvm/MCA/View.h"
19 #include "llvm/Support/JSON.h"
26 // The base class for views that deal with individual machine instructions.
27 class InstructionView
: public View
{
28 const llvm::MCSubtargetInfo
&STI
;
29 llvm::MCInstPrinter
&MCIP
;
30 llvm::ArrayRef
<llvm::MCInst
> Source
;
32 mutable std::string InstructionString
;
33 mutable raw_string_ostream InstrStream
;
36 void printView(llvm::raw_ostream
&) const override
{}
37 InstructionView(const llvm::MCSubtargetInfo
&STI
,
38 llvm::MCInstPrinter
&Printer
, llvm::ArrayRef
<llvm::MCInst
> S
)
39 : STI(STI
), MCIP(Printer
), Source(S
), InstrStream(InstructionString
) {}
41 virtual ~InstructionView();
43 StringRef
getNameAsString() const override
{ return "Instructions"; }
45 // Return a reference to a string representing a given machine instruction.
46 // The result should be used or copied before the next call to
47 // printInstructionString() as it will overwrite the previous result.
48 StringRef
printInstructionString(const llvm::MCInst
&MCI
) const;
49 const llvm::MCSubtargetInfo
&getSubTargetInfo() const { return STI
; }
51 llvm::MCInstPrinter
&getInstPrinter() const { return MCIP
; }
52 llvm::ArrayRef
<llvm::MCInst
> getSource() const { return Source
; }
54 json::Value
toJSON() const override
;