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