[llvm] r305880 - [XRay] Reduce synthetic references emitted by XRay

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 20 23:39:42 PDT 2017


Author: dberris
Date: Wed Jun 21 01:39:42 2017
New Revision: 305880

URL: http://llvm.org/viewvc/llvm-project?rev=305880&view=rev
Log:
[XRay] Reduce synthetic references emitted by XRay

Summary:
When we're building with XRay instrumentation, we use a trick that
preserves references from the function to a function sled index. This
index table lives in a separate section, and without this trick the
linker is free to garbage-collect this section and all the segments it
refers to. Until we're able to tell the linkers to preserve these
sections, we use this reference trick to keep around both the index and
the entries in the instrumentation map.

Before this change we emitted both a synthetic reference to the label in
the instrumentation map, and to the entry in the function map index.
This change removes the first synthetic reference and only emits one
synthetic reference to the index -- the index entry has the references
to the labels in the instrumentation map, so the linker will still
preserve those if the function itself is preserved.

This reduces the amount of synthetic references we emit from 16 bytes to
just 8 bytes in x86_64, and similarly to other platforms.

Reviewers: dblaikie

Subscribers: javed.absar, kpw, pelikan, llvm-commits

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

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/test/CodeGen/AArch64/xray-attribute-instrumentation.ll
    llvm/trunk/test/CodeGen/AArch64/xray-tail-call-sled.ll
    llvm/trunk/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll
    llvm/trunk/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll
    llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll
    llvm/trunk/test/CodeGen/X86/xray-custom-log.ll
    llvm/trunk/test/CodeGen/X86/xray-log-args.ll
    llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Jun 21 01:39:42 2017
@@ -2801,26 +2801,24 @@ void AsmPrinter::emitXRayTable() {
   }
 
   // Before we switch over, we force a reference to a label inside the
-  // xray_instr_map and xray_fn_idx sections. Since this function is always
-  // called just before the function's end, we assume that this is happening
-  // after the last return instruction. We also use the synthetic label in the
-  // xray_inster_map as a delimeter for the range of sleds for this function in
-  // the index.
+  // xray_fn_idx sections. This makes sure that the xray_fn_idx section is kept
+  // live by the linker if the function is not garbage-collected. Since this
+  // function is always called just before the function's end, we assume that
+  // this is happening after the last return instruction.
   auto WordSizeBytes = MAI->getCodePointerSize();
-  MCSymbol *SledsStart = OutContext.createTempSymbol("xray_synthetic_", true);
   MCSymbol *IdxRef = OutContext.createTempSymbol("xray_fn_idx_synth_", true);
   OutStreamer->EmitCodeAlignment(16);
-  OutStreamer->EmitSymbolValue(SledsStart, WordSizeBytes, false);
   OutStreamer->EmitSymbolValue(IdxRef, WordSizeBytes, false);
 
   // Now we switch to the instrumentation map section. Because this is done
   // per-function, we are able to create an index entry that will represent the
   // range of sleds associated with a function.
+  MCSymbol *SledsStart = OutContext.createTempSymbol("xray_sleds_start", true);
   OutStreamer->SwitchSection(InstMap);
   OutStreamer->EmitLabel(SledsStart);
   for (const auto &Sled : Sleds)
     Sled.emit(WordSizeBytes, OutStreamer.get(), CurrentFnSym);
-  MCSymbol *SledsEnd = OutContext.createTempSymbol("xray_synthetic_end", true);
+  MCSymbol *SledsEnd = OutContext.createTempSymbol("xray_sleds_end", true);
   OutStreamer->EmitLabel(SledsEnd);
 
   // We then emit a single entry in the index per function. We use the symbols

Modified: llvm/trunk/test/CodeGen/AArch64/xray-attribute-instrumentation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/xray-attribute-instrumentation.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/xray-attribute-instrumentation.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/xray-attribute-instrumentation.ll Wed Jun 21 01:39:42 2017
@@ -25,9 +25,9 @@ define i32 @foo() nounwind noinline uwta
 ; CHECK-NEXT:  ret
 }
 ; CHECK:       .p2align 4
-; CHECK-NEXT:  .xword .Lxray_synthetic_0
 ; CHECK-NEXT:  .xword .Lxray_fn_idx_synth_0
 ; CHECK-NEXT:  .section xray_instr_map,{{.*}}
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0
 ; CHECK:       .xword .Lxray_sled_0
 ; CHECK:       .xword .Lxray_sled_1
+; CHECK-LABEL: Lxray_sleds_end0

Modified: llvm/trunk/test/CodeGen/AArch64/xray-tail-call-sled.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/xray-tail-call-sled.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/xray-tail-call-sled.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/xray-tail-call-sled.ll Wed Jun 21 01:39:42 2017
@@ -28,21 +28,20 @@ define i32 @callee() nounwind noinline u
 ; CHECK-NEXT:  ret
 }
 ; CHECK:       .p2align 4
-; CHECK-NEXT:  .xword .Lxray_synthetic_0
 ; CHECK-NEXT:  .xword .Lxray_fn_idx_synth_0
 ; CHECK-NEXT:  .section xray_instr_map,{{.*}}
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0:
 ; CHECK:       .xword .Lxray_sled_0
 ; CHECK:       .xword .Lxray_sled_1
-; CHECK-LABEL: Lxray_synthetic_end0:
+; CHECK-LABEL: Lxray_sleds_end0:
 ; CHECK:       .section xray_fn_idx,{{.*}}
 ; CHECK-LABEL: Lxray_fn_idx_synth_0:
-; CHECK:       .xword .Lxray_synthetic_0
-; CHECK-NEXT:  .xword .Lxray_synthetic_end0
+; CHECK:       .xword .Lxray_sleds_start0
+; CHECK-NEXT:  .xword .Lxray_sleds_end0
 
 define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" {
 ; CHECK:       .p2align	2
-; CHECK-LABEL: .Lxray_sled_2:
+; CHECK-LABEL: Lxray_sled_2:
 ; CHECK-NEXT:  b	#32
 ; CHECK-NEXT:  nop
 ; CHECK-NEXT:  nop
@@ -53,7 +52,7 @@ define i32 @caller() nounwind noinline u
 ; CHECK-NEXT:  nop
 ; CHECK-LABEL: .Ltmp2:
 ; CHECK:       .p2align	2
-; CHECK-LABEL: .Lxray_sled_3:
+; CHECK-LABEL: Lxray_sled_3:
 ; CHECK-NEXT:  b	#32
 ; CHECK-NEXT:  nop
 ; CHECK-NEXT:  nop
@@ -68,14 +67,13 @@ define i32 @caller() nounwind noinline u
   ret i32 %retval
 }
 ; CHECK:       .p2align 4
-; CHECK-NEXT:  .xword .Lxray_synthetic_1
 ; CHECK-NEXT:  .xword .Lxray_fn_idx_synth_1
 ; CHECK-NEXT:  .section xray_instr_map,{{.*}}
-; CHECK-LABEL: Lxray_synthetic_1:
+; CHECK-LABEL: Lxray_sleds_start1:
 ; CHECK:       .xword .Lxray_sled_2
 ; CHECK:       .xword .Lxray_sled_3
-; CHECK-LABEL: Lxray_synthetic_end1:
+; CHECK-LABEL: Lxray_sleds_end1:
 ; CHECK:       .section xray_fn_idx,{{.*}}
 ; CHECK-LABEL: Lxray_fn_idx_synth_1:
-; CHECK:       .xword .Lxray_synthetic_1
-; CHECK-NEXT:  .xword .Lxray_synthetic_end1
+; CHECK:       .xword .Lxray_sleds_start1
+; CHECK-NEXT:  .xword .Lxray_sleds_end1

Modified: llvm/trunk/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll Wed Jun 21 01:39:42 2017
@@ -24,14 +24,13 @@ define i32 @foo() nounwind noinline uwta
 ; CHECK-NEXT:  bx	lr
 }
 ; CHECK:       .p2align 4
-; CHECK-NEXT:  .long {{.*}}Lxray_synthetic_0
 ; CHECK-NEXT:  .long {{.*}}Lxray_fn_idx_synth_0
 ; CHECK-NEXT:  .section {{.*}}xray_instr_map{{.*}}
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0:
 ; CHECK:       .long {{.*}}Lxray_sled_0
 ; CHECK:       .long {{.*}}Lxray_sled_1
-; CHECK-LABEL: Lxray_synthetic_end0:
+; CHECK-LABEL: Lxray_sleds_end0:
 ; CHECK:       .section {{.*}}xray_fn_idx{{.*}}
 ; CHECK-LABEL: Lxray_fn_idx_synth_0:
-; CHECK:       .long {{.*}}Lxray_synthetic_0
-; CHECK-NEXT:  .long {{.*}}Lxray_synthetic_end0
+; CHECK:       .long {{.*}}Lxray_sleds_start0
+; CHECK-NEXT:  .long {{.*}}Lxray_sleds_end0

Modified: llvm/trunk/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll Wed Jun 21 01:39:42 2017
@@ -24,15 +24,14 @@ define i32 @foo() nounwind noinline uwta
 ; CHECK-NEXT:  bx lr
 }
 ; CHECK:       .p2align 4
-; CHECK-NEXT:  .long {{.*}}Lxray_synthetic_0
 ; CHECK-NEXT:  .long {{.*}}Lxray_fn_idx_synth_0
 ; CHECK-NEXT:  .section {{.*}}xray_instr_map{{.*}}
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0:
 ; CHECK:       .long {{.*}}Lxray_sled_0
 ; CHECK:       .long {{.*}}Lxray_sled_1
-; CHECK-LABEL: Lxray_synthetic_end0:
+; CHECK-LABEL: Lxray_sleds_end0:
 ; CHECK:       .section {{.*}}xray_fn_idx{{.*}}
 ; CHECK-LABEL: Lxray_fn_idx_synth_0:
-; CHECK:       .long {{.*}}xray_synthetic_0
-; CHECK-NEXT:  .long {{.*}}xray_synthetic_end0
+; CHECK:       .long {{.*}}xray_sleds_start0
+; CHECK-NEXT:  .long {{.*}}xray_sleds_end0
 

Modified: llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll (original)
+++ llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll Wed Jun 21 01:39:42 2017
@@ -14,17 +14,16 @@ define i32 @foo() nounwind noinline uwta
 ; CHECK-NEXT:  nopw %cs:512(%rax,%rax)
 }
 ; CHECK:       .p2align 4, 0x90
-; CHECK-NEXT:  .quad {{.*}}xray_synthetic_0
 ; CHECK-NEXT:  .quad {{.*}}xray_fn_idx_synth_0
 ; CHECK-NEXT:  .section {{.*}}xray_instr_map
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0:
 ; CHECK:       .quad {{.*}}xray_sled_0
 ; CHECK:       .quad {{.*}}xray_sled_1
-; CHECK-LABEL: Lxray_synthetic_end0:
+; CHECK-LABEL: Lxray_sleds_end0:
 ; CHECK:       .section {{.*}}xray_fn_idx
 ; CHECK-LABEL: Lxray_fn_idx_synth_0:
-; CHECK:       .quad {{.*}}xray_synthetic_0
-; CHECK-NEXT:  .quad {{.*}}xray_synthetic_end0
+; CHECK:       .quad {{.*}}xray_sleds_start0
+; CHECK-NEXT:  .quad {{.*}}xray_sleds_end0
 
 
 ; We test multiple returns in a single function to make sure we're getting all
@@ -52,15 +51,14 @@ NotEqual:
 ; CHECK-NEXT:  nopw %cs:512(%rax,%rax)
 }
 ; CHECK:       .p2align 4, 0x90
-; CHECK-NEXT:  .quad {{.*}}xray_synthetic_1
 ; CHECK-NEXT:  .quad {{.*}}xray_fn_idx_synth_1
 ; CHECK-NEXT:  .section {{.*}}xray_instr_map
-; CHECK-LABEL: Lxray_synthetic_1:
+; CHECK-LABEL: Lxray_sleds_start1:
 ; CHECK:       .quad {{.*}}xray_sled_2
 ; CHECK:       .quad {{.*}}xray_sled_3
 ; CHECK:       .quad {{.*}}xray_sled_4
-; CHECK-LABEL: Lxray_synthetic_end1:
+; CHECK-LABEL: Lxray_sleds_end1:
 ; CHECK:       .section {{.*}}xray_fn_idx
 ; CHECK-LABEL: Lxray_fn_idx_synth_1:
-; CHECK:       .quad {{.*}}xray_synthetic_1
-; CHECK-NEXT:  .quad {{.*}}xray_synthetic_end1
+; CHECK:       .quad {{.*}}xray_sleds_start1
+; CHECK-NEXT:  .quad {{.*}}xray_sleds_end1

Modified: llvm/trunk/test/CodeGen/X86/xray-custom-log.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-custom-log.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-custom-log.ll (original)
+++ llvm/trunk/test/CodeGen/X86/xray-custom-log.ll Wed Jun 21 01:39:42 2017
@@ -17,7 +17,7 @@ define i32 @fn() nounwind noinline uwtab
     ret i32 0
 }
 ; CHECK:       .section {{.*}}xray_instr_map
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0:
 ; CHECK:       .quad {{.*}}xray_event_sled_0
 
 declare void @llvm.xray.customevent(i8*, i32)

Modified: llvm/trunk/test/CodeGen/X86/xray-log-args.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-log-args.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-log-args.ll (original)
+++ llvm/trunk/test/CodeGen/X86/xray-log-args.ll Wed Jun 21 01:39:42 2017
@@ -6,7 +6,7 @@
 define i32 @callee(i32 %arg) nounwind noinline uwtable "function-instrument"="xray-always" "xray-log-args"="1" {
   ret i32 %arg
 }
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0:
 ; CHECK:	.quad	{{\.?}}Lxray_sled_0
 ; CHECK:	.quad	{{_?}}callee
 ; CHECK:	.byte	3
@@ -22,7 +22,7 @@ define i32 @caller(i32 %arg) nounwind no
   %retval = tail call i32 @callee(i32 %arg)
   ret i32 %retval
 }
-; CHECK-LABEL: Lxray_synthetic_1:
+; CHECK-LABEL: Lxray_sleds_start1:
 ; CHECK:	.quad	{{\.?}}Lxray_sled_2
 ; CHECK:	.quad	{{_?}}caller
 ; CHECK:	.byte	3

Modified: llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll?rev=305880&r1=305879&r2=305880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll (original)
+++ llvm/trunk/test/CodeGen/X86/xray-tail-call-sled.ll Wed Jun 21 01:39:42 2017
@@ -14,17 +14,16 @@ define i32 @callee() nounwind noinline u
 ; CHECK-NEXT:  nopw %cs:512(%rax,%rax)
 }
 ; CHECK:       .p2align 4, 0x90
-; CHECK-NEXT:  .quad {{.*}}xray_synthetic_0{{.*}}
 ; CHECK-NEXT:  .quad {{.*}}xray_fn_idx_synth_0{{.*}}
 ; CHECK-NEXT:  .section {{.*}}xray_instr_map
-; CHECK-LABEL: Lxray_synthetic_0:
+; CHECK-LABEL: Lxray_sleds_start0:
 ; CHECK:       .quad {{.*}}xray_sled_0
 ; CHECK:       .quad {{.*}}xray_sled_1
-; CHECK-LABEL: Lxray_synthetic_end0:
+; CHECK-LABEL: Lxray_sleds_end0:
 ; CHECK-NEXT:  .section {{.*}}xray_fn_idx
 ; CHECK-LABEL: Lxray_fn_idx_synth_0:
-; CHECK:       .quad {{.*}}xray_synthetic_0
-; CHECK-NEXT:  .quad {{.*}}xray_synthetic_end0
+; CHECK:       .quad {{.*}}xray_sleds_start0
+; CHECK-NEXT:  .quad {{.*}}xray_sleds_end0
 
 define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" {
 ; CHECK:       .p2align 1, 0x90
@@ -42,13 +41,12 @@ define i32 @caller() nounwind noinline u
   ret i32 %retval
 }
 ; CHECK:       .p2align 4, 0x90
-; CHECK-NEXT:  .quad {{.*}}xray_synthetic_1{{.*}}
 ; CHECK-NEXT:  .quad {{.*}}xray_fn_idx_synth_1{{.*}}
-; CHECK-LABEL: Lxray_synthetic_1:
+; CHECK-LABEL: Lxray_sleds_start1:
 ; CHECK:       .quad {{.*}}xray_sled_2
 ; CHECK:       .quad {{.*}}xray_sled_3
-; CHECK-LABEL: Lxray_synthetic_end1:
+; CHECK-LABEL: Lxray_sleds_end1:
 ; CHECK:       .section {{.*}}xray_fn_idx
 ; CHECK-LABEL: Lxray_fn_idx_synth_1:
-; CHECK:       .quad {{.*}}xray_synthetic_1
-; CHECK:       .quad {{.*}}xray_synthetic_end1
+; CHECK:       .quad {{.*}}xray_sleds_start1
+; CHECK:       .quad {{.*}}xray_sleds_end1




More information about the llvm-commits mailing list