- cl::ParseCommandLineOptions(argc, argv, " llvm profile dump decoder\n");
-
- // Read in the bytecode file...
- std::string ErrorMessage;
- Module *M = ParseBytecodeFile(BytecodeFile, &ErrorMessage);
- if (M == 0) {
- std::cerr << argv[0] << ": " << BytecodeFile << ": " << ErrorMessage
- << "\n";
- return 1;
- }
-
- // Read the profiling information
- ProfileInfo PI(argv[0], ProfileDataFile, *M);
-
- std::map<const Function *, unsigned> FuncFreqs;
- std::map<const BasicBlock*, unsigned> BlockFreqs;
-
- // Output a report. Eventually, there will be multiple reports selectable on
- // the command line, for now, just keep things simple.
-
- // Emit the most frequent function table...
- std::vector<std::pair<Function*, unsigned> > FunctionCounts;
- PI.getFunctionCounts(FunctionCounts);
- FuncFreqs.insert(FunctionCounts.begin(), FunctionCounts.end());
-
- // Sort by the frequency, backwards.
- std::sort(FunctionCounts.begin(), FunctionCounts.end(),
- PairSecondSortReverse<Function*>());
-
- unsigned long long TotalExecutions = 0;
- for (unsigned i = 0, e = FunctionCounts.size(); i != e; ++i)
- TotalExecutions += FunctionCounts[i].second;
-
- std::cout << "===" << std::string(73, '-') << "===\n"
- << "LLVM profiling output for execution";
- if (PI.getNumExecutions() != 1) std::cout << "s";
- std::cout << ":\n";
-
- for (unsigned i = 0, e = PI.getNumExecutions(); i != e; ++i) {
- std::cout << " ";
- if (e != 1) std::cout << i+1 << ". ";
- std::cout << PI.getExecution(i) << "\n";
- }
-
- std::cout << "\n===" << std::string(73, '-') << "===\n";
- std::cout << "Function execution frequencies:\n\n";
-
- // Print out the function frequencies...
- printf(" ## Frequency\n");
- for (unsigned i = 0, e = FunctionCounts.size(); i != e; ++i) {
- if (FunctionCounts[i].second == 0) {
- printf("\n NOTE: %d function%s never executed!\n",
- e-i, e-i-1 ? "s were" : " was");
- break;
+ llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ try {
+ cl::ParseCommandLineOptions(argc, argv, " llvm profile dump decoder\n");
+ sys::PrintStackTraceOnErrorSignal();
+
+ // Read in the bytecode file...
+ std::string ErrorMessage;
+ Module *M = 0;
+ if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BytecodeFile,
+ &ErrorMessage)) {
+ M = ParseBitcodeFile(Buffer, &ErrorMessage);
+ delete Buffer;
+ }
+ if (M == 0) {
+ std::cerr << argv[0] << ": " << BytecodeFile << ": "
+ << ErrorMessage << "\n";
+ return 1;