LLVM  14.0.0git
InstrBuilder.h
Go to the documentation of this file.
1 //===--------------------- InstrBuilder.h -----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// A builder class for instructions that are statically analyzed by llvm-mca.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MCA_INSTRBUILDER_H
15 #define LLVM_MCA_INSTRBUILDER_H
16 
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MCA/Instruction.h"
22 #include "llvm/MCA/Support.h"
23 #include "llvm/Support/Error.h"
24 
25 namespace llvm {
26 namespace mca {
27 
28 /// A builder class that knows how to construct Instruction objects.
29 ///
30 /// Every llvm-mca Instruction is described by an object of class InstrDesc.
31 /// An InstrDesc describes which registers are read/written by the instruction,
32 /// as well as the instruction latency and hardware resources consumed.
33 ///
34 /// This class is used by the tool to construct Instructions and instruction
35 /// descriptors (i.e. InstrDesc objects).
36 /// Information from the machine scheduling model is used to identify processor
37 /// resources that are consumed by an instruction.
38 class InstrBuilder {
39  const MCSubtargetInfo &STI;
40  const MCInstrInfo &MCII;
41  const MCRegisterInfo &MRI;
42  const MCInstrAnalysis *MCIA;
43  SmallVector<uint64_t, 8> ProcResourceMasks;
44 
47 
48  bool FirstCallInst;
49  bool FirstReturnInst;
50 
51  Expected<const InstrDesc &> createInstrDescImpl(const MCInst &MCI);
52  Expected<const InstrDesc &> getOrCreateInstrDesc(const MCInst &MCI);
53 
54  InstrBuilder(const InstrBuilder &) = delete;
55  InstrBuilder &operator=(const InstrBuilder &) = delete;
56 
57  void populateWrites(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
58  void populateReads(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
59  Error verifyInstrDesc(const InstrDesc &ID, const MCInst &MCI) const;
60 
61 public:
62  InstrBuilder(const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
63  const MCRegisterInfo &RI, const MCInstrAnalysis *IA);
64 
65  void clear() {
66  Descriptors.clear();
67  VariantDescriptors.clear();
68  FirstCallInst = true;
69  FirstReturnInst = true;
70  }
71 
73 };
74 } // namespace mca
75 } // namespace llvm
76 
77 #endif // LLVM_MCA_INSTRBUILDER_H
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::SmallVector< uint64_t, 8 >
Error.h
llvm::mca::InstrBuilder::clear
void clear()
Definition: InstrBuilder.h:65
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
Instruction.h
MCInstrInfo.h
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:27
MCSubtargetInfo.h
llvm::mca::InstrBuilder::createInstruction
Expected< std::unique_ptr< Instruction > > createInstruction(const MCInst &MCI)
Definition: InstrBuilder.cpp:642
llvm::mca::InstrDesc
An instruction descriptor.
Definition: Instruction.h:447
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::clear
void clear()
Definition: DenseMap.h:111
llvm::DenseMap
Definition: DenseMap.h:714
MCRegisterInfo.h
llvm::mca::InstrBuilder
A builder class that knows how to construct Instruction objects.
Definition: InstrBuilder.h:38
MCInstrAnalysis.h
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:25
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
Support.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37