From 6cd71f0c4026217a501e09dcc2198c6c7a462e44 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 2 Sep 2010 23:21:44 +0000 Subject: [PATCH] add a new "llvm-dis -show-annotations" option, which causes it to print #uses comments, with a testcase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112906 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Assembler/comment.ll | 20 ++++++++++++++++++++ tools/llvm-dis/llvm-dis.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/Assembler/comment.ll diff --git a/test/Assembler/comment.ll b/test/Assembler/comment.ll new file mode 100644 index 00000000000..fe23d26fbeb --- /dev/null +++ b/test/Assembler/comment.ll @@ -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: } + +@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] + + diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 9d36f1055c8..9d2d31da164 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -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 @@ Force("f", cl::desc("Enable binary output on terminals")); static cl::opt DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden); +static cl::opt +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 @@ int main(int argc, char **argv) { return 1; } + OwningPtr 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();