Index: lib/CodeGen/RegUsageInfoPropagate.cpp =================================================================== --- lib/CodeGen/RegUsageInfoPropagate.cpp +++ lib/CodeGen/RegUsageInfoPropagate.cpp @@ -87,6 +87,20 @@ MachineFunctionPass::getAnalysisUsage(AU); } +// Assumes call instructions have a single reference to a function. +// TODO: Should this be a TII hook? +static const Function *findCalledFunction(const Module &M, MachineInstr &MI) { + for (MachineOperand &MO : MI.operands()) { + if (MO.isGlobal()) + return cast(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(); @@ -113,15 +127,14 @@ Changed = true; }; - MachineOperand &Operand = MI.getOperand(0); - if (Operand.isGlobal()) - UpdateRegMask(cast(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'); } }