Update .debug_line section version information to match DWARF version.

One more attempt to re-commit the patch r285355, which I had to revert in r285362, because some tests were failing (the reason is because the size of the line_table varied depending on the full file name).

In the past the compiler always emitted .debug_line version 2, though some opcodes from DWARF 3 (e.g. DW_LNS_set_prologue_end, DW_LNS_set_epilogue_begin or DW_LNS_set_isa) and from DWARF 4 could be emitted by the compiler.

This patch changes version information of .debug_line to exactly match the DWARF version. For .debug_line version 4, a new field maximum_operations_per_instruction is emitted.

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

llvm-svn: 289925
diff --git a/llvm/test/DebugInfo/X86/debug-line-version.s b/llvm/test/DebugInfo/X86/debug-line-version.s
new file mode 100644
index 0000000..2d5fceb
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/debug-line-version.s
@@ -0,0 +1,39 @@
+// RUN: llvm-mc -dwarf-version 2 -triple  i686-pc-linux-gnu %s -filetype=obj -o - | llvm-readobj -r -s -sd | FileCheck --check-prefixes=DWARF,DWARF2 %s
+// RUN: llvm-mc -dwarf-version 3 -triple  i686-pc-linux-gnu %s -filetype=obj -o - | llvm-readobj -r -s -sd | FileCheck --check-prefixes=DWARF,DWARF3 %s
+// RUN: llvm-mc -dwarf-version 4 -triple  i686-pc-linux-gnu %s -filetype=obj -o - | llvm-readobj -r -s -sd | FileCheck --check-prefixes=DWARF,DWARF4 %s
+
+// DWARF:    Name: .debug_line (11)
+// DWARF-NEXT:    Type: SHT_PROGBITS (0x1)
+// DWARF-NEXT:    Flags [ (0x0)
+// DWARF-NEXT:    ]
+// DWARF-NEXT:    Address: 0x0
+// DWARF-NEXT:    Offset: 0x35
+// DWARF2-NEXT:    Size: 51
+// DWARF3-NEXT:    Size: 51
+// DWARF4-NEXT:    Size: 52
+// DWARF-NEXT:    Link: 0
+// DWARF-NEXT:    Info: 0
+// DWARF-NEXT:    AddressAlignment: 1
+// DWARF-NEXT:    EntrySize: 0
+// DWARF2-NEXT:    SectionData (
+// DWARF2-NEXT:      0000: 2F000000 02001A00 00000101 FB0E0D00  |/...............|
+// DWARF2-NEXT:      0010: 01010101 00000001 00000100 666F6F00  |............foo.|
+// DWARF2-NEXT:      0020: 00000000 00050200 00000003 3F010201  |............?...|
+// DWARF2-NEXT:      0030: 000101                               |...|
+// DWARF2-NEXT:    )
+// DWARF3-NEXT:    SectionData (
+// DWARF3-NEXT:      0000: 2F000000 03001A00 00000101 FB0E0D00  |/...............|
+// DWARF3-NEXT:      0010: 01010101 00000001 00000100 666F6F00  |............foo.|
+// DWARF3-NEXT:      0020: 00000000 00050200 00000003 3F010201  |............?...|
+// DWARF3-NEXT:      0030: 000101                               |...|
+// DWARF3-NEXT:    )
+// DWARF4-NEXT:    SectionData (
+// DWARF4-NEXT:      0000: 30000000 04001B00 00000101 01FB0E0D  |0...............|
+// DWARF4-NEXT:      0010: 00010101 01000000 01000001 00666F6F  |.............foo|
+// DWARF4-NEXT:      0020: 00000000 00000502 00000000 033F0102  |.............?..|
+// DWARF4-NEXT:      0030: 01000101                             |....|
+// DWARF4-NEXT:    )
+
+        .file   1 "foo"
+        .loc    1 64 0
+        nop
diff --git a/llvm/test/DebugInfo/X86/empty.ll b/llvm/test/DebugInfo/X86/empty.ll
index e156e3b..6506f55 100644
--- a/llvm/test/DebugInfo/X86/empty.ll
+++ b/llvm/test/DebugInfo/X86/empty.ll
@@ -4,7 +4,7 @@
 ; Expect no line table entry since there are no functions and file references in this compile unit
 ; CHECK: .debug_line contents:
 ; CHECK: Line table prologue:
-; CHECK: total_length: 0x00000019
+; CHECK: total_length: 0x0000001a
 ; CHECK-NOT: file_names[
 
 ; CHECK: .debug_pubnames contents:
diff --git a/llvm/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll b/llvm/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll
index 527f577..a60725f 100644
--- a/llvm/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll
+++ b/llvm/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll
@@ -15,7 +15,7 @@
 ; CHECK: DW_AT_high_pc [DW_FORM_data4]          (0x00000010)
 
 ; CHECK: DW_TAG_compile_unit
-; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x0000003c)
+; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x0000003d)
 ; CHECK: DW_AT_low_pc [DW_FORM_addr]            (0x0000000000000010)
 ; CHECK: DW_AT_high_pc [DW_FORM_data4]          (0x00000009)
 ; CHECK: DW_TAG_subprogram
@@ -25,10 +25,10 @@
 
 ; CHECK: .debug_line contents:
 ; CHECK-NEXT: Line table prologue:
-; CHECK-NEXT: total_length: 0x00000038
+; CHECK-NEXT: total_length: 0x00000039
 ; CHECK: file_names[  1]    0 0x00000000 0x00000000 simple.c
 ; CHECK: Line table prologue:
-; CHECK-NEXT: total_length: 0x00000039
+; CHECK-NEXT: total_length: 0x0000003a
 ; CHECK: file_names[  1]    0 0x00000000 0x00000000 simple2.c
 ; CHECK-NOT: file_names