From cbb22e218ecffc2c0c03b2fe41f7cd5ca5879c07 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Thu, 10 Jun 2004 22:00:54 +0000 Subject: [PATCH] Implement detailed function level data collection and reporting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14122 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Analyzer/Analyzer.cpp | 226 ++++++++------------- lib/Bytecode/Analyzer/AnalyzerWrappers.cpp | 26 ++- lib/Bytecode/Reader/Analyzer.cpp | 226 ++++++++------------- lib/Bytecode/Reader/AnalyzerWrappers.cpp | 26 ++- 4 files changed, 208 insertions(+), 296 deletions(-) diff --git a/lib/Bytecode/Analyzer/Analyzer.cpp b/lib/Bytecode/Analyzer/Analyzer.cpp index 133c1fbaa6f..3500ed09ea0 100644 --- a/lib/Bytecode/Analyzer/Analyzer.cpp +++ b/lib/Bytecode/Analyzer/Analyzer.cpp @@ -22,19 +22,18 @@ namespace { class AnalyzerHandler : public BytecodeHandler { BytecodeAnalysis& bca; + BytecodeAnalysis::BytecodeFunctionInfo* currFunc; public: AnalyzerHandler(BytecodeAnalysis& TheBca) - : bca(TheBca) - { - } + : bca(TheBca) + , currFunc(0) + { } - bool handleError(const std::string& str ) - { + virtual bool handleError(const std::string& str ) { return false; } - void handleStart() - { + virtual void handleStart() { bca.ModuleId.clear(); bca.numBlocks = 0; bca.numTypes = 0; @@ -70,8 +69,7 @@ public: bca.BlockSizes[BytecodeFormat::CompactionTable] = 0; } - void handleFinish() - { + virtual void handleFinish() { bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues ); double globalSize = 0.0; globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPool]); @@ -83,198 +81,143 @@ public: double(bca.numFunctions); } - void handleModuleBegin(const std::string& id) - { + virtual void handleModuleBegin(const std::string& id) { bca.ModuleId = id; } - void handleModuleEnd(const std::string& id) - { - } + virtual void handleModuleEnd(const std::string& id) { } - void handleVersionInfo( + virtual void handleVersionInfo( unsigned char RevisionNum, ///< Byte code revision number Module::Endianness Endianness, ///< Endianness indicator Module::PointerSize PointerSize ///< PointerSize indicator - ) - { - } + ) { } - void handleModuleGlobalsBegin(unsigned size) - { - // bca.globalBytesize += size; - } + virtual void handleModuleGlobalsBegin(unsigned size) { } - void handleGlobalVariable( + virtual void handleGlobalVariable( const Type* ElemType, ///< The type of the global variable bool isConstant, ///< Whether the GV is constant or not GlobalValue::LinkageTypes ///< The linkage type of the GV - ) - { + ) { bca.numGlobalVars++; bca.numValues++; } - void handleInitializedGV( + virtual void handleInitializedGV( const Type* ElemType, ///< The type of the global variable bool isConstant, ///< Whether the GV is constant or not GlobalValue::LinkageTypes,///< The linkage type of the GV unsigned initSlot ///< Slot number of GV's initializer - ) - { + ) { bca.numGlobalVars++; bca.numValues++; } - virtual void handleType( const Type* Ty ) - { - bca.numTypes++; - } + virtual void handleType( const Type* Ty ) { bca.numTypes++; } - void handleFunctionDeclaration( - const Type* FuncType ///< The type of the function - ) - { + virtual void handleFunctionDeclaration( + Function* Func, ///< The function + const FunctionType* FuncType ///< The type of the function + ) { bca.numFunctions++; bca.numValues++; } - void handleModuleGlobalsEnd() - { - } + virtual void handleModuleGlobalsEnd() { } - void handleCompactionTableBegin() - { - } + virtual void handleCompactionTableBegin() { } - void handleCompactionTablePlane( - unsigned Ty, - unsigned NumEntries - ) - { + virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) { bca.numCmpctnTables++; } - void handleCompactionTableType( - unsigned i, - unsigned TypSlot, - const Type* - ) - { - } + virtual void handleCompactionTableType( unsigned i, unsigned TypSlot, + const Type* ) {} - void handleCompactionTableValue( + virtual void handleCompactionTableValue( unsigned i, unsigned ValSlot, - const Type* - ) - { - } + const Type* ) { } - void handleCompactionTableEnd() - { - } + virtual void handleCompactionTableEnd() { } - void handleSymbolTableBegin() - { - bca.numSymTab++; - } + virtual void handleSymbolTableBegin() { bca.numSymTab++; } - void handleSymbolTablePlane( - unsigned Ty, - unsigned NumEntries, - const Type* Typ - ) - { - } + virtual void handleSymbolTablePlane( unsigned Ty, unsigned NumEntries, + const Type* Typ) { } - void handleSymbolTableType( - unsigned i, - unsigned slot, - const std::string& name - ) - { - } + virtual void handleSymbolTableType( unsigned i, unsigned slot, + const std::string& name ) { } - void handleSymbolTableValue( - unsigned i, - unsigned slot, - const std::string& name - ) - { - } + virtual void handleSymbolTableValue( unsigned i, unsigned slot, + const std::string& name ) { } - void handleSymbolTableEnd() - { - } + virtual void handleSymbolTableEnd() { } - void handleFunctionBegin( - const Type* FType, - GlobalValue::LinkageTypes linkage - ) - { + virtual void handleFunctionBegin( Function* Func, unsigned Size) { + const FunctionType* FType = + cast(Func->getType()->getElementType()); + currFunc = &bca.FunctionInfo[Func]; + currFunc->description = FType->getDescription(); + currFunc->name = Func->getName(); + currFunc->byteSize = Size; + currFunc->numInstructions = 0; + currFunc->numBasicBlocks = 0; + currFunc->numPhis = 0; + currFunc->numOperands = 0; + currFunc->density = 0.0; + currFunc->vbrCount32 = 0; + currFunc->vbrCount64 = 0; + currFunc->vbrCompBytes = 0; + currFunc->vbrExpdBytes = 0; } - void handleFunctionEnd( - const Type* FType - ) - { + virtual void handleFunctionEnd( Function* Func) { + currFunc->density = double(currFunc->byteSize) / + double(currFunc->numInstructions+currFunc->numBasicBlocks); } - void handleBasicBlockBegin( - unsigned blocknum - ) - { + virtual void handleBasicBlockBegin( unsigned blocknum) { bca.numBasicBlocks++; bca.numValues++; + if ( currFunc ) currFunc->numBasicBlocks++; } - bool handleInstruction( - unsigned Opcode, - const Type* iType, - std::vector& Operands, - unsigned Size - ) - { + virtual bool handleInstruction( unsigned Opcode, const Type* iType, + std::vector& Operands, unsigned Size) { bca.numInstructions++; bca.numValues++; bca.numOperands += Operands.size(); + if ( currFunc ) { + currFunc->numInstructions++; + if ( Instruction::isPhiNode(Opcode) ) currFunc->numPhis++; + } return Instruction::isTerminator(Opcode); } - void handleBasicBlockEnd(unsigned blocknum) - { - } + virtual void handleBasicBlockEnd(unsigned blocknum) { } - void handleGlobalConstantsBegin() - { - } + virtual void handleGlobalConstantsBegin() { } - void handleConstantExpression( - unsigned Opcode, - const Type* Typ, - std::vector > ArgVec - ) - { + virtual void handleConstantExpression( unsigned Opcode, const Type* Typ, + std::vector > ArgVec ) { bca.numConstants++; bca.numValues++; } - void handleConstantValue( Constant * c ) - { + virtual void handleConstantValue( Constant * c ) { bca.numConstants++; bca.numValues++; } - void handleConstantArray( - const ArrayType* AT, - std::vector& Elements ) - { + virtual void handleConstantArray( const ArrayType* AT, + std::vector& Elements ) { bca.numConstants++; bca.numValues++; } - void handleConstantStruct( + virtual void handleConstantStruct( const StructType* ST, std::vector& ElementSlots) { @@ -282,27 +225,23 @@ public: bca.numValues++; } - void handleConstantPointer( - const PointerType* PT, unsigned Slot) - { + virtual void handleConstantPointer( const PointerType* PT, unsigned Slot) { bca.numConstants++; bca.numValues++; } - void handleConstantString( const ConstantArray* CA ) - { + virtual void handleConstantString( const ConstantArray* CA ) { bca.numConstants++; bca.numValues++; } + virtual void handleGlobalConstantsEnd() { } - void handleGlobalConstantsEnd() { } - - void handleAlignment(unsigned numBytes) { + virtual void handleAlignment(unsigned numBytes) { bca.numAlignment += numBytes; } - void handleBlock( + virtual void handleBlock( unsigned BType, const unsigned char* StartPtr, unsigned Size) { bca.numBlocks++; bca.BlockSizes[llvm::BytecodeFormat::FileBlockIDs(BType)] += Size; @@ -312,11 +251,22 @@ public: bca.vbrCount32++; bca.vbrCompBytes += Size; bca.vbrExpdBytes += sizeof(uint32_t); + if (currFunc) { + currFunc->vbrCount32++; + currFunc->vbrCompBytes += Size; + currFunc->vbrExpdBytes += sizeof(uint32_t); + } } + virtual void handleVBR64(unsigned Size ) { bca.vbrCount64++; bca.vbrCompBytes += Size; bca.vbrExpdBytes += sizeof(uint64_t); + if ( currFunc ) { + currFunc->vbrCount64++; + currFunc->vbrCompBytes += Size; + currFunc->vbrExpdBytes += sizeof(uint64_t); + } } }; diff --git a/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp b/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp index fd23dc80867..a3cf9f5413f 100644 --- a/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp +++ b/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp @@ -293,21 +293,27 @@ void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) double(bca.BlockSizes[BytecodeFormat::CompactionTable]), double(bca.byteSize)); - std::map::iterator I = + std::map::iterator I = bca.FunctionInfo.begin(); - std::map::iterator E = + std::map::iterator E = bca.FunctionInfo.end(); while ( I != E ) { Out << std::left << std::setw(0); - Out << "Function: " << I->second.name << " Slot=" << I->first << "\n"; - print(Out,"Type:", I->second.description); - print(Out,"Byte Size", I->second.byteSize); - print(Out,"Instructions", I->second.numInstructions); - print(Out,"Basic Blocks", I->second.numBasicBlocks); - print(Out,"Operand", I->second.numOperands); - print(Out,"Function Density", I->second.density); - print(Out,"VBR Effectiveness", I->second.vbrEffectiveness); + Out << "Function: " << I->second.name << "\n"; + print(Out, "Type:", I->second.description); + print(Out, "Byte Size", I->second.byteSize); + print(Out, "Instructions", I->second.numInstructions); + print(Out, "Basic Blocks", I->second.numBasicBlocks); + print(Out, "Operand", I->second.numOperands); + print(Out, "Function Density", I->second.density); + print(Out, "Number of VBR 32-bit Integers", I->second.vbrCount32); + print(Out, "Number of VBR 64-bit Integers", I->second.vbrCount64); + print(Out, "Number of VBR Compressed Bytes", I->second.vbrCompBytes); + print(Out, "Number of VBR Expanded Bytes", I->second.vbrExpdBytes); + print(Out, "VBR Savings", + double(I->second.vbrExpdBytes)-double(I->second.vbrCompBytes), + double(I->second.byteSize)); ++I; } } diff --git a/lib/Bytecode/Reader/Analyzer.cpp b/lib/Bytecode/Reader/Analyzer.cpp index 133c1fbaa6f..3500ed09ea0 100644 --- a/lib/Bytecode/Reader/Analyzer.cpp +++ b/lib/Bytecode/Reader/Analyzer.cpp @@ -22,19 +22,18 @@ namespace { class AnalyzerHandler : public BytecodeHandler { BytecodeAnalysis& bca; + BytecodeAnalysis::BytecodeFunctionInfo* currFunc; public: AnalyzerHandler(BytecodeAnalysis& TheBca) - : bca(TheBca) - { - } + : bca(TheBca) + , currFunc(0) + { } - bool handleError(const std::string& str ) - { + virtual bool handleError(const std::string& str ) { return false; } - void handleStart() - { + virtual void handleStart() { bca.ModuleId.clear(); bca.numBlocks = 0; bca.numTypes = 0; @@ -70,8 +69,7 @@ public: bca.BlockSizes[BytecodeFormat::CompactionTable] = 0; } - void handleFinish() - { + virtual void handleFinish() { bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues ); double globalSize = 0.0; globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPool]); @@ -83,198 +81,143 @@ public: double(bca.numFunctions); } - void handleModuleBegin(const std::string& id) - { + virtual void handleModuleBegin(const std::string& id) { bca.ModuleId = id; } - void handleModuleEnd(const std::string& id) - { - } + virtual void handleModuleEnd(const std::string& id) { } - void handleVersionInfo( + virtual void handleVersionInfo( unsigned char RevisionNum, ///< Byte code revision number Module::Endianness Endianness, ///< Endianness indicator Module::PointerSize PointerSize ///< PointerSize indicator - ) - { - } + ) { } - void handleModuleGlobalsBegin(unsigned size) - { - // bca.globalBytesize += size; - } + virtual void handleModuleGlobalsBegin(unsigned size) { } - void handleGlobalVariable( + virtual void handleGlobalVariable( const Type* ElemType, ///< The type of the global variable bool isConstant, ///< Whether the GV is constant or not GlobalValue::LinkageTypes ///< The linkage type of the GV - ) - { + ) { bca.numGlobalVars++; bca.numValues++; } - void handleInitializedGV( + virtual void handleInitializedGV( const Type* ElemType, ///< The type of the global variable bool isConstant, ///< Whether the GV is constant or not GlobalValue::LinkageTypes,///< The linkage type of the GV unsigned initSlot ///< Slot number of GV's initializer - ) - { + ) { bca.numGlobalVars++; bca.numValues++; } - virtual void handleType( const Type* Ty ) - { - bca.numTypes++; - } + virtual void handleType( const Type* Ty ) { bca.numTypes++; } - void handleFunctionDeclaration( - const Type* FuncType ///< The type of the function - ) - { + virtual void handleFunctionDeclaration( + Function* Func, ///< The function + const FunctionType* FuncType ///< The type of the function + ) { bca.numFunctions++; bca.numValues++; } - void handleModuleGlobalsEnd() - { - } + virtual void handleModuleGlobalsEnd() { } - void handleCompactionTableBegin() - { - } + virtual void handleCompactionTableBegin() { } - void handleCompactionTablePlane( - unsigned Ty, - unsigned NumEntries - ) - { + virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) { bca.numCmpctnTables++; } - void handleCompactionTableType( - unsigned i, - unsigned TypSlot, - const Type* - ) - { - } + virtual void handleCompactionTableType( unsigned i, unsigned TypSlot, + const Type* ) {} - void handleCompactionTableValue( + virtual void handleCompactionTableValue( unsigned i, unsigned ValSlot, - const Type* - ) - { - } + const Type* ) { } - void handleCompactionTableEnd() - { - } + virtual void handleCompactionTableEnd() { } - void handleSymbolTableBegin() - { - bca.numSymTab++; - } + virtual void handleSymbolTableBegin() { bca.numSymTab++; } - void handleSymbolTablePlane( - unsigned Ty, - unsigned NumEntries, - const Type* Typ - ) - { - } + virtual void handleSymbolTablePlane( unsigned Ty, unsigned NumEntries, + const Type* Typ) { } - void handleSymbolTableType( - unsigned i, - unsigned slot, - const std::string& name - ) - { - } + virtual void handleSymbolTableType( unsigned i, unsigned slot, + const std::string& name ) { } - void handleSymbolTableValue( - unsigned i, - unsigned slot, - const std::string& name - ) - { - } + virtual void handleSymbolTableValue( unsigned i, unsigned slot, + const std::string& name ) { } - void handleSymbolTableEnd() - { - } + virtual void handleSymbolTableEnd() { } - void handleFunctionBegin( - const Type* FType, - GlobalValue::LinkageTypes linkage - ) - { + virtual void handleFunctionBegin( Function* Func, unsigned Size) { + const FunctionType* FType = + cast(Func->getType()->getElementType()); + currFunc = &bca.FunctionInfo[Func]; + currFunc->description = FType->getDescription(); + currFunc->name = Func->getName(); + currFunc->byteSize = Size; + currFunc->numInstructions = 0; + currFunc->numBasicBlocks = 0; + currFunc->numPhis = 0; + currFunc->numOperands = 0; + currFunc->density = 0.0; + currFunc->vbrCount32 = 0; + currFunc->vbrCount64 = 0; + currFunc->vbrCompBytes = 0; + currFunc->vbrExpdBytes = 0; } - void handleFunctionEnd( - const Type* FType - ) - { + virtual void handleFunctionEnd( Function* Func) { + currFunc->density = double(currFunc->byteSize) / + double(currFunc->numInstructions+currFunc->numBasicBlocks); } - void handleBasicBlockBegin( - unsigned blocknum - ) - { + virtual void handleBasicBlockBegin( unsigned blocknum) { bca.numBasicBlocks++; bca.numValues++; + if ( currFunc ) currFunc->numBasicBlocks++; } - bool handleInstruction( - unsigned Opcode, - const Type* iType, - std::vector& Operands, - unsigned Size - ) - { + virtual bool handleInstruction( unsigned Opcode, const Type* iType, + std::vector& Operands, unsigned Size) { bca.numInstructions++; bca.numValues++; bca.numOperands += Operands.size(); + if ( currFunc ) { + currFunc->numInstructions++; + if ( Instruction::isPhiNode(Opcode) ) currFunc->numPhis++; + } return Instruction::isTerminator(Opcode); } - void handleBasicBlockEnd(unsigned blocknum) - { - } + virtual void handleBasicBlockEnd(unsigned blocknum) { } - void handleGlobalConstantsBegin() - { - } + virtual void handleGlobalConstantsBegin() { } - void handleConstantExpression( - unsigned Opcode, - const Type* Typ, - std::vector > ArgVec - ) - { + virtual void handleConstantExpression( unsigned Opcode, const Type* Typ, + std::vector > ArgVec ) { bca.numConstants++; bca.numValues++; } - void handleConstantValue( Constant * c ) - { + virtual void handleConstantValue( Constant * c ) { bca.numConstants++; bca.numValues++; } - void handleConstantArray( - const ArrayType* AT, - std::vector& Elements ) - { + virtual void handleConstantArray( const ArrayType* AT, + std::vector& Elements ) { bca.numConstants++; bca.numValues++; } - void handleConstantStruct( + virtual void handleConstantStruct( const StructType* ST, std::vector& ElementSlots) { @@ -282,27 +225,23 @@ public: bca.numValues++; } - void handleConstantPointer( - const PointerType* PT, unsigned Slot) - { + virtual void handleConstantPointer( const PointerType* PT, unsigned Slot) { bca.numConstants++; bca.numValues++; } - void handleConstantString( const ConstantArray* CA ) - { + virtual void handleConstantString( const ConstantArray* CA ) { bca.numConstants++; bca.numValues++; } + virtual void handleGlobalConstantsEnd() { } - void handleGlobalConstantsEnd() { } - - void handleAlignment(unsigned numBytes) { + virtual void handleAlignment(unsigned numBytes) { bca.numAlignment += numBytes; } - void handleBlock( + virtual void handleBlock( unsigned BType, const unsigned char* StartPtr, unsigned Size) { bca.numBlocks++; bca.BlockSizes[llvm::BytecodeFormat::FileBlockIDs(BType)] += Size; @@ -312,11 +251,22 @@ public: bca.vbrCount32++; bca.vbrCompBytes += Size; bca.vbrExpdBytes += sizeof(uint32_t); + if (currFunc) { + currFunc->vbrCount32++; + currFunc->vbrCompBytes += Size; + currFunc->vbrExpdBytes += sizeof(uint32_t); + } } + virtual void handleVBR64(unsigned Size ) { bca.vbrCount64++; bca.vbrCompBytes += Size; bca.vbrExpdBytes += sizeof(uint64_t); + if ( currFunc ) { + currFunc->vbrCount64++; + currFunc->vbrCompBytes += Size; + currFunc->vbrExpdBytes += sizeof(uint64_t); + } } }; diff --git a/lib/Bytecode/Reader/AnalyzerWrappers.cpp b/lib/Bytecode/Reader/AnalyzerWrappers.cpp index fd23dc80867..a3cf9f5413f 100644 --- a/lib/Bytecode/Reader/AnalyzerWrappers.cpp +++ b/lib/Bytecode/Reader/AnalyzerWrappers.cpp @@ -293,21 +293,27 @@ void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) double(bca.BlockSizes[BytecodeFormat::CompactionTable]), double(bca.byteSize)); - std::map::iterator I = + std::map::iterator I = bca.FunctionInfo.begin(); - std::map::iterator E = + std::map::iterator E = bca.FunctionInfo.end(); while ( I != E ) { Out << std::left << std::setw(0); - Out << "Function: " << I->second.name << " Slot=" << I->first << "\n"; - print(Out,"Type:", I->second.description); - print(Out,"Byte Size", I->second.byteSize); - print(Out,"Instructions", I->second.numInstructions); - print(Out,"Basic Blocks", I->second.numBasicBlocks); - print(Out,"Operand", I->second.numOperands); - print(Out,"Function Density", I->second.density); - print(Out,"VBR Effectiveness", I->second.vbrEffectiveness); + Out << "Function: " << I->second.name << "\n"; + print(Out, "Type:", I->second.description); + print(Out, "Byte Size", I->second.byteSize); + print(Out, "Instructions", I->second.numInstructions); + print(Out, "Basic Blocks", I->second.numBasicBlocks); + print(Out, "Operand", I->second.numOperands); + print(Out, "Function Density", I->second.density); + print(Out, "Number of VBR 32-bit Integers", I->second.vbrCount32); + print(Out, "Number of VBR 64-bit Integers", I->second.vbrCount64); + print(Out, "Number of VBR Compressed Bytes", I->second.vbrCompBytes); + print(Out, "Number of VBR Expanded Bytes", I->second.vbrExpdBytes); + print(Out, "VBR Savings", + double(I->second.vbrExpdBytes)-double(I->second.vbrCompBytes), + double(I->second.byteSize)); ++I; } } -- 2.34.1