39#define DEBUG_TYPE "hexagon-hvx-save"
43 cl::desc(
"Minimum number of bytes of HVX caller-saved register data live "
44 "across a call to trigger a remark (default: 8 x 128-byte "
56 static unsigned hvxVecCount(
Register VReg,
const MachineRegisterInfo &MRI) {
57 const TargetRegisterClass *RC = MRI.
getRegClass(VReg);
58 if (RC == &Hexagon::HvxWRRegClass)
60 if (RC == &Hexagon::HvxVRRegClass)
65 bool runOnMachineFunction(MachineFunction &MF)
override {
66 auto &
MORE = getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
70 const HexagonSubtarget &HST = MF.
getSubtarget<HexagonSubtarget>();
74 const MachineRegisterInfo &MRI = MF.
getRegInfo();
93 using VRegSet = SmallSet<Register, 8>;
98 for (
const MachineBasicBlock &
MBB : MF) {
101 for (
const MachineInstr &
MI :
MBB) {
102 for (
const MachineOperand &MO :
MI.operands()) {
106 if (!
R.isVirtual() || !hvxVecCount(R, MRI))
110 }
else if (MO.isUse() && !Defs.count(R)) {
122 for (
unsigned I = 0;
I < NumBlocks; ++
I)
123 LiveIn[
I] = UEVar[
I];
128 for (
const MachineBasicBlock &
MBB : MF) {
134 for (
Register R : LiveIn[Succ->getNumber()])
135 NewLiveOut.insert(R);
137 if (NewLiveOut != LiveOut[BN]) {
138 LiveOut[BN] = NewLiveOut;
143 VRegSet NewLiveIn = UEVar[BN];
145 if (!BlockDef[BN].
count(R))
148 if (NewLiveIn != LiveIn[BN]) {
149 LiveIn[BN] = NewLiveIn;
156 for (
const MachineBasicBlock &
MBB : MF) {
173 unsigned NumVecs = 0;
175 NumVecs += hvxVecCount(VReg, MRI);
176 unsigned TotalBytes = NumVecs * HVXLen;
179 <<
" has " << NumVecs <<
" HVX vector(s) live ("
180 << TotalBytes <<
" bytes)\n");
184 MachineOptimizationRemarkAnalysis
R(
187 <<
" HVX caller-saved register(s) ("
188 <<
ore::NV(
"TotalBytes", TotalBytes)
189 <<
" bytes) live across call";
196 for (
const MachineOperand &MO :
MI.operands()) {
197 if (!MO.isReg() || !MO.getReg().isVirtual())
200 LiveVRegs.erase(MO.getReg());
202 LiveVRegs.insert(MO.getReg());
210 StringRef getPassName()
const override {
return "Hexagon HVX Save Remarks"; }
212 void getAnalysisUsage(AnalysisUsage &AU)
const override {
213 AU.
addRequired<MachineOptimizationRemarkEmitterPass>();
219char HexagonHVXSaveRemark::ID = 0;
227 return new HexagonHVXSaveRemark();
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallSet class.
This file defines the SmallVector class.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
FunctionPass class - This class is used to implement most global optimizations.
unsigned getVectorLength() const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
iterator_range< succ_iterator > successors()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
FunctionPass * createHexagonHVXSaveRemark()