[Propeller] Do not generate the BB address map for empty functions.
authorRahman Lavaee <rahmanl@google.com>
Fri, 26 Mar 2021 01:44:00 +0000 (18:44 -0700)
committerRahman Lavaee <rahmanl@google.com>
Tue, 30 Mar 2021 03:15:01 +0000 (20:15 -0700)
Empty functions (functions with no real code) are irrelevant for propeller optimizations and their addresses sometimes conflict with other functions which obfuscates the analysis.
This simple change skips the BB address map emission for such functions.

Reviewed By: tmsriram

Differential Revision: https://reviews.llvm.org/D99395

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll [new file with mode: 0644]

index 160eaef..c1416cd 100644 (file)
@@ -1430,8 +1430,8 @@ void AsmPrinter::emitFunctionBody() {
   }
 
   // Emit section containing BB address offsets and their metadata, when
-  // BB labels are requested for this function.
-  if (MF->hasBBLabels())
+  // BB labels are requested for this function. Skip empty functions.
+  if (MF->hasBBLabels() && HasAnyRealCode)
     emitBBAddrMapSection(*MF);
 
   // Emit section containing stack size metadata.
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll b/llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll
new file mode 100644 (file)
index 0000000..4d814b5
--- /dev/null
@@ -0,0 +1,21 @@
+;; Verify that the BB address map is not emitted for empty functions.
+; RUN: llc < %s -mtriple=x86_64 -basic-block-sections=labels | FileCheck %s
+
+define void @empty_func() {
+entry:
+  unreachable
+}
+; CHECK:               {{^ *}}.text{{$}}
+; CHECK:       empty_func:
+; CHECK:       .Lfunc_begin0:
+; CHECK-NOT:   .section        .llvm_bb_addr_map
+
+define void @func() {
+entry:
+  ret void
+}
+
+; CHECK:       func:
+; CHECK:       .Lfunc_begin1:
+; CHECK:               .section        .llvm_bb_addr_map,"o",@llvm_bb_addr_map,.text{{$}}
+; CHECK:               .quad   .Lfunc_begin1