blob: 2d90c938263d136f96e58230f13922e66798104a [file] [log] [blame]
Chris Lattner4f9ff5a2007-02-07 07:19:19 +00001//===-- Analyzer.cpp - Analysis and Dumping of Bytecode ---------*- C++ -*-===//
Misha Brukman8a96c532005-04-21 21:44:41 +00002//
Reid Spencerdac69c82004-06-07 17:53:43 +00003// The LLVM Compiler Infrastructure
4//
Misha Brukman8a96c532005-04-21 21:44:41 +00005// This file was developed by Reid Spencer and is distributed under the
Reid Spencerdac69c82004-06-07 17:53:43 +00006// University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman8a96c532005-04-21 21:44:41 +00007//
Reid Spencerdac69c82004-06-07 17:53:43 +00008//===----------------------------------------------------------------------===//
9//
Reid Spencerf41aa732004-06-29 23:23:12 +000010// 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
Reid Spencerdac69c82004-06-07 17:53:43 +000016//
17//===----------------------------------------------------------------------===//
18
Reid Spencerf41aa732004-06-29 23:23:12 +000019#include "Reader.h"
20#include "llvm/Constants.h"
21#include "llvm/DerivedTypes.h"
22#include "llvm/Module.h"
23#include "llvm/Analysis/Verifier.h"
Reid Spencerf41aa732004-06-29 23:23:12 +000024#include "llvm/Bytecode/BytecodeHandler.h"
Reid Spencer911ec6d2004-08-21 20:58:19 +000025#include "llvm/Assembly/Writer.h"
Reid Spencerf41aa732004-06-29 23:23:12 +000026#include <iomanip>
27#include <sstream>
Duraid Madina0f7bfba2005-12-26 14:23:22 +000028#include <ios>
Reid Spencerdac69c82004-06-07 17:53:43 +000029using namespace llvm;
30
Reid Spencerdac69c82004-06-07 17:53:43 +000031namespace {
32
Reid Spencerf41aa732004-06-29 23:23:12 +000033/// @brief Bytecode reading handler for analyzing bytecode.
Reid Spencerdac69c82004-06-07 17:53:43 +000034class AnalyzerHandler : public BytecodeHandler {
Reid Spencerf41aa732004-06-29 23:23:12 +000035 BytecodeAnalysis& bca; ///< The structure in which data is recorded
Reid Spencer911ec6d2004-08-21 20:58:19 +000036 std::ostream* os; ///< A convenience for osing data.
Reid Spencerf41aa732004-06-29 23:23:12 +000037 /// @brief Keeps track of current function
Misha Brukman8a96c532005-04-21 21:44:41 +000038 BytecodeAnalysis::BytecodeFunctionInfo* currFunc;
Reid Spencerf41aa732004-06-29 23:23:12 +000039 Module* M; ///< Keeps track of current module
40
41/// @name Constructor
42/// @{
Reid Spencerdac69c82004-06-07 17:53:43 +000043public:
Reid Spencerf41aa732004-06-29 23:23:12 +000044 /// 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.
Misha Brukman8a96c532005-04-21 21:44:41 +000047 AnalyzerHandler(BytecodeAnalysis& TheBca, std::ostream* output)
48 : bca(TheBca)
Reid Spencer911ec6d2004-08-21 20:58:19 +000049 , os(output)
Reid Spencercbb22e22004-06-10 22:00:54 +000050 , currFunc(0)
Reid Spencer911ec6d2004-08-21 20:58:19 +000051 { }
Reid Spencer649ee572004-06-09 06:16:43 +000052
Reid Spencerf41aa732004-06-29 23:23:12 +000053/// @}
54/// @name BytecodeHandler Implementations
55/// @{
56public:
Misha Brukman8a96c532005-04-21 21:44:41 +000057 virtual void handleError(const std::string& str ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +000058 if (os)
59 *os << "ERROR: " << str << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +000060 }
61
Reid Spencerf41aa732004-06-29 23:23:12 +000062 virtual void handleStart( Module* Mod, unsigned theSize ) {
63 M = Mod;
Reid Spencer911ec6d2004-08-21 20:58:19 +000064 if (os)
65 *os << "Bytecode {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +000066 bca.byteSize = theSize;
Reid Spencer649ee572004-06-09 06:16:43 +000067 bca.ModuleId.clear();
Reid Spencer00c28a72004-06-10 08:09:13 +000068 bca.numBlocks = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000069 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;
Reid Spencer911ec6d2004-08-21 20:58:19 +000079 bca.numLibraries = 0;
80 bca.libSize = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000081 bca.maxTypeSlot = 0;
82 bca.maxValueSlot = 0;
Reid Spencer00c28a72004-06-10 08:09:13 +000083 bca.numAlignment = 0;
84 bca.fileDensity = 0.0;
85 bca.globalsDensity = 0.0;
86 bca.functionDensity = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +000087 bca.instructionSize = 0;
88 bca.longInstructions = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000089 bca.FunctionInfo.clear();
Reid Spencer911ec6d2004-08-21 20:58:19 +000090 bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse] = 0;
91 bca.BlockSizes[BytecodeFormat::ModuleBlockID] = theSize;
92 bca.BlockSizes[BytecodeFormat::FunctionBlockID] = 0;
93 bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID] = 0;
Reid Spencer78d033e2007-01-06 07:24:44 +000094 bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID] = 0;
Reid Spencer911ec6d2004-08-21 20:58:19 +000095 bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
96 bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
97 bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
Reid Spencer78d033e2007-01-06 07:24:44 +000098 bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
Reid Spencerdac69c82004-06-07 17:53:43 +000099 }
100
Reid Spencercbb22e22004-06-10 22:00:54 +0000101 virtual void handleFinish() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000102 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000103 *os << "} End Bytecode\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000104
Reid Spencer00c28a72004-06-10 08:09:13 +0000105 bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
106 double globalSize = 0.0;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000107 globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]);
108 globalSize += double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]);
109 globalSize += double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]);
Misha Brukman8a96c532005-04-21 21:44:41 +0000110 bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants +
Reid Spencer00c28a72004-06-10 08:09:13 +0000111 bca.numGlobalVars );
Misha Brukman8a96c532005-04-21 21:44:41 +0000112 bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) /
Reid Spencer00c28a72004-06-10 08:09:13 +0000113 double(bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000114
Chris Lattner05ac92c2006-07-06 18:02:27 +0000115 if (bca.progressiveVerify) {
116 std::string msg;
117 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000118 bca.VerifyInfo += "Verify@Finish: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000119 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000120 }
121
Reid Spencercbb22e22004-06-10 22:00:54 +0000122 virtual void handleModuleBegin(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000123 if (os)
124 *os << " Module " << id << " {\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000125 bca.ModuleId = id;
Reid Spencerdac69c82004-06-07 17:53:43 +0000126 }
127
Misha Brukman8a96c532005-04-21 21:44:41 +0000128 virtual void handleModuleEnd(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000129 if (os)
130 *os << " } End Module " << id << "\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000131 if (bca.progressiveVerify) {
132 std::string msg;
133 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000134 bca.VerifyInfo += "Verify@EndModule: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000135 }
136 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000137
Reid Spencercbb22e22004-06-10 22:00:54 +0000138 virtual void handleVersionInfo(
Reid Spenceraacc35a2007-01-26 08:10:24 +0000139 unsigned char RevisionNum ///< Byte code revision number
Misha Brukman8a96c532005-04-21 21:44:41 +0000140 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000141 if (os)
Reid Spenceraacc35a2007-01-26 08:10:24 +0000142 *os << " RevisionNum: " << int(RevisionNum) << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000143 bca.version = RevisionNum;
Reid Spencerf41aa732004-06-29 23:23:12 +0000144 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000145
Misha Brukman8a96c532005-04-21 21:44:41 +0000146 virtual void handleModuleGlobalsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000147 if (os)
148 *os << " BLOCK: ModuleGlobalInfo {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000149 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000150
Misha Brukman8a96c532005-04-21 21:44:41 +0000151 virtual void handleGlobalVariable(
152 const Type* ElemType,
153 bool isConstant,
Reid Spencerf41aa732004-06-29 23:23:12 +0000154 GlobalValue::LinkageTypes Linkage,
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000155 GlobalValue::VisibilityTypes Visibility,
Reid Spencerf41aa732004-06-29 23:23:12 +0000156 unsigned SlotNum,
Lauro Ramos Venancioc7635522007-04-12 18:32:50 +0000157 unsigned initSlot,
158 bool isThreadLocal
Reid Spencercbb22e22004-06-10 22:00:54 +0000159 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000160 if (os) {
161 *os << " GV: "
162 << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, "
163 << ( isConstant? "Constant, " : "Variable, ")
Lauro Ramos Venancioc7635522007-04-12 18:32:50 +0000164 << " Thread Local = " << ( isThreadLocal? "yes, " : "no, ")
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000165 << " Linkage=" << Linkage
166 << " Visibility="<< Visibility
167 << " Type=";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000168 //WriteTypeSymbolic(*os, ElemType, M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000169 *os << " Slot=" << SlotNum << " InitSlot=" << initSlot
Reid Spencer911ec6d2004-08-21 20:58:19 +0000170 << "\n";
171 }
172
Reid Spencer649ee572004-06-09 06:16:43 +0000173 bca.numGlobalVars++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000174 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000175 if (SlotNum > bca.maxValueSlot)
176 bca.maxValueSlot = SlotNum;
177 if (initSlot > bca.maxValueSlot)
178 bca.maxValueSlot = initSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000179
Reid Spencer911ec6d2004-08-21 20:58:19 +0000180 }
181
Anton Korobeynikova80e1182007-04-28 13:45:00 +0000182 virtual void handleGlobalAlias(
183 const Type* ElemType,
184 GlobalValue::LinkageTypes Linkage,
185 unsigned TypeSlotNum,
186 unsigned AliaseeSlot) {
187 if (os) {
188 *os << " GA: "
189 << " Linkage=" << Linkage
190 << " Type=";
191 //WriteTypeSymbolic(*os, ElemType, M);
192 *os << " Slot=" << TypeSlotNum << " AliaseeSlot=" << AliaseeSlot
193 << "\n";
194 }
195
196 bca.numValues++;
197 if (TypeSlotNum > bca.maxValueSlot)
198 bca.maxValueSlot = TypeSlotNum;
199 if (AliaseeSlot > bca.maxValueSlot)
200 bca.maxValueSlot = AliaseeSlot;
201 }
202
Reid Spencer911ec6d2004-08-21 20:58:19 +0000203 virtual void handleTypeList(unsigned numEntries) {
204 bca.maxTypeSlot = numEntries - 1;
Reid Spencerdac69c82004-06-07 17:53:43 +0000205 }
206
Misha Brukman8a96c532005-04-21 21:44:41 +0000207 virtual void handleType( const Type* Ty ) {
208 bca.numTypes++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000209 if (os) {
210 *os << " Type: ";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000211 //WriteTypeSymbolic(*os,Ty,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000212 *os << "\n";
213 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000214 }
215
Misha Brukman8a96c532005-04-21 21:44:41 +0000216 virtual void handleFunctionDeclaration(
Reid Spencerb61cdb72004-07-04 11:00:39 +0000217 Function* Func ///< The function
Reid Spencercbb22e22004-06-10 22:00:54 +0000218 ) {
Reid Spencer649ee572004-06-09 06:16:43 +0000219 bca.numFunctions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000220 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000221 if (os) {
222 *os << " Function Decl: ";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000223 //WriteTypeSymbolic(*os,Func->getType(),M);
Anton Korobeynikov93c2b372006-09-17 13:06:18 +0000224 *os <<", Linkage=" << Func->getLinkage();
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000225 *os <<", Visibility=" << Func->getVisibility();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000226 *os << "\n";
227 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000228 }
229
Reid Spencerf41aa732004-06-29 23:23:12 +0000230 virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000231 if (os) {
232 *os << " Initializer: GV=";
233 GV->print(*os);
234 *os << " CV=";
235 CV->print(*os);
236 *os << "\n";
237 }
238 }
239
240 virtual void handleDependentLibrary(const std::string& libName) {
241 bca.numLibraries++;
242 bca.libSize += libName.size() + (libName.size() < 128 ? 1 : 2);
Reid Spencer3ee8eed2004-09-11 04:14:07 +0000243 if (os)
244 *os << " Library: '" << libName << "'\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000245 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000246
Misha Brukman8a96c532005-04-21 21:44:41 +0000247 virtual void handleModuleGlobalsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000248 if (os)
249 *os << " } END BLOCK: ModuleGlobalInfo\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000250 if (bca.progressiveVerify) {
251 std::string msg;
252 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000253 bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000254 }
255 }
256
Reid Spenceref9b9a72007-02-05 20:47:22 +0000257 virtual void handleTypeSymbolTableBegin(TypeSymbolTable* ST) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000258 bca.numSymTab++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000259 if (os)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000260 *os << " BLOCK: TypeSymbolTable {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000261 }
Reid Spenceref9b9a72007-02-05 20:47:22 +0000262 virtual void handleValueSymbolTableBegin(Function* CF, ValueSymbolTable* ST) {
263 bca.numSymTab++;
264 if (os)
265 *os << " BLOCK: ValueSymbolTable {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000266 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000267
Misha Brukman8a96c532005-04-21 21:44:41 +0000268 virtual void handleSymbolTableType(unsigned i, unsigned TypSlot,
269 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000270 if (os)
271 *os << " Type " << i << " Slot=" << TypSlot
Misha Brukman8a96c532005-04-21 21:44:41 +0000272 << " Name: " << name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000273 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000274
Reid Spenceref9b9a72007-02-05 20:47:22 +0000275 virtual void handleSymbolTableValue(unsigned TySlot, unsigned ValSlot,
Chris Lattnerdd8cec52007-02-12 18:53:43 +0000276 const char *Name, unsigned NameLen) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000277 if (os)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000278 *os << " Value " << TySlot << " Slot=" << ValSlot
Chris Lattnerdd8cec52007-02-12 18:53:43 +0000279 << " Name: " << std::string(Name, Name+NameLen) << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000280 if (ValSlot > bca.maxValueSlot)
281 bca.maxValueSlot = ValSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000282 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000283
Reid Spenceref9b9a72007-02-05 20:47:22 +0000284 virtual void handleValueSymbolTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000285 if (os)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000286 *os << " } END BLOCK: ValueSymbolTable\n";
287 }
288
289 virtual void handleTypeSymbolTableEnd() {
290 if (os)
291 *os << " } END BLOCK: TypeSymbolTable\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000292 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000293
Reid Spencerf41aa732004-06-29 23:23:12 +0000294 virtual void handleFunctionBegin(Function* Func, unsigned Size) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000295 if (os) {
296 *os << " BLOCK: Function {\n"
297 << " Linkage: " << Func->getLinkage() << "\n"
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000298 << " Visibility: " << Func->getVisibility() << "\n"
Misha Brukman8a96c532005-04-21 21:44:41 +0000299 << " Type: ";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000300 //WriteTypeSymbolic(*os,Func->getType(),M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000301 *os << "\n";
302 }
303
Reid Spencercbb22e22004-06-10 22:00:54 +0000304 currFunc = &bca.FunctionInfo[Func];
Reid Spencer911ec6d2004-08-21 20:58:19 +0000305 std::ostringstream tmp;
Chris Lattner4ab2d202007-04-24 17:20:52 +0000306 //WriteTypeSymbolic(tmp,Func->getType(),M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000307 currFunc->description = tmp.str();
Reid Spencercbb22e22004-06-10 22:00:54 +0000308 currFunc->name = Func->getName();
309 currFunc->byteSize = Size;
310 currFunc->numInstructions = 0;
311 currFunc->numBasicBlocks = 0;
312 currFunc->numPhis = 0;
313 currFunc->numOperands = 0;
314 currFunc->density = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +0000315 currFunc->instructionSize = 0;
316 currFunc->longInstructions = 0;
Reid Spencerf41aa732004-06-29 23:23:12 +0000317
Reid Spencerdac69c82004-06-07 17:53:43 +0000318 }
319
Reid Spencercbb22e22004-06-10 22:00:54 +0000320 virtual void handleFunctionEnd( Function* Func) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000321 if (os)
322 *os << " } END BLOCK: Function\n";
Reid Spencercbb22e22004-06-10 22:00:54 +0000323 currFunc->density = double(currFunc->byteSize) /
Reid Spencer3120e712004-08-24 22:45:32 +0000324 double(currFunc->numInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000325
Chris Lattner05ac92c2006-07-06 18:02:27 +0000326 if (bca.progressiveVerify) {
327 std::string msg;
328 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000329 bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000330 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000331 }
332
Reid Spencercbb22e22004-06-10 22:00:54 +0000333 virtual void handleBasicBlockBegin( unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000334 if (os)
335 *os << " BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000336 bca.numBasicBlocks++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000337 bca.numValues++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000338 if ( currFunc ) currFunc->numBasicBlocks++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000339 }
340
Misha Brukman8a96c532005-04-21 21:44:41 +0000341 virtual bool handleInstruction( unsigned Opcode, const Type* iType,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000342 unsigned *Operands, unsigned NumOps,
Reid Spenceref9b9a72007-02-05 20:47:22 +0000343 Instruction *Inst,
344 unsigned Size){
Reid Spencer911ec6d2004-08-21 20:58:19 +0000345 if (os) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000346 *os << " INST: OpCode="
Reid Spenceref9b9a72007-02-05 20:47:22 +0000347 << Instruction::getOpcodeName(Opcode);
Chris Lattner63cf59e2007-02-07 05:08:39 +0000348 for (unsigned i = 0; i != NumOps; ++i)
Reid Spenceref9b9a72007-02-05 20:47:22 +0000349 *os << " Op(" << Operands[i] << ")";
350 *os << *Inst;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000351 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000352
Reid Spencer649ee572004-06-09 06:16:43 +0000353 bca.numInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000354 bca.numValues++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000355 bca.instructionSize += Size;
356 if (Size > 4 ) bca.longInstructions++;
Chris Lattner63cf59e2007-02-07 05:08:39 +0000357 bca.numOperands += NumOps;
358 for (unsigned i = 0; i != NumOps; ++i)
Reid Spencer911ec6d2004-08-21 20:58:19 +0000359 if (Operands[i] > bca.maxValueSlot)
360 bca.maxValueSlot = Operands[i];
Reid Spencercbb22e22004-06-10 22:00:54 +0000361 if ( currFunc ) {
362 currFunc->numInstructions++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000363 currFunc->instructionSize += Size;
364 if (Size > 4 ) currFunc->longInstructions++;
Chris Lattner63cf59e2007-02-07 05:08:39 +0000365 if (Opcode == Instruction::PHI) currFunc->numPhis++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000366 }
Misha Brukman8a96c532005-04-21 21:44:41 +0000367 return Instruction::isTerminator(Opcode);
Reid Spencerdac69c82004-06-07 17:53:43 +0000368 }
369
Misha Brukman8a96c532005-04-21 21:44:41 +0000370 virtual void handleBasicBlockEnd(unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000371 if (os)
Reid Spencerc6d416a2006-12-15 21:46:37 +0000372 *os << " } END BLOCK: BasicBlock #" << blocknum << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000373 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000374
Misha Brukman8a96c532005-04-21 21:44:41 +0000375 virtual void handleGlobalConstantsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000376 if (os)
377 *os << " BLOCK: GlobalConstants {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000378 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000379
Chris Lattner63cf59e2007-02-07 05:08:39 +0000380 virtual void handleConstantExpression(unsigned Opcode,
381 Constant**ArgVec, unsigned NumArgs, Constant* C) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000382 if (os) {
383 *os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000384 for ( unsigned i = 0; i != NumArgs; ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000385 *os << " Arg#" << i << " "; ArgVec[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000386 *os << "\n";
387 }
388 *os << " Value=";
389 C->print(*os);
390 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000391 }
Reid Spencer649ee572004-06-09 06:16:43 +0000392 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000393 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000394 }
395
Reid Spencercbb22e22004-06-10 22:00:54 +0000396 virtual void handleConstantValue( Constant * c ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000397 if (os) {
398 *os << " VALUE: ";
399 c->print(*os);
400 *os << "\n";
401 }
Reid Spencer649ee572004-06-09 06:16:43 +0000402 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000403 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000404 }
405
Misha Brukman8a96c532005-04-21 21:44:41 +0000406 virtual void handleConstantArray( const ArrayType* AT,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000407 Constant**Elements, unsigned NumElts,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000408 unsigned TypeSlot,
409 Constant* ArrayVal ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000410 if (os) {
411 *os << " ARRAY: ";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000412 //WriteTypeSymbolic(*os,AT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000413 *os << " TypeSlot=" << TypeSlot << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000414 for (unsigned i = 0; i != NumElts; ++i) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000415 *os << " #" << i;
416 Elements[i]->print(*os);
417 *os << "\n";
418 }
419 *os << " Value=";
420 ArrayVal->print(*os);
421 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000422 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000423
Reid Spencer649ee572004-06-09 06:16:43 +0000424 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000425 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000426 }
427
Reid Spencercbb22e22004-06-10 22:00:54 +0000428 virtual void handleConstantStruct(
Reid Spencer00c28a72004-06-10 08:09:13 +0000429 const StructType* ST,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000430 Constant**Elements, unsigned NumElts,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000431 Constant* StructVal)
Reid Spencerdac69c82004-06-07 17:53:43 +0000432 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000433 if (os) {
434 *os << " STRUC: ";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000435 //WriteTypeSymbolic(*os,ST,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000436 *os << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000437 for ( unsigned i = 0; i != NumElts; ++i) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000438 *os << " #" << i << " "; Elements[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000439 *os << "\n";
440 }
441 *os << " Value=";
442 StructVal->print(*os);
443 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000444 }
Reid Spencer649ee572004-06-09 06:16:43 +0000445 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000446 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000447 }
448
Reid Spencer9d6565a2007-02-15 02:26:10 +0000449 virtual void handleConstantVector(
450 const VectorType* PT,
Chris Lattner63cf59e2007-02-07 05:08:39 +0000451 Constant**Elements, unsigned NumElts,
Misha Brukman8a96c532005-04-21 21:44:41 +0000452 unsigned TypeSlot,
Reid Spencerac9dcb92007-02-15 03:39:18 +0000453 Constant* VectorVal)
Brian Gaeke715c90b2004-08-20 06:00:58 +0000454 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000455 if (os) {
456 *os << " PACKD: ";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000457 //WriteTypeSymbolic(*os,PT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000458 *os << " TypeSlot=" << TypeSlot << "\n";
Chris Lattner63cf59e2007-02-07 05:08:39 +0000459 for ( unsigned i = 0; i != NumElts; ++i ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000460 *os << " #" << i;
461 Elements[i]->print(*os);
462 *os << "\n";
463 }
464 *os << " Value=";
Reid Spencerac9dcb92007-02-15 03:39:18 +0000465 VectorVal->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000466 *os << "\n";
Brian Gaeke715c90b2004-08-20 06:00:58 +0000467 }
Brian Gaeke715c90b2004-08-20 06:00:58 +0000468
469 bca.numConstants++;
470 bca.numValues++;
471 }
472
Misha Brukman8a96c532005-04-21 21:44:41 +0000473 virtual void handleConstantPointer( const PointerType* PT,
Reid Spencer3c90f9f2004-07-18 00:10:36 +0000474 unsigned Slot, GlobalValue* GV ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000475 if (os) {
476 *os << " PNTR: ";
Chris Lattner4ab2d202007-04-24 17:20:52 +0000477 //WriteTypeSymbolic(*os,PT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000478 *os << " Slot=" << Slot << " GlobalValue=";
479 GV->print(*os);
480 *os << "\n";
481 }
Reid Spencer649ee572004-06-09 06:16:43 +0000482 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000483 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000484 }
485
Reid Spencercbb22e22004-06-10 22:00:54 +0000486 virtual void handleConstantString( const ConstantArray* CA ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000487 if (os) {
488 *os << " STRNG: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000489 CA->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000490 *os << "\n";
491 }
Reid Spencer649ee572004-06-09 06:16:43 +0000492 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000493 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000494 }
495
Misha Brukman8a96c532005-04-21 21:44:41 +0000496 virtual void handleGlobalConstantsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000497 if (os)
498 *os << " } END BLOCK: GlobalConstants\n";
499
Chris Lattner05ac92c2006-07-06 18:02:27 +0000500 if (bca.progressiveVerify) {
501 std::string msg;
502 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000503 bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000504 }
505 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000506
Reid Spencercbb22e22004-06-10 22:00:54 +0000507 virtual void handleAlignment(unsigned numBytes) {
Reid Spencer00c28a72004-06-10 08:09:13 +0000508 bca.numAlignment += numBytes;
Reid Spencerdac69c82004-06-07 17:53:43 +0000509 }
510
Reid Spencercbb22e22004-06-10 22:00:54 +0000511 virtual void handleBlock(
Reid Spencer00c28a72004-06-10 08:09:13 +0000512 unsigned BType, const unsigned char* StartPtr, unsigned Size) {
513 bca.numBlocks++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000514 assert(BType >= BytecodeFormat::ModuleBlockID);
515 assert(BType < BytecodeFormat::NumberOfBlockIDs);
516 bca.BlockSizes[
Reid Spencerd798a512006-11-14 04:47:22 +0000517 llvm::BytecodeFormat::BytecodeBlockIdentifiers(BType)] += Size;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000518
519 if (bca.version < 3) // Check for long block headers versions
520 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;
521 else
522 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 4;
Reid Spencer00c28a72004-06-10 08:09:13 +0000523 }
524
Reid Spencerdac69c82004-06-07 17:53:43 +0000525};
Chris Lattnerc6d0b162007-02-07 23:46:55 +0000526} // end anonymous namespace
Reid Spencerf41aa732004-06-29 23:23:12 +0000527
528/// @brief Utility for printing a titled unsigned value with
529/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000530inline static void print(std::ostream& Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000531 unsigned val, bool nl = true ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000532 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000533 << std::setw(0) << ": "
534 << std::setw(9) << val << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000535}
536
Reid Spencerf41aa732004-06-29 23:23:12 +0000537/// @brief Utility for printing a titled double value with an
538/// aligned colon
Misha Brukman8a96c532005-04-21 21:44:41 +0000539inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000540 double val ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000541 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000542 << std::setw(0) << ": "
543 << std::setw(9) << std::setprecision(6) << val << "\n" ;
544}
545
546/// @brief Utility for printing a titled double value with a
547/// percentage and aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000548inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000549 double top, double bot ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000550 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000551 << std::setw(0) << ": "
Misha Brukman8a96c532005-04-21 21:44:41 +0000552 << std::setw(9) << std::setprecision(6) << top
553 << " (" << std::left << std::setw(0) << std::setprecision(4)
Reid Spencerf41aa732004-06-29 23:23:12 +0000554 << (top/bot)*100.0 << "%)\n";
555}
556
557/// @brief Utility for printing a titled string value with
558/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000559inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000560 std::string val, bool nl = true) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000561 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000562 << std::setw(0) << ": "
563 << std::left << val << (nl ? "\n" : "");
564}
565
Reid Spencerf41aa732004-06-29 23:23:12 +0000566/// This function prints the contents of rhe BytecodeAnalysis structure in
567/// a human legible form.
568/// @brief Print BytecodeAnalysis structure to an ostream
Chris Lattnerc6d0b162007-02-07 23:46:55 +0000569void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
Reid Spencerdac69c82004-06-07 17:53:43 +0000570{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000571 Out << "\nSummary Analysis Of " << bca.ModuleId << ": \n\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000572 print(Out, "Bytecode Analysis Of Module", bca.ModuleId);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000573 print(Out, "Bytecode Version Number", bca.version);
Reid Spencerf41aa732004-06-29 23:23:12 +0000574 print(Out, "File Size", bca.byteSize);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000575 print(Out, "Module Bytes",
576 double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]),
577 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000578 print(Out, "Function Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000579 double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]),
580 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000581 print(Out, "Global Types Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000582 double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]),
583 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000584 print(Out, "Constant Pool Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000585 double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]),
586 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000587 print(Out, "Module Globals Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000588 double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]),
589 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000590 print(Out, "Instruction List Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000591 double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
592 double(bca.byteSize));
Reid Spencer78d033e2007-01-06 07:24:44 +0000593 print(Out, "Value Symbol Table Bytes",
594 double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
595 double(bca.byteSize));
596 print(Out, "Type Symbol Table Bytes",
597 double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000598 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000599 print(Out, "Alignment Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000600 double(bca.numAlignment), double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000601 print(Out, "Block Header Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000602 double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]),
603 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000604 print(Out, "Dependent Libraries Bytes", double(bca.libSize),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000605 double(bca.byteSize));
Reid Spencerf41aa732004-06-29 23:23:12 +0000606 print(Out, "Number Of Bytecode Blocks", bca.numBlocks);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000607 print(Out, "Number Of Functions", bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000608 print(Out, "Number Of Types", bca.numTypes);
Reid Spencerf41aa732004-06-29 23:23:12 +0000609 print(Out, "Number Of Constants", bca.numConstants);
610 print(Out, "Number Of Global Variables", bca.numGlobalVars);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000611 print(Out, "Number Of Values", bca.numValues);
Reid Spencerf41aa732004-06-29 23:23:12 +0000612 print(Out, "Number Of Basic Blocks", bca.numBasicBlocks);
613 print(Out, "Number Of Instructions", bca.numInstructions);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000614 print(Out, "Number Of Long Instructions", bca.longInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000615 print(Out, "Number Of Operands", bca.numOperands);
Reid Spencerf41aa732004-06-29 23:23:12 +0000616 print(Out, "Number Of Symbol Tables", bca.numSymTab);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000617 print(Out, "Number Of Dependent Libs", bca.numLibraries);
618 print(Out, "Total Instruction Size", bca.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000619 print(Out, "Average Instruction Size",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000620 double(bca.instructionSize)/double(bca.numInstructions));
621
Reid Spencerf41aa732004-06-29 23:23:12 +0000622 print(Out, "Maximum Type Slot Number", bca.maxTypeSlot);
623 print(Out, "Maximum Value Slot Number", bca.maxValueSlot);
Reid Spencer3120e712004-08-24 22:45:32 +0000624 print(Out, "Bytes Per Value ", bca.fileDensity);
625 print(Out, "Bytes Per Global", bca.globalsDensity);
626 print(Out, "Bytes Per Function", bca.functionDensity);
Reid Spencerf41aa732004-06-29 23:23:12 +0000627
Reid Spencer911ec6d2004-08-21 20:58:19 +0000628 if (bca.detailedResults) {
629 Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000630
Misha Brukman8a96c532005-04-21 21:44:41 +0000631 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
Reid Spencerf41aa732004-06-29 23:23:12 +0000632 bca.FunctionInfo.begin();
Misha Brukman8a96c532005-04-21 21:44:41 +0000633 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
Reid Spencerf41aa732004-06-29 23:23:12 +0000634 bca.FunctionInfo.end();
635
636 while ( I != E ) {
Chris Lattner4a8167f2004-10-15 19:40:31 +0000637 Out << std::left << std::setw(0) << "\n";
638 if (I->second.numBasicBlocks == 0) Out << "External ";
639 Out << "Function: " << I->second.name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000640 print(Out, "Type:", I->second.description);
641 print(Out, "Byte Size", I->second.byteSize);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000642 if (I->second.numBasicBlocks) {
643 print(Out, "Basic Blocks", I->second.numBasicBlocks);
644 print(Out, "Instructions", I->second.numInstructions);
645 print(Out, "Long Instructions", I->second.longInstructions);
646 print(Out, "Operands", I->second.numOperands);
647 print(Out, "Instruction Size", I->second.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000648 print(Out, "Average Instruction Size",
Chris Lattner4a8167f2004-10-15 19:40:31 +0000649 double(I->second.instructionSize) / I->second.numInstructions);
650 print(Out, "Bytes Per Instruction", I->second.density);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000651 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000652 ++I;
653 }
654 }
655
Reid Spencerf41aa732004-06-29 23:23:12 +0000656 if ( bca.progressiveVerify )
657 Out << bca.VerifyInfo;
658}
659
Chris Lattnerc6d0b162007-02-07 23:46:55 +0000660// AnalyzeBytecodeFile - analyze one file
661Module* llvm::AnalyzeBytecodeFile(const std::string &Filename, ///< File to analyze
662 BytecodeAnalysis& bca, ///< Statistical output
663 BCDecompressor_t *BCDC,
664 std::string *ErrMsg, ///< Error output
665 std::ostream* output ///< Dump output
666 ) {
667 BytecodeHandler* AH = new AnalyzerHandler(bca, output);
668 ModuleProvider* MP = getBytecodeModuleProvider(Filename, BCDC, ErrMsg, AH);
669 if (!MP) return 0;
670 Module *M = MP->releaseModule(ErrMsg);
671 delete MP;
672 return M;
Reid Spencerf41aa732004-06-29 23:23:12 +0000673}