LLVM 22.0.0git
RegisterUsageInfo.h
Go to the documentation of this file.
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_REGISTERUSAGEINFO_H
19#define LLVM_CODEGEN_REGISTERUSAGEINFO_H
20
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/IR/PassManager.h"
25#include "llvm/Pass.h"
26#include "llvm/PassRegistry.h"
27#include <cstdint>
28#include <vector>
29
30namespace llvm {
31
32class Function;
33class TargetMachine;
34
36public:
37 /// Set TargetMachine which is used to print analysis.
39
40 bool doInitialization(Module &M);
41
42 bool doFinalization(Module &M);
43
44 /// To store RegMask for given Function *.
46 ArrayRef<uint32_t> RegMask);
47
48 /// To query stored RegMask for given Function *, it will returns ane empty
49 /// array if function is not known.
51
52 void print(raw_ostream &OS, const Module *M = nullptr) const;
53
54 bool invalidate(Module &M, const PreservedAnalyses &PA,
55 ModuleAnalysisManager::Invalidator &Inv);
56
57private:
58 /// A Dense map from Function * to RegMask.
59 /// In RegMask 0 means register used (clobbered) by function.
60 /// and 1 means content of register will be preserved around function call.
62
63 const TargetMachine *TM = nullptr;
64};
65
67 std::unique_ptr<PhysicalRegisterUsageInfo> PRUI;
68
69public:
70 static char ID;
75
77 const PhysicalRegisterUsageInfo &getPRUI() const { return *PRUI; }
78
79 bool doInitialization(Module &M) override {
80 PRUI.reset(new PhysicalRegisterUsageInfo());
81 return PRUI->doInitialization(M);
82 }
83
84 bool doFinalization(Module &M) override { return PRUI->doFinalization(M); }
85
86 void print(raw_ostream &OS, const Module *M = nullptr) const override {
87 PRUI->print(OS, M);
88 }
89};
90
101
103 : public PassInfoMixin<PhysicalRegisterUsageInfoPrinterPass> {
104 raw_ostream &OS;
105
106public:
109 static bool isRequired() { return true; }
110};
111
112} // end namespace llvm
113
114#endif // LLVM_CODEGEN_REGISTERUSAGEINFO_H
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
ImmutablePass(char &pid)
Definition Pass.h:287
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PhysicalRegisterUsageInfo run(Module &M, ModuleAnalysisManager &)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const PhysicalRegisterUsageInfo & getPRUI() const
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv)
ArrayRef< uint32_t > getRegUsageInfo(const Function &FP)
To query stored RegMask for given Function *, it will returns ane empty array if function is not know...
void setTargetMachine(const TargetMachine &TM)
Set TargetMachine which is used to print analysis.
void print(raw_ostream &OS, const Module *M=nullptr) const
void storeUpdateRegUsageInfo(const Function &FP, ArrayRef< uint32_t > RegMask)
To store RegMask for given Function *.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Primary interface to the complete machine description for the target machine.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void initializePhysicalRegisterUsageInfoWrapperLegacyPass(PassRegistry &)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition PassManager.h:70