LLVM  9.0.0svn
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  VariantDescriptors.shrink_and_clear();
67  FirstCallInst = true;
68  FirstReturnInst = true;
69  }
70 
72 };
73 } // namespace mca
74 } // namespace llvm
75 
76 #endif // LLVM_MCA_INSTRBUILDER_H
Expected< std::unique_ptr< Instruction > > createInstruction(const MCInst &MCI)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A builder class that knows how to construct Instruction objects.
Definition: InstrBuilder.h:38
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
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:23
Helper functions used by various pipeline components.
void shrink_and_clear()
Definition: DenseMap.h:815
An instruction descriptor.
Definition: Instruction.h:330
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:157