aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/RegUsageInfoPropagate.cpp')
-rw-r--r--llvm/lib/CodeGen/RegUsageInfoPropagate.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp b/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp
index a39c945..f6d4506 100644
--- a/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp
+++ b/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp
@@ -88,6 +88,19 @@ void RegUsageInfoPropagationPass::getAnalysisUsage(AnalysisUsage &AU) const {
MachineFunctionPass::getAnalysisUsage(AU);
}
+// Assumes call instructions have a single reference to a function.
+static const Function *findCalledFunction(const Module &M, MachineInstr &MI) {
+ for (MachineOperand &MO : MI.operands()) {
+ if (MO.isGlobal())
+ return dyn_cast<Function>(MO.getGlobal());
+
+ if (MO.isSymbol())
+ return M.getFunction(MO.getSymbolName());
+ }
+
+ return nullptr;
+}
+
bool RegUsageInfoPropagationPass::runOnMachineFunction(MachineFunction &MF) {
const Module *M = MF.getFunction()->getParent();
PhysicalRegisterUsageInfo *PRUI = &getAnalysis<PhysicalRegisterUsageInfo>();
@@ -118,15 +131,14 @@ bool RegUsageInfoPropagationPass::runOnMachineFunction(MachineFunction &MF) {
Changed = true;
};
- MachineOperand &Operand = MI.getOperand(0);
- if (Operand.isGlobal())
- UpdateRegMask(cast<Function>(Operand.getGlobal()));
- else if (Operand.isSymbol())
- UpdateRegMask(M->getFunction(Operand.getSymbolName()));
+ if (const Function *F = findCalledFunction(*M, MI)) {
+ UpdateRegMask(F);
+ } else {
+ DEBUG(dbgs() << "Failed to find call target function\n");
+ }
- DEBUG(dbgs()
- << "Call Instruction After Register Usage Info Propagation : \n");
- DEBUG(dbgs() << MI << "\n");
+ DEBUG(dbgs() << "Call Instruction After Register Usage Info Propagation : "
+ << MI << '\n');
}
}