[llvm-commits] CVS: llvm/tools/llvm-prof/Makefile llvm-prof.cpp

Chris Lattner sabre at nondot.org
Sat May 5 21:43:23 PDT 2007



Changes in directory llvm/tools/llvm-prof:

Makefile updated: 1.9 -> 1.10
llvm-prof.cpp updated: 1.31 -> 1.32
---
Log message:

add support to llvm-prof for reading from a bitcode file


---
Diffs of the changes:  (+18 -4)

 Makefile      |    2 +-
 llvm-prof.cpp |   20 +++++++++++++++++---
 2 files changed, 18 insertions(+), 4 deletions(-)


Index: llvm/tools/llvm-prof/Makefile
diff -u llvm/tools/llvm-prof/Makefile:1.9 llvm/tools/llvm-prof/Makefile:1.10
--- llvm/tools/llvm-prof/Makefile:1.9	Mon Sep  4 00:59:09 2006
+++ llvm/tools/llvm-prof/Makefile	Sat May  5 23:43:00 2007
@@ -9,7 +9,7 @@
 LEVEL = ../..
 
 TOOLNAME = llvm-prof
-LINK_COMPONENTS = bcreader analysis
+LINK_COMPONENTS = bcreader bitreader analysis
 REQUIRES_EH := 1
 
 include $(LEVEL)/Makefile.common


Index: llvm/tools/llvm-prof/llvm-prof.cpp
diff -u llvm/tools/llvm-prof/llvm-prof.cpp:1.31 llvm/tools/llvm-prof/llvm-prof.cpp:1.32
--- llvm/tools/llvm-prof/llvm-prof.cpp:1.31	Sun Mar  4 18:00:42 2007
+++ llvm/tools/llvm-prof/llvm-prof.cpp	Sat May  5 23:43:00 2007
@@ -18,8 +18,10 @@
 #include "llvm/Assembly/AsmAnnotationWriter.h"
 #include "llvm/Analysis/ProfileInfoLoader.h"
 #include "llvm/Bytecode/Reader.h"
+#include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/System/Signals.h"
 #include <algorithm>
 #include <iostream>
@@ -30,6 +32,7 @@
 using namespace llvm;
 
 namespace {
+  cl::opt<bool> Bitcode("bitcode");
   cl::opt<std::string>
   BytecodeFile(cl::Positional, cl::desc("<program bytecode file>"),
                cl::Required);
@@ -116,9 +119,20 @@
 
     // Read in the bytecode file...
     std::string ErrorMessage;
-    Module *M = ParseBytecodeFile(BytecodeFile, 
-                                  Compressor::decompressToNewBuffer, 
-                                  &ErrorMessage);
+    Module *M;
+    if (Bitcode) {
+      MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&BytecodeFile[0],
+                                                          BytecodeFile.size());
+      if (Buffer == 0)
+        ErrorMessage = "Error reading file '" + BytecodeFile + "'";
+      else
+        M = ParseBitcodeFile(Buffer, &ErrorMessage);
+      delete Buffer;
+    } else {
+      M = ParseBytecodeFile(BytecodeFile, 
+                            Compressor::decompressToNewBuffer, 
+                            &ErrorMessage);
+    }
     if (M == 0) {
       std::cerr << argv[0] << ": " << BytecodeFile << ": " 
         << ErrorMessage << "\n";






More information about the llvm-commits mailing list