blob: a26b84607b643f90d18bc5c2657a8ac95fb9eed0 [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===--------------------- 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 Biagio3a6b0922018-03-08 13:05:02 +000018#include "Instruction.h"
Andrea Di Biagio4704f032018-03-20 12:25:54 +000019#include "Support.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000020#include "llvm/MC/MCInstrInfo.h"
21#include "llvm/MC/MCSubtargetInfo.h"
22
23namespace mca {
24
25class 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.
37class InstrBuilder {
Andrea Di Biagio4704f032018-03-20 12:25:54 +000038 const llvm::MCSubtargetInfo &STI;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000039 const llvm::MCInstrInfo &MCII;
Andrea Di Biagio4704f032018-03-20 12:25:54 +000040 llvm::SmallVector<uint64_t, 8> ProcResourceMasks;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000041
42 llvm::DenseMap<unsigned short, std::unique_ptr<const InstrDesc>> Descriptors;
43 llvm::DenseMap<unsigned, std::unique_ptr<Instruction>> Instructions;
44
Andrea Di Biagio4704f032018-03-20 12:25:54 +000045 void createInstrDescImpl(const llvm::MCInst &MCI);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000046
47public:
Andrea Di Biagio4704f032018-03-20 12:25:54 +000048 InstrBuilder(const llvm::MCSubtargetInfo &sti, const llvm::MCInstrInfo &mcii)
49 : STI(sti), MCII(mcii),
50 ProcResourceMasks(STI.getSchedModel().getNumProcResourceKinds()) {
51 computeProcResourceMasks(STI.getSchedModel(), ProcResourceMasks);
52 }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000053
Andrea Di Biagio4704f032018-03-20 12:25:54 +000054 const InstrDesc &getOrCreateInstrDesc(const llvm::MCInst &MCI);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000055
Andrea Di Biagio4704f032018-03-20 12:25:54 +000056 Instruction *createInstruction(unsigned Idx, const llvm::MCInst &MCI);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000057};
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000058} // namespace mca
59
60#endif