diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-06 04:43:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-06 04:43:00 +0000 |
commit | 592488a4ef92ce8e454dc029808ed1b6612b7312 (patch) | |
tree | f4de499ba43831ac16bc1714d6e723336861a2dd /tools/llvm-prof | |
parent | e96eec0c6966473ed8f71ecf4d2dd37daec29d36 (diff) |
add support to llvm-prof for reading from a bitcode file
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36836 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-prof')
-rw-r--r-- | tools/llvm-prof/Makefile | 2 | ||||
-rw-r--r-- | tools/llvm-prof/llvm-prof.cpp | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/tools/llvm-prof/Makefile b/tools/llvm-prof/Makefile index b745e65492..72e2bcf184 100644 --- a/tools/llvm-prof/Makefile +++ b/tools/llvm-prof/Makefile @@ -9,7 +9,7 @@ LEVEL = ../.. TOOLNAME = llvm-prof -LINK_COMPONENTS = bcreader analysis +LINK_COMPONENTS = bcreader bitreader analysis REQUIRES_EH := 1 include $(LEVEL)/Makefile.common diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp index 6b1d514bcd..7b1e292253 100644 --- a/tools/llvm-prof/llvm-prof.cpp +++ b/tools/llvm-prof/llvm-prof.cpp @@ -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 @@ int main(int argc, char **argv) { // 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"; |