1 //===--------------------- InstrBuilder.h -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// A builder class for instructions that are statically analyzed by llvm-mca.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVM_MCA_INSTRBUILDER_H
16 #define LLVM_TOOLS_LLVM_MCA_INSTRBUILDER_H
18 #include "Instruction.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
27 /// A builder class that knows how to construct Instruction objects.
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.
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.
38 const llvm::MCSubtargetInfo &STI;
39 const llvm::MCInstrInfo &MCII;
40 llvm::SmallVector<uint64_t, 8> ProcResourceMasks;
42 llvm::DenseMap<unsigned short, std::unique_ptr<const InstrDesc>> Descriptors;
44 void createInstrDescImpl(const llvm::MCInst &MCI);
47 InstrBuilder(const llvm::MCSubtargetInfo &sti, const llvm::MCInstrInfo &mcii)
48 : STI(sti), MCII(mcii),
49 ProcResourceMasks(STI.getSchedModel().getNumProcResourceKinds()) {
50 computeProcResourceMasks(STI.getSchedModel(), ProcResourceMasks);
53 const InstrDesc &getOrCreateInstrDesc(const llvm::MCInst &MCI);
54 // Returns an array of processor resource masks.
55 // Masks are computed by function mca::computeProcResourceMasks. see
56 // Support.h for a description of how masks are computed and how masks can be
57 // used to solve set membership problems.
58 llvm::ArrayRef<uint64_t> getProcResourceMasks() const {
59 return ProcResourceMasks;
62 std::unique_ptr<Instruction> createInstruction(unsigned Idx,
63 const llvm::MCInst &MCI);