[PATCH] D146467: [MachineInstr] make getCalledFunction method of MachineInstr
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 20 16:02:10 PDT 2023
nickdesaulniers created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This will be useful in other places in a follow up commit.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146467
Files:
llvm/include/llvm/CodeGen/MachineInstr.h
llvm/lib/CodeGen/MachineInstr.cpp
llvm/lib/CodeGen/MachineRegisterInfo.cpp
Index: llvm/lib/CodeGen/MachineRegisterInfo.cpp
===================================================================
--- llvm/lib/CodeGen/MachineRegisterInfo.cpp
+++ llvm/lib/CodeGen/MachineRegisterInfo.cpp
@@ -542,17 +542,6 @@
}
}
-static const Function *getCalledFunction(const MachineInstr &MI) {
- for (const MachineOperand &MO : MI.operands()) {
- if (!MO.isGlobal())
- continue;
- const Function *Func = dyn_cast<Function>(MO.getGlobal());
- if (Func != nullptr)
- return Func;
- }
- return nullptr;
-}
-
static bool isNoReturnDef(const MachineOperand &MO) {
// Anything which is not a noreturn function is a real def.
const MachineInstr &MI = *MO.getParent();
@@ -566,7 +555,7 @@
// not return, since the runtime may need it.
if (MF.getFunction().hasFnAttribute(Attribute::UWTable))
return false;
- const Function *Called = getCalledFunction(MI);
+ const Function *Called = MI.getCalledFunction();
return !(Called == nullptr || !Called->hasFnAttribute(Attribute::NoReturn) ||
!Called->hasFnAttribute(Attribute::NoUnwind));
}
Index: llvm/lib/CodeGen/MachineInstr.cpp
===================================================================
--- llvm/lib/CodeGen/MachineInstr.cpp
+++ llvm/lib/CodeGen/MachineInstr.cpp
@@ -2378,3 +2378,11 @@
DebugInstrNum = MF.getNewDebugInstrNum();
return DebugInstrNum;
}
+
+const Function *MachineInstr::getCalledFunction() const {
+ for (const MachineOperand &MO : operands())
+ if (MO.isGlobal())
+ if (const auto *F = dyn_cast<Function>(MO.getGlobal()))
+ return F;
+ return nullptr;
+}
Index: llvm/include/llvm/CodeGen/MachineInstr.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineInstr.h
+++ llvm/include/llvm/CodeGen/MachineInstr.h
@@ -44,6 +44,7 @@
template <typename T> class ArrayRef;
class DIExpression;
class DILocalVariable;
+class Function;
class MachineBasicBlock;
class MachineFunction;
class MachineRegisterInfo;
@@ -872,6 +873,9 @@
bool isCall(QueryType Type = AnyInBundle) const {
return hasProperty(MCID::Call, Type);
}
+ /// Return a pointer to the Function being called, or nullptr if MI is not
+ /// a call instruction or is an indirect call.
+ const Function *getCalledFunction() const;
/// Return true if this is a call instruction that may have an associated
/// call site entry in the debug info.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146467.506759.patch
Type: text/x-patch
Size: 2433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230320/e0d424d6/attachment.bin>
More information about the llvm-commits
mailing list