1 //==- RegisterUsageInfo.h - Register Usage Informartion Storage --*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This pass is required to take advantage of the interprocedural register
11 /// allocation infrastructure.
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.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H
20 #define LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/Pass.h"
33 class PhysicalRegisterUsageInfo : public ImmutablePass {
34 virtual void anchor();
39 PhysicalRegisterUsageInfo() : ImmutablePass(ID) {
40 PassRegistry &Registry = *PassRegistry::getPassRegistry();
41 initializePhysicalRegisterUsageInfoPass(Registry);
44 void getAnalysisUsage(AnalysisUsage &AU) const override {
48 /// To set TargetMachine *, which is used to print
49 /// analysis when command line option -print-regusage is used.
50 void setTargetMachine(const TargetMachine *TM_) { TM = TM_; }
52 bool doInitialization(Module &M) override;
54 bool doFinalization(Module &M) override;
56 /// To store RegMask for given Function *.
57 void storeUpdateRegUsageInfo(const Function *FP,
58 std::vector<uint32_t> RegMask);
60 /// To query stored RegMask for given Function *, it will return nullptr if
61 /// function is not known.
62 const std::vector<uint32_t> *getRegUsageInfo(const Function *FP);
64 void print(raw_ostream &OS, const Module *M = nullptr) const override;
67 /// A Dense map from Function * to RegMask.
68 /// In RegMask 0 means register used (clobbered) by function.
69 /// and 1 means content of register will be preserved around function call.
70 DenseMap<const Function *, std::vector<uint32_t>> RegMasks;
72 const TargetMachine *TM;
75 } // end namespace llvm
77 #endif // LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H