[llvm] [BOLT]Identify indirect call (PR #123305)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 04:41:51 PST 2025


================
@@ -1961,6 +1961,59 @@ bool BinaryFunction::postProcessIndirectBranches(
       bool IsEpilogue = llvm::any_of(BB, [&](const MCInst &Instr) {
         return BC.MIB->isLeave(Instr) || BC.MIB->isPop(Instr);
       });
+      if (BC.isAArch64()) {
+        // Any adr instruction of aarch64 will generate a new entry,
+        // Adr instruction cannt afford to do any optimizations
+        if (!IsEpilogue && !isMultiEntry()) {
+          BinaryBasicBlock::iterator LastDefCFAOffsetInstIter = BB.end();
+          // find the last OpDefCfaOffset 0 instruction.
+          for (BinaryBasicBlock::iterator Iter = BB.begin(); Iter != BB.end();
+               ++Iter) {
+            if (&*Iter == &Instr) {
+              break;
+            }
+            if (BC.MIB->isCFI(*Iter)) {
+              const MCCFIInstruction *CFIInst =
+                  BB.getParent()->getCFIFor(*Iter);
+              if ((CFIInst->getOperation() ==
+                   MCCFIInstruction::OpDefCfaOffset) &&
+                  (CFIInst->getOffset() == 0)) {
+                LastDefCFAOffsetInstIter = Iter;
+                break;
----------------
paschalis-mpeis wrote:

Consider simplifying a bit here:
Instead of breaking, you can continue your iteration`LastDefCFAOffsetInstIter` till `Iter` and only set epilogue to true when you validate that no stack changes can occur.

Then you can get rid of the 'if statement' at [L1986](https://github.com/llvm/llvm-project/pull/123305/files#diff-ca39122670f58da421af7031c33576d77078d2b81f48aa9baccd945724edb891R1986)

https://github.com/llvm/llvm-project/pull/123305


More information about the llvm-commits mailing list