[PATCH] D36697: IPRA: Don't assume called function is first call operand
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 14 09:54:47 PDT 2017
arsenm updated this revision to Diff 111017.
arsenm added a comment.
Use a dyn_cast. It might be possible to see a call to something that isn't directly a Function
https://reviews.llvm.org/D36697
Files:
lib/CodeGen/RegUsageInfoPropagate.cpp
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 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>();
@@ -113,15 +127,14 @@
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');
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36697.111017.patch
Type: text/x-patch
Size: 1637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170814/a1db3647/attachment.bin>
More information about the llvm-commits
mailing list