Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame^] | 1 | //===--------------------- InstrBuilder.h -----------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// |
| 11 | /// A builder class for instructions that are statically analyzed by llvm-mca. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_TOOLS_LLVM_MCA_INSTRBUILDER_H |
| 16 | #define LLVM_TOOLS_LLVM_MCA_INSTRBUILDER_H |
| 17 | |
| 18 | #include "Dispatch.h" |
| 19 | #include "Instruction.h" |
| 20 | #include "llvm/MC/MCInstrInfo.h" |
| 21 | #include "llvm/MC/MCSubtargetInfo.h" |
| 22 | |
| 23 | namespace mca { |
| 24 | |
| 25 | class DispatchUnit; |
| 26 | |
| 27 | /// \brief A builder class that knows how to construct Instruction objects. |
| 28 | /// |
| 29 | /// Every llvm-mca Instruction is described by an object of class InstrDesc. |
| 30 | /// An InstrDesc describes which registers are read/written by the instruction, |
| 31 | /// as well as the instruction latency and hardware resources consumed. |
| 32 | /// |
| 33 | /// This class is used by the tool to construct Instructions and instruction |
| 34 | /// descriptors (i.e. InstrDesc objects). |
| 35 | /// Information from the machine scheduling model is used to identify processor |
| 36 | /// resources that are consumed by an instruction. |
| 37 | class InstrBuilder { |
| 38 | const llvm::MCInstrInfo &MCII; |
| 39 | const llvm::ArrayRef<uint64_t> ProcResourceMasks; |
| 40 | |
| 41 | llvm::DenseMap<unsigned short, std::unique_ptr<const InstrDesc>> Descriptors; |
| 42 | llvm::DenseMap<unsigned, std::unique_ptr<Instruction>> Instructions; |
| 43 | |
| 44 | void createInstrDescImpl(const llvm::MCSubtargetInfo &STI, |
| 45 | const llvm::MCInst &MCI); |
| 46 | |
| 47 | public: |
| 48 | InstrBuilder(const llvm::MCInstrInfo &mcii, |
| 49 | const llvm::ArrayRef<uint64_t> Masks) |
| 50 | : MCII(mcii), ProcResourceMasks(Masks) {} |
| 51 | |
| 52 | const InstrDesc &getOrCreateInstrDesc(const llvm::MCSubtargetInfo &STI, |
| 53 | const llvm::MCInst &MCI); |
| 54 | |
| 55 | Instruction *createInstruction(const llvm::MCSubtargetInfo &STI, |
| 56 | DispatchUnit &DU, unsigned Idx, |
| 57 | const llvm::MCInst &MCI); |
| 58 | }; |
| 59 | |
| 60 | } // namespace mca |
| 61 | |
| 62 | #endif |