blob: 252b68ca5b0a958b73796bc98ab644d7f2b5a918 [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"
19#include "llvm/MC/MCInstrInfo.h"
20#include "llvm/MC/MCSubtargetInfo.h"
21
22namespace mca {
23
24class DispatchUnit;
25
26/// \brief A builder class that knows how to construct Instruction objects.
27///
28/// Every llvm-mca Instruction is described by an object of class InstrDesc.
29/// An InstrDesc describes which registers are read/written by the instruction,
30/// as well as the instruction latency and hardware resources consumed.
31///
32/// This class is used by the tool to construct Instructions and instruction
33/// descriptors (i.e. InstrDesc objects).
34/// Information from the machine scheduling model is used to identify processor
35/// resources that are consumed by an instruction.
36class InstrBuilder {
37 const llvm::MCInstrInfo &MCII;
38 const llvm::ArrayRef<uint64_t> ProcResourceMasks;
39
40 llvm::DenseMap<unsigned short, std::unique_ptr<const InstrDesc>> Descriptors;
41 llvm::DenseMap<unsigned, std::unique_ptr<Instruction>> Instructions;
42
43 void createInstrDescImpl(const llvm::MCSubtargetInfo &STI,
44 const llvm::MCInst &MCI);
45
46public:
47 InstrBuilder(const llvm::MCInstrInfo &mcii,
48 const llvm::ArrayRef<uint64_t> Masks)
49 : MCII(mcii), ProcResourceMasks(Masks) {}
50
51 const InstrDesc &getOrCreateInstrDesc(const llvm::MCSubtargetInfo &STI,
52 const llvm::MCInst &MCI);
53
54 Instruction *createInstruction(const llvm::MCSubtargetInfo &STI,
Andrea Di Biagio4732d43ca2018-03-14 14:57:23 +000055 unsigned Idx,
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000056 const llvm::MCInst &MCI);
57};
58
59} // namespace mca
60
61#endif