Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 1 | //===- llvm-prof.cpp - Read in and process llvmprof.out data files --------===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 21c62da | 2007-12-29 20:44:31 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This tools is meant for use with the various LLVM profiling instrumentation |
| 11 | // passes. It reads in the data file produced by executing an instrumented |
| 12 | // program, and outputs a nice report. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Chris Lattner | 8c2730e | 2004-03-08 20:04:32 +0000 | [diff] [blame] | 16 | #include "llvm/InstrTypes.h" |
Owen Anderson | 8b477ed | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 17 | #include "llvm/LLVMContext.h" |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 19 | #include "llvm/PassManager.h" |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 20 | #include "llvm/Assembly/AsmAnnotationWriter.h" |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/ProfileInfo.h" |
Chris Lattner | 89cf393 | 2004-02-11 05:56:07 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/ProfileInfoLoader.h" |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/Passes.h" |
Chris Lattner | 592488a | 2007-05-06 04:43:00 +0000 | [diff] [blame] | 24 | #include "llvm/Bitcode/ReaderWriter.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 25 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | c30598b | 2006-12-06 01:18:01 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ManagedStatic.h" |
Chris Lattner | 592488a | 2007-05-06 04:43:00 +0000 | [diff] [blame] | 27 | #include "llvm/Support/MemoryBuffer.h" |
Chris Lattner | cc14d25 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 28 | #include "llvm/Support/PrettyStackTrace.h" |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | bed85ff | 2004-05-27 05:41:36 +0000 | [diff] [blame] | 30 | #include "llvm/System/Signals.h" |
Jeff Cohen | ca5183d | 2007-03-05 00:00:42 +0000 | [diff] [blame] | 31 | #include <algorithm> |
Reid Spencer | 86f42bd | 2004-07-04 12:20:55 +0000 | [diff] [blame] | 32 | #include <iostream> |
Reid Spencer | 78b0e6a | 2005-12-29 21:13:45 +0000 | [diff] [blame] | 33 | #include <iomanip> |
Chris Lattner | 33f1ca7 | 2003-10-28 21:25:23 +0000 | [diff] [blame] | 34 | #include <map> |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 35 | #include <set> |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 36 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 37 | using namespace llvm; |
| 38 | |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 39 | namespace { |
Reid Spencer | 1adc3de | 2005-12-30 09:07:29 +0000 | [diff] [blame] | 40 | cl::opt<std::string> |
Gabor Greif | a99be51 | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 41 | BitcodeFile(cl::Positional, cl::desc("<program bitcode file>"), |
| 42 | cl::Required); |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 43 | |
Reid Spencer | 1adc3de | 2005-12-30 09:07:29 +0000 | [diff] [blame] | 44 | cl::opt<std::string> |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 45 | ProfileDataFile(cl::Positional, cl::desc("<llvmprof.out file>"), |
| 46 | cl::Optional, cl::init("llvmprof.out")); |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 47 | |
| 48 | cl::opt<bool> |
| 49 | PrintAnnotatedLLVM("annotated-llvm", |
| 50 | cl::desc("Print LLVM code with frequency annotations")); |
| 51 | cl::alias PrintAnnotated2("A", cl::desc("Alias for --annotated-llvm"), |
| 52 | cl::aliasopt(PrintAnnotatedLLVM)); |
Chris Lattner | cde1cf3 | 2003-11-06 20:29:25 +0000 | [diff] [blame] | 53 | cl::opt<bool> |
| 54 | PrintAllCode("print-all-code", |
| 55 | cl::desc("Print annotated code for the entire program")); |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Chris Lattner | 7a78d81 | 2003-10-28 21:08:18 +0000 | [diff] [blame] | 58 | // PairSecondSort - A sorting predicate to sort by the second element of a pair. |
| 59 | template<class T> |
Chris Lattner | 18884a8 | 2003-10-29 21:41:17 +0000 | [diff] [blame] | 60 | struct PairSecondSortReverse |
Reid Spencer | 1adc3de | 2005-12-30 09:07:29 +0000 | [diff] [blame] | 61 | : public std::binary_function<std::pair<T, unsigned>, |
| 62 | std::pair<T, unsigned>, bool> { |
| 63 | bool operator()(const std::pair<T, unsigned> &LHS, |
| 64 | const std::pair<T, unsigned> &RHS) const { |
Chris Lattner | 18884a8 | 2003-10-29 21:41:17 +0000 | [diff] [blame] | 65 | return LHS.second > RHS.second; |
Chris Lattner | 7a78d81 | 2003-10-28 21:08:18 +0000 | [diff] [blame] | 66 | } |
| 67 | }; |
| 68 | |
Daniel Dunbar | caaa493 | 2009-08-08 17:43:09 +0000 | [diff] [blame^] | 69 | static double ignoreMissing(double w) { |
| 70 | if (w == ProfileInfo::MissingValue) return 0; |
| 71 | return w; |
| 72 | } |
| 73 | |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 74 | namespace { |
| 75 | class ProfileAnnotator : public AssemblyAnnotationWriter { |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 76 | ProfileInfo &PI; |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 77 | public: |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 78 | ProfileAnnotator(ProfileInfo& pi) : PI(pi) {} |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 79 | |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 80 | virtual void emitFunctionAnnot(const Function *F, raw_ostream &OS) { |
Daniel Dunbar | caaa493 | 2009-08-08 17:43:09 +0000 | [diff] [blame^] | 81 | OS << ";;; %" << F->getName() << " called "; |
| 82 | double w = PI.getExecutionCount(F); |
| 83 | if (w == ProfileInfo::MissingValue) |
| 84 | OS << "(no value)"; |
| 85 | else |
| 86 | OS << (unsigned)w; |
| 87 | OS << " times.\n;;;\n"; |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 88 | } |
Chris Lattner | 8c2730e | 2004-03-08 20:04:32 +0000 | [diff] [blame] | 89 | virtual void emitBasicBlockStartAnnot(const BasicBlock *BB, |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 90 | raw_ostream &OS) { |
Daniel Dunbar | caaa493 | 2009-08-08 17:43:09 +0000 | [diff] [blame^] | 91 | double w = PI.getExecutionCount(BB); |
| 92 | if (w == ProfileInfo::MissingValue) |
| 93 | OS << "\t;;; (no value)\n"; |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 94 | else |
Daniel Dunbar | caaa493 | 2009-08-08 17:43:09 +0000 | [diff] [blame^] | 95 | if (w != 0) |
| 96 | OS << "\t;;; Basic block executed " << w << " times.\n"; |
| 97 | else |
| 98 | OS << "\t;;; Never executed!\n"; |
Chris Lattner | 8c2730e | 2004-03-08 20:04:32 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 101 | virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, raw_ostream &OS) { |
Chris Lattner | 8c2730e | 2004-03-08 20:04:32 +0000 | [diff] [blame] | 102 | // Figure out how many times each successor executed. |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 103 | std::vector<std::pair<ProfileInfo::Edge, unsigned> > SuccCounts; |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 104 | |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 105 | const TerminatorInst *TI = BB->getTerminator(); |
| 106 | for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) { |
| 107 | BasicBlock* Succ = TI->getSuccessor(s); |
Daniel Dunbar | caaa493 | 2009-08-08 17:43:09 +0000 | [diff] [blame^] | 108 | double w = ignoreMissing(PI.getEdgeWeight(std::make_pair(BB,Succ))); |
| 109 | SuccCounts.push_back(std::make_pair(std::make_pair(BB,Succ), w)); |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 110 | } |
Chris Lattner | 8c2730e | 2004-03-08 20:04:32 +0000 | [diff] [blame] | 111 | if (!SuccCounts.empty()) { |
| 112 | OS << "\t;;; Out-edge counts:"; |
| 113 | for (unsigned i = 0, e = SuccCounts.size(); i != e; ++i) |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 114 | OS << " [" << (SuccCounts[i]).second << " -> " |
| 115 | << (SuccCounts[i]).first.second->getName() << "]"; |
Chris Lattner | 8c2730e | 2004-03-08 20:04:32 +0000 | [diff] [blame] | 116 | OS << "\n"; |
| 117 | } |
Chris Lattner | 5e71764 | 2003-10-30 23:42:09 +0000 | [diff] [blame] | 118 | } |
| 119 | }; |
| 120 | } |
| 121 | |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 122 | namespace { |
| 123 | /// ProfileInfoPrinterPass - Helper pass to dump the profile information for |
| 124 | /// a module. |
| 125 | // |
| 126 | // FIXME: This should move elsewhere. |
| 127 | class ProfileInfoPrinterPass : public ModulePass { |
| 128 | ProfileInfoLoader &PIL; |
| 129 | public: |
| 130 | static char ID; // Class identification, replacement for typeinfo. |
| 131 | explicit ProfileInfoPrinterPass(ProfileInfoLoader &_PIL) |
| 132 | : ModulePass(&ID), PIL(_PIL) {} |
| 133 | |
| 134 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 135 | AU.setPreservesAll(); |
| 136 | AU.addRequired<ProfileInfo>(); |
| 137 | } |
| 138 | |
| 139 | bool runOnModule(Module &M); |
| 140 | }; |
| 141 | } |
| 142 | |
| 143 | char ProfileInfoPrinterPass::ID = 0; |
| 144 | |
| 145 | bool ProfileInfoPrinterPass::runOnModule(Module &M) { |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 146 | ProfileInfo &PI = getAnalysis<ProfileInfo>(); |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 147 | std::map<const Function *, unsigned> FuncFreqs; |
| 148 | std::map<const BasicBlock*, unsigned> BlockFreqs; |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 149 | std::map<ProfileInfo::Edge, unsigned> EdgeFreqs; |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 150 | |
| 151 | // Output a report. Eventually, there will be multiple reports selectable on |
| 152 | // the command line, for now, just keep things simple. |
| 153 | |
| 154 | // Emit the most frequent function table... |
| 155 | std::vector<std::pair<Function*, unsigned> > FunctionCounts; |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 156 | std::vector<std::pair<BasicBlock*, unsigned> > Counts; |
| 157 | for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) { |
Daniel Dunbar | c9008c5 | 2009-08-05 21:51:16 +0000 | [diff] [blame] | 158 | if (FI->isDeclaration()) continue; |
Daniel Dunbar | caaa493 | 2009-08-08 17:43:09 +0000 | [diff] [blame^] | 159 | double w = ignoreMissing(PI.getExecutionCount(FI)); |
| 160 | FunctionCounts.push_back(std::make_pair(FI,w)); |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 161 | for (Function::iterator BB = FI->begin(), BBE = FI->end(); |
| 162 | BB != BBE; ++BB) { |
Daniel Dunbar | caaa493 | 2009-08-08 17:43:09 +0000 | [diff] [blame^] | 163 | double w = ignoreMissing(PI.getExecutionCount(BB)); |
| 164 | Counts.push_back(std::make_pair(BB,w)); |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 167 | |
| 168 | // Sort by the frequency, backwards. |
| 169 | sort(FunctionCounts.begin(), FunctionCounts.end(), |
| 170 | PairSecondSortReverse<Function*>()); |
| 171 | |
| 172 | uint64_t TotalExecutions = 0; |
| 173 | for (unsigned i = 0, e = FunctionCounts.size(); i != e; ++i) |
| 174 | TotalExecutions += FunctionCounts[i].second; |
| 175 | |
| 176 | std::cout << "===" << std::string(73, '-') << "===\n" |
| 177 | << "LLVM profiling output for execution"; |
| 178 | if (PIL.getNumExecutions() != 1) std::cout << "s"; |
| 179 | std::cout << ":\n"; |
| 180 | |
| 181 | for (unsigned i = 0, e = PIL.getNumExecutions(); i != e; ++i) { |
| 182 | std::cout << " "; |
| 183 | if (e != 1) std::cout << i+1 << ". "; |
| 184 | std::cout << PIL.getExecution(i) << "\n"; |
| 185 | } |
| 186 | |
| 187 | std::cout << "\n===" << std::string(73, '-') << "===\n"; |
| 188 | std::cout << "Function execution frequencies:\n\n"; |
| 189 | |
| 190 | // Print out the function frequencies... |
| 191 | std::cout << " ## Frequency\n"; |
| 192 | for (unsigned i = 0, e = FunctionCounts.size(); i != e; ++i) { |
| 193 | if (FunctionCounts[i].second == 0) { |
| 194 | std::cout << "\n NOTE: " << e-i << " function" << |
| 195 | (e-i-1 ? "s were" : " was") << " never executed!\n"; |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | std::cout << std::setw(3) << i+1 << ". " |
| 200 | << std::setw(5) << FunctionCounts[i].second << "/" |
| 201 | << TotalExecutions << " " |
Daniel Dunbar | d5b385c | 2009-07-25 00:43:31 +0000 | [diff] [blame] | 202 | << FunctionCounts[i].first->getNameStr() << "\n"; |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | std::set<Function*> FunctionsToPrint; |
| 206 | |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 207 | TotalExecutions = 0; |
| 208 | for (unsigned i = 0, e = Counts.size(); i != e; ++i) |
| 209 | TotalExecutions += Counts[i].second; |
| 210 | |
| 211 | // Sort by the frequency, backwards. |
| 212 | sort(Counts.begin(), Counts.end(), |
| 213 | PairSecondSortReverse<BasicBlock*>()); |
| 214 | |
| 215 | std::cout << "\n===" << std::string(73, '-') << "===\n"; |
| 216 | std::cout << "Top 20 most frequently executed basic blocks:\n\n"; |
| 217 | |
| 218 | // Print out the function frequencies... |
| 219 | std::cout <<" ## %% \tFrequency\n"; |
| 220 | unsigned BlocksToPrint = Counts.size(); |
| 221 | if (BlocksToPrint > 20) BlocksToPrint = 20; |
| 222 | for (unsigned i = 0; i != BlocksToPrint; ++i) { |
| 223 | if (Counts[i].second == 0) break; |
| 224 | Function *F = Counts[i].first->getParent(); |
| 225 | std::cout << std::setw(3) << i+1 << ". " |
Daniel Dunbar | c9008c5 | 2009-08-05 21:51:16 +0000 | [diff] [blame] | 226 | << std::setw(5) << std::setprecision(3) |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 227 | << Counts[i].second/(double)TotalExecutions*100 << "% " |
| 228 | << std::setw(5) << Counts[i].second << "/" |
| 229 | << TotalExecutions << "\t" |
| 230 | << F->getNameStr() << "() - " |
| 231 | << Counts[i].first->getNameStr() << "\n"; |
| 232 | FunctionsToPrint.insert(F); |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | if (PrintAnnotatedLLVM || PrintAllCode) { |
| 236 | std::cout << "\n===" << std::string(73, '-') << "===\n"; |
| 237 | std::cout << "Annotated LLVM code for the module:\n\n"; |
Daniel Dunbar | ee16638 | 2009-08-05 15:55:56 +0000 | [diff] [blame] | 238 | |
| 239 | ProfileAnnotator PA(PI); |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 240 | |
| 241 | if (FunctionsToPrint.empty() || PrintAllCode) |
| 242 | M.print(std::cout, &PA); |
| 243 | else |
| 244 | // Print just a subset of the functions. |
| 245 | for (std::set<Function*>::iterator I = FunctionsToPrint.begin(), |
| 246 | E = FunctionsToPrint.end(); I != E; ++I) |
| 247 | (*I)->print(std::cout, &PA); |
| 248 | } |
| 249 | |
| 250 | return false; |
| 251 | } |
Chris Lattner | 7a78d81 | 2003-10-28 21:08:18 +0000 | [diff] [blame] | 252 | |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 253 | int main(int argc, char **argv) { |
Chris Lattner | cc14d25 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 254 | // Print a stack trace if we signal out. |
| 255 | sys::PrintStackTraceOnErrorSignal(); |
| 256 | PrettyStackTraceProgram X(argc, argv); |
Owen Anderson | 8b477ed | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 257 | |
Owen Anderson | 0d7c695 | 2009-07-15 22:16:10 +0000 | [diff] [blame] | 258 | LLVMContext &Context = getGlobalContext(); |
Chris Lattner | cc14d25 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 259 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 260 | try { |
Dan Gohman | 82a13c9 | 2007-10-08 15:45:12 +0000 | [diff] [blame] | 261 | cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n"); |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 262 | |
Gabor Greif | a99be51 | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 263 | // Read in the bitcode file... |
Reid Spencer | 1adc3de | 2005-12-30 09:07:29 +0000 | [diff] [blame] | 264 | std::string ErrorMessage; |
Reid Spencer | 295b1ce | 2007-05-07 18:50:07 +0000 | [diff] [blame] | 265 | Module *M = 0; |
Gabor Greif | a99be51 | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 266 | if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile, |
Chris Lattner | 065344d | 2007-05-06 23:45:49 +0000 | [diff] [blame] | 267 | &ErrorMessage)) { |
Owen Anderson | 31895e7 | 2009-07-01 21:22:36 +0000 | [diff] [blame] | 268 | M = ParseBitcodeFile(Buffer, Context, &ErrorMessage); |
Chris Lattner | 065344d | 2007-05-06 23:45:49 +0000 | [diff] [blame] | 269 | delete Buffer; |
| 270 | } |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 271 | if (M == 0) { |
Dan Gohman | 65f57c2 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 272 | errs() << argv[0] << ": " << BitcodeFile << ": " |
Reid Spencer | 1adc3de | 2005-12-30 09:07:29 +0000 | [diff] [blame] | 273 | << ErrorMessage << "\n"; |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 274 | return 1; |
Chris Lattner | 4963dcf | 2003-10-28 22:30:37 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 277 | // Read the profiling information. This is redundant since we load it again |
| 278 | // using the standard profile info provider pass, but for now this gives us |
| 279 | // access to additional information not exposed via the ProfileInfo |
| 280 | // interface. |
| 281 | ProfileInfoLoader PIL(argv[0], ProfileDataFile, *M); |
Chris Lattner | 33f1ca7 | 2003-10-28 21:25:23 +0000 | [diff] [blame] | 282 | |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 283 | // Run the printer pass. |
| 284 | PassManager PassMgr; |
| 285 | PassMgr.add(createProfileLoaderPass(ProfileDataFile)); |
| 286 | PassMgr.add(new ProfileInfoPrinterPass(PIL)); |
| 287 | PassMgr.run(*M); |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 288 | |
| 289 | return 0; |
Reid Spencer | 1adc3de | 2005-12-30 09:07:29 +0000 | [diff] [blame] | 290 | } catch (const std::string& msg) { |
Dan Gohman | 65f57c2 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 291 | errs() << argv[0] << ": " << msg << "\n"; |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 292 | } catch (...) { |
Dan Gohman | 65f57c2 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 293 | errs() << argv[0] << ": Unexpected unknown exception occurred.\n"; |
Chris Lattner | 33f1ca7 | 2003-10-28 21:25:23 +0000 | [diff] [blame] | 294 | } |
Daniel Dunbar | 314fa8e | 2009-07-14 07:41:11 +0000 | [diff] [blame] | 295 | |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 296 | return 1; |
Chris Lattner | 6f82d07 | 2003-10-28 19:16:35 +0000 | [diff] [blame] | 297 | } |