File indexing completed on 2026-05-10 08:43:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
0031 #define LLVM_CODEGEN_MACHINEMODULEINFO_H
0032
0033 #include "llvm/ADT/DenseMap.h"
0034 #include "llvm/ADT/PointerIntPair.h"
0035 #include "llvm/IR/PassManager.h"
0036 #include "llvm/MC/MCContext.h"
0037 #include "llvm/MC/MCSymbol.h"
0038 #include "llvm/Pass.h"
0039 #include <memory>
0040 #include <utility>
0041 #include <vector>
0042
0043 namespace llvm {
0044
0045 class Function;
0046 class TargetMachine;
0047 class MachineFunction;
0048 class Module;
0049
0050
0051
0052
0053
0054
0055
0056 class MachineModuleInfoImpl {
0057 public:
0058 using StubValueTy = PointerIntPair<MCSymbol *, 1, bool>;
0059 using SymbolListTy = std::vector<std::pair<MCSymbol *, StubValueTy>>;
0060
0061
0062 using ExprStubListTy = std::vector<std::pair<MCSymbol *, const MCExpr *>>;
0063
0064 virtual ~MachineModuleInfoImpl();
0065
0066 protected:
0067
0068
0069 static SymbolListTy getSortedStubs(DenseMap<MCSymbol*, StubValueTy>&);
0070
0071
0072
0073 static ExprStubListTy
0074 getSortedExprStubs(DenseMap<MCSymbol *, const MCExpr *> &);
0075 };
0076
0077
0078
0079
0080
0081
0082 class MachineModuleInfo {
0083 friend class MachineModuleInfoWrapperPass;
0084 friend class MachineModuleAnalysis;
0085
0086 const TargetMachine &TM;
0087
0088
0089 MCContext Context;
0090
0091
0092 MCContext *ExternalContext = nullptr;
0093
0094
0095 const Module *TheModule = nullptr;
0096
0097
0098
0099
0100 MachineModuleInfoImpl *ObjFileMMI;
0101
0102
0103 DenseMap<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
0104
0105 unsigned NextFnNum = 0;
0106 const Function *LastRequest = nullptr;
0107 MachineFunction *LastResult = nullptr;
0108
0109 MachineModuleInfo &operator=(MachineModuleInfo &&MMII) = delete;
0110
0111 public:
0112 explicit MachineModuleInfo(const TargetMachine *TM = nullptr);
0113
0114 explicit MachineModuleInfo(const TargetMachine *TM, MCContext *ExtContext);
0115
0116 MachineModuleInfo(MachineModuleInfo &&MMII);
0117
0118 ~MachineModuleInfo();
0119
0120 void initialize();
0121 void finalize();
0122
0123 const TargetMachine &getTarget() const { return TM; }
0124
0125 const MCContext &getContext() const {
0126 return ExternalContext ? *ExternalContext : Context;
0127 }
0128 MCContext &getContext() {
0129 return ExternalContext ? *ExternalContext : Context;
0130 }
0131
0132 const Module *getModule() const { return TheModule; }
0133
0134
0135
0136
0137
0138 MachineFunction &getOrCreateMachineFunction(Function &F);
0139
0140
0141
0142
0143
0144 MachineFunction *getMachineFunction(const Function &F) const;
0145
0146
0147
0148 void deleteMachineFunctionFor(Function &F);
0149
0150
0151 void insertFunction(const Function &F, std::unique_ptr<MachineFunction> &&MF);
0152
0153
0154
0155 template<typename Ty>
0156 Ty &getObjFileInfo() {
0157 if (ObjFileMMI == nullptr)
0158 ObjFileMMI = new Ty(*this);
0159 return *static_cast<Ty*>(ObjFileMMI);
0160 }
0161
0162 template<typename Ty>
0163 const Ty &getObjFileInfo() const {
0164 return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
0165 }
0166
0167
0168 };
0169
0170 class MachineModuleInfoWrapperPass : public ImmutablePass {
0171 MachineModuleInfo MMI;
0172
0173 public:
0174 static char ID;
0175 explicit MachineModuleInfoWrapperPass(const TargetMachine *TM = nullptr);
0176
0177 explicit MachineModuleInfoWrapperPass(const TargetMachine *TM,
0178 MCContext *ExtContext);
0179
0180
0181 bool doInitialization(Module &) override;
0182 bool doFinalization(Module &) override;
0183
0184 MachineModuleInfo &getMMI() { return MMI; }
0185 const MachineModuleInfo &getMMI() const { return MMI; }
0186 };
0187
0188
0189
0190
0191
0192
0193 class MachineModuleAnalysis : public AnalysisInfoMixin<MachineModuleAnalysis> {
0194 friend AnalysisInfoMixin<MachineModuleAnalysis>;
0195 static AnalysisKey Key;
0196
0197 MachineModuleInfo &MMI;
0198
0199 public:
0200 class Result {
0201 MachineModuleInfo &MMI;
0202 Result(MachineModuleInfo &MMI) : MMI(MMI) {}
0203 friend class MachineModuleAnalysis;
0204
0205 public:
0206 MachineModuleInfo &getMMI() { return MMI; }
0207
0208
0209 bool invalidate(Module &, const PreservedAnalyses &,
0210 ModuleAnalysisManager::Invalidator &) {
0211 return false;
0212 }
0213 };
0214
0215 MachineModuleAnalysis(MachineModuleInfo &MMI) : MMI(MMI) {}
0216
0217
0218 Result run(Module &M, ModuleAnalysisManager &);
0219 };
0220
0221 }
0222
0223 #endif