diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-08-17 22:05:15 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-08-17 22:05:15 +0000 |
commit | d3ff211ac735262729e59559c94dee37d40eb4db (patch) | |
tree | be51bacf164ec876e82912f44f1002039ed28f90 | |
parent | d8ea8746b1de52eea2fb41a4cb66272082788448 (diff) |
MIR Serialization: Serialize the memory operand's TBAA metadata node.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245244 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/MIRParser/MILexer.cpp | 31 | ||||
-rw-r--r-- | lib/CodeGen/MIRParser/MILexer.h | 3 | ||||
-rw-r--r-- | lib/CodeGen/MIRParser/MIParser.cpp | 28 | ||||
-rw-r--r-- | lib/CodeGen/MIRPrinter.cpp | 9 | ||||
-rw-r--r-- | test/CodeGen/MIR/X86/memory-operands.mir | 34 | ||||
-rw-r--r-- | test/CodeGen/MIR/X86/unknown-metadata-keyword.mir | 25 |
6 files changed, 119 insertions, 11 deletions
diff --git a/lib/CodeGen/MIRParser/MILexer.cpp b/lib/CodeGen/MIRParser/MILexer.cpp index f607edddecc..f4c9786d421 100644 --- a/lib/CodeGen/MIRParser/MILexer.cpp +++ b/lib/CodeGen/MIRParser/MILexer.cpp @@ -442,6 +442,33 @@ static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token) { return C; } +static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier) { + return StringSwitch<MIToken::TokenKind>(Identifier) + .Case("!tbaa", MIToken::md_tbaa) + .Default(MIToken::Error); +} + +static Cursor maybeLexExlaim( + Cursor C, MIToken &Token, + function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { + if (C.peek() != '!') + return None; + auto Range = C; + C.advance(1); + if (isdigit(C.peek()) || !isIdentifierChar(C.peek())) { + Token.reset(MIToken::exclaim, Range.upto(C)); + return C; + } + while (isIdentifierChar(C.peek())) + C.advance(); + StringRef StrVal = Range.upto(C); + Token.reset(getMetadataKeywordKind(StrVal), StrVal); + if (Token.isError()) + ErrorCallback(Token.location(), + "use of unknown metadata keyword '" + StrVal + "'"); + return C; +} + static MIToken::TokenKind symbolToken(char C) { switch (C) { case ',': @@ -450,8 +477,6 @@ static MIToken::TokenKind symbolToken(char C) { return MIToken::equal; case ':': return MIToken::colon; - case '!': - return MIToken::exclaim; case '(': return MIToken::lparen; case ')': @@ -531,6 +556,8 @@ StringRef llvm::lexMIToken( return R.remaining(); if (Cursor R = maybeLexNumericalLiteral(C, Token)) return R.remaining(); + if (Cursor R = maybeLexExlaim(C, Token, ErrorCallback)) + return R.remaining(); if (Cursor R = maybeLexSymbol(C, Token)) return R.remaining(); if (Cursor R = maybeLexNewline(C, Token)) diff --git a/lib/CodeGen/MIRParser/MILexer.h b/lib/CodeGen/MIRParser/MILexer.h index 747e6523e4b..fc92cc14e89 100644 --- a/lib/CodeGen/MIRParser/MILexer.h +++ b/lib/CodeGen/MIRParser/MILexer.h @@ -85,6 +85,9 @@ struct MIToken { kw_liveins, kw_successors, + // Named metadata keywords + md_tbaa, + // Identifier tokens Identifier, IntegerType, diff --git a/lib/CodeGen/MIRParser/MIParser.cpp b/lib/CodeGen/MIRParser/MIParser.cpp index c6383720e23..e076a2d5b5e 100644 --- a/lib/CodeGen/MIRParser/MIParser.cpp +++ b/lib/CodeGen/MIRParser/MIParser.cpp @@ -1526,17 +1526,29 @@ bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) { if (parseMachinePointerInfo(Ptr)) return true; unsigned BaseAlignment = Size; - if (Token.is(MIToken::comma)) { - lex(); - if (Token.isNot(MIToken::kw_align)) - return error("expected 'align'"); - if (parseAlignment(BaseAlignment)) - return true; + AAMDNodes AAInfo; + while (consumeIfPresent(MIToken::comma)) { + switch (Token.kind()) { + case MIToken::kw_align: + if (parseAlignment(BaseAlignment)) + return true; + break; + case MIToken::md_tbaa: + lex(); + if (parseMDNode(AAInfo.TBAA)) + return true; + break; + // TODO: Parse AA Scope metadata. + // TODO: Parse AA NoAlias metadata. + // TODO: Parse the ranges metadata. + // TODO: Report an error on duplicate metadata nodes. + default: + return error("expected 'align' or '!tbaa'"); + } } - // TODO: Parse the attached metadata nodes. if (expectAndConsume(MIToken::rparen)) return true; - Dest = MF.getMachineMemOperand(Ptr, Flags, Size, BaseAlignment); + Dest = MF.getMachineMemOperand(Ptr, Flags, Size, BaseAlignment, AAInfo); return false; } diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index 248db52790e..b7292f3e151 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -777,7 +777,14 @@ void MIPrinter::print(const MachineMemOperand &Op) { printOffset(Op.getOffset()); if (Op.getBaseAlignment() != Op.getSize()) OS << ", align " << Op.getBaseAlignment(); - // TODO: Print the metadata attributes. + auto AAInfo = Op.getAAInfo(); + if (AAInfo.TBAA) { + OS << ", !tbaa "; + AAInfo.TBAA->printAsOperand(OS, MST); + } + // TODO: Print AA Scope metadata. + // TODO: Print AA NoAlias metadata. + // TODO: Print the ranges metadata. OS << ')'; } diff --git a/test/CodeGen/MIR/X86/memory-operands.mir b/test/CodeGen/MIR/X86/memory-operands.mir index 7b4d60b0044..0a3f13a9ab8 100644 --- a/test/CodeGen/MIR/X86/memory-operands.mir +++ b/test/CodeGen/MIR/X86/memory-operands.mir @@ -111,6 +111,27 @@ ret i32 8 } + %struct.XXH_state64_t = type { i32, i32, i64, i64, i64 } + + @a = common global i32 0, align 4 + + define i32 @tbaa_metadata() { + entry: + %0 = load i32, i32* @a, align 4, !tbaa !2 + %1 = inttoptr i32 %0 to %struct.XXH_state64_t* + %total_len2 = bitcast %struct.XXH_state64_t* %1 to i32* + %2 = load i32, i32* %total_len2, align 4, !tbaa !6 + ret i32 %2 + } + + !2 = !{!3, !3, i64 0} + !3 = !{!"int", !4, i64 0} + !4 = !{!"omnipotent char", !5, i64 0} + !5 = !{!"Simple C/C++ TBAA"} + !6 = !{!7, !3, i64 0} + !7 = !{!"XXH_state64_t", !3, i64 0, !3, i64 4, !8, i64 8, !8, i64 16, !8, i64 24} + !8 = !{!"long long", !4, i64 0} + ... --- name: test @@ -338,3 +359,16 @@ body: | %eax = MOV32ri 8 RETQ %eax ... +--- +name: tbaa_metadata +tracksRegLiveness: true +body: | + bb.0.entry: + %rax = MOV64rm %rip, 1, _, @a, _ :: (load 8 from got) + ; CHECK-LABEL: name: tbaa_metadata + ; CHECK: %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from %ir.a, !tbaa !2) + ; CHECK-NEXT: %eax = MOV32rm killed %rax, 1, _, 0, _ :: (load 4 from %ir.total_len2, !tbaa !6) + %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from %ir.a, !tbaa !2) + %eax = MOV32rm killed %rax, 1, _, 0, _ :: (load 4 from %ir.total_len2, !tbaa !6) + RETQ %eax +... diff --git a/test/CodeGen/MIR/X86/unknown-metadata-keyword.mir b/test/CodeGen/MIR/X86/unknown-metadata-keyword.mir new file mode 100644 index 00000000000..c58c38ab132 --- /dev/null +++ b/test/CodeGen/MIR/X86/unknown-metadata-keyword.mir @@ -0,0 +1,25 @@ +# RUN: not llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s + +--- | + define i32 @inc(i32* %x) { + entry: + %0 = load i32, i32* %x + %1 = add i32 %0, 1 + store i32 %1, i32* %x + ret i32 %1 + } +... +--- +name: inc +tracksRegLiveness: true +liveins: + - { reg: '%rdi' } +body: | + bb.0.entry: + liveins: %rdi + ; CHECK: [[@LINE+1]]:60: use of unknown metadata keyword '!tba' + %eax = MOV32rm %rdi, 1, _, 0, _ :: (load 4 from %ir.x, !tba !0) + %eax = INC32r killed %eax, implicit-def dead %eflags + MOV32mr killed %rdi, 1, _, 0, _, %eax :: (store 4 into %ir.x) + RETQ %eax +... |