[PATCH] D146467: [MachineInstr] make getCalledFunction method of MachineInstr

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 20 16:05:40 PDT 2023


arsenm added a comment.

It's a sketchy function to begin with, making a lot of assumptions about what a call looks like.



================
Comment at: llvm/include/llvm/CodeGen/MachineInstr.h:876
   }
+  /// Return a pointer to the Function being called, or nullptr if MI is not
+  /// a call instruction or is an indirect call.
----------------
This doesn't check it's a call


================
Comment at: llvm/lib/CodeGen/MachineInstr.cpp:2383
+const Function *MachineInstr::getCalledFunction() const {
+  for (const MachineOperand &MO : operands())
+    if (MO.isGlobal())
----------------
Preserve the braces


================
Comment at: llvm/lib/CodeGen/MachineInstr.cpp:2385
+    if (MO.isGlobal())
+      if (const auto *F = dyn_cast<Function>(MO.getGlobal()))
+        return F;
----------------
This also misses aliases, maybe it should just return the GlobalValue?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146467/new/

https://reviews.llvm.org/D146467



More information about the llvm-commits mailing list