38#define DEBUG_TYPE "hexagon-hvx-save"
42 cl::desc(
"Minimum number of bytes of HVX caller-saved register data live "
43 "across a call to trigger a remark (default: 8 x 128-byte "
55 static unsigned hvxVecCount(
Register VReg,
const MachineRegisterInfo &MRI) {
57 if (RC == &Hexagon::HvxWRRegClass)
59 if (RC == &Hexagon::HvxVRRegClass)
65 auto &
MORE = getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
69 const HexagonSubtarget &HST = MF.
getSubtarget<HexagonSubtarget>();
73 const MachineRegisterInfo &MRI = MF.
getRegInfo();
92 using VRegSet = SmallSet<Register, 8>;
97 for (
const MachineBasicBlock &
MBB : MF) {
100 for (
const MachineInstr &
MI :
MBB) {
101 for (
const MachineOperand &MO :
MI.operands()) {
105 if (!
R.isVirtual() || !hvxVecCount(R, MRI))
109 }
else if (MO.isUse() && !Defs.count(R)) {
121 for (
unsigned I = 0;
I < NumBlocks; ++
I)
122 LiveIn[
I] = UEVar[
I];
127 for (
const MachineBasicBlock &
MBB : MF) {
133 for (
Register R : LiveIn[Succ->getNumber()])
134 NewLiveOut.insert(R);
136 if (NewLiveOut != LiveOut[BN]) {
137 LiveOut[BN] = NewLiveOut;
142 VRegSet NewLiveIn = UEVar[BN];
144 if (!BlockDef[BN].
count(R))
147 if (NewLiveIn != LiveIn[BN]) {
148 LiveIn[BN] = NewLiveIn;
155 for (
const MachineBasicBlock &
MBB : MF) {
172 unsigned NumVecs = 0;
174 NumVecs += hvxVecCount(VReg, MRI);
175 unsigned TotalBytes = NumVecs * HVXLen;
178 <<
" has " << NumVecs <<
" HVX vector(s) live ("
179 << TotalBytes <<
" bytes)\n");
183 MachineOptimizationRemarkAnalysis
R(
186 <<
" HVX caller-saved register(s) ("
187 <<
ore::NV(
"TotalBytes", TotalBytes)
188 <<
" bytes) live across call";
195 for (
const MachineOperand &MO :
MI.operands()) {
196 if (!MO.isReg() || !MO.getReg().isVirtual())
199 LiveVRegs.erase(MO.getReg());
201 LiveVRegs.insert(MO.getReg());
209 StringRef getPassName()
const override {
return "Hexagon HVX Save Remarks"; }
211 void getAnalysisUsage(AnalysisUsage &AU)
const override {
212 AU.
addRequired<MachineOptimizationRemarkEmitterPass>();
218char HexagonHVXSaveRemark::ID = 0;
226 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.
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()
MCRegisterClass TargetRegisterClass