LLVM 20.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/Function.h"
20#include "llvm/IR/Module.h"
21#include "llvm/Pass.h"
25#include <cstdint>
26#include <utility>
27#include <vector>
28
29using namespace llvm;
30
32 "print-regusage", cl::init(false), cl::Hidden,
33 cl::desc("print register usage details collected for analysis."));
34
36 "Register Usage Information Storage", false, true)
37
39
40void PhysicalRegisterUsageInfo::setTargetMachine(const LLVMTargetMachine &TM) {
41 this->TM = &TM;
42}
43
45 RegMasks.grow(M.size());
46 return false;
47}
48
50 if (DumpRegUsage)
51 print(errs());
52
53 RegMasks.shrink_and_clear();
54 return false;
55}
56
58 const Function &FP, ArrayRef<uint32_t> RegMask) {
59 RegMasks[&FP] = RegMask;
60}
61
64 auto It = RegMasks.find(&FP);
65 if (It != RegMasks.end())
66 return ArrayRef<uint32_t>(It->second);
67 return ArrayRef<uint32_t>();
68}
69
71 using FuncPtrRegMaskPair = std::pair<const Function *, std::vector<uint32_t>>;
72
74
75 // Create a vector of pointer to RegMasks entries
76 for (const auto &RegMask : RegMasks)
77 FPRMPairVector.push_back(&RegMask);
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))
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}
aarch64 promote const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
unsigned const TargetRegisterInfo * TRI
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
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.
raw_pwrite_stream & OS
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class describes a target machine that is implemented with the LLVM target-independent code gener...
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:65
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
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...
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
void storeUpdateRegUsageInfo(const Function &FP, ArrayRef< uint32_t > RegMask)
To store RegMask for given Function *.
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1647
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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.