================
@@ -706,16 +723,101 @@ void MachineSMEABI::insertStateChanges(EmitContext 
&Context,
 
 static DebugLoc getDebugLoc(MachineBasicBlock &MBB,
                             MachineBasicBlock::iterator MBBI) {
-  if (MBBI != MBB.end())
-    return MBBI->getDebugLoc();
-  return DebugLoc();
+  if (MBB.empty())
+    return DebugLoc();
+  return MBBI != MBB.end() ? MBBI->getDebugLoc() : MBB.back().getDebugLoc();
+}
+
+static bool findMarkedCall(const MachineBasicBlock &MBB,
+                           MachineBasicBlock::const_iterator MBBI,
+                           SmallVectorImpl<const MachineInstr *> &Calls,
+                           unsigned Marker, unsigned CallDestroyOpcode) {
+  auto IsMarker = [&](auto &MI) { return MI.getOpcode() == Marker; };
+  auto MarkerInst = std::find_if(MBBI, MBB.end(), IsMarker);
+  if (MarkerInst == MBB.end())
+    return false;
+  MachineBasicBlock::const_iterator I = MarkerInst;
+  while (++I != MBB.end()) {
+    if (I->isCall() || I->getOpcode() == CallDestroyOpcode)
+      break;
+  }
+  if (I != MBB.end() && I->isCall())
+    Calls.push_back(&*I);
+  // Note: This function always returns true if a "Marker" was found.
+  return true;
+}
+
+void MachineSMEABI::collectReachableMarkedCalls(
+    const MachineBasicBlock &StartMBB,
+    MachineBasicBlock::const_iterator StartInst,
+    SmallVectorImpl<const MachineInstr *> &Calls, unsigned Marker) const {
+  assert(Marker == AArch64::InOutZAUsePseudo ||
+         Marker == AArch64::RequiresZASavePseudo ||
+         Marker == AArch64::RequiresZT0SavePseudo);
+  unsigned CallDestroyOpcode = TII->getCallFrameDestroyOpcode();
+  if (findMarkedCall(StartMBB, StartInst, Calls, Marker, CallDestroyOpcode))
+    return;
+
+  SmallPtrSet<const MachineBasicBlock *, 4> Visited;
+  SmallVector<const MachineBasicBlock *> Worklist(StartMBB.succ_rbegin(),
+                                                  StartMBB.succ_rend());
+  while (!Worklist.empty()) {
+    const MachineBasicBlock *MBB = Worklist.pop_back_val();
+    auto [_, Inserted] = Visited.insert(MBB);
+    if (!Inserted)
+      continue;
+
+    if (!findMarkedCall(*MBB, MBB->begin(), Calls, Marker, CallDestroyOpcode))
+      Worklist.append(MBB->succ_rbegin(), MBB->succ_rend());
+  }
+}
+
+static StringRef getCalleeName(const MachineInstr &CallInst) {
+  assert(CallInst.isCall() && "expected a call");
+  for (const MachineOperand &MO : CallInst.operands()) {
+    if (MO.isSymbol())
+      return MO.getSymbolName();
+    if (MO.isGlobal())
+      return MO.getGlobal()->getName();
+  }
+  return {};
----------------
MacDue wrote:

I don't think there's a string that could be resolved (in the IR it's just a 
`BLR %0`). Neither lowerings new/old resolve a name for indirect calls. I've 
added a test that shows this. 

https://github.com/llvm/llvm-project/pull/170277
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to