File indexing completed on 2026-05-10 08:44:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_MCA_INSTRBUILDER_H
0015 #define LLVM_MCA_INSTRBUILDER_H
0016
0017 #include "llvm/ADT/Hashing.h"
0018 #include "llvm/ADT/STLExtras.h"
0019 #include "llvm/MC/MCInstrAnalysis.h"
0020 #include "llvm/MC/MCInstrInfo.h"
0021 #include "llvm/MC/MCRegisterInfo.h"
0022 #include "llvm/MC/MCSubtargetInfo.h"
0023 #include "llvm/MCA/CustomBehaviour.h"
0024 #include "llvm/MCA/Instruction.h"
0025 #include "llvm/MCA/Support.h"
0026 #include "llvm/Support/Error.h"
0027
0028 namespace llvm {
0029 namespace mca {
0030
0031 class RecycledInstErr : public ErrorInfo<RecycledInstErr> {
0032 Instruction *RecycledInst;
0033
0034 public:
0035 static char ID;
0036
0037 explicit RecycledInstErr(Instruction *Inst) : RecycledInst(Inst) {}
0038
0039 RecycledInstErr() = delete;
0040
0041 Instruction *getInst() const { return RecycledInst; }
0042
0043 void log(raw_ostream &OS) const override {
0044 OS << "Instruction is recycled\n";
0045 }
0046
0047 std::error_code convertToErrorCode() const override {
0048 return llvm::inconvertibleErrorCode();
0049 }
0050 };
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 class InstrBuilder {
0063 const MCSubtargetInfo &STI;
0064 const MCInstrInfo &MCII;
0065 const MCRegisterInfo &MRI;
0066 const MCInstrAnalysis *MCIA;
0067 const InstrumentManager &IM;
0068 SmallVector<uint64_t, 8> ProcResourceMasks;
0069
0070
0071 DenseMap<std::pair<unsigned short, unsigned>,
0072 std::unique_ptr<const InstrDesc>>
0073 Descriptors;
0074
0075
0076
0077 DenseMap<std::pair<hash_code, unsigned>, std::unique_ptr<const InstrDesc>>
0078 VariantDescriptors;
0079
0080 bool FirstCallInst;
0081 bool FirstReturnInst;
0082 unsigned CallLatency;
0083
0084 using InstRecycleCallback = std::function<Instruction *(const InstrDesc &)>;
0085 InstRecycleCallback InstRecycleCB;
0086
0087 Expected<unsigned> getVariantSchedClassID(const MCInst &MCI, unsigned SchedClassID);
0088 Expected<const InstrDesc &>
0089 createInstrDescImpl(const MCInst &MCI, const SmallVector<Instrument *> &IVec);
0090 Expected<const InstrDesc &>
0091 getOrCreateInstrDesc(const MCInst &MCI,
0092 const SmallVector<Instrument *> &IVec);
0093
0094 InstrBuilder(const InstrBuilder &) = delete;
0095 InstrBuilder &operator=(const InstrBuilder &) = delete;
0096
0097 void populateWrites(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
0098 void populateReads(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
0099 Error verifyInstrDesc(const InstrDesc &ID, const MCInst &MCI) const;
0100
0101 public:
0102 InstrBuilder(const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
0103 const MCRegisterInfo &RI, const MCInstrAnalysis *IA,
0104 const InstrumentManager &IM, unsigned CallLatency);
0105
0106 void clear() {
0107 Descriptors.clear();
0108 VariantDescriptors.clear();
0109 FirstCallInst = true;
0110 FirstReturnInst = true;
0111 }
0112
0113
0114
0115 void setInstRecycleCallback(InstRecycleCallback CB) { InstRecycleCB = CB; }
0116
0117 Expected<std::unique_ptr<Instruction>>
0118 createInstruction(const MCInst &MCI, const SmallVector<Instrument *> &IVec);
0119 };
0120 }
0121 }
0122
0123 #endif