[llvm-commits] [llvm] r112906 - in /llvm/trunk: test/Assembler/comment.ll tools/llvm-dis/llvm-dis.cpp

Chris Lattner sabre at nondot.org
Thu Sep 2 16:21:44 PDT 2010


Author: lattner
Date: Thu Sep  2 18:21:44 2010
New Revision: 112906

URL: http://llvm.org/viewvc/llvm-project?rev=112906&view=rev
Log:
add a new "llvm-dis -show-annotations" option, which causes it to print
#uses comments, with a testcase.

Added:
    llvm/trunk/test/Assembler/comment.ll
Modified:
    llvm/trunk/tools/llvm-dis/llvm-dis.cpp

Added: llvm/trunk/test/Assembler/comment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/comment.ll?rev=112906&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/comment.ll (added)
+++ llvm/trunk/test/Assembler/comment.ll Thu Sep  2 18:21:44 2010
@@ -0,0 +1,20 @@
+; RUN: llvm-as < %s | llvm-dis -show-annotations | FileCheck -check-prefix=ANNOT %s
+; RUN: llvm-as < %s | llvm-dis | FileCheck -check-prefix=BARE %s
+
+; The bare version of this file should not have any #uses lines.
+; BARE: @B =
+; BARE-NOT: #uses
+; BARE: }
+
+ at B = external global i32
+; ANNOT: @B = external global i32   ; [#uses=0]
+
+define <4 x i1> @foo(<4 x float> %a, <4 x float> %b) nounwind {
+entry:
+  %cmp = fcmp olt <4 x float> %a, %b              ; [#uses=1]
+  ret <4 x i1> %cmp
+}
+
+; ANNOT: %cmp = fcmp olt <4 x float> %a, %b              ; [#uses=1]
+
+

Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=112906&r1=112905&r2=112906&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Thu Sep  2 18:21:44 2010
@@ -18,8 +18,11 @@
 
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
+#include "llvm/Type.h"
 #include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Assembly/AssemblyAnnotationWriter.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/PrettyStackTrace.h"
@@ -40,6 +43,29 @@
 static cl::opt<bool>
 DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden);
 
+static cl::opt<bool>
+ShowAnnotations("show-annotations",
+                cl::desc("Add informational comments to the .ll file"));
+
+namespace {
+  
+class CommentWriter : public AssemblyAnnotationWriter {
+public:
+  void emitFunctionAnnot(const Function *F,
+                         formatted_raw_ostream &OS) {
+    OS << "; [#uses=" << F->getNumUses() << ']';  // Output # uses
+    OS << '\n';
+  }
+  void printInfoComment(const Value &V, formatted_raw_ostream &OS) {
+    if (V.getType()->isVoidTy()) return;
+      
+    OS.PadToColumn(50);
+    OS << "; [#uses=" << V.getNumUses() << ']';  // Output # uses
+  }
+};
+  
+} // end anon namespace
+
 int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
@@ -96,9 +122,13 @@
     return 1;
   }
 
+  OwningPtr<AssemblyAnnotationWriter> Annotator;
+  if (ShowAnnotations)
+    Annotator.reset(new CommentWriter());
+  
   // All that llvm-dis does is write the assembly to a file.
   if (!DontPrint)
-    Out->os() << *M;
+    M->print(Out->os(), Annotator.get());
 
   // Declare success.
   Out->keep();





More information about the llvm-commits mailing list