[llvm] r245244 - MIR Serialization: Serialize the memory operand's TBAA metadata node.

Alex Lorenz via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 15:05:15 PDT 2015


Author: arphaman
Date: Mon Aug 17 17:05:15 2015
New Revision: 245244

URL: http://llvm.org/viewvc/llvm-project?rev=245244&view=rev
Log:
MIR Serialization: Serialize the memory operand's TBAA metadata node.

Added:
    llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-keyword.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
    llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir

Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp?rev=245244&r1=245243&r2=245244&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp Mon Aug 17 17:05:15 2015
@@ -442,6 +442,33 @@ static Cursor maybeLexNumericalLiteral(C
   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(ch
     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))

Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.h?rev=245244&r1=245243&r2=245244&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.h (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.h Mon Aug 17 17:05:15 2015
@@ -85,6 +85,9 @@ struct MIToken {
     kw_liveins,
     kw_successors,
 
+    // Named metadata keywords
+    md_tbaa,
+
     // Identifier tokens
     Identifier,
     IntegerType,

Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=245244&r1=245243&r2=245244&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Mon Aug 17 17:05:15 2015
@@ -1526,17 +1526,29 @@ bool MIParser::parseMachineMemoryOperand
   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;
 }
 

Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=245244&r1=245243&r2=245244&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Mon Aug 17 17:05:15 2015
@@ -777,7 +777,14 @@ void MIPrinter::print(const MachineMemOp
   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 << ')';
 }
 

Modified: llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir?rev=245244&r1=245243&r2=245244&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir Mon Aug 17 17:05:15 2015
@@ -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
+...

Added: llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-keyword.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-keyword.mir?rev=245244&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-keyword.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/unknown-metadata-keyword.mir Mon Aug 17 17:05:15 2015
@@ -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
+...




More information about the llvm-commits mailing list