MIR Serialization: Serialize the machine instruction's debug location.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242938 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz 2015-07-22 21:15:11 +00:00
parent 27513fc040
commit 6f3ab8dd7b
6 changed files with 148 additions and 2 deletions

View File

@ -123,6 +123,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
.Case("killed", MIToken::kw_killed)
.Case("undef", MIToken::kw_undef)
.Case("frame-setup", MIToken::kw_frame_setup)
.Case("debug-location", MIToken::kw_debug_location)
.Case(".cfi_def_cfa_offset", MIToken::kw_cfi_def_cfa_offset)
.Default(MIToken::Identifier);
}

View File

@ -45,6 +45,7 @@ struct MIToken {
kw_killed,
kw_undef,
kw_frame_setup,
kw_debug_location,
kw_cfi_def_cfa_offset,
// Identifier tokens

View File

@ -205,7 +205,7 @@ bool MIParser::parse(MachineInstr *&MI) {
// TODO: Parse the bundle instruction flags and memory operands.
// Parse the remaining machine operands.
while (Token.isNot(MIToken::Eof)) {
while (Token.isNot(MIToken::Eof) && Token.isNot(MIToken::kw_debug_location)) {
auto Loc = Token.location();
if (parseMachineOperand(MO))
return true;
@ -217,6 +217,17 @@ bool MIParser::parse(MachineInstr *&MI) {
lex();
}
DebugLoc DebugLocation;
if (Token.is(MIToken::kw_debug_location)) {
lex();
if (Token.isNot(MIToken::exclaim))
return error("expected a metadata node after 'debug-location'");
MDNode *Node = nullptr;
if (parseMDNode(Node))
return true;
DebugLocation = DebugLoc(Node);
}
const auto &MCID = MF.getSubtarget().getInstrInfo()->get(OpCode);
if (!MCID.isVariadic()) {
// FIXME: Move the implicit operand verification to the machine verifier.
@ -225,7 +236,7 @@ bool MIParser::parse(MachineInstr *&MI) {
}
// TODO: Check for extraneous machine operands.
MI = MF.CreateMachineInstr(MCID, DebugLoc(), /*NoImplicit=*/true);
MI = MF.CreateMachineInstr(MCID, DebugLocation, /*NoImplicit=*/true);
MI->setFlags(Flags);
for (const auto &Operand : Operands)
MI->addOperand(MF, Operand.Operand);

View File

@ -378,6 +378,13 @@ void MIPrinter::print(const MachineInstr &MI) {
print(MI.getOperand(I), TRI);
NeedComma = true;
}
if (MI.getDebugLoc()) {
if (NeedComma)
OS << ',';
OS << " debug-location ";
MI.getDebugLoc()->printAsOperand(OS, MST);
}
}
void MIPrinter::printMBBReference(const MachineBasicBlock &MBB) {

View File

@ -0,0 +1,61 @@
# RUN: not llc -march=x86-64 -start-after machine-sink -stop-after machine-sink -o /dev/null %s 2>&1 | FileCheck %s
--- |
define i32 @test(i32 %x) #0 {
entry:
%x.addr = alloca i32, align 4
store i32 %x, i32* %x.addr, align 4
call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !12, metadata !13), !dbg !14
%0 = load i32, i32* %x.addr, align 4, !dbg !15
ret i32 %0, !dbg !15
}
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
attributes #0 = { nounwind "no-frame-pointer-elim"="false" }
attributes #1 = { nounwind readnone }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!9, !10}
!llvm.ident = !{!11}
!0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
!1 = !DIFile(filename: "test.ll", directory: "")
!2 = !{}
!3 = !{!4}
!4 = !DISubprogram(name: "test", scope: !5, file: !5, line: 4, type: !6, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32)* @test, variables: !2)
!5 = !DIFile(filename: "test.c", directory: "")
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !8}
!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!9 = !{i32 2, !"Dwarf Version", i32 4}
!10 = !{i32 2, !"Debug Info Version", i32 3}
!11 = !{!"clang version 3.7.0"}
!12 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1, scope: !4, file: !5, line: 4, type: !8)
!13 = !DIExpression()
!14 = !DILocation(line: 4, scope: !4)
!15 = !DILocation(line: 8, scope: !4)
...
---
name: test
isSSA: true
tracksRegLiveness: true
registers:
- { id: 0, class: gr32 }
frameInfo:
maxAlignment: 4
stack:
- { id: 0, name: x.addr, size: 4, alignment: 4 }
body:
- id: 0
name: entry
instructions:
- '%0 = COPY %edi'
# CHECK: [[@LINE+1]]:51: expected a metadata node after 'debug-location'
- 'DBG_VALUE _, 0, !12, !13, debug-location 14'
- 'MOV32mr %stack.x.addr, 1, _, 0, _, %0'
- '%eax = COPY %0'
- 'RETQ %eax'
...

View File

@ -0,0 +1,65 @@
# RUN: llc -march=x86-64 -start-after machine-sink -stop-after machine-sink -o /dev/null %s | FileCheck %s
# This test ensures that the MIR parser parses the machine instruction's
# debug location metadata correctly.
--- |
define i32 @test(i32 %x) #0 {
entry:
%x.addr = alloca i32, align 4
store i32 %x, i32* %x.addr, align 4
call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !12, metadata !13), !dbg !14
%0 = load i32, i32* %x.addr, align 4, !dbg !15
ret i32 %0, !dbg !15
}
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
attributes #0 = { nounwind "no-frame-pointer-elim"="false" }
attributes #1 = { nounwind readnone }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!9, !10}
!llvm.ident = !{!11}
!0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
!1 = !DIFile(filename: "test.ll", directory: "")
!2 = !{}
!3 = !{!4}
!4 = !DISubprogram(name: "test", scope: !5, file: !5, line: 4, type: !6, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32)* @test, variables: !2)
!5 = !DIFile(filename: "test.c", directory: "")
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !8}
!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!9 = !{i32 2, !"Dwarf Version", i32 4}
!10 = !{i32 2, !"Debug Info Version", i32 3}
!11 = !{!"clang version 3.7.0"}
!12 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1, scope: !4, file: !5, line: 4, type: !8)
!13 = !DIExpression()
!14 = !DILocation(line: 4, scope: !4)
!15 = !DILocation(line: 8, scope: !4)
...
---
name: test
isSSA: true
tracksRegLiveness: true
registers:
- { id: 0, class: gr32 }
frameInfo:
maxAlignment: 4
stack:
- { id: 0, name: x.addr, size: 4, alignment: 4 }
body:
- id: 0
name: entry
instructions:
# CHECK: DBG_VALUE _, 0, !12, !13, debug-location !14
# CHECK: %eax = COPY %0, debug-location !15
# CHECK: RETQ %eax, debug-location !15
- '%0 = COPY %edi'
- 'DBG_VALUE _, 0, !12, !13, debug-location !14'
- 'MOV32mr %stack.0.x.addr, 1, _, 0, _, %0'
- '%eax = COPY %0, debug-location !15'
- 'RETQ %eax, debug-location !15'
...