[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:52:26 PDT 2017
arsenm created this revision.
Herald added subscribers: tpr, wdng.
Fixes not finding the called global for AMDGPU
call pseudoinstructions. The call instruction can't
directly refer to a global, so we use a pseudo mirroring
the actual instruction's operands with an extra operand
appended to refer to the 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 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.111015.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170814/98566559/attachment.bin>
More information about the llvm-commits
mailing list