[llvm-commits] CVS: llvm/lib/Bytecode/Analyzer/Analyzer.cpp AnalyzerWrappers.cpp
LLVM
llvm at cs.uiuc.edu
Thu Jun 10 17:06:08 PDT 2004
Changes in directory llvm/lib/Bytecode/Analyzer:
Analyzer.cpp updated: 1.3 -> 1.4
AnalyzerWrappers.cpp updated: 1.4 -> 1.5
---
Log message:
Implement detailed function level data collection and reporting.
---
Diffs of the changes: (+104 -148)
Index: llvm/lib/Bytecode/Analyzer/Analyzer.cpp
diff -u llvm/lib/Bytecode/Analyzer/Analyzer.cpp:1.3 llvm/lib/Bytecode/Analyzer/Analyzer.cpp:1.4
--- llvm/lib/Bytecode/Analyzer/Analyzer.cpp:1.3 Thu Jun 10 03:09:12 2004
+++ llvm/lib/Bytecode/Analyzer/Analyzer.cpp Thu Jun 10 17:00:54 2004
@@ -22,19 +22,18 @@
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 @@
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 @@
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<FunctionType>(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<unsigned>& Operands,
- unsigned Size
- )
- {
+ virtual bool handleInstruction( unsigned Opcode, const Type* iType,
+ std::vector<unsigned>& 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<std::pair<const Type*,unsigned> > ArgVec
- )
- {
+ virtual void handleConstantExpression( unsigned Opcode, const Type* Typ,
+ std::vector<std::pair<const Type*,unsigned> > 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<unsigned>& Elements )
- {
+ virtual void handleConstantArray( const ArrayType* AT,
+ std::vector<unsigned>& Elements ) {
bca.numConstants++;
bca.numValues++;
}
- void handleConstantStruct(
+ virtual void handleConstantStruct(
const StructType* ST,
std::vector<unsigned>& ElementSlots)
{
@@ -282,27 +225,23 @@
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 @@
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);
+ }
}
};
Index: llvm/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp
diff -u llvm/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp:1.4 llvm/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp:1.5
--- llvm/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp:1.4 Thu Jun 10 03:09:13 2004
+++ llvm/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp Thu Jun 10 17:00:54 2004
@@ -293,21 +293,27 @@
double(bca.BlockSizes[BytecodeFormat::CompactionTable]),
double(bca.byteSize));
- std::map<unsigned,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
+ std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I =
bca.FunctionInfo.begin();
- std::map<unsigned,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E =
+ std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::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;
}
}
More information about the llvm-commits
mailing list