[PATCH] Emit Clang version information into .comment section (LLVM's part of implementation) [PART 2]

Katya Romanova Katya_Romanova at playstation.sony.com
Mon Sep 30 14:24:21 PDT 2013


  By Rafael's request, the main patch was split into 2 parts:
  CodeGen and MC. This patch is a CodeGen part of the fix. It needs to be applied after MC part.

http://llvm-reviews.chandlerc.com/D1729

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1729?vs=4555&id=4556#toc

Files:
  test/CodeGen/X86/ident-metadata.ll
  include/llvm/CodeGen/AsmPrinter.h
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Index: test/CodeGen/X86/ident-metadata.ll
===================================================================
--- test/CodeGen/X86/ident-metadata.ll
+++ test/CodeGen/X86/ident-metadata.ll
@@ -0,0 +1,19 @@
+; RUN: llc -march=x86 < %s | FileCheck %s
+; RUN: llc -march=x86 -filetype=obj -o %t < %s
+; RUN: llvm-readobj -s -sd  %t | FileCheck %s -check-prefix=OBJ
+; Verify that llvm.ident metadata is emitted as .ident
+; directives in assembly files, and in the .comment section in ELF object files.
+
+; CHECK: .ident  "clang version x.x"
+; CHECK-NEXT: .ident  "something else"
+; CHECK-NEXT: .ident  "plus another"
+
+; OBJ: Name: .comment (7)
+; OBJ: SectionData (
+; OBJ-NEXT: 0000: 00636C61 6E672076 65727369 6F6E2078
+; OBJ-NEXT: 0010: 2E780073 6F6D6574 68696E67 20656C73
+; OBJ-NEXT: 0020: 6500706C 75732061 6E6F7468 657200
+!llvm.ident = !{!0, !1, !2}
+!0 = metadata !{metadata !"clang version x.x"}
+!1 = metadata !{metadata !"something else", metadata !"plus another"}
+!2 = metadata !{i32 1}
Index: include/llvm/CodeGen/AsmPrinter.h
===================================================================
--- include/llvm/CodeGen/AsmPrinter.h
+++ include/llvm/CodeGen/AsmPrinter.h
@@ -487,6 +487,8 @@
                             const MachineBasicBlock *MBB,
                             unsigned uid) const;
     void EmitLLVMUsedList(const ConstantArray *InitList);
+    /// EmitModuleIdents - Emit llvm.ident metadata in an '.ident' directive.
+    void EmitModuleIdents(Module &M);
     void EmitXXStructorList(const Constant *List, bool isCtor);
     GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
   };
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -953,6 +953,9 @@
     if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
       MP->finishAssembly(*this);
 
+  // Emit llvm.ident metadata in an '.ident' directive.
+  EmitModuleIdents(M);
+
   // If we don't have any trampolines, then we don't require stack memory
   // to be executable. Some targets have a directive to declare this.
   Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
@@ -1332,6 +1335,21 @@
   }
 }
 
+void AsmPrinter::EmitModuleIdents(Module &M) {
+  if (!MAI->hasIdentDirective())
+    return;
+
+  if (const NamedMDNode *NMD = M.getNamedMetadata("llvm.ident")) {
+    for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
+      const MDNode *N = NMD->getOperand(i);
+      for (unsigned j = 0, ee = N->getNumOperands(); j != ee; ++j) {
+        if (const MDString *S = dyn_cast<MDString>(N->getOperand(j)))
+          OutStreamer.EmitIdent(S->getString());
+      }
+    }
+  }
+}
+
 //===--------------------------------------------------------------------===//
 // Emission and print routines
 //
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1729.3.patch
Type: text/x-patch
Size: 2891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130930/f0c2a994/attachment.bin>


More information about the llvm-commits mailing list