[llvm-commits] CVS: llvm/include/llvm/Bytecode/Analyzer.h

LLVM llvm at cs.uiuc.edu
Mon Jun 7 12:59:08 PDT 2004


Changes in directory llvm/include/llvm/Bytecode:

Analyzer.h added (r1.1)

---
Log message:

Commit For New Tool: llvm-abcd (Analysis of ByteCode Dumper).  This tool 
will (eventually) provide statistical analysis of bytecode files as well 
as the ability to dump them in a low level format (slot numbers not 
resolved). The purpose of this is to aid in the Type!=Value change of 
bug 122: http://llvm.cs.uiuc.edu/PR122 . With this initial release, llvm-abcd merely dumps out the 
bytecode. However, the infrastructure for separating bytecode parsing from 
handling the parsing events is in place. The style chosen is similar to
SAX XML parsing where a handler object is called to handlign the parsing
events. This probably isn't useful to anyone but me right now as there is 
no analysis yet, and the dumper doesn't work on every bytecode file. It 
will probably be useful by the end of this week. Note that there is some 
duplication of code from the bytecode reader.  This was done to eliminate 
errors from being introduced in the reader and to minimize the impact to 
other LLVM developers. At some point, the Analyzer and the Reader will be
integrated to use the same infrastructure. Also, sorry for the minor change 
to Instruction.h but I just couldn't bring myself to write code that 
depends on Instruction internals.


---
Diffs of the changes:  (+97 -0)

Index: llvm/include/llvm/Bytecode/Analyzer.h
diff -c /dev/null llvm/include/llvm/Bytecode/Analyzer.h:1.1
*** /dev/null	Mon Jun  7 12:53:53 2004
--- llvm/include/llvm/Bytecode/Analyzer.h	Mon Jun  7 12:53:43 2004
***************
*** 0 ****
--- 1,97 ----
+ //===-- llvm/Bytecode/Analyzer.h - Analyzer for bytecode files --*- C++ -*-===//
+ // 
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Reid Spencer and is distributed under the 
+ // University of Illinois Open Source License. See LICENSE.TXT for details.
+ // 
+ //===----------------------------------------------------------------------===//
+ //
+ // This functionality is implemented by the lib/Bytecode/Analysis library.
+ // This library is used to read VM bytecode files from an iostream 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 bytecode files.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #ifndef LLVM_BYTECODE_ANALYZER_H
+ #define LLVM_BYTECODE_ANALYZER_H
+ 
+ #include <string>
+ #include <map>
+ 
+ namespace llvm {
+ 
+ /// This structure is used to contain the output of the Bytecode Analysis 
+ /// library. It simply contains fields to hold each item of the analysis 
+ /// results.
+ /// @brief Bytecode Analysis results structure
+ struct BytecodeAnalysis {
+   unsigned byteSize;            ///< The size of the bytecode file in bytes
+   unsigned numTypes;        ///< The number of types
+   unsigned numValues;       ///< The number of values
+   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
+   unsigned maxTypeSlot;     ///< The maximum slot number for types
+   unsigned maxValueSlot;    ///< The maximum slot number for values
+   double   density;         ///< Density of file (bytes/defs) 
+ 
+   /// A structure that contains various pieces of information related to
+   /// an analysis of a single function.
+   struct BytecodeFunctionInfo {
+     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
+     unsigned numOperands;     ///< The number of operands in the function
+     double density;           ///< Density of function
+     double vbrEffectiveness;  ///< Effectiveness of variable bit rate encoding.
+     ///< This is the average number of bytes per unsigned value written in the
+     ///< vbr encoding. A "perfect" score of 1.0 means all vbr values were 
+     ///< encoded in one byte. A score between 1.0 and 4.0 means that some
+     ///< savings were achieved. A score of 4.0 means vbr didn't help. A score
+     ///< greater than 4.0 means vbr negatively impacted size of the file.
+   };
+ 
+   /// A mapping of function names to the collected information about the 
+   /// function.
+   std::map<std::string,BytecodeFunctionInfo> FunctionInfo; 
+ 
+   /// Flags for what should be done
+   bool dumpBytecode;
+ };
+ 
+ /// This function is the main entry point into the bytecode analysis library. It
+ /// allows you to simply provide a \P filename and storage for the \P Results 
+ /// that will be filled in with the analysis results.
+ /// @brief Analyze contents of a bytecode File
+ void AnalyzeBytecodeFile(
+       const std::string& Filename, ///< The name of the bytecode file to read
+       BytecodeAnalysis& Results,   ///< The results of the analysis
+       std::string* ErrorStr = 0    ///< Errors, if any.
+     );
+ 
+ /// This function is an alternate entry point into the bytecode analysis
+ /// library. It allows you to provide an arbitrary memory buffer which is
+ /// assumed to contain a complete bytecode file. The \P Buffer is analyzed and
+ /// the \P Results are filled in.
+ /// @brief Analyze contents of a bytecode buffer.
+ void AnalyzeBytecodeBuffer(
+        const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
+        unsigned BufferSize,         ///< Size of the bytecode buffer
+        BytecodeAnalysis& Results,   ///< The results of the analysis
+        std::string* ErrorStr = 0    ///< Errors, if any.
+      );
+ 
+ /// 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 );
+ 
+ } // End llvm namespace
+ 
+ #endif





More information about the llvm-commits mailing list