LLVM  8.0.1
InstrBuilder.h
Go to the documentation of this file.
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_MCA_INSTRBUILDER_H
16 #define LLVM_MCA_INSTRBUILDER_H
17 
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/MCA/Instruction.h"
23 #include "llvm/MCA/Support.h"
24 #include "llvm/Support/Error.h"
25 
26 namespace llvm {
27 namespace mca {
28 
29 /// A builder class that knows how to construct Instruction objects.
30 ///
31 /// Every llvm-mca Instruction is described by an object of class InstrDesc.
32 /// An InstrDesc describes which registers are read/written by the instruction,
33 /// as well as the instruction latency and hardware resources consumed.
34 ///
35 /// This class is used by the tool to construct Instructions and instruction
36 /// descriptors (i.e. InstrDesc objects).
37 /// Information from the machine scheduling model is used to identify processor
38 /// resources that are consumed by an instruction.
39 class InstrBuilder {
40  const MCSubtargetInfo &STI;
41  const MCInstrInfo &MCII;
42  const MCRegisterInfo &MRI;
43  const MCInstrAnalysis *MCIA;
44  SmallVector<uint64_t, 8> ProcResourceMasks;
45 
48 
49  bool FirstCallInst;
50  bool FirstReturnInst;
51 
52  Expected<const InstrDesc &> createInstrDescImpl(const MCInst &MCI);
53  Expected<const InstrDesc &> getOrCreateInstrDesc(const MCInst &MCI);
54 
55  InstrBuilder(const InstrBuilder &) = delete;
56  InstrBuilder &operator=(const InstrBuilder &) = delete;
57 
58  void populateWrites(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
59  void populateReads(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
60  Error verifyInstrDesc(const InstrDesc &ID, const MCInst &MCI) const;
61 
62 public:
63  InstrBuilder(const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
64  const MCRegisterInfo &RI, const MCInstrAnalysis *IA);
65 
66  void clear() {
67  VariantDescriptors.shrink_and_clear();
68  FirstCallInst = true;
69  FirstReturnInst = true;
70  }
71 
73 };
74 } // namespace mca
75 } // namespace llvm
76 
77 #endif // LLVM_MCA_INSTRBUILDER_H
Expected< std::unique_ptr< Instruction > > createInstruction(const MCInst &MCI)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A builder class that knows how to construct Instruction objects.
Definition: InstrBuilder.h:39
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
Helper functions used by various pipeline components.
void shrink_and_clear()
Definition: DenseMap.h:814
An instruction descriptor.
Definition: Instruction.h:322
Generic base class for all target subtargets.
This file defines abstractions used by the Pipeline to model register reads, register writes and inst...
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158