blob: 3d6a001080eacb5574608190eb8440f48ab329b6 [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;
99 bca.BlockSizes[BytecodeFormat::SymbolTableBlockID] = 0;
100 bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
101 bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
102 bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
103 bca.BlockSizes[BytecodeFormat::CompactionTableBlockID] = 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 Spencerdac69c82004-06-07 17:53:43 +0000144 unsigned char RevisionNum, ///< Byte code revision number
145 Module::Endianness Endianness, ///< Endianness indicator
146 Module::PointerSize PointerSize ///< PointerSize indicator
Misha Brukman8a96c532005-04-21 21:44:41 +0000147 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000148 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000149 *os << " RevisionNum: " << int(RevisionNum)
Reid Spencerb61cdb72004-07-04 11:00:39 +0000150 << " Endianness: " << Endianness
151 << " PointerSize: " << PointerSize << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000152 bca.version = RevisionNum;
Reid Spencerf41aa732004-06-29 23:23:12 +0000153 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000154
Misha Brukman8a96c532005-04-21 21:44:41 +0000155 virtual void handleModuleGlobalsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000156 if (os)
157 *os << " BLOCK: ModuleGlobalInfo {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000158 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000159
Misha Brukman8a96c532005-04-21 21:44:41 +0000160 virtual void handleGlobalVariable(
161 const Type* ElemType,
162 bool isConstant,
Reid Spencerf41aa732004-06-29 23:23:12 +0000163 GlobalValue::LinkageTypes Linkage,
164 unsigned SlotNum,
165 unsigned initSlot
Reid Spencercbb22e22004-06-10 22:00:54 +0000166 ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000167 if (os) {
168 *os << " GV: "
169 << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, "
170 << ( isConstant? "Constant, " : "Variable, ")
171 << " Linkage=" << Linkage << " Type=";
172 WriteTypeSymbolic(*os, ElemType, M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000173 *os << " Slot=" << SlotNum << " InitSlot=" << initSlot
Reid Spencer911ec6d2004-08-21 20:58:19 +0000174 << "\n";
175 }
176
Reid Spencer649ee572004-06-09 06:16:43 +0000177 bca.numGlobalVars++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000178 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000179 if (SlotNum > bca.maxValueSlot)
180 bca.maxValueSlot = SlotNum;
181 if (initSlot > bca.maxValueSlot)
182 bca.maxValueSlot = initSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000183
Reid Spencer911ec6d2004-08-21 20:58:19 +0000184 }
185
186 virtual void handleTypeList(unsigned numEntries) {
187 bca.maxTypeSlot = numEntries - 1;
Reid Spencerdac69c82004-06-07 17:53:43 +0000188 }
189
Misha Brukman8a96c532005-04-21 21:44:41 +0000190 virtual void handleType( const Type* Ty ) {
191 bca.numTypes++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000192 if (os) {
193 *os << " Type: ";
194 WriteTypeSymbolic(*os,Ty,M);
195 *os << "\n";
196 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000197 }
198
Misha Brukman8a96c532005-04-21 21:44:41 +0000199 virtual void handleFunctionDeclaration(
Reid Spencerb61cdb72004-07-04 11:00:39 +0000200 Function* Func ///< The function
Reid Spencercbb22e22004-06-10 22:00:54 +0000201 ) {
Reid Spencer649ee572004-06-09 06:16:43 +0000202 bca.numFunctions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000203 bca.numValues++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000204 if (os) {
205 *os << " Function Decl: ";
206 WriteTypeSymbolic(*os,Func->getType(),M);
Anton Korobeynikov93c2b372006-09-17 13:06:18 +0000207 *os <<", Linkage=" << Func->getLinkage();
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"
Misha Brukman8a96c532005-04-21 21:44:41 +0000313 << " Type: ";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000314 WriteTypeSymbolic(*os,Func->getType(),M);
315 *os << "\n";
316 }
317
Reid Spencercbb22e22004-06-10 22:00:54 +0000318 currFunc = &bca.FunctionInfo[Func];
Reid Spencer911ec6d2004-08-21 20:58:19 +0000319 std::ostringstream tmp;
320 WriteTypeSymbolic(tmp,Func->getType(),M);
321 currFunc->description = tmp.str();
Reid Spencercbb22e22004-06-10 22:00:54 +0000322 currFunc->name = Func->getName();
323 currFunc->byteSize = Size;
324 currFunc->numInstructions = 0;
325 currFunc->numBasicBlocks = 0;
326 currFunc->numPhis = 0;
327 currFunc->numOperands = 0;
328 currFunc->density = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +0000329 currFunc->instructionSize = 0;
330 currFunc->longInstructions = 0;
Reid Spencercbb22e22004-06-10 22:00:54 +0000331 currFunc->vbrCount32 = 0;
332 currFunc->vbrCount64 = 0;
333 currFunc->vbrCompBytes = 0;
334 currFunc->vbrExpdBytes = 0;
Reid Spencerf41aa732004-06-29 23:23:12 +0000335
Reid Spencerdac69c82004-06-07 17:53:43 +0000336 }
337
Reid Spencercbb22e22004-06-10 22:00:54 +0000338 virtual void handleFunctionEnd( Function* Func) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000339 if (os)
340 *os << " } END BLOCK: Function\n";
Reid Spencercbb22e22004-06-10 22:00:54 +0000341 currFunc->density = double(currFunc->byteSize) /
Reid Spencer3120e712004-08-24 22:45:32 +0000342 double(currFunc->numInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000343
Chris Lattner05ac92c2006-07-06 18:02:27 +0000344 if (bca.progressiveVerify) {
345 std::string msg;
346 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000347 bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000348 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000349 }
350
Reid Spencercbb22e22004-06-10 22:00:54 +0000351 virtual void handleBasicBlockBegin( unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000352 if (os)
353 *os << " BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000354 bca.numBasicBlocks++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000355 bca.numValues++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000356 if ( currFunc ) currFunc->numBasicBlocks++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000357 }
358
Misha Brukman8a96c532005-04-21 21:44:41 +0000359 virtual bool handleInstruction( unsigned Opcode, const Type* iType,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000360 std::vector<unsigned>& Operands, unsigned Size){
Reid Spencer911ec6d2004-08-21 20:58:19 +0000361 if (os) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000362 *os << " INST: OpCode="
Reid Spencer911ec6d2004-08-21 20:58:19 +0000363 << Instruction::getOpcodeName(Opcode) << " Type=\"";
364 WriteTypeSymbolic(*os,iType,M);
365 *os << "\"";
Misha Brukman8a96c532005-04-21 21:44:41 +0000366 for ( unsigned i = 0; i < Operands.size(); ++i )
Reid Spencer911ec6d2004-08-21 20:58:19 +0000367 *os << " Op(" << i << ")=Slot(" << Operands[i] << ")";
368 *os << "\n";
369 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000370
Reid Spencer649ee572004-06-09 06:16:43 +0000371 bca.numInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000372 bca.numValues++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000373 bca.instructionSize += Size;
374 if (Size > 4 ) bca.longInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000375 bca.numOperands += Operands.size();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000376 for (unsigned i = 0; i < Operands.size(); ++i )
377 if (Operands[i] > bca.maxValueSlot)
378 bca.maxValueSlot = Operands[i];
Reid Spencercbb22e22004-06-10 22:00:54 +0000379 if ( currFunc ) {
380 currFunc->numInstructions++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000381 currFunc->instructionSize += Size;
382 if (Size > 4 ) currFunc->longInstructions++;
Reid Spencer8a9a3702004-06-11 03:06:43 +0000383 if ( Opcode == Instruction::PHI ) currFunc->numPhis++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000384 }
Misha Brukman8a96c532005-04-21 21:44:41 +0000385 return Instruction::isTerminator(Opcode);
Reid Spencerdac69c82004-06-07 17:53:43 +0000386 }
387
Misha Brukman8a96c532005-04-21 21:44:41 +0000388 virtual void handleBasicBlockEnd(unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000389 if (os)
390 *os << " } END BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000391 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000392
Misha Brukman8a96c532005-04-21 21:44:41 +0000393 virtual void handleGlobalConstantsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000394 if (os)
395 *os << " BLOCK: GlobalConstants {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000396 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000397
Misha Brukman8a96c532005-04-21 21:44:41 +0000398 virtual void handleConstantExpression( unsigned Opcode,
Reid Spencerf41aa732004-06-29 23:23:12 +0000399 std::vector<Constant*> ArgVec, Constant* C ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000400 if (os) {
401 *os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
402 for ( unsigned i = 0; i < ArgVec.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000403 *os << " Arg#" << i << " "; ArgVec[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000404 *os << "\n";
405 }
406 *os << " Value=";
407 C->print(*os);
408 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000409 }
Reid Spencer649ee572004-06-09 06:16:43 +0000410 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000411 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000412 }
413
Reid Spencercbb22e22004-06-10 22:00:54 +0000414 virtual void handleConstantValue( Constant * c ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000415 if (os) {
416 *os << " VALUE: ";
417 c->print(*os);
418 *os << "\n";
419 }
Reid Spencer649ee572004-06-09 06:16:43 +0000420 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000421 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000422 }
423
Misha Brukman8a96c532005-04-21 21:44:41 +0000424 virtual void handleConstantArray( const ArrayType* AT,
Reid Spencerf41aa732004-06-29 23:23:12 +0000425 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000426 unsigned TypeSlot,
427 Constant* ArrayVal ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000428 if (os) {
429 *os << " ARRAY: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000430 WriteTypeSymbolic(*os,AT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000431 *os << " TypeSlot=" << TypeSlot << "\n";
432 for ( unsigned i = 0; i < Elements.size(); ++i ) {
433 *os << " #" << i;
434 Elements[i]->print(*os);
435 *os << "\n";
436 }
437 *os << " Value=";
438 ArrayVal->print(*os);
439 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000440 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000441
Reid Spencer649ee572004-06-09 06:16:43 +0000442 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000443 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000444 }
445
Reid Spencercbb22e22004-06-10 22:00:54 +0000446 virtual void handleConstantStruct(
Reid Spencer00c28a72004-06-10 08:09:13 +0000447 const StructType* ST,
Reid Spencerf41aa732004-06-29 23:23:12 +0000448 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000449 Constant* StructVal)
Reid Spencerdac69c82004-06-07 17:53:43 +0000450 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000451 if (os) {
452 *os << " STRUC: ";
453 WriteTypeSymbolic(*os,ST,M);
454 *os << "\n";
455 for ( unsigned i = 0; i < Elements.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000456 *os << " #" << i << " "; Elements[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000457 *os << "\n";
458 }
459 *os << " Value=";
460 StructVal->print(*os);
461 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000462 }
Reid Spencer649ee572004-06-09 06:16:43 +0000463 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000464 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000465 }
466
Misha Brukman8a96c532005-04-21 21:44:41 +0000467 virtual void handleConstantPacked(
468 const PackedType* PT,
Brian Gaeke715c90b2004-08-20 06:00:58 +0000469 std::vector<Constant*>& Elements,
Misha Brukman8a96c532005-04-21 21:44:41 +0000470 unsigned TypeSlot,
471 Constant* PackedVal)
Brian Gaeke715c90b2004-08-20 06:00:58 +0000472 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000473 if (os) {
474 *os << " PACKD: ";
475 WriteTypeSymbolic(*os,PT,M);
476 *os << " TypeSlot=" << TypeSlot << "\n";
477 for ( unsigned i = 0; i < Elements.size(); ++i ) {
478 *os << " #" << i;
479 Elements[i]->print(*os);
480 *os << "\n";
481 }
482 *os << " Value=";
483 PackedVal->print(*os);
484 *os << "\n";
Brian Gaeke715c90b2004-08-20 06:00:58 +0000485 }
Brian Gaeke715c90b2004-08-20 06:00:58 +0000486
487 bca.numConstants++;
488 bca.numValues++;
489 }
490
Misha Brukman8a96c532005-04-21 21:44:41 +0000491 virtual void handleConstantPointer( const PointerType* PT,
Reid Spencer3c90f9f2004-07-18 00:10:36 +0000492 unsigned Slot, GlobalValue* GV ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000493 if (os) {
494 *os << " PNTR: ";
495 WriteTypeSymbolic(*os,PT,M);
496 *os << " Slot=" << Slot << " GlobalValue=";
497 GV->print(*os);
498 *os << "\n";
499 }
Reid Spencer649ee572004-06-09 06:16:43 +0000500 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000501 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000502 }
503
Reid Spencercbb22e22004-06-10 22:00:54 +0000504 virtual void handleConstantString( const ConstantArray* CA ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000505 if (os) {
506 *os << " STRNG: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000507 CA->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000508 *os << "\n";
509 }
Reid Spencer649ee572004-06-09 06:16:43 +0000510 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000511 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000512 }
513
Misha Brukman8a96c532005-04-21 21:44:41 +0000514 virtual void handleGlobalConstantsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000515 if (os)
516 *os << " } END BLOCK: GlobalConstants\n";
517
Chris Lattner05ac92c2006-07-06 18:02:27 +0000518 if (bca.progressiveVerify) {
519 std::string msg;
520 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000521 bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000522 }
523 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000524
Reid Spencercbb22e22004-06-10 22:00:54 +0000525 virtual void handleAlignment(unsigned numBytes) {
Reid Spencer00c28a72004-06-10 08:09:13 +0000526 bca.numAlignment += numBytes;
Reid Spencerdac69c82004-06-07 17:53:43 +0000527 }
528
Reid Spencercbb22e22004-06-10 22:00:54 +0000529 virtual void handleBlock(
Reid Spencer00c28a72004-06-10 08:09:13 +0000530 unsigned BType, const unsigned char* StartPtr, unsigned Size) {
531 bca.numBlocks++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000532 assert(BType >= BytecodeFormat::ModuleBlockID);
533 assert(BType < BytecodeFormat::NumberOfBlockIDs);
534 bca.BlockSizes[
Reid Spencerd798a512006-11-14 04:47:22 +0000535 llvm::BytecodeFormat::BytecodeBlockIdentifiers(BType)] += Size;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000536
537 if (bca.version < 3) // Check for long block headers versions
538 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;
539 else
540 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 4;
Reid Spencer00c28a72004-06-10 08:09:13 +0000541 }
542
543 virtual void handleVBR32(unsigned Size ) {
544 bca.vbrCount32++;
545 bca.vbrCompBytes += Size;
546 bca.vbrExpdBytes += sizeof(uint32_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000547 if (currFunc) {
548 currFunc->vbrCount32++;
549 currFunc->vbrCompBytes += Size;
550 currFunc->vbrExpdBytes += sizeof(uint32_t);
551 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000552 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000553
Reid Spencer00c28a72004-06-10 08:09:13 +0000554 virtual void handleVBR64(unsigned Size ) {
555 bca.vbrCount64++;
556 bca.vbrCompBytes += Size;
557 bca.vbrExpdBytes += sizeof(uint64_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000558 if ( currFunc ) {
559 currFunc->vbrCount64++;
560 currFunc->vbrCompBytes += Size;
561 currFunc->vbrExpdBytes += sizeof(uint64_t);
562 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000563 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000564};
565
Reid Spencerf41aa732004-06-29 23:23:12 +0000566
567/// @brief Utility for printing a titled unsigned value with
568/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000569inline static void print(std::ostream& Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000570 unsigned val, bool nl = true ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000571 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000572 << std::setw(0) << ": "
573 << std::setw(9) << val << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000574}
575
Reid Spencerf41aa732004-06-29 23:23:12 +0000576/// @brief Utility for printing a titled double value with an
577/// aligned colon
Misha Brukman8a96c532005-04-21 21:44:41 +0000578inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000579 double val ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000580 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000581 << std::setw(0) << ": "
582 << std::setw(9) << std::setprecision(6) << val << "\n" ;
583}
584
585/// @brief Utility for printing a titled double value with a
586/// percentage and aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000587inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000588 double top, double bot ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000589 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000590 << std::setw(0) << ": "
Misha Brukman8a96c532005-04-21 21:44:41 +0000591 << std::setw(9) << std::setprecision(6) << top
592 << " (" << std::left << std::setw(0) << std::setprecision(4)
Reid Spencerf41aa732004-06-29 23:23:12 +0000593 << (top/bot)*100.0 << "%)\n";
594}
595
596/// @brief Utility for printing a titled string value with
597/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000598inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000599 std::string val, bool nl = true) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000600 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000601 << std::setw(0) << ": "
602 << std::left << val << (nl ? "\n" : "");
603}
604
605}
606
607namespace llvm {
608
609/// This function prints the contents of rhe BytecodeAnalysis structure in
610/// a human legible form.
611/// @brief Print BytecodeAnalysis structure to an ostream
612void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
Reid Spencerdac69c82004-06-07 17:53:43 +0000613{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000614 Out << "\nSummary Analysis Of " << bca.ModuleId << ": \n\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000615 print(Out, "Bytecode Analysis Of Module", bca.ModuleId);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000616 print(Out, "Bytecode Version Number", bca.version);
Reid Spencerf41aa732004-06-29 23:23:12 +0000617 print(Out, "File Size", bca.byteSize);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000618 print(Out, "Module Bytes",
619 double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]),
620 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000621 print(Out, "Function Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000622 double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]),
623 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000624 print(Out, "Global Types Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000625 double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]),
626 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000627 print(Out, "Constant Pool Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000628 double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]),
629 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000630 print(Out, "Module Globals Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000631 double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]),
632 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000633 print(Out, "Instruction List Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000634 double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
635 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000636 print(Out, "Compaction Table Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000637 double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]),
638 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000639 print(Out, "Symbol Table Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000640 double(bca.BlockSizes[BytecodeFormat::SymbolTableBlockID]),
641 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000642 print(Out, "Alignment Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000643 double(bca.numAlignment), double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000644 print(Out, "Block Header Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000645 double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]),
646 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000647 print(Out, "Dependent Libraries Bytes", double(bca.libSize),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000648 double(bca.byteSize));
Reid Spencerf41aa732004-06-29 23:23:12 +0000649 print(Out, "Number Of Bytecode Blocks", bca.numBlocks);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000650 print(Out, "Number Of Functions", bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000651 print(Out, "Number Of Types", bca.numTypes);
Reid Spencerf41aa732004-06-29 23:23:12 +0000652 print(Out, "Number Of Constants", bca.numConstants);
653 print(Out, "Number Of Global Variables", bca.numGlobalVars);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000654 print(Out, "Number Of Values", bca.numValues);
Reid Spencerf41aa732004-06-29 23:23:12 +0000655 print(Out, "Number Of Basic Blocks", bca.numBasicBlocks);
656 print(Out, "Number Of Instructions", bca.numInstructions);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000657 print(Out, "Number Of Long Instructions", bca.longInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000658 print(Out, "Number Of Operands", bca.numOperands);
659 print(Out, "Number Of Compaction Tables", bca.numCmpctnTables);
660 print(Out, "Number Of Symbol Tables", bca.numSymTab);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000661 print(Out, "Number Of Dependent Libs", bca.numLibraries);
662 print(Out, "Total Instruction Size", bca.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000663 print(Out, "Average Instruction Size",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000664 double(bca.instructionSize)/double(bca.numInstructions));
665
Reid Spencerf41aa732004-06-29 23:23:12 +0000666 print(Out, "Maximum Type Slot Number", bca.maxTypeSlot);
667 print(Out, "Maximum Value Slot Number", bca.maxValueSlot);
Reid Spencer3120e712004-08-24 22:45:32 +0000668 print(Out, "Bytes Per Value ", bca.fileDensity);
669 print(Out, "Bytes Per Global", bca.globalsDensity);
670 print(Out, "Bytes Per Function", bca.functionDensity);
671 print(Out, "# of VBR 32-bit Integers", bca.vbrCount32);
672 print(Out, "# of VBR 64-bit Integers", bca.vbrCount64);
673 print(Out, "# of VBR Compressed Bytes", bca.vbrCompBytes);
674 print(Out, "# of VBR Expanded Bytes", bca.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000675 print(Out, "Bytes Saved With VBR",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000676 double(bca.vbrExpdBytes)-double(bca.vbrCompBytes),
677 double(bca.vbrExpdBytes));
Reid Spencerf41aa732004-06-29 23:23:12 +0000678
Reid Spencer911ec6d2004-08-21 20:58:19 +0000679 if (bca.detailedResults) {
680 Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000681
Misha Brukman8a96c532005-04-21 21:44:41 +0000682 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
Reid Spencerf41aa732004-06-29 23:23:12 +0000683 bca.FunctionInfo.begin();
Misha Brukman8a96c532005-04-21 21:44:41 +0000684 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
Reid Spencerf41aa732004-06-29 23:23:12 +0000685 bca.FunctionInfo.end();
686
687 while ( I != E ) {
Chris Lattner4a8167f2004-10-15 19:40:31 +0000688 Out << std::left << std::setw(0) << "\n";
689 if (I->second.numBasicBlocks == 0) Out << "External ";
690 Out << "Function: " << I->second.name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000691 print(Out, "Type:", I->second.description);
692 print(Out, "Byte Size", I->second.byteSize);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000693 if (I->second.numBasicBlocks) {
694 print(Out, "Basic Blocks", I->second.numBasicBlocks);
695 print(Out, "Instructions", I->second.numInstructions);
696 print(Out, "Long Instructions", I->second.longInstructions);
697 print(Out, "Operands", I->second.numOperands);
698 print(Out, "Instruction Size", I->second.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000699 print(Out, "Average Instruction Size",
Chris Lattner4a8167f2004-10-15 19:40:31 +0000700 double(I->second.instructionSize) / I->second.numInstructions);
701 print(Out, "Bytes Per Instruction", I->second.density);
702 print(Out, "# of VBR 32-bit Integers", I->second.vbrCount32);
703 print(Out, "# of VBR 64-bit Integers", I->second.vbrCount64);
704 print(Out, "# of VBR Compressed Bytes", I->second.vbrCompBytes);
705 print(Out, "# of VBR Expanded Bytes", I->second.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000706 print(Out, "Bytes Saved With VBR",
Reid Spencere03f09c2006-11-03 01:44:51 +0000707 double(I->second.vbrExpdBytes) - I->second.vbrCompBytes);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000708 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000709 ++I;
710 }
711 }
712
Reid Spencerf41aa732004-06-29 23:23:12 +0000713 if ( bca.progressiveVerify )
714 Out << bca.VerifyInfo;
715}
716
Reid Spencer911ec6d2004-08-21 20:58:19 +0000717BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca,
718 std::ostream* output)
Reid Spencerf41aa732004-06-29 23:23:12 +0000719{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000720 return new AnalyzerHandler(bca,output);
Reid Spencerf41aa732004-06-29 23:23:12 +0000721}
722
Reid Spencerdac69c82004-06-07 17:53:43 +0000723}
724