blob: 465e3b053e96f9c380235f8b10cd937091849b89 [file] [log] [blame]
Reid Spencerf41aa732004-06-29 23:23:12 +00001//===-- Analyzer.cpp - Analysis and Dumping of Bytecode 000000---*- 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 +000029
30using namespace llvm;
31
Reid Spencerdac69c82004-06-07 17:53:43 +000032namespace {
33
Reid Spencerf41aa732004-06-29 23:23:12 +000034/// @brief Bytecode reading handler for analyzing bytecode.
Reid Spencerdac69c82004-06-07 17:53:43 +000035class AnalyzerHandler : public BytecodeHandler {
Reid Spencerf41aa732004-06-29 23:23:12 +000036 BytecodeAnalysis& bca; ///< The structure in which data is recorded
Reid Spencer911ec6d2004-08-21 20:58:19 +000037 std::ostream* os; ///< A convenience for osing data.
Reid Spencerf41aa732004-06-29 23:23:12 +000038 /// @brief Keeps track of current function
Misha Brukman8a96c532005-04-21 21:44:41 +000039 BytecodeAnalysis::BytecodeFunctionInfo* currFunc;
Reid Spencerf41aa732004-06-29 23:23:12 +000040 Module* M; ///< Keeps track of current module
41
42/// @name Constructor
43/// @{
Reid Spencerdac69c82004-06-07 17:53:43 +000044public:
Reid Spencerf41aa732004-06-29 23:23:12 +000045 /// The only way to construct an AnalyzerHandler. All that is needed is a
46 /// reference to the BytecodeAnalysis structure where the output will be
47 /// placed.
Misha Brukman8a96c532005-04-21 21:44:41 +000048 AnalyzerHandler(BytecodeAnalysis& TheBca, std::ostream* output)
49 : bca(TheBca)
Reid Spencer911ec6d2004-08-21 20:58:19 +000050 , os(output)
Reid Spencercbb22e22004-06-10 22:00:54 +000051 , currFunc(0)
Reid Spencer911ec6d2004-08-21 20:58:19 +000052 { }
Reid Spencer649ee572004-06-09 06:16:43 +000053
Reid Spencerf41aa732004-06-29 23:23:12 +000054/// @}
55/// @name BytecodeHandler Implementations
56/// @{
57public:
Misha Brukman8a96c532005-04-21 21:44:41 +000058 virtual void handleError(const std::string& str ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +000059 if (os)
60 *os << "ERROR: " << str << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +000061 }
62
Reid Spencerf41aa732004-06-29 23:23:12 +000063 virtual void handleStart( Module* Mod, unsigned theSize ) {
64 M = Mod;
Reid Spencer911ec6d2004-08-21 20:58:19 +000065 if (os)
66 *os << "Bytecode {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +000067 bca.byteSize = theSize;
Reid Spencer649ee572004-06-09 06:16:43 +000068 bca.ModuleId.clear();
Reid Spencer00c28a72004-06-10 08:09:13 +000069 bca.numBlocks = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000070 bca.numTypes = 0;
71 bca.numValues = 0;
72 bca.numFunctions = 0;
73 bca.numConstants = 0;
74 bca.numGlobalVars = 0;
75 bca.numInstructions = 0;
76 bca.numBasicBlocks = 0;
77 bca.numOperands = 0;
78 bca.numCmpctnTables = 0;
79 bca.numSymTab = 0;
Reid Spencer911ec6d2004-08-21 20:58:19 +000080 bca.numLibraries = 0;
81 bca.libSize = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000082 bca.maxTypeSlot = 0;
83 bca.maxValueSlot = 0;
Reid Spencer00c28a72004-06-10 08:09:13 +000084 bca.numAlignment = 0;
85 bca.fileDensity = 0.0;
86 bca.globalsDensity = 0.0;
87 bca.functionDensity = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +000088 bca.instructionSize = 0;
89 bca.longInstructions = 0;
Reid Spencer00c28a72004-06-10 08:09:13 +000090 bca.vbrCount32 = 0;
91 bca.vbrCount64 = 0;
92 bca.vbrCompBytes = 0;
93 bca.vbrExpdBytes = 0;
Reid Spencer649ee572004-06-09 06:16:43 +000094 bca.FunctionInfo.clear();
Reid Spencer911ec6d2004-08-21 20:58:19 +000095 bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse] = 0;
96 bca.BlockSizes[BytecodeFormat::ModuleBlockID] = theSize;
97 bca.BlockSizes[BytecodeFormat::FunctionBlockID] = 0;
98 bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID] = 0;
Reid Spencer78d033e2007-01-06 07:24:44 +000099 bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID] = 0;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000100 bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
101 bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
102 bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
103 bca.BlockSizes[BytecodeFormat::CompactionTableBlockID] = 0;
Reid Spencer78d033e2007-01-06 07:24:44 +0000104 bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
Reid Spencerdac69c82004-06-07 17:53:43 +0000105 }
106
Reid Spencercbb22e22004-06-10 22:00:54 +0000107 virtual void handleFinish() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000108 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000109 *os << "} End Bytecode\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000110
Reid Spencer00c28a72004-06-10 08:09:13 +0000111 bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
112 double globalSize = 0.0;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000113 globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]);
114 globalSize += double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]);
115 globalSize += double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]);
Misha Brukman8a96c532005-04-21 21:44:41 +0000116 bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants +
Reid Spencer00c28a72004-06-10 08:09:13 +0000117 bca.numGlobalVars );
Misha Brukman8a96c532005-04-21 21:44:41 +0000118 bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) /
Reid Spencer00c28a72004-06-10 08:09:13 +0000119 double(bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000120
Chris Lattner05ac92c2006-07-06 18:02:27 +0000121 if (bca.progressiveVerify) {
122 std::string msg;
123 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000124 bca.VerifyInfo += "Verify@Finish: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000125 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000126 }
127
Reid Spencercbb22e22004-06-10 22:00:54 +0000128 virtual void handleModuleBegin(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000129 if (os)
130 *os << " Module " << id << " {\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000131 bca.ModuleId = id;
Reid Spencerdac69c82004-06-07 17:53:43 +0000132 }
133
Misha Brukman8a96c532005-04-21 21:44:41 +0000134 virtual void handleModuleEnd(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000135 if (os)
136 *os << " } End Module " << id << "\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000137 if (bca.progressiveVerify) {
138 std::string msg;
139 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000140 bca.VerifyInfo += "Verify@EndModule: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000141 }
142 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000143
Reid Spencercbb22e22004-06-10 22:00:54 +0000144 virtual void handleVersionInfo(
Reid Spencerdac69c82004-06-07 17:53:43 +0000145 unsigned char RevisionNum, ///< Byte code revision number
146 Module::Endianness Endianness, ///< Endianness indicator
147 Module::PointerSize PointerSize ///< PointerSize indicator
Misha Brukman8a96c532005-04-21 21:44:41 +0000148 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000149 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000150 *os << " RevisionNum: " << int(RevisionNum)
Reid Spencerb61cdb72004-07-04 11:00:39 +0000151 << " Endianness: " << Endianness
152 << " PointerSize: " << PointerSize << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000153 bca.version = RevisionNum;
Reid Spencerf41aa732004-06-29 23:23:12 +0000154 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000155
Misha Brukman8a96c532005-04-21 21:44:41 +0000156 virtual void handleModuleGlobalsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000157 if (os)
158 *os << " BLOCK: ModuleGlobalInfo {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000159 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000160
Misha Brukman8a96c532005-04-21 21:44:41 +0000161 virtual void handleGlobalVariable(
162 const Type* ElemType,
163 bool isConstant,
Reid Spencerf41aa732004-06-29 23:23:12 +0000164 GlobalValue::LinkageTypes Linkage,
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000165 GlobalValue::VisibilityTypes Visibility,
Reid Spencerf41aa732004-06-29 23:23:12 +0000166 unsigned SlotNum,
167 unsigned initSlot
Reid Spencercbb22e22004-06-10 22:00:54 +0000168 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000169 if (os) {
170 *os << " GV: "
171 << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, "
172 << ( isConstant? "Constant, " : "Variable, ")
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000173 << " Linkage=" << Linkage
174 << " Visibility="<< Visibility
175 << " Type=";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000176 WriteTypeSymbolic(*os, ElemType, M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000177 *os << " Slot=" << SlotNum << " InitSlot=" << initSlot
Reid Spencer911ec6d2004-08-21 20:58:19 +0000178 << "\n";
179 }
180
Reid Spencer649ee572004-06-09 06:16:43 +0000181 bca.numGlobalVars++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000182 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000183 if (SlotNum > bca.maxValueSlot)
184 bca.maxValueSlot = SlotNum;
185 if (initSlot > bca.maxValueSlot)
186 bca.maxValueSlot = initSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000187
Reid Spencer911ec6d2004-08-21 20:58:19 +0000188 }
189
190 virtual void handleTypeList(unsigned numEntries) {
191 bca.maxTypeSlot = numEntries - 1;
Reid Spencerdac69c82004-06-07 17:53:43 +0000192 }
193
Misha Brukman8a96c532005-04-21 21:44:41 +0000194 virtual void handleType( const Type* Ty ) {
195 bca.numTypes++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000196 if (os) {
197 *os << " Type: ";
198 WriteTypeSymbolic(*os,Ty,M);
199 *os << "\n";
200 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000201 }
202
Misha Brukman8a96c532005-04-21 21:44:41 +0000203 virtual void handleFunctionDeclaration(
Reid Spencerb61cdb72004-07-04 11:00:39 +0000204 Function* Func ///< The function
Reid Spencercbb22e22004-06-10 22:00:54 +0000205 ) {
Reid Spencer649ee572004-06-09 06:16:43 +0000206 bca.numFunctions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000207 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000208 if (os) {
209 *os << " Function Decl: ";
210 WriteTypeSymbolic(*os,Func->getType(),M);
Anton Korobeynikov93c2b372006-09-17 13:06:18 +0000211 *os <<", Linkage=" << Func->getLinkage();
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000212 *os <<", Visibility=" << Func->getVisibility();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000213 *os << "\n";
214 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000215 }
216
Reid Spencerf41aa732004-06-29 23:23:12 +0000217 virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000218 if (os) {
219 *os << " Initializer: GV=";
220 GV->print(*os);
221 *os << " CV=";
222 CV->print(*os);
223 *os << "\n";
224 }
225 }
226
227 virtual void handleDependentLibrary(const std::string& libName) {
228 bca.numLibraries++;
229 bca.libSize += libName.size() + (libName.size() < 128 ? 1 : 2);
Reid Spencer3ee8eed2004-09-11 04:14:07 +0000230 if (os)
231 *os << " Library: '" << libName << "'\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000232 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000233
Misha Brukman8a96c532005-04-21 21:44:41 +0000234 virtual void handleModuleGlobalsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000235 if (os)
236 *os << " } END BLOCK: ModuleGlobalInfo\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000237 if (bca.progressiveVerify) {
238 std::string msg;
239 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000240 bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000241 }
242 }
243
Misha Brukman8a96c532005-04-21 21:44:41 +0000244 virtual void handleCompactionTableBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000245 if (os)
246 *os << " BLOCK: CompactionTable {\n";
Reid Spencer488d73a2004-08-27 00:43:51 +0000247 bca.numCmpctnTables++;
Reid Spencerf41aa732004-06-29 23:23:12 +0000248 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000249
Reid Spencercbb22e22004-06-10 22:00:54 +0000250 virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000251 if (os)
252 *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000253 }
254
Misha Brukman8a96c532005-04-21 21:44:41 +0000255 virtual void handleCompactionTableType( unsigned i, unsigned TypSlot,
Reid Spencerf41aa732004-06-29 23:23:12 +0000256 const Type* Ty ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000257 if (os) {
258 *os << " Type: " << i << " Slot:" << TypSlot << " is ";
259 WriteTypeSymbolic(*os,Ty,M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000260 *os << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000261 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000262 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000263
Chris Lattner2c6c14d2004-08-04 00:19:23 +0000264 virtual void handleCompactionTableValue(unsigned i, unsigned TypSlot,
Misha Brukman8a96c532005-04-21 21:44:41 +0000265 unsigned ValSlot) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000266 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000267 *os << " Value: " << i << " TypSlot: " << TypSlot
Chris Lattner2c6c14d2004-08-04 00:19:23 +0000268 << " ValSlot:" << ValSlot << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000269 if (ValSlot > bca.maxValueSlot)
270 bca.maxValueSlot = ValSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000271 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000272
Misha Brukman8a96c532005-04-21 21:44:41 +0000273 virtual void handleCompactionTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000274 if (os)
275 *os << " } END BLOCK: CompactionTable\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000276 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000277
Misha Brukman8a96c532005-04-21 21:44:41 +0000278 virtual void handleSymbolTableBegin(Function* CF, SymbolTable* ST) {
279 bca.numSymTab++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000280 if (os)
281 *os << " BLOCK: SymbolTable {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000282 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000283
Misha Brukman8a96c532005-04-21 21:44:41 +0000284 virtual void handleSymbolTablePlane(unsigned Ty, unsigned NumEntries,
285 const Type* Typ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000286 if (os) {
287 *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << " Type: ";
288 WriteTypeSymbolic(*os,Typ,M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000289 *os << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000290 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000291 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000292
Misha Brukman8a96c532005-04-21 21:44:41 +0000293 virtual void handleSymbolTableType(unsigned i, unsigned TypSlot,
294 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000295 if (os)
296 *os << " Type " << i << " Slot=" << TypSlot
Misha Brukman8a96c532005-04-21 21:44:41 +0000297 << " Name: " << name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000298 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000299
Misha Brukman8a96c532005-04-21 21:44:41 +0000300 virtual void handleSymbolTableValue(unsigned i, unsigned ValSlot,
301 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000302 if (os)
303 *os << " Value " << i << " Slot=" << ValSlot
304 << " Name: " << name << "\n";
305 if (ValSlot > bca.maxValueSlot)
306 bca.maxValueSlot = ValSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000307 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000308
Misha Brukman8a96c532005-04-21 21:44:41 +0000309 virtual void handleSymbolTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000310 if (os)
311 *os << " } END BLOCK: SymbolTable\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000312 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000313
Reid Spencerf41aa732004-06-29 23:23:12 +0000314 virtual void handleFunctionBegin(Function* Func, unsigned Size) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000315 if (os) {
316 *os << " BLOCK: Function {\n"
317 << " Linkage: " << Func->getLinkage() << "\n"
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000318 << " Visibility: " << Func->getVisibility() << "\n"
Misha Brukman8a96c532005-04-21 21:44:41 +0000319 << " Type: ";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000320 WriteTypeSymbolic(*os,Func->getType(),M);
321 *os << "\n";
322 }
323
Reid Spencercbb22e22004-06-10 22:00:54 +0000324 currFunc = &bca.FunctionInfo[Func];
Reid Spencer911ec6d2004-08-21 20:58:19 +0000325 std::ostringstream tmp;
326 WriteTypeSymbolic(tmp,Func->getType(),M);
327 currFunc->description = tmp.str();
Reid Spencercbb22e22004-06-10 22:00:54 +0000328 currFunc->name = Func->getName();
329 currFunc->byteSize = Size;
330 currFunc->numInstructions = 0;
331 currFunc->numBasicBlocks = 0;
332 currFunc->numPhis = 0;
333 currFunc->numOperands = 0;
334 currFunc->density = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +0000335 currFunc->instructionSize = 0;
336 currFunc->longInstructions = 0;
Reid Spencercbb22e22004-06-10 22:00:54 +0000337 currFunc->vbrCount32 = 0;
338 currFunc->vbrCount64 = 0;
339 currFunc->vbrCompBytes = 0;
340 currFunc->vbrExpdBytes = 0;
Reid Spencerf41aa732004-06-29 23:23:12 +0000341
Reid Spencerdac69c82004-06-07 17:53:43 +0000342 }
343
Reid Spencercbb22e22004-06-10 22:00:54 +0000344 virtual void handleFunctionEnd( Function* Func) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000345 if (os)
346 *os << " } END BLOCK: Function\n";
Reid Spencercbb22e22004-06-10 22:00:54 +0000347 currFunc->density = double(currFunc->byteSize) /
Reid Spencer3120e712004-08-24 22:45:32 +0000348 double(currFunc->numInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000349
Chris Lattner05ac92c2006-07-06 18:02:27 +0000350 if (bca.progressiveVerify) {
351 std::string msg;
352 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000353 bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000354 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000355 }
356
Reid Spencercbb22e22004-06-10 22:00:54 +0000357 virtual void handleBasicBlockBegin( unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000358 if (os)
359 *os << " BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000360 bca.numBasicBlocks++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000361 bca.numValues++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000362 if ( currFunc ) currFunc->numBasicBlocks++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000363 }
364
Misha Brukman8a96c532005-04-21 21:44:41 +0000365 virtual bool handleInstruction( unsigned Opcode, const Type* iType,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000366 std::vector<unsigned>& Operands, unsigned Size){
Reid Spencer911ec6d2004-08-21 20:58:19 +0000367 if (os) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000368 *os << " INST: OpCode="
Reid Spencer911ec6d2004-08-21 20:58:19 +0000369 << Instruction::getOpcodeName(Opcode) << " Type=\"";
370 WriteTypeSymbolic(*os,iType,M);
371 *os << "\"";
Misha Brukman8a96c532005-04-21 21:44:41 +0000372 for ( unsigned i = 0; i < Operands.size(); ++i )
Reid Spencer911ec6d2004-08-21 20:58:19 +0000373 *os << " Op(" << i << ")=Slot(" << Operands[i] << ")";
374 *os << "\n";
375 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000376
Reid Spencer649ee572004-06-09 06:16:43 +0000377 bca.numInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000378 bca.numValues++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000379 bca.instructionSize += Size;
380 if (Size > 4 ) bca.longInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000381 bca.numOperands += Operands.size();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000382 for (unsigned i = 0; i < Operands.size(); ++i )
383 if (Operands[i] > bca.maxValueSlot)
384 bca.maxValueSlot = Operands[i];
Reid Spencercbb22e22004-06-10 22:00:54 +0000385 if ( currFunc ) {
386 currFunc->numInstructions++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000387 currFunc->instructionSize += Size;
388 if (Size > 4 ) currFunc->longInstructions++;
Reid Spencer8a9a3702004-06-11 03:06:43 +0000389 if ( Opcode == Instruction::PHI ) currFunc->numPhis++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000390 }
Misha Brukman8a96c532005-04-21 21:44:41 +0000391 return Instruction::isTerminator(Opcode);
Reid Spencerdac69c82004-06-07 17:53:43 +0000392 }
393
Misha Brukman8a96c532005-04-21 21:44:41 +0000394 virtual void handleBasicBlockEnd(unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000395 if (os)
Reid Spencerc6d416a2006-12-15 21:46:37 +0000396 *os << " } END BLOCK: BasicBlock #" << blocknum << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000397 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000398
Misha Brukman8a96c532005-04-21 21:44:41 +0000399 virtual void handleGlobalConstantsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000400 if (os)
401 *os << " BLOCK: GlobalConstants {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000402 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000403
Misha Brukman8a96c532005-04-21 21:44:41 +0000404 virtual void handleConstantExpression( unsigned Opcode,
Reid Spencerf41aa732004-06-29 23:23:12 +0000405 std::vector<Constant*> ArgVec, Constant* C ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000406 if (os) {
407 *os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
408 for ( unsigned i = 0; i < ArgVec.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000409 *os << " Arg#" << i << " "; ArgVec[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000410 *os << "\n";
411 }
412 *os << " Value=";
413 C->print(*os);
414 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000415 }
Reid Spencer649ee572004-06-09 06:16:43 +0000416 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000417 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000418 }
419
Reid Spencercbb22e22004-06-10 22:00:54 +0000420 virtual void handleConstantValue( Constant * c ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000421 if (os) {
422 *os << " VALUE: ";
423 c->print(*os);
424 *os << "\n";
425 }
Reid Spencer649ee572004-06-09 06:16:43 +0000426 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000427 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000428 }
429
Misha Brukman8a96c532005-04-21 21:44:41 +0000430 virtual void handleConstantArray( const ArrayType* AT,
Reid Spencerf41aa732004-06-29 23:23:12 +0000431 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000432 unsigned TypeSlot,
433 Constant* ArrayVal ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000434 if (os) {
435 *os << " ARRAY: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000436 WriteTypeSymbolic(*os,AT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000437 *os << " TypeSlot=" << TypeSlot << "\n";
438 for ( unsigned i = 0; i < Elements.size(); ++i ) {
439 *os << " #" << i;
440 Elements[i]->print(*os);
441 *os << "\n";
442 }
443 *os << " Value=";
444 ArrayVal->print(*os);
445 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000446 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000447
Reid Spencer649ee572004-06-09 06:16:43 +0000448 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000449 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000450 }
451
Reid Spencercbb22e22004-06-10 22:00:54 +0000452 virtual void handleConstantStruct(
Reid Spencer00c28a72004-06-10 08:09:13 +0000453 const StructType* ST,
Reid Spencerf41aa732004-06-29 23:23:12 +0000454 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000455 Constant* StructVal)
Reid Spencerdac69c82004-06-07 17:53:43 +0000456 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000457 if (os) {
458 *os << " STRUC: ";
459 WriteTypeSymbolic(*os,ST,M);
460 *os << "\n";
461 for ( unsigned i = 0; i < Elements.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000462 *os << " #" << i << " "; Elements[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000463 *os << "\n";
464 }
465 *os << " Value=";
466 StructVal->print(*os);
467 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000468 }
Reid Spencer649ee572004-06-09 06:16:43 +0000469 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000470 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000471 }
472
Misha Brukman8a96c532005-04-21 21:44:41 +0000473 virtual void handleConstantPacked(
474 const PackedType* PT,
Brian Gaeke715c90b2004-08-20 06:00:58 +0000475 std::vector<Constant*>& Elements,
Misha Brukman8a96c532005-04-21 21:44:41 +0000476 unsigned TypeSlot,
477 Constant* PackedVal)
Brian Gaeke715c90b2004-08-20 06:00:58 +0000478 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000479 if (os) {
480 *os << " PACKD: ";
481 WriteTypeSymbolic(*os,PT,M);
482 *os << " TypeSlot=" << TypeSlot << "\n";
483 for ( unsigned i = 0; i < Elements.size(); ++i ) {
484 *os << " #" << i;
485 Elements[i]->print(*os);
486 *os << "\n";
487 }
488 *os << " Value=";
489 PackedVal->print(*os);
490 *os << "\n";
Brian Gaeke715c90b2004-08-20 06:00:58 +0000491 }
Brian Gaeke715c90b2004-08-20 06:00:58 +0000492
493 bca.numConstants++;
494 bca.numValues++;
495 }
496
Misha Brukman8a96c532005-04-21 21:44:41 +0000497 virtual void handleConstantPointer( const PointerType* PT,
Reid Spencer3c90f9f2004-07-18 00:10:36 +0000498 unsigned Slot, GlobalValue* GV ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000499 if (os) {
500 *os << " PNTR: ";
501 WriteTypeSymbolic(*os,PT,M);
502 *os << " Slot=" << Slot << " GlobalValue=";
503 GV->print(*os);
504 *os << "\n";
505 }
Reid Spencer649ee572004-06-09 06:16:43 +0000506 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000507 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000508 }
509
Reid Spencercbb22e22004-06-10 22:00:54 +0000510 virtual void handleConstantString( const ConstantArray* CA ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000511 if (os) {
512 *os << " STRNG: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000513 CA->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000514 *os << "\n";
515 }
Reid Spencer649ee572004-06-09 06:16:43 +0000516 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000517 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000518 }
519
Misha Brukman8a96c532005-04-21 21:44:41 +0000520 virtual void handleGlobalConstantsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000521 if (os)
522 *os << " } END BLOCK: GlobalConstants\n";
523
Chris Lattner05ac92c2006-07-06 18:02:27 +0000524 if (bca.progressiveVerify) {
525 std::string msg;
526 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000527 bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000528 }
529 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000530
Reid Spencercbb22e22004-06-10 22:00:54 +0000531 virtual void handleAlignment(unsigned numBytes) {
Reid Spencer00c28a72004-06-10 08:09:13 +0000532 bca.numAlignment += numBytes;
Reid Spencerdac69c82004-06-07 17:53:43 +0000533 }
534
Reid Spencercbb22e22004-06-10 22:00:54 +0000535 virtual void handleBlock(
Reid Spencer00c28a72004-06-10 08:09:13 +0000536 unsigned BType, const unsigned char* StartPtr, unsigned Size) {
537 bca.numBlocks++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000538 assert(BType >= BytecodeFormat::ModuleBlockID);
539 assert(BType < BytecodeFormat::NumberOfBlockIDs);
540 bca.BlockSizes[
Reid Spencerd798a512006-11-14 04:47:22 +0000541 llvm::BytecodeFormat::BytecodeBlockIdentifiers(BType)] += Size;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000542
543 if (bca.version < 3) // Check for long block headers versions
544 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;
545 else
546 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 4;
Reid Spencer00c28a72004-06-10 08:09:13 +0000547 }
548
549 virtual void handleVBR32(unsigned Size ) {
550 bca.vbrCount32++;
551 bca.vbrCompBytes += Size;
552 bca.vbrExpdBytes += sizeof(uint32_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000553 if (currFunc) {
554 currFunc->vbrCount32++;
555 currFunc->vbrCompBytes += Size;
556 currFunc->vbrExpdBytes += sizeof(uint32_t);
557 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000558 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000559
Reid Spencer00c28a72004-06-10 08:09:13 +0000560 virtual void handleVBR64(unsigned Size ) {
561 bca.vbrCount64++;
562 bca.vbrCompBytes += Size;
563 bca.vbrExpdBytes += sizeof(uint64_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000564 if ( currFunc ) {
565 currFunc->vbrCount64++;
566 currFunc->vbrCompBytes += Size;
567 currFunc->vbrExpdBytes += sizeof(uint64_t);
568 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000569 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000570};
571
Reid Spencerf41aa732004-06-29 23:23:12 +0000572
573/// @brief Utility for printing a titled unsigned value with
574/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000575inline static void print(std::ostream& Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000576 unsigned val, bool nl = true ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000577 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000578 << std::setw(0) << ": "
579 << std::setw(9) << val << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000580}
581
Reid Spencerf41aa732004-06-29 23:23:12 +0000582/// @brief Utility for printing a titled double value with an
583/// aligned colon
Misha Brukman8a96c532005-04-21 21:44:41 +0000584inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000585 double val ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000586 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000587 << std::setw(0) << ": "
588 << std::setw(9) << std::setprecision(6) << val << "\n" ;
589}
590
591/// @brief Utility for printing a titled double value with a
592/// percentage and aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000593inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000594 double top, double bot ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000595 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000596 << std::setw(0) << ": "
Misha Brukman8a96c532005-04-21 21:44:41 +0000597 << std::setw(9) << std::setprecision(6) << top
598 << " (" << std::left << std::setw(0) << std::setprecision(4)
Reid Spencerf41aa732004-06-29 23:23:12 +0000599 << (top/bot)*100.0 << "%)\n";
600}
601
602/// @brief Utility for printing a titled string value with
603/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000604inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000605 std::string val, bool nl = true) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000606 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000607 << std::setw(0) << ": "
608 << std::left << val << (nl ? "\n" : "");
609}
610
611}
612
613namespace llvm {
614
615/// This function prints the contents of rhe BytecodeAnalysis structure in
616/// a human legible form.
617/// @brief Print BytecodeAnalysis structure to an ostream
618void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
Reid Spencerdac69c82004-06-07 17:53:43 +0000619{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000620 Out << "\nSummary Analysis Of " << bca.ModuleId << ": \n\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000621 print(Out, "Bytecode Analysis Of Module", bca.ModuleId);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000622 print(Out, "Bytecode Version Number", bca.version);
Reid Spencerf41aa732004-06-29 23:23:12 +0000623 print(Out, "File Size", bca.byteSize);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000624 print(Out, "Module Bytes",
625 double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]),
626 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000627 print(Out, "Function Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000628 double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]),
629 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000630 print(Out, "Global Types Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000631 double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]),
632 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000633 print(Out, "Constant Pool Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000634 double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]),
635 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000636 print(Out, "Module Globals Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000637 double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]),
638 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000639 print(Out, "Instruction List Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000640 double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
641 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000642 print(Out, "Compaction Table Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000643 double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]),
644 double(bca.byteSize));
Reid Spencer78d033e2007-01-06 07:24:44 +0000645 print(Out, "Value Symbol Table Bytes",
646 double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
647 double(bca.byteSize));
648 print(Out, "Type Symbol Table Bytes",
649 double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000650 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000651 print(Out, "Alignment Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000652 double(bca.numAlignment), double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000653 print(Out, "Block Header Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000654 double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]),
655 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000656 print(Out, "Dependent Libraries Bytes", double(bca.libSize),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000657 double(bca.byteSize));
Reid Spencerf41aa732004-06-29 23:23:12 +0000658 print(Out, "Number Of Bytecode Blocks", bca.numBlocks);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000659 print(Out, "Number Of Functions", bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000660 print(Out, "Number Of Types", bca.numTypes);
Reid Spencerf41aa732004-06-29 23:23:12 +0000661 print(Out, "Number Of Constants", bca.numConstants);
662 print(Out, "Number Of Global Variables", bca.numGlobalVars);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000663 print(Out, "Number Of Values", bca.numValues);
Reid Spencerf41aa732004-06-29 23:23:12 +0000664 print(Out, "Number Of Basic Blocks", bca.numBasicBlocks);
665 print(Out, "Number Of Instructions", bca.numInstructions);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000666 print(Out, "Number Of Long Instructions", bca.longInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000667 print(Out, "Number Of Operands", bca.numOperands);
668 print(Out, "Number Of Compaction Tables", bca.numCmpctnTables);
669 print(Out, "Number Of Symbol Tables", bca.numSymTab);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000670 print(Out, "Number Of Dependent Libs", bca.numLibraries);
671 print(Out, "Total Instruction Size", bca.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000672 print(Out, "Average Instruction Size",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000673 double(bca.instructionSize)/double(bca.numInstructions));
674
Reid Spencerf41aa732004-06-29 23:23:12 +0000675 print(Out, "Maximum Type Slot Number", bca.maxTypeSlot);
676 print(Out, "Maximum Value Slot Number", bca.maxValueSlot);
Reid Spencer3120e712004-08-24 22:45:32 +0000677 print(Out, "Bytes Per Value ", bca.fileDensity);
678 print(Out, "Bytes Per Global", bca.globalsDensity);
679 print(Out, "Bytes Per Function", bca.functionDensity);
680 print(Out, "# of VBR 32-bit Integers", bca.vbrCount32);
681 print(Out, "# of VBR 64-bit Integers", bca.vbrCount64);
682 print(Out, "# of VBR Compressed Bytes", bca.vbrCompBytes);
683 print(Out, "# of VBR Expanded Bytes", bca.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000684 print(Out, "Bytes Saved With VBR",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000685 double(bca.vbrExpdBytes)-double(bca.vbrCompBytes),
686 double(bca.vbrExpdBytes));
Reid Spencerf41aa732004-06-29 23:23:12 +0000687
Reid Spencer911ec6d2004-08-21 20:58:19 +0000688 if (bca.detailedResults) {
689 Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000690
Misha Brukman8a96c532005-04-21 21:44:41 +0000691 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
Reid Spencerf41aa732004-06-29 23:23:12 +0000692 bca.FunctionInfo.begin();
Misha Brukman8a96c532005-04-21 21:44:41 +0000693 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
Reid Spencerf41aa732004-06-29 23:23:12 +0000694 bca.FunctionInfo.end();
695
696 while ( I != E ) {
Chris Lattner4a8167f2004-10-15 19:40:31 +0000697 Out << std::left << std::setw(0) << "\n";
698 if (I->second.numBasicBlocks == 0) Out << "External ";
699 Out << "Function: " << I->second.name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000700 print(Out, "Type:", I->second.description);
701 print(Out, "Byte Size", I->second.byteSize);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000702 if (I->second.numBasicBlocks) {
703 print(Out, "Basic Blocks", I->second.numBasicBlocks);
704 print(Out, "Instructions", I->second.numInstructions);
705 print(Out, "Long Instructions", I->second.longInstructions);
706 print(Out, "Operands", I->second.numOperands);
707 print(Out, "Instruction Size", I->second.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000708 print(Out, "Average Instruction Size",
Chris Lattner4a8167f2004-10-15 19:40:31 +0000709 double(I->second.instructionSize) / I->second.numInstructions);
710 print(Out, "Bytes Per Instruction", I->second.density);
711 print(Out, "# of VBR 32-bit Integers", I->second.vbrCount32);
712 print(Out, "# of VBR 64-bit Integers", I->second.vbrCount64);
713 print(Out, "# of VBR Compressed Bytes", I->second.vbrCompBytes);
714 print(Out, "# of VBR Expanded Bytes", I->second.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000715 print(Out, "Bytes Saved With VBR",
Reid Spencere03f09c2006-11-03 01:44:51 +0000716 double(I->second.vbrExpdBytes) - I->second.vbrCompBytes);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000717 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000718 ++I;
719 }
720 }
721
Reid Spencerf41aa732004-06-29 23:23:12 +0000722 if ( bca.progressiveVerify )
723 Out << bca.VerifyInfo;
724}
725
Reid Spencer911ec6d2004-08-21 20:58:19 +0000726BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca,
727 std::ostream* output)
Reid Spencerf41aa732004-06-29 23:23:12 +0000728{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000729 return new AnalyzerHandler(bca,output);
Reid Spencerf41aa732004-06-29 23:23:12 +0000730}
731
Reid Spencerdac69c82004-06-07 17:53:43 +0000732}
733