blob: ce20ac2e3a52fe96e02ece0785d5fad7f23f4de1 [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);
207 *os << "\n";
208 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000209 }
210
Reid Spencerf41aa732004-06-29 23:23:12 +0000211 virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000212 if (os) {
213 *os << " Initializer: GV=";
214 GV->print(*os);
215 *os << " CV=";
216 CV->print(*os);
217 *os << "\n";
218 }
219 }
220
221 virtual void handleDependentLibrary(const std::string& libName) {
222 bca.numLibraries++;
223 bca.libSize += libName.size() + (libName.size() < 128 ? 1 : 2);
Reid Spencer3ee8eed2004-09-11 04:14:07 +0000224 if (os)
225 *os << " Library: '" << libName << "'\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000226 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000227
Misha Brukman8a96c532005-04-21 21:44:41 +0000228 virtual void handleModuleGlobalsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000229 if (os)
230 *os << " } END BLOCK: ModuleGlobalInfo\n";
Chris Lattner05ac92c2006-07-06 18:02:27 +0000231 if (bca.progressiveVerify) {
232 std::string msg;
233 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000234 bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000235 }
236 }
237
Misha Brukman8a96c532005-04-21 21:44:41 +0000238 virtual void handleCompactionTableBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000239 if (os)
240 *os << " BLOCK: CompactionTable {\n";
Reid Spencer488d73a2004-08-27 00:43:51 +0000241 bca.numCmpctnTables++;
Reid Spencerf41aa732004-06-29 23:23:12 +0000242 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000243
Reid Spencercbb22e22004-06-10 22:00:54 +0000244 virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000245 if (os)
246 *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000247 }
248
Misha Brukman8a96c532005-04-21 21:44:41 +0000249 virtual void handleCompactionTableType( unsigned i, unsigned TypSlot,
Reid Spencerf41aa732004-06-29 23:23:12 +0000250 const Type* Ty ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000251 if (os) {
252 *os << " Type: " << i << " Slot:" << TypSlot << " is ";
253 WriteTypeSymbolic(*os,Ty,M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000254 *os << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000255 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000256 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000257
Chris Lattner2c6c14d2004-08-04 00:19:23 +0000258 virtual void handleCompactionTableValue(unsigned i, unsigned TypSlot,
Misha Brukman8a96c532005-04-21 21:44:41 +0000259 unsigned ValSlot) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000260 if (os)
Misha Brukman8a96c532005-04-21 21:44:41 +0000261 *os << " Value: " << i << " TypSlot: " << TypSlot
Chris Lattner2c6c14d2004-08-04 00:19:23 +0000262 << " ValSlot:" << ValSlot << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000263 if (ValSlot > bca.maxValueSlot)
264 bca.maxValueSlot = ValSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000265 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000266
Misha Brukman8a96c532005-04-21 21:44:41 +0000267 virtual void handleCompactionTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000268 if (os)
269 *os << " } END BLOCK: CompactionTable\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000270 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000271
Misha Brukman8a96c532005-04-21 21:44:41 +0000272 virtual void handleSymbolTableBegin(Function* CF, SymbolTable* ST) {
273 bca.numSymTab++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000274 if (os)
275 *os << " BLOCK: SymbolTable {\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 handleSymbolTablePlane(unsigned Ty, unsigned NumEntries,
279 const Type* Typ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000280 if (os) {
281 *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << " Type: ";
282 WriteTypeSymbolic(*os,Typ,M);
Misha Brukman8a96c532005-04-21 21:44:41 +0000283 *os << "\n";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000284 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000285 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000286
Misha Brukman8a96c532005-04-21 21:44:41 +0000287 virtual void handleSymbolTableType(unsigned i, unsigned TypSlot,
288 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000289 if (os)
290 *os << " Type " << i << " Slot=" << TypSlot
Misha Brukman8a96c532005-04-21 21:44:41 +0000291 << " Name: " << name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000292 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000293
Misha Brukman8a96c532005-04-21 21:44:41 +0000294 virtual void handleSymbolTableValue(unsigned i, unsigned ValSlot,
295 const std::string& name ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000296 if (os)
297 *os << " Value " << i << " Slot=" << ValSlot
298 << " Name: " << name << "\n";
299 if (ValSlot > bca.maxValueSlot)
300 bca.maxValueSlot = ValSlot;
Reid Spencerf41aa732004-06-29 23:23:12 +0000301 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000302
Misha Brukman8a96c532005-04-21 21:44:41 +0000303 virtual void handleSymbolTableEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000304 if (os)
305 *os << " } END BLOCK: SymbolTable\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000306 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000307
Reid Spencerf41aa732004-06-29 23:23:12 +0000308 virtual void handleFunctionBegin(Function* Func, unsigned Size) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000309 if (os) {
310 *os << " BLOCK: Function {\n"
311 << " Linkage: " << Func->getLinkage() << "\n"
Misha Brukman8a96c532005-04-21 21:44:41 +0000312 << " Type: ";
Reid Spencer911ec6d2004-08-21 20:58:19 +0000313 WriteTypeSymbolic(*os,Func->getType(),M);
314 *os << "\n";
315 }
316
Reid Spencercbb22e22004-06-10 22:00:54 +0000317 currFunc = &bca.FunctionInfo[Func];
Reid Spencer911ec6d2004-08-21 20:58:19 +0000318 std::ostringstream tmp;
319 WriteTypeSymbolic(tmp,Func->getType(),M);
320 currFunc->description = tmp.str();
Reid Spencercbb22e22004-06-10 22:00:54 +0000321 currFunc->name = Func->getName();
322 currFunc->byteSize = Size;
323 currFunc->numInstructions = 0;
324 currFunc->numBasicBlocks = 0;
325 currFunc->numPhis = 0;
326 currFunc->numOperands = 0;
327 currFunc->density = 0.0;
Reid Spencer1cf50242004-06-11 15:10:38 +0000328 currFunc->instructionSize = 0;
329 currFunc->longInstructions = 0;
Reid Spencercbb22e22004-06-10 22:00:54 +0000330 currFunc->vbrCount32 = 0;
331 currFunc->vbrCount64 = 0;
332 currFunc->vbrCompBytes = 0;
333 currFunc->vbrExpdBytes = 0;
Reid Spencerf41aa732004-06-29 23:23:12 +0000334
Reid Spencerdac69c82004-06-07 17:53:43 +0000335 }
336
Reid Spencercbb22e22004-06-10 22:00:54 +0000337 virtual void handleFunctionEnd( Function* Func) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000338 if (os)
339 *os << " } END BLOCK: Function\n";
Reid Spencercbb22e22004-06-10 22:00:54 +0000340 currFunc->density = double(currFunc->byteSize) /
Reid Spencer3120e712004-08-24 22:45:32 +0000341 double(currFunc->numInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000342
Chris Lattner05ac92c2006-07-06 18:02:27 +0000343 if (bca.progressiveVerify) {
344 std::string msg;
345 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000346 bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000347 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000348 }
349
Reid Spencercbb22e22004-06-10 22:00:54 +0000350 virtual void handleBasicBlockBegin( unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000351 if (os)
352 *os << " BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencer649ee572004-06-09 06:16:43 +0000353 bca.numBasicBlocks++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000354 bca.numValues++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000355 if ( currFunc ) currFunc->numBasicBlocks++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000356 }
357
Misha Brukman8a96c532005-04-21 21:44:41 +0000358 virtual bool handleInstruction( unsigned Opcode, const Type* iType,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000359 std::vector<unsigned>& Operands, unsigned Size){
Reid Spencer911ec6d2004-08-21 20:58:19 +0000360 if (os) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000361 *os << " INST: OpCode="
Reid Spencer911ec6d2004-08-21 20:58:19 +0000362 << Instruction::getOpcodeName(Opcode) << " Type=\"";
363 WriteTypeSymbolic(*os,iType,M);
364 *os << "\"";
Misha Brukman8a96c532005-04-21 21:44:41 +0000365 for ( unsigned i = 0; i < Operands.size(); ++i )
Reid Spencer911ec6d2004-08-21 20:58:19 +0000366 *os << " Op(" << i << ")=Slot(" << Operands[i] << ")";
367 *os << "\n";
368 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000369
Reid Spencer649ee572004-06-09 06:16:43 +0000370 bca.numInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000371 bca.numValues++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000372 bca.instructionSize += Size;
373 if (Size > 4 ) bca.longInstructions++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000374 bca.numOperands += Operands.size();
Reid Spencer911ec6d2004-08-21 20:58:19 +0000375 for (unsigned i = 0; i < Operands.size(); ++i )
376 if (Operands[i] > bca.maxValueSlot)
377 bca.maxValueSlot = Operands[i];
Reid Spencercbb22e22004-06-10 22:00:54 +0000378 if ( currFunc ) {
379 currFunc->numInstructions++;
Reid Spencer1cf50242004-06-11 15:10:38 +0000380 currFunc->instructionSize += Size;
381 if (Size > 4 ) currFunc->longInstructions++;
Reid Spencer8a9a3702004-06-11 03:06:43 +0000382 if ( Opcode == Instruction::PHI ) currFunc->numPhis++;
Reid Spencercbb22e22004-06-10 22:00:54 +0000383 }
Misha Brukman8a96c532005-04-21 21:44:41 +0000384 return Instruction::isTerminator(Opcode);
Reid Spencerdac69c82004-06-07 17:53:43 +0000385 }
386
Misha Brukman8a96c532005-04-21 21:44:41 +0000387 virtual void handleBasicBlockEnd(unsigned blocknum) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000388 if (os)
389 *os << " } END BLOCK: BasicBlock #" << blocknum << "{\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000390 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000391
Misha Brukman8a96c532005-04-21 21:44:41 +0000392 virtual void handleGlobalConstantsBegin() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000393 if (os)
394 *os << " BLOCK: GlobalConstants {\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000395 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000396
Misha Brukman8a96c532005-04-21 21:44:41 +0000397 virtual void handleConstantExpression( unsigned Opcode,
Reid Spencerf41aa732004-06-29 23:23:12 +0000398 std::vector<Constant*> ArgVec, Constant* C ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000399 if (os) {
400 *os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
401 for ( unsigned i = 0; i < ArgVec.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000402 *os << " Arg#" << i << " "; ArgVec[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000403 *os << "\n";
404 }
405 *os << " Value=";
406 C->print(*os);
407 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000408 }
Reid Spencer649ee572004-06-09 06:16:43 +0000409 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000410 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000411 }
412
Reid Spencercbb22e22004-06-10 22:00:54 +0000413 virtual void handleConstantValue( Constant * c ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000414 if (os) {
415 *os << " VALUE: ";
416 c->print(*os);
417 *os << "\n";
418 }
Reid Spencer649ee572004-06-09 06:16:43 +0000419 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000420 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000421 }
422
Misha Brukman8a96c532005-04-21 21:44:41 +0000423 virtual void handleConstantArray( const ArrayType* AT,
Reid Spencerf41aa732004-06-29 23:23:12 +0000424 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000425 unsigned TypeSlot,
426 Constant* ArrayVal ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000427 if (os) {
428 *os << " ARRAY: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000429 WriteTypeSymbolic(*os,AT,M);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000430 *os << " TypeSlot=" << TypeSlot << "\n";
431 for ( unsigned i = 0; i < Elements.size(); ++i ) {
432 *os << " #" << i;
433 Elements[i]->print(*os);
434 *os << "\n";
435 }
436 *os << " Value=";
437 ArrayVal->print(*os);
438 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000439 }
Reid Spencerf41aa732004-06-29 23:23:12 +0000440
Reid Spencer649ee572004-06-09 06:16:43 +0000441 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000442 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000443 }
444
Reid Spencercbb22e22004-06-10 22:00:54 +0000445 virtual void handleConstantStruct(
Reid Spencer00c28a72004-06-10 08:09:13 +0000446 const StructType* ST,
Reid Spencerf41aa732004-06-29 23:23:12 +0000447 std::vector<Constant*>& Elements,
Reid Spencerb61cdb72004-07-04 11:00:39 +0000448 Constant* StructVal)
Reid Spencerdac69c82004-06-07 17:53:43 +0000449 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000450 if (os) {
451 *os << " STRUC: ";
452 WriteTypeSymbolic(*os,ST,M);
453 *os << "\n";
454 for ( unsigned i = 0; i < Elements.size(); ++i ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000455 *os << " #" << i << " "; Elements[i]->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000456 *os << "\n";
457 }
458 *os << " Value=";
459 StructVal->print(*os);
460 *os << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000461 }
Reid Spencer649ee572004-06-09 06:16:43 +0000462 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000463 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000464 }
465
Misha Brukman8a96c532005-04-21 21:44:41 +0000466 virtual void handleConstantPacked(
467 const PackedType* PT,
Brian Gaeke715c90b2004-08-20 06:00:58 +0000468 std::vector<Constant*>& Elements,
Misha Brukman8a96c532005-04-21 21:44:41 +0000469 unsigned TypeSlot,
470 Constant* PackedVal)
Brian Gaeke715c90b2004-08-20 06:00:58 +0000471 {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000472 if (os) {
473 *os << " PACKD: ";
474 WriteTypeSymbolic(*os,PT,M);
475 *os << " TypeSlot=" << TypeSlot << "\n";
476 for ( unsigned i = 0; i < Elements.size(); ++i ) {
477 *os << " #" << i;
478 Elements[i]->print(*os);
479 *os << "\n";
480 }
481 *os << " Value=";
482 PackedVal->print(*os);
483 *os << "\n";
Brian Gaeke715c90b2004-08-20 06:00:58 +0000484 }
Brian Gaeke715c90b2004-08-20 06:00:58 +0000485
486 bca.numConstants++;
487 bca.numValues++;
488 }
489
Misha Brukman8a96c532005-04-21 21:44:41 +0000490 virtual void handleConstantPointer( const PointerType* PT,
Reid Spencer3c90f9f2004-07-18 00:10:36 +0000491 unsigned Slot, GlobalValue* GV ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000492 if (os) {
493 *os << " PNTR: ";
494 WriteTypeSymbolic(*os,PT,M);
495 *os << " Slot=" << Slot << " GlobalValue=";
496 GV->print(*os);
497 *os << "\n";
498 }
Reid Spencer649ee572004-06-09 06:16:43 +0000499 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000500 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000501 }
502
Reid Spencercbb22e22004-06-10 22:00:54 +0000503 virtual void handleConstantString( const ConstantArray* CA ) {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000504 if (os) {
505 *os << " STRNG: ";
Misha Brukman8a96c532005-04-21 21:44:41 +0000506 CA->print(*os);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000507 *os << "\n";
508 }
Reid Spencer649ee572004-06-09 06:16:43 +0000509 bca.numConstants++;
Reid Spencer00c28a72004-06-10 08:09:13 +0000510 bca.numValues++;
Reid Spencerdac69c82004-06-07 17:53:43 +0000511 }
512
Misha Brukman8a96c532005-04-21 21:44:41 +0000513 virtual void handleGlobalConstantsEnd() {
Reid Spencer911ec6d2004-08-21 20:58:19 +0000514 if (os)
515 *os << " } END BLOCK: GlobalConstants\n";
516
Chris Lattner05ac92c2006-07-06 18:02:27 +0000517 if (bca.progressiveVerify) {
518 std::string msg;
519 if (verifyModule(*M, ReturnStatusAction, &msg))
Reid Spencerb61cdb72004-07-04 11:00:39 +0000520 bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000521 }
522 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000523
Reid Spencercbb22e22004-06-10 22:00:54 +0000524 virtual void handleAlignment(unsigned numBytes) {
Reid Spencer00c28a72004-06-10 08:09:13 +0000525 bca.numAlignment += numBytes;
Reid Spencerdac69c82004-06-07 17:53:43 +0000526 }
527
Reid Spencercbb22e22004-06-10 22:00:54 +0000528 virtual void handleBlock(
Reid Spencer00c28a72004-06-10 08:09:13 +0000529 unsigned BType, const unsigned char* StartPtr, unsigned Size) {
530 bca.numBlocks++;
Reid Spencer911ec6d2004-08-21 20:58:19 +0000531 assert(BType >= BytecodeFormat::ModuleBlockID);
532 assert(BType < BytecodeFormat::NumberOfBlockIDs);
533 bca.BlockSizes[
534 llvm::BytecodeFormat::CompressedBytecodeBlockIdentifiers(BType)] += Size;
535
536 if (bca.version < 3) // Check for long block headers versions
537 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;
538 else
539 bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 4;
Reid Spencer00c28a72004-06-10 08:09:13 +0000540 }
541
542 virtual void handleVBR32(unsigned Size ) {
543 bca.vbrCount32++;
544 bca.vbrCompBytes += Size;
545 bca.vbrExpdBytes += sizeof(uint32_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000546 if (currFunc) {
547 currFunc->vbrCount32++;
548 currFunc->vbrCompBytes += Size;
549 currFunc->vbrExpdBytes += sizeof(uint32_t);
550 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000551 }
Reid Spencercbb22e22004-06-10 22:00:54 +0000552
Reid Spencer00c28a72004-06-10 08:09:13 +0000553 virtual void handleVBR64(unsigned Size ) {
554 bca.vbrCount64++;
555 bca.vbrCompBytes += Size;
556 bca.vbrExpdBytes += sizeof(uint64_t);
Reid Spencercbb22e22004-06-10 22:00:54 +0000557 if ( currFunc ) {
558 currFunc->vbrCount64++;
559 currFunc->vbrCompBytes += Size;
560 currFunc->vbrExpdBytes += sizeof(uint64_t);
561 }
Reid Spencer00c28a72004-06-10 08:09:13 +0000562 }
Reid Spencerdac69c82004-06-07 17:53:43 +0000563};
564
Reid Spencerf41aa732004-06-29 23:23:12 +0000565
566/// @brief Utility for printing a titled unsigned value with
567/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000568inline static void print(std::ostream& Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000569 unsigned val, bool nl = true ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000570 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000571 << std::setw(0) << ": "
572 << std::setw(9) << val << "\n";
Reid Spencerdac69c82004-06-07 17:53:43 +0000573}
574
Reid Spencerf41aa732004-06-29 23:23:12 +0000575/// @brief Utility for printing a titled double value with an
576/// aligned colon
Misha Brukman8a96c532005-04-21 21:44:41 +0000577inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000578 double val ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000579 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000580 << std::setw(0) << ": "
581 << std::setw(9) << std::setprecision(6) << val << "\n" ;
582}
583
584/// @brief Utility for printing a titled double value with a
585/// percentage and aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000586inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000587 double top, double bot ) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000588 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000589 << std::setw(0) << ": "
Misha Brukman8a96c532005-04-21 21:44:41 +0000590 << std::setw(9) << std::setprecision(6) << top
591 << " (" << std::left << std::setw(0) << std::setprecision(4)
Reid Spencerf41aa732004-06-29 23:23:12 +0000592 << (top/bot)*100.0 << "%)\n";
593}
594
595/// @brief Utility for printing a titled string value with
596/// an aligned colon.
Misha Brukman8a96c532005-04-21 21:44:41 +0000597inline static void print(std::ostream&Out, const char*title,
Reid Spencerf41aa732004-06-29 23:23:12 +0000598 std::string val, bool nl = true) {
Misha Brukman8a96c532005-04-21 21:44:41 +0000599 Out << std::setw(30) << std::right << title
Reid Spencerf41aa732004-06-29 23:23:12 +0000600 << std::setw(0) << ": "
601 << std::left << val << (nl ? "\n" : "");
602}
603
604}
605
606namespace llvm {
607
608/// This function prints the contents of rhe BytecodeAnalysis structure in
609/// a human legible form.
610/// @brief Print BytecodeAnalysis structure to an ostream
611void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
Reid Spencerdac69c82004-06-07 17:53:43 +0000612{
Reid Spencer911ec6d2004-08-21 20:58:19 +0000613 Out << "\nSummary Analysis Of " << bca.ModuleId << ": \n\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000614 print(Out, "Bytecode Analysis Of Module", bca.ModuleId);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000615 print(Out, "Bytecode Version Number", bca.version);
Reid Spencerf41aa732004-06-29 23:23:12 +0000616 print(Out, "File Size", bca.byteSize);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000617 print(Out, "Module Bytes",
618 double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]),
619 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000620 print(Out, "Function Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000621 double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]),
622 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000623 print(Out, "Global Types Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000624 double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]),
625 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000626 print(Out, "Constant Pool Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000627 double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]),
628 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000629 print(Out, "Module Globals Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000630 double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]),
631 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000632 print(Out, "Instruction List Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000633 double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
634 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000635 print(Out, "Compaction Table Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000636 double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]),
637 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000638 print(Out, "Symbol Table Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000639 double(bca.BlockSizes[BytecodeFormat::SymbolTableBlockID]),
640 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000641 print(Out, "Alignment Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000642 double(bca.numAlignment), double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000643 print(Out, "Block Header Bytes",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000644 double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]),
645 double(bca.byteSize));
Misha Brukman8a96c532005-04-21 21:44:41 +0000646 print(Out, "Dependent Libraries Bytes", double(bca.libSize),
Reid Spencer911ec6d2004-08-21 20:58:19 +0000647 double(bca.byteSize));
Reid Spencerf41aa732004-06-29 23:23:12 +0000648 print(Out, "Number Of Bytecode Blocks", bca.numBlocks);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000649 print(Out, "Number Of Functions", bca.numFunctions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000650 print(Out, "Number Of Types", bca.numTypes);
Reid Spencerf41aa732004-06-29 23:23:12 +0000651 print(Out, "Number Of Constants", bca.numConstants);
652 print(Out, "Number Of Global Variables", bca.numGlobalVars);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000653 print(Out, "Number Of Values", bca.numValues);
Reid Spencerf41aa732004-06-29 23:23:12 +0000654 print(Out, "Number Of Basic Blocks", bca.numBasicBlocks);
655 print(Out, "Number Of Instructions", bca.numInstructions);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000656 print(Out, "Number Of Long Instructions", bca.longInstructions);
Reid Spencerf41aa732004-06-29 23:23:12 +0000657 print(Out, "Number Of Operands", bca.numOperands);
658 print(Out, "Number Of Compaction Tables", bca.numCmpctnTables);
659 print(Out, "Number Of Symbol Tables", bca.numSymTab);
Reid Spencer911ec6d2004-08-21 20:58:19 +0000660 print(Out, "Number Of Dependent Libs", bca.numLibraries);
661 print(Out, "Total Instruction Size", bca.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000662 print(Out, "Average Instruction Size",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000663 double(bca.instructionSize)/double(bca.numInstructions));
664
Reid Spencerf41aa732004-06-29 23:23:12 +0000665 print(Out, "Maximum Type Slot Number", bca.maxTypeSlot);
666 print(Out, "Maximum Value Slot Number", bca.maxValueSlot);
Reid Spencer3120e712004-08-24 22:45:32 +0000667 print(Out, "Bytes Per Value ", bca.fileDensity);
668 print(Out, "Bytes Per Global", bca.globalsDensity);
669 print(Out, "Bytes Per Function", bca.functionDensity);
670 print(Out, "# of VBR 32-bit Integers", bca.vbrCount32);
671 print(Out, "# of VBR 64-bit Integers", bca.vbrCount64);
672 print(Out, "# of VBR Compressed Bytes", bca.vbrCompBytes);
673 print(Out, "# of VBR Expanded Bytes", bca.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000674 print(Out, "Bytes Saved With VBR",
Reid Spencer911ec6d2004-08-21 20:58:19 +0000675 double(bca.vbrExpdBytes)-double(bca.vbrCompBytes),
676 double(bca.vbrExpdBytes));
Reid Spencerf41aa732004-06-29 23:23:12 +0000677
Reid Spencer911ec6d2004-08-21 20:58:19 +0000678 if (bca.detailedResults) {
679 Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000680
Misha Brukman8a96c532005-04-21 21:44:41 +0000681 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
Reid Spencerf41aa732004-06-29 23:23:12 +0000682 bca.FunctionInfo.begin();
Misha Brukman8a96c532005-04-21 21:44:41 +0000683 std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
Reid Spencerf41aa732004-06-29 23:23:12 +0000684 bca.FunctionInfo.end();
685
686 while ( I != E ) {
Chris Lattner4a8167f2004-10-15 19:40:31 +0000687 Out << std::left << std::setw(0) << "\n";
688 if (I->second.numBasicBlocks == 0) Out << "External ";
689 Out << "Function: " << I->second.name << "\n";
Reid Spencerf41aa732004-06-29 23:23:12 +0000690 print(Out, "Type:", I->second.description);
691 print(Out, "Byte Size", I->second.byteSize);
Chris Lattner4a8167f2004-10-15 19:40:31 +0000692 if (I->second.numBasicBlocks) {
693 print(Out, "Basic Blocks", I->second.numBasicBlocks);
694 print(Out, "Instructions", I->second.numInstructions);
695 print(Out, "Long Instructions", I->second.longInstructions);
696 print(Out, "Operands", I->second.numOperands);
697 print(Out, "Instruction Size", I->second.instructionSize);
Misha Brukman8a96c532005-04-21 21:44:41 +0000698 print(Out, "Average Instruction Size",
Chris Lattner4a8167f2004-10-15 19:40:31 +0000699 double(I->second.instructionSize) / I->second.numInstructions);
700 print(Out, "Bytes Per Instruction", I->second.density);
701 print(Out, "# of VBR 32-bit Integers", I->second.vbrCount32);
702 print(Out, "# of VBR 64-bit Integers", I->second.vbrCount64);
703 print(Out, "# of VBR Compressed Bytes", I->second.vbrCompBytes);
704 print(Out, "# of VBR Expanded Bytes", I->second.vbrExpdBytes);
Misha Brukman8a96c532005-04-21 21:44:41 +0000705 print(Out, "Bytes Saved With VBR",
Chris Lattner4a8167f2004-10-15 19:40:31 +0000706 double(I->second.vbrExpdBytes) - I->second.vbrCompBytes),
707 double(I->second.vbrExpdBytes);
708 }
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