blob: 64907a8e80d1465a51cfabf2222f84ef327810c2 [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;
Reid Spencer78d033e2007-01-06 07:24:44 +0000103 bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
Reid Spencerdac69c82004-06-07 17:53:43 +0000104 }
105
Reid Spencercbb22e22004-06-10 22:00:54 +0000106 virtual void handleFinish() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000107 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000108 *os << "} End Bytecode\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000109
Reid Spencer00c28a72004-06-10 08:09:13 +0000110 bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
111 double globalSize = 0.0;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000112 globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]);
113 globalSize += double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]);
114 globalSize += double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]);
Misha Brukman8a96c532005-04-21 21:44:41 +0000115 bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants +
Reid Spencer00c28a72004-06-10 08:09:13 +0000116 bca.numGlobalVars );
Misha Brukman8a96c532005-04-21 21:44:41 +0000117 bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) /
Reid Spencer00c28a72004-06-10 08:09:13 +0000118 double(bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000119
Chris Lattner05ac92c2006-07-06 18:02:27 +0000120 if (bca.progressiveVerify) {
121 std::string msg;
122 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000123 bca.VerifyInfo += "Verify@Finish: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000124 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000125 }
126
Reid Spencercbb22e22004-06-10 22:00:54 +0000127 virtual void handleModuleBegin(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000128 if (os)
129 *os << " Module " << id << " {\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000130 bca.ModuleId = id;
Reid Spencerdac69c82004-06-07 17:53:43 +0000131 }
132
Misha Brukman8a96c532005-04-21 21:44:41 +0000133 virtual void handleModuleEnd(const std::string& id) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000134 if (os)
135 *os << " } End Module " << id << "\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000136 if (bca.progressiveVerify) {
137 std::string msg;
138 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000139 bca.VerifyInfo += "Verify@EndModule: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000140 }
141 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000142
Reid Spencercbb22e22004-06-10 22:00:54 +0000143 virtual void handleVersionInfo(
Reid Spenceraacc35a2007-01-26 08:10:24 +0000144 unsigned char RevisionNum ///< Byte code revision number
Misha Brukman8a96c532005-04-21 21:44:41 +0000145 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000146 if (os)
Reid Spenceraacc35a2007-01-26 08:10:24 +0000147 *os << " RevisionNum: " << int(RevisionNum) << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000148 bca.version = RevisionNum;
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 handleModuleGlobalsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000152 if (os)
153 *os << " BLOCK: ModuleGlobalInfo {\n";
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 handleGlobalVariable(
157 const Type* ElemType,
158 bool isConstant,
Reid Spencerf41aa732004-06-29 23:23:12 +0000159 GlobalValue::LinkageTypes Linkage,
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000160 GlobalValue::VisibilityTypes Visibility,
Reid Spencerf41aa732004-06-29 23:23:12 +0000161 unsigned SlotNum,
162 unsigned initSlot
Reid Spencercbb22e22004-06-10 22:00:54 +0000163 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000164 if (os) {
165 *os << " GV: "
166 << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, "
167 << ( isConstant? "Constant, " : "Variable, ")
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000168 << " Linkage=" << Linkage
169 << " Visibility="<< Visibility
170 << " Type=";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000171 WriteTypeSymbolic(*os, ElemType, M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000172 *os << " Slot=" << SlotNum << " InitSlot=" << initSlot
Reid Spencer911ec6d2004-08-21 20:58:19 +0000173 << "\n";
174 }
175
Reid Spencer649ee572004-06-09 06:16:43 +0000176 bca.numGlobalVars++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000177 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000178 if (SlotNum > bca.maxValueSlot)
179 bca.maxValueSlot = SlotNum;
180 if (initSlot > bca.maxValueSlot)
181 bca.maxValueSlot = initSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000182
Reid Spencer911ec6d2004-08-21 20:58:19 +0000183 }
184
185 virtual void handleTypeList(unsigned numEntries) {
186 bca.maxTypeSlot = numEntries - 1;
Reid Spencerdac69c82004-06-07 17:53:43 +0000187 }
188
Misha Brukman8a96c532005-04-21 21:44:41 +0000189 virtual void handleType( const Type* Ty ) {
190 bca.numTypes++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000191 if (os) {
192 *os << " Type: ";
193 WriteTypeSymbolic(*os,Ty,M);
194 *os << "\n";
195 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000196 }
197
Misha Brukman8a96c532005-04-21 21:44:41 +0000198 virtual void handleFunctionDeclaration(
Reid Spencerb61cdb72004-07-04 11:00:39 +0000199 Function* Func ///< The function
Reid Spencercbb22e22004-06-10 22:00:54 +0000200 ) {
Reid Spencer649ee572004-06-09 06:16:43 +0000201 bca.numFunctions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000202 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000203 if (os) {
204 *os << " Function Decl: ";
205 WriteTypeSymbolic(*os,Func->getType(),M);
Anton Korobeynikov93c2b372006-09-17 13:06:18 +0000206 *os <<", Linkage=" << Func->getLinkage();
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000207 *os <<", Visibility=" << Func->getVisibility();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000208 *os << "\n";
209 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000210 }
211
Reid Spencerf41aa732004-06-29 23:23:12 +0000212 virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000213 if (os) {
214 *os << " Initializer: GV=";
215 GV->print(*os);
216 *os << " CV=";
217 CV->print(*os);
218 *os << "\n";
219 }
220 }
221
222 virtual void handleDependentLibrary(const std::string& libName) {
223 bca.numLibraries++;
224 bca.libSize += libName.size() + (libName.size() < 128 ? 1 : 2);
Reid Spencer3ee8eed2004-09-11 04:14:07 +0000225 if (os)
226 *os << " Library: '" << libName << "'\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000227 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000228
Misha Brukman8a96c532005-04-21 21:44:41 +0000229 virtual void handleModuleGlobalsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000230 if (os)
231 *os << " } END BLOCK: ModuleGlobalInfo\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000232 if (bca.progressiveVerify) {
233 std::string msg;
234 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000235 bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000236 }
237 }
238
Misha Brukman8a96c532005-04-21 21:44:41 +0000239 virtual void handleCompactionTableBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000240 if (os)
241 *os << " BLOCK: CompactionTable {\n";
Reid Spencer488d73a2004-08-27 00:43:51 +0000242 bca.numCmpctnTables++;
Reid Spencerf41aa732004-06-29 23:23:12 +0000243 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000244
Reid Spencercbb22e22004-06-10 22:00:54 +0000245 virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000246 if (os)
247 *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000248 }
249
Misha Brukman8a96c532005-04-21 21:44:41 +0000250 virtual void handleCompactionTableType( unsigned i, unsigned TypSlot,
Reid Spencerf41aa732004-06-29 23:23:12 +0000251 const Type* Ty ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000252 if (os) {
253 *os << " Type: " << i << " Slot:" << TypSlot << " is ";
254 WriteTypeSymbolic(*os,Ty,M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000255 *os << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000256 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000257 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000258
Chris Lattner2c6c14d2004-08-04 00:19:23 +0000259 virtual void handleCompactionTableValue(unsigned i, unsigned TypSlot,
Misha Brukman8a96c532005-04-21 21:44:41 +0000260 unsigned ValSlot) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000261 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000262 *os << " Value: " << i << " TypSlot: " << TypSlot
Chris Lattner2c6c14d2004-08-04 00:19:23 +0000263 << " ValSlot:" << ValSlot << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000264 if (ValSlot > bca.maxValueSlot)
265 bca.maxValueSlot = ValSlot;
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 handleCompactionTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000269 if (os)
270 *os << " } END BLOCK: CompactionTable\n";
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 handleSymbolTableBegin(Function* CF, SymbolTable* ST) {
274 bca.numSymTab++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000275 if (os)
276 *os << " BLOCK: SymbolTable {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000277 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000278
Misha Brukman8a96c532005-04-21 21:44:41 +0000279 virtual void handleSymbolTablePlane(unsigned Ty, unsigned NumEntries,
280 const Type* Typ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000281 if (os) {
282 *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << " Type: ";
283 WriteTypeSymbolic(*os,Typ,M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000284 *os << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000285 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000286 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000287
Misha Brukman8a96c532005-04-21 21:44:41 +0000288 virtual void handleSymbolTableType(unsigned i, unsigned TypSlot,
289 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000290 if (os)
291 *os << " Type " << i << " Slot=" << TypSlot
Misha Brukman8a96c532005-04-21 21:44:41 +0000292 << " Name: " << name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000293 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000294
Misha Brukman8a96c532005-04-21 21:44:41 +0000295 virtual void handleSymbolTableValue(unsigned i, unsigned ValSlot,
296 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000297 if (os)
298 *os << " Value " << i << " Slot=" << ValSlot
299 << " Name: " << name << "\n";
300 if (ValSlot > bca.maxValueSlot)
301 bca.maxValueSlot = ValSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000302 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000303
Misha Brukman8a96c532005-04-21 21:44:41 +0000304 virtual void handleSymbolTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000305 if (os)
306 *os << " } END BLOCK: SymbolTable\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000307 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000308
Reid Spencerf41aa732004-06-29 23:23:12 +0000309 virtual void handleFunctionBegin(Function* Func, unsigned Size) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000310 if (os) {
311 *os << " BLOCK: Function {\n"
312 << " Linkage: " << Func->getLinkage() << "\n"
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000313 << " Visibility: " << Func->getVisibility() << "\n"
Misha Brukman8a96c532005-04-21 21:44:41 +0000314 << " Type: ";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000315 WriteTypeSymbolic(*os,Func->getType(),M);
316 *os << "\n";
317 }
318
Reid Spencercbb22e22004-06-10 22:00:54 +0000319 currFunc = &bca.FunctionInfo[Func];
Reid Spencer911ec6d2004-08-21 20:58:19 +0000320 std::ostringstream tmp;
321 WriteTypeSymbolic(tmp,Func->getType(),M);
322 currFunc->description = tmp.str();
Reid Spencercbb22e22004-06-10 22:00:54 +0000323 currFunc->name = Func->getName();
324 currFunc->byteSize = Size;
325 currFunc->numInstructions = 0;
326 currFunc->numBasicBlocks = 0;
327 currFunc->numPhis = 0;
328 currFunc->numOperands = 0;
329 currFunc->density = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +0000330 currFunc->instructionSize = 0;
331 currFunc->longInstructions = 0;
Reid Spencercbb22e22004-06-10 22:00:54 +0000332 currFunc->vbrCount32 = 0;
333 currFunc->vbrCount64 = 0;
334 currFunc->vbrCompBytes = 0;
335 currFunc->vbrExpdBytes = 0;
Reid Spencerf41aa732004-06-29 23:23:12 +0000336
Reid Spencerdac69c82004-06-07 17:53:43 +0000337 }
338
Reid Spencercbb22e22004-06-10 22:00:54 +0000339 virtual void handleFunctionEnd( Function* Func) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000340 if (os)
341 *os << " } END BLOCK: Function\n";
Reid Spencercbb22e22004-06-10 22:00:54 +0000342 currFunc->density = double(currFunc->byteSize) /
Reid Spencer3120e712004-08-24 22:45:32 +0000343 double(currFunc->numInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000344
Chris Lattner05ac92c2006-07-06 18:02:27 +0000345 if (bca.progressiveVerify) {
346 std::string msg;
347 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000348 bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000349 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000350 }
351
Reid Spencercbb22e22004-06-10 22:00:54 +0000352 virtual void handleBasicBlockBegin( unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000353 if (os)
354 *os << " BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000355 bca.numBasicBlocks++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000356 bca.numValues++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000357 if ( currFunc ) currFunc->numBasicBlocks++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000358 }
359
Misha Brukman8a96c532005-04-21 21:44:41 +0000360 virtual bool handleInstruction( unsigned Opcode, const Type* iType,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000361 std::vector<unsigned>& Operands, unsigned Size){
Reid Spencer911ec6d2004-08-21 20:58:19 +0000362 if (os) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000363 *os << " INST: OpCode="
Reid Spencer911ec6d2004-08-21 20:58:19 +0000364 << Instruction::getOpcodeName(Opcode) << " Type=\"";
365 WriteTypeSymbolic(*os,iType,M);
366 *os << "\"";
Misha Brukman8a96c532005-04-21 21:44:41 +0000367 for ( unsigned i = 0; i < Operands.size(); ++i )
Reid Spencer911ec6d2004-08-21 20:58:19 +0000368 *os << " Op(" << i << ")=Slot(" << Operands[i] << ")";
369 *os << "\n";
370 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000371
Reid Spencer649ee572004-06-09 06:16:43 +0000372 bca.numInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000373 bca.numValues++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000374 bca.instructionSize += Size;
375 if (Size > 4 ) bca.longInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000376 bca.numOperands += Operands.size();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000377 for (unsigned i = 0; i < Operands.size(); ++i )
378 if (Operands[i] > bca.maxValueSlot)
379 bca.maxValueSlot = Operands[i];
Reid Spencercbb22e22004-06-10 22:00:54 +0000380 if ( currFunc ) {
381 currFunc->numInstructions++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000382 currFunc->instructionSize += Size;
383 if (Size > 4 ) currFunc->longInstructions++;
Reid Spencer8a9a3702004-06-11 03:06:43 +0000384 if ( Opcode == Instruction::PHI ) currFunc->numPhis++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000385 }
Misha Brukman8a96c532005-04-21 21:44:41 +0000386 return Instruction::isTerminator(Opcode);
Reid Spencerdac69c82004-06-07 17:53:43 +0000387 }
388
Misha Brukman8a96c532005-04-21 21:44:41 +0000389 virtual void handleBasicBlockEnd(unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000390 if (os)
Reid Spencerc6d416a2006-12-15 21:46:37 +0000391 *os << " } END BLOCK: BasicBlock #" << blocknum << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000392 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000393
Misha Brukman8a96c532005-04-21 21:44:41 +0000394 virtual void handleGlobalConstantsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000395 if (os)
396 *os << " BLOCK: GlobalConstants {\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 handleConstantExpression( unsigned Opcode,
Reid Spencerf41aa732004-06-29 23:23:12 +0000400 std::vector<Constant*> ArgVec, Constant* C ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000401 if (os) {
402 *os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
403 for ( unsigned i = 0; i < ArgVec.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000404 *os << " Arg#" << i << " "; ArgVec[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000405 *os << "\n";
406 }
407 *os << " Value=";
408 C->print(*os);
409 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000410 }
Reid Spencer649ee572004-06-09 06:16:43 +0000411 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000412 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000413 }
414
Reid Spencercbb22e22004-06-10 22:00:54 +0000415 virtual void handleConstantValue( Constant * c ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000416 if (os) {
417 *os << " VALUE: ";
418 c->print(*os);
419 *os << "\n";
420 }
Reid Spencer649ee572004-06-09 06:16:43 +0000421 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000422 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000423 }
424
Misha Brukman8a96c532005-04-21 21:44:41 +0000425 virtual void handleConstantArray( const ArrayType* AT,
Reid Spencerf41aa732004-06-29 23:23:12 +0000426 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000427 unsigned TypeSlot,
428 Constant* ArrayVal ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000429 if (os) {
430 *os << " ARRAY: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000431 WriteTypeSymbolic(*os,AT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000432 *os << " TypeSlot=" << TypeSlot << "\n";
433 for ( unsigned i = 0; i < Elements.size(); ++i ) {
434 *os << " #" << i;
435 Elements[i]->print(*os);
436 *os << "\n";
437 }
438 *os << " Value=";
439 ArrayVal->print(*os);
440 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000441 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000442
Reid Spencer649ee572004-06-09 06:16:43 +0000443 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000444 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000445 }
446
Reid Spencercbb22e22004-06-10 22:00:54 +0000447 virtual void handleConstantStruct(
Reid Spencer00c28a72004-06-10 08:09:13 +0000448 const StructType* ST,
Reid Spencerf41aa732004-06-29 23:23:12 +0000449 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000450 Constant* StructVal)
Reid Spencerdac69c82004-06-07 17:53:43 +0000451 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000452 if (os) {
453 *os << " STRUC: ";
454 WriteTypeSymbolic(*os,ST,M);
455 *os << "\n";
456 for ( unsigned i = 0; i < Elements.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000457 *os << " #" << i << " "; Elements[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000458 *os << "\n";
459 }
460 *os << " Value=";
461 StructVal->print(*os);
462 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000463 }
Reid Spencer649ee572004-06-09 06:16:43 +0000464 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000465 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000466 }
467
Misha Brukman8a96c532005-04-21 21:44:41 +0000468 virtual void handleConstantPacked(
469 const PackedType* PT,
Brian Gaeke715c90b2004-08-20 06:00:58 +0000470 std::vector<Constant*>& Elements,
Misha Brukman8a96c532005-04-21 21:44:41 +0000471 unsigned TypeSlot,
472 Constant* PackedVal)
Brian Gaeke715c90b2004-08-20 06:00:58 +0000473 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000474 if (os) {
475 *os << " PACKD: ";
476 WriteTypeSymbolic(*os,PT,M);
477 *os << " TypeSlot=" << TypeSlot << "\n";
478 for ( unsigned i = 0; i < Elements.size(); ++i ) {
479 *os << " #" << i;
480 Elements[i]->print(*os);
481 *os << "\n";
482 }
483 *os << " Value=";
484 PackedVal->print(*os);
485 *os << "\n";
Brian Gaeke715c90b2004-08-20 06:00:58 +0000486 }
Brian Gaeke715c90b2004-08-20 06:00:58 +0000487
488 bca.numConstants++;
489 bca.numValues++;
490 }
491
Misha Brukman8a96c532005-04-21 21:44:41 +0000492 virtual void handleConstantPointer( const PointerType* PT,
Reid Spencer3c90f9f2004-07-18 00:10:36 +0000493 unsigned Slot, GlobalValue* GV ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000494 if (os) {
495 *os << " PNTR: ";
496 WriteTypeSymbolic(*os,PT,M);
497 *os << " Slot=" << Slot << " GlobalValue=";
498 GV->print(*os);
499 *os << "\n";
500 }
Reid Spencer649ee572004-06-09 06:16:43 +0000501 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000502 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000503 }
504
Reid Spencercbb22e22004-06-10 22:00:54 +0000505 virtual void handleConstantString( const ConstantArray* CA ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000506 if (os) {
507 *os << " STRNG: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000508 CA->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000509 *os << "\n";
510 }
Reid Spencer649ee572004-06-09 06:16:43 +0000511 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000512 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000513 }
514
Misha Brukman8a96c532005-04-21 21:44:41 +0000515 virtual void handleGlobalConstantsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000516 if (os)
517 *os << " } END BLOCK: GlobalConstants\n";
518
Chris Lattner05ac92c2006-07-06 18:02:27 +0000519 if (bca.progressiveVerify) {
520 std::string msg;
521 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000522 bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000523 }
524 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000525
Reid Spencercbb22e22004-06-10 22:00:54 +0000526 virtual void handleAlignment(unsigned numBytes) {
Reid Spencer00c28a72004-06-10 08:09:13 +0000527 bca.numAlignment += numBytes;
Reid Spencerdac69c82004-06-07 17:53:43 +0000528 }
529
Reid Spencercbb22e22004-06-10 22:00:54 +0000530 virtual void handleBlock(
Reid Spencer00c28a72004-06-10 08:09:13 +0000531 unsigned BType, const unsigned char* StartPtr, unsigned Size) {
532 bca.numBlocks++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000533 assert(BType >= BytecodeFormat::ModuleBlockID);
534 assert(BType < BytecodeFormat::NumberOfBlockIDs);
535 bca.BlockSizes[
Reid Spencerd798a512006-11-14 04:47:22 +0000536 llvm::BytecodeFormat::BytecodeBlockIdentifiers(BType)] += Size;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000537
538 if (bca.version < 3) // Check for long block headers versions
539 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;
540 else
541 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 4;
Reid Spencer00c28a72004-06-10 08:09:13 +0000542 }
543
544 virtual void handleVBR32(unsigned Size ) {
545 bca.vbrCount32++;
546 bca.vbrCompBytes += Size;
547 bca.vbrExpdBytes += sizeof(uint32_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000548 if (currFunc) {
549 currFunc->vbrCount32++;
550 currFunc->vbrCompBytes += Size;
551 currFunc->vbrExpdBytes += sizeof(uint32_t);
552 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000553 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000554
Reid Spencer00c28a72004-06-10 08:09:13 +0000555 virtual void handleVBR64(unsigned Size ) {
556 bca.vbrCount64++;
557 bca.vbrCompBytes += Size;
558 bca.vbrExpdBytes += sizeof(uint64_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000559 if ( currFunc ) {
560 currFunc->vbrCount64++;
561 currFunc->vbrCompBytes += Size;
562 currFunc->vbrExpdBytes += sizeof(uint64_t);
563 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000564 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000565};
566
Reid Spencerf41aa732004-06-29 23:23:12 +0000567
568/// @brief Utility for printing a titled unsigned value with
569/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000570inline static void print(std::ostream& Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000571 unsigned val, bool nl = true ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000572 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000573 << std::setw(0) << ": "
574 << std::setw(9) << val << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000575}
576
Reid Spencerf41aa732004-06-29 23:23:12 +0000577/// @brief Utility for printing a titled double value with an
578/// aligned colon
Misha Brukman8a96c532005-04-21 21:44:41 +0000579inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000580 double val ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000581 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000582 << std::setw(0) << ": "
583 << std::setw(9) << std::setprecision(6) << val << "\n" ;
584}
585
586/// @brief Utility for printing a titled double value with a
587/// percentage and aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000588inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000589 double top, double bot ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000590 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000591 << std::setw(0) << ": "
Misha Brukman8a96c532005-04-21 21:44:41 +0000592 << std::setw(9) << std::setprecision(6) << top
593 << " (" << std::left << std::setw(0) << std::setprecision(4)
Reid Spencerf41aa732004-06-29 23:23:12 +0000594 << (top/bot)*100.0 << "%)\n";
595}
596
597/// @brief Utility for printing a titled string value with
598/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000599inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000600 std::string val, bool nl = true) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000601 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000602 << std::setw(0) << ": "
603 << std::left << val << (nl ? "\n" : "");
604}
605
606}
607
608namespace llvm {
609
610/// This function prints the contents of rhe BytecodeAnalysis structure in
611/// a human legible form.
612/// @brief Print BytecodeAnalysis structure to an ostream
613void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
Reid Spencerdac69c82004-06-07 17:53:43 +0000614{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000615 Out << "\nSummary Analysis Of " << bca.ModuleId << ": \n\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000616 print(Out, "Bytecode Analysis Of Module", bca.ModuleId);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000617 print(Out, "Bytecode Version Number", bca.version);
Reid Spencerf41aa732004-06-29 23:23:12 +0000618 print(Out, "File Size", bca.byteSize);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000619 print(Out, "Module Bytes",
620 double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]),
621 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000622 print(Out, "Function Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000623 double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]),
624 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000625 print(Out, "Global Types Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000626 double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]),
627 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000628 print(Out, "Constant Pool Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000629 double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]),
630 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000631 print(Out, "Module Globals Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000632 double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]),
633 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000634 print(Out, "Instruction List Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000635 double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
636 double(bca.byteSize));
Reid Spencer78d033e2007-01-06 07:24:44 +0000637 print(Out, "Value Symbol Table Bytes",
638 double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
639 double(bca.byteSize));
640 print(Out, "Type Symbol Table Bytes",
641 double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000642 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000643 print(Out, "Alignment Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000644 double(bca.numAlignment), double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000645 print(Out, "Block Header Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000646 double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]),
647 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000648 print(Out, "Dependent Libraries Bytes", double(bca.libSize),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000649 double(bca.byteSize));
Reid Spencerf41aa732004-06-29 23:23:12 +0000650 print(Out, "Number Of Bytecode Blocks", bca.numBlocks);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000651 print(Out, "Number Of Functions", bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000652 print(Out, "Number Of Types", bca.numTypes);
Reid Spencerf41aa732004-06-29 23:23:12 +0000653 print(Out, "Number Of Constants", bca.numConstants);
654 print(Out, "Number Of Global Variables", bca.numGlobalVars);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000655 print(Out, "Number Of Values", bca.numValues);
Reid Spencerf41aa732004-06-29 23:23:12 +0000656 print(Out, "Number Of Basic Blocks", bca.numBasicBlocks);
657 print(Out, "Number Of Instructions", bca.numInstructions);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000658 print(Out, "Number Of Long Instructions", bca.longInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000659 print(Out, "Number Of Operands", bca.numOperands);
660 print(Out, "Number Of Compaction Tables", bca.numCmpctnTables);
661 print(Out, "Number Of Symbol Tables", bca.numSymTab);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000662 print(Out, "Number Of Dependent Libs", bca.numLibraries);
663 print(Out, "Total Instruction Size", bca.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000664 print(Out, "Average Instruction Size",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000665 double(bca.instructionSize)/double(bca.numInstructions));
666
Reid Spencerf41aa732004-06-29 23:23:12 +0000667 print(Out, "Maximum Type Slot Number", bca.maxTypeSlot);
668 print(Out, "Maximum Value Slot Number", bca.maxValueSlot);
Reid Spencer3120e712004-08-24 22:45:32 +0000669 print(Out, "Bytes Per Value ", bca.fileDensity);
670 print(Out, "Bytes Per Global", bca.globalsDensity);
671 print(Out, "Bytes Per Function", bca.functionDensity);
672 print(Out, "# of VBR 32-bit Integers", bca.vbrCount32);
673 print(Out, "# of VBR 64-bit Integers", bca.vbrCount64);
674 print(Out, "# of VBR Compressed Bytes", bca.vbrCompBytes);
675 print(Out, "# of VBR Expanded Bytes", bca.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000676 print(Out, "Bytes Saved With VBR",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000677 double(bca.vbrExpdBytes)-double(bca.vbrCompBytes),
678 double(bca.vbrExpdBytes));
Reid Spencerf41aa732004-06-29 23:23:12 +0000679
Reid Spencer911ec6d2004-08-21 20:58:19 +0000680 if (bca.detailedResults) {
681 Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000682
Misha Brukman8a96c532005-04-21 21:44:41 +0000683 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
Reid Spencerf41aa732004-06-29 23:23:12 +0000684 bca.FunctionInfo.begin();
Misha Brukman8a96c532005-04-21 21:44:41 +0000685 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
Reid Spencerf41aa732004-06-29 23:23:12 +0000686 bca.FunctionInfo.end();
687
688 while ( I != E ) {
Chris Lattner4a8167f2004-10-15 19:40:31 +0000689 Out << std::left << std::setw(0) << "\n";
690 if (I->second.numBasicBlocks == 0) Out << "External ";
691 Out << "Function: " << I->second.name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000692 print(Out, "Type:", I->second.description);
693 print(Out, "Byte Size", I->second.byteSize);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000694 if (I->second.numBasicBlocks) {
695 print(Out, "Basic Blocks", I->second.numBasicBlocks);
696 print(Out, "Instructions", I->second.numInstructions);
697 print(Out, "Long Instructions", I->second.longInstructions);
698 print(Out, "Operands", I->second.numOperands);
699 print(Out, "Instruction Size", I->second.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000700 print(Out, "Average Instruction Size",
Chris Lattner4a8167f2004-10-15 19:40:31 +0000701 double(I->second.instructionSize) / I->second.numInstructions);
702 print(Out, "Bytes Per Instruction", I->second.density);
703 print(Out, "# of VBR 32-bit Integers", I->second.vbrCount32);
704 print(Out, "# of VBR 64-bit Integers", I->second.vbrCount64);
705 print(Out, "# of VBR Compressed Bytes", I->second.vbrCompBytes);
706 print(Out, "# of VBR Expanded Bytes", I->second.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000707 print(Out, "Bytes Saved With VBR",
Reid Spencere03f09c2006-11-03 01:44:51 +0000708 double(I->second.vbrExpdBytes) - I->second.vbrCompBytes);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000709 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000710 ++I;
711 }
712 }
713
Reid Spencerf41aa732004-06-29 23:23:12 +0000714 if ( bca.progressiveVerify )
715 Out << bca.VerifyInfo;
716}
717
Reid Spencer911ec6d2004-08-21 20:58:19 +0000718BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca,
719 std::ostream* output)
Reid Spencerf41aa732004-06-29 23:23:12 +0000720{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000721 return new AnalyzerHandler(bca,output);
Reid Spencerf41aa732004-06-29 23:23:12 +0000722}
723
Reid Spencerdac69c82004-06-07 17:53:43 +0000724}
725