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 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 18 | #include "Instruction.h" |
Andrea Di Biagio | 4704f03 | 2018-03-20 12:25:54 +0000 | [diff] [blame] | 19 | #include "Support.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCInstrInfo.h" |
| 21 | #include "llvm/MC/MCSubtargetInfo.h" |
| 22 | |
| 23 | namespace mca { |
| 24 | |
| 25 | class DispatchUnit; |
| 26 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 27 | /// A builder class that knows how to construct Instruction objects. |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 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 { |
Andrea Di Biagio | 4704f03 | 2018-03-20 12:25:54 +0000 | [diff] [blame] | 38 | const llvm::MCSubtargetInfo &STI; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 39 | const llvm::MCInstrInfo &MCII; |
Andrea Di Biagio | 4704f03 | 2018-03-20 12:25:54 +0000 | [diff] [blame] | 40 | llvm::SmallVector<uint64_t, 8> ProcResourceMasks; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 41 | |
| 42 | llvm::DenseMap<unsigned short, std::unique_ptr<const InstrDesc>> Descriptors; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 43 | |
Andrea Di Biagio | 49c8591 | 2018-05-04 13:10:10 +0000 | [diff] [blame^] | 44 | const InstrDesc &createInstrDescImpl(const llvm::MCInst &MCI); |
| 45 | |
| 46 | InstrBuilder(const InstrBuilder &) = delete; |
| 47 | InstrBuilder &operator=(const InstrBuilder &) = delete; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 48 | |
| 49 | public: |
Andrea Di Biagio | 4704f03 | 2018-03-20 12:25:54 +0000 | [diff] [blame] | 50 | InstrBuilder(const llvm::MCSubtargetInfo &sti, const llvm::MCInstrInfo &mcii) |
| 51 | : STI(sti), MCII(mcii), |
| 52 | ProcResourceMasks(STI.getSchedModel().getNumProcResourceKinds()) { |
| 53 | computeProcResourceMasks(STI.getSchedModel(), ProcResourceMasks); |
| 54 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 55 | |
Andrea Di Biagio | 4704f03 | 2018-03-20 12:25:54 +0000 | [diff] [blame] | 56 | const InstrDesc &getOrCreateInstrDesc(const llvm::MCInst &MCI); |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 57 | // Returns an array of processor resource masks. |
| 58 | // Masks are computed by function mca::computeProcResourceMasks. see |
| 59 | // Support.h for a description of how masks are computed and how masks can be |
| 60 | // used to solve set membership problems. |
| 61 | llvm::ArrayRef<uint64_t> getProcResourceMasks() const { |
| 62 | return ProcResourceMasks; |
| 63 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 64 | |
Andrea Di Biagio | 49c8591 | 2018-05-04 13:10:10 +0000 | [diff] [blame^] | 65 | std::unique_ptr<Instruction> createInstruction(const llvm::MCInst &MCI); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 66 | }; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 67 | } // namespace mca |
| 68 | |
| 69 | #endif |