LLVM 24.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
15#include "CodeGenOptions.h"
20#include "llvm/IR/Analysis.h"
21#include "llvm/IR/Function.h"
22#include "llvm/IR/Module.h"
23#include "llvm/IR/PassManager.h"
25#include "llvm/Pass.h"
28#include <cstdint>
29#include <vector>
30
31using namespace llvm;
32
34 "Register Usage Information Storage", false, true)
35
37
38void PhysicalRegisterUsageInfo::setTargetMachine(const TargetMachine &TM) {
39 this->TM = &TM;
40}
41
43 RegMasks.reserve(M.size());
44 return false;
45}
46
48 if (getCodeGenOptions(M).print_regusage)
49 print(errs());
50
51 RegMasks.shrink_and_clear();
52 return false;
53}
54
56 const Function &FP, ArrayRef<uint32_t> RegMask) {
57 RegMasks[&FP] = RegMask;
58}
59
62 auto It = RegMasks.find(&FP);
63 if (It != RegMasks.end())
64 return ArrayRef<uint32_t>(It->second);
65 return ArrayRef<uint32_t>();
66}
67
69 using FuncPtrRegMaskPair = decltype(RegMasks)::value_type;
70
71 // Create a vector of pointer to RegMasks entries
73 llvm::make_pointer_range(RegMasks));
74
75 // sort the vector to print analysis in alphabatic order of function name.
77 FPRMPairVector,
78 [](const FuncPtrRegMaskPair *A, const FuncPtrRegMaskPair *B) -> bool {
79 return A->first->getName() < B->first->getName();
80 });
81
82 for (const FuncPtrRegMaskPair *FPRMPair : FPRMPairVector) {
83 OS << FPRMPair->first->getName() << " "
84 << "Clobbered Registers: ";
86 = TM->getSubtarget<TargetSubtargetInfo>(*(FPRMPair->first))
87 .getRegisterInfo();
88
89 for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) {
90 if (MachineOperand::clobbersPhysReg(&(FPRMPair->second[0]), PReg))
91 OS << printReg(PReg, TRI) << " ";
92 }
93 OS << "\n";
94 }
95}
96
98 Module &M, const PreservedAnalyses &PA,
99 ModuleAnalysisManager::Invalidator &) {
101 return !PAC.preservedWhenStateless();
102}
103
104AnalysisKey PhysicalRegisterUsageAnalysis::Key;
111
115 auto *PRUI = &AM.getResult<PhysicalRegisterUsageAnalysis>(M);
116 PRUI->print(OS, &M);
117 return PreservedAnalyses::all();
118}
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
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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:68
LLVM_ABI PhysicalRegisterUsageInfo run(Module &M, ModuleAnalysisManager &)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv)
LLVM_ABI bool doFinalization(Module &M)
LLVM_ABI 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...
LLVM_ABI bool doInitialization(Module &M)
LLVM_ABI void print(raw_ostream &OS, const Module *M=nullptr) const
LLVM_ABI 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.
This is an optimization pass for GlobalISel generic memory operations.
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1652
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:368
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
const CodeGenOptions & getCodeGenOptions(const LLVMContext &C)
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29