[llvm] r242916 - MIR Serialization: Serialize the metadata machine operands.
Alex Lorenz
arphaman at gmail.com
Wed Jul 22 10:58:47 PDT 2015
Author: arphaman
Date: Wed Jul 22 12:58:46 2015
New Revision: 242916
URL: http://llvm.org/viewvc/llvm-project?rev=242916&view=rev
Log:
MIR Serialization: Serialize the metadata machine operands.
Added:
llvm/trunk/test/CodeGen/MIR/X86/expected-metadata-node-after-exclaim.mir
llvm/trunk/test/CodeGen/MIR/X86/metadata-operands.mir
llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-node.mir
Modified:
llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
llvm/trunk/lib/CodeGen/MIRPrinter.cpp
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp?rev=242916&r1=242915&r2=242916&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp Wed Jul 22 12:58:46 2015
@@ -310,6 +310,8 @@ static MIToken::TokenKind symbolToken(ch
return MIToken::equal;
case ':':
return MIToken::colon;
+ case '!':
+ return MIToken::exclaim;
default:
return MIToken::Error;
}
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.h?rev=242916&r1=242915&r2=242916&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.h (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.h Wed Jul 22 12:58:46 2015
@@ -36,6 +36,7 @@ struct MIToken {
equal,
underscore,
colon,
+ exclaim,
// Keywords
kw_implicit,
Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=242916&r1=242915&r2=242916&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Wed Jul 22 12:58:46 2015
@@ -112,6 +112,7 @@ public:
bool parseConstantPoolIndexOperand(MachineOperand &Dest);
bool parseJumpTableIndexOperand(MachineOperand &Dest);
bool parseExternalSymbolOperand(MachineOperand &Dest);
+ bool parseMetadataOperand(MachineOperand &Dest);
bool parseCFIOffset(int &Offset);
bool parseCFIOperand(MachineOperand &Dest);
bool parseMachineOperand(MachineOperand &Dest);
@@ -575,6 +576,23 @@ bool MIParser::parseExternalSymbolOperan
return false;
}
+bool MIParser::parseMetadataOperand(MachineOperand &Dest) {
+ assert(Token.is(MIToken::exclaim));
+ auto Loc = Token.location();
+ lex();
+ if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
+ return error("expected metadata id after '!'");
+ unsigned ID;
+ if (getUnsigned(ID))
+ return true;
+ auto NodeInfo = IRSlots.MetadataNodes.find(ID);
+ if (NodeInfo == IRSlots.MetadataNodes.end())
+ return error(Loc, "use of undefined metadata '!" + Twine(ID) + "'");
+ lex();
+ Dest = MachineOperand::CreateMetadata(NodeInfo->second.get());
+ return false;
+}
+
bool MIParser::parseCFIOffset(int &Offset) {
if (Token.isNot(MIToken::IntegerLiteral))
return error("expected a cfi offset");
@@ -628,6 +646,8 @@ bool MIParser::parseMachineOperand(Machi
case MIToken::ExternalSymbol:
case MIToken::QuotedExternalSymbol:
return parseExternalSymbolOperand(Dest);
+ case MIToken::exclaim:
+ return parseMetadataOperand(Dest);
case MIToken::kw_cfi_def_cfa_offset:
return parseCFIOperand(Dest);
case MIToken::Error:
Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=242916&r1=242915&r2=242916&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Wed Jul 22 12:58:46 2015
@@ -453,6 +453,9 @@ void MIPrinter::print(const MachineOpera
llvm_unreachable("Can't print this machine register mask yet.");
break;
}
+ case MachineOperand::MO_Metadata:
+ Op.getMetadata()->printAsOperand(OS, MST);
+ break;
case MachineOperand::MO_CFIIndex: {
const auto &MMI = Op.getParent()->getParent()->getParent()->getMMI();
print(MMI.getFrameInstructions()[Op.getCFIIndex()]);
Added: llvm/trunk/test/CodeGen/MIR/X86/expected-metadata-node-after-exclaim.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/expected-metadata-node-after-exclaim.mir?rev=242916&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/expected-metadata-node-after-exclaim.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/expected-metadata-node-after-exclaim.mir Wed Jul 22 12:58:46 2015
@@ -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]]:33: expected metadata id after '!'
+ - 'DBG_VALUE _, 0, !12, ! _'
+ - 'MOV32mr %stack.0.x.addr, 1, _, 0, _, %0'
+ - '%eax = COPY %0'
+ - 'RETQ %eax'
+...
Added: llvm/trunk/test/CodeGen/MIR/X86/metadata-operands.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/metadata-operands.mir?rev=242916&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/metadata-operands.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/metadata-operands.mir Wed Jul 22 12:58:46 2015
@@ -0,0 +1,64 @@
+# 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 metadata machine operands
+# 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: %0 = COPY %edi
+ # CHECK-NEXT: DBG_VALUE _, 0, !12, !13
+ - '%0 = COPY %edi'
+ - 'DBG_VALUE _, 0, !12, ! 13'
+ - 'MOV32mr %stack.0.x.addr, 1, _, 0, _, %0'
+ - '%eax = COPY %0'
+ - 'RETQ %eax'
+...
Added: llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-node.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-node.mir?rev=242916&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-node.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-node.mir Wed Jul 22 12:58:46 2015
@@ -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]]:26: use of undefined metadata '!42'
+ - 'DBG_VALUE _, 0, !42, !13'
+ - 'MOV32mr %stack.0.x.addr, 1, _, 0, _, %0'
+ - '%eax = COPY %0'
+ - 'RETQ %eax'
+...
More information about the llvm-commits
mailing list