• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //==- RegisterUsageInfo.h - Register Usage Informartion Storage -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// This pass is required to take advantage of the interprocedural register
11 /// allocation infrastructure.
12 ///
13 /// This pass is simple immutable pass which keeps RegMasks (calculated based on
14 /// actual register allocation) for functions in a module and provides simple
15 /// API to query this information.
16 ///
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H
20 #define LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H
21 
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/CodeGen/MachineRegisterInfo.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/IR/Module.h"
26 #include "llvm/Pass.h"
27 #include "llvm/Support/CommandLine.h"
28 #include "llvm/Support/raw_ostream.h"
29 
30 namespace llvm {
31 
32 class PhysicalRegisterUsageInfo : public ImmutablePass {
33   virtual void anchor();
34 
35 public:
36   static char ID;
37 
PhysicalRegisterUsageInfo()38   PhysicalRegisterUsageInfo() : ImmutablePass(ID) {
39     PassRegistry &Registry = *PassRegistry::getPassRegistry();
40     initializePhysicalRegisterUsageInfoPass(Registry);
41   }
42 
getAnalysisUsage(AnalysisUsage & AU)43   void getAnalysisUsage(AnalysisUsage &AU) const override {
44     AU.setPreservesAll();
45   }
46 
47   /// To set TargetMachine *, which is used to print
48   /// analysis when command line option -print-regusage is used.
setTargetMachine(const TargetMachine * TM_)49   void setTargetMachine(const TargetMachine *TM_) { TM = TM_; }
50 
51   bool doInitialization(Module &M) override;
52 
53   bool doFinalization(Module &M) override;
54 
55   /// To store RegMask for given Function *.
56   void storeUpdateRegUsageInfo(const Function *FP,
57                                std::vector<uint32_t> RegMask);
58 
59   /// To query stored RegMask for given Function *, it will return nullptr if
60   /// function is not known.
61   const std::vector<uint32_t> *getRegUsageInfo(const Function *FP);
62 
63   void print(raw_ostream &OS, const Module *M = nullptr) const override;
64 
65 private:
66   /// A Dense map from Function * to RegMask.
67   /// In RegMask 0 means register used (clobbered) by function.
68   /// and 1 means content of register will be preserved around function call.
69   DenseMap<const Function *, std::vector<uint32_t>> RegMasks;
70 
71   const TargetMachine *TM;
72 };
73 }
74 
75 #endif
76