Teach our Dwarf emission to use the string pool.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143097 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGen/ARM/debug-info-sreg2.ll b/test/CodeGen/ARM/debug-info-sreg2.ll
index ee777ce..3972e68 100644
--- a/test/CodeGen/ARM/debug-info-sreg2.ll
+++ b/test/CodeGen/ARM/debug-info-sreg2.ll
@@ -6,8 +6,8 @@
 ;CHECK: Ldebug_loc0:
 ;CHECK-NEXT:        .long   Ltmp1
 ;CHECK-NEXT:        .long   Ltmp2
-;CHECK-NEXT: Lset8 = Ltmp10-Ltmp9                    @ Loc expr size
-;CHECK-NEXT:        .short  Lset8
+;CHECK-NEXT: Lset[[N:[0-9]+]] = Ltmp10-Ltmp9        @ Loc expr size
+;CHECK-NEXT:        .short  Lset[[N]]
 ;CHECK-NEXT: Ltmp9:
 ;CHECK-NEXT:        .byte   144                     @ DW_OP_regx for S register
 
diff --git a/test/CodeGen/X86/2010-06-28-DbgEntryPC.ll b/test/CodeGen/X86/2010-06-28-DbgEntryPC.ll
index 2ba12df..b9b538a 100644
--- a/test/CodeGen/X86/2010-06-28-DbgEntryPC.ll
+++ b/test/CodeGen/X86/2010-06-28-DbgEntryPC.ll
@@ -5,17 +5,17 @@
 ; CHECK:	.byte	17                      ## DW_TAG_compile_unit
 ; CHECK-NEXT:	.byte	1                       ## DW_CHILDREN_yes
 ; CHECK-NEXT:	.byte	37                      ## DW_AT_producer
-; CHECK-NEXT:	.byte	8                       ## DW_FORM_string
+; CHECK-NEXT:	.byte	14                      ## DW_FORM_strp
 ; CHECK-NEXT:	.byte	19                      ## DW_AT_language
 ; CHECK-NEXT:	.byte	5                       ## DW_FORM_data2
 ; CHECK-NEXT:	.byte	3                       ## DW_AT_name
-; CHECK-NEXT:	.byte	8                       ## DW_FORM_string
+; CHECK-NEXT:	.byte	14                      ## DW_FORM_strp
 ; CHECK-NEXT:	.byte	82                      ## DW_AT_entry_pc
 ; CHECK-NEXT:	.byte	1                       ## DW_FORM_addr
 ; CHECK-NEXT:	.byte	16                      ## DW_AT_stmt_list
 ; CHECK-NEXT:	.byte	6                       ## DW_FORM_data4
 ; CHECK-NEXT:	.byte	27                      ## DW_AT_comp_dir
-; CHECK-NEXT:	.byte	8                       ## DW_FORM_string
+; CHECK-NEXT:	.byte	14                      ## DW_FORM_strp
 ; CHECK-NEXT:	.byte	225                     ## DW_AT_APPLE_optimized
 
 %struct.a = type { i32, %struct.a* }
diff --git a/test/DebugInfo/2011-09-26-GlobalVarContext.ll b/test/DebugInfo/2011-09-26-GlobalVarContext.ll
index 3e9fa88..1452ff9 100644
--- a/test/DebugInfo/2011-09-26-GlobalVarContext.ll
+++ b/test/DebugInfo/2011-09-26-GlobalVarContext.ll
@@ -2,14 +2,14 @@
 
 ; ModuleID = 'test.c'
 
-@GLOBAL = common global i32 0, align 4
+@GLB = common global i32 0, align 4
 
 define i32 @f() nounwind {
-  %LOCAL = alloca i32, align 4
-  call void @llvm.dbg.declare(metadata !{i32* %LOCAL}, metadata !15), !dbg !17
-  %1 = load i32* @GLOBAL, align 4, !dbg !18
-  store i32 %1, i32* %LOCAL, align 4, !dbg !18
-  %2 = load i32* @GLOBAL, align 4, !dbg !19
+  %LOC = alloca i32, align 4
+  call void @llvm.dbg.declare(metadata !{i32* %LOC}, metadata !15), !dbg !17
+  %1 = load i32* @GLB, align 4, !dbg !18
+  store i32 %1, i32* %LOC, align 4, !dbg !18
+  %2 = load i32* @GLB, align 4, !dbg !19
   ret i32 %2, !dbg !19
 }
 
@@ -31,17 +31,17 @@
 !11 = metadata !{i32 720932}                      ; [ DW_TAG_base_type ]
 !12 = metadata !{metadata !13}
 !13 = metadata !{metadata !14}
-!14 = metadata !{i32 720948, i32 0, null, metadata !"GLOBAL", metadata !"GLOBAL", metadata !"", metadata !6, i32 1, metadata !9, i32 0, i32 1, i32* @GLOBAL} ; [ DW_TAG_variable ]
-!15 = metadata !{i32 721152, metadata !16, metadata !"LOCAL", metadata !6, i32 4, metadata !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ]
+!14 = metadata !{i32 720948, i32 0, null, metadata !"GLB", metadata !"GLB", metadata !"", metadata !6, i32 1, metadata !9, i32 0, i32 1, i32* @GLB} ; [ DW_TAG_variable ]
+!15 = metadata !{i32 721152, metadata !16, metadata !"LOC", metadata !6, i32 4, metadata !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ]
 !16 = metadata !{i32 720907, metadata !5, i32 3, i32 9, metadata !6, i32 0} ; [ DW_TAG_lexical_block ]
 !17 = metadata !{i32 4, i32 9, metadata !16, null}
 !18 = metadata !{i32 4, i32 23, metadata !16, null}
 !19 = metadata !{i32 5, i32 5, metadata !16, null}
 
-; CHECK: .ascii	 "GLOBAL"
+; CHECK: .ascii	 "GLB"
 ; CHECK: .byte	1
 ; CHECK: .byte	1
 
-; CHECK: .ascii	 "LOCAL"
+; CHECK: .ascii	 "LOC"
 ; CHECK: .byte	1
 ; CHECK: .byte	4
diff --git a/test/DebugInfo/stringpool.ll b/test/DebugInfo/stringpool.ll
new file mode 100644
index 0000000..0a7c979
--- /dev/null
+++ b/test/DebugInfo/stringpool.ll
@@ -0,0 +1,54 @@
+; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s --check-prefix=LINUX
+; RUN: llc -O0 -mtriple=x86_64-darwin < %s | FileCheck %s --check-prefix=DARWIN
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@x = common global i32 0, align 4
+@yyyyyyyy = common global i32 0, align 4
+
+!llvm.dbg.cu = !{!0}
+
+!0 = metadata !{i32 720913, i32 0, i32 12, metadata !"hello.c", metadata !"/home/nlewycky", metadata !"clang version 3.1 (trunk 143048)", i1 true, i1 true, metadata !"", i32 0, metadata !1, metadata !1, metadata !1, metadata !3} ; [ DW_TAG_compile_unit ]
+!1 = metadata !{metadata !2}
+!2 = metadata !{i32 0}
+!3 = metadata !{metadata !4}
+!4 = metadata !{metadata !5, metadata !8}
+!5 = metadata !{i32 720948, i32 0, null, metadata !"x", metadata !"x", metadata !"", metadata !6, i32 1, metadata !7, i32 0, i32 1, i32* @x} ; [ DW_TAG_variable ]
+!6 = metadata !{i32 720937, metadata !"hello.c", metadata !"/home/nlewycky", null} ; [ DW_TAG_file_type ]
+!7 = metadata !{i32 720932, null, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!8 = metadata !{i32 720948, i32 0, null, metadata !"yyyyyyyy", metadata !"yyyyyyyy", metadata !"", metadata !6, i32 2, metadata !7, i32 0, i32 1, i32* @yyyyyyyy} ; [ DW_TAG_variable ]
+
+; 120 is ASCII 'x'. Verify that we use it directly as its name and don't emit
+; a reference to the string pool.
+; LINUX:        .byte   120                     # DW_AT_name
+; DARWIN:       .byte   120                     ## DW_AT_name
+
+; Verify that we refer to 'yyyyyyyy' with a relocation.
+; LINUX:      .long   .Lstring{{[0-9]+}}      # DW_AT_name
+; LINUX-NEXT: .long   39                      # DW_AT_type
+; LINUX-NEXT: .byte   1                       # DW_AT_external
+; LINUX-NEXT: .byte   1                       # DW_AT_decl_file
+; LINUX-NEXT: .byte   2                       # DW_AT_decl_line
+; LINUX-NEXT: .byte   9                       # DW_AT_location
+; LINUX-NEXT: .byte   3
+; LINUX-NEXT: .quad   yyyyyyyy
+
+; Verify that we refer to 'yyyyyyyy' without a relocation.
+; DARWIN: Lset[[N:[0-9]+]] = Lstring{{[0-9]+}}-Lsection_str   ## DW_AT_name
+; DARWIN-NEXT:        .long   Lset[[N]]
+; DARWIN-NEXT:        .long   39                      ## DW_AT_type
+; DARWIN-NEXT:        .byte   1                       ## DW_AT_external
+; DARWIN-NEXT:        .byte   1                       ## DW_AT_decl_file
+; DARWIN-NEXT:        .byte   2                       ## DW_AT_decl_line
+; DARWIN-NEXT:        .byte   9                       ## DW_AT_location
+; DARWIN-NEXT:        .byte   3
+; DARWIN-NEXT:        .quad   _yyyyyyyy
+
+
+; Verify that "yyyyyyyy" ended up in the stringpool.
+; LINUX: .section .debug_str,"MS",@progbits,1
+; LINUX-NOT: .section
+; LINUX: yyyyyyyy
+; DARWIN: .section __DWARF,__debug_str,regular,debug
+; DARWIN-NOT: .section
+; DARWIN: yyyyyyyy