summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-06 04:43:00 +0000
committerChris Lattner <sabre@nondot.org>2007-05-06 04:43:00 +0000
commitc424ba7ebda75f912c36b4b05a452872eba4198f (patch)
treef81c694f86408fcb82c37f0b2c63d70ab0b2e9e3
parent7284541754f2504b841b35c75278cfb78d5df1ca (diff)
downloadbcm5719-llvm-c424ba7ebda75f912c36b4b05a452872eba4198f.tar.gz
bcm5719-llvm-c424ba7ebda75f912c36b4b05a452872eba4198f.zip
add support to llvm-prof for reading from a bitcode file
llvm-svn: 36836
-rw-r--r--llvm/tools/llvm-prof/Makefile2
-rw-r--r--llvm/tools/llvm-prof/llvm-prof.cpp20
-rw-r--r--llvm/tools/opt/opt.cpp8
3 files changed, 20 insertions, 10 deletions
diff --git a/llvm/tools/llvm-prof/Makefile b/llvm/tools/llvm-prof/Makefile
index b745e654927..72e2bcf184b 100644
--- a/llvm/tools/llvm-prof/Makefile
+++ b/llvm/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/llvm/tools/llvm-prof/llvm-prof.cpp b/llvm/tools/llvm-prof/llvm-prof.cpp
index 6b1d514bcd6..7b1e2922533 100644
--- a/llvm/tools/llvm-prof/llvm-prof.cpp
+++ b/llvm/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";
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index 6c770858930..218e5f0b1de 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -268,12 +268,8 @@ int main(int argc, char **argv) {
// Load the input module...
std::auto_ptr<Module> M;
if (Bitcode) {
- MemoryBuffer *Buffer;
- if (InputFilename == "-") {
- Buffer = MemoryBuffer::getSTDIN();
- } else {
- Buffer = MemoryBuffer::getFile(&InputFilename[0], InputFilename.size());
- }
+ MemoryBuffer *Buffer
+ = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size());
if (Buffer == 0)
ErrorMessage = "Error reading file '" + InputFilename + "'";
OpenPOWER on IntegriCloud