LLVM 22.0.0git
RegisterUsageInfo.cpp
Go to the documentation of this file.
1//===- RegisterUsageInfo.cpp - Register Usage Information Storage ---------===//
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///
9/// This pass is required to take advantage of the interprocedural register
10/// allocation infrastructure.
11///
12//===----------------------------------------------------------------------===//
13
19#include "llvm/IR/Analysis.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/Module.h"
22#include "llvm/IR/PassManager.h"
23#include "llvm/Pass.h"
27#include <cstdint>
28#include <utility>
29#include <vector>
30
31using namespace llvm;
32
34 "print-regusage", cl::init(false), cl::Hidden,
35 cl::desc("print register usage details collected for analysis."));
36
38 "Register Usage Information Storage", false, true)
39
41
42void PhysicalRegisterUsageInfo::setTargetMachine(const TargetMachine &TM) {
43 this->TM = &TM;
44}
45
47 RegMasks.grow(M.size());
48 return false;
49}
50
52 if (DumpRegUsage)
53 print(errs());
54
55 RegMasks.shrink_and_clear();
56 return false;
57}
58
60 const Function &FP, ArrayRef<uint32_t> RegMask) {
61 RegMasks[&FP] = RegMask;
62}
63
66 auto It = RegMasks.find(&FP);
67 if (It != RegMasks.end())
68 return ArrayRef<uint32_t>(It->second);
69 return ArrayRef<uint32_t>();
70}
71
73 using FuncPtrRegMaskPair = std::pair<const Function *, std::vector<uint32_t>>;
74
75 // Create a vector of pointer to RegMasks entries
77 llvm::make_pointer_range(RegMasks));
78
79 // sort the vector to print analysis in alphabatic order of function name.
81 FPRMPairVector,
82 [](const FuncPtrRegMaskPair *A, const FuncPtrRegMaskPair *B) -> bool {
83 return A->first->getName() < B->first->getName();
84 });
85
86 for (const FuncPtrRegMaskPair *FPRMPair : FPRMPairVector) {
87 OS << FPRMPair->first->getName() << " "
88 << "Clobbered Registers: ";
90 = TM->getSubtarget<TargetSubtargetInfo>(*(FPRMPair->first))
91 .getRegisterInfo();
92
93 for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) {
94 if (MachineOperand::clobbersPhysReg(&(FPRMPair->second[0]), PReg))
95 OS << printReg(PReg, TRI) << " ";
96 }
97 OS << "\n";
98 }
99}
100
102 Module &M, const PreservedAnalyses &PA,
103 ModuleAnalysisManager::Invalidator &) {
105 return !PAC.preservedWhenStateless();
106}
107
108AnalysisKey PhysicalRegisterUsageAnalysis::Key;
115
119 auto *PRUI = &AM.getResult<PhysicalRegisterUsageAnalysis>(M);
120 PRUI->print(OS, &M);
121 return PreservedAnalyses::all();
122}
aarch64 promote const
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static cl::opt< bool > DumpRegUsage("print-regusage", cl::init(false), cl::Hidden, cl::desc("print register usage details collected for analysis."))
This pass is required to take advantage of the interprocedural register allocation infrastructure.
This file defines the SmallVector class.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
PhysicalRegisterUsageInfo run(Module &M, ModuleAnalysisManager &)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
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 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
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition Analysis.h:275
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
Pass manager infrastructure for declaring and invalidating analyses.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1624
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition iterator.h:363
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29