Line data Source code
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/ArrayRef.h"
23 : #include "llvm/ADT/DenseMap.h"
24 : #include "llvm/IR/Instructions.h"
25 : #include "llvm/Pass.h"
26 : #include <cstdint>
27 : #include <vector>
28 :
29 : namespace llvm {
30 :
31 : class Function;
32 : class TargetMachine;
33 :
34 : class PhysicalRegisterUsageInfo : public ImmutablePass {
35 : public:
36 : static char ID;
37 :
38 3890 : PhysicalRegisterUsageInfo() : ImmutablePass(ID) {
39 1945 : PassRegistry &Registry = *PassRegistry::getPassRegistry();
40 1945 : initializePhysicalRegisterUsageInfoPass(Registry);
41 1945 : }
42 :
43 : /// Set TargetMachine which is used to print analysis.
44 : void setTargetMachine(const TargetMachine &TM);
45 :
46 : bool doInitialization(Module &M) override;
47 :
48 : bool doFinalization(Module &M) override;
49 :
50 : /// To store RegMask for given Function *.
51 : void storeUpdateRegUsageInfo(const Function &FP,
52 : ArrayRef<uint32_t> RegMask);
53 :
54 : /// To query stored RegMask for given Function *, it will returns ane empty
55 : /// array if function is not known.
56 : ArrayRef<uint32_t> getRegUsageInfo(const Function &FP);
57 :
58 : void print(raw_ostream &OS, const Module *M = nullptr) const override;
59 :
60 : private:
61 : /// A Dense map from Function * to RegMask.
62 : /// In RegMask 0 means register used (clobbered) by function.
63 : /// and 1 means content of register will be preserved around function call.
64 : DenseMap<const Function *, std::vector<uint32_t>> RegMasks;
65 :
66 : const TargetMachine *TM;
67 : };
68 :
69 : } // end namespace llvm
70 :
71 : #endif // LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H
|