Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:34

0001 //==- RegisterUsageInfo.h - Register Usage Informartion Storage --*- C++ -*-==//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 /// This pass is required to take advantage of the interprocedural register
0010 /// allocation infrastructure.
0011 ///
0012 /// This pass is simple immutable pass which keeps RegMasks (calculated based on
0013 /// actual register allocation) for functions in a module and provides simple
0014 /// API to query this information.
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   /// Set TargetMachine which is used to print analysis.
0038   void setTargetMachine(const TargetMachine &TM);
0039 
0040   bool doInitialization(Module &M);
0041 
0042   bool doFinalization(Module &M);
0043 
0044   /// To store RegMask for given Function *.
0045   void storeUpdateRegUsageInfo(const Function &FP,
0046                                ArrayRef<uint32_t> RegMask);
0047 
0048   /// To query stored RegMask for given Function *, it will returns ane empty
0049   /// array if function is not known.
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   /// A Dense map from Function * to RegMask.
0059   /// In RegMask 0 means register used (clobbered) by function.
0060   /// and 1 means content of register will be preserved around function call.
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 } // end namespace llvm
0113 
0114 #endif // LLVM_CODEGEN_REGISTERUSAGEINFO_H