Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 1 | //===-- Analyzer.cpp - Analysis and Dumping of Bytecode 000000---*- C++ -*-===// |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Reid Spencer and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 10 | // 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 Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 19 | #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 Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 24 | #include "llvm/Bytecode/BytecodeHandler.h" |
| 25 | #include <iomanip> |
| 26 | #include <sstream> |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace llvm; |
| 29 | |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 30 | namespace { |
| 31 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 32 | /// @brief Bytecode reading handler for analyzing bytecode. |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 33 | class AnalyzerHandler : public BytecodeHandler { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 34 | BytecodeAnalysis& bca; ///< The structure in which data is recorded |
| 35 | std::ostringstream dump; ///< A convenience for dumping data. |
| 36 | /// @brief Keeps track of current function |
| 37 | BytecodeAnalysis::BytecodeFunctionInfo* currFunc; |
| 38 | Module* M; ///< Keeps track of current module |
| 39 | |
| 40 | /// @name Constructor |
| 41 | /// @{ |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 42 | public: |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 43 | /// The only way to construct an AnalyzerHandler. All that is needed is a |
| 44 | /// reference to the BytecodeAnalysis structure where the output will be |
| 45 | /// placed. |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 46 | AnalyzerHandler(BytecodeAnalysis& TheBca) |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 47 | : bca(TheBca) |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 48 | , dump() |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 49 | , currFunc(0) |
| 50 | { } |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 51 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 52 | /// @} |
| 53 | /// @name BytecodeHandler Implementations |
| 54 | /// @{ |
| 55 | public: |
| 56 | virtual void handleError(const std::string& str ) { |
| 57 | dump << "ERROR: " << str << "\n"; |
| 58 | bca.BytecodeDump = dump.str() ; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 61 | virtual void handleStart( Module* Mod, unsigned theSize ) { |
| 62 | M = Mod; |
| 63 | dump << "Bytecode {\n"; |
| 64 | bca.byteSize = theSize; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 65 | bca.ModuleId.clear(); |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 66 | bca.numBlocks = 0; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 67 | bca.numTypes = 0; |
| 68 | bca.numValues = 0; |
| 69 | bca.numFunctions = 0; |
| 70 | bca.numConstants = 0; |
| 71 | bca.numGlobalVars = 0; |
| 72 | bca.numInstructions = 0; |
| 73 | bca.numBasicBlocks = 0; |
| 74 | bca.numOperands = 0; |
| 75 | bca.numCmpctnTables = 0; |
| 76 | bca.numSymTab = 0; |
| 77 | bca.maxTypeSlot = 0; |
| 78 | bca.maxValueSlot = 0; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 79 | bca.numAlignment = 0; |
| 80 | bca.fileDensity = 0.0; |
| 81 | bca.globalsDensity = 0.0; |
| 82 | bca.functionDensity = 0.0; |
Reid Spencer | 1cf5024 | 2004-06-11 15:10:38 +0000 | [diff] [blame] | 83 | bca.instructionSize = 0; |
| 84 | bca.longInstructions = 0; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 85 | bca.vbrCount32 = 0; |
| 86 | bca.vbrCount64 = 0; |
| 87 | bca.vbrCompBytes = 0; |
| 88 | bca.vbrExpdBytes = 0; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 89 | bca.FunctionInfo.clear(); |
| 90 | bca.BytecodeDump.clear(); |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 91 | bca.BlockSizes[BytecodeFormat::Module] = 0; |
| 92 | bca.BlockSizes[BytecodeFormat::Function] = 0; |
| 93 | bca.BlockSizes[BytecodeFormat::ConstantPool] = 0; |
| 94 | bca.BlockSizes[BytecodeFormat::SymbolTable] = 0; |
| 95 | bca.BlockSizes[BytecodeFormat::ModuleGlobalInfo] = 0; |
| 96 | bca.BlockSizes[BytecodeFormat::GlobalTypePlane] = 0; |
| 97 | bca.BlockSizes[BytecodeFormat::BasicBlock] = 0; |
| 98 | bca.BlockSizes[BytecodeFormat::InstructionList] = 0; |
| 99 | bca.BlockSizes[BytecodeFormat::CompactionTable] = 0; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 102 | virtual void handleFinish() { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 103 | dump << "} End Bytecode\n"; |
| 104 | bca.BytecodeDump = dump.str() ; |
| 105 | |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 106 | bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues ); |
| 107 | double globalSize = 0.0; |
| 108 | globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPool]); |
| 109 | globalSize += double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfo]); |
| 110 | globalSize += double(bca.BlockSizes[BytecodeFormat::GlobalTypePlane]); |
| 111 | bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants + |
| 112 | bca.numGlobalVars ); |
| 113 | bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::Function]) / |
| 114 | double(bca.numFunctions); |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 115 | |
| 116 | if ( bca.progressiveVerify ) { |
| 117 | try { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 118 | verifyModule(*M, ThrowExceptionAction); |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 119 | } catch ( std::string& msg ) { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 120 | bca.VerifyInfo += "Verify@Finish: " + msg + "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 125 | virtual void handleModuleBegin(const std::string& id) { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 126 | dump << " Module " << id << " {\n"; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 127 | bca.ModuleId = id; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 130 | virtual void handleModuleEnd(const std::string& id) { |
| 131 | dump << " } End Module " << id << "\n"; |
| 132 | if ( bca.progressiveVerify ) { |
| 133 | try { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 134 | verifyModule(*M, ThrowExceptionAction); |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 135 | } catch ( std::string& msg ) { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 136 | bca.VerifyInfo += "Verify@EndModule: " + msg + "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 140 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 141 | virtual void handleVersionInfo( |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 142 | unsigned char RevisionNum, ///< Byte code revision number |
| 143 | Module::Endianness Endianness, ///< Endianness indicator |
| 144 | Module::PointerSize PointerSize ///< PointerSize indicator |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 145 | ) { |
| 146 | dump << " RevisionNum: " << int(RevisionNum) |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 147 | << " Endianness: " << Endianness |
| 148 | << " PointerSize: " << PointerSize << "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 149 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 150 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 151 | virtual void handleModuleGlobalsBegin() { |
| 152 | dump << " BLOCK: ModuleGlobalInfo {\n"; |
| 153 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 154 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 155 | virtual void handleGlobalVariable( |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 156 | const Type* ElemType, |
| 157 | bool isConstant, |
| 158 | GlobalValue::LinkageTypes Linkage, |
| 159 | unsigned SlotNum, |
| 160 | unsigned initSlot |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 161 | ) { |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 162 | bca.numGlobalVars++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 163 | bca.numValues++; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 164 | |
| 165 | dump << " GV: " |
| 166 | << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, " |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 167 | << ( isConstant? "Constant, " : "Variable, ") |
| 168 | << " Linkage=" << Linkage << " Type=" |
| 169 | << ElemType->getDescription() |
| 170 | << " Slot=" << SlotNum << " InitSlot=" << initSlot |
| 171 | << "\n"; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 174 | virtual void handleType( const Type* Ty ) { |
| 175 | bca.numTypes++; |
| 176 | dump << " Type: " << Ty->getDescription() << "\n"; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 179 | virtual void handleFunctionDeclaration( |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 180 | Function* Func ///< The function |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 181 | ) { |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 182 | bca.numFunctions++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 183 | bca.numValues++; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 184 | dump << " Function Decl: " << Func->getType()->getDescription() << "\n"; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 187 | virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) { |
| 188 | dump << " Initializer: GV="; |
| 189 | GV->print(dump); |
| 190 | dump << " CV="; |
| 191 | CV->print(dump); |
| 192 | dump << "\n"; |
| 193 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 194 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 195 | virtual void handleModuleGlobalsEnd() { |
| 196 | dump << " } END BLOCK: ModuleGlobalInfo\n"; |
| 197 | if ( bca.progressiveVerify ) { |
| 198 | try { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 199 | verifyModule(*M, ThrowExceptionAction); |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 200 | } catch ( std::string& msg ) { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 201 | bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | virtual void handleCompactionTableBegin() { |
| 207 | dump << " BLOCK: CompactionTable {\n"; |
| 208 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 209 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 210 | virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) { |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 211 | bca.numCmpctnTables++; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 212 | dump << " Plane: Ty=" << Ty << " Size=" << NumEntries << "\n"; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 215 | virtual void handleCompactionTableType( unsigned i, unsigned TypSlot, |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 216 | const Type* Ty ) { |
| 217 | dump << " Type: " << i << " Slot:" << TypSlot |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 218 | << " is " << Ty->getDescription() << "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 219 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 220 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 221 | virtual void handleCompactionTableValue( |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 222 | unsigned i, |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 223 | unsigned TypSlot, |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 224 | unsigned ValSlot, |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 225 | const Type* Ty ) { |
| 226 | dump << " Value: " << i << " TypSlot: " << TypSlot |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 227 | << " ValSlot:" << ValSlot << " is " << Ty->getDescription() |
| 228 | << "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 229 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 230 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 231 | virtual void handleCompactionTableEnd() { |
| 232 | dump << " } END BLOCK: CompactionTable\n"; |
| 233 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 234 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 235 | virtual void handleSymbolTableBegin(Function* CF, SymbolTable* ST) { |
| 236 | bca.numSymTab++; |
| 237 | dump << " BLOCK: SymbolTable {\n"; |
| 238 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 239 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 240 | virtual void handleSymbolTablePlane(unsigned Ty, unsigned NumEntries, |
| 241 | const Type* Typ) { |
| 242 | dump << " Plane: Ty=" << Ty << " Size=" << NumEntries |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 243 | << " Type: " << Typ->getDescription() << "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 244 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 245 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 246 | virtual void handleSymbolTableType(unsigned i, unsigned slot, |
| 247 | const std::string& name ) { |
| 248 | dump << " Type " << i << " Slot=" << slot |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 249 | << " Name: " << name << "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 250 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 251 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 252 | virtual void handleSymbolTableValue(unsigned i, unsigned slot, |
| 253 | const std::string& name ) { |
| 254 | dump << " Value " << i << " Slot=" << slot |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 255 | << " Name: " << name << "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 256 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 257 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 258 | virtual void handleSymbolTableEnd() { |
| 259 | dump << " } END BLOCK: SymbolTable\n"; |
| 260 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 261 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 262 | virtual void handleFunctionBegin(Function* Func, unsigned Size) { |
| 263 | dump << "BLOCK: Function {\n"; |
| 264 | dump << " Linkage: " << Func->getLinkage() << "\n"; |
| 265 | dump << " Type: " << Func->getType()->getDescription() << "\n"; |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 266 | const FunctionType* FType = |
| 267 | cast<FunctionType>(Func->getType()->getElementType()); |
| 268 | currFunc = &bca.FunctionInfo[Func]; |
| 269 | currFunc->description = FType->getDescription(); |
| 270 | currFunc->name = Func->getName(); |
| 271 | currFunc->byteSize = Size; |
| 272 | currFunc->numInstructions = 0; |
| 273 | currFunc->numBasicBlocks = 0; |
| 274 | currFunc->numPhis = 0; |
| 275 | currFunc->numOperands = 0; |
| 276 | currFunc->density = 0.0; |
Reid Spencer | 1cf5024 | 2004-06-11 15:10:38 +0000 | [diff] [blame] | 277 | currFunc->instructionSize = 0; |
| 278 | currFunc->longInstructions = 0; |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 279 | currFunc->vbrCount32 = 0; |
| 280 | currFunc->vbrCount64 = 0; |
| 281 | currFunc->vbrCompBytes = 0; |
| 282 | currFunc->vbrExpdBytes = 0; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 283 | |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 286 | virtual void handleFunctionEnd( Function* Func) { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 287 | dump << "} END BLOCK: Function\n"; |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 288 | currFunc->density = double(currFunc->byteSize) / |
| 289 | double(currFunc->numInstructions+currFunc->numBasicBlocks); |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 290 | |
| 291 | if ( bca.progressiveVerify ) { |
| 292 | try { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 293 | verifyModule(*M, ThrowExceptionAction); |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 294 | } catch ( std::string& msg ) { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 295 | bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 300 | virtual void handleBasicBlockBegin( unsigned blocknum) { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 301 | dump << " BLOCK: BasicBlock #" << blocknum << "{\n"; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 302 | bca.numBasicBlocks++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 303 | bca.numValues++; |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 304 | if ( currFunc ) currFunc->numBasicBlocks++; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 307 | virtual bool handleInstruction( unsigned Opcode, const Type* iType, |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 308 | std::vector<unsigned>& Operands, unsigned Size){ |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 309 | dump << " INST: OpCode=" |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 310 | << Instruction::getOpcodeName(Opcode) << " Type=" |
| 311 | << iType->getDescription() << "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 312 | for ( unsigned i = 0; i < Operands.size(); ++i ) |
| 313 | dump << " Op#" << i << " Slot=" << Operands[i] << "\n"; |
| 314 | |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 315 | bca.numInstructions++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 316 | bca.numValues++; |
Reid Spencer | 1cf5024 | 2004-06-11 15:10:38 +0000 | [diff] [blame] | 317 | bca.instructionSize += Size; |
| 318 | if (Size > 4 ) bca.longInstructions++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 319 | bca.numOperands += Operands.size(); |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 320 | if ( currFunc ) { |
| 321 | currFunc->numInstructions++; |
Reid Spencer | 1cf5024 | 2004-06-11 15:10:38 +0000 | [diff] [blame] | 322 | currFunc->instructionSize += Size; |
| 323 | if (Size > 4 ) currFunc->longInstructions++; |
Reid Spencer | 8a9a370 | 2004-06-11 03:06:43 +0000 | [diff] [blame] | 324 | if ( Opcode == Instruction::PHI ) currFunc->numPhis++; |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 325 | } |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 326 | return Instruction::isTerminator(Opcode); |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 329 | virtual void handleBasicBlockEnd(unsigned blocknum) { |
| 330 | dump << " } END BLOCK: BasicBlock #" << blocknum << "{\n"; |
| 331 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 332 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 333 | virtual void handleGlobalConstantsBegin() { |
| 334 | dump << " BLOCK: GlobalConstants {\n"; |
| 335 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 336 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 337 | virtual void handleConstantExpression( unsigned Opcode, |
| 338 | std::vector<Constant*> ArgVec, Constant* C ) { |
| 339 | dump << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n"; |
| 340 | for ( unsigned i = 0; i < ArgVec.size(); ++i ) { |
| 341 | dump << " Arg#" << i << " "; ArgVec[i]->print(dump); dump << "\n"; |
| 342 | } |
| 343 | dump << " Value="; |
| 344 | C->print(dump); |
| 345 | dump << "\n"; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 346 | bca.numConstants++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 347 | bca.numValues++; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 350 | virtual void handleConstantValue( Constant * c ) { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 351 | dump << " VALUE: "; |
| 352 | c->print(dump); |
| 353 | dump << "\n"; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 354 | bca.numConstants++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 355 | bca.numValues++; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 358 | virtual void handleConstantArray( const ArrayType* AT, |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 359 | std::vector<Constant*>& Elements, |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 360 | unsigned TypeSlot, |
| 361 | Constant* ArrayVal ) { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 362 | dump << " ARRAY: " << AT->getDescription() |
| 363 | << " TypeSlot=" << TypeSlot << "\n"; |
| 364 | for ( unsigned i = 0; i < Elements.size(); ++i ) { |
| 365 | dump << " #" << i; |
| 366 | Elements[i]->print(dump); |
| 367 | dump << "\n"; |
| 368 | } |
| 369 | dump << " Value="; |
| 370 | ArrayVal->print(dump); |
| 371 | dump << "\n"; |
| 372 | |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 373 | bca.numConstants++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 374 | bca.numValues++; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 377 | virtual void handleConstantStruct( |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 378 | const StructType* ST, |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 379 | std::vector<Constant*>& Elements, |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 380 | Constant* StructVal) |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 381 | { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 382 | dump << " STRUC: " << ST->getDescription() << "\n"; |
| 383 | for ( unsigned i = 0; i < Elements.size(); ++i ) { |
| 384 | dump << " #" << i << " "; Elements[i]->print(dump); dump << "\n"; |
| 385 | } |
| 386 | dump << " Value="; |
| 387 | StructVal->print(dump); |
| 388 | dump << "\n"; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 389 | bca.numConstants++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 390 | bca.numValues++; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 393 | virtual void handleConstantPointer( const PointerType* PT, |
| 394 | unsigned Slot, GlobalValue* GV, Constant* PtrVal) { |
| 395 | dump << " PNTR: " << PT->getDescription() |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 396 | << " Slot=" << Slot << " GlobalValue="; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 397 | GV->print(dump); |
| 398 | dump << "\n Value="; |
| 399 | PtrVal->print(dump); |
| 400 | dump << "\n"; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 401 | bca.numConstants++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 402 | bca.numValues++; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 405 | virtual void handleConstantString( const ConstantArray* CA ) { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 406 | dump << " STRNG: "; |
| 407 | CA->print(dump); |
| 408 | dump << "\n"; |
Reid Spencer | 649ee57 | 2004-06-09 06:16:43 +0000 | [diff] [blame] | 409 | bca.numConstants++; |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 410 | bca.numValues++; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 413 | virtual void handleGlobalConstantsEnd() { |
| 414 | dump << " } END BLOCK: GlobalConstants\n"; |
| 415 | if ( bca.progressiveVerify ) { |
| 416 | try { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 417 | verifyModule(*M, ThrowExceptionAction); |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 418 | } catch ( std::string& msg ) { |
Reid Spencer | b61cdb7 | 2004-07-04 11:00:39 +0000 | [diff] [blame^] | 419 | bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n"; |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 423 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 424 | virtual void handleAlignment(unsigned numBytes) { |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 425 | bca.numAlignment += numBytes; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 428 | virtual void handleBlock( |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 429 | unsigned BType, const unsigned char* StartPtr, unsigned Size) { |
| 430 | bca.numBlocks++; |
| 431 | bca.BlockSizes[llvm::BytecodeFormat::FileBlockIDs(BType)] += Size; |
| 432 | } |
| 433 | |
| 434 | virtual void handleVBR32(unsigned Size ) { |
| 435 | bca.vbrCount32++; |
| 436 | bca.vbrCompBytes += Size; |
| 437 | bca.vbrExpdBytes += sizeof(uint32_t); |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 438 | if (currFunc) { |
| 439 | currFunc->vbrCount32++; |
| 440 | currFunc->vbrCompBytes += Size; |
| 441 | currFunc->vbrExpdBytes += sizeof(uint32_t); |
| 442 | } |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 443 | } |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 444 | |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 445 | virtual void handleVBR64(unsigned Size ) { |
| 446 | bca.vbrCount64++; |
| 447 | bca.vbrCompBytes += Size; |
| 448 | bca.vbrExpdBytes += sizeof(uint64_t); |
Reid Spencer | cbb22e2 | 2004-06-10 22:00:54 +0000 | [diff] [blame] | 449 | if ( currFunc ) { |
| 450 | currFunc->vbrCount64++; |
| 451 | currFunc->vbrCompBytes += Size; |
| 452 | currFunc->vbrExpdBytes += sizeof(uint64_t); |
| 453 | } |
Reid Spencer | 00c28a7 | 2004-06-10 08:09:13 +0000 | [diff] [blame] | 454 | } |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 455 | }; |
| 456 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 457 | |
| 458 | /// @brief Utility for printing a titled unsigned value with |
| 459 | /// an aligned colon. |
| 460 | inline static void print(std::ostream& Out, const char*title, |
| 461 | unsigned val, bool nl = true ) { |
| 462 | Out << std::setw(30) << std::right << title |
| 463 | << std::setw(0) << ": " |
| 464 | << std::setw(9) << val << "\n"; |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 467 | /// @brief Utility for printing a titled double value with an |
| 468 | /// aligned colon |
| 469 | inline static void print(std::ostream&Out, const char*title, |
| 470 | double val ) { |
| 471 | Out << std::setw(30) << std::right << title |
| 472 | << std::setw(0) << ": " |
| 473 | << std::setw(9) << std::setprecision(6) << val << "\n" ; |
| 474 | } |
| 475 | |
| 476 | /// @brief Utility for printing a titled double value with a |
| 477 | /// percentage and aligned colon. |
| 478 | inline static void print(std::ostream&Out, const char*title, |
| 479 | double top, double bot ) { |
| 480 | Out << std::setw(30) << std::right << title |
| 481 | << std::setw(0) << ": " |
| 482 | << std::setw(9) << std::setprecision(6) << top |
| 483 | << " (" << std::left << std::setw(0) << std::setprecision(4) |
| 484 | << (top/bot)*100.0 << "%)\n"; |
| 485 | } |
| 486 | |
| 487 | /// @brief Utility for printing a titled string value with |
| 488 | /// an aligned colon. |
| 489 | inline static void print(std::ostream&Out, const char*title, |
| 490 | std::string val, bool nl = true) { |
| 491 | Out << std::setw(30) << std::right << title |
| 492 | << std::setw(0) << ": " |
| 493 | << std::left << val << (nl ? "\n" : ""); |
| 494 | } |
| 495 | |
| 496 | } |
| 497 | |
| 498 | namespace llvm { |
| 499 | |
| 500 | /// This function prints the contents of rhe BytecodeAnalysis structure in |
| 501 | /// a human legible form. |
| 502 | /// @brief Print BytecodeAnalysis structure to an ostream |
| 503 | void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 504 | { |
Reid Spencer | f41aa73 | 2004-06-29 23:23:12 +0000 | [diff] [blame] | 505 | print(Out, "Bytecode Analysis Of Module", bca.ModuleId); |
| 506 | print(Out, "File Size", bca.byteSize); |
| 507 | print(Out, "Bytecode Compression Index",std::string("TBD")); |
| 508 | print(Out, "Number Of Bytecode Blocks", bca.numBlocks); |
| 509 | print(Out, "Number Of Types", bca.numTypes); |
| 510 | print(Out, "Number Of Values", bca.numValues); |
| 511 | print(Out, "Number Of Constants", bca.numConstants); |
| 512 | print(Out, "Number Of Global Variables", bca.numGlobalVars); |
| 513 | print(Out, "Number Of Functions", bca.numFunctions); |
| 514 | print(Out, "Number Of Basic Blocks", bca.numBasicBlocks); |
| 515 | print(Out, "Number Of Instructions", bca.numInstructions); |
| 516 | print(Out, "Number Of Operands", bca.numOperands); |
| 517 | print(Out, "Number Of Compaction Tables", bca.numCmpctnTables); |
| 518 | print(Out, "Number Of Symbol Tables", bca.numSymTab); |
| 519 | print(Out, "Long Instructions", bca.longInstructions); |
| 520 | print(Out, "Instruction Size", bca.instructionSize); |
| 521 | print(Out, "Average Instruction Size", |
| 522 | double(bca.instructionSize)/double(bca.numInstructions)); |
| 523 | print(Out, "Maximum Type Slot Number", bca.maxTypeSlot); |
| 524 | print(Out, "Maximum Value Slot Number", bca.maxValueSlot); |
| 525 | print(Out, "Bytes Thrown To Alignment", double(bca.numAlignment), |
| 526 | double(bca.byteSize)); |
| 527 | print(Out, "File Density (bytes/def)", bca.fileDensity); |
| 528 | print(Out, "Globals Density (bytes/def)", bca.globalsDensity); |
| 529 | print(Out, "Function Density (bytes/func)", bca.functionDensity); |
| 530 | print(Out, "Number of VBR 32-bit Integers", bca.vbrCount32); |
| 531 | print(Out, "Number of VBR 64-bit Integers", bca.vbrCount64); |
| 532 | print(Out, "Number of VBR Compressed Bytes", bca.vbrCompBytes); |
| 533 | print(Out, "Number of VBR Expanded Bytes", bca.vbrExpdBytes); |
| 534 | print(Out, "VBR Savings", |
| 535 | double(bca.vbrExpdBytes)-double(bca.vbrCompBytes), |
| 536 | double(bca.byteSize)); |
| 537 | |
| 538 | if ( bca.detailedResults ) { |
| 539 | print(Out, "Module Bytes", |
| 540 | double(bca.BlockSizes[BytecodeFormat::Module]), |
| 541 | double(bca.byteSize)); |
| 542 | print(Out, "Function Bytes", |
| 543 | double(bca.BlockSizes[BytecodeFormat::Function]), |
| 544 | double(bca.byteSize)); |
| 545 | print(Out, "Constant Pool Bytes", |
| 546 | double(bca.BlockSizes[BytecodeFormat::ConstantPool]), |
| 547 | double(bca.byteSize)); |
| 548 | print(Out, "Symbol Table Bytes", |
| 549 | double(bca.BlockSizes[BytecodeFormat::SymbolTable]), |
| 550 | double(bca.byteSize)); |
| 551 | print(Out, "Module Global Info Bytes", |
| 552 | double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfo]), |
| 553 | double(bca.byteSize)); |
| 554 | print(Out, "Global Type Plane Bytes", |
| 555 | double(bca.BlockSizes[BytecodeFormat::GlobalTypePlane]), |
| 556 | double(bca.byteSize)); |
| 557 | print(Out, "Basic Block Bytes", |
| 558 | double(bca.BlockSizes[BytecodeFormat::BasicBlock]), |
| 559 | double(bca.byteSize)); |
| 560 | print(Out, "Instruction List Bytes", |
| 561 | double(bca.BlockSizes[BytecodeFormat::InstructionList]), |
| 562 | double(bca.byteSize)); |
| 563 | print(Out, "Compaction Table Bytes", |
| 564 | double(bca.BlockSizes[BytecodeFormat::CompactionTable]), |
| 565 | double(bca.byteSize)); |
| 566 | |
| 567 | std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I = |
| 568 | bca.FunctionInfo.begin(); |
| 569 | std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E = |
| 570 | bca.FunctionInfo.end(); |
| 571 | |
| 572 | while ( I != E ) { |
| 573 | Out << std::left << std::setw(0); |
| 574 | Out << "Function: " << I->second.name << "\n"; |
| 575 | print(Out, "Type:", I->second.description); |
| 576 | print(Out, "Byte Size", I->second.byteSize); |
| 577 | print(Out, "Instructions", I->second.numInstructions); |
| 578 | print(Out, "Long Instructions", I->second.longInstructions); |
| 579 | print(Out, "Instruction Size", I->second.instructionSize); |
| 580 | print(Out, "Average Instruction Size", |
| 581 | double(I->second.instructionSize)/double(I->second.numInstructions)); |
| 582 | print(Out, "Basic Blocks", I->second.numBasicBlocks); |
| 583 | print(Out, "Operand", I->second.numOperands); |
| 584 | print(Out, "Function Density", I->second.density); |
| 585 | print(Out, "Number of VBR 32-bit Integers", I->second.vbrCount32); |
| 586 | print(Out, "Number of VBR 64-bit Integers", I->second.vbrCount64); |
| 587 | print(Out, "Number of VBR Compressed Bytes", I->second.vbrCompBytes); |
| 588 | print(Out, "Number of VBR Expanded Bytes", I->second.vbrExpdBytes); |
| 589 | print(Out, "VBR Savings", |
| 590 | double(I->second.vbrExpdBytes)-double(I->second.vbrCompBytes), |
| 591 | double(I->second.byteSize)); |
| 592 | ++I; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | if ( bca.dumpBytecode ) |
| 597 | Out << bca.BytecodeDump; |
| 598 | |
| 599 | if ( bca.progressiveVerify ) |
| 600 | Out << bca.VerifyInfo; |
| 601 | } |
| 602 | |
| 603 | BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca) |
| 604 | { |
| 605 | return new AnalyzerHandler(bca); |
| 606 | } |
| 607 | |
Reid Spencer | dac69c8 | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | // vim: sw=2 |