]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/RegisterUsageInfo.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / RegisterUsageInfo.h
1 //==- RegisterUsageInfo.h - Register Usage Informartion Storage --*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This pass is required to take advantage of the interprocedural register
10 /// allocation infrastructure.
11 ///
12 /// This pass is simple immutable pass which keeps RegMasks (calculated based on
13 /// actual register allocation) for functions in a module and provides simple
14 /// API to query this information.
15 ///
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H
19 #define LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H
20
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/Pass.h"
25 #include <cstdint>
26 #include <vector>
27
28 namespace llvm {
29
30 class Function;
31 class LLVMTargetMachine;
32
33 class PhysicalRegisterUsageInfo : public ImmutablePass {
34 public:
35   static char ID;
36
37   PhysicalRegisterUsageInfo() : ImmutablePass(ID) {
38     PassRegistry &Registry = *PassRegistry::getPassRegistry();
39     initializePhysicalRegisterUsageInfoPass(Registry);
40   }
41
42   /// Set TargetMachine which is used to print analysis.
43   void setTargetMachine(const LLVMTargetMachine &TM);
44
45   bool doInitialization(Module &M) override;
46
47   bool doFinalization(Module &M) override;
48
49   /// To store RegMask for given Function *.
50   void storeUpdateRegUsageInfo(const Function &FP,
51                                ArrayRef<uint32_t> RegMask);
52
53   /// To query stored RegMask for given Function *, it will returns ane empty
54   /// array if function is not known.
55   ArrayRef<uint32_t> getRegUsageInfo(const Function &FP);
56
57   void print(raw_ostream &OS, const Module *M = nullptr) const override;
58
59 private:
60   /// A Dense map from Function * to RegMask.
61   /// In RegMask 0 means register used (clobbered) by function.
62   /// and 1 means content of register will be preserved around function call.
63   DenseMap<const Function *, std::vector<uint32_t>> RegMasks;
64
65   const LLVMTargetMachine *TM;
66 };
67
68 } // end namespace llvm
69
70 #endif // LLVM_CODEGEN_PHYSICALREGISTERUSAGEINFO_H