[PATCH] D130133: Add a nop instruction if a section starts with landing pad for function splitter

Archit Saxena via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 22 14:04:38 PDT 2022


iamarchit123 updated this revision to Diff 446976.
iamarchit123 added a comment.

Correct minor spelling mistakes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130133

Files:
  llvm/include/llvm/CodeGen/BasicBlockSectionUtils.h
  llvm/lib/CodeGen/BasicBlockSections.cpp
  llvm/lib/CodeGen/MachineFunctionSplitter.cpp
  llvm/test/CodeGen/X86/machine-function-splitter.ll


Index: llvm/test/CodeGen/X86/machine-function-splitter.ll
===================================================================
--- llvm/test/CodeGen/X86/machine-function-splitter.ll
+++ llvm/test/CodeGen/X86/machine-function-splitter.ll
@@ -242,6 +242,28 @@
   ret void
 }
 
+define i32 @foo10(i1 zeroext %0) personality ptr @__gxx_personality_v0 !prof !14 {
+;; Check that nop is inserted just before EH pad if it's beginning a section.
+; MFS-DEFAULTS-LABEL: foo10
+; MFS-DEFAULTS-LABEL: callq   baz
+; MFS-DEFAULTS:       .section        .text.split.foo10,"ax", at progbits
+; MFS-DEFAULTS-NEXT:  foo10.cold:
+; MFS-DEFAULTS:       nop
+; MFS-DEFAULTS:       callq   _Unwind_Resume at PLT
+entry:
+  invoke void @_Z1fv()
+          to label %try.cont unwind label %lpad, !prof !17
+
+lpad:
+  %1 = landingpad { ptr, i32 }
+          cleanup
+          catch ptr @_ZTIi
+  resume { ptr, i32 } %1
+
+try.cont:
+  %2 = call i32 @baz()
+  ret i32 %2
+}
 
 declare i32 @bar()
 declare i32 @baz()
Index: llvm/lib/CodeGen/MachineFunctionSplitter.cpp
===================================================================
--- llvm/lib/CodeGen/MachineFunctionSplitter.cpp
+++ llvm/lib/CodeGen/MachineFunctionSplitter.cpp
@@ -146,7 +146,7 @@
     return X.getSectionID().Type < Y.getSectionID().Type;
   };
   llvm::sortBasicBlocksAndUpdateBranches(MF, Comparator);
-
+  llvm::avoidZeroOffsetLandingPad(MF);
   return true;
 }
 
Index: llvm/lib/CodeGen/BasicBlockSections.cpp
===================================================================
--- llvm/lib/CodeGen/BasicBlockSections.cpp
+++ llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -268,8 +268,8 @@
 // If the exception section begins with a landing pad, that landing pad will
 // assume a zero offset (relative to @LPStart) in the LSDA. However, a value of
 // zero implies "no landing pad." This function inserts a NOP just before the EH
-// pad label to ensure a nonzero offset. Returns true if padding is not needed.
-static bool avoidZeroOffsetLandingPad(MachineFunction &MF) {
+// pad label to ensure a nonzero offset.
+void llvm::avoidZeroOffsetLandingPad(MachineFunction &MF) {
   for (auto &MBB : MF) {
     if (MBB.isBeginSection() && MBB.isEHPad()) {
       MachineBasicBlock::iterator MI = MBB.begin();
@@ -278,10 +278,8 @@
       MCInst Nop = MF.getSubtarget().getInstrInfo()->getNop();
       BuildMI(MBB, MI, DebugLoc(),
               MF.getSubtarget().getInstrInfo()->get(Nop.getOpcode()));
-      return false;
     }
   }
-  return true;
 }
 
 // This checks if the source of this function has drifted since this binary was
Index: llvm/include/llvm/CodeGen/BasicBlockSectionUtils.h
===================================================================
--- llvm/include/llvm/CodeGen/BasicBlockSectionUtils.h
+++ llvm/include/llvm/CodeGen/BasicBlockSectionUtils.h
@@ -25,6 +25,8 @@
 void sortBasicBlocksAndUpdateBranches(MachineFunction &MF,
                                       MachineBasicBlockComparator MBBCmp);
 
+void avoidZeroOffsetLandingPad(MachineFunction &MF);
+
 } // end namespace llvm
 
 #endif // LLVM_CODEGEN_BASICBLOCKSECTIONUTILS_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130133.446976.patch
Type: text/x-patch
Size: 3103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220722/8cbad27b/attachment.bin>


More information about the llvm-commits mailing list