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