2004-06-08 07:55:53 +02:00
|
|
|
//===-- llvm/Bytecode/Analyzer.h - Analyzer for Bytecode files --*- C++ -*-===//
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2004-06-07 19:53:43 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-04-21 22:39:54 +02:00
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
2004-06-07 19:53:43 +02:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2004-06-07 19:53:43 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2004-06-30 01:17:34 +02:00
|
|
|
// This functionality is implemented by the lib/Bytecode/Reader library.
|
|
|
|
// It is used to read VM bytecode files from a file or memory buffer
|
2005-04-21 22:39:54 +02:00
|
|
|
// and print out a diagnostic analysis of the contents of the file. It is
|
|
|
|
// intended for three uses: (a) understanding the bytecode format, (b) ensuring
|
|
|
|
// correctness of bytecode format, (c) statistical analysis of generated
|
2004-06-08 07:55:53 +02:00
|
|
|
// bytecode files.
|
2004-06-07 19:53:43 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_BYTECODE_ANALYZER_H
|
|
|
|
#define LLVM_BYTECODE_ANALYZER_H
|
|
|
|
|
2004-06-10 10:09:13 +02:00
|
|
|
#include "llvm/Bytecode/Format.h"
|
2004-06-07 19:53:43 +02:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2005-01-16 02:22:18 +01:00
|
|
|
#include <iostream>
|
2004-06-07 19:53:43 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2004-06-30 01:17:34 +02:00
|
|
|
// Forward declarations
|
2004-06-11 00:28:11 +02:00
|
|
|
class Function;
|
2004-06-30 01:17:34 +02:00
|
|
|
class Module;
|
2004-06-11 00:28:11 +02:00
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// This structure is used to contain the output of the Bytecode Analysis
|
|
|
|
/// library. It simply contains fields to hold each item of the analysis
|
2004-06-07 19:53:43 +02:00
|
|
|
/// results.
|
|
|
|
/// @brief Bytecode Analysis results structure
|
|
|
|
struct BytecodeAnalysis {
|
2004-06-09 08:18:53 +02:00
|
|
|
std::string ModuleId; ///< Identification of the module
|
2004-08-21 22:40:08 +02:00
|
|
|
unsigned version; ///< The version number of the bytecode file
|
2004-06-09 08:18:53 +02:00
|
|
|
unsigned byteSize; ///< The size of the bytecode file in bytes
|
2004-06-07 19:53:43 +02:00
|
|
|
unsigned numTypes; ///< The number of types
|
|
|
|
unsigned numValues; ///< The number of values
|
2004-06-10 10:09:13 +02:00
|
|
|
unsigned numBlocks; ///< The number of *bytecode* blocks
|
2004-06-07 19:53:43 +02:00
|
|
|
unsigned numFunctions; ///< The number of functions defined
|
|
|
|
unsigned numConstants; ///< The number of constants
|
|
|
|
unsigned numGlobalVars; ///< The number of global variables
|
|
|
|
unsigned numInstructions; ///< The number of instructions in all functions
|
|
|
|
unsigned numBasicBlocks; ///< The number of BBs in all functions
|
|
|
|
unsigned numOperands; ///< The number of BBs in all functions
|
2004-06-09 08:18:53 +02:00
|
|
|
unsigned numCmpctnTables; ///< The number of compaction tables
|
|
|
|
unsigned numSymTab; ///< The number of symbol tables
|
2004-06-10 10:09:13 +02:00
|
|
|
unsigned numAlignment; ///< The number of alignment bytes
|
2004-08-21 22:40:08 +02:00
|
|
|
unsigned numLibraries; ///< The number of dependent libraries
|
|
|
|
unsigned libSize; ///< Number of bytes taken by dep libs.
|
2004-06-07 19:53:43 +02:00
|
|
|
unsigned maxTypeSlot; ///< The maximum slot number for types
|
|
|
|
unsigned maxValueSlot; ///< The maximum slot number for values
|
2004-06-10 10:09:13 +02:00
|
|
|
double fileDensity; ///< Density of file (bytes/definition)
|
|
|
|
///< This is the density of the bytecode file. It is the ratio of
|
|
|
|
///< the number of bytes to the number of definitions in the file. Smaller
|
|
|
|
///< numbers mean the file is more compact (denser). Larger numbers mean
|
|
|
|
///< the file is more sparse.
|
|
|
|
double globalsDensity; ///< density of global defs (bytes/definition)
|
|
|
|
double functionDensity; ///< Average density of functions (bytes/function)
|
2004-06-11 17:10:38 +02:00
|
|
|
unsigned instructionSize; ///< Size of instructions in bytes
|
|
|
|
unsigned longInstructions;///< Number of instructions > 4 bytes
|
2004-06-10 10:09:13 +02:00
|
|
|
unsigned vbrCount32; ///< Number of 32-bit vbr values
|
|
|
|
unsigned vbrCount64; ///< Number of 64-bit vbr values
|
|
|
|
unsigned vbrCompBytes; ///< Number of vbr bytes (compressed)
|
|
|
|
unsigned vbrExpdBytes; ///< Number of vbr bytes (expanded)
|
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
typedef std::map<BytecodeFormat::CompressedBytecodeBlockIdentifiers,unsigned>
|
2004-08-21 22:40:08 +02:00
|
|
|
BlockSizeMap;
|
2004-06-10 10:09:13 +02:00
|
|
|
BlockSizeMap BlockSizes;
|
2004-06-07 19:53:43 +02:00
|
|
|
|
|
|
|
/// A structure that contains various pieces of information related to
|
|
|
|
/// an analysis of a single function.
|
|
|
|
struct BytecodeFunctionInfo {
|
2004-06-10 10:09:13 +02:00
|
|
|
std::string description; ///< Function type description
|
2004-06-11 17:10:38 +02:00
|
|
|
std::string name; ///< Name of function if it has one
|
2004-06-07 19:53:43 +02:00
|
|
|
unsigned byteSize; ///< The size of the function in bytecode bytes
|
|
|
|
unsigned numInstructions; ///< The number of instructions in the function
|
|
|
|
unsigned numBasicBlocks; ///< The number of basic blocks in the function
|
2004-06-11 00:28:11 +02:00
|
|
|
unsigned numPhis; ///< Number of Phi Nodes in Instructions
|
2004-06-07 19:53:43 +02:00
|
|
|
unsigned numOperands; ///< The number of operands in the function
|
2004-06-11 00:28:11 +02:00
|
|
|
double density; ///< Density of function
|
2004-06-11 17:10:38 +02:00
|
|
|
unsigned instructionSize; ///< Size of instructions in bytes
|
|
|
|
unsigned longInstructions;///< Number of instructions > 4 bytes
|
2004-06-11 00:28:11 +02:00
|
|
|
unsigned vbrCount32; ///< Number of 32-bit vbr values
|
|
|
|
unsigned vbrCount64; ///< Number of 64-bit vbr values
|
|
|
|
unsigned vbrCompBytes; ///< Number of vbr bytes (compressed)
|
|
|
|
unsigned vbrExpdBytes; ///< Number of vbr bytes (expanded)
|
2004-06-07 19:53:43 +02:00
|
|
|
};
|
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// A mapping of function slot numbers to the collected information about
|
2004-06-10 10:09:13 +02:00
|
|
|
/// the function.
|
2005-04-21 22:39:54 +02:00
|
|
|
std::map<const Function*,BytecodeFunctionInfo> FunctionInfo;
|
2004-06-07 19:53:43 +02:00
|
|
|
|
2004-06-30 01:17:34 +02:00
|
|
|
/// The content of the progressive verification
|
|
|
|
std::string VerifyInfo;
|
|
|
|
|
2004-06-07 19:53:43 +02:00
|
|
|
/// Flags for what should be done
|
2005-04-21 22:39:54 +02:00
|
|
|
bool detailedResults; ///< If true, FunctionInfo has contents
|
2004-06-30 01:17:34 +02:00
|
|
|
bool progressiveVerify; ///< If true, VerifyInfo has contents
|
2004-06-07 19:53:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This function is the main entry point into the bytecode analysis library. It
|
2005-04-21 22:39:54 +02:00
|
|
|
/// allows you to simply provide a \p filename and storage for the \p Results
|
2004-06-07 19:53:43 +02:00
|
|
|
/// that will be filled in with the analysis results.
|
|
|
|
/// @brief Analyze contents of a bytecode File
|
2004-06-30 01:17:34 +02:00
|
|
|
Module* AnalyzeBytecodeFile(
|
2004-06-07 19:53:43 +02:00
|
|
|
const std::string& Filename, ///< The name of the bytecode file to read
|
|
|
|
BytecodeAnalysis& Results, ///< The results of the analysis
|
2004-08-21 22:40:08 +02:00
|
|
|
std::string* ErrorStr = 0, ///< Errors, if any.
|
|
|
|
std::ostream* output = 0 ///< Stream for dump output, if wanted
|
2004-06-07 19:53:43 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/// This function is an alternate entry point into the bytecode analysis
|
|
|
|
/// library. It allows you to provide an arbitrary memory buffer which is
|
2004-06-08 15:49:17 +02:00
|
|
|
/// assumed to contain a complete bytecode file. The \p Buffer is analyzed and
|
|
|
|
/// the \p Results are filled in.
|
2004-06-07 19:53:43 +02:00
|
|
|
/// @brief Analyze contents of a bytecode buffer.
|
2004-06-30 01:17:34 +02:00
|
|
|
Module* AnalyzeBytecodeBuffer(
|
2004-06-07 19:53:43 +02:00
|
|
|
const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
|
|
|
|
unsigned BufferSize, ///< Size of the bytecode buffer
|
2004-06-30 01:17:34 +02:00
|
|
|
const std::string& ModuleID, ///< Identifier for the module
|
2004-06-07 19:53:43 +02:00
|
|
|
BytecodeAnalysis& Results, ///< The results of the analysis
|
2004-08-21 22:40:08 +02:00
|
|
|
std::string* ErrorStr = 0, ///< Errors, if any.
|
|
|
|
std::ostream* output = 0 ///< Stream for dump output, if wanted
|
2004-06-07 19:53:43 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/// This function prints the contents of rhe BytecodeAnalysis structure in
|
|
|
|
/// a human legible form.
|
|
|
|
/// @brief Print BytecodeAnalysis structure to an ostream
|
|
|
|
void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out );
|
|
|
|
|
2004-06-08 07:55:53 +02:00
|
|
|
/// @brief std::ostream inserter for BytecodeAnalysis structure
|
|
|
|
inline std::ostream& operator<<(std::ostream& Out, BytecodeAnalysis& bca ) {
|
|
|
|
PrintBytecodeAnalysis(bca,Out);
|
|
|
|
return Out;
|
|
|
|
}
|
|
|
|
|
2004-06-07 19:53:43 +02:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|