[llvm-commits] [parallel] CVS: llvm/include/llvm/Analysis/Trace.h DSGraph.h ProfileInfo.h ProfileInfoLoader.h

Misha Brukman brukman at cs.uiuc.edu
Wed Mar 10 19:23:00 PST 2004


Changes in directory llvm/include/llvm/Analysis:

Trace.h added (r1.2.2.1)
DSGraph.h updated: 1.64.4.1 -> 1.64.4.2
ProfileInfo.h updated: 1.2.2.1 -> 1.2.2.2
ProfileInfoLoader.h updated: 1.1.2.1 -> 1.1.2.2

---
Log message:

Merge from trunk.

---
Diffs of the changes:  (+172 -26)

Index: llvm/include/llvm/Analysis/Trace.h
diff -c /dev/null llvm/include/llvm/Analysis/Trace.h:1.2.2.1
*** /dev/null	Wed Mar 10 19:22:15 2004
--- llvm/include/llvm/Analysis/Trace.h	Wed Mar 10 19:22:05 2004
***************
*** 0 ****
--- 1,116 ----
+ //===- llvm/Analysis/Trace.h - Represent one trace of LLVM code -*- C++ -*-===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This class represents a single trace of LLVM basic blocks.  A trace is a
+ // single entry, multiple exit, region of code that is often hot.  Trace-based
+ // optimizations treat traces almost like they are a large, strange, basic
+ // block: because the trace path is assumed to be hot, optimizations for the
+ // fall-through path are made at the expense of the non-fall-through paths.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #ifndef LLVM_ANALYSIS_TRACE_H
+ #define LLVM_ANALYSIS_TRACE_H
+ 
+ #include <iosfwd>
+ #include <vector>
+ #include <cassert>
+ 
+ namespace llvm { 
+   class BasicBlock;
+   class Function;
+   class Module;
+ 
+ class Trace {
+   typedef std::vector<BasicBlock *> BasicBlockListType;
+   BasicBlockListType BasicBlocks;
+ 
+ public:
+   /// Trace ctor - Make a new trace from a vector of basic blocks,
+   /// residing in the function which is the parent of the first
+   /// basic block in the vector.
+   ///
+   Trace(const std::vector<BasicBlock *> &vBB) : BasicBlocks (vBB) {}
+ 
+   /// getEntryBasicBlock - Return the entry basic block (first block)
+   /// of the trace.
+   ///
+   BasicBlock *getEntryBasicBlock () const { return BasicBlocks[0]; }
+ 
+   /// operator[]/getBlock - Return basic block N in the trace.
+   ///
+   BasicBlock *operator[](unsigned i) const { return BasicBlocks[i]; }
+   BasicBlock *getBlock(unsigned i)   const { return BasicBlocks[i]; }
+ 
+   /// getFunction - Return this trace's parent function.
+   ///
+   Function *getFunction () const;
+ 
+   /// getModule - Return this Module that contains this trace's parent
+   /// function.
+   ///
+   Module *getModule () const;
+ 
+   /// getBlockIndex - Return the index of the specified basic block in the
+   /// trace, or -1 if it is not in the trace.
+   int getBlockIndex(const BasicBlock *X) const {
+     for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
+       if (BasicBlocks[i] == X)
+         return i;
+     return -1;
+   }
+ 
+   /// contains - Returns true if this trace contains the given basic
+   /// block.
+   ///
+   bool contains(const BasicBlock *X) const {
+     return getBlockIndex(X) != -1;
+   }
+ 
+   /// Returns true if B1 occurs before B2 in the trace, or if it is the same
+   /// block as B2..  Both blocks must be in the trace.
+   ///
+   bool dominates(const BasicBlock *B1, const BasicBlock *B2) const {
+     int B1Idx = getBlockIndex(B1), B2Idx = getBlockIndex(B2);
+     assert(B1Idx != -1 && B2Idx != -1 && "Block is not in the trace!");
+     return B1Idx <= B2Idx;
+   }
+ 
+   // BasicBlock iterators...
+   typedef BasicBlockListType::iterator iterator;
+   typedef BasicBlockListType::const_iterator const_iterator;
+   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+   typedef std::reverse_iterator<iterator> reverse_iterator;
+ 
+   iterator                begin()       { return BasicBlocks.begin(); }
+   const_iterator          begin() const { return BasicBlocks.begin(); }
+   iterator                end  ()       { return BasicBlocks.end();   }
+   const_iterator          end  () const { return BasicBlocks.end();   }
+ 
+   reverse_iterator       rbegin()       { return BasicBlocks.rbegin(); }
+   const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
+   reverse_iterator       rend  ()       { return BasicBlocks.rend();   }
+   const_reverse_iterator rend  () const { return BasicBlocks.rend();   }
+ 
+   unsigned                 size() const { return BasicBlocks.size(); }
+   bool                    empty() const { return BasicBlocks.empty(); }
+ 
+   /// print - Write trace to output stream.
+   ///
+   void print (std::ostream &O) const;
+ 
+   /// dump - Debugger convenience method; writes trace to standard error
+   /// output stream.
+   ///
+   void dump () const;
+ };
+ 
+ } // end namespace llvm
+ 
+ #endif // TRACE_H


Index: llvm/include/llvm/Analysis/DSGraph.h
diff -u llvm/include/llvm/Analysis/DSGraph.h:1.64.4.1 llvm/include/llvm/Analysis/DSGraph.h:1.64.4.2
--- llvm/include/llvm/Analysis/DSGraph.h:1.64.4.1	Mon Mar  1 17:57:19 2004
+++ llvm/include/llvm/Analysis/DSGraph.h	Wed Mar 10 19:22:05 2004
@@ -360,6 +360,10 @@
   ///
   DSCallSite getCallSiteForArguments(Function &F) const;
 
+  /// getDSCallSiteForCallSite - Given an LLVM CallSite object that is live in
+  /// the context of this graph, return the DSCallSite for it.
+  DSCallSite getDSCallSiteForCallSite(CallSite CS) const;
+
   // Methods for checking to make sure graphs are well formed...
   void AssertNodeInGraph(const DSNode *N) const {
     assert((!N || N->getParentGraph() == this) &&
@@ -370,22 +374,9 @@
            N->getGlobals().end() && "Global value not in node!");
   }
 
-  void AssertCallSiteInGraph(const DSCallSite &CS) const {
-    if (CS.isIndirectCall())
-      AssertNodeInGraph(CS.getCalleeNode());
-    AssertNodeInGraph(CS.getRetVal().getNode());
-    for (unsigned j = 0, e = CS.getNumPtrArgs(); j != e; ++j)
-      AssertNodeInGraph(CS.getPtrArg(j).getNode());
-  }
-
-  void AssertCallNodesInGraph() const {
-    for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i)
-      AssertCallSiteInGraph(FunctionCalls[i]);
-  }
-  void AssertAuxCallNodesInGraph() const {
-    for (unsigned i = 0, e = AuxFunctionCalls.size(); i != e; ++i)
-      AssertCallSiteInGraph(AuxFunctionCalls[i]);
-  }
+  void AssertCallSiteInGraph(const DSCallSite &CS) const;
+  void AssertCallNodesInGraph() const;
+  void AssertAuxCallNodesInGraph() const;
 
   void AssertGraphOK() const;
 
@@ -436,7 +427,13 @@
     /// site into the nodes reachable from DestCS.
     void mergeCallSite(const DSCallSite &DestCS, const DSCallSite &SrcCS);
 
-    bool clonedNode() const { return !NodeMap.empty(); }
+    bool clonedAnyNodes() const { return !NodeMap.empty(); }
+
+    /// hasClonedNode - Return true if the specified node has been cloned from
+    /// the source graph into the destination graph.
+    bool hasClonedNode(const DSNode *N) {
+      return NodeMap.count(N);
+    }
 
     void destroy() { NodeMap.clear(); }
   };


Index: llvm/include/llvm/Analysis/ProfileInfo.h
diff -u llvm/include/llvm/Analysis/ProfileInfo.h:1.2.2.1 llvm/include/llvm/Analysis/ProfileInfo.h:1.2.2.2
--- llvm/include/llvm/Analysis/ProfileInfo.h:1.2.2.1	Mon Mar  1 17:57:19 2004
+++ llvm/include/llvm/Analysis/ProfileInfo.h	Wed Mar 10 19:22:05 2004
@@ -22,30 +22,45 @@
 #define LLVM_ANALYSIS_PROFILEINFO_H
 
 #include <string>
+#include <map>
 
 namespace llvm {
   class BasicBlock;
   class Pass;
 
-  /// createProfileLoaderPass - This function returns a Pass that loads the
-  /// profiling information for the module from the specified filename, making
-  /// it available to the optimizers.
-  Pass *createProfileLoaderPass(const std::string &Filename);
-
-  struct ProfileInfo {
+  /// ProfileInfo Class - This class holds and maintains edge profiling
+  /// information for some unit of code.
+  class ProfileInfo {
+  protected:
+    // EdgeCounts - Count the number of times a transition between two blocks is
+    // executed.  As a special case, we also hold an edge from the null
+    // BasicBlock to the entry block to indicate how many times the function was
+    // entered.
+    std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned> EdgeCounts;
+  public:
     virtual ~ProfileInfo();  // We want to be subclassed
     
     //===------------------------------------------------------------------===//
     /// Profile Information Queries
     ///
-    virtual unsigned getExecutionCount(BasicBlock *BB) = 0;
-    
+    unsigned getExecutionCount(BasicBlock *BB) const;
+
+    unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dest) const {
+      std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned>::const_iterator I=
+        EdgeCounts.find(std::make_pair(Src, Dest));
+      return I != EdgeCounts.end() ? I->second : 0;
+    }
+
     //===------------------------------------------------------------------===//
     /// Analysis Update Methods
     ///
 
   };
 
+  /// createProfileLoaderPass - This function returns a Pass that loads the
+  /// profiling information for the module from the specified filename, making
+  /// it available to the optimizers.
+  Pass *createProfileLoaderPass(const std::string &Filename);
 } // End llvm namespace
 
 #endif


Index: llvm/include/llvm/Analysis/ProfileInfoLoader.h
diff -u llvm/include/llvm/Analysis/ProfileInfoLoader.h:1.1.2.1 llvm/include/llvm/Analysis/ProfileInfoLoader.h:1.1.2.2
--- llvm/include/llvm/Analysis/ProfileInfoLoader.h:1.1.2.1	Mon Mar  1 17:57:19 2004
+++ llvm/include/llvm/Analysis/ProfileInfoLoader.h	Wed Mar 10 19:22:05 2004
@@ -31,6 +31,7 @@
   std::vector<std::string> CommandLines;
   std::vector<unsigned>    FunctionCounts;
   std::vector<unsigned>    BlockCounts;
+  std::vector<unsigned>    EdgeCounts;
 public:
   // ProfileInfoLoader ctor - Read the specified profiling data file, exiting
   // the program if the file is invalid or broken.
@@ -50,7 +51,14 @@
   // frequency information from whatever we have.
   //
   bool hasAccurateBlockCounts() const {
-    return !BlockCounts.empty();
+    return !BlockCounts.empty() || !EdgeCounts.empty();
+  }
+
+  // hasAccurateEdgeCounts - Return true if we can synthesize accurate edge
+  // frequency information from whatever we have.
+  //
+  bool hasAccurateEdgeCounts() const {
+    return !EdgeCounts.empty();
   }
 
   // getBlockCounts - This method is used by consumers of block counting
@@ -58,6 +66,16 @@
   // compute it from other, more refined, types of profile information.
   //
   void getBlockCounts(std::vector<std::pair<BasicBlock*, unsigned> > &Counts);
+
+  // getEdgeCounts - This method is used by consumers of edge counting
+  // information.  If we do not directly have edge count information, we compute
+  // it from other, more refined, types of profile information.
+  //
+  // Edges are represented as a pair, where the first element is the basic block
+  // and the second element is the successor number.
+  //
+  typedef std::pair<BasicBlock*, unsigned> Edge;
+  void getEdgeCounts(std::vector<std::pair<Edge, unsigned> > &Counts);
 };
 
 } // End llvm namespace





More information about the llvm-commits mailing list