LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ProfileInfo.h

Go to the documentation of this file.
00001 //===- llvm/Analysis/ProfileInfo.h - Profile Info Interface -----*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the generic ProfileInfo interface, which is used as the
00011 // common interface used by all clients of profiling information, and
00012 // implemented either by making static guestimations, or by actually reading in
00013 // profiling information gathered by running the program.
00014 //
00015 // Note that to be useful, all profile-based optimizations should preserve
00016 // ProfileInfo, which requires that they notify it when changes to the CFG are
00017 // made.
00018 //
00019 //===----------------------------------------------------------------------===//
00020 
00021 #ifndef LLVM_ANALYSIS_PROFILEINFO_H
00022 #define LLVM_ANALYSIS_PROFILEINFO_H
00023 
00024 #include <string>
00025 #include <map>
00026 
00027 namespace llvm {
00028   class BasicBlock;
00029   class Pass;
00030 
00031   /// ProfileInfo Class - This class holds and maintains edge profiling
00032   /// information for some unit of code.
00033   class ProfileInfo {
00034   protected:
00035     // EdgeCounts - Count the number of times a transition between two blocks is
00036     // executed.  As a special case, we also hold an edge from the null
00037     // BasicBlock to the entry block to indicate how many times the function was
00038     // entered.
00039     std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned> EdgeCounts;
00040   public:
00041     virtual ~ProfileInfo();  // We want to be subclassed
00042     
00043     //===------------------------------------------------------------------===//
00044     /// Profile Information Queries
00045     ///
00046     unsigned getExecutionCount(BasicBlock *BB) const;
00047 
00048     unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dest) const {
00049       std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned>::const_iterator I=
00050         EdgeCounts.find(std::make_pair(Src, Dest));
00051       return I != EdgeCounts.end() ? I->second : 0;
00052     }
00053 
00054     //===------------------------------------------------------------------===//
00055     /// Analysis Update Methods
00056     ///
00057 
00058   };
00059 
00060   /// createProfileLoaderPass - This function returns a Pass that loads the
00061   /// profiling information for the module from the specified filename, making
00062   /// it available to the optimizers.
00063   Pass *createProfileLoaderPass(const std::string &Filename);
00064 } // End llvm namespace
00065 
00066 #endif