[PATCH] D134691: [MC] Don't emit redundant compact unwind entries

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 26 19:09:58 PDT 2022


int3 created this revision.
Herald added a subscriber: hiraditya.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If there's no DWARF instructions, personality, or LSDA, I don't think
there's a need to emit a CU entry either. This canonicalization of
unwind info allows link-time code folding to fold more functions (since
functions with trivial unwind info are now obviously identical to
functions with the same code but with no unwind info).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134691

Files:
  lld/test/MachO/lit.local.cfg
  llvm/lib/MC/MCStreamer.cpp
  llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s
  llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
  llvm/test/MC/AArch64/arm64_32-compact-unwind.s


Index: llvm/test/MC/AArch64/arm64_32-compact-unwind.s
===================================================================
--- llvm/test/MC/AArch64/arm64_32-compact-unwind.s
+++ llvm/test/MC/AArch64/arm64_32-compact-unwind.s
@@ -5,11 +5,12 @@
 ; references to addresses (function, personality, LSDA) are pointer-sized.
 
 ; CHECK: Contents of section __LD,__compact_unwind:
-; CHECK-NEXT:  0004 00000000 04000000 00000002 00000000
+; CHECK-NEXT:  0004 00000000 04000000 00100002 00000000
 ; CHECK-NEXT:  0014 00000000
         .globl  _test_compact_unwind
         .align  2
 _test_compact_unwind:
         .cfi_startproc
+        .cfi_def_cfa_offset 16
         ret
         .cfi_endproc
Index: llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
===================================================================
--- llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
+++ llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
@@ -6,18 +6,14 @@
 
 # CHECK:      Contents of __compact_unwind section:
 # CHECK-NEXT:   Entry at offset 0x0:
-# CHECK-NEXT:     start:                0x0 ltmp0
-# CHECK-NEXT:     length:               0x8
-# CHECK-NEXT:     compact encoding:     0x02000000
-# CHECK-NEXT:   Entry at offset 0x20:
 # CHECK-NEXT:     start:                0x8 _foo2
 # CHECK-NEXT:     length:               0x40
 # CHECK-NEXT:     compact encoding:     0x02009000
-# CHECK-NEXT:   Entry at offset 0x40:
+# CHECK-NEXT:   Entry at offset 0x20:
 # CHECK-NEXT:     start:                0x48 _foo3
 # CHECK-NEXT:     length:               0xd4
 # CHECK-NEXT:     compact encoding:     0x0200400f
-# CHECK-NEXT:   Entry at offset 0x60:
+# CHECK-NEXT:   Entry at offset 0x40:
 # CHECK-NEXT:     start:                0x11c _foo4
 # CHECK-NEXT:     length:               0x54
 # CHECK-NEXT:     compact encoding:     0x02021010
Index: llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s
===================================================================
--- llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s
+++ llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s
@@ -13,6 +13,7 @@
 	.p2align	2
 _main:
 	.cfi_startproc
+  .cfi_def_cfa_offset 16
 	ret
 	.cfi_endproc
 
Index: llvm/lib/MC/MCStreamer.cpp
===================================================================
--- llvm/lib/MC/MCStreamer.cpp
+++ llvm/lib/MC/MCStreamer.cpp
@@ -124,9 +124,12 @@
 void MCStreamer::emitExplicitComments() {}
 
 void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) {
-  for (auto &FI : DwarfFrameInfos)
+  for (auto &FI : DwarfFrameInfos) {
+    if (!MAB || FI.Instructions.empty() && !FI.Personality && !FI.Lsda)
+      continue;
     FI.CompactUnwindEncoding =
-        (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0);
+        MAB->generateCompactUnwindEncoding(FI.Instructions);
+  }
 }
 
 /// EmitIntValue - Special case of EmitValue that avoids the client having to
Index: lld/test/MachO/lit.local.cfg
===================================================================
--- lld/test/MachO/lit.local.cfg
+++ lld/test/MachO/lit.local.cfg
@@ -19,7 +19,7 @@
 
 # Since most of our tests are written around x86_64, we give this platform the
 # shortest substitution of "%lld".
-lld = ('ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot ' +
+lld = ('~/pika14/build/RelWithDebInfo/Darwin-x86_64/toolchain/bin/ld64.ld64 -deduplicate_safe -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot ' +
     os.path.join(config.test_source_root, "MachO", "Inputs", "MacOSX.sdk"))
 config.substitutions.append(('%lld', lld + ' -fatal_warnings'))
 config.substitutions.append(('%no-fatal-warnings-lld', lld))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134691.463074.patch
Type: text/x-patch
Size: 3694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220927/c65b00a7/attachment.bin>


More information about the llvm-commits mailing list