[llvm] d14460d - [AsmPrinter] Fix placement of function entry comments
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 15:01:42 PDT 2023
Author: Fangrui Song
Date: 2023-04-18T15:01:36-07:00
New Revision: d14460d00ebacd296405872ae37e7ba743f9eecb
URL: https://github.com/llvm/llvm-project/commit/d14460d00ebacd296405872ae37e7ba743f9eecb
DIFF: https://github.com/llvm/llvm-project/commit/d14460d00ebacd296405872ae37e7ba743f9eecb.diff
LOG: [AsmPrinter] Fix placement of function entry comments
The placement is currently wrong in the presence of function entry related
instrumentations (prefixdata, -fpatchable-function-entry=, -fsanitize=kcfi,
etc).
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/test/CodeGen/AArch64/patchable-function-entry.ll
llvm/test/CodeGen/AArch64/prefixdata.ll
llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
llvm/test/CodeGen/RISCV/patchable-function-entry.ll
llvm/test/CodeGen/X86/patchable-function-entry.ll
llvm/test/CodeGen/X86/prefixdata.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 10b6e52dc9649..0a803d8a1405b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -927,13 +927,6 @@ void AsmPrinter::emitFunctionHeader() {
if (F.hasFnAttribute(Attribute::Cold))
OutStreamer->emitSymbolAttribute(CurrentFnSym, MCSA_Cold);
- if (isVerbose()) {
- F.printAsOperand(OutStreamer->getCommentOS(),
- /*PrintType=*/false, F.getParent());
- emitFunctionHeaderComment();
- OutStreamer->getCommentOS() << '\n';
- }
-
// Emit the prefix data.
if (F.hasPrefixData()) {
if (MAI->hasSubsectionsViaSymbols()) {
@@ -977,6 +970,13 @@ void AsmPrinter::emitFunctionHeader() {
CurrentPatchableFunctionEntrySym = CurrentFnBegin;
}
+ if (isVerbose()) {
+ F.printAsOperand(OutStreamer->getCommentOS(),
+ /*PrintType=*/false, F.getParent());
+ emitFunctionHeaderComment();
+ OutStreamer->getCommentOS() << '\n';
+ }
+
// Emit the function descriptor. This is a virtual function to allow targets
// to emit their specific function descriptor. Right now it is only used by
// the AIX target. The PowerPC 64-bit V1 ELF target also uses function
diff --git a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
index 776890639ec6c..5750c1f601bde 100644
--- a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
@@ -71,10 +71,10 @@ define void @f5() "patchable-function-entry"="5" comdat {
;; "patchable-function-prefix" emits data before the function entry label.
define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
; CHECK-LABEL: .type f3_2, at function
-; CHECK-NEXT: .Ltmp1: // @f3_2
+; CHECK-NEXT: .Ltmp1:
; CHECK-NEXT: nop
; CHECK-NEXT: nop
-; CHECK-NEXT: f3_2:
+; CHECK-NEXT: f3_2: // @f3_2
; CHECK: // %bb.0:
; CHECK-NEXT: nop
; CHECK-NEXT: ret
@@ -90,10 +90,10 @@ define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="
;; When prefix data is used, arbitrarily place NOPs after prefix data.
define void @prefix() "patchable-function-entry"="0" "patchable-function-prefix"="1" prefix i32 1 {
; CHECK-LABEL: .type prefix, at function
-; CHECK-NEXT: .word 1 // @prefix
+; CHECK-NEXT: .word 1 // 0x1
; CHECK: .Ltmp2:
; CHECK: nop
-; CHECK-NEXT: prefix:
+; CHECK-NEXT: prefix: // @prefix
;; Emit a __patchable_function_entries entry even if "patchable-function-entry" is 0.
; CHECK: .section __patchable_function_entries,"awo", at progbits,prefix{{$}}
; CHECK: .p2align 3
diff --git a/llvm/test/CodeGen/AArch64/prefixdata.ll b/llvm/test/CodeGen/AArch64/prefixdata.ll
index 37d4cc02a44cb..eeeeb7b5373cd 100644
--- a/llvm/test/CodeGen/AArch64/prefixdata.ll
+++ b/llvm/test/CodeGen/AArch64/prefixdata.ll
@@ -8,9 +8,8 @@
; MACHO-NEXT: .alt_entry _f
; MACHO-NEXT: _f:
; ELF: .type f, at function
-; ELF-NEXT: .word 1
-; ELF-NEXT: // 0x1
-; ELF-NEXT: f:
+; ELF-NEXT: .word 1 // 0x1
+; ELF-NEXT: f: // @f
define void @f() prefix i32 1 {
ret void
}
diff --git a/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll b/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
index 12d4bfb50a198..aaa3fda1ae776 100644
--- a/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
@@ -43,9 +43,9 @@ define void @f5() "patchable-function-entry"="5" comdat {
;; "patchable-function-prefix" emits data before the function entry label.
define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
; CHECK-LABEL: .type f3_2, at function
-; CHECK-NEXT: .Ltmp0: # @f3_2
+; CHECK-NEXT: .Ltmp0:
; CHECK-COUNT-2: nop
-; CHECK-NEXT: f3_2:
+; CHECK-NEXT: f3_2: # @f3_2
; CHECK: # %bb.0:
; CHECK-NEXT: nop
; LA32-NEXT: addi.w $sp, $sp, -16
diff --git a/llvm/test/CodeGen/RISCV/patchable-function-entry.ll b/llvm/test/CodeGen/RISCV/patchable-function-entry.ll
index 9c4eb2c414dfd..2804fdfc1ac9c 100644
--- a/llvm/test/CodeGen/RISCV/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/RISCV/patchable-function-entry.ll
@@ -49,10 +49,10 @@ define void @f5() "patchable-function-entry"="5" comdat {
;; "patchable-function-prefix" emits data before the function entry label.
define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
; CHECK-LABEL: .type f3_2, at function
-; CHECK-NEXT: .Ltmp0: # @f3_2
+; CHECK-NEXT: .Ltmp0:
; NORVC-COUNT-2: addi zero, zero, 0
; RVC-COUNT-2: c.nop
-; CHECK-NEXT: f3_2:
+; CHECK-NEXT: f3_2: # @f3_2
; CHECK: # %bb.0:
; NORVC-NEXT: addi zero, zero, 0
; NORVC-NEXT: addi sp, sp, -16
diff --git a/llvm/test/CodeGen/X86/patchable-function-entry.ll b/llvm/test/CodeGen/X86/patchable-function-entry.ll
index 8d0984327ffc4..124f5c57c74b5 100644
--- a/llvm/test/CodeGen/X86/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/X86/patchable-function-entry.ll
@@ -80,10 +80,10 @@ define void @f5() "patchable-function-entry"="5" comdat {
;; the remaining instructions do not need to be modified.
define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
; CHECK-LABEL: .type f3_2, at function
-; CHECK-NEXT: .Ltmp0: # @f3_2
+; CHECK-NEXT: .Ltmp0:
; CHECK-NEXT: nop
; CHECK-NEXT: nop
-; CHECK-NEXT: f3_2:
+; CHECK-NEXT: f3_2: # @f3_2
; CHECK: # %bb.0:
; CHECK-NEXT: nop
; CHECK-NEXT: ret
diff --git a/llvm/test/CodeGen/X86/prefixdata.ll b/llvm/test/CodeGen/X86/prefixdata.ll
index 2c3f277796452..20a558c9e03bb 100644
--- a/llvm/test/CodeGen/X86/prefixdata.ll
+++ b/llvm/test/CodeGen/X86/prefixdata.ll
@@ -4,13 +4,12 @@
@i = linkonce_odr global i32 1
; MACHO: ltmp0:
-; MACHO-NEXT: .long 1
+; MACHO-NEXT: .long 1 ## 0x1
; MACHO-NEXT: .alt_entry _f
-; MACHO-NEXT: _f:
+; MACHO-NEXT: _f: ## @f
; ELF: .type f, at function
-; ELF-NEXT: .long 1
-; ELF-NEXT: # 0x1
-; ELF-NEXT: f:
+; ELF-NEXT: .long 1 # 0x1
+; ELF-NEXT: f: # @f
define void @f() prefix i32 1 {
ret void
}
More information about the llvm-commits
mailing list