Implement detailed function level data collection and reporting.
llvm-svn: 14122
This commit is contained in:
		
							parent
							
								
									90f0032664
								
							
						
					
					
						commit
						7670bbdfb9
					
				| 
						 | 
					@ -22,19 +22,18 @@ namespace {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AnalyzerHandler : public BytecodeHandler {
 | 
					class AnalyzerHandler : public BytecodeHandler {
 | 
				
			||||||
  BytecodeAnalysis& bca;
 | 
					  BytecodeAnalysis& bca;
 | 
				
			||||||
 | 
					  BytecodeAnalysis::BytecodeFunctionInfo* currFunc;
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  AnalyzerHandler(BytecodeAnalysis& TheBca) 
 | 
					  AnalyzerHandler(BytecodeAnalysis& TheBca) 
 | 
				
			||||||
    : bca(TheBca) 
 | 
					    : bca(TheBca) 
 | 
				
			||||||
  {
 | 
					    , currFunc(0)
 | 
				
			||||||
  }  
 | 
					    { }  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool handleError(const std::string& str )
 | 
					  virtual bool handleError(const std::string& str ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleStart()
 | 
					  virtual void handleStart() {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.ModuleId.clear();
 | 
					    bca.ModuleId.clear();
 | 
				
			||||||
    bca.numBlocks = 0;
 | 
					    bca.numBlocks = 0;
 | 
				
			||||||
    bca.numTypes = 0;
 | 
					    bca.numTypes = 0;
 | 
				
			||||||
| 
						 | 
					@ -70,8 +69,7 @@ public:
 | 
				
			||||||
    bca.BlockSizes[BytecodeFormat::CompactionTable] = 0;
 | 
					    bca.BlockSizes[BytecodeFormat::CompactionTable] = 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleFinish()
 | 
					  virtual void handleFinish() {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
 | 
					    bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
 | 
				
			||||||
    double globalSize = 0.0;
 | 
					    double globalSize = 0.0;
 | 
				
			||||||
    globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPool]);
 | 
					    globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPool]);
 | 
				
			||||||
| 
						 | 
					@ -83,198 +81,143 @@ public:
 | 
				
			||||||
      double(bca.numFunctions);
 | 
					      double(bca.numFunctions);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleModuleBegin(const std::string& id)
 | 
					  virtual void handleModuleBegin(const std::string& id) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.ModuleId = 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
 | 
					    unsigned char RevisionNum,        ///< Byte code revision number
 | 
				
			||||||
    Module::Endianness Endianness,    ///< Endianness indicator
 | 
					    Module::Endianness Endianness,    ///< Endianness indicator
 | 
				
			||||||
    Module::PointerSize PointerSize   ///< PointerSize indicator
 | 
					    Module::PointerSize PointerSize   ///< PointerSize indicator
 | 
				
			||||||
  )
 | 
					  ) { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleModuleGlobalsBegin(unsigned size)
 | 
					  virtual void handleModuleGlobalsBegin(unsigned size) { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    // bca.globalBytesize += size;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleGlobalVariable( 
 | 
					  virtual void handleGlobalVariable( 
 | 
				
			||||||
    const Type* ElemType,     ///< The type of the global variable
 | 
					    const Type* ElemType,     ///< The type of the global variable
 | 
				
			||||||
    bool isConstant,          ///< Whether the GV is constant or not
 | 
					    bool isConstant,          ///< Whether the GV is constant or not
 | 
				
			||||||
    GlobalValue::LinkageTypes ///< The linkage type of the GV
 | 
					    GlobalValue::LinkageTypes ///< The linkage type of the GV
 | 
				
			||||||
  )
 | 
					  ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numGlobalVars++;
 | 
					    bca.numGlobalVars++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleInitializedGV( 
 | 
					  virtual void handleInitializedGV( 
 | 
				
			||||||
    const Type* ElemType,     ///< The type of the global variable
 | 
					    const Type* ElemType,     ///< The type of the global variable
 | 
				
			||||||
    bool isConstant,          ///< Whether the GV is constant or not
 | 
					    bool isConstant,          ///< Whether the GV is constant or not
 | 
				
			||||||
    GlobalValue::LinkageTypes,///< The linkage type of the GV
 | 
					    GlobalValue::LinkageTypes,///< The linkage type of the GV
 | 
				
			||||||
    unsigned initSlot         ///< Slot number of GV's initializer
 | 
					    unsigned initSlot         ///< Slot number of GV's initializer
 | 
				
			||||||
  )
 | 
					  ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numGlobalVars++;
 | 
					    bca.numGlobalVars++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  virtual void handleType( const Type* Ty ) 
 | 
					  virtual void handleType( const Type* Ty ) { bca.numTypes++; }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numTypes++;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleFunctionDeclaration( 
 | 
					  virtual void handleFunctionDeclaration( 
 | 
				
			||||||
    const Type* FuncType      ///< The type of the function
 | 
					    Function* Func,	    ///< The function
 | 
				
			||||||
  )
 | 
					    const FunctionType* FuncType    ///< The type of the function
 | 
				
			||||||
  {
 | 
					  ) {
 | 
				
			||||||
    bca.numFunctions++;
 | 
					    bca.numFunctions++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleModuleGlobalsEnd()
 | 
					  virtual void handleModuleGlobalsEnd() { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTableBegin()
 | 
					  virtual void handleCompactionTableBegin() { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTablePlane( 
 | 
					  virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) {
 | 
				
			||||||
    unsigned Ty, 
 | 
					 | 
				
			||||||
    unsigned NumEntries
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numCmpctnTables++;
 | 
					    bca.numCmpctnTables++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTableType( 
 | 
					  virtual void handleCompactionTableType( unsigned i, unsigned TypSlot, 
 | 
				
			||||||
    unsigned i, 
 | 
					      const Type* ) {}
 | 
				
			||||||
    unsigned TypSlot, 
 | 
					 | 
				
			||||||
    const Type* 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTableValue( 
 | 
					  virtual void handleCompactionTableValue( 
 | 
				
			||||||
    unsigned i, 
 | 
					    unsigned i, 
 | 
				
			||||||
    unsigned ValSlot, 
 | 
					    unsigned ValSlot, 
 | 
				
			||||||
    const Type* 
 | 
					    const Type* ) { }
 | 
				
			||||||
  )
 | 
					
 | 
				
			||||||
  {
 | 
					  virtual void handleCompactionTableEnd() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableBegin() { bca.numSymTab++; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTablePlane( unsigned Ty, unsigned NumEntries, 
 | 
				
			||||||
 | 
					    const Type* Typ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableType( unsigned i, unsigned slot, 
 | 
				
			||||||
 | 
					    const std::string& name ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableValue( unsigned i, unsigned slot, 
 | 
				
			||||||
 | 
					    const std::string& name ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableEnd() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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 handleCompactionTableEnd()
 | 
					  virtual void handleFunctionEnd( Function* Func) {
 | 
				
			||||||
  {
 | 
					    currFunc->density = double(currFunc->byteSize) /
 | 
				
			||||||
 | 
					      double(currFunc->numInstructions+currFunc->numBasicBlocks);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleSymbolTableBegin()
 | 
					  virtual void handleBasicBlockBegin( unsigned blocknum) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numSymTab++;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTablePlane( 
 | 
					 | 
				
			||||||
    unsigned Ty, 
 | 
					 | 
				
			||||||
    unsigned NumEntries, 
 | 
					 | 
				
			||||||
    const Type* Typ
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTableType( 
 | 
					 | 
				
			||||||
    unsigned i, 
 | 
					 | 
				
			||||||
    unsigned slot, 
 | 
					 | 
				
			||||||
    const std::string& name 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTableValue( 
 | 
					 | 
				
			||||||
    unsigned i, 
 | 
					 | 
				
			||||||
    unsigned slot, 
 | 
					 | 
				
			||||||
    const std::string& name 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTableEnd()
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleFunctionBegin(
 | 
					 | 
				
			||||||
    const Type* FType, 
 | 
					 | 
				
			||||||
    GlobalValue::LinkageTypes linkage 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleFunctionEnd(
 | 
					 | 
				
			||||||
    const Type* FType
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleBasicBlockBegin(
 | 
					 | 
				
			||||||
    unsigned blocknum
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numBasicBlocks++;
 | 
					    bca.numBasicBlocks++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
 | 
					    if ( currFunc ) currFunc->numBasicBlocks++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool handleInstruction(
 | 
					  virtual bool handleInstruction( unsigned Opcode, const Type* iType, 
 | 
				
			||||||
    unsigned Opcode, 
 | 
					    std::vector<unsigned>& Operands, unsigned Size) {
 | 
				
			||||||
    const Type* iType, 
 | 
					 | 
				
			||||||
    std::vector<unsigned>& Operands,
 | 
					 | 
				
			||||||
    unsigned Size
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numInstructions++;
 | 
					    bca.numInstructions++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
    bca.numOperands += Operands.size();
 | 
					    bca.numOperands += Operands.size();
 | 
				
			||||||
 | 
					    if ( currFunc ) {
 | 
				
			||||||
 | 
					      currFunc->numInstructions++;
 | 
				
			||||||
 | 
					      if ( Instruction::isPhiNode(Opcode) ) currFunc->numPhis++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return Instruction::isTerminator(Opcode); 
 | 
					    return Instruction::isTerminator(Opcode); 
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleBasicBlockEnd(unsigned blocknum)
 | 
					  virtual void handleBasicBlockEnd(unsigned blocknum) { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleGlobalConstantsBegin()
 | 
					  virtual void handleGlobalConstantsBegin() { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantExpression( 
 | 
					  virtual void handleConstantExpression( unsigned Opcode, const Type* Typ, 
 | 
				
			||||||
      unsigned Opcode, 
 | 
					      std::vector<std::pair<const Type*,unsigned> > ArgVec ) {
 | 
				
			||||||
      const Type* Typ, 
 | 
					 | 
				
			||||||
      std::vector<std::pair<const Type*,unsigned> > ArgVec 
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantValue( Constant * c )
 | 
					  virtual void handleConstantValue( Constant * c ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantArray( 
 | 
					  virtual void handleConstantArray( const ArrayType* AT, 
 | 
				
			||||||
          const ArrayType* AT, 
 | 
					          std::vector<unsigned>& Elements ) {
 | 
				
			||||||
          std::vector<unsigned>& Elements )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantStruct(
 | 
					  virtual void handleConstantStruct(
 | 
				
			||||||
        const StructType* ST,
 | 
					        const StructType* ST,
 | 
				
			||||||
        std::vector<unsigned>& ElementSlots)
 | 
					        std::vector<unsigned>& ElementSlots)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
| 
						 | 
					@ -282,27 +225,23 @@ public:
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantPointer(
 | 
					  virtual void handleConstantPointer( const PointerType* PT, unsigned Slot) {
 | 
				
			||||||
        const PointerType* PT, unsigned Slot)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantString( const ConstantArray* CA ) 
 | 
					  virtual void handleConstantString( const ConstantArray* CA ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleGlobalConstantsEnd() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleGlobalConstantsEnd() { }
 | 
					  virtual void handleAlignment(unsigned numBytes) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleAlignment(unsigned numBytes) {
 | 
					 | 
				
			||||||
    bca.numAlignment += numBytes;
 | 
					    bca.numAlignment += numBytes;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleBlock(
 | 
					  virtual void handleBlock(
 | 
				
			||||||
    unsigned BType, const unsigned char* StartPtr, unsigned Size) {
 | 
					    unsigned BType, const unsigned char* StartPtr, unsigned Size) {
 | 
				
			||||||
    bca.numBlocks++;
 | 
					    bca.numBlocks++;
 | 
				
			||||||
    bca.BlockSizes[llvm::BytecodeFormat::FileBlockIDs(BType)] += Size;
 | 
					    bca.BlockSizes[llvm::BytecodeFormat::FileBlockIDs(BType)] += Size;
 | 
				
			||||||
| 
						 | 
					@ -312,11 +251,22 @@ public:
 | 
				
			||||||
    bca.vbrCount32++;
 | 
					    bca.vbrCount32++;
 | 
				
			||||||
    bca.vbrCompBytes += Size;
 | 
					    bca.vbrCompBytes += Size;
 | 
				
			||||||
    bca.vbrExpdBytes += sizeof(uint32_t);
 | 
					    bca.vbrExpdBytes += sizeof(uint32_t);
 | 
				
			||||||
 | 
					    if (currFunc) {
 | 
				
			||||||
 | 
					      currFunc->vbrCount32++;
 | 
				
			||||||
 | 
					      currFunc->vbrCompBytes += Size;
 | 
				
			||||||
 | 
					      currFunc->vbrExpdBytes += sizeof(uint32_t);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  virtual void handleVBR64(unsigned Size ) {
 | 
					  virtual void handleVBR64(unsigned Size ) {
 | 
				
			||||||
    bca.vbrCount64++;
 | 
					    bca.vbrCount64++;
 | 
				
			||||||
    bca.vbrCompBytes += Size;
 | 
					    bca.vbrCompBytes += Size;
 | 
				
			||||||
    bca.vbrExpdBytes += sizeof(uint64_t);
 | 
					    bca.vbrExpdBytes += sizeof(uint64_t);
 | 
				
			||||||
 | 
					    if ( currFunc ) {
 | 
				
			||||||
 | 
					      currFunc->vbrCount64++;
 | 
				
			||||||
 | 
					      currFunc->vbrCompBytes += Size;
 | 
				
			||||||
 | 
					      currFunc->vbrExpdBytes += sizeof(uint64_t);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -293,21 +293,27 @@ void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
 | 
				
			||||||
        double(bca.BlockSizes[BytecodeFormat::CompactionTable]),
 | 
					        double(bca.BlockSizes[BytecodeFormat::CompactionTable]),
 | 
				
			||||||
        double(bca.byteSize));
 | 
					        double(bca.byteSize));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::map<unsigned,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I = 
 | 
					    std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I = 
 | 
				
			||||||
      bca.FunctionInfo.begin();
 | 
					      bca.FunctionInfo.begin();
 | 
				
			||||||
    std::map<unsigned,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E = 
 | 
					    std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E = 
 | 
				
			||||||
      bca.FunctionInfo.end();
 | 
					      bca.FunctionInfo.end();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while ( I != E ) {
 | 
					    while ( I != E ) {
 | 
				
			||||||
      Out << std::left << std::setw(0);
 | 
					      Out << std::left << std::setw(0);
 | 
				
			||||||
      Out << "Function: " << I->second.name << " Slot=" << I->first << "\n";
 | 
					      Out << "Function: " << I->second.name << "\n";
 | 
				
			||||||
      print(Out,"Type:", I->second.description);
 | 
					      print(Out, "Type:", I->second.description);
 | 
				
			||||||
      print(Out,"Byte Size", I->second.byteSize);
 | 
					      print(Out, "Byte Size", I->second.byteSize);
 | 
				
			||||||
      print(Out,"Instructions", I->second.numInstructions);
 | 
					      print(Out, "Instructions", I->second.numInstructions);
 | 
				
			||||||
      print(Out,"Basic Blocks", I->second.numBasicBlocks);
 | 
					      print(Out, "Basic Blocks", I->second.numBasicBlocks);
 | 
				
			||||||
      print(Out,"Operand", I->second.numOperands);
 | 
					      print(Out, "Operand", I->second.numOperands);
 | 
				
			||||||
      print(Out,"Function Density", I->second.density);
 | 
					      print(Out, "Function Density", I->second.density);
 | 
				
			||||||
      print(Out,"VBR Effectiveness", I->second.vbrEffectiveness);
 | 
					      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;
 | 
					      ++I;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,19 +22,18 @@ namespace {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AnalyzerHandler : public BytecodeHandler {
 | 
					class AnalyzerHandler : public BytecodeHandler {
 | 
				
			||||||
  BytecodeAnalysis& bca;
 | 
					  BytecodeAnalysis& bca;
 | 
				
			||||||
 | 
					  BytecodeAnalysis::BytecodeFunctionInfo* currFunc;
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  AnalyzerHandler(BytecodeAnalysis& TheBca) 
 | 
					  AnalyzerHandler(BytecodeAnalysis& TheBca) 
 | 
				
			||||||
    : bca(TheBca) 
 | 
					    : bca(TheBca) 
 | 
				
			||||||
  {
 | 
					    , currFunc(0)
 | 
				
			||||||
  }  
 | 
					    { }  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool handleError(const std::string& str )
 | 
					  virtual bool handleError(const std::string& str ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleStart()
 | 
					  virtual void handleStart() {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.ModuleId.clear();
 | 
					    bca.ModuleId.clear();
 | 
				
			||||||
    bca.numBlocks = 0;
 | 
					    bca.numBlocks = 0;
 | 
				
			||||||
    bca.numTypes = 0;
 | 
					    bca.numTypes = 0;
 | 
				
			||||||
| 
						 | 
					@ -70,8 +69,7 @@ public:
 | 
				
			||||||
    bca.BlockSizes[BytecodeFormat::CompactionTable] = 0;
 | 
					    bca.BlockSizes[BytecodeFormat::CompactionTable] = 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleFinish()
 | 
					  virtual void handleFinish() {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
 | 
					    bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues );
 | 
				
			||||||
    double globalSize = 0.0;
 | 
					    double globalSize = 0.0;
 | 
				
			||||||
    globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPool]);
 | 
					    globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPool]);
 | 
				
			||||||
| 
						 | 
					@ -83,198 +81,143 @@ public:
 | 
				
			||||||
      double(bca.numFunctions);
 | 
					      double(bca.numFunctions);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleModuleBegin(const std::string& id)
 | 
					  virtual void handleModuleBegin(const std::string& id) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.ModuleId = 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
 | 
					    unsigned char RevisionNum,        ///< Byte code revision number
 | 
				
			||||||
    Module::Endianness Endianness,    ///< Endianness indicator
 | 
					    Module::Endianness Endianness,    ///< Endianness indicator
 | 
				
			||||||
    Module::PointerSize PointerSize   ///< PointerSize indicator
 | 
					    Module::PointerSize PointerSize   ///< PointerSize indicator
 | 
				
			||||||
  )
 | 
					  ) { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleModuleGlobalsBegin(unsigned size)
 | 
					  virtual void handleModuleGlobalsBegin(unsigned size) { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    // bca.globalBytesize += size;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleGlobalVariable( 
 | 
					  virtual void handleGlobalVariable( 
 | 
				
			||||||
    const Type* ElemType,     ///< The type of the global variable
 | 
					    const Type* ElemType,     ///< The type of the global variable
 | 
				
			||||||
    bool isConstant,          ///< Whether the GV is constant or not
 | 
					    bool isConstant,          ///< Whether the GV is constant or not
 | 
				
			||||||
    GlobalValue::LinkageTypes ///< The linkage type of the GV
 | 
					    GlobalValue::LinkageTypes ///< The linkage type of the GV
 | 
				
			||||||
  )
 | 
					  ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numGlobalVars++;
 | 
					    bca.numGlobalVars++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleInitializedGV( 
 | 
					  virtual void handleInitializedGV( 
 | 
				
			||||||
    const Type* ElemType,     ///< The type of the global variable
 | 
					    const Type* ElemType,     ///< The type of the global variable
 | 
				
			||||||
    bool isConstant,          ///< Whether the GV is constant or not
 | 
					    bool isConstant,          ///< Whether the GV is constant or not
 | 
				
			||||||
    GlobalValue::LinkageTypes,///< The linkage type of the GV
 | 
					    GlobalValue::LinkageTypes,///< The linkage type of the GV
 | 
				
			||||||
    unsigned initSlot         ///< Slot number of GV's initializer
 | 
					    unsigned initSlot         ///< Slot number of GV's initializer
 | 
				
			||||||
  )
 | 
					  ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numGlobalVars++;
 | 
					    bca.numGlobalVars++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  virtual void handleType( const Type* Ty ) 
 | 
					  virtual void handleType( const Type* Ty ) { bca.numTypes++; }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numTypes++;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleFunctionDeclaration( 
 | 
					  virtual void handleFunctionDeclaration( 
 | 
				
			||||||
    const Type* FuncType      ///< The type of the function
 | 
					    Function* Func,	    ///< The function
 | 
				
			||||||
  )
 | 
					    const FunctionType* FuncType    ///< The type of the function
 | 
				
			||||||
  {
 | 
					  ) {
 | 
				
			||||||
    bca.numFunctions++;
 | 
					    bca.numFunctions++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleModuleGlobalsEnd()
 | 
					  virtual void handleModuleGlobalsEnd() { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTableBegin()
 | 
					  virtual void handleCompactionTableBegin() { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTablePlane( 
 | 
					  virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) {
 | 
				
			||||||
    unsigned Ty, 
 | 
					 | 
				
			||||||
    unsigned NumEntries
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numCmpctnTables++;
 | 
					    bca.numCmpctnTables++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTableType( 
 | 
					  virtual void handleCompactionTableType( unsigned i, unsigned TypSlot, 
 | 
				
			||||||
    unsigned i, 
 | 
					      const Type* ) {}
 | 
				
			||||||
    unsigned TypSlot, 
 | 
					 | 
				
			||||||
    const Type* 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleCompactionTableValue( 
 | 
					  virtual void handleCompactionTableValue( 
 | 
				
			||||||
    unsigned i, 
 | 
					    unsigned i, 
 | 
				
			||||||
    unsigned ValSlot, 
 | 
					    unsigned ValSlot, 
 | 
				
			||||||
    const Type* 
 | 
					    const Type* ) { }
 | 
				
			||||||
  )
 | 
					
 | 
				
			||||||
  {
 | 
					  virtual void handleCompactionTableEnd() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableBegin() { bca.numSymTab++; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTablePlane( unsigned Ty, unsigned NumEntries, 
 | 
				
			||||||
 | 
					    const Type* Typ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableType( unsigned i, unsigned slot, 
 | 
				
			||||||
 | 
					    const std::string& name ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableValue( unsigned i, unsigned slot, 
 | 
				
			||||||
 | 
					    const std::string& name ) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleSymbolTableEnd() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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 handleCompactionTableEnd()
 | 
					  virtual void handleFunctionEnd( Function* Func) {
 | 
				
			||||||
  {
 | 
					    currFunc->density = double(currFunc->byteSize) /
 | 
				
			||||||
 | 
					      double(currFunc->numInstructions+currFunc->numBasicBlocks);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleSymbolTableBegin()
 | 
					  virtual void handleBasicBlockBegin( unsigned blocknum) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numSymTab++;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTablePlane( 
 | 
					 | 
				
			||||||
    unsigned Ty, 
 | 
					 | 
				
			||||||
    unsigned NumEntries, 
 | 
					 | 
				
			||||||
    const Type* Typ
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTableType( 
 | 
					 | 
				
			||||||
    unsigned i, 
 | 
					 | 
				
			||||||
    unsigned slot, 
 | 
					 | 
				
			||||||
    const std::string& name 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTableValue( 
 | 
					 | 
				
			||||||
    unsigned i, 
 | 
					 | 
				
			||||||
    unsigned slot, 
 | 
					 | 
				
			||||||
    const std::string& name 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleSymbolTableEnd()
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleFunctionBegin(
 | 
					 | 
				
			||||||
    const Type* FType, 
 | 
					 | 
				
			||||||
    GlobalValue::LinkageTypes linkage 
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleFunctionEnd(
 | 
					 | 
				
			||||||
    const Type* FType
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleBasicBlockBegin(
 | 
					 | 
				
			||||||
    unsigned blocknum
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numBasicBlocks++;
 | 
					    bca.numBasicBlocks++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
 | 
					    if ( currFunc ) currFunc->numBasicBlocks++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool handleInstruction(
 | 
					  virtual bool handleInstruction( unsigned Opcode, const Type* iType, 
 | 
				
			||||||
    unsigned Opcode, 
 | 
					    std::vector<unsigned>& Operands, unsigned Size) {
 | 
				
			||||||
    const Type* iType, 
 | 
					 | 
				
			||||||
    std::vector<unsigned>& Operands,
 | 
					 | 
				
			||||||
    unsigned Size
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numInstructions++;
 | 
					    bca.numInstructions++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
    bca.numOperands += Operands.size();
 | 
					    bca.numOperands += Operands.size();
 | 
				
			||||||
 | 
					    if ( currFunc ) {
 | 
				
			||||||
 | 
					      currFunc->numInstructions++;
 | 
				
			||||||
 | 
					      if ( Instruction::isPhiNode(Opcode) ) currFunc->numPhis++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return Instruction::isTerminator(Opcode); 
 | 
					    return Instruction::isTerminator(Opcode); 
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleBasicBlockEnd(unsigned blocknum)
 | 
					  virtual void handleBasicBlockEnd(unsigned blocknum) { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleGlobalConstantsBegin()
 | 
					  virtual void handleGlobalConstantsBegin() { }
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantExpression( 
 | 
					  virtual void handleConstantExpression( unsigned Opcode, const Type* Typ, 
 | 
				
			||||||
      unsigned Opcode, 
 | 
					      std::vector<std::pair<const Type*,unsigned> > ArgVec ) {
 | 
				
			||||||
      const Type* Typ, 
 | 
					 | 
				
			||||||
      std::vector<std::pair<const Type*,unsigned> > ArgVec 
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantValue( Constant * c )
 | 
					  virtual void handleConstantValue( Constant * c ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantArray( 
 | 
					  virtual void handleConstantArray( const ArrayType* AT, 
 | 
				
			||||||
          const ArrayType* AT, 
 | 
					          std::vector<unsigned>& Elements ) {
 | 
				
			||||||
          std::vector<unsigned>& Elements )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantStruct(
 | 
					  virtual void handleConstantStruct(
 | 
				
			||||||
        const StructType* ST,
 | 
					        const StructType* ST,
 | 
				
			||||||
        std::vector<unsigned>& ElementSlots)
 | 
					        std::vector<unsigned>& ElementSlots)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
| 
						 | 
					@ -282,27 +225,23 @@ public:
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantPointer(
 | 
					  virtual void handleConstantPointer( const PointerType* PT, unsigned Slot) {
 | 
				
			||||||
        const PointerType* PT, unsigned Slot)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleConstantString( const ConstantArray* CA ) 
 | 
					  virtual void handleConstantString( const ConstantArray* CA ) {
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    bca.numConstants++;
 | 
					    bca.numConstants++;
 | 
				
			||||||
    bca.numValues++;
 | 
					    bca.numValues++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  virtual void handleGlobalConstantsEnd() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleGlobalConstantsEnd() { }
 | 
					  virtual void handleAlignment(unsigned numBytes) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
  void handleAlignment(unsigned numBytes) {
 | 
					 | 
				
			||||||
    bca.numAlignment += numBytes;
 | 
					    bca.numAlignment += numBytes;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void handleBlock(
 | 
					  virtual void handleBlock(
 | 
				
			||||||
    unsigned BType, const unsigned char* StartPtr, unsigned Size) {
 | 
					    unsigned BType, const unsigned char* StartPtr, unsigned Size) {
 | 
				
			||||||
    bca.numBlocks++;
 | 
					    bca.numBlocks++;
 | 
				
			||||||
    bca.BlockSizes[llvm::BytecodeFormat::FileBlockIDs(BType)] += Size;
 | 
					    bca.BlockSizes[llvm::BytecodeFormat::FileBlockIDs(BType)] += Size;
 | 
				
			||||||
| 
						 | 
					@ -312,11 +251,22 @@ public:
 | 
				
			||||||
    bca.vbrCount32++;
 | 
					    bca.vbrCount32++;
 | 
				
			||||||
    bca.vbrCompBytes += Size;
 | 
					    bca.vbrCompBytes += Size;
 | 
				
			||||||
    bca.vbrExpdBytes += sizeof(uint32_t);
 | 
					    bca.vbrExpdBytes += sizeof(uint32_t);
 | 
				
			||||||
 | 
					    if (currFunc) {
 | 
				
			||||||
 | 
					      currFunc->vbrCount32++;
 | 
				
			||||||
 | 
					      currFunc->vbrCompBytes += Size;
 | 
				
			||||||
 | 
					      currFunc->vbrExpdBytes += sizeof(uint32_t);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  virtual void handleVBR64(unsigned Size ) {
 | 
					  virtual void handleVBR64(unsigned Size ) {
 | 
				
			||||||
    bca.vbrCount64++;
 | 
					    bca.vbrCount64++;
 | 
				
			||||||
    bca.vbrCompBytes += Size;
 | 
					    bca.vbrCompBytes += Size;
 | 
				
			||||||
    bca.vbrExpdBytes += sizeof(uint64_t);
 | 
					    bca.vbrExpdBytes += sizeof(uint64_t);
 | 
				
			||||||
 | 
					    if ( currFunc ) {
 | 
				
			||||||
 | 
					      currFunc->vbrCount64++;
 | 
				
			||||||
 | 
					      currFunc->vbrCompBytes += Size;
 | 
				
			||||||
 | 
					      currFunc->vbrExpdBytes += sizeof(uint64_t);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -293,21 +293,27 @@ void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
 | 
				
			||||||
        double(bca.BlockSizes[BytecodeFormat::CompactionTable]),
 | 
					        double(bca.BlockSizes[BytecodeFormat::CompactionTable]),
 | 
				
			||||||
        double(bca.byteSize));
 | 
					        double(bca.byteSize));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::map<unsigned,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I = 
 | 
					    std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I = 
 | 
				
			||||||
      bca.FunctionInfo.begin();
 | 
					      bca.FunctionInfo.begin();
 | 
				
			||||||
    std::map<unsigned,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E = 
 | 
					    std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E = 
 | 
				
			||||||
      bca.FunctionInfo.end();
 | 
					      bca.FunctionInfo.end();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while ( I != E ) {
 | 
					    while ( I != E ) {
 | 
				
			||||||
      Out << std::left << std::setw(0);
 | 
					      Out << std::left << std::setw(0);
 | 
				
			||||||
      Out << "Function: " << I->second.name << " Slot=" << I->first << "\n";
 | 
					      Out << "Function: " << I->second.name << "\n";
 | 
				
			||||||
      print(Out,"Type:", I->second.description);
 | 
					      print(Out, "Type:", I->second.description);
 | 
				
			||||||
      print(Out,"Byte Size", I->second.byteSize);
 | 
					      print(Out, "Byte Size", I->second.byteSize);
 | 
				
			||||||
      print(Out,"Instructions", I->second.numInstructions);
 | 
					      print(Out, "Instructions", I->second.numInstructions);
 | 
				
			||||||
      print(Out,"Basic Blocks", I->second.numBasicBlocks);
 | 
					      print(Out, "Basic Blocks", I->second.numBasicBlocks);
 | 
				
			||||||
      print(Out,"Operand", I->second.numOperands);
 | 
					      print(Out, "Operand", I->second.numOperands);
 | 
				
			||||||
      print(Out,"Function Density", I->second.density);
 | 
					      print(Out, "Function Density", I->second.density);
 | 
				
			||||||
      print(Out,"VBR Effectiveness", I->second.vbrEffectiveness);
 | 
					      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;
 | 
					      ++I;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue