File indexing completed on 2026-05-10 08:43:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef LLVM_CODEGEN_REGISTERUSAGEINFO_H
0019 #define LLVM_CODEGEN_REGISTERUSAGEINFO_H
0020
0021 #include "llvm/ADT/ArrayRef.h"
0022 #include "llvm/ADT/DenseMap.h"
0023 #include "llvm/IR/PassManager.h"
0024 #include "llvm/InitializePasses.h"
0025 #include "llvm/Pass.h"
0026 #include "llvm/PassRegistry.h"
0027 #include <cstdint>
0028 #include <vector>
0029
0030 namespace llvm {
0031
0032 class Function;
0033 class TargetMachine;
0034
0035 class PhysicalRegisterUsageInfo {
0036 public:
0037
0038 void setTargetMachine(const TargetMachine &TM);
0039
0040 bool doInitialization(Module &M);
0041
0042 bool doFinalization(Module &M);
0043
0044
0045 void storeUpdateRegUsageInfo(const Function &FP,
0046 ArrayRef<uint32_t> RegMask);
0047
0048
0049
0050 ArrayRef<uint32_t> getRegUsageInfo(const Function &FP);
0051
0052 void print(raw_ostream &OS, const Module *M = nullptr) const;
0053
0054 bool invalidate(Module &M, const PreservedAnalyses &PA,
0055 ModuleAnalysisManager::Invalidator &Inv);
0056
0057 private:
0058
0059
0060
0061 DenseMap<const Function *, std::vector<uint32_t>> RegMasks;
0062
0063 const TargetMachine *TM = nullptr;
0064 };
0065
0066 class PhysicalRegisterUsageInfoWrapperLegacy : public ImmutablePass {
0067 std::unique_ptr<PhysicalRegisterUsageInfo> PRUI;
0068
0069 public:
0070 static char ID;
0071 PhysicalRegisterUsageInfoWrapperLegacy() : ImmutablePass(ID) {
0072 initializePhysicalRegisterUsageInfoWrapperLegacyPass(
0073 *PassRegistry::getPassRegistry());
0074 }
0075
0076 PhysicalRegisterUsageInfo &getPRUI() { return *PRUI; }
0077 const PhysicalRegisterUsageInfo &getPRUI() const { return *PRUI; }
0078
0079 bool doInitialization(Module &M) override {
0080 PRUI.reset(new PhysicalRegisterUsageInfo());
0081 return PRUI->doInitialization(M);
0082 }
0083
0084 bool doFinalization(Module &M) override { return PRUI->doFinalization(M); }
0085
0086 void print(raw_ostream &OS, const Module *M = nullptr) const override {
0087 PRUI->print(OS, M);
0088 }
0089 };
0090
0091 class PhysicalRegisterUsageAnalysis
0092 : public AnalysisInfoMixin<PhysicalRegisterUsageAnalysis> {
0093 friend AnalysisInfoMixin<PhysicalRegisterUsageAnalysis>;
0094 static AnalysisKey Key;
0095
0096 public:
0097 using Result = PhysicalRegisterUsageInfo;
0098
0099 PhysicalRegisterUsageInfo run(Module &M, ModuleAnalysisManager &);
0100 };
0101
0102 class PhysicalRegisterUsageInfoPrinterPass
0103 : public PassInfoMixin<PhysicalRegisterUsageInfoPrinterPass> {
0104 raw_ostream &OS;
0105
0106 public:
0107 explicit PhysicalRegisterUsageInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
0108 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
0109 static bool isRequired() { return true; }
0110 };
0111
0112 }
0113
0114 #endif