Implement the "thread_local" keyword.
[oota-llvm.git] / lib / Bytecode / Reader / Analyzer.cpp
1 //===-- Analyzer.cpp - Analysis and Dumping of Bytecode ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file implements the AnalyzerHandler class and PrintBytecodeAnalysis
11 //  function which together comprise the basic functionality of the llmv-abcd
12 //  tool. The AnalyzerHandler collects information about the bytecode file into
13 //  the BytecodeAnalysis structure. The PrintBytecodeAnalysis function prints
14 //  out the content of that structure.
15 //  @see include/llvm/Bytecode/Analysis.h
16 //
17 //===----------------------------------------------------------------------===//
18
19 #include "Reader.h"
20 #include "llvm/Constants.h"
21 #include "llvm/DerivedTypes.h"
22 #include "llvm/Module.h"
23 #include "llvm/Analysis/Verifier.h"
24 #include "llvm/Bytecode/BytecodeHandler.h"
25 #include "llvm/Assembly/Writer.h"
26 #include <iomanip>
27 #include <sstream>
28 #include <ios>
29 using namespace llvm;
30
31 namespace {
32
33 /// @brief Bytecode reading handler for analyzing bytecode.
34 class AnalyzerHandler : public BytecodeHandler {
35   BytecodeAnalysis& bca;     ///< The structure in which data is recorded
36   std::ostream* os;        ///< A convenience for osing data.
37   /// @brief Keeps track of current function
38   BytecodeAnalysis::BytecodeFunctionInfo* currFunc;
39   Module* M; ///< Keeps track of current module
40
41 /// @name Constructor
42 /// @{
43 public:
44   /// The only way to construct an AnalyzerHandler. All that is needed is a
45   /// reference to the BytecodeAnalysis structure where the output will be
46   /// placed.
47   AnalyzerHandler(BytecodeAnalysis& TheBca, std::ostream* output)
48     : bca(TheBca)
49     , os(output)
50     , currFunc(0)
51     { }
52
53 /// @}
54 /// @name BytecodeHandler Implementations
55 /// @{
56 public:
57   virtual void handleError(const std::string& str ) {
58     if (os)
59       *os << "ERROR: " << str << "\n";
60   }
61
62   virtual void handleStart( Module* Mod, unsigned theSize ) {
63     M = Mod;
64     if (os)
65       *os << "Bytecode {\n";
66     bca.byteSize = theSize;
67     bca.ModuleId.clear();
68     bca.numBlocks = 0;
69     bca.numTypes = 0;
70     bca.numValues = 0;
71     bca.numFunctions = 0;
72     bca.numConstants = 0;
73     bca.numGlobalVars = 0;
74     bca.numInstructions = 0;
75     bca.numBasicBlocks = 0;
76     bca.numOperands = 0;
77     bca.numCmpctnTables = 0;
78     bca.numSymTab = 0;
79     bca.numLibraries = 0;
80     bca.libSize = 0;
81     bca.maxTypeSlot = 0;
82     bca.maxValueSlot = 0;
83     bca.numAlignment = 0;
84     bca.fileDensity = 0.0;
85     bca.globalsDensity = 0.0;
86     bca.functionDensity = 0.0;
87     bca.instructionSize = 0;
88     bca.longInstructions = 0;
89     bca.FunctionInfo.clear();
90     bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse] = 0;
91     bca.BlockSizes[BytecodeFormat::ModuleBlockID] = theSize;
92     bca.BlockSizes[BytecodeFormat::FunctionBlockID] = 0;
93     bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID] = 0;
94     bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID] = 0;
95     bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
96     bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
97     bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
98     bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
99   }
100
101   virtual void handleFinish() {
102     if (os)
103       *os << "} End Bytecode\n";
104
105     bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
106     double globalSize = 0.0;
107     globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]);
108     globalSize += double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]);
109     globalSize += double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]);
110     bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants +
111       bca.numGlobalVars );
112     bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) /
113       double(bca.numFunctions);
114
115     if (bca.progressiveVerify) {
116       std::string msg;
117       if (verifyModule(*M, ReturnStatusAction, &msg))
118         bca.VerifyInfo += "Verify@Finish: " + msg + "\n";
119     }
120   }
121
122   virtual void handleModuleBegin(const std::string& id) {
123     if (os)
124       *os << "  Module " << id << " {\n";
125     bca.ModuleId = id;
126   }
127
128   virtual void handleModuleEnd(const std::string& id) {
129     if (os)
130       *os << "  } End Module " << id << "\n";
131     if (bca.progressiveVerify) {
132       std::string msg;
133       if (verifyModule(*M, ReturnStatusAction, &msg))
134         bca.VerifyInfo += "Verify@EndModule: " + msg + "\n";
135     }
136   }
137
138   virtual void handleVersionInfo(
139     unsigned char RevisionNum        ///< Byte code revision number
140   ) {
141     if (os)
142       *os << "    RevisionNum: " << int(RevisionNum) << "\n";
143     bca.version = RevisionNum;
144   }
145
146   virtual void handleModuleGlobalsBegin() {
147     if (os)
148       *os << "    BLOCK: ModuleGlobalInfo {\n";
149   }
150
151   virtual void handleGlobalVariable(
152     const Type* ElemType,
153     bool isConstant,
154     GlobalValue::LinkageTypes Linkage,
155     GlobalValue::VisibilityTypes Visibility,
156     unsigned SlotNum,
157     unsigned initSlot,
158     bool isThreadLocal
159   ) {
160     if (os) {
161       *os << "      GV: "
162           << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, "
163           << ( isConstant? "Constant, " : "Variable, ")
164           << " Thread Local = " << ( isThreadLocal? "yes, " : "no, ")
165           << " Linkage=" << Linkage
166           << " Visibility="<< Visibility
167           << " Type=";
168       WriteTypeSymbolic(*os, ElemType, M);
169       *os << " Slot=" << SlotNum << " InitSlot=" << initSlot
170           << "\n";
171     }
172
173     bca.numGlobalVars++;
174     bca.numValues++;
175     if (SlotNum > bca.maxValueSlot)
176       bca.maxValueSlot = SlotNum;
177     if (initSlot > bca.maxValueSlot)
178       bca.maxValueSlot = initSlot;
179
180   }
181
182   virtual void handleTypeList(unsigned numEntries) {
183     bca.maxTypeSlot = numEntries - 1;
184   }
185
186   virtual void handleType( const Type* Ty ) {
187     bca.numTypes++;
188     if (os) {
189       *os << "      Type: ";
190       WriteTypeSymbolic(*os,Ty,M);
191       *os << "\n";
192     }
193   }
194
195   virtual void handleFunctionDeclaration(
196     Function* Func            ///< The function
197   ) {
198     bca.numFunctions++;
199     bca.numValues++;
200     if (os) {
201       *os << "      Function Decl: ";
202       WriteTypeSymbolic(*os,Func->getType(),M);
203       *os <<", Linkage=" << Func->getLinkage();
204       *os <<", Visibility=" << Func->getVisibility();
205       *os << "\n";
206     }
207   }
208
209   virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
210     if (os) {
211       *os << "    Initializer: GV=";
212       GV->print(*os);
213       *os << "      CV=";
214       CV->print(*os);
215       *os << "\n";
216     }
217   }
218
219   virtual void handleDependentLibrary(const std::string& libName) {
220     bca.numLibraries++;
221     bca.libSize += libName.size() + (libName.size() < 128 ? 1 : 2);
222     if (os)
223       *os << "      Library: '" << libName << "'\n";
224   }
225
226   virtual void handleModuleGlobalsEnd() {
227     if (os)
228       *os << "    } END BLOCK: ModuleGlobalInfo\n";
229     if (bca.progressiveVerify) {
230       std::string msg;
231       if (verifyModule(*M, ReturnStatusAction, &msg))
232         bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n";
233     }
234   }
235
236   virtual void handleTypeSymbolTableBegin(TypeSymbolTable* ST) {
237     bca.numSymTab++;
238     if (os)
239       *os << "    BLOCK: TypeSymbolTable {\n";
240   }
241   virtual void handleValueSymbolTableBegin(Function* CF, ValueSymbolTable* ST) {
242     bca.numSymTab++;
243     if (os)
244       *os << "    BLOCK: ValueSymbolTable {\n";
245   }
246
247   virtual void handleSymbolTableType(unsigned i, unsigned TypSlot,
248     const std::string& name ) {
249     if (os)
250       *os << "        Type " << i << " Slot=" << TypSlot
251          << " Name: " << name << "\n";
252   }
253
254   virtual void handleSymbolTableValue(unsigned TySlot, unsigned ValSlot, 
255                                       const char *Name, unsigned NameLen) {
256     if (os)
257       *os << "        Value " << TySlot << " Slot=" << ValSlot
258           << " Name: " << std::string(Name, Name+NameLen) << "\n";
259     if (ValSlot > bca.maxValueSlot)
260       bca.maxValueSlot = ValSlot;
261   }
262
263   virtual void handleValueSymbolTableEnd() {
264     if (os)
265       *os << "    } END BLOCK: ValueSymbolTable\n";
266   }
267
268   virtual void handleTypeSymbolTableEnd() {
269     if (os)
270       *os << "    } END BLOCK: TypeSymbolTable\n";
271   }
272
273   virtual void handleFunctionBegin(Function* Func, unsigned Size) {
274     if (os) {
275       *os << "    BLOCK: Function {\n"
276           << "      Linkage: " << Func->getLinkage() << "\n"
277           << "      Visibility: " << Func->getVisibility() << "\n"
278           << "      Type: ";
279       WriteTypeSymbolic(*os,Func->getType(),M);
280       *os << "\n";
281     }
282
283     currFunc = &bca.FunctionInfo[Func];
284     std::ostringstream tmp;
285     WriteTypeSymbolic(tmp,Func->getType(),M);
286     currFunc->description = tmp.str();
287     currFunc->name = Func->getName();
288     currFunc->byteSize = Size;
289     currFunc->numInstructions = 0;
290     currFunc->numBasicBlocks = 0;
291     currFunc->numPhis = 0;
292     currFunc->numOperands = 0;
293     currFunc->density = 0.0;
294     currFunc->instructionSize = 0;
295     currFunc->longInstructions = 0;
296
297   }
298
299   virtual void handleFunctionEnd( Function* Func) {
300     if (os)
301       *os << "    } END BLOCK: Function\n";
302     currFunc->density = double(currFunc->byteSize) /
303       double(currFunc->numInstructions);
304
305     if (bca.progressiveVerify) {
306       std::string msg;
307       if (verifyModule(*M, ReturnStatusAction, &msg))
308         bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
309     }
310   }
311
312   virtual void handleBasicBlockBegin( unsigned blocknum) {
313     if (os)
314       *os << "      BLOCK: BasicBlock #" << blocknum << "{\n";
315     bca.numBasicBlocks++;
316     bca.numValues++;
317     if ( currFunc ) currFunc->numBasicBlocks++;
318   }
319
320   virtual bool handleInstruction( unsigned Opcode, const Type* iType,
321                                 unsigned *Operands, unsigned NumOps, 
322                                 Instruction *Inst,
323                                 unsigned Size){
324     if (os) {
325       *os << "        INST: OpCode="
326          << Instruction::getOpcodeName(Opcode);
327       for (unsigned i = 0; i != NumOps; ++i)
328         *os << " Op(" << Operands[i] << ")";
329       *os << *Inst;
330     }
331
332     bca.numInstructions++;
333     bca.numValues++;
334     bca.instructionSize += Size;
335     if (Size > 4 ) bca.longInstructions++;
336     bca.numOperands += NumOps;
337     for (unsigned i = 0; i != NumOps; ++i)
338       if (Operands[i] > bca.maxValueSlot)
339         bca.maxValueSlot = Operands[i];
340     if ( currFunc ) {
341       currFunc->numInstructions++;
342       currFunc->instructionSize += Size;
343       if (Size > 4 ) currFunc->longInstructions++;
344       if (Opcode == Instruction::PHI) currFunc->numPhis++;
345     }
346     return Instruction::isTerminator(Opcode);
347   }
348
349   virtual void handleBasicBlockEnd(unsigned blocknum) {
350     if (os)
351       *os << "      } END BLOCK: BasicBlock #" << blocknum << "\n";
352   }
353
354   virtual void handleGlobalConstantsBegin() {
355     if (os)
356       *os << "    BLOCK: GlobalConstants {\n";
357   }
358
359   virtual void handleConstantExpression(unsigned Opcode,
360       Constant**ArgVec, unsigned NumArgs, Constant* C) {
361     if (os) {
362       *os << "      EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
363       for ( unsigned i = 0; i != NumArgs; ++i ) {
364         *os << "        Arg#" << i << " "; ArgVec[i]->print(*os);
365         *os << "\n";
366       }
367       *os << "        Value=";
368       C->print(*os);
369       *os << "\n";
370     }
371     bca.numConstants++;
372     bca.numValues++;
373   }
374
375   virtual void handleConstantValue( Constant * c ) {
376     if (os) {
377       *os << "      VALUE: ";
378       c->print(*os);
379       *os << "\n";
380     }
381     bca.numConstants++;
382     bca.numValues++;
383   }
384
385   virtual void handleConstantArray( const ArrayType* AT,
386           Constant**Elements, unsigned NumElts,
387           unsigned TypeSlot,
388           Constant* ArrayVal ) {
389     if (os) {
390       *os << "      ARRAY: ";
391       WriteTypeSymbolic(*os,AT,M);
392       *os << " TypeSlot=" << TypeSlot << "\n";
393       for (unsigned i = 0; i != NumElts; ++i) {
394         *os << "        #" << i;
395         Elements[i]->print(*os);
396         *os << "\n";
397       }
398       *os << "        Value=";
399       ArrayVal->print(*os);
400       *os << "\n";
401     }
402
403     bca.numConstants++;
404     bca.numValues++;
405   }
406
407   virtual void handleConstantStruct(
408         const StructType* ST,
409         Constant**Elements, unsigned NumElts,
410         Constant* StructVal)
411   {
412     if (os) {
413       *os << "      STRUC: ";
414       WriteTypeSymbolic(*os,ST,M);
415       *os << "\n";
416       for ( unsigned i = 0; i != NumElts; ++i) {
417         *os << "        #" << i << " "; Elements[i]->print(*os);
418         *os << "\n";
419       }
420       *os << "        Value=";
421       StructVal->print(*os);
422       *os << "\n";
423     }
424     bca.numConstants++;
425     bca.numValues++;
426   }
427
428   virtual void handleConstantVector(
429     const VectorType* PT,
430     Constant**Elements, unsigned NumElts,
431     unsigned TypeSlot,
432     Constant* VectorVal)
433   {
434     if (os) {
435       *os << "      PACKD: ";
436       WriteTypeSymbolic(*os,PT,M);
437       *os << " TypeSlot=" << TypeSlot << "\n";
438       for ( unsigned i = 0; i != NumElts; ++i ) {
439         *os << "        #" << i;
440         Elements[i]->print(*os);
441         *os << "\n";
442       }
443       *os << "        Value=";
444       VectorVal->print(*os);
445       *os << "\n";
446     }
447
448     bca.numConstants++;
449     bca.numValues++;
450   }
451
452   virtual void handleConstantPointer( const PointerType* PT,
453       unsigned Slot, GlobalValue* GV ) {
454     if (os) {
455       *os << "       PNTR: ";
456       WriteTypeSymbolic(*os,PT,M);
457       *os << " Slot=" << Slot << " GlobalValue=";
458       GV->print(*os);
459       *os << "\n";
460     }
461     bca.numConstants++;
462     bca.numValues++;
463   }
464
465   virtual void handleConstantString( const ConstantArray* CA ) {
466     if (os) {
467       *os << "      STRNG: ";
468       CA->print(*os);
469       *os << "\n";
470     }
471     bca.numConstants++;
472     bca.numValues++;
473   }
474
475   virtual void handleGlobalConstantsEnd() {
476     if (os)
477       *os << "    } END BLOCK: GlobalConstants\n";
478
479     if (bca.progressiveVerify) {
480       std::string msg;
481       if (verifyModule(*M, ReturnStatusAction, &msg))
482         bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
483     }
484   }
485
486   virtual void handleAlignment(unsigned numBytes) {
487     bca.numAlignment += numBytes;
488   }
489
490   virtual void handleBlock(
491     unsigned BType, const unsigned char* StartPtr, unsigned Size) {
492     bca.numBlocks++;
493     assert(BType >= BytecodeFormat::ModuleBlockID);
494     assert(BType < BytecodeFormat::NumberOfBlockIDs);
495     bca.BlockSizes[
496       llvm::BytecodeFormat::BytecodeBlockIdentifiers(BType)] += Size;
497
498     if (bca.version < 3) // Check for long block headers versions
499       bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;
500     else
501       bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 4;
502   }
503
504 };
505 } // end anonymous namespace
506
507 /// @brief Utility for printing a titled unsigned value with
508 /// an aligned colon.
509 inline static void print(std::ostream& Out, const char*title,
510   unsigned val, bool nl = true ) {
511   Out << std::setw(30) << std::right << title
512       << std::setw(0) << ": "
513       << std::setw(9) << val << "\n";
514 }
515
516 /// @brief Utility for printing a titled double value with an
517 /// aligned colon
518 inline static void print(std::ostream&Out, const char*title,
519   double val ) {
520   Out << std::setw(30) << std::right << title
521       << std::setw(0) << ": "
522       << std::setw(9) << std::setprecision(6) << val << "\n" ;
523 }
524
525 /// @brief Utility for printing a titled double value with a
526 /// percentage and aligned colon.
527 inline static void print(std::ostream&Out, const char*title,
528   double top, double bot ) {
529   Out << std::setw(30) << std::right << title
530       << std::setw(0) << ": "
531       << std::setw(9) << std::setprecision(6) << top
532       << " (" << std::left << std::setw(0) << std::setprecision(4)
533       << (top/bot)*100.0 << "%)\n";
534 }
535
536 /// @brief Utility for printing a titled string value with
537 /// an aligned colon.
538 inline static void print(std::ostream&Out, const char*title,
539   std::string val, bool nl = true) {
540   Out << std::setw(30) << std::right << title
541       << std::setw(0) << ": "
542       << std::left << val << (nl ? "\n" : "");
543 }
544
545 /// This function prints the contents of rhe BytecodeAnalysis structure in
546 /// a human legible form.
547 /// @brief Print BytecodeAnalysis structure to an ostream
548 void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
549 {
550   Out << "\nSummary Analysis Of " << bca.ModuleId << ": \n\n";
551   print(Out, "Bytecode Analysis Of Module",     bca.ModuleId);
552   print(Out, "Bytecode Version Number",         bca.version);
553   print(Out, "File Size",                       bca.byteSize);
554   print(Out, "Module Bytes",
555         double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]),
556         double(bca.byteSize));
557   print(Out, "Function Bytes",
558         double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]),
559         double(bca.byteSize));
560   print(Out, "Global Types Bytes",
561         double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]),
562         double(bca.byteSize));
563   print(Out, "Constant Pool Bytes",
564         double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]),
565         double(bca.byteSize));
566   print(Out, "Module Globals Bytes",
567         double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]),
568         double(bca.byteSize));
569   print(Out, "Instruction List Bytes",
570         double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
571         double(bca.byteSize));
572   print(Out, "Value Symbol Table Bytes",
573         double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
574         double(bca.byteSize));
575   print(Out, "Type Symbol Table Bytes",
576         double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]),
577         double(bca.byteSize));
578   print(Out, "Alignment Bytes",
579         double(bca.numAlignment), double(bca.byteSize));
580   print(Out, "Block Header Bytes",
581         double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]),
582         double(bca.byteSize));
583   print(Out, "Dependent Libraries Bytes", double(bca.libSize),
584         double(bca.byteSize));
585   print(Out, "Number Of Bytecode Blocks",       bca.numBlocks);
586   print(Out, "Number Of Functions",             bca.numFunctions);
587   print(Out, "Number Of Types",                 bca.numTypes);
588   print(Out, "Number Of Constants",             bca.numConstants);
589   print(Out, "Number Of Global Variables",      bca.numGlobalVars);
590   print(Out, "Number Of Values",                bca.numValues);
591   print(Out, "Number Of Basic Blocks",          bca.numBasicBlocks);
592   print(Out, "Number Of Instructions",          bca.numInstructions);
593   print(Out, "Number Of Long Instructions",     bca.longInstructions);
594   print(Out, "Number Of Operands",              bca.numOperands);
595   print(Out, "Number Of Symbol Tables",         bca.numSymTab);
596   print(Out, "Number Of Dependent Libs",        bca.numLibraries);
597   print(Out, "Total Instruction Size",          bca.instructionSize);
598   print(Out, "Average Instruction Size",
599         double(bca.instructionSize)/double(bca.numInstructions));
600
601   print(Out, "Maximum Type Slot Number",        bca.maxTypeSlot);
602   print(Out, "Maximum Value Slot Number",       bca.maxValueSlot);
603   print(Out, "Bytes Per Value ",                bca.fileDensity);
604   print(Out, "Bytes Per Global",                bca.globalsDensity);
605   print(Out, "Bytes Per Function",              bca.functionDensity);
606
607   if (bca.detailedResults) {
608     Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n";
609
610     std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
611       bca.FunctionInfo.begin();
612     std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
613       bca.FunctionInfo.end();
614
615     while ( I != E ) {
616       Out << std::left << std::setw(0) << "\n";
617       if (I->second.numBasicBlocks == 0) Out << "External ";
618       Out << "Function: " << I->second.name << "\n";
619       print(Out, "Type:", I->second.description);
620       print(Out, "Byte Size", I->second.byteSize);
621       if (I->second.numBasicBlocks) {
622         print(Out, "Basic Blocks", I->second.numBasicBlocks);
623         print(Out, "Instructions", I->second.numInstructions);
624         print(Out, "Long Instructions", I->second.longInstructions);
625         print(Out, "Operands", I->second.numOperands);
626         print(Out, "Instruction Size", I->second.instructionSize);
627         print(Out, "Average Instruction Size",
628               double(I->second.instructionSize) / I->second.numInstructions);
629         print(Out, "Bytes Per Instruction", I->second.density);
630       }
631       ++I;
632     }
633   }
634
635   if ( bca.progressiveVerify )
636     Out << bca.VerifyInfo;
637 }
638
639 // AnalyzeBytecodeFile - analyze one file
640 Module* llvm::AnalyzeBytecodeFile(const std::string &Filename,  ///< File to analyze
641                                   BytecodeAnalysis& bca,        ///< Statistical output
642                                   BCDecompressor_t *BCDC,
643                                   std::string *ErrMsg,          ///< Error output
644                                   std::ostream* output          ///< Dump output
645                                   ) {
646   BytecodeHandler* AH = new AnalyzerHandler(bca, output);
647   ModuleProvider* MP = getBytecodeModuleProvider(Filename, BCDC, ErrMsg, AH);
648   if (!MP) return 0;
649   Module *M = MP->releaseModule(ErrMsg);
650   delete MP;
651   return M;
652 }