remove extraneous top-level semi's
[oota-llvm.git] / include / llvm / Bytecode / Analyzer.h
1 //===-- llvm/Bytecode/Analyzer.h - Analyzer for Bytecode files --*- C++ -*-===//
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 //
10 // This functionality is implemented by the lib/Bytecode/Reader library.
11 // It is used to read VM bytecode files from a file or memory buffer
12 // and print out a diagnostic analysis of the contents of the file. It is
13 // intended for three uses: (a) understanding the bytecode format, (b) ensuring
14 // correctness of bytecode format, (c) statistical analysis of generated
15 // bytecode files.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_BYTECODE_ANALYZER_H
20 #define LLVM_BYTECODE_ANALYZER_H
21
22 #include "llvm/Bytecode/Format.h"
23 #include "llvm/Bytecode/Reader.h"
24 #include <string>
25 #include <map>
26 #include <iosfwd>
27
28 namespace llvm {
29
30 // Forward declarations
31 class Function;
32 class Module;
33
34 /// This structure is used to contain the output of the Bytecode Analysis
35 /// library. It simply contains fields to hold each item of the analysis
36 /// results.
37 /// @brief Bytecode Analysis results structure
38 struct BytecodeAnalysis {
39   std::string ModuleId;     ///< Identification of the module
40   unsigned version;         ///< The version number of the bytecode file
41   unsigned byteSize;        ///< The size of the bytecode file in bytes
42   unsigned numTypes;        ///< The number of types
43   unsigned numValues;       ///< The number of values
44   unsigned numBlocks;       ///< The number of *bytecode* blocks
45   unsigned numFunctions;    ///< The number of functions defined
46   unsigned numConstants;    ///< The number of constants
47   unsigned numGlobalVars;   ///< The number of global variables
48   unsigned numInstructions; ///< The number of instructions in all functions
49   unsigned numBasicBlocks;  ///< The number of BBs in all functions
50   unsigned numOperands;     ///< The number of BBs in all functions
51   unsigned numCmpctnTables; ///< The number of compaction tables
52   unsigned numSymTab;       ///< The number of symbol tables
53   unsigned numAlignment;    ///< The number of alignment bytes
54   unsigned numLibraries;    ///< The number of dependent libraries
55   unsigned libSize;         ///< Number of bytes taken by dep libs.
56   unsigned maxTypeSlot;     ///< The maximum slot number for types
57   unsigned maxValueSlot;    ///< The maximum slot number for values
58   double   fileDensity;     ///< Density of file (bytes/definition)
59     ///< This is the density of the bytecode file. It is the ratio of
60     ///< the number of bytes to the number of definitions in the file. Smaller
61     ///< numbers mean the file is more compact (denser). Larger numbers mean
62     ///< the file is more sparse.
63   double   globalsDensity;  ///< density of global defs (bytes/definition)
64   double   functionDensity; ///< Average density of functions (bytes/function)
65   unsigned instructionSize; ///< Size of instructions in bytes
66   unsigned longInstructions;///< Number of instructions > 4 bytes
67
68   typedef std::map<BytecodeFormat::BytecodeBlockIdentifiers,unsigned>
69       BlockSizeMap;
70   BlockSizeMap BlockSizes;
71
72   /// A structure that contains various pieces of information related to
73   /// an analysis of a single function.
74   struct BytecodeFunctionInfo {
75     std::string description;  ///< Function type description
76     std::string name;         ///< Name of function if it has one
77     unsigned byteSize;        ///< The size of the function in bytecode bytes
78     unsigned numInstructions; ///< The number of instructions in the function
79     unsigned numBasicBlocks;  ///< The number of basic blocks in the function
80     unsigned numPhis;         ///< Number of Phi Nodes in Instructions
81     unsigned numOperands;     ///< The number of operands in the function
82     double   density;         ///< Density of function
83     unsigned instructionSize; ///< Size of instructions in bytes
84     unsigned longInstructions;///< Number of instructions > 4 bytes
85   };
86
87   /// A mapping of function slot numbers to the collected information about
88   /// the function.
89   std::map<const Function*,BytecodeFunctionInfo> FunctionInfo;
90
91   /// The content of the progressive verification
92   std::string VerifyInfo;
93
94   /// Flags for what should be done
95   bool detailedResults;       ///< If true, FunctionInfo has contents
96   bool progressiveVerify;     ///< If true, VerifyInfo has contents
97 };
98
99 /// This function is the main entry point into the bytecode analysis library. It
100 /// allows you to simply provide a \p filename and storage for the \p Results
101 /// that will be filled in with the analysis results.
102 /// @brief Analyze contents of a bytecode File
103 Module* AnalyzeBytecodeFile(
104       const std::string& Filename, ///< The name of the bytecode file to read
105       BytecodeAnalysis& Results,   ///< The results of the analysis
106       BCDecompressor_t *BCDC = 0,     ///< Optional decompressor to use.
107       std::string* ErrorStr = 0,   ///< Errors, if any.
108       std::ostream* output = 0     ///< Stream for dump output, if wanted
109     );
110
111
112 /// This function prints the contents of rhe BytecodeAnalysis structure in
113 /// a human legible form.
114 /// @brief Print BytecodeAnalysis structure to an ostream
115 void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out );
116
117 /// @brief std::ostream inserter for BytecodeAnalysis structure
118 inline std::ostream& operator<<(std::ostream& Out, BytecodeAnalysis& bca ) {
119     PrintBytecodeAnalysis(bca,Out);
120     return Out;
121 }
122
123 } // End llvm namespace
124
125 #endif