1 //===--------------------- InstrBuilder.h -----------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
28 /// A builder class that knows how to construct Instruction objects.
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.
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.
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
;
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;
62 InstrBuilder(const MCSubtargetInfo
&STI
, const MCInstrInfo
&MCII
,
63 const MCRegisterInfo
&RI
, const MCInstrAnalysis
*IA
);
66 VariantDescriptors
.shrink_and_clear();
68 FirstReturnInst
= true;
71 Expected
<std::unique_ptr
<Instruction
>> createInstruction(const MCInst
&MCI
);
76 #endif // LLVM_MCA_INSTRBUILDER_H