[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / MCA / InstrBuilder.h
blob690016354f7a7a361e68314810b451a8c81fb489
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MCA_INSTRBUILDER_H
15 #define LLVM_MCA_INSTRBUILDER_H
17 #include "llvm/MC/MCInstrAnalysis.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/MCA/Instruction.h"
22 #include "llvm/MCA/Support.h"
23 #include "llvm/Support/Error.h"
25 namespace llvm {
26 namespace mca {
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;
45 DenseMap<unsigned short, std::unique_ptr<const InstrDesc>> Descriptors;
46 DenseMap<const MCInst *, std::unique_ptr<const InstrDesc>> VariantDescriptors;
48 bool FirstCallInst;
49 bool FirstReturnInst;
51 Expected<const InstrDesc &> createInstrDescImpl(const MCInst &MCI);
52 Expected<const InstrDesc &> getOrCreateInstrDesc(const MCInst &MCI);
54 InstrBuilder(const InstrBuilder &) = delete;
55 InstrBuilder &operator=(const InstrBuilder &) = delete;
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;
61 public:
62 InstrBuilder(const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
63 const MCRegisterInfo &RI, const MCInstrAnalysis *IA);
65 void clear() {
66 VariantDescriptors.shrink_and_clear();
67 FirstCallInst = true;
68 FirstReturnInst = true;
71 Expected<std::unique_ptr<Instruction>> createInstruction(const MCInst &MCI);
73 } // namespace mca
74 } // namespace llvm
76 #endif // LLVM_MCA_INSTRBUILDER_H