1 //===----------------------- InstructionView.h ------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 /// \file 9 /// 10 /// This file defines the main interface for Views that examine and reference 11 /// a sequence of machine instructions. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H 16 #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H 17 18 #include "llvm/MCA/View.h" 19 #include "llvm/Support/JSON.h" 20 21 namespace llvm { 22 class MCInstPrinter; 23 24 namespace mca { 25 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; 31 32 mutable std::string InstructionString; 33 mutable raw_string_ostream InstrStream; 34 35 public: 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) {} 40 41 virtual ~InstructionView(); 42 43 StringRef getNameAsString() const override { return "Instructions"; } 44 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; } 50 51 llvm::MCInstPrinter &getInstPrinter() const { return MCIP; } 52 llvm::ArrayRef<llvm::MCInst> getSource() const { return Source; } 53 54 json::Value toJSON() const override; 55 }; 56 57 } // namespace mca 58 } // namespace llvm 59 60 #endif 61