<div dir="ltr">FYI, I've restored LLVM_BUILD_RUNTIME CMake option in r191948 - otherwise this change silently discarded building compiler-rt and libcxx :)<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Oct 2, 2013 at 7:57 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
61 files changed, 12 insertions(+), 8640 deletions(-)<br>
<br>
Nice!<br>
<br>
On 2 October 2013 11:42, Chandler Carruth <<a href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>> wrote:<br>
> Author: chandlerc<br>
> Date: Wed Oct 2 10:42:23 2013<br>
> New Revision: 191835<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=191835&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=191835&view=rev</a><br>
> Log:<br>
> Remove the very substantial, largely unmaintained legacy PGO<br>
> infrastructure.<br>
><br>
> This was essentially work toward PGO based on a design that had several<br>
> flaws, partially dating from a time when LLVM had a different<br>
> architecture, and with an effort to modernize it abandoned without being<br>
> completed. Since then, it has bitrotted for several years further. The<br>
> result is nearly unusable, and isn't helping any of the modern PGO<br>
> efforts. Instead, it is getting in the way, adding confusion about PGO<br>
> in LLVM and distracting everyone with maintenance on essentially dead<br>
> code. Removing it paves the way for modern efforts around PGO.<br>
><br>
> Among other effects, this removes the last of the runtime libraries from<br>
> LLVM. Those are being developed in the separate 'compiler-rt' project<br>
> now, with somewhat different licensing specifically more approriate for<br>
> runtimes.<br>
><br>
> Removed:<br>
> llvm/trunk/include/llvm/Analysis/PathNumbering.h<br>
> llvm/trunk/include/llvm/Analysis/PathProfileInfo.h<br>
> llvm/trunk/include/llvm/Analysis/ProfileDataLoader.h<br>
> llvm/trunk/include/llvm/Analysis/ProfileDataTypes.h<br>
> llvm/trunk/include/llvm/Analysis/ProfileInfo.h<br>
> llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h<br>
> llvm/trunk/include/llvm/Analysis/ProfileInfoTypes.h<br>
> llvm/trunk/lib/Analysis/PathNumbering.cpp<br>
> llvm/trunk/lib/Analysis/PathProfileInfo.cpp<br>
> llvm/trunk/lib/Analysis/PathProfileVerifier.cpp<br>
> llvm/trunk/lib/Analysis/ProfileDataLoader.cpp<br>
> llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp<br>
> llvm/trunk/lib/Analysis/ProfileEstimatorPass.cpp<br>
> llvm/trunk/lib/Analysis/ProfileInfo.cpp<br>
> llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp<br>
> llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp<br>
> llvm/trunk/lib/Analysis/ProfileVerifierPass.cpp<br>
> llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp<br>
> llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp<br>
> llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp<br>
> llvm/trunk/runtime/<br>
> llvm/trunk/test/Analysis/Profiling/<br>
> llvm/trunk/tools/llvm-prof/<br>
> Modified:<br>
> llvm/trunk/CMakeLists.txt<br>
> llvm/trunk/LLVMBuild.txt<br>
> llvm/trunk/Makefile<br>
> llvm/trunk/include/llvm/Analysis/Passes.h<br>
> llvm/trunk/include/llvm/InitializePasses.h<br>
> llvm/trunk/include/llvm/LinkAllPasses.h<br>
> llvm/trunk/include/llvm/Transforms/Instrumentation.h<br>
> llvm/trunk/lib/Analysis/Analysis.cpp<br>
> llvm/trunk/lib/Analysis/CMakeLists.txt<br>
> llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp<br>
> llvm/trunk/lib/Transforms/Instrumentation/CMakeLists.txt<br>
> llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp<br>
> llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp<br>
> llvm/trunk/lib/Transforms/Utils/BreakCriticalEdges.cpp<br>
> llvm/trunk/lib/Transforms/Utils/Local.cpp<br>
> llvm/trunk/test/lit.cfg<br>
> llvm/trunk/tools/CMakeLists.txt<br>
> llvm/trunk/tools/LLVMBuild.txt<br>
> llvm/trunk/tools/Makefile<br>
><br>
> Modified: llvm/trunk/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/CMakeLists.txt (original)<br>
> +++ llvm/trunk/CMakeLists.txt Wed Oct 2 10:42:23 2013<br>
> @@ -246,18 +246,13 @@ if( WIN32 AND NOT CYGWIN )<br>
> endif()<br>
><br>
> # Define options to control the inclusion and default build behavior for<br>
> -# components which may not strictly be necessary (tools, runtime, examples, and<br>
> -# tests).<br>
> +# components which may not strictly be necessary (tools, examples, and tests).<br>
> #<br>
> # This is primarily to support building smaller or faster project files.<br>
> option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)<br>
> option(LLVM_BUILD_TOOLS<br>
> "Build the LLVM tools. If OFF, just generate build targets." ON)<br>
><br>
> -option(LLVM_INCLUDE_RUNTIME "Generate build targets for the LLVM runtimes" ON)<br>
> -option(LLVM_BUILD_RUNTIME<br>
> - "Build the LLVM runtime libraries. If OFF, just generate build targets." ON)<br>
> -<br>
> option(LLVM_BUILD_EXAMPLES<br>
> "Build the LLVM example programs. If OFF, just generate build targets." OFF)<br>
> option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)<br>
> @@ -471,10 +466,6 @@ if( LLVM_INCLUDE_TOOLS )<br>
> add_subdirectory(tools)<br>
> endif()<br>
><br>
> -if( LLVM_INCLUDE_RUNTIME )<br>
> - add_subdirectory(runtime)<br>
> -endif()<br>
> -<br>
> if( LLVM_INCLUDE_EXAMPLES )<br>
> add_subdirectory(examples)<br>
> endif()<br>
><br>
> Modified: llvm/trunk/LLVMBuild.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/LLVMBuild.txt?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/LLVMBuild.txt?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/LLVMBuild.txt (original)<br>
> +++ llvm/trunk/LLVMBuild.txt Wed Oct 2 10:42:23 2013<br>
> @@ -16,7 +16,7 @@<br>
> ;===------------------------------------------------------------------------===;<br>
><br>
> [common]<br>
> -subdirectories = bindings docs examples lib projects runtime tools utils<br>
> +subdirectories = bindings docs examples lib projects tools utils<br>
><br>
> [component_0]<br>
> type = Group<br>
><br>
> Modified: llvm/trunk/Makefile<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/Makefile?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/Makefile?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/Makefile (original)<br>
> +++ llvm/trunk/Makefile Wed Oct 2 10:42:23 2013<br>
> @@ -15,7 +15,7 @@ LEVEL := .<br>
> # 3. Build IR, which builds the Intrinsics.inc file used by libs.<br>
> # 4. Build libs, which are needed by llvm-config.<br>
> # 5. Build llvm-config, which determines inter-lib dependencies for tools.<br>
> -# 6. Build tools, runtime, docs.<br>
> +# 6. Build tools and docs.<br>
> #<br>
> # When cross-compiling, there are some things (tablegen) that need to<br>
> # be build for the build system first.<br>
> @@ -31,7 +31,7 @@ ifeq ($(BUILD_DIRS_ONLY),1)<br>
> OPTIONAL_DIRS := tools/clang/utils/TableGen<br>
> else<br>
> DIRS := lib/Support lib/TableGen utils lib/IR lib tools/llvm-shlib \<br>
> - tools/llvm-config tools runtime docs unittests<br>
> + tools/llvm-config tools docs unittests<br>
> OPTIONAL_DIRS := projects bindings<br>
> endif<br>
><br>
> @@ -52,17 +52,17 @@ ifneq ($(ENABLE_DOCS),1)<br>
> endif<br>
><br>
> ifeq ($(MAKECMDGOALS),libs-only)<br>
> - DIRS := $(filter-out tools runtime docs, $(DIRS))<br>
> + DIRS := $(filter-out tools docs, $(DIRS))<br>
> OPTIONAL_DIRS :=<br>
> endif<br>
><br>
> ifeq ($(MAKECMDGOALS),install-libs)<br>
> - DIRS := $(filter-out tools runtime docs, $(DIRS))<br>
> + DIRS := $(filter-out tools docs, $(DIRS))<br>
> OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))<br>
> endif<br>
><br>
> ifeq ($(MAKECMDGOALS),tools-only)<br>
> - DIRS := $(filter-out runtime docs, $(DIRS))<br>
> + DIRS := $(filter-out docs, $(DIRS))<br>
> OPTIONAL_DIRS :=<br>
> endif<br>
><br>
> @@ -72,7 +72,7 @@ ifeq ($(MAKECMDGOALS),install-clang)<br>
> tools/clang/tools/c-index-test \<br>
> tools/clang/include/clang-c \<br>
> tools/clang/runtime tools/clang/docs \<br>
> - tools/lto runtime<br>
> + tools/lto<br>
> OPTIONAL_DIRS :=<br>
> NO_INSTALL = 1<br>
> endif<br>
> @@ -84,7 +84,7 @@ ifeq ($(MAKECMDGOALS),clang-only)<br>
> endif<br>
><br>
> ifeq ($(MAKECMDGOALS),unittests)<br>
> - DIRS := $(filter-out tools runtime docs, $(DIRS)) utils unittests<br>
> + DIRS := $(filter-out tools docs, $(DIRS)) utils unittests<br>
> OPTIONAL_DIRS :=<br>
> endif<br>
><br>
><br>
> Modified: llvm/trunk/include/llvm/Analysis/Passes.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Passes.h?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Passes.h?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/Passes.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/Passes.h Wed Oct 2 10:42:23 2013<br>
> @@ -95,64 +95,6 @@ namespace llvm {<br>
><br>
> //===--------------------------------------------------------------------===//<br>
> //<br>
> - // createProfileLoaderPass - This pass loads information from a profile dump<br>
> - // file.<br>
> - //<br>
> - ModulePass *createProfileLoaderPass();<br>
> - extern char &ProfileLoaderPassID;<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> - // createProfileMetadataLoaderPass - This pass loads information from a<br>
> - // profile dump file and sets branch weight metadata.<br>
> - //<br>
> - ModulePass *createProfileMetadataLoaderPass();<br>
> - extern char &ProfileMetadataLoaderPassID;<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> - // createNoProfileInfoPass - This pass implements the default "no profile".<br>
> - //<br>
> - ImmutablePass *createNoProfileInfoPass();<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> - // createProfileEstimatorPass - This pass estimates profiling information<br>
> - // instead of loading it from a previous run.<br>
> - //<br>
> - FunctionPass *createProfileEstimatorPass();<br>
> - extern char &ProfileEstimatorPassID;<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> - // createProfileVerifierPass - This pass verifies profiling information.<br>
> - //<br>
> - FunctionPass *createProfileVerifierPass();<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> - // createPathProfileLoaderPass - This pass loads information from a path<br>
> - // profile dump file.<br>
> - //<br>
> - ModulePass *createPathProfileLoaderPass();<br>
> - extern char &PathProfileLoaderPassID;<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> - // createNoPathProfileInfoPass - This pass implements the default<br>
> - // "no path profile".<br>
> - //<br>
> - ImmutablePass *createNoPathProfileInfoPass();<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> - // createPathProfileVerifierPass - This pass verifies path profiling<br>
> - // information.<br>
> - //<br>
> - ModulePass *createPathProfileVerifierPass();<br>
> -<br>
> - //===--------------------------------------------------------------------===//<br>
> - //<br>
> // createDSAAPass - This pass implements simple context sensitive alias<br>
> // analysis.<br>
> //<br>
><br>
> Removed: llvm/trunk/include/llvm/Analysis/PathNumbering.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PathNumbering.h?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PathNumbering.h?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/PathNumbering.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/PathNumbering.h (removed)<br>
> @@ -1,304 +0,0 @@<br>
> -//===- PathNumbering.h ----------------------------------------*- C++ -*---===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// Ball-Larus path numbers uniquely identify paths through a directed acyclic<br>
> -// graph (DAG) [Ball96]. For a CFG backedges are removed and replaced by phony<br>
> -// edges to obtain a DAG, and thus the unique path numbers [Ball96].<br>
> -//<br>
> -// The purpose of this analysis is to enumerate the edges in a CFG in order<br>
> -// to obtain paths from path numbers in a convenient manner. As described in<br>
> -// [Ball96] edges can be enumerated such that given a path number by following<br>
> -// the CFG and updating the path number, the path is obtained.<br>
> -//<br>
> -// [Ball96]<br>
> -// T. Ball and J. R. Larus. "Efficient Path Profiling."<br>
> -// International Symposium on Microarchitecture, pages 46-57, 1996.<br>
> -// <a href="http://portal.acm.org/citation.cfm?id=243857" target="_blank">http://portal.acm.org/citation.cfm?id=243857</a><br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_ANALYSIS_PATHNUMBERING_H<br>
> -#define LLVM_ANALYSIS_PATHNUMBERING_H<br>
> -<br>
> -#include "llvm/Analysis/ProfileInfoTypes.h"<br>
> -#include "llvm/IR/BasicBlock.h"<br>
> -#include "llvm/IR/Instructions.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CFG.h"<br>
> -#include <map><br>
> -#include <stack><br>
> -#include <vector><br>
> -<br>
> -namespace llvm {<br>
> -class BallLarusNode;<br>
> -class BallLarusEdge;<br>
> -class BallLarusDag;<br>
> -<br>
> -// typedefs for storage/ interators of various DAG components<br>
> -typedef std::vector<BallLarusNode*> BLNodeVector;<br>
> -typedef std::vector<BallLarusNode*>::iterator BLNodeIterator;<br>
> -typedef std::vector<BallLarusEdge*> BLEdgeVector;<br>
> -typedef std::vector<BallLarusEdge*>::iterator BLEdgeIterator;<br>
> -typedef std::map<BasicBlock*, BallLarusNode*> BLBlockNodeMap;<br>
> -typedef std::stack<BallLarusNode*> BLNodeStack;<br>
> -<br>
> -// Represents a basic block with information necessary for the BallLarus<br>
> -// algorithms.<br>
> -class BallLarusNode {<br>
> -public:<br>
> - enum NodeColor { WHITE, GRAY, BLACK };<br>
> -<br>
> - // Constructor: Initializes a new Node for the given BasicBlock<br>
> - BallLarusNode(BasicBlock* BB) :<br>
> - _basicBlock(BB), _numberPaths(0), _color(WHITE) {<br>
> - static unsigned nextUID = 0;<br>
> - _uid = nextUID++;<br>
> - }<br>
> -<br>
> - // Returns the basic block for the BallLarusNode<br>
> - BasicBlock* getBlock();<br>
> -<br>
> - // Get/set the number of paths to the exit starting at the node.<br>
> - unsigned getNumberPaths();<br>
> - void setNumberPaths(unsigned numberPaths);<br>
> -<br>
> - // Get/set the NodeColor used in graph algorithms.<br>
> - NodeColor getColor();<br>
> - void setColor(NodeColor color);<br>
> -<br>
> - // Iterator information for predecessor edges. Includes phony and<br>
> - // backedges.<br>
> - BLEdgeIterator predBegin();<br>
> - BLEdgeIterator predEnd();<br>
> - unsigned getNumberPredEdges();<br>
> -<br>
> - // Iterator information for successor edges. Includes phony and<br>
> - // backedges.<br>
> - BLEdgeIterator succBegin();<br>
> - BLEdgeIterator succEnd();<br>
> - unsigned getNumberSuccEdges();<br>
> -<br>
> - // Add an edge to the predecessor list.<br>
> - void addPredEdge(BallLarusEdge* edge);<br>
> -<br>
> - // Remove an edge from the predecessor list.<br>
> - void removePredEdge(BallLarusEdge* edge);<br>
> -<br>
> - // Add an edge to the successor list.<br>
> - void addSuccEdge(BallLarusEdge* edge);<br>
> -<br>
> - // Remove an edge from the successor list.<br>
> - void removeSuccEdge(BallLarusEdge* edge);<br>
> -<br>
> - // Returns the name of the BasicBlock being represented. If BasicBlock<br>
> - // is null then returns "<null>". If BasicBlock has no name, then<br>
> - // "<unnamed>" is returned. Intended for use with debug output.<br>
> - std::string getName();<br>
> -<br>
> -private:<br>
> - // The corresponding underlying BB.<br>
> - BasicBlock* _basicBlock;<br>
> -<br>
> - // Holds the predecessor edges of this node.<br>
> - BLEdgeVector _predEdges;<br>
> -<br>
> - // Holds the successor edges of this node.<br>
> - BLEdgeVector _succEdges;<br>
> -<br>
> - // The number of paths from the node to the exit.<br>
> - unsigned _numberPaths;<br>
> -<br>
> - // 'Color' used by graph algorithms to mark the node.<br>
> - NodeColor _color;<br>
> -<br>
> - // Unique ID to ensure naming difference with dotgraphs<br>
> - unsigned _uid;<br>
> -<br>
> - // Removes an edge from an edgeVector. Used by removePredEdge and<br>
> - // removeSuccEdge.<br>
> - void removeEdge(BLEdgeVector& v, BallLarusEdge* e);<br>
> -};<br>
> -<br>
> -// Represents an edge in the Dag. For an edge, v -> w, v is the source, and<br>
> -// w is the target.<br>
> -class BallLarusEdge {<br>
> -public:<br>
> - enum EdgeType { NORMAL, BACKEDGE, SPLITEDGE,<br>
> - BACKEDGE_PHONY, SPLITEDGE_PHONY, CALLEDGE_PHONY };<br>
> -<br>
> - // Constructor: Initializes an BallLarusEdge with a source and target.<br>
> - BallLarusEdge(BallLarusNode* source, BallLarusNode* target,<br>
> - unsigned duplicateNumber)<br>
> - : _source(source), _target(target), _weight(0), _edgeType(NORMAL),<br>
> - _realEdge(NULL), _duplicateNumber(duplicateNumber) {}<br>
> -<br>
> - // Returns the source/ target node of this edge.<br>
> - BallLarusNode* getSource() const;<br>
> - BallLarusNode* getTarget() const;<br>
> -<br>
> - // Sets the type of the edge.<br>
> - EdgeType getType() const;<br>
> -<br>
> - // Gets the type of the edge.<br>
> - void setType(EdgeType type);<br>
> -<br>
> - // Returns the weight of this edge. Used to decode path numbers to<br>
> - // sequences of basic blocks.<br>
> - unsigned getWeight();<br>
> -<br>
> - // Sets the weight of the edge. Used during path numbering.<br>
> - void setWeight(unsigned weight);<br>
> -<br>
> - // Gets/sets the phony edge originating at the root.<br>
> - BallLarusEdge* getPhonyRoot();<br>
> - void setPhonyRoot(BallLarusEdge* phonyRoot);<br>
> -<br>
> - // Gets/sets the phony edge terminating at the exit.<br>
> - BallLarusEdge* getPhonyExit();<br>
> - void setPhonyExit(BallLarusEdge* phonyExit);<br>
> -<br>
> - // Gets/sets the associated real edge if this is a phony edge.<br>
> - BallLarusEdge* getRealEdge();<br>
> - void setRealEdge(BallLarusEdge* realEdge);<br>
> -<br>
> - // Returns the duplicate number of the edge.<br>
> - unsigned getDuplicateNumber();<br>
> -<br>
> -protected:<br>
> - // Source node for this edge.<br>
> - BallLarusNode* _source;<br>
> -<br>
> - // Target node for this edge.<br>
> - BallLarusNode* _target;<br>
> -<br>
> -private:<br>
> - // Edge weight cooresponding to path number increments before removing<br>
> - // increments along a spanning tree. The sum over the edge weights gives<br>
> - // the path number.<br>
> - unsigned _weight;<br>
> -<br>
> - // Type to represent for what this edge is intended<br>
> - EdgeType _edgeType;<br>
> -<br>
> - // For backedges and split-edges, the phony edge which is linked to the<br>
> - // root node of the DAG. This contains a path number initialization.<br>
> - BallLarusEdge* _phonyRoot;<br>
> -<br>
> - // For backedges and split-edges, the phony edge which is linked to the<br>
> - // exit node of the DAG. This contains a path counter increment, and<br>
> - // potentially a path number increment.<br>
> - BallLarusEdge* _phonyExit;<br>
> -<br>
> - // If this is a phony edge, _realEdge is a link to the back or split<br>
> - // edge. Otherwise, this is null.<br>
> - BallLarusEdge* _realEdge;<br>
> -<br>
> - // An ID to differentiate between those edges which have the same source<br>
> - // and destination blocks.<br>
> - unsigned _duplicateNumber;<br>
> -};<br>
> -<br>
> -// Represents the Ball Larus DAG for a given Function. Can calculate<br>
> -// various properties required for instrumentation or analysis. E.g. the<br>
> -// edge weights that determine the path number.<br>
> -class BallLarusDag {<br>
> -public:<br>
> - // Initializes a BallLarusDag from the CFG of a given function. Must<br>
> - // call init() after creation, since some initialization requires<br>
> - // virtual functions.<br>
> - BallLarusDag(Function &F)<br>
> - : _root(NULL), _exit(NULL), _function(F) {}<br>
> -<br>
> - // Initialization that requires virtual functions which are not fully<br>
> - // functional in the constructor.<br>
> - void init();<br>
> -<br>
> - // Frees all memory associated with the DAG.<br>
> - virtual ~BallLarusDag();<br>
> -<br>
> - // Calculate the path numbers by assigning edge increments as prescribed<br>
> - // in Ball-Larus path profiling.<br>
> - void calculatePathNumbers();<br>
> -<br>
> - // Returns the number of paths for the DAG.<br>
> - unsigned getNumberOfPaths();<br>
> -<br>
> - // Returns the root (i.e. entry) node for the DAG.<br>
> - BallLarusNode* getRoot();<br>
> -<br>
> - // Returns the exit node for the DAG.<br>
> - BallLarusNode* getExit();<br>
> -<br>
> - // Returns the function for the DAG.<br>
> - Function& getFunction();<br>
> -<br>
> - // Clears the node colors.<br>
> - void clearColors(BallLarusNode::NodeColor color);<br>
> -<br>
> -protected:<br>
> - // All nodes in the DAG.<br>
> - BLNodeVector _nodes;<br>
> -<br>
> - // All edges in the DAG.<br>
> - BLEdgeVector _edges;<br>
> -<br>
> - // All backedges in the DAG.<br>
> - BLEdgeVector _backEdges;<br>
> -<br>
> - // Allows subclasses to determine which type of Node is created.<br>
> - // Override this method to produce subclasses of BallLarusNode if<br>
> - // necessary. The destructor of BallLarusDag will call free on each pointer<br>
> - // created.<br>
> - virtual BallLarusNode* createNode(BasicBlock* BB);<br>
> -<br>
> - // Allows subclasses to determine which type of Edge is created.<br>
> - // Override this method to produce subclasses of BallLarusEdge if<br>
> - // necessary. Parameters source and target will have been created by<br>
> - // createNode and can be cast to the subclass of BallLarusNode*<br>
> - // returned by createNode. The destructor of BallLarusDag will call free<br>
> - // on each pointer created.<br>
> - virtual BallLarusEdge* createEdge(BallLarusNode* source, BallLarusNode*<br>
> - target, unsigned duplicateNumber);<br>
> -<br>
> - // Proxy to node's constructor. Updates the DAG state.<br>
> - BallLarusNode* addNode(BasicBlock* BB);<br>
> -<br>
> - // Proxy to edge's constructor. Updates the DAG state.<br>
> - BallLarusEdge* addEdge(BallLarusNode* source, BallLarusNode* target,<br>
> - unsigned duplicateNumber);<br>
> -<br>
> -private:<br>
> - // The root (i.e. entry) node for this DAG.<br>
> - BallLarusNode* _root;<br>
> -<br>
> - // The exit node for this DAG.<br>
> - BallLarusNode* _exit;<br>
> -<br>
> - // The function represented by this DAG.<br>
> - Function& _function;<br>
> -<br>
> - // Processes one node and its imediate edges for building the DAG.<br>
> - void buildNode(BLBlockNodeMap& inDag, std::stack<BallLarusNode*>& dfsStack);<br>
> -<br>
> - // Process an edge in the CFG for DAG building.<br>
> - void buildEdge(BLBlockNodeMap& inDag, std::stack<BallLarusNode*>& dfsStack,<br>
> - BallLarusNode* currentNode, BasicBlock* succBB,<br>
> - unsigned duplicateNumber);<br>
> -<br>
> - // The weight on each edge is the increment required along any path that<br>
> - // contains that edge.<br>
> - void calculatePathNumbersFrom(BallLarusNode* node);<br>
> -<br>
> - // Adds a backedge with its phony edges. Updates the DAG state.<br>
> - void addBackedge(BallLarusNode* source, BallLarusNode* target,<br>
> - unsigned duplicateCount);<br>
> -};<br>
> -} // end namespace llvm<br>
> -<br>
> -#endif<br>
><br>
> Removed: llvm/trunk/include/llvm/Analysis/PathProfileInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PathProfileInfo.h?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PathProfileInfo.h?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/PathProfileInfo.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/PathProfileInfo.h (removed)<br>
> @@ -1,112 +0,0 @@<br>
> -//===- PathProfileInfo.h --------------------------------------*- C++ -*---===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file outlines the interface used by optimizers to load path profiles.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_ANALYSIS_PATHPROFILEINFO_H<br>
> -#define LLVM_ANALYSIS_PATHPROFILEINFO_H<br>
> -<br>
> -#include "llvm/Analysis/PathNumbering.h"<br>
> -#include "llvm/IR/BasicBlock.h"<br>
> -<br>
> -namespace llvm {<br>
> -<br>
> -class ProfilePath;<br>
> -class ProfilePathEdge;<br>
> -class PathProfileInfo;<br>
> -<br>
> -typedef std::vector<ProfilePathEdge> ProfilePathEdgeVector;<br>
> -typedef std::vector<ProfilePathEdge>::iterator ProfilePathEdgeIterator;<br>
> -<br>
> -typedef std::vector<BasicBlock*> ProfilePathBlockVector;<br>
> -typedef std::vector<BasicBlock*>::iterator ProfilePathBlockIterator;<br>
> -<br>
> -typedef std::map<unsigned int,ProfilePath*> ProfilePathMap;<br>
> -typedef std::map<unsigned int,ProfilePath*>::iterator ProfilePathIterator;<br>
> -<br>
> -typedef std::map<Function*,unsigned int> FunctionPathCountMap;<br>
> -typedef std::map<Function*,ProfilePathMap> FunctionPathMap;<br>
> -typedef std::map<Function*,ProfilePathMap>::iterator FunctionPathIterator;<br>
> -<br>
> -class ProfilePathEdge {<br>
> -public:<br>
> - ProfilePathEdge(BasicBlock* source, BasicBlock* target,<br>
> - unsigned duplicateNumber);<br>
> -<br>
> - inline unsigned getDuplicateNumber() { return _duplicateNumber; }<br>
> - inline BasicBlock* getSource() { return _source; }<br>
> - inline BasicBlock* getTarget() { return _target; }<br>
> -<br>
> -protected:<br>
> - BasicBlock* _source;<br>
> - BasicBlock* _target;<br>
> - unsigned _duplicateNumber;<br>
> -};<br>
> -<br>
> -class ProfilePath {<br>
> -public:<br>
> - ProfilePath(unsigned int number, unsigned int count,<br>
> - double countStdDev, PathProfileInfo* ppi);<br>
> -<br>
> - double getFrequency() const;<br>
> -<br>
> - inline unsigned int getNumber() const { return _number; }<br>
> - inline unsigned int getCount() const { return _count; }<br>
> - inline double getCountStdDev() const { return _countStdDev; }<br>
> -<br>
> - ProfilePathEdgeVector* getPathEdges() const;<br>
> - ProfilePathBlockVector* getPathBlocks() const;<br>
> -<br>
> - BasicBlock* getFirstBlockInPath() const;<br>
> -<br>
> -private:<br>
> - unsigned int _number;<br>
> - unsigned int _count;<br>
> - double _countStdDev;<br>
> -<br>
> - // double pointer back to the profiling info<br>
> - PathProfileInfo* _ppi;<br>
> -};<br>
> -<br>
> -// TODO: overload [] operator for getting path<br>
> -// Add: getFunctionCallCount()<br>
> -class PathProfileInfo {<br>
> - public:<br>
> - PathProfileInfo();<br>
> - ~PathProfileInfo();<br>
> -<br>
> - void setCurrentFunction(Function* F);<br>
> - Function* getCurrentFunction() const;<br>
> - BasicBlock* getCurrentFunctionEntry();<br>
> -<br>
> - ProfilePath* getPath(unsigned int number);<br>
> - unsigned int getPotentialPathCount();<br>
> -<br>
> - ProfilePathIterator pathBegin();<br>
> - ProfilePathIterator pathEnd();<br>
> - unsigned int pathsRun();<br>
> -<br>
> - static char ID; // Pass identification<br>
> - std::string argList;<br>
> -<br>
> -protected:<br>
> - FunctionPathMap _functionPaths;<br>
> - FunctionPathCountMap _functionPathCounts;<br>
> -<br>
> -private:<br>
> - BallLarusDag* _currentDag;<br>
> - Function* _currentFunction;<br>
> -<br>
> - friend class ProfilePath;<br>
> -};<br>
> -} // end namespace llvm<br>
> -<br>
> -#endif<br>
><br>
> Removed: llvm/trunk/include/llvm/Analysis/ProfileDataLoader.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileDataLoader.h?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileDataLoader.h?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/ProfileDataLoader.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/ProfileDataLoader.h (removed)<br>
> @@ -1,140 +0,0 @@<br>
> -//===- ProfileDataLoader.h - Load & convert profile info ----*- C++ -*-===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// The ProfileDataLoader class is used to load profiling data from a dump file.<br>
> -// The ProfileDataT<FType, BType> class is used to store the mapping of this<br>
> -// data to control flow edges.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_ANALYSIS_PROFILEDATALOADER_H<br>
> -#define LLVM_ANALYSIS_PROFILEDATALOADER_H<br>
> -<br>
> -#include "llvm/ADT/ArrayRef.h"<br>
> -#include "llvm/ADT/DenseMap.h"<br>
> -#include "llvm/ADT/SmallVector.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/ErrorHandling.h"<br>
> -#include <string><br>
> -<br>
> -namespace llvm {<br>
> -<br>
> -class ModulePass;<br>
> -class Function;<br>
> -class BasicBlock;<br>
> -<br>
> -// Helper for dumping edges to dbgs().<br>
> -raw_ostream& operator<<(raw_ostream &O, std::pair<const BasicBlock *,<br>
> - const BasicBlock *> E);<br>
> -<br>
> -/// \brief The ProfileDataT<FType, BType> class is used to store the mapping of<br>
> -/// profiling data to control flow edges.<br>
> -///<br>
> -/// An edge is defined by its source and sink basic blocks.<br>
> -template<class FType, class BType><br>
> -class ProfileDataT {<br>
> -public:<br>
> - // The profiling information defines an Edge by its source and sink basic<br>
> - // blocks.<br>
> - typedef std::pair<const BType*, const BType*> Edge;<br>
> -<br>
> -private:<br>
> - typedef DenseMap<Edge, unsigned> EdgeWeights;<br>
> -<br>
> - /// \brief Count the number of times a transition between two blocks is<br>
> - /// executed.<br>
> - ///<br>
> - /// As a special case, we also hold an edge from the null BasicBlock to the<br>
> - /// entry block to indicate how many times the function was entered.<br>
> - DenseMap<const FType*, EdgeWeights> EdgeInformation;<br>
> -<br>
> -public:<br>
> - /// getFunction() - Returns the Function for an Edge.<br>
> - static const FType *getFunction(Edge e) {<br>
> - // e.first may be NULL<br>
> - assert(((!e.first) || (e.first->getParent() == e.second->getParent()))<br>
> - && "A ProfileData::Edge can not be between two functions");<br>
> - assert(e.second && "A ProfileData::Edge must have a real sink");<br>
> - return e.second->getParent();<br>
> - }<br>
> -<br>
> - /// getEdge() - Creates an Edge between two BasicBlocks.<br>
> - static Edge getEdge(const BType *Src, const BType *Dest) {<br>
> - return Edge(Src, Dest);<br>
> - }<br>
> -<br>
> - /// getEdgeWeight - Return the number of times that a given edge was<br>
> - /// executed.<br>
> - unsigned getEdgeWeight(Edge e) const {<br>
> - const FType *f = getFunction(e);<br>
> - assert((EdgeInformation.find(f) != EdgeInformation.end())<br>
> - && "No profiling information for function");<br>
> - EdgeWeights weights = EdgeInformation.find(f)->second;<br>
> -<br>
> - assert((weights.find(e) != weights.end())<br>
> - && "No profiling information for edge");<br>
> - return weights.find(e)->second;<br>
> - }<br>
> -<br>
> - /// addEdgeWeight - Add 'weight' to the already stored execution count for<br>
> - /// this edge.<br>
> - void addEdgeWeight(Edge e, unsigned weight) {<br>
> - EdgeInformation[getFunction(e)][e] += weight;<br>
> - }<br>
> -};<br>
> -<br>
> -typedef ProfileDataT<Function, BasicBlock> ProfileData;<br>
> -//typedef ProfileDataT<MachineFunction, MachineBasicBlock> MachineProfileData;<br>
> -<br>
> -/// The ProfileDataLoader class is used to load raw profiling data from the<br>
> -/// dump file.<br>
> -class ProfileDataLoader {<br>
> -private:<br>
> - /// The name of the file where the raw profiling data is stored.<br>
> - const std::string &Filename;<br>
> -<br>
> - /// A vector of the command line arguments used when the target program was<br>
> - /// run to generate profiling data. One entry per program run.<br>
> - SmallVector<std::string, 1> CommandLines;<br>
> -<br>
> - /// The raw values for how many times each edge was traversed, values from<br>
> - /// multiple program runs are accumulated.<br>
> - SmallVector<unsigned, 32> EdgeCounts;<br>
> -<br>
> -public:<br>
> - /// ProfileDataLoader ctor - Read the specified profiling data file, exiting<br>
> - /// the program if the file is invalid or broken.<br>
> - ProfileDataLoader(const char *ToolName, const std::string &Filename);<br>
> -<br>
> - /// A special value used to represent the weight of an edge which has not<br>
> - /// been counted yet.<br>
> - static const unsigned Uncounted;<br>
> -<br>
> - /// getNumExecutions - Return the number of times the target program was run<br>
> - /// to generate this profiling data.<br>
> - unsigned getNumExecutions() const { return CommandLines.size(); }<br>
> -<br>
> - /// getExecution - Return the command line parameters used to generate the<br>
> - /// i'th set of profiling data.<br>
> - const std::string &getExecution(unsigned i) const { return CommandLines[i]; }<br>
> -<br>
> - const std::string &getFileName() const { return Filename; }<br>
> -<br>
> - /// getRawEdgeCounts - Return the raw profiling data, this is just a list of<br>
> - /// numbers with no mappings to edges.<br>
> - ArrayRef<unsigned> getRawEdgeCounts() const { return EdgeCounts; }<br>
> -};<br>
> -<br>
> -/// createProfileMetadataLoaderPass - This function returns a Pass that loads<br>
> -/// the profiling information for the module from the specified filename.<br>
> -ModulePass *createProfileMetadataLoaderPass(const std::string &Filename);<br>
> -<br>
> -} // End llvm namespace<br>
> -<br>
> -#endif<br>
><br>
> Removed: llvm/trunk/include/llvm/Analysis/ProfileDataTypes.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileDataTypes.h?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileDataTypes.h?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/ProfileDataTypes.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/ProfileDataTypes.h (removed)<br>
> @@ -1,39 +0,0 @@<br>
> -/*===-- ProfileDataTypes.h - Profiling info shared constants --------------===*\<br>
> -|*<br>
> -|* The LLVM Compiler Infrastructure<br>
> -|*<br>
> -|* This file is distributed under the University of Illinois Open Source<br>
> -|* License. See LICENSE.TXT for details.<br>
> -|*<br>
> -|*===----------------------------------------------------------------------===*|<br>
> -|*<br>
> -|* This file defines constants shared by the various different profiling<br>
> -|* runtime libraries and the LLVM C++ profile metadata loader. It must be a<br>
> -|* C header because, at present, the profiling runtimes are written in C.<br>
> -|*<br>
> -\*===----------------------------------------------------------------------===*/<br>
> -<br>
> -#ifndef LLVM_ANALYSIS_PROFILEDATATYPES_H<br>
> -#define LLVM_ANALYSIS_PROFILEDATATYPES_H<br>
> -<br>
> -/* Included by libprofile. */<br>
> -#if defined(__cplusplus)<br>
> -extern "C" {<br>
> -#endif<br>
> -<br>
> -/* TODO: Strip out unused entries once ProfileInfo etc has been removed. */<br>
> -enum ProfilingType {<br>
> - ArgumentInfo = 1, /* The command line argument block */<br>
> - FunctionInfo = 2, /* Function profiling information */<br>
> - BlockInfo = 3, /* Block profiling information */<br>
> - EdgeInfo = 4, /* Edge profiling information */<br>
> - PathInfo = 5, /* Path profiling information */<br>
> - BBTraceInfo = 6, /* Basic block trace information */<br>
> - OptEdgeInfo = 7 /* Edge profiling information, optimal version */<br>
> -};<br>
> -<br>
> -#if defined(__cplusplus)<br>
> -}<br>
> -#endif<br>
> -<br>
> -#endif /* LLVM_ANALYSIS_PROFILEDATATYPES_H */<br>
><br>
> Removed: llvm/trunk/include/llvm/Analysis/ProfileInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileInfo.h?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileInfo.h?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/ProfileInfo.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/ProfileInfo.h (removed)<br>
> @@ -1,247 +0,0 @@<br>
> -//===- llvm/Analysis/ProfileInfo.h - Profile Info Interface -----*- C++ -*-===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file defines the generic ProfileInfo interface, which is used as the<br>
> -// common interface used by all clients of profiling information, and<br>
> -// implemented either by making static guestimations, or by actually reading in<br>
> -// profiling information gathered by running the program.<br>
> -//<br>
> -// Note that to be useful, all profile-based optimizations should preserve<br>
> -// ProfileInfo, which requires that they notify it when changes to the CFG are<br>
> -// made. (This is not implemented yet.)<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_ANALYSIS_PROFILEINFO_H<br>
> -#define LLVM_ANALYSIS_PROFILEINFO_H<br>
> -<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/ErrorHandling.h"<br>
> -#include "llvm/Support/Format.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <cassert><br>
> -#include <map><br>
> -#include <set><br>
> -#include <string><br>
> -<br>
> -namespace llvm {<br>
> - class Pass;<br>
> - class raw_ostream;<br>
> -<br>
> - class BasicBlock;<br>
> - class Function;<br>
> - class MachineBasicBlock;<br>
> - class MachineFunction;<br>
> -<br>
> - // Helper for dumping edges to dbgs().<br>
> - raw_ostream& operator<<(raw_ostream &O, std::pair<const BasicBlock *, const BasicBlock *> E);<br>
> - raw_ostream& operator<<(raw_ostream &O, std::pair<const MachineBasicBlock *, const MachineBasicBlock *> E);<br>
> -<br>
> - raw_ostream& operator<<(raw_ostream &O, const BasicBlock *BB);<br>
> - raw_ostream& operator<<(raw_ostream &O, const MachineBasicBlock *MBB);<br>
> -<br>
> - raw_ostream& operator<<(raw_ostream &O, const Function *F);<br>
> - raw_ostream& operator<<(raw_ostream &O, const MachineFunction *MF);<br>
> -<br>
> - /// ProfileInfo Class - This class holds and maintains profiling<br>
> - /// information for some unit of code.<br>
> - template<class FType, class BType><br>
> - class ProfileInfoT {<br>
> - public:<br>
> - // Types for handling profiling information.<br>
> - typedef std::pair<const BType*, const BType*> Edge;<br>
> - typedef std::pair<Edge, double> EdgeWeight;<br>
> - typedef std::map<Edge, double> EdgeWeights;<br>
> - typedef std::map<const BType*, double> BlockCounts;<br>
> - typedef std::map<const BType*, const BType*> Path;<br>
> -<br>
> - protected:<br>
> - // EdgeInformation - Count the number of times a transition between two<br>
> - // blocks is executed. As a special case, we also hold an edge from the<br>
> - // null BasicBlock to the entry block to indicate how many times the<br>
> - // function was entered.<br>
> - std::map<const FType*, EdgeWeights> EdgeInformation;<br>
> -<br>
> - // BlockInformation - Count the number of times a block is executed.<br>
> - std::map<const FType*, BlockCounts> BlockInformation;<br>
> -<br>
> - // FunctionInformation - Count the number of times a function is executed.<br>
> - std::map<const FType*, double> FunctionInformation;<br>
> -<br>
> - ProfileInfoT<MachineFunction, MachineBasicBlock> *MachineProfile;<br>
> - public:<br>
> - static char ID; // Class identification, replacement for typeinfo<br>
> - ProfileInfoT();<br>
> - ~ProfileInfoT(); // We want to be subclassed<br>
> -<br>
> - // MissingValue - The value that is returned for execution counts in case<br>
> - // no value is available.<br>
> - static const double MissingValue;<br>
> -<br>
> - // getFunction() - Returns the Function for an Edge, checking for validity.<br>
> - static const FType* getFunction(Edge e) {<br>
> - if (e.first)<br>
> - return e.first->getParent();<br>
> - if (e.second)<br>
> - return e.second->getParent();<br>
> - llvm_unreachable("Invalid ProfileInfo::Edge");<br>
> - }<br>
> -<br>
> - // getEdge() - Creates an Edge from two BasicBlocks.<br>
> - static Edge getEdge(const BType *Src, const BType *Dest) {<br>
> - return std::make_pair(Src, Dest);<br>
> - }<br>
> -<br>
> - //===------------------------------------------------------------------===//<br>
> - /// Profile Information Queries<br>
> - ///<br>
> - double getExecutionCount(const FType *F);<br>
> -<br>
> - double getExecutionCount(const BType *BB);<br>
> -<br>
> - void setExecutionCount(const BType *BB, double w);<br>
> -<br>
> - void addExecutionCount(const BType *BB, double w);<br>
> -<br>
> - double getEdgeWeight(Edge e) const {<br>
> - typename std::map<const FType*, EdgeWeights>::const_iterator J =<br>
> - EdgeInformation.find(getFunction(e));<br>
> - if (J == EdgeInformation.end()) return MissingValue;<br>
> -<br>
> - typename EdgeWeights::const_iterator I = J->second.find(e);<br>
> - if (I == J->second.end()) return MissingValue;<br>
> -<br>
> - return I->second;<br>
> - }<br>
> -<br>
> - void setEdgeWeight(Edge e, double w) {<br>
> - DEBUG_WITH_TYPE("profile-info",<br>
> - dbgs() << "Creating Edge " << e<br>
> - << " (weight: " << format("%.20g",w) << ")\n");<br>
> - EdgeInformation[getFunction(e)][e] = w;<br>
> - }<br>
> -<br>
> - void addEdgeWeight(Edge e, double w);<br>
> -<br>
> - EdgeWeights &getEdgeWeights (const FType *F) {<br>
> - return EdgeInformation[F];<br>
> - }<br>
> -<br>
> - //===------------------------------------------------------------------===//<br>
> - /// Analysis Update Methods<br>
> - ///<br>
> - void removeBlock(const BType *BB);<br>
> -<br>
> - void removeEdge(Edge e);<br>
> -<br>
> - void replaceEdge(const Edge &, const Edge &);<br>
> -<br>
> - enum GetPathMode {<br>
> - GetPathToExit = 1,<br>
> - GetPathToValue = 2,<br>
> - GetPathToDest = 4,<br>
> - GetPathWithNewEdges = 8<br>
> - };<br>
> -<br>
> - const BType *GetPath(const BType *Src, const BType *Dest,<br>
> - Path &P, unsigned Mode);<br>
> -<br>
> - void divertFlow(const Edge &, const Edge &);<br>
> -<br>
> - void splitEdge(const BType *FirstBB, const BType *SecondBB,<br>
> - const BType *NewBB, bool MergeIdenticalEdges = false);<br>
> -<br>
> - void splitBlock(const BType *Old, const BType* New);<br>
> -<br>
> - void splitBlock(const BType *BB, const BType* NewBB,<br>
> - BType *const *Preds, unsigned NumPreds);<br>
> -<br>
> - void replaceAllUses(const BType *RmBB, const BType *DestBB);<br>
> -<br>
> - void transfer(const FType *Old, const FType *New);<br>
> -<br>
> - void repair(const FType *F);<br>
> -<br>
> - void dump(FType *F = 0, bool real = true) {<br>
> - dbgs() << "**** This is ProfileInfo " << this << " speaking:\n";<br>
> - if (!real) {<br>
> - typename std::set<const FType*> Functions;<br>
> -<br>
> - dbgs() << "Functions: \n";<br>
> - if (F) {<br>
> - dbgs() << F << "@" << format("%p", F) << ": " << format("%.20g",getExecutionCount(F)) << "\n";<br>
> - Functions.insert(F);<br>
> - } else {<br>
> - for (typename std::map<const FType*, double>::iterator fi = FunctionInformation.begin(),<br>
> - fe = FunctionInformation.end(); fi != fe; ++fi) {<br>
> - dbgs() << fi->first << "@" << format("%p",fi->first) << ": " << format("%.20g",fi->second) << "\n";<br>
> - Functions.insert(fi->first);<br>
> - }<br>
> - }<br>
> -<br>
> - for (typename std::set<const FType*>::iterator FI = Functions.begin(), FE = Functions.end();<br>
> - FI != FE; ++FI) {<br>
> - const FType *F = *FI;<br>
> - typename std::map<const FType*, BlockCounts>::iterator bwi = BlockInformation.find(F);<br>
> - dbgs() << "BasicBlocks for Function " << F << ":\n";<br>
> - for (typename BlockCounts::const_iterator bi = bwi->second.begin(), be = bwi->second.end(); bi != be; ++bi) {<br>
> - dbgs() << bi->first << "@" << format("%p", bi->first) << ": " << format("%.20g",bi->second) << "\n";<br>
> - }<br>
> - }<br>
> -<br>
> - for (typename std::set<const FType*>::iterator FI = Functions.begin(), FE = Functions.end();<br>
> - FI != FE; ++FI) {<br>
> - typename std::map<const FType*, EdgeWeights>::iterator ei = EdgeInformation.find(*FI);<br>
> - dbgs() << "Edges for Function " << ei->first << ":\n";<br>
> - for (typename EdgeWeights::iterator ewi = ei->second.begin(), ewe = ei->second.end();<br>
> - ewi != ewe; ++ewi) {<br>
> - dbgs() << ewi->first << ": " << format("%.20g",ewi->second) << "\n";<br>
> - }<br>
> - }<br>
> - } else {<br>
> - assert(F && "No function given, this is not supported!");<br>
> - dbgs() << "Functions: \n";<br>
> - dbgs() << F << "@" << format("%p", F) << ": " << format("%.20g",getExecutionCount(F)) << "\n";<br>
> -<br>
> - dbgs() << "BasicBlocks for Function " << F << ":\n";<br>
> - for (typename FType::const_iterator BI = F->begin(), BE = F->end();<br>
> - BI != BE; ++BI) {<br>
> - const BType *BB = &(*BI);<br>
> - dbgs() << BB << "@" << format("%p", BB) << ": " << format("%.20g",getExecutionCount(BB)) << "\n";<br>
> - }<br>
> - }<br>
> - dbgs() << "**** ProfileInfo " << this << ", over and out.\n";<br>
> - }<br>
> -<br>
> - bool CalculateMissingEdge(const BType *BB, Edge &removed, bool assumeEmptyExit = false);<br>
> -<br>
> - bool EstimateMissingEdges(const BType *BB);<br>
> -<br>
> - ProfileInfoT<MachineFunction, MachineBasicBlock> *MI() {<br>
> - if (MachineProfile == 0)<br>
> - MachineProfile = new ProfileInfoT<MachineFunction, MachineBasicBlock>();<br>
> - return MachineProfile;<br>
> - }<br>
> -<br>
> - bool hasMI() const {<br>
> - return (MachineProfile != 0);<br>
> - }<br>
> - };<br>
> -<br>
> - typedef ProfileInfoT<Function, BasicBlock> ProfileInfo;<br>
> - typedef ProfileInfoT<MachineFunction, MachineBasicBlock> MachineProfileInfo;<br>
> -<br>
> - /// createProfileLoaderPass - This function returns a Pass that loads the<br>
> - /// profiling information for the module from the specified filename, making<br>
> - /// it available to the optimizers.<br>
> - Pass *createProfileLoaderPass(const std::string &Filename);<br>
> -<br>
> -} // End llvm namespace<br>
> -<br>
> -#endif<br>
><br>
> Removed: llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h (removed)<br>
> @@ -1,81 +0,0 @@<br>
> -//===- ProfileInfoLoader.h - Load & convert profile information -*- C++ -*-===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// The ProfileInfoLoader class is used to load and represent profiling<br>
> -// information read in from the dump file. If conversions between formats are<br>
> -// needed, it can also do this.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_ANALYSIS_PROFILEINFOLOADER_H<br>
> -#define LLVM_ANALYSIS_PROFILEINFOLOADER_H<br>
> -<br>
> -#include <string><br>
> -#include <utility><br>
> -#include <vector><br>
> -<br>
> -namespace llvm {<br>
> -<br>
> -class Module;<br>
> -class Function;<br>
> -class BasicBlock;<br>
> -<br>
> -class ProfileInfoLoader {<br>
> - const std::string &Filename;<br>
> - std::vector<std::string> CommandLines;<br>
> - std::vector<unsigned> FunctionCounts;<br>
> - std::vector<unsigned> BlockCounts;<br>
> - std::vector<unsigned> EdgeCounts;<br>
> - std::vector<unsigned> OptimalEdgeCounts;<br>
> - std::vector<unsigned> BBTrace;<br>
> -public:<br>
> - // ProfileInfoLoader ctor - Read the specified profiling data file, exiting<br>
> - // the program if the file is invalid or broken.<br>
> - ProfileInfoLoader(const char *ToolName, const std::string &Filename);<br>
> -<br>
> - static const unsigned Uncounted;<br>
> -<br>
> - unsigned getNumExecutions() const { return CommandLines.size(); }<br>
> - const std::string &getExecution(unsigned i) const { return CommandLines[i]; }<br>
> -<br>
> - const std::string &getFileName() const { return Filename; }<br>
> -<br>
> - // getRawFunctionCounts - This method is used by consumers of function<br>
> - // counting information.<br>
> - //<br>
> - const std::vector<unsigned> &getRawFunctionCounts() const {<br>
> - return FunctionCounts;<br>
> - }<br>
> -<br>
> - // getRawBlockCounts - This method is used by consumers of block counting<br>
> - // information.<br>
> - //<br>
> - const std::vector<unsigned> &getRawBlockCounts() const {<br>
> - return BlockCounts;<br>
> - }<br>
> -<br>
> - // getEdgeCounts - This method is used by consumers of edge counting<br>
> - // information.<br>
> - //<br>
> - const std::vector<unsigned> &getRawEdgeCounts() const {<br>
> - return EdgeCounts;<br>
> - }<br>
> -<br>
> - // getEdgeOptimalCounts - This method is used by consumers of optimal edge<br>
> - // counting information.<br>
> - //<br>
> - const std::vector<unsigned> &getRawOptimalEdgeCounts() const {<br>
> - return OptimalEdgeCounts;<br>
> - }<br>
> -<br>
> -};<br>
> -<br>
> -} // End llvm namespace<br>
> -<br>
> -#endif<br>
><br>
> Removed: llvm/trunk/include/llvm/Analysis/ProfileInfoTypes.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileInfoTypes.h?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileInfoTypes.h?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/ProfileInfoTypes.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/ProfileInfoTypes.h (removed)<br>
> @@ -1,52 +0,0 @@<br>
> -/*===-- ProfileInfoTypes.h - Profiling info shared constants --------------===*\<br>
> -|*<br>
> -|* The LLVM Compiler Infrastructure<br>
> -|*<br>
> -|* This file is distributed under the University of Illinois Open Source<br>
> -|* License. See LICENSE.TXT for details.<br>
> -|*<br>
> -|*===----------------------------------------------------------------------===*|<br>
> -|*<br>
> -|* This file defines constants shared by the various different profiling<br>
> -|* runtime libraries and the LLVM C++ profile info loader. It must be a<br>
> -|* C header because, at present, the profiling runtimes are written in C.<br>
> -|*<br>
> -\*===----------------------------------------------------------------------===*/<br>
> -<br>
> -#ifndef LLVM_ANALYSIS_PROFILEINFOTYPES_H<br>
> -#define LLVM_ANALYSIS_PROFILEINFOTYPES_H<br>
> -<br>
> -/* Included by libprofile. */<br>
> -#if defined(__cplusplus)<br>
> -extern "C" {<br>
> -#endif<br>
> -<br>
> -/* IDs to distinguish between those path counters stored in hashses vs arrays */<br>
> -enum ProfilingStorageType {<br>
> - ProfilingArray = 1,<br>
> - ProfilingHash = 2<br>
> -};<br>
> -<br>
> -#include "llvm/Analysis/ProfileDataTypes.h"<br>
> -<br>
> -/*<br>
> - * The header for tables that map path numbers to path counters.<br>
> - */<br>
> -typedef struct {<br>
> - unsigned fnNumber; /* function number for these counters */<br>
> - unsigned numEntries; /* number of entries stored */<br>
> -} PathProfileHeader;<br>
> -<br>
> -/*<br>
> - * Describes an entry in a tagged table for path counters.<br>
> - */<br>
> -typedef struct {<br>
> - unsigned pathNumber;<br>
> - unsigned pathCounter;<br>
> -} PathProfileTableEntry;<br>
> -<br>
> -#if defined(__cplusplus)<br>
> -}<br>
> -#endif<br>
> -<br>
> -#endif /* LLVM_ANALYSIS_PROFILEINFOTYPES_H */<br>
><br>
> Modified: llvm/trunk/include/llvm/InitializePasses.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/InitializePasses.h (original)<br>
> +++ llvm/trunk/include/llvm/InitializePasses.h Wed Oct 2 10:42:23 2013<br>
> @@ -113,9 +113,7 @@ void initializeDominanceFrontierPass(Pas<br>
> void initializeDominatorTreePass(PassRegistry&);<br>
> void initializeEarlyIfConverterPass(PassRegistry&);<br>
> void initializeEdgeBundlesPass(PassRegistry&);<br>
> -void initializeEdgeProfilerPass(PassRegistry&);<br>
> void initializeExpandPostRAPass(PassRegistry&);<br>
> -void initializePathProfilerPass(PassRegistry&);<br>
> void initializeGCOVProfilerPass(PassRegistry&);<br>
> void initializeAddressSanitizerPass(PassRegistry&);<br>
> void initializeAddressSanitizerModulePass(PassRegistry&);<br>
> @@ -155,8 +153,6 @@ void initializeLiveRegMatrixPass(PassReg<br>
> void initializeLiveStacksPass(PassRegistry&);<br>
> void initializeLiveVariablesPass(PassRegistry&);<br>
> void initializeLoaderPassPass(PassRegistry&);<br>
> -void initializeProfileMetadataLoaderPassPass(PassRegistry&);<br>
> -void initializePathProfileLoaderPassPass(PassRegistry&);<br>
> void initializeLocalStackSlotPassPass(PassRegistry&);<br>
> void initializeLoopDeletionPass(PassRegistry&);<br>
> void initializeLoopExtractorPass(PassRegistry&);<br>
> @@ -195,14 +191,11 @@ void initializeMetaRenamerPass(PassRegis<br>
> void initializeMergeFunctionsPass(PassRegistry&);<br>
> void initializeModuleDebugInfoPrinterPass(PassRegistry&);<br>
> void initializeNoAAPass(PassRegistry&);<br>
> -void initializeNoProfileInfoPass(PassRegistry&);<br>
> -void initializeNoPathProfileInfoPass(PassRegistry&);<br>
> void initializeObjCARCAliasAnalysisPass(PassRegistry&);<br>
> void initializeObjCARCAPElimPass(PassRegistry&);<br>
> void initializeObjCARCExpandPass(PassRegistry&);<br>
> void initializeObjCARCContractPass(PassRegistry&);<br>
> void initializeObjCARCOptPass(PassRegistry&);<br>
> -void initializeOptimalEdgeProfilerPass(PassRegistry&);<br>
> void initializeOptimizePHIsPass(PassRegistry&);<br>
> void initializePartiallyInlineLibCallsPass(PassRegistry&);<br>
> void initializePEIPass(PassRegistry&);<br>
> @@ -220,11 +213,6 @@ void initializePrintFunctionPassPass(Pas<br>
> void initializePrintModulePassPass(PassRegistry&);<br>
> void initializePrintBasicBlockPassPass(PassRegistry&);<br>
> void initializeProcessImplicitDefsPass(PassRegistry&);<br>
> -void initializeProfileEstimatorPassPass(PassRegistry&);<br>
> -void initializeProfileInfoAnalysisGroup(PassRegistry&);<br>
> -void initializePathProfileInfoAnalysisGroup(PassRegistry&);<br>
> -void initializePathProfileVerifierPass(PassRegistry&);<br>
> -void initializeProfileVerifierPassPass(PassRegistry&);<br>
> void initializePromotePassPass(PassRegistry&);<br>
> void initializePruneEHPass(PassRegistry&);<br>
> void initializeReassociatePass(PassRegistry&);<br>
><br>
> Modified: llvm/trunk/include/llvm/LinkAllPasses.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllPasses.h?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllPasses.h?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/LinkAllPasses.h (original)<br>
> +++ llvm/trunk/include/llvm/LinkAllPasses.h Wed Oct 2 10:42:23 2013<br>
> @@ -74,9 +74,6 @@ namespace {<br>
> (void) llvm::createDomPrinterPass();<br>
> (void) llvm::createDomOnlyViewerPass();<br>
> (void) llvm::createDomViewerPass();<br>
> - (void) llvm::createEdgeProfilerPass();<br>
> - (void) llvm::createOptimalEdgeProfilerPass();<br>
> - (void) llvm::createPathProfilerPass();<br>
> (void) llvm::createGCOVProfilerPass();<br>
> (void) llvm::createFunctionInliningPass();<br>
> (void) llvm::createAlwaysInlinerPass();<br>
> @@ -102,18 +99,11 @@ namespace {<br>
> (void) llvm::createLowerInvokePass();<br>
> (void) llvm::createLowerSwitchPass();<br>
> (void) llvm::createNoAAPass();<br>
> - (void) llvm::createNoProfileInfoPass();<br>
> (void) llvm::createObjCARCAliasAnalysisPass();<br>
> (void) llvm::createObjCARCAPElimPass();<br>
> (void) llvm::createObjCARCExpandPass();<br>
> (void) llvm::createObjCARCContractPass();<br>
> (void) llvm::createObjCARCOptPass();<br>
> - (void) llvm::createProfileEstimatorPass();<br>
> - (void) llvm::createProfileVerifierPass();<br>
> - (void) llvm::createPathProfileVerifierPass();<br>
> - (void) llvm::createProfileLoaderPass();<br>
> - (void) llvm::createProfileMetadataLoaderPass();<br>
> - (void) llvm::createPathProfileLoaderPass();<br>
> (void) llvm::createPromoteMemoryToRegisterPass();<br>
> (void) llvm::createDemoteRegisterToMemoryPass();<br>
> (void) llvm::createPruneEHPass();<br>
><br>
> Modified: llvm/trunk/include/llvm/Transforms/Instrumentation.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Instrumentation.h?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Instrumentation.h?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Transforms/Instrumentation.h (original)<br>
> +++ llvm/trunk/include/llvm/Transforms/Instrumentation.h Wed Oct 2 10:42:23 2013<br>
> @@ -35,15 +35,6 @@ namespace llvm {<br>
> class ModulePass;<br>
> class FunctionPass;<br>
><br>
> -// Insert edge profiling instrumentation<br>
> -ModulePass *createEdgeProfilerPass();<br>
> -<br>
> -// Insert optimal edge profiling instrumentation<br>
> -ModulePass *createOptimalEdgeProfilerPass();<br>
> -<br>
> -// Insert path profiling instrumentation<br>
> -ModulePass *createPathProfilerPass();<br>
> -<br>
> // Insert GCOV profiling instrumentation<br>
> struct GCOVOptions {<br>
> static GCOVOptions getDefault();<br>
><br>
> Modified: llvm/trunk/lib/Analysis/Analysis.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/Analysis.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/Analysis.cpp Wed Oct 2 10:42:23 2013<br>
> @@ -54,16 +54,6 @@ void llvm::initializeAnalysis(PassRegist<br>
> initializeMemoryDependenceAnalysisPass(Registry);<br>
> initializeModuleDebugInfoPrinterPass(Registry);<br>
> initializePostDominatorTreePass(Registry);<br>
> - initializeProfileEstimatorPassPass(Registry);<br>
> - initializeNoProfileInfoPass(Registry);<br>
> - initializeNoPathProfileInfoPass(Registry);<br>
> - initializeProfileInfoAnalysisGroup(Registry);<br>
> - initializePathProfileInfoAnalysisGroup(Registry);<br>
> - initializeLoaderPassPass(Registry);<br>
> - initializePathProfileLoaderPassPass(Registry);<br>
> - initializeProfileVerifierPassPass(Registry);<br>
> - initializePathProfileVerifierPass(Registry);<br>
> - initializeProfileMetadataLoaderPassPass(Registry);<br>
> initializeRegionInfoPass(Registry);<br>
> initializeRegionViewerPass(Registry);<br>
> initializeRegionPrinterPass(Registry);<br>
><br>
> Modified: llvm/trunk/lib/Analysis/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/CMakeLists.txt (original)<br>
> +++ llvm/trunk/lib/Analysis/CMakeLists.txt Wed Oct 2 10:42:23 2013<br>
> @@ -35,17 +35,7 @@ add_llvm_library(LLVMAnalysis<br>
> ModuleDebugInfoPrinter.cpp<br>
> NoAliasAnalysis.cpp<br>
> PHITransAddr.cpp<br>
> - PathNumbering.cpp<br>
> - PathProfileInfo.cpp<br>
> - PathProfileVerifier.cpp<br>
> PostDominators.cpp<br>
> - ProfileEstimatorPass.cpp<br>
> - ProfileInfo.cpp<br>
> - ProfileInfoLoader.cpp<br>
> - ProfileInfoLoaderPass.cpp<br>
> - ProfileVerifierPass.cpp<br>
> - ProfileDataLoader.cpp<br>
> - ProfileDataLoaderPass.cpp<br>
> PtrUseVisitor.cpp<br>
> RegionInfo.cpp<br>
> RegionPass.cpp<br>
><br>
> Removed: llvm/trunk/lib/Analysis/PathNumbering.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PathNumbering.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PathNumbering.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/PathNumbering.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/PathNumbering.cpp (removed)<br>
> @@ -1,521 +0,0 @@<br>
> -//===- PathNumbering.cpp --------------------------------------*- C++ -*---===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// Ball-Larus path numbers uniquely identify paths through a directed acyclic<br>
> -// graph (DAG) [Ball96]. For a CFG backedges are removed and replaced by phony<br>
> -// edges to obtain a DAG, and thus the unique path numbers [Ball96].<br>
> -//<br>
> -// The purpose of this analysis is to enumerate the edges in a CFG in order<br>
> -// to obtain paths from path numbers in a convenient manner. As described in<br>
> -// [Ball96] edges can be enumerated such that given a path number by following<br>
> -// the CFG and updating the path number, the path is obtained.<br>
> -//<br>
> -// [Ball96]<br>
> -// T. Ball and J. R. Larus. "Efficient Path Profiling."<br>
> -// International Symposium on Microarchitecture, pages 46-57, 1996.<br>
> -// <a href="http://portal.acm.org/citation.cfm?id=243857" target="_blank">http://portal.acm.org/citation.cfm?id=243857</a><br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "ball-larus-numbering"<br>
> -<br>
> -#include "llvm/Analysis/PathNumbering.h"<br>
> -#include "llvm/IR/Constants.h"<br>
> -#include "llvm/IR/DerivedTypes.h"<br>
> -#include "llvm/IR/InstrTypes.h"<br>
> -#include "llvm/IR/Instructions.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/IR/TypeBuilder.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CFG.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Compiler.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <queue><br>
> -#include <sstream><br>
> -#include <stack><br>
> -#include <string><br>
> -#include <utility><br>
> -<br>
> -using namespace llvm;<br>
> -<br>
> -// Are we enabling early termination<br>
> -static cl::opt<bool> ProcessEarlyTermination(<br>
> - "path-profile-early-termination", cl::Hidden,<br>
> - cl::desc("In path profiling, insert extra instrumentation to account for "<br>
> - "unexpected function termination."));<br>
> -<br>
> -// Returns the basic block for the BallLarusNode<br>
> -BasicBlock* BallLarusNode::getBlock() {<br>
> - return(_basicBlock);<br>
> -}<br>
> -<br>
> -// Returns the number of paths to the exit starting at the node.<br>
> -unsigned BallLarusNode::getNumberPaths() {<br>
> - return(_numberPaths);<br>
> -}<br>
> -<br>
> -// Sets the number of paths to the exit starting at the node.<br>
> -void BallLarusNode::setNumberPaths(unsigned numberPaths) {<br>
> - _numberPaths = numberPaths;<br>
> -}<br>
> -<br>
> -// Gets the NodeColor used in graph algorithms.<br>
> -BallLarusNode::NodeColor BallLarusNode::getColor() {<br>
> - return(_color);<br>
> -}<br>
> -<br>
> -// Sets the NodeColor used in graph algorithms.<br>
> -void BallLarusNode::setColor(BallLarusNode::NodeColor color) {<br>
> - _color = color;<br>
> -}<br>
> -<br>
> -// Returns an iterator over predecessor edges. Includes phony and<br>
> -// backedges.<br>
> -BLEdgeIterator BallLarusNode::predBegin() {<br>
> - return(_predEdges.begin());<br>
> -}<br>
> -<br>
> -// Returns the end sentinel for the predecessor iterator.<br>
> -BLEdgeIterator BallLarusNode::predEnd() {<br>
> - return(_predEdges.end());<br>
> -}<br>
> -<br>
> -// Returns the number of predecessor edges. Includes phony and<br>
> -// backedges.<br>
> -unsigned BallLarusNode::getNumberPredEdges() {<br>
> - return(_predEdges.size());<br>
> -}<br>
> -<br>
> -// Returns an iterator over successor edges. Includes phony and<br>
> -// backedges.<br>
> -BLEdgeIterator BallLarusNode::succBegin() {<br>
> - return(_succEdges.begin());<br>
> -}<br>
> -<br>
> -// Returns the end sentinel for the successor iterator.<br>
> -BLEdgeIterator BallLarusNode::succEnd() {<br>
> - return(_succEdges.end());<br>
> -}<br>
> -<br>
> -// Returns the number of successor edges. Includes phony and<br>
> -// backedges.<br>
> -unsigned BallLarusNode::getNumberSuccEdges() {<br>
> - return(_succEdges.size());<br>
> -}<br>
> -<br>
> -// Add an edge to the predecessor list.<br>
> -void BallLarusNode::addPredEdge(BallLarusEdge* edge) {<br>
> - _predEdges.push_back(edge);<br>
> -}<br>
> -<br>
> -// Remove an edge from the predecessor list.<br>
> -void BallLarusNode::removePredEdge(BallLarusEdge* edge) {<br>
> - removeEdge(_predEdges, edge);<br>
> -}<br>
> -<br>
> -// Add an edge to the successor list.<br>
> -void BallLarusNode::addSuccEdge(BallLarusEdge* edge) {<br>
> - _succEdges.push_back(edge);<br>
> -}<br>
> -<br>
> -// Remove an edge from the successor list.<br>
> -void BallLarusNode::removeSuccEdge(BallLarusEdge* edge) {<br>
> - removeEdge(_succEdges, edge);<br>
> -}<br>
> -<br>
> -// Returns the name of the BasicBlock being represented. If BasicBlock<br>
> -// is null then returns "<null>". If BasicBlock has no name, then<br>
> -// "<unnamed>" is returned. Intended for use with debug output.<br>
> -std::string BallLarusNode::getName() {<br>
> - std::stringstream name;<br>
> -<br>
> - if(getBlock() != NULL) {<br>
> - if(getBlock()->hasName()) {<br>
> - std::string tempName(getBlock()->getName());<br>
> - name << tempName.c_str() << " (" << _uid << ")";<br>
> - } else<br>
> - name << "<unnamed> (" << _uid << ")";<br>
> - } else<br>
> - name << "<null> (" << _uid << ")";<br>
> -<br>
> - return name.str();<br>
> -}<br>
> -<br>
> -// Removes an edge from an edgeVector. Used by removePredEdge and<br>
> -// removeSuccEdge.<br>
> -void BallLarusNode::removeEdge(BLEdgeVector& v, BallLarusEdge* e) {<br>
> - // TODO: Avoid linear scan by using a set instead<br>
> - for(BLEdgeIterator i = v.begin(),<br>
> - end = v.end();<br>
> - i != end;<br>
> - ++i) {<br>
> - if((*i) == e) {<br>
> - v.erase(i);<br>
> - break;<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -// Returns the source node of this edge.<br>
> -BallLarusNode* BallLarusEdge::getSource() const {<br>
> - return(_source);<br>
> -}<br>
> -<br>
> -// Returns the target node of this edge.<br>
> -BallLarusNode* BallLarusEdge::getTarget() const {<br>
> - return(_target);<br>
> -}<br>
> -<br>
> -// Sets the type of the edge.<br>
> -BallLarusEdge::EdgeType BallLarusEdge::getType() const {<br>
> - return _edgeType;<br>
> -}<br>
> -<br>
> -// Gets the type of the edge.<br>
> -void BallLarusEdge::setType(EdgeType type) {<br>
> - _edgeType = type;<br>
> -}<br>
> -<br>
> -// Returns the weight of this edge. Used to decode path numbers to sequences<br>
> -// of basic blocks.<br>
> -unsigned BallLarusEdge::getWeight() {<br>
> - return(_weight);<br>
> -}<br>
> -<br>
> -// Sets the weight of the edge. Used during path numbering.<br>
> -void BallLarusEdge::setWeight(unsigned weight) {<br>
> - _weight = weight;<br>
> -}<br>
> -<br>
> -// Gets the phony edge originating at the root.<br>
> -BallLarusEdge* BallLarusEdge::getPhonyRoot() {<br>
> - return _phonyRoot;<br>
> -}<br>
> -<br>
> -// Sets the phony edge originating at the root.<br>
> -void BallLarusEdge::setPhonyRoot(BallLarusEdge* phonyRoot) {<br>
> - _phonyRoot = phonyRoot;<br>
> -}<br>
> -<br>
> -// Gets the phony edge terminating at the exit.<br>
> -BallLarusEdge* BallLarusEdge::getPhonyExit() {<br>
> - return _phonyExit;<br>
> -}<br>
> -<br>
> -// Sets the phony edge terminating at the exit.<br>
> -void BallLarusEdge::setPhonyExit(BallLarusEdge* phonyExit) {<br>
> - _phonyExit = phonyExit;<br>
> -}<br>
> -<br>
> -// Gets the associated real edge if this is a phony edge.<br>
> -BallLarusEdge* BallLarusEdge::getRealEdge() {<br>
> - return _realEdge;<br>
> -}<br>
> -<br>
> -// Sets the associated real edge if this is a phony edge.<br>
> -void BallLarusEdge::setRealEdge(BallLarusEdge* realEdge) {<br>
> - _realEdge = realEdge;<br>
> -}<br>
> -<br>
> -// Returns the duplicate number of the edge.<br>
> -unsigned BallLarusEdge::getDuplicateNumber() {<br>
> - return(_duplicateNumber);<br>
> -}<br>
> -<br>
> -// Initialization that requires virtual functions which are not fully<br>
> -// functional in the constructor.<br>
> -void BallLarusDag::init() {<br>
> - BLBlockNodeMap inDag;<br>
> - std::stack<BallLarusNode*> dfsStack;<br>
> -<br>
> - _root = addNode(&(_function.getEntryBlock()));<br>
> - _exit = addNode(NULL);<br>
> -<br>
> - // start search from root<br>
> - dfsStack.push(getRoot());<br>
> -<br>
> - // dfs to add each bb into the dag<br>
> - while(dfsStack.size())<br>
> - buildNode(inDag, dfsStack);<br>
> -<br>
> - // put in the final edge<br>
> - addEdge(getExit(),getRoot(),0);<br>
> -}<br>
> -<br>
> -// Frees all memory associated with the DAG.<br>
> -BallLarusDag::~BallLarusDag() {<br>
> - for(BLEdgeIterator edge = _edges.begin(), end = _edges.end(); edge != end;<br>
> - ++edge)<br>
> - delete (*edge);<br>
> -<br>
> - for(BLNodeIterator node = _nodes.begin(), end = _nodes.end(); node != end;<br>
> - ++node)<br>
> - delete (*node);<br>
> -}<br>
> -<br>
> -// Calculate the path numbers by assigning edge increments as prescribed<br>
> -// in Ball-Larus path profiling.<br>
> -void BallLarusDag::calculatePathNumbers() {<br>
> - BallLarusNode* node;<br>
> - std::queue<BallLarusNode*> bfsQueue;<br>
> - bfsQueue.push(getExit());<br>
> -<br>
> - while(bfsQueue.size() > 0) {<br>
> - node = bfsQueue.front();<br>
> -<br>
> - DEBUG(dbgs() << "calculatePathNumbers on " << node->getName() << "\n");<br>
> -<br>
> - bfsQueue.pop();<br>
> - unsigned prevPathNumber = node->getNumberPaths();<br>
> - calculatePathNumbersFrom(node);<br>
> -<br>
> - // Check for DAG splitting<br>
> - if( node->getNumberPaths() > 100000000 && node != getRoot() ) {<br>
> - // Add new phony edge from the split-node to the DAG's exit<br>
> - BallLarusEdge* exitEdge = addEdge(node, getExit(), 0);<br>
> - exitEdge->setType(BallLarusEdge::SPLITEDGE_PHONY);<br>
> -<br>
> - // Counters to handle the possibility of a multi-graph<br>
> - BasicBlock* oldTarget = 0;<br>
> - unsigned duplicateNumber = 0;<br>
> -<br>
> - // Iterate through each successor edge, adding phony edges<br>
> - for( BLEdgeIterator succ = node->succBegin(), end = node->succEnd();<br>
> - succ != end; oldTarget = (*succ)->getTarget()->getBlock(), succ++ ) {<br>
> -<br>
> - if( (*succ)->getType() == BallLarusEdge::NORMAL ) {<br>
> - // is this edge a duplicate?<br>
> - if( oldTarget != (*succ)->getTarget()->getBlock() )<br>
> - duplicateNumber = 0;<br>
> -<br>
> - // create the new phony edge: root -> succ<br>
> - BallLarusEdge* rootEdge =<br>
> - addEdge(getRoot(), (*succ)->getTarget(), duplicateNumber++);<br>
> - rootEdge->setType(BallLarusEdge::SPLITEDGE_PHONY);<br>
> - rootEdge->setRealEdge(*succ);<br>
> -<br>
> - // split on this edge and reference it's exit/root phony edges<br>
> - (*succ)->setType(BallLarusEdge::SPLITEDGE);<br>
> - (*succ)->setPhonyRoot(rootEdge);<br>
> - (*succ)->setPhonyExit(exitEdge);<br>
> - (*succ)->setWeight(0);<br>
> - }<br>
> - }<br>
> -<br>
> - calculatePathNumbersFrom(node);<br>
> - }<br>
> -<br>
> - DEBUG(dbgs() << "prev, new number paths " << prevPathNumber << ", "<br>
> - << node->getNumberPaths() << ".\n");<br>
> -<br>
> - if(prevPathNumber == 0 && node->getNumberPaths() != 0) {<br>
> - DEBUG(dbgs() << "node ready : " << node->getName() << "\n");<br>
> - for(BLEdgeIterator pred = node->predBegin(), end = node->predEnd();<br>
> - pred != end; pred++) {<br>
> - if( (*pred)->getType() == BallLarusEdge::BACKEDGE ||<br>
> - (*pred)->getType() == BallLarusEdge::SPLITEDGE )<br>
> - continue;<br>
> -<br>
> - BallLarusNode* nextNode = (*pred)->getSource();<br>
> - // not yet visited?<br>
> - if(nextNode->getNumberPaths() == 0)<br>
> - bfsQueue.push(nextNode);<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - DEBUG(dbgs() << "\tNumber of paths: " << getRoot()->getNumberPaths() << "\n");<br>
> -}<br>
> -<br>
> -// Returns the number of paths for the Dag.<br>
> -unsigned BallLarusDag::getNumberOfPaths() {<br>
> - return(getRoot()->getNumberPaths());<br>
> -}<br>
> -<br>
> -// Returns the root (i.e. entry) node for the DAG.<br>
> -BallLarusNode* BallLarusDag::getRoot() {<br>
> - return _root;<br>
> -}<br>
> -<br>
> -// Returns the exit node for the DAG.<br>
> -BallLarusNode* BallLarusDag::getExit() {<br>
> - return _exit;<br>
> -}<br>
> -<br>
> -// Returns the function for the DAG.<br>
> -Function& BallLarusDag::getFunction() {<br>
> - return(_function);<br>
> -}<br>
> -<br>
> -// Clears the node colors.<br>
> -void BallLarusDag::clearColors(BallLarusNode::NodeColor color) {<br>
> - for (BLNodeIterator nodeIt = _nodes.begin(); nodeIt != _nodes.end(); nodeIt++)<br>
> - (*nodeIt)->setColor(color);<br>
> -}<br>
> -<br>
> -// Processes one node and its imediate edges for building the DAG.<br>
> -void BallLarusDag::buildNode(BLBlockNodeMap& inDag, BLNodeStack& dfsStack) {<br>
> - BallLarusNode* currentNode = dfsStack.top();<br>
> - BasicBlock* currentBlock = currentNode->getBlock();<br>
> -<br>
> - if(currentNode->getColor() != BallLarusNode::WHITE) {<br>
> - // we have already visited this node<br>
> - dfsStack.pop();<br>
> - currentNode->setColor(BallLarusNode::BLACK);<br>
> - } else {<br>
> - // are there any external procedure calls?<br>
> - if( ProcessEarlyTermination ) {<br>
> - for( BasicBlock::iterator bbCurrent = currentNode->getBlock()->begin(),<br>
> - bbEnd = currentNode->getBlock()->end(); bbCurrent != bbEnd;<br>
> - bbCurrent++ ) {<br>
> - Instruction& instr = *bbCurrent;<br>
> - if( instr.getOpcode() == Instruction::Call ) {<br>
> - BallLarusEdge* callEdge = addEdge(currentNode, getExit(), 0);<br>
> - callEdge->setType(BallLarusEdge::CALLEDGE_PHONY);<br>
> - break;<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - TerminatorInst* terminator = currentNode->getBlock()->getTerminator();<br>
> - if(isa<ReturnInst>(terminator) || isa<UnreachableInst>(terminator) ||<br>
> - isa<ResumeInst>(terminator))<br>
> - addEdge(currentNode, getExit(),0);<br>
> -<br>
> - currentNode->setColor(BallLarusNode::GRAY);<br>
> - inDag[currentBlock] = currentNode;<br>
> -<br>
> - BasicBlock* oldSuccessor = 0;<br>
> - unsigned duplicateNumber = 0;<br>
> -<br>
> - // iterate through this node's successors<br>
> - for(succ_iterator successor = succ_begin(currentBlock),<br>
> - succEnd = succ_end(currentBlock); successor != succEnd;<br>
> - oldSuccessor = *successor, ++successor ) {<br>
> - BasicBlock* succBB = *successor;<br>
> -<br>
> - // is this edge a duplicate?<br>
> - if (oldSuccessor == succBB)<br>
> - duplicateNumber++;<br>
> - else<br>
> - duplicateNumber = 0;<br>
> -<br>
> - buildEdge(inDag, dfsStack, currentNode, succBB, duplicateNumber);<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -// Process an edge in the CFG for DAG building.<br>
> -void BallLarusDag::buildEdge(BLBlockNodeMap& inDag, std::stack<BallLarusNode*>&<br>
> - dfsStack, BallLarusNode* currentNode,<br>
> - BasicBlock* succBB, unsigned duplicateCount) {<br>
> - BallLarusNode* succNode = inDag[succBB];<br>
> -<br>
> - if(succNode && succNode->getColor() == BallLarusNode::BLACK) {<br>
> - // visited node and forward edge<br>
> - addEdge(currentNode, succNode, duplicateCount);<br>
> - } else if(succNode && succNode->getColor() == BallLarusNode::GRAY) {<br>
> - // visited node and back edge<br>
> - DEBUG(dbgs() << "Backedge detected.\n");<br>
> - addBackedge(currentNode, succNode, duplicateCount);<br>
> - } else {<br>
> - BallLarusNode* childNode;<br>
> - // not visited node and forward edge<br>
> - if(succNode) // an unvisited node that is child of a gray node<br>
> - childNode = succNode;<br>
> - else { // an unvisited node that is a child of a an unvisted node<br>
> - childNode = addNode(succBB);<br>
> - inDag[succBB] = childNode;<br>
> - }<br>
> - addEdge(currentNode, childNode, duplicateCount);<br>
> - dfsStack.push(childNode);<br>
> - }<br>
> -}<br>
> -<br>
> -// The weight on each edge is the increment required along any path that<br>
> -// contains that edge.<br>
> -void BallLarusDag::calculatePathNumbersFrom(BallLarusNode* node) {<br>
> - if(node == getExit())<br>
> - // The Exit node must be base case<br>
> - node->setNumberPaths(1);<br>
> - else {<br>
> - unsigned sumPaths = 0;<br>
> - BallLarusNode* succNode;<br>
> -<br>
> - for(BLEdgeIterator succ = node->succBegin(), end = node->succEnd();<br>
> - succ != end; succ++) {<br>
> - if( (*succ)->getType() == BallLarusEdge::BACKEDGE ||<br>
> - (*succ)->getType() == BallLarusEdge::SPLITEDGE )<br>
> - continue;<br>
> -<br>
> - (*succ)->setWeight(sumPaths);<br>
> - succNode = (*succ)->getTarget();<br>
> -<br>
> - if( !succNode->getNumberPaths() )<br>
> - return;<br>
> - sumPaths += succNode->getNumberPaths();<br>
> - }<br>
> -<br>
> - node->setNumberPaths(sumPaths);<br>
> - }<br>
> -}<br>
> -<br>
> -// Allows subclasses to determine which type of Node is created.<br>
> -// Override this method to produce subclasses of BallLarusNode if<br>
> -// necessary. The destructor of BallLarusDag will call free on each<br>
> -// pointer created.<br>
> -BallLarusNode* BallLarusDag::createNode(BasicBlock* BB) {<br>
> - return( new BallLarusNode(BB) );<br>
> -}<br>
> -<br>
> -// Allows subclasses to determine which type of Edge is created.<br>
> -// Override this method to produce subclasses of BallLarusEdge if<br>
> -// necessary. The destructor of BallLarusDag will call free on each<br>
> -// pointer created.<br>
> -BallLarusEdge* BallLarusDag::createEdge(BallLarusNode* source,<br>
> - BallLarusNode* target,<br>
> - unsigned duplicateCount) {<br>
> - return( new BallLarusEdge(source, target, duplicateCount) );<br>
> -}<br>
> -<br>
> -// Proxy to node's constructor. Updates the DAG state.<br>
> -BallLarusNode* BallLarusDag::addNode(BasicBlock* BB) {<br>
> - BallLarusNode* newNode = createNode(BB);<br>
> - _nodes.push_back(newNode);<br>
> - return( newNode );<br>
> -}<br>
> -<br>
> -// Proxy to edge's constructor. Updates the DAG state.<br>
> -BallLarusEdge* BallLarusDag::addEdge(BallLarusNode* source,<br>
> - BallLarusNode* target,<br>
> - unsigned duplicateCount) {<br>
> - BallLarusEdge* newEdge = createEdge(source, target, duplicateCount);<br>
> - _edges.push_back(newEdge);<br>
> - source->addSuccEdge(newEdge);<br>
> - target->addPredEdge(newEdge);<br>
> - return(newEdge);<br>
> -}<br>
> -<br>
> -// Adds a backedge with its phony edges. Updates the DAG state.<br>
> -void BallLarusDag::addBackedge(BallLarusNode* source, BallLarusNode* target,<br>
> - unsigned duplicateCount) {<br>
> - BallLarusEdge* childEdge = addEdge(source, target, duplicateCount);<br>
> - childEdge->setType(BallLarusEdge::BACKEDGE);<br>
> -<br>
> - childEdge->setPhonyRoot(addEdge(getRoot(), target,0));<br>
> - childEdge->setPhonyExit(addEdge(source, getExit(),0));<br>
> -<br>
> - childEdge->getPhonyRoot()->setRealEdge(childEdge);<br>
> - childEdge->getPhonyRoot()->setType(BallLarusEdge::BACKEDGE_PHONY);<br>
> -<br>
> - childEdge->getPhonyExit()->setRealEdge(childEdge);<br>
> - childEdge->getPhonyExit()->setType(BallLarusEdge::BACKEDGE_PHONY);<br>
> - _backEdges.push_back(childEdge);<br>
> -}<br>
><br>
> Removed: llvm/trunk/lib/Analysis/PathProfileInfo.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PathProfileInfo.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PathProfileInfo.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/PathProfileInfo.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/PathProfileInfo.cpp (removed)<br>
> @@ -1,433 +0,0 @@<br>
> -//===- PathProfileInfo.cpp ------------------------------------*- C++ -*---===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file defines the interface used by optimizers to load path profiles,<br>
> -// and provides a loader pass which reads a path profile file.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "path-profile-info"<br>
> -<br>
> -#include "llvm/Analysis/PathProfileInfo.h"<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/Analysis/ProfileInfoTypes.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <cstdio><br>
> -<br>
> -using namespace llvm;<br>
> -<br>
> -// command line option for loading path profiles<br>
> -static cl::opt<std::string><br>
> -PathProfileInfoFilename("path-profile-loader-file", cl::init("llvmprof.out"),<br>
> - cl::value_desc("filename"),<br>
> - cl::desc("Path profile file loaded by -path-profile-loader"), cl::Hidden);<br>
> -<br>
> -namespace {<br>
> - class PathProfileLoaderPass : public ModulePass, public PathProfileInfo {<br>
> - public:<br>
> - PathProfileLoaderPass() : ModulePass(ID) { }<br>
> - ~PathProfileLoaderPass();<br>
> -<br>
> - // this pass doesn't change anything (only loads information)<br>
> - virtual void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> - AU.setPreservesAll();<br>
> - }<br>
> -<br>
> - // the full name of the loader pass<br>
> - virtual const char* getPassName() const {<br>
> - return "Path Profiling Information Loader";<br>
> - }<br>
> -<br>
> - // required since this pass implements multiple inheritance<br>
> - virtual void *getAdjustedAnalysisPointer(AnalysisID PI) {<br>
> - if (PI == &PathProfileInfo::ID)<br>
> - return (PathProfileInfo*)this;<br>
> - return this;<br>
> - }<br>
> -<br>
> - // entry point to run the pass<br>
> - bool runOnModule(Module &M);<br>
> -<br>
> - // pass identification<br>
> - static char ID;<br>
> -<br>
> - private:<br>
> - // make a reference table to refer to function by number<br>
> - void buildFunctionRefs(Module &M);<br>
> -<br>
> - // process argument info of a program from the input file<br>
> - void handleArgumentInfo();<br>
> -<br>
> - // process path number information from the input file<br>
> - void handlePathInfo();<br>
> -<br>
> - // array of references to the functions in the module<br>
> - std::vector<Function*> _functions;<br>
> -<br>
> - // path profile file handle<br>
> - FILE* _file;<br>
> -<br>
> - // path profile file name<br>
> - std::string _filename;<br>
> - };<br>
> -}<br>
> -<br>
> -// register PathLoader<br>
> -char PathProfileLoaderPass::ID = 0;<br>
> -<br>
> -INITIALIZE_ANALYSIS_GROUP(PathProfileInfo, "Path Profile Information",<br>
> - NoPathProfileInfo)<br>
> -INITIALIZE_AG_PASS(PathProfileLoaderPass, PathProfileInfo,<br>
> - "path-profile-loader",<br>
> - "Load path profile information from file",<br>
> - false, true, false)<br>
> -<br>
> -char &llvm::PathProfileLoaderPassID = PathProfileLoaderPass::ID;<br>
> -<br>
> -// link PathLoader as a pass, and make it available as an optimisation<br>
> -ModulePass *llvm::createPathProfileLoaderPass() {<br>
> - return new PathProfileLoaderPass;<br>
> -}<br>
> -<br>
> -// ----------------------------------------------------------------------------<br>
> -// PathEdge implementation<br>
> -//<br>
> -ProfilePathEdge::ProfilePathEdge (BasicBlock* source, BasicBlock* target,<br>
> - unsigned duplicateNumber)<br>
> - : _source(source), _target(target), _duplicateNumber(duplicateNumber) {}<br>
> -<br>
> -// ----------------------------------------------------------------------------<br>
> -// Path implementation<br>
> -//<br>
> -<br>
> -ProfilePath::ProfilePath (unsigned int number, unsigned int count,<br>
> - double countStdDev, PathProfileInfo* ppi)<br>
> - : _number(number) , _count(count), _countStdDev(countStdDev), _ppi(ppi) {}<br>
> -<br>
> -double ProfilePath::getFrequency() const {<br>
> - return 100 * double(_count) /<br>
> - double(_ppi->_functionPathCounts[_ppi->_currentFunction]);<br>
> -}<br>
> -<br>
> -static BallLarusEdge* getNextEdge (BallLarusNode* node,<br>
> - unsigned int pathNumber) {<br>
> - BallLarusEdge* best = 0;<br>
> -<br>
> - for( BLEdgeIterator next = node->succBegin(),<br>
> - end = node->succEnd(); next != end; next++ ) {<br>
> - if( (*next)->getType() != BallLarusEdge::BACKEDGE && // no backedges<br>
> - (*next)->getType() != BallLarusEdge::SPLITEDGE && // no split edges<br>
> - (*next)->getWeight() <= pathNumber && // weight must be <= pathNumber<br>
> - (!best || (best->getWeight() < (*next)->getWeight())) ) // best one?<br>
> - best = *next;<br>
> - }<br>
> -<br>
> - return best;<br>
> -}<br>
> -<br>
> -ProfilePathEdgeVector* ProfilePath::getPathEdges() const {<br>
> - BallLarusNode* currentNode = _ppi->_currentDag->getRoot ();<br>
> - unsigned int increment = _number;<br>
> - ProfilePathEdgeVector* pev = new ProfilePathEdgeVector;<br>
> -<br>
> - while (currentNode != _ppi->_currentDag->getExit()) {<br>
> - BallLarusEdge* next = getNextEdge(currentNode, increment);<br>
> -<br>
> - increment -= next->getWeight();<br>
> -<br>
> - if( next->getType() != BallLarusEdge::BACKEDGE_PHONY &&<br>
> - next->getType() != BallLarusEdge::SPLITEDGE_PHONY &&<br>
> - next->getTarget() != _ppi->_currentDag->getExit() )<br>
> - pev->push_back(ProfilePathEdge(<br>
> - next->getSource()->getBlock(),<br>
> - next->getTarget()->getBlock(),<br>
> - next->getDuplicateNumber()));<br>
> -<br>
> - if( next->getType() == BallLarusEdge::BACKEDGE_PHONY &&<br>
> - next->getTarget() == _ppi->_currentDag->getExit() )<br>
> - pev->push_back(ProfilePathEdge(<br>
> - next->getRealEdge()->getSource()->getBlock(),<br>
> - next->getRealEdge()->getTarget()->getBlock(),<br>
> - next->getDuplicateNumber()));<br>
> -<br>
> - if( next->getType() == BallLarusEdge::SPLITEDGE_PHONY &&<br>
> - next->getSource() == _ppi->_currentDag->getRoot() )<br>
> - pev->push_back(ProfilePathEdge(<br>
> - next->getRealEdge()->getSource()->getBlock(),<br>
> - next->getRealEdge()->getTarget()->getBlock(),<br>
> - next->getDuplicateNumber()));<br>
> -<br>
> - // set the new node<br>
> - currentNode = next->getTarget();<br>
> - }<br>
> -<br>
> - return pev;<br>
> -}<br>
> -<br>
> -ProfilePathBlockVector* ProfilePath::getPathBlocks() const {<br>
> - BallLarusNode* currentNode = _ppi->_currentDag->getRoot ();<br>
> - unsigned int increment = _number;<br>
> - ProfilePathBlockVector* pbv = new ProfilePathBlockVector;<br>
> -<br>
> - while (currentNode != _ppi->_currentDag->getExit()) {<br>
> - BallLarusEdge* next = getNextEdge(currentNode, increment);<br>
> - increment -= next->getWeight();<br>
> -<br>
> - // add block to the block list if it is a real edge<br>
> - if( next->getType() == BallLarusEdge::NORMAL)<br>
> - pbv->push_back (currentNode->getBlock());<br>
> - // make the back edge the last edge since we are at the end<br>
> - else if( next->getTarget() == _ppi->_currentDag->getExit() ) {<br>
> - pbv->push_back (currentNode->getBlock());<br>
> - pbv->push_back (next->getRealEdge()->getTarget()->getBlock());<br>
> - }<br>
> -<br>
> - // set the new node<br>
> - currentNode = next->getTarget();<br>
> - }<br>
> -<br>
> - return pbv;<br>
> -}<br>
> -<br>
> -BasicBlock* ProfilePath::getFirstBlockInPath() const {<br>
> - BallLarusNode* root = _ppi->_currentDag->getRoot();<br>
> - BallLarusEdge* edge = getNextEdge(root, _number);<br>
> -<br>
> - if( edge && (edge->getType() == BallLarusEdge::BACKEDGE_PHONY ||<br>
> - edge->getType() == BallLarusEdge::SPLITEDGE_PHONY) )<br>
> - return edge->getTarget()->getBlock();<br>
> -<br>
> - return root->getBlock();<br>
> -}<br>
> -<br>
> -// ----------------------------------------------------------------------------<br>
> -// PathProfileInfo implementation<br>
> -//<br>
> -<br>
> -// Pass identification<br>
> -char llvm::PathProfileInfo::ID = 0;<br>
> -<br>
> -PathProfileInfo::PathProfileInfo () : _currentDag(0) , _currentFunction(0) {<br>
> -}<br>
> -<br>
> -PathProfileInfo::~PathProfileInfo() {<br>
> - if (_currentDag)<br>
> - delete _currentDag;<br>
> -}<br>
> -<br>
> -// set the function for which paths are currently begin processed<br>
> -void PathProfileInfo::setCurrentFunction(Function* F) {<br>
> - // Make sure it exists<br>
> - if (!F) return;<br>
> -<br>
> - if (_currentDag)<br>
> - delete _currentDag;<br>
> -<br>
> - _currentFunction = F;<br>
> - _currentDag = new BallLarusDag(*F);<br>
> - _currentDag->init();<br>
> - _currentDag->calculatePathNumbers();<br>
> -}<br>
> -<br>
> -// get the function for which paths are currently being processed<br>
> -Function* PathProfileInfo::getCurrentFunction() const {<br>
> - return _currentFunction;<br>
> -}<br>
> -<br>
> -// get the entry block of the function<br>
> -BasicBlock* PathProfileInfo::getCurrentFunctionEntry() {<br>
> - return _currentDag->getRoot()->getBlock();<br>
> -}<br>
> -<br>
> -// return the path based on its number<br>
> -ProfilePath* PathProfileInfo::getPath(unsigned int number) {<br>
> - return _functionPaths[_currentFunction][number];<br>
> -}<br>
> -<br>
> -// return the number of paths which a function may potentially execute<br>
> -unsigned int PathProfileInfo::getPotentialPathCount() {<br>
> - return _currentDag ? _currentDag->getNumberOfPaths() : 0;<br>
> -}<br>
> -<br>
> -// return an iterator for the beginning of a functions executed paths<br>
> -ProfilePathIterator PathProfileInfo::pathBegin() {<br>
> - return _functionPaths[_currentFunction].begin();<br>
> -}<br>
> -<br>
> -// return an iterator for the end of a functions executed paths<br>
> -ProfilePathIterator PathProfileInfo::pathEnd() {<br>
> - return _functionPaths[_currentFunction].end();<br>
> -}<br>
> -<br>
> -// returns the total number of paths run in the function<br>
> -unsigned int PathProfileInfo::pathsRun() {<br>
> - return _currentFunction ? _functionPaths[_currentFunction].size() : 0;<br>
> -}<br>
> -<br>
> -// ----------------------------------------------------------------------------<br>
> -// PathLoader implementation<br>
> -//<br>
> -<br>
> -// remove all generated paths<br>
> -PathProfileLoaderPass::~PathProfileLoaderPass() {<br>
> - for( FunctionPathIterator funcNext = _functionPaths.begin(),<br>
> - funcEnd = _functionPaths.end(); funcNext != funcEnd; funcNext++)<br>
> - for( ProfilePathIterator pathNext = funcNext->second.begin(),<br>
> - pathEnd = funcNext->second.end(); pathNext != pathEnd; pathNext++)<br>
> - delete pathNext->second;<br>
> -}<br>
> -<br>
> -// entry point of the pass; this loads and parses a file<br>
> -bool PathProfileLoaderPass::runOnModule(Module &M) {<br>
> - // get the filename and setup the module's function references<br>
> - _filename = PathProfileInfoFilename;<br>
> - buildFunctionRefs (M);<br>
> -<br>
> - if (!(_file = fopen(_filename.c_str(), "rb"))) {<br>
> - errs () << "error: input '" << _filename << "' file does not exist.\n";<br>
> - return false;<br>
> - }<br>
> -<br>
> - ProfilingType profType;<br>
> -<br>
> - while( fread(&profType, sizeof(ProfilingType), 1, _file) ) {<br>
> - switch (profType) {<br>
> - case ArgumentInfo:<br>
> - handleArgumentInfo ();<br>
> - break;<br>
> - case PathInfo:<br>
> - handlePathInfo ();<br>
> - break;<br>
> - default:<br>
> - errs () << "error: bad path profiling file syntax, " << profType << "\n";<br>
> - fclose (_file);<br>
> - return false;<br>
> - }<br>
> - }<br>
> -<br>
> - fclose (_file);<br>
> -<br>
> - return true;<br>
> -}<br>
> -<br>
> -// create a reference table for functions defined in the path profile file<br>
> -void PathProfileLoaderPass::buildFunctionRefs (Module &M) {<br>
> - _functions.push_back(0); // make the 0 index a null pointer<br>
> -<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; F++) {<br>
> - if (F->isDeclaration())<br>
> - continue;<br>
> - _functions.push_back(F);<br>
> - }<br>
> -}<br>
> -<br>
> -// handle command like argument infor in the output file<br>
> -void PathProfileLoaderPass::handleArgumentInfo() {<br>
> - // get the argument list's length<br>
> - unsigned savedArgsLength;<br>
> - if( fread(&savedArgsLength, sizeof(unsigned), 1, _file) != 1 ) {<br>
> - errs() << "warning: argument info header/data mismatch\n";<br>
> - return;<br>
> - }<br>
> -<br>
> - // allocate a buffer, and get the arguments<br>
> - char* args = new char[savedArgsLength+1];<br>
> - if( fread(args, 1, savedArgsLength, _file) != savedArgsLength )<br>
> - errs() << "warning: argument info header/data mismatch\n";<br>
> -<br>
> - args[savedArgsLength] = '\0';<br>
> - argList = std::string(args);<br>
> - delete [] args; // cleanup dynamic string<br>
> -<br>
> - // byte alignment<br>
> - if (savedArgsLength & 3)<br>
> - fseek(_file, 4-(savedArgsLength&3), SEEK_CUR);<br>
> -}<br>
> -<br>
> -// Handle path profile information in the output file<br>
> -void PathProfileLoaderPass::handlePathInfo () {<br>
> - // get the number of functions in this profile<br>
> - unsigned functionCount;<br>
> - if( fread(&functionCount, sizeof(functionCount), 1, _file) != 1 ) {<br>
> - errs() << "warning: path info header/data mismatch\n";<br>
> - return;<br>
> - }<br>
> -<br>
> - // gather path information for each function<br>
> - for (unsigned i = 0; i < functionCount; i++) {<br>
> - PathProfileHeader pathHeader;<br>
> - if( fread(&pathHeader, sizeof(pathHeader), 1, _file) != 1 ) {<br>
> - errs() << "warning: bad header for path function info\n";<br>
> - break;<br>
> - }<br>
> -<br>
> - Function* f = _functions[pathHeader.fnNumber];<br>
> -<br>
> - // dynamically allocate a table to store path numbers<br>
> - PathProfileTableEntry* pathTable =<br>
> - new PathProfileTableEntry[pathHeader.numEntries];<br>
> -<br>
> - if( fread(pathTable, sizeof(PathProfileTableEntry),<br>
> - pathHeader.numEntries, _file) != pathHeader.numEntries) {<br>
> - delete [] pathTable;<br>
> - errs() << "warning: path function info header/data mismatch\n";<br>
> - return;<br>
> - }<br>
> -<br>
> - // Build a new path for the current function<br>
> - unsigned int totalPaths = 0;<br>
> - for (unsigned int j = 0; j < pathHeader.numEntries; j++) {<br>
> - totalPaths += pathTable[j].pathCounter;<br>
> - _functionPaths[f][pathTable[j].pathNumber]<br>
> - = new ProfilePath(pathTable[j].pathNumber, pathTable[j].pathCounter,<br>
> - 0, this);<br>
> - }<br>
> -<br>
> - _functionPathCounts[f] = totalPaths;<br>
> -<br>
> - delete [] pathTable;<br>
> - }<br>
> -}<br>
> -<br>
> -//===----------------------------------------------------------------------===//<br>
> -// NoProfile PathProfileInfo implementation<br>
> -//<br>
> -<br>
> -namespace {<br>
> - struct NoPathProfileInfo : public ImmutablePass, public PathProfileInfo {<br>
> - static char ID; // Class identification, replacement for typeinfo<br>
> - NoPathProfileInfo() : ImmutablePass(ID) {<br>
> - initializeNoPathProfileInfoPass(*PassRegistry::getPassRegistry());<br>
> - }<br>
> -<br>
> - /// getAdjustedAnalysisPointer - This method is used when a pass implements<br>
> - /// an analysis interface through multiple inheritance. If needed, it<br>
> - /// should override this to adjust the this pointer as needed for the<br>
> - /// specified pass info.<br>
> - virtual void *getAdjustedAnalysisPointer(AnalysisID PI) {<br>
> - if (PI == &PathProfileInfo::ID)<br>
> - return (PathProfileInfo*)this;<br>
> - return this;<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "NoPathProfileInfo";<br>
> - }<br>
> - };<br>
> -} // End of anonymous namespace<br>
> -<br>
> -char NoPathProfileInfo::ID = 0;<br>
> -// Register this pass...<br>
> -INITIALIZE_AG_PASS(NoPathProfileInfo, PathProfileInfo, "no-path-profile",<br>
> - "No Path Profile Information", false, true, true)<br>
> -<br>
> -ImmutablePass *llvm::createNoPathProfileInfoPass() { return new NoPathProfileInfo(); }<br>
><br>
> Removed: llvm/trunk/lib/Analysis/PathProfileVerifier.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PathProfileVerifier.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PathProfileVerifier.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/PathProfileVerifier.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/PathProfileVerifier.cpp (removed)<br>
> @@ -1,205 +0,0 @@<br>
> -//===- PathProfileVerifier.cpp --------------------------------*- C++ -*---===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This verifier derives an edge profile file from current path profile<br>
> -// information<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "path-profile-verifier"<br>
> -<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/Analysis/PathProfileInfo.h"<br>
> -#include "llvm/Analysis/ProfileInfoTypes.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <stdio.h><br>
> -<br>
> -using namespace llvm;<br>
> -<br>
> -namespace {<br>
> - class PathProfileVerifier : public ModulePass {<br>
> - private:<br>
> - bool runOnModule(Module &M);<br>
> -<br>
> - public:<br>
> - static char ID; // Pass identification, replacement for typeid<br>
> - PathProfileVerifier() : ModulePass(ID) {<br>
> - initializePathProfileVerifierPass(*PassRegistry::getPassRegistry());<br>
> - }<br>
> -<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "Path Profiler Verifier";<br>
> - }<br>
> -<br>
> - // The verifier requires the path profile and edge profile.<br>
> - virtual void getAnalysisUsage(AnalysisUsage& AU) const;<br>
> - };<br>
> -}<br>
> -<br>
> -static cl::opt<std::string><br>
> -EdgeProfileFilename("path-profile-verifier-file",<br>
> - cl::init("edgefrompath.llvmprof.out"),<br>
> - cl::value_desc("filename"),<br>
> - cl::desc("Edge profile file generated by -path-profile-verifier"),<br>
> - cl::Hidden);<br>
> -<br>
> -char PathProfileVerifier::ID = 0;<br>
> -INITIALIZE_PASS(PathProfileVerifier, "path-profile-verifier",<br>
> - "Compare the path profile derived edge profile against the "<br>
> - "edge profile.", true, true)<br>
> -<br>
> -ModulePass *llvm::createPathProfileVerifierPass() {<br>
> - return new PathProfileVerifier();<br>
> -}<br>
> -<br>
> -// The verifier requires the path profile and edge profile.<br>
> -void PathProfileVerifier::getAnalysisUsage(AnalysisUsage& AU) const {<br>
> - AU.addRequired<PathProfileInfo>();<br>
> - AU.addPreserved<PathProfileInfo>();<br>
> -}<br>
> -<br>
> -typedef std::map<unsigned, unsigned> DuplicateToIndexMap;<br>
> -typedef std::map<BasicBlock*,DuplicateToIndexMap> BlockToDuplicateMap;<br>
> -typedef std::map<BasicBlock*,BlockToDuplicateMap> NestedBlockToIndexMap;<br>
> -<br>
> -// the verifier iterates through each path to gather the total<br>
> -// number of edge frequencies<br>
> -bool PathProfileVerifier::runOnModule (Module &M) {<br>
> - PathProfileInfo& pathProfileInfo = getAnalysis<PathProfileInfo>();<br>
> -<br>
> - // setup a data structure to map path edges which index an<br>
> - // array of edge counters<br>
> - NestedBlockToIndexMap arrayMap;<br>
> - unsigned i = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> -<br>
> - arrayMap[(BasicBlock*)0][F->begin()][0] = i++;<br>
> -<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - TerminatorInst *TI = BB->getTerminator();<br>
> -<br>
> - unsigned duplicate = 0;<br>
> - BasicBlock* prev = 0;<br>
> - for (unsigned s = 0, e = TI->getNumSuccessors(); s != e;<br>
> - prev = TI->getSuccessor(s), ++s) {<br>
> - if (prev == TI->getSuccessor(s))<br>
> - duplicate++;<br>
> - else duplicate = 0;<br>
> -<br>
> - arrayMap[BB][TI->getSuccessor(s)][duplicate] = i++;<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - std::vector<unsigned> edgeArray(i);<br>
> -<br>
> - // iterate through each path and increment the edge counters as needed<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> -<br>
> - pathProfileInfo.setCurrentFunction(F);<br>
> -<br>
> - DEBUG(dbgs() << "function '" << F->getName() << "' ran "<br>
> - << pathProfileInfo.pathsRun()<br>
> - << "/" << pathProfileInfo.getPotentialPathCount()<br>
> - << " potential paths\n");<br>
> -<br>
> - for( ProfilePathIterator nextPath = pathProfileInfo.pathBegin(),<br>
> - endPath = pathProfileInfo.pathEnd();<br>
> - nextPath != endPath; nextPath++ ) {<br>
> - ProfilePath* currentPath = nextPath->second;<br>
> -<br>
> - ProfilePathEdgeVector* pev = currentPath->getPathEdges();<br>
> - DEBUG(dbgs () << "path #" << currentPath->getNumber() << ": "<br>
> - << currentPath->getCount() << "\n");<br>
> - // setup the entry edge (normally path profiling doesn't care about this)<br>
> - if (currentPath->getFirstBlockInPath() == &F->getEntryBlock())<br>
> - edgeArray[arrayMap[(BasicBlock*)0][currentPath->getFirstBlockInPath()][0]]<br>
> - += currentPath->getCount();<br>
> -<br>
> - for( ProfilePathEdgeIterator nextEdge = pev->begin(),<br>
> - endEdge = pev->end(); nextEdge != endEdge; nextEdge++ ) {<br>
> - if (nextEdge != pev->begin())<br>
> - DEBUG(dbgs() << " :: ");<br>
> -<br>
> - BasicBlock* source = nextEdge->getSource();<br>
> - BasicBlock* target = nextEdge->getTarget();<br>
> - unsigned duplicateNumber = nextEdge->getDuplicateNumber();<br>
> - DEBUG(dbgs() << source->getName() << " --{" << duplicateNumber<br>
> - << "}--> " << target->getName());<br>
> -<br>
> - // Ensure all the referenced edges exist<br>
> - // TODO: make this a separate function<br>
> - if( !arrayMap.count(source) ) {<br>
> - errs() << " error [" << F->getName() << "()]: source '"<br>
> - << source->getName()<br>
> - << "' does not exist in the array map.\n";<br>
> - } else if( !arrayMap[source].count(target) ) {<br>
> - errs() << " error [" << F->getName() << "()]: target '"<br>
> - << target->getName()<br>
> - << "' does not exist in the array map.\n";<br>
> - } else if( !arrayMap[source][target].count(duplicateNumber) ) {<br>
> - errs() << " error [" << F->getName() << "()]: edge "<br>
> - << source->getName() << " -> " << target->getName()<br>
> - << " duplicate number " << duplicateNumber<br>
> - << " does not exist in the array map.\n";<br>
> - } else {<br>
> - edgeArray[arrayMap[source][target][duplicateNumber]]<br>
> - += currentPath->getCount();<br>
> - }<br>
> - }<br>
> -<br>
> - DEBUG(errs() << "\n");<br>
> -<br>
> - delete pev;<br>
> - }<br>
> - }<br>
> -<br>
> - std::string filename = EdgeProfileFilename;<br>
> -<br>
> - // Open a handle to the file<br>
> - FILE* edgeFile = fopen(filename.c_str(),"wb");<br>
> -<br>
> - if (!edgeFile) {<br>
> - errs() << "error: unable to open file '" << filename << "' for output.\n";<br>
> - return false;<br>
> - }<br>
> -<br>
> - errs() << "Generating edge profile '" << filename << "' ...\n";<br>
> -<br>
> - // write argument info<br>
> - unsigned type = ArgumentInfo;<br>
> - unsigned num = pathProfileInfo.argList.size();<br>
> - int zeros = 0;<br>
> -<br>
> - fwrite(&type,sizeof(unsigned),1,edgeFile);<br>
> - fwrite(&num,sizeof(unsigned),1,edgeFile);<br>
> - fwrite(pathProfileInfo.argList.c_str(),1,num,edgeFile);<br>
> - if (num&3)<br>
> - fwrite(&zeros, 1, 4-(num&3), edgeFile);<br>
> -<br>
> - type = EdgeInfo;<br>
> - num = edgeArray.size();<br>
> - fwrite(&type,sizeof(unsigned),1,edgeFile);<br>
> - fwrite(&num,sizeof(unsigned),1,edgeFile);<br>
> -<br>
> - // write each edge to the file<br>
> - for( std::vector<unsigned>::iterator s = edgeArray.begin(),<br>
> - e = edgeArray.end(); s != e; s++)<br>
> - fwrite(&*s, sizeof (unsigned), 1, edgeFile);<br>
> -<br>
> - fclose (edgeFile);<br>
> -<br>
> - return true;<br>
> -}<br>
><br>
> Removed: llvm/trunk/lib/Analysis/ProfileDataLoader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileDataLoader.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileDataLoader.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/ProfileDataLoader.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ProfileDataLoader.cpp (removed)<br>
> @@ -1,155 +0,0 @@<br>
> -//===- ProfileDataLoader.cpp - Load profile information from disk ---------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// The ProfileDataLoader class is used to load raw profiling data from the dump<br>
> -// file.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "llvm/Analysis/ProfileDataLoader.h"<br>
> -#include "llvm/ADT/ArrayRef.h"<br>
> -#include "llvm/ADT/OwningPtr.h"<br>
> -#include "llvm/Analysis/ProfileDataTypes.h"<br>
> -#include "llvm/IR/InstrTypes.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include "llvm/Support/system_error.h"<br>
> -#include <cstdio><br>
> -#include <cstdlib><br>
> -using namespace llvm;<br>
> -<br>
> -raw_ostream &llvm::operator<<(raw_ostream &O, std::pair<const BasicBlock *,<br>
> - const BasicBlock *> E) {<br>
> - O << "(";<br>
> -<br>
> - if (E.first)<br>
> - O << E.first->getName();<br>
> - else<br>
> - O << "0";<br>
> -<br>
> - O << ",";<br>
> -<br>
> - if (E.second)<br>
> - O << E.second->getName();<br>
> - else<br>
> - O << "0";<br>
> -<br>
> - return O << ")";<br>
> -}<br>
> -<br>
> -/// AddCounts - Add 'A' and 'B', accounting for the fact that the value of one<br>
> -/// (or both) may not be defined.<br>
> -static unsigned AddCounts(unsigned A, unsigned B) {<br>
> - // If either value is undefined, use the other.<br>
> - // Undefined + undefined = undefined.<br>
> - if (A == ProfileDataLoader::Uncounted) return B;<br>
> - if (B == ProfileDataLoader::Uncounted) return A;<br>
> -<br>
> - return A + B;<br>
> -}<br>
> -<br>
> -/// ReadProfilingData - Load 'NumEntries' items of type 'T' from file 'F'<br>
> -template <typename T><br>
> -static void ReadProfilingData(const char *ToolName, FILE *F,<br>
> - T *Data, size_t NumEntries) {<br>
> - // Read in the block of data...<br>
> - if (fread(Data, sizeof(T), NumEntries, F) != NumEntries)<br>
> - report_fatal_error(Twine(ToolName) + ": Profiling data truncated");<br>
> -}<br>
> -<br>
> -/// ReadProfilingNumEntries - Read how many entries are in this profiling data<br>
> -/// packet.<br>
> -static unsigned ReadProfilingNumEntries(const char *ToolName, FILE *F,<br>
> - bool ShouldByteSwap) {<br>
> - unsigned Entry;<br>
> - ReadProfilingData<unsigned>(ToolName, F, &Entry, 1);<br>
> - return ShouldByteSwap ? ByteSwap_32(Entry) : Entry;<br>
> -}<br>
> -<br>
> -/// ReadProfilingBlock - Read the number of entries in the next profiling data<br>
> -/// packet and then accumulate the entries into 'Data'.<br>
> -static void ReadProfilingBlock(const char *ToolName, FILE *F,<br>
> - bool ShouldByteSwap,<br>
> - SmallVectorImpl<unsigned> &Data) {<br>
> - // Read the number of entries...<br>
> - unsigned NumEntries = ReadProfilingNumEntries(ToolName, F, ShouldByteSwap);<br>
> -<br>
> - // Read in the data.<br>
> - SmallVector<unsigned, 8> TempSpace(NumEntries);<br>
> - ReadProfilingData<unsigned>(ToolName, F, TempSpace.data(), NumEntries);<br>
> -<br>
> - // Make sure we have enough space ...<br>
> - if (Data.size() < NumEntries)<br>
> - Data.resize(NumEntries, ProfileDataLoader::Uncounted);<br>
> -<br>
> - // Accumulate the data we just read into the existing data.<br>
> - for (unsigned i = 0; i < NumEntries; ++i) {<br>
> - unsigned Entry = ShouldByteSwap ? ByteSwap_32(TempSpace[i]) : TempSpace[i];<br>
> - Data[i] = AddCounts(Entry, Data[i]);<br>
> - }<br>
> -}<br>
> -<br>
> -/// ReadProfilingArgBlock - Read the command line arguments that the progam was<br>
> -/// run with when the current profiling data packet(s) were generated.<br>
> -static void ReadProfilingArgBlock(const char *ToolName, FILE *F,<br>
> - bool ShouldByteSwap,<br>
> - SmallVectorImpl<std::string> &CommandLines) {<br>
> - // Read the number of bytes ...<br>
> - unsigned ArgLength = ReadProfilingNumEntries(ToolName, F, ShouldByteSwap);<br>
> -<br>
> - // Read in the arguments (if there are any to read). Round up the length to<br>
> - // the nearest 4-byte multiple.<br>
> - SmallVector<char, 8> Args(ArgLength+4);<br>
> - if (ArgLength)<br>
> - ReadProfilingData<char>(ToolName, F, Args.data(), (ArgLength+3) & ~3);<br>
> -<br>
> - // Store the arguments.<br>
> - CommandLines.push_back(std::string(&Args[0], &Args[ArgLength]));<br>
> -}<br>
> -<br>
> -const unsigned ProfileDataLoader::Uncounted = ~0U;<br>
> -<br>
> -/// ProfileDataLoader ctor - Read the specified profiling data file, reporting<br>
> -/// a fatal error if the file is invalid or broken.<br>
> -ProfileDataLoader::ProfileDataLoader(const char *ToolName,<br>
> - const std::string &Filename)<br>
> - : Filename(Filename) {<br>
> - FILE *F = fopen(Filename.c_str(), "rb");<br>
> - if (F == 0)<br>
> - report_fatal_error(Twine(ToolName) + ": Error opening '" +<br>
> - Filename + "': ");<br>
> -<br>
> - // Keep reading packets until we run out of them.<br>
> - unsigned PacketType;<br>
> - while (fread(&PacketType, sizeof(unsigned), 1, F) == 1) {<br>
> - // If the low eight bits of the packet are zero, we must be dealing with an<br>
> - // endianness mismatch. Byteswap all words read from the profiling<br>
> - // information. This can happen when the compiler host and target have<br>
> - // different endianness.<br>
> - bool ShouldByteSwap = (char)PacketType == 0;<br>
> - PacketType = ShouldByteSwap ? ByteSwap_32(PacketType) : PacketType;<br>
> -<br>
> - switch (PacketType) {<br>
> - case ArgumentInfo:<br>
> - ReadProfilingArgBlock(ToolName, F, ShouldByteSwap, CommandLines);<br>
> - break;<br>
> -<br>
> - case EdgeInfo:<br>
> - ReadProfilingBlock(ToolName, F, ShouldByteSwap, EdgeCounts);<br>
> - break;<br>
> -<br>
> - default:<br>
> - report_fatal_error(std::string(ToolName)<br>
> - + ": Unknown profiling packet type");<br>
> - break;<br>
> - }<br>
> - }<br>
> -<br>
> - fclose(F);<br>
> -}<br>
><br>
> Removed: llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ProfileDataLoaderPass.cpp (removed)<br>
> @@ -1,188 +0,0 @@<br>
> -//===- ProfileDataLoaderPass.cpp - Set branch weight metadata from prof ---===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This pass loads profiling data from a dump file and sets branch weight<br>
> -// metadata.<br>
> -//<br>
> -// TODO: Replace all "profile-metadata-loader" strings with "profile-loader"<br>
> -// once ProfileInfo etc. has been removed.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "profile-metadata-loader"<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/ADT/ArrayRef.h"<br>
> -#include "llvm/ADT/Statistic.h"<br>
> -#include "llvm/Analysis/ProfileDataLoader.h"<br>
> -#include "llvm/IR/BasicBlock.h"<br>
> -#include "llvm/IR/InstrTypes.h"<br>
> -#include "llvm/IR/LLVMContext.h"<br>
> -#include "llvm/IR/MDBuilder.h"<br>
> -#include "llvm/IR/Metadata.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CFG.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/Format.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -using namespace llvm;<br>
> -<br>
> -STATISTIC(NumEdgesRead, "The # of edges read.");<br>
> -STATISTIC(NumTermsAnnotated, "The # of terminator instructions annotated.");<br>
> -<br>
> -static cl::opt<std::string><br>
> -ProfileMetadataFilename("profile-file", cl::init("llvmprof.out"),<br>
> - cl::value_desc("filename"),<br>
> - cl::desc("Profile file loaded by -profile-metadata-loader"));<br>
> -<br>
> -namespace {<br>
> - /// This pass loads profiling data from a dump file and sets branch weight<br>
> - /// metadata.<br>
> - class ProfileMetadataLoaderPass : public ModulePass {<br>
> - std::string Filename;<br>
> - public:<br>
> - static char ID; // Class identification, replacement for typeinfo<br>
> - explicit ProfileMetadataLoaderPass(const std::string &filename = "")<br>
> - : ModulePass(ID), Filename(filename) {<br>
> - initializeProfileMetadataLoaderPassPass(*PassRegistry::getPassRegistry());<br>
> - if (filename.empty()) Filename = ProfileMetadataFilename;<br>
> - }<br>
> -<br>
> - virtual void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> - AU.setPreservesAll();<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "Profile loader";<br>
> - }<br>
> -<br>
> - virtual void readEdge(unsigned, ProfileData&, ProfileData::Edge,<br>
> - ArrayRef<unsigned>);<br>
> - virtual unsigned matchEdges(Module&, ProfileData&, ArrayRef<unsigned>);<br>
> - virtual void setBranchWeightMetadata(Module&, ProfileData&);<br>
> -<br>
> - virtual bool runOnModule(Module &M);<br>
> - };<br>
> -} // End of anonymous namespace<br>
> -<br>
> -char ProfileMetadataLoaderPass::ID = 0;<br>
> -INITIALIZE_PASS_BEGIN(ProfileMetadataLoaderPass, "profile-metadata-loader",<br>
> - "Load profile information from llvmprof.out", false, true)<br>
> -INITIALIZE_PASS_END(ProfileMetadataLoaderPass, "profile-metadata-loader",<br>
> - "Load profile information from llvmprof.out", false, true)<br>
> -<br>
> -char &llvm::ProfileMetadataLoaderPassID = ProfileMetadataLoaderPass::ID;<br>
> -<br>
> -/// createProfileMetadataLoaderPass - This function returns a Pass that loads<br>
> -/// the profiling information for the module from the specified filename,<br>
> -/// making it available to the optimizers.<br>
> -ModulePass *llvm::createProfileMetadataLoaderPass() {<br>
> - return new ProfileMetadataLoaderPass();<br>
> -}<br>
> -ModulePass *llvm::createProfileMetadataLoaderPass(const std::string &Filename) {<br>
> - return new ProfileMetadataLoaderPass(Filename);<br>
> -}<br>
> -<br>
> -/// readEdge - Take the value from a profile counter and assign it to an edge.<br>
> -void ProfileMetadataLoaderPass::readEdge(unsigned ReadCount,<br>
> - ProfileData &PB, ProfileData::Edge e,<br>
> - ArrayRef<unsigned> Counters) {<br>
> - if (ReadCount >= Counters.size()) return;<br>
> -<br>
> - unsigned weight = Counters[ReadCount];<br>
> - assert(weight != ProfileDataLoader::Uncounted);<br>
> - PB.addEdgeWeight(e, weight);<br>
> -<br>
> - DEBUG(dbgs() << "-- Read Edge Counter for " << e<br>
> - << " (# "<< (ReadCount) << "): "<br>
> - << PB.getEdgeWeight(e) << "\n");<br>
> -}<br>
> -<br>
> -/// matchEdges - Link every profile counter with an edge.<br>
> -unsigned ProfileMetadataLoaderPass::matchEdges(Module &M, ProfileData &PB,<br>
> - ArrayRef<unsigned> Counters) {<br>
> - if (Counters.size() == 0) return 0;<br>
> -<br>
> - unsigned ReadCount = 0;<br>
> -<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - DEBUG(dbgs() << "Loading edges in '" << F->getName() << "'\n");<br>
> - readEdge(ReadCount++, PB, PB.getEdge(0, &F->getEntryBlock()), Counters);<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - TerminatorInst *TI = BB->getTerminator();<br>
> - for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {<br>
> - readEdge(ReadCount++, PB, PB.getEdge(BB,TI->getSuccessor(s)),<br>
> - Counters);<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - return ReadCount;<br>
> -}<br>
> -<br>
> -/// setBranchWeightMetadata - Translate the counter values associated with each<br>
> -/// edge into branch weights for each conditional branch (a branch with 2 or<br>
> -/// more desinations).<br>
> -void ProfileMetadataLoaderPass::setBranchWeightMetadata(Module &M,<br>
> - ProfileData &PB) {<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - DEBUG(dbgs() << "Setting branch metadata in '" << F->getName() << "'\n");<br>
> -<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - TerminatorInst *TI = BB->getTerminator();<br>
> - unsigned NumSuccessors = TI->getNumSuccessors();<br>
> -<br>
> - // If there is only one successor then we can not set a branch<br>
> - // probability as the target is certain.<br>
> - if (NumSuccessors < 2) continue;<br>
> -<br>
> - // Load the weights of all edges leading from this terminator.<br>
> - DEBUG(dbgs() << "-- Terminator with " << NumSuccessors<br>
> - << " successors:\n");<br>
> - SmallVector<uint32_t, 4> Weights(NumSuccessors);<br>
> - for (unsigned s = 0 ; s < NumSuccessors ; ++s) {<br>
> - ProfileData::Edge edge = PB.getEdge(BB, TI->getSuccessor(s));<br>
> - Weights[s] = (uint32_t)PB.getEdgeWeight(edge);<br>
> - DEBUG(dbgs() << "---- Edge '" << edge << "' has weight "<br>
> - << Weights[s] << "\n");<br>
> - }<br>
> -<br>
> - // Set branch weight metadata. This will set branch probabilities of<br>
> - // 100%/0% if that is true of the dynamic execution.<br>
> - // BranchProbabilityInfo can account for this when it loads this metadata<br>
> - // (it gives the unexectuted branch a weight of 1 for the purposes of<br>
> - // probability calculations).<br>
> - MDBuilder MDB(TI->getContext());<br>
> - MDNode *Node = MDB.createBranchWeights(Weights);<br>
> - TI->setMetadata(LLVMContext::MD_prof, Node);<br>
> - NumTermsAnnotated++;<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -bool ProfileMetadataLoaderPass::runOnModule(Module &M) {<br>
> - ProfileDataLoader PDL("profile-data-loader", Filename);<br>
> - ProfileData PB;<br>
> -<br>
> - ArrayRef<unsigned> Counters = PDL.getRawEdgeCounts();<br>
> -<br>
> - unsigned ReadCount = matchEdges(M, PB, Counters);<br>
> -<br>
> - if (ReadCount != Counters.size()) {<br>
> - errs() << "WARNING: profile information is inconsistent with "<br>
> - << "the current program!\n";<br>
> - }<br>
> - NumEdgesRead = ReadCount;<br>
> -<br>
> - setBranchWeightMetadata(M, PB);<br>
> -<br>
> - return ReadCount > 0;<br>
> -}<br>
><br>
> Removed: llvm/trunk/lib/Analysis/ProfileEstimatorPass.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileEstimatorPass.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileEstimatorPass.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/ProfileEstimatorPass.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ProfileEstimatorPass.cpp (removed)<br>
> @@ -1,426 +0,0 @@<br>
> -//===- ProfileEstimatorPass.cpp - LLVM Pass to estimate profile info ------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file implements a concrete implementation of profiling information that<br>
> -// estimates the profiling information in a very crude and unimaginative way.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "profile-estimator"<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/Analysis/LoopInfo.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/Format.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -using namespace llvm;<br>
> -<br>
> -static cl::opt<double><br>
> -LoopWeight(<br>
> - "profile-estimator-loop-weight", cl::init(10),<br>
> - cl::value_desc("loop-weight"),<br>
> - cl::desc("Number of loop executions used for profile-estimator")<br>
> -);<br>
> -<br>
> -namespace {<br>
> - class ProfileEstimatorPass : public FunctionPass, public ProfileInfo {<br>
> - double ExecCount;<br>
> - LoopInfo *LI;<br>
> - std::set<BasicBlock*> BBToVisit;<br>
> - std::map<Loop*,double> LoopExitWeights;<br>
> - std::map<Edge,double> MinimalWeight;<br>
> - public:<br>
> - static char ID; // Class identification, replacement for typeinfo<br>
> - explicit ProfileEstimatorPass(const double execcount = 0)<br>
> - : FunctionPass(ID), ExecCount(execcount) {<br>
> - initializeProfileEstimatorPassPass(*PassRegistry::getPassRegistry());<br>
> - if (execcount == 0) ExecCount = LoopWeight;<br>
> - }<br>
> -<br>
> - virtual void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> - AU.setPreservesAll();<br>
> - AU.addRequired<LoopInfo>();<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "Profiling information estimator";<br>
> - }<br>
> -<br>
> - /// run - Estimate the profile information from the specified file.<br>
> - virtual bool runOnFunction(Function &F);<br>
> -<br>
> - /// getAdjustedAnalysisPointer - This method is used when a pass implements<br>
> - /// an analysis interface through multiple inheritance. If needed, it<br>
> - /// should override this to adjust the this pointer as needed for the<br>
> - /// specified pass info.<br>
> - virtual void *getAdjustedAnalysisPointer(AnalysisID PI) {<br>
> - if (PI == &ProfileInfo::ID)<br>
> - return (ProfileInfo*)this;<br>
> - return this;<br>
> - }<br>
> -<br>
> - virtual void recurseBasicBlock(BasicBlock *BB);<br>
> -<br>
> - void inline printEdgeWeight(Edge);<br>
> - };<br>
> -} // End of anonymous namespace<br>
> -<br>
> -char ProfileEstimatorPass::ID = 0;<br>
> -INITIALIZE_AG_PASS_BEGIN(ProfileEstimatorPass, ProfileInfo, "profile-estimator",<br>
> - "Estimate profiling information", false, true, false)<br>
> -INITIALIZE_PASS_DEPENDENCY(LoopInfo)<br>
> -INITIALIZE_AG_PASS_END(ProfileEstimatorPass, ProfileInfo, "profile-estimator",<br>
> - "Estimate profiling information", false, true, false)<br>
> -<br>
> -namespace llvm {<br>
> - char &ProfileEstimatorPassID = ProfileEstimatorPass::ID;<br>
> -<br>
> - FunctionPass *createProfileEstimatorPass() {<br>
> - return new ProfileEstimatorPass();<br>
> - }<br>
> -<br>
> - /// createProfileEstimatorPass - This function returns a Pass that estimates<br>
> - /// profiling information using the given loop execution count.<br>
> - Pass *createProfileEstimatorPass(const unsigned execcount) {<br>
> - return new ProfileEstimatorPass(execcount);<br>
> - }<br>
> -}<br>
> -<br>
> -static double ignoreMissing(double w) {<br>
> - if (w == ProfileInfo::MissingValue) return 0;<br>
> - return w;<br>
> -}<br>
> -<br>
> -static void inline printEdgeError(ProfileInfo::Edge e, const char *M) {<br>
> - DEBUG(dbgs() << "-- Edge " << e << " is not calculated, " << M << "\n");<br>
> -}<br>
> -<br>
> -void inline ProfileEstimatorPass::printEdgeWeight(Edge E) {<br>
> - DEBUG(dbgs() << "-- Weight of Edge " << E << ":"<br>
> - << format("%20.20g", getEdgeWeight(E)) << "\n");<br>
> -}<br>
> -<br>
> -// recurseBasicBlock() - This calculates the ProfileInfo estimation for a<br>
> -// single block and then recurses into the successors.<br>
> -// The algorithm preserves the flow condition, meaning that the sum of the<br>
> -// weight of the incoming edges must be equal the block weight which must in<br>
> -// turn be equal to the sume of the weights of the outgoing edges.<br>
> -// Since the flow of an block is deterimined from the current state of the<br>
> -// flow, once an edge has a flow assigned this flow is never changed again,<br>
> -// otherwise it would be possible to violate the flow condition in another<br>
> -// block.<br>
> -void ProfileEstimatorPass::recurseBasicBlock(BasicBlock *BB) {<br>
> -<br>
> - // Break the recursion if this BasicBlock was already visited.<br>
> - if (BBToVisit.find(BB) == BBToVisit.end()) return;<br>
> -<br>
> - // Read the LoopInfo for this block.<br>
> - bool BBisHeader = LI->isLoopHeader(BB);<br>
> - Loop* BBLoop = LI->getLoopFor(BB);<br>
> -<br>
> - // To get the block weight, read all incoming edges.<br>
> - double BBWeight = 0;<br>
> - std::set<BasicBlock*> ProcessedPreds;<br>
> - for ( pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB);<br>
> - bbi != bbe; ++bbi ) {<br>
> - // If this block was not considered already, add weight.<br>
> - Edge edge = getEdge(*bbi,BB);<br>
> - double w = getEdgeWeight(edge);<br>
> - if (ProcessedPreds.insert(*bbi).second) {<br>
> - BBWeight += ignoreMissing(w);<br>
> - }<br>
> - // If this block is a loop header and the predecessor is contained in this<br>
> - // loop, thus the edge is a backedge, continue and do not check if the<br>
> - // value is valid.<br>
> - if (BBisHeader && BBLoop->contains(*bbi)) {<br>
> - printEdgeError(edge, "but is backedge, continuing");<br>
> - continue;<br>
> - }<br>
> - // If the edges value is missing (and this is no loop header, and this is<br>
> - // no backedge) return, this block is currently non estimatable.<br>
> - if (w == MissingValue) {<br>
> - printEdgeError(edge, "returning");<br>
> - return;<br>
> - }<br>
> - }<br>
> - if (getExecutionCount(BB) != MissingValue) {<br>
> - BBWeight = getExecutionCount(BB);<br>
> - }<br>
> -<br>
> - // Fetch all necessary information for current block.<br>
> - SmallVector<Edge, 8> ExitEdges;<br>
> - SmallVector<Edge, 8> Edges;<br>
> - if (BBLoop) {<br>
> - BBLoop->getExitEdges(ExitEdges);<br>
> - }<br>
> -<br>
> - // If this is a loop header, consider the following:<br>
> - // Exactly the flow that is entering this block, must exit this block too. So<br>
> - // do the following:<br>
> - // *) get all the exit edges, read the flow that is already leaving this<br>
> - // loop, remember the edges that do not have any flow on them right now.<br>
> - // (The edges that have already flow on them are most likely exiting edges of<br>
> - // other loops, do not touch those flows because the previously caclulated<br>
> - // loopheaders would not be exact anymore.)<br>
> - // *) In case there is not a single exiting edge left, create one at the loop<br>
> - // latch to prevent the flow from building up in the loop.<br>
> - // *) Take the flow that is not leaving the loop already and distribute it on<br>
> - // the remaining exiting edges.<br>
> - // (This ensures that all flow that enters the loop also leaves it.)<br>
> - // *) Increase the flow into the loop by increasing the weight of this block.<br>
> - // There is at least one incoming backedge that will bring us this flow later<br>
> - // on. (So that the flow condition in this node is valid again.)<br>
> - if (BBisHeader) {<br>
> - double incoming = BBWeight;<br>
> - // Subtract the flow leaving the loop.<br>
> - std::set<Edge> ProcessedExits;<br>
> - for (SmallVectorImpl<Edge>::iterator ei = ExitEdges.begin(),<br>
> - ee = ExitEdges.end(); ei != ee; ++ei) {<br>
> - if (ProcessedExits.insert(*ei).second) {<br>
> - double w = getEdgeWeight(*ei);<br>
> - if (w == MissingValue) {<br>
> - Edges.push_back(*ei);<br>
> - // Check if there is a necessary minimal weight, if yes, subtract it<br>
> - // from weight.<br>
> - if (MinimalWeight.find(*ei) != MinimalWeight.end()) {<br>
> - incoming -= MinimalWeight[*ei];<br>
> - DEBUG(dbgs() << "Reserving " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n");<br>
> - }<br>
> - } else {<br>
> - incoming -= w;<br>
> - }<br>
> - }<br>
> - }<br>
> - // If no exit edges, create one:<br>
> - if (Edges.size() == 0) {<br>
> - BasicBlock *Latch = BBLoop->getLoopLatch();<br>
> - if (Latch) {<br>
> - Edge edge = getEdge(Latch,0);<br>
> - EdgeInformation[BB->getParent()][edge] = BBWeight;<br>
> - printEdgeWeight(edge);<br>
> - edge = getEdge(Latch, BB);<br>
> - EdgeInformation[BB->getParent()][edge] = BBWeight * ExecCount;<br>
> - printEdgeWeight(edge);<br>
> - }<br>
> - }<br>
> -<br>
> - // Distribute remaining weight to the exting edges. To prevent fractions<br>
> - // from building up and provoking precision problems the weight which is to<br>
> - // be distributed is split and the rounded, the last edge gets a somewhat<br>
> - // bigger value, but we are close enough for an estimation.<br>
> - double fraction = floor(incoming/Edges.size());<br>
> - for (SmallVectorImpl<Edge>::iterator ei = Edges.begin(), ee = Edges.end();<br>
> - ei != ee; ++ei) {<br>
> - double w = 0;<br>
> - if (ei != (ee-1)) {<br>
> - w = fraction;<br>
> - incoming -= fraction;<br>
> - } else {<br>
> - w = incoming;<br>
> - }<br>
> - EdgeInformation[BB->getParent()][*ei] += w;<br>
> - // Read necessary minimal weight.<br>
> - if (MinimalWeight.find(*ei) != MinimalWeight.end()) {<br>
> - EdgeInformation[BB->getParent()][*ei] += MinimalWeight[*ei];<br>
> - DEBUG(dbgs() << "Additionally " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n");<br>
> - }<br>
> - printEdgeWeight(*ei);<br>
> -<br>
> - // Add minimal weight to paths to all exit edges, this is used to ensure<br>
> - // that enough flow is reaching this edges.<br>
> - Path p;<br>
> - const BasicBlock *Dest = GetPath(BB, (*ei).first, p, GetPathToDest);<br>
> - while (Dest != BB) {<br>
> - const BasicBlock *Parent = p.find(Dest)->second;<br>
> - Edge e = getEdge(Parent, Dest);<br>
> - if (MinimalWeight.find(e) == MinimalWeight.end()) {<br>
> - MinimalWeight[e] = 0;<br>
> - }<br>
> - MinimalWeight[e] += w;<br>
> - DEBUG(dbgs() << "Minimal Weight for " << e << ": " << format("%.20g",MinimalWeight[e]) << "\n");<br>
> - Dest = Parent;<br>
> - }<br>
> - }<br>
> - // Increase flow into the loop.<br>
> - BBWeight *= (ExecCount+1);<br>
> - }<br>
> -<br>
> - BlockInformation[BB->getParent()][BB] = BBWeight;<br>
> - // Up until now we considered only the loop exiting edges, now we have a<br>
> - // definite block weight and must distribute this onto the outgoing edges.<br>
> - // Since there may be already flow attached to some of the edges, read this<br>
> - // flow first and remember the edges that have still now flow attached.<br>
> - Edges.clear();<br>
> - std::set<BasicBlock*> ProcessedSuccs;<br>
> -<br>
> - succ_iterator bbi = succ_begin(BB), bbe = succ_end(BB);<br>
> - // Also check for (BB,0) edges that may already contain some flow. (But only<br>
> - // in case there are no successors.)<br>
> - if (bbi == bbe) {<br>
> - Edge edge = getEdge(BB,0);<br>
> - EdgeInformation[BB->getParent()][edge] = BBWeight;<br>
> - printEdgeWeight(edge);<br>
> - }<br>
> - for ( ; bbi != bbe; ++bbi ) {<br>
> - if (ProcessedSuccs.insert(*bbi).second) {<br>
> - Edge edge = getEdge(BB,*bbi);<br>
> - double w = getEdgeWeight(edge);<br>
> - if (w != MissingValue) {<br>
> - BBWeight -= getEdgeWeight(edge);<br>
> - } else {<br>
> - Edges.push_back(edge);<br>
> - // If minimal weight is necessary, reserve weight by subtracting weight<br>
> - // from block weight, this is readded later on.<br>
> - if (MinimalWeight.find(edge) != MinimalWeight.end()) {<br>
> - BBWeight -= MinimalWeight[edge];<br>
> - DEBUG(dbgs() << "Reserving " << format("%.20g",MinimalWeight[edge]) << " at " << edge << "\n");<br>
> - }<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - double fraction = Edges.size() ? floor(BBWeight/Edges.size()) : 0.0;<br>
> - // Finally we know what flow is still not leaving the block, distribute this<br>
> - // flow onto the empty edges.<br>
> - for (SmallVectorImpl<Edge>::iterator ei = Edges.begin(), ee = Edges.end();<br>
> - ei != ee; ++ei) {<br>
> - if (ei != (ee-1)) {<br>
> - EdgeInformation[BB->getParent()][*ei] += fraction;<br>
> - BBWeight -= fraction;<br>
> - } else {<br>
> - EdgeInformation[BB->getParent()][*ei] += BBWeight;<br>
> - }<br>
> - // Readd minial necessary weight.<br>
> - if (MinimalWeight.find(*ei) != MinimalWeight.end()) {<br>
> - EdgeInformation[BB->getParent()][*ei] += MinimalWeight[*ei];<br>
> - DEBUG(dbgs() << "Additionally " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n");<br>
> - }<br>
> - printEdgeWeight(*ei);<br>
> - }<br>
> -<br>
> - // This block is visited, mark this before the recursion.<br>
> - BBToVisit.erase(BB);<br>
> -<br>
> - // Recurse into successors.<br>
> - for (succ_iterator bbi = succ_begin(BB), bbe = succ_end(BB);<br>
> - bbi != bbe; ++bbi) {<br>
> - recurseBasicBlock(*bbi);<br>
> - }<br>
> -}<br>
> -<br>
> -bool ProfileEstimatorPass::runOnFunction(Function &F) {<br>
> - if (F.isDeclaration()) return false;<br>
> -<br>
> - // Fetch LoopInfo and clear ProfileInfo for this function.<br>
> - LI = &getAnalysis<LoopInfo>();<br>
> - FunctionInformation.erase(&F);<br>
> - BlockInformation[&F].clear();<br>
> - EdgeInformation[&F].clear();<br>
> - BBToVisit.clear();<br>
> -<br>
> - // Mark all blocks as to visit.<br>
> - for (Function::iterator bi = F.begin(), be = F.end(); bi != be; ++bi)<br>
> - BBToVisit.insert(bi);<br>
> -<br>
> - // Clear Minimal Edges.<br>
> - MinimalWeight.clear();<br>
> -<br>
> - DEBUG(dbgs() << "Working on function " << F.getName() << "\n");<br>
> -<br>
> - // Since the entry block is the first one and has no predecessors, the edge<br>
> - // (0,entry) is inserted with the starting weight of 1.<br>
> - BasicBlock *entry = &F.getEntryBlock();<br>
> - BlockInformation[&F][entry] = pow(2.0, 32.0);<br>
> - Edge edge = getEdge(0,entry);<br>
> - EdgeInformation[&F][edge] = BlockInformation[&F][entry];<br>
> - printEdgeWeight(edge);<br>
> -<br>
> - // Since recurseBasicBlock() maybe returns with a block which was not fully<br>
> - // estimated, use recurseBasicBlock() until everything is calculated.<br>
> - bool cleanup = false;<br>
> - recurseBasicBlock(entry);<br>
> - while (BBToVisit.size() > 0 && !cleanup) {<br>
> - // Remember number of open blocks, this is later used to check if progress<br>
> - // was made.<br>
> - unsigned size = BBToVisit.size();<br>
> -<br>
> - // Try to calculate all blocks in turn.<br>
> - for (std::set<BasicBlock*>::iterator bi = BBToVisit.begin(),<br>
> - be = BBToVisit.end(); bi != be; ++bi) {<br>
> - recurseBasicBlock(*bi);<br>
> - // If at least one block was finished, break because iterator may be<br>
> - // invalid.<br>
> - if (BBToVisit.size() < size) break;<br>
> - }<br>
> -<br>
> - // If there was not a single block resolved, make some assumptions.<br>
> - if (BBToVisit.size() == size) {<br>
> - bool found = false;<br>
> - for (std::set<BasicBlock*>::iterator BBI = BBToVisit.begin(), BBE = BBToVisit.end();<br>
> - (BBI != BBE) && (!found); ++BBI) {<br>
> - BasicBlock *BB = *BBI;<br>
> - // Try each predecessor if it can be assumend.<br>
> - for (pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB);<br>
> - (bbi != bbe) && (!found); ++bbi) {<br>
> - Edge e = getEdge(*bbi,BB);<br>
> - double w = getEdgeWeight(e);<br>
> - // Check that edge from predecessor is still free.<br>
> - if (w == MissingValue) {<br>
> - // Check if there is a circle from this block to predecessor.<br>
> - Path P;<br>
> - const BasicBlock *Dest = GetPath(BB, *bbi, P, GetPathToDest);<br>
> - if (Dest != *bbi) {<br>
> - // If there is no circle, just set edge weight to 0<br>
> - EdgeInformation[&F][e] = 0;<br>
> - DEBUG(dbgs() << "Assuming edge weight: ");<br>
> - printEdgeWeight(e);<br>
> - found = true;<br>
> - }<br>
> - }<br>
> - }<br>
> - }<br>
> - if (!found) {<br>
> - cleanup = true;<br>
> - DEBUG(dbgs() << "No assumption possible in Fuction "<<F.getName()<<", setting all to zero\n");<br>
> - }<br>
> - }<br>
> - }<br>
> - // In case there was no safe way to assume edges, set as a last measure,<br>
> - // set _everything_ to zero.<br>
> - if (cleanup) {<br>
> - FunctionInformation[&F] = 0;<br>
> - BlockInformation[&F].clear();<br>
> - EdgeInformation[&F].clear();<br>
> - for (Function::const_iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) {<br>
> - const BasicBlock *BB = &(*FI);<br>
> - BlockInformation[&F][BB] = 0;<br>
> - const_pred_iterator predi = pred_begin(BB), prede = pred_end(BB);<br>
> - if (predi == prede) {<br>
> - Edge e = getEdge(0,BB);<br>
> - setEdgeWeight(e,0);<br>
> - }<br>
> - for (;predi != prede; ++predi) {<br>
> - Edge e = getEdge(*predi,BB);<br>
> - setEdgeWeight(e,0);<br>
> - }<br>
> - succ_const_iterator succi = succ_begin(BB), succe = succ_end(BB);<br>
> - if (succi == succe) {<br>
> - Edge e = getEdge(BB,0);<br>
> - setEdgeWeight(e,0);<br>
> - }<br>
> - for (;succi != succe; ++succi) {<br>
> - Edge e = getEdge(*succi,BB);<br>
> - setEdgeWeight(e,0);<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - return false;<br>
> -}<br>
><br>
> Removed: llvm/trunk/lib/Analysis/ProfileInfo.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfo.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfo.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/ProfileInfo.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ProfileInfo.cpp (removed)<br>
> @@ -1,1079 +0,0 @@<br>
> -//===- ProfileInfo.cpp - Profile Info Interface ---------------------------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file implements the abstract ProfileInfo interface, and the default<br>
> -// "no profile" implementation.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "profile-info"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> -#include "llvm/ADT/SmallSet.h"<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/CodeGen/MachineBasicBlock.h"<br>
> -#include "llvm/CodeGen/MachineFunction.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CFG.h"<br>
> -#include <limits><br>
> -#include <queue><br>
> -#include <set><br>
> -using namespace llvm;<br>
> -<br>
> -namespace llvm {<br>
> - template<> char ProfileInfoT<Function,BasicBlock>::ID = 0;<br>
> -}<br>
> -<br>
> -// Register the ProfileInfo interface, providing a nice name to refer to.<br>
> -INITIALIZE_ANALYSIS_GROUP(ProfileInfo, "Profile Information", NoProfileInfo)<br>
> -<br>
> -namespace llvm {<br>
> -<br>
> -template <><br>
> -ProfileInfoT<MachineFunction, MachineBasicBlock>::ProfileInfoT() {}<br>
> -template <><br>
> -ProfileInfoT<MachineFunction, MachineBasicBlock>::~ProfileInfoT() {}<br>
> -<br>
> -template <><br>
> -ProfileInfoT<Function, BasicBlock>::ProfileInfoT() {<br>
> - MachineProfile = 0;<br>
> -}<br>
> -template <><br>
> -ProfileInfoT<Function, BasicBlock>::~ProfileInfoT() {<br>
> - if (MachineProfile) delete MachineProfile;<br>
> -}<br>
> -<br>
> -template<><br>
> -char ProfileInfoT<MachineFunction, MachineBasicBlock>::ID = 0;<br>
> -<br>
> -template<><br>
> -const double ProfileInfoT<Function,BasicBlock>::MissingValue = -1;<br>
> -<br>
> -template<> const<br>
> -double ProfileInfoT<MachineFunction, MachineBasicBlock>::MissingValue = -1;<br>
> -<br>
> -template<> double<br>
> -ProfileInfoT<Function,BasicBlock>::getExecutionCount(const BasicBlock *BB) {<br>
> - std::map<const Function*, BlockCounts>::iterator J =<br>
> - BlockInformation.find(BB->getParent());<br>
> - if (J != BlockInformation.end()) {<br>
> - BlockCounts::iterator I = J->second.find(BB);<br>
> - if (I != J->second.end())<br>
> - return I->second;<br>
> - }<br>
> -<br>
> - double Count = MissingValue;<br>
> -<br>
> - const_pred_iterator PI = pred_begin(BB), PE = pred_end(BB);<br>
> -<br>
> - // Are there zero predecessors of this block?<br>
> - if (PI == PE) {<br>
> - Edge e = getEdge(0, BB);<br>
> - Count = getEdgeWeight(e);<br>
> - } else {<br>
> - // Otherwise, if there are predecessors, the execution count of this block is<br>
> - // the sum of the edge frequencies from the incoming edges.<br>
> - std::set<const BasicBlock*> ProcessedPreds;<br>
> - Count = 0;<br>
> - for (; PI != PE; ++PI) {<br>
> - const BasicBlock *P = *PI;<br>
> - if (ProcessedPreds.insert(P).second) {<br>
> - double w = getEdgeWeight(getEdge(P, BB));<br>
> - if (w == MissingValue) {<br>
> - Count = MissingValue;<br>
> - break;<br>
> - }<br>
> - Count += w;<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - // If the predecessors did not suffice to get block weight, try successors.<br>
> - if (Count == MissingValue) {<br>
> -<br>
> - succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);<br>
> -<br>
> - // Are there zero successors of this block?<br>
> - if (SI == SE) {<br>
> - Edge e = getEdge(BB,0);<br>
> - Count = getEdgeWeight(e);<br>
> - } else {<br>
> - std::set<const BasicBlock*> ProcessedSuccs;<br>
> - Count = 0;<br>
> - for (; SI != SE; ++SI)<br>
> - if (ProcessedSuccs.insert(*SI).second) {<br>
> - double w = getEdgeWeight(getEdge(BB, *SI));<br>
> - if (w == MissingValue) {<br>
> - Count = MissingValue;<br>
> - break;<br>
> - }<br>
> - Count += w;<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - if (Count != MissingValue) BlockInformation[BB->getParent()][BB] = Count;<br>
> - return Count;<br>
> -}<br>
> -<br>
> -template<><br>
> -double ProfileInfoT<MachineFunction, MachineBasicBlock>::<br>
> - getExecutionCount(const MachineBasicBlock *MBB) {<br>
> - std::map<const MachineFunction*, BlockCounts>::iterator J =<br>
> - BlockInformation.find(MBB->getParent());<br>
> - if (J != BlockInformation.end()) {<br>
> - BlockCounts::iterator I = J->second.find(MBB);<br>
> - if (I != J->second.end())<br>
> - return I->second;<br>
> - }<br>
> -<br>
> - return MissingValue;<br>
> -}<br>
> -<br>
> -template<><br>
> -double ProfileInfoT<Function,BasicBlock>::getExecutionCount(const Function *F) {<br>
> - std::map<const Function*, double>::iterator J =<br>
> - FunctionInformation.find(F);<br>
> - if (J != FunctionInformation.end())<br>
> - return J->second;<br>
> -<br>
> - // isDeclaration() is checked here and not at start of function to allow<br>
> - // functions without a body still to have a execution count.<br>
> - if (F->isDeclaration()) return MissingValue;<br>
> -<br>
> - double Count = getExecutionCount(&F->getEntryBlock());<br>
> - if (Count != MissingValue) FunctionInformation[F] = Count;<br>
> - return Count;<br>
> -}<br>
> -<br>
> -template<><br>
> -double ProfileInfoT<MachineFunction, MachineBasicBlock>::<br>
> - getExecutionCount(const MachineFunction *MF) {<br>
> - std::map<const MachineFunction*, double>::iterator J =<br>
> - FunctionInformation.find(MF);<br>
> - if (J != FunctionInformation.end())<br>
> - return J->second;<br>
> -<br>
> - double Count = getExecutionCount(&MF->front());<br>
> - if (Count != MissingValue) FunctionInformation[MF] = Count;<br>
> - return Count;<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::<br>
> - setExecutionCount(const BasicBlock *BB, double w) {<br>
> - DEBUG(dbgs() << "Creating Block " << BB->getName()<br>
> - << " (weight: " << format("%.20g",w) << ")\n");<br>
> - BlockInformation[BB->getParent()][BB] = w;<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<MachineFunction, MachineBasicBlock>::<br>
> - setExecutionCount(const MachineBasicBlock *MBB, double w) {<br>
> - DEBUG(dbgs() << "Creating Block " << MBB->getBasicBlock()->getName()<br>
> - << " (weight: " << format("%.20g",w) << ")\n");<br>
> - BlockInformation[MBB->getParent()][MBB] = w;<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::addEdgeWeight(Edge e, double w) {<br>
> - double oldw = getEdgeWeight(e);<br>
> - assert (oldw != MissingValue && "Adding weight to Edge with no previous weight");<br>
> - DEBUG(dbgs() << "Adding to Edge " << e<br>
> - << " (new weight: " << format("%.20g",oldw + w) << ")\n");<br>
> - EdgeInformation[getFunction(e)][e] = oldw + w;<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::<br>
> - addExecutionCount(const BasicBlock *BB, double w) {<br>
> - double oldw = getExecutionCount(BB);<br>
> - assert (oldw != MissingValue && "Adding weight to Block with no previous weight");<br>
> - DEBUG(dbgs() << "Adding to Block " << BB->getName()<br>
> - << " (new weight: " << format("%.20g",oldw + w) << ")\n");<br>
> - BlockInformation[BB->getParent()][BB] = oldw + w;<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::removeBlock(const BasicBlock *BB) {<br>
> - std::map<const Function*, BlockCounts>::iterator J =<br>
> - BlockInformation.find(BB->getParent());<br>
> - if (J == BlockInformation.end()) return;<br>
> -<br>
> - DEBUG(dbgs() << "Deleting " << BB->getName() << "\n");<br>
> - J->second.erase(BB);<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::removeEdge(Edge e) {<br>
> - std::map<const Function*, EdgeWeights>::iterator J =<br>
> - EdgeInformation.find(getFunction(e));<br>
> - if (J == EdgeInformation.end()) return;<br>
> -<br>
> - DEBUG(dbgs() << "Deleting" << e << "\n");<br>
> - J->second.erase(e);<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::<br>
> - replaceEdge(const Edge &oldedge, const Edge &newedge) {<br>
> - double w;<br>
> - if ((w = getEdgeWeight(newedge)) == MissingValue) {<br>
> - w = getEdgeWeight(oldedge);<br>
> - DEBUG(dbgs() << "Replacing " << oldedge << " with " << newedge << "\n");<br>
> - } else {<br>
> - w += getEdgeWeight(oldedge);<br>
> - DEBUG(dbgs() << "Adding " << oldedge << " to " << newedge << "\n");<br>
> - }<br>
> - setEdgeWeight(newedge,w);<br>
> - removeEdge(oldedge);<br>
> -}<br>
> -<br>
> -template<><br>
> -const BasicBlock *ProfileInfoT<Function,BasicBlock>::<br>
> - GetPath(const BasicBlock *Src, const BasicBlock *Dest,<br>
> - Path &P, unsigned Mode) {<br>
> - const BasicBlock *BB = 0;<br>
> - bool hasFoundPath = false;<br>
> -<br>
> - std::queue<const BasicBlock *> BFS;<br>
> - BFS.push(Src);<br>
> -<br>
> - while(BFS.size() && !hasFoundPath) {<br>
> - BB = BFS.front();<br>
> - BFS.pop();<br>
> -<br>
> - succ_const_iterator Succ = succ_begin(BB), End = succ_end(BB);<br>
> - if (Succ == End) {<br>
> - P[(const BasicBlock*)0] = BB;<br>
> - if (Mode & GetPathToExit) {<br>
> - hasFoundPath = true;<br>
> - BB = 0;<br>
> - }<br>
> - }<br>
> - for(;Succ != End; ++Succ) {<br>
> - if (P.find(*Succ) != P.end()) continue;<br>
> - Edge e = getEdge(BB,*Succ);<br>
> - if ((Mode & GetPathWithNewEdges) && (getEdgeWeight(e) != MissingValue)) continue;<br>
> - P[*Succ] = BB;<br>
> - BFS.push(*Succ);<br>
> - if ((Mode & GetPathToDest) && *Succ == Dest) {<br>
> - hasFoundPath = true;<br>
> - BB = *Succ;<br>
> - break;<br>
> - }<br>
> - if ((Mode & GetPathToValue) && (getExecutionCount(*Succ) != MissingValue)) {<br>
> - hasFoundPath = true;<br>
> - BB = *Succ;<br>
> - break;<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - return BB;<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::<br>
> - divertFlow(const Edge &oldedge, const Edge &newedge) {<br>
> - DEBUG(dbgs() << "Diverting " << oldedge << " via " << newedge );<br>
> -<br>
> - // First check if the old edge was taken, if not, just delete it...<br>
> - if (getEdgeWeight(oldedge) == 0) {<br>
> - removeEdge(oldedge);<br>
> - return;<br>
> - }<br>
> -<br>
> - Path P;<br>
> - P[newedge.first] = 0;<br>
> - P[newedge.second] = newedge.first;<br>
> - const BasicBlock *BB = GetPath(newedge.second,oldedge.second,P,GetPathToExit | GetPathToDest);<br>
> -<br>
> - double w = getEdgeWeight (oldedge);<br>
> - DEBUG(dbgs() << ", Weight: " << format("%.20g",w) << "\n");<br>
> - do {<br>
> - const BasicBlock *Parent = P.find(BB)->second;<br>
> - Edge e = getEdge(Parent,BB);<br>
> - double oldw = getEdgeWeight(e);<br>
> - double oldc = getExecutionCount(e.first);<br>
> - setEdgeWeight(e, w+oldw);<br>
> - if (Parent != oldedge.first) {<br>
> - setExecutionCount(e.first, w+oldc);<br>
> - }<br>
> - BB = Parent;<br>
> - } while (BB != newedge.first);<br>
> - removeEdge(oldedge);<br>
> -}<br>
> -<br>
> -/// Replaces all occurrences of RmBB in the ProfilingInfo with DestBB.<br>
> -/// This checks all edges of the function the blocks reside in and replaces the<br>
> -/// occurrences of RmBB with DestBB.<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::<br>
> - replaceAllUses(const BasicBlock *RmBB, const BasicBlock *DestBB) {<br>
> - DEBUG(dbgs() << "Replacing " << RmBB->getName()<br>
> - << " with " << DestBB->getName() << "\n");<br>
> - const Function *F = DestBB->getParent();<br>
> - std::map<const Function*, EdgeWeights>::iterator J =<br>
> - EdgeInformation.find(F);<br>
> - if (J == EdgeInformation.end()) return;<br>
> -<br>
> - Edge e, newedge;<br>
> - bool erasededge = false;<br>
> - EdgeWeights::iterator I = J->second.begin(), E = J->second.end();<br>
> - while(I != E) {<br>
> - e = (I++)->first;<br>
> - bool foundedge = false; bool eraseedge = false;<br>
> - if (e.first == RmBB) {<br>
> - if (e.second == DestBB) {<br>
> - eraseedge = true;<br>
> - } else {<br>
> - newedge = getEdge(DestBB, e.second);<br>
> - foundedge = true;<br>
> - }<br>
> - }<br>
> - if (e.second == RmBB) {<br>
> - if (e.first == DestBB) {<br>
> - eraseedge = true;<br>
> - } else {<br>
> - newedge = getEdge(e.first, DestBB);<br>
> - foundedge = true;<br>
> - }<br>
> - }<br>
> - if (foundedge) {<br>
> - replaceEdge(e, newedge);<br>
> - }<br>
> - if (eraseedge) {<br>
> - if (erasededge) {<br>
> - Edge newedge = getEdge(DestBB, DestBB);<br>
> - replaceEdge(e, newedge);<br>
> - } else {<br>
> - removeEdge(e);<br>
> - erasededge = true;<br>
> - }<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -/// Splits an edge in the ProfileInfo and redirects flow over NewBB.<br>
> -/// Since its possible that there is more than one edge in the CFG from FristBB<br>
> -/// to SecondBB its necessary to redirect the flow proporionally.<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::splitEdge(const BasicBlock *FirstBB,<br>
> - const BasicBlock *SecondBB,<br>
> - const BasicBlock *NewBB,<br>
> - bool MergeIdenticalEdges) {<br>
> - const Function *F = FirstBB->getParent();<br>
> - std::map<const Function*, EdgeWeights>::iterator J =<br>
> - EdgeInformation.find(F);<br>
> - if (J == EdgeInformation.end()) return;<br>
> -<br>
> - // Generate edges and read current weight.<br>
> - Edge e = getEdge(FirstBB, SecondBB);<br>
> - Edge n1 = getEdge(FirstBB, NewBB);<br>
> - Edge n2 = getEdge(NewBB, SecondBB);<br>
> - EdgeWeights &ECs = J->second;<br>
> - double w = ECs[e];<br>
> -<br>
> - int succ_count = 0;<br>
> - if (!MergeIdenticalEdges) {<br>
> - // First count the edges from FristBB to SecondBB, if there is more than<br>
> - // one, only slice out a proporional part for NewBB.<br>
> - for(succ_const_iterator BBI = succ_begin(FirstBB), BBE = succ_end(FirstBB);<br>
> - BBI != BBE; ++BBI) {<br>
> - if (*BBI == SecondBB) succ_count++;<br>
> - }<br>
> - // When the NewBB is completely new, increment the count by one so that<br>
> - // the counts are properly distributed.<br>
> - if (getExecutionCount(NewBB) == ProfileInfo::MissingValue) succ_count++;<br>
> - } else {<br>
> - // When the edges are merged anyway, then redirect all flow.<br>
> - succ_count = 1;<br>
> - }<br>
> -<br>
> - // We know now how many edges there are from FirstBB to SecondBB, reroute a<br>
> - // proportional part of the edge weight over NewBB.<br>
> - double neww = floor(w / succ_count);<br>
> - ECs[n1] += neww;<br>
> - ECs[n2] += neww;<br>
> - BlockInformation[F][NewBB] += neww;<br>
> - if (succ_count == 1) {<br>
> - ECs.erase(e);<br>
> - } else {<br>
> - ECs[e] -= neww;<br>
> - }<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::splitBlock(const BasicBlock *Old,<br>
> - const BasicBlock* New) {<br>
> - const Function *F = Old->getParent();<br>
> - std::map<const Function*, EdgeWeights>::iterator J =<br>
> - EdgeInformation.find(F);<br>
> - if (J == EdgeInformation.end()) return;<br>
> -<br>
> - DEBUG(dbgs() << "Splitting " << Old->getName() << " to " << New->getName() << "\n");<br>
> -<br>
> - std::set<Edge> Edges;<br>
> - for (EdgeWeights::iterator ewi = J->second.begin(), ewe = J->second.end();<br>
> - ewi != ewe; ++ewi) {<br>
> - Edge old = ewi->first;<br>
> - if (old.first == Old) {<br>
> - Edges.insert(old);<br>
> - }<br>
> - }<br>
> - for (std::set<Edge>::iterator EI = Edges.begin(), EE = Edges.end();<br>
> - EI != EE; ++EI) {<br>
> - Edge newedge = getEdge(New, EI->second);<br>
> - replaceEdge(*EI, newedge);<br>
> - }<br>
> -<br>
> - double w = getExecutionCount(Old);<br>
> - setEdgeWeight(getEdge(Old, New), w);<br>
> - setExecutionCount(New, w);<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::splitBlock(const BasicBlock *BB,<br>
> - const BasicBlock* NewBB,<br>
> - BasicBlock *const *Preds,<br>
> - unsigned NumPreds) {<br>
> - const Function *F = BB->getParent();<br>
> - std::map<const Function*, EdgeWeights>::iterator J =<br>
> - EdgeInformation.find(F);<br>
> - if (J == EdgeInformation.end()) return;<br>
> -<br>
> - DEBUG(dbgs() << "Splitting " << NumPreds << " Edges from " << BB->getName()<br>
> - << " to " << NewBB->getName() << "\n");<br>
> -<br>
> - // Collect weight that was redirected over NewBB.<br>
> - double newweight = 0;<br>
> -<br>
> - std::set<const BasicBlock *> ProcessedPreds;<br>
> - // For all requestes Predecessors.<br>
> - for (unsigned pred = 0; pred < NumPreds; ++pred) {<br>
> - const BasicBlock * Pred = Preds[pred];<br>
> - if (ProcessedPreds.insert(Pred).second) {<br>
> - // Create edges and read old weight.<br>
> - Edge oldedge = getEdge(Pred, BB);<br>
> - Edge newedge = getEdge(Pred, NewBB);<br>
> -<br>
> - // Remember how much weight was redirected.<br>
> - newweight += getEdgeWeight(oldedge);<br>
> -<br>
> - replaceEdge(oldedge,newedge);<br>
> - }<br>
> - }<br>
> -<br>
> - Edge newedge = getEdge(NewBB,BB);<br>
> - setEdgeWeight(newedge, newweight);<br>
> - setExecutionCount(NewBB, newweight);<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::transfer(const Function *Old,<br>
> - const Function *New) {<br>
> - DEBUG(dbgs() << "Replacing Function " << Old->getName() << " with "<br>
> - << New->getName() << "\n");<br>
> - std::map<const Function*, EdgeWeights>::iterator J =<br>
> - EdgeInformation.find(Old);<br>
> - if(J != EdgeInformation.end()) {<br>
> - EdgeInformation[New] = J->second;<br>
> - }<br>
> - EdgeInformation.erase(Old);<br>
> - BlockInformation.erase(Old);<br>
> - FunctionInformation.erase(Old);<br>
> -}<br>
> -<br>
> -static double readEdgeOrRemember(ProfileInfo::Edge edge, double w,<br>
> - ProfileInfo::Edge &tocalc, unsigned &uncalc) {<br>
> - if (w == ProfileInfo::MissingValue) {<br>
> - tocalc = edge;<br>
> - uncalc++;<br>
> - return 0;<br>
> - } else {<br>
> - return w;<br>
> - }<br>
> -}<br>
> -<br>
> -template<><br>
> -bool ProfileInfoT<Function,BasicBlock>::<br>
> - CalculateMissingEdge(const BasicBlock *BB, Edge &removed,<br>
> - bool assumeEmptySelf) {<br>
> - Edge edgetocalc;<br>
> - unsigned uncalculated = 0;<br>
> -<br>
> - // collect weights of all incoming and outgoing edges, rememer edges that<br>
> - // have no value<br>
> - double incount = 0;<br>
> - SmallSet<const BasicBlock*,8> pred_visited;<br>
> - const_pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB);<br>
> - if (bbi==bbe) {<br>
> - Edge e = getEdge(0,BB);<br>
> - incount += readEdgeOrRemember(e, getEdgeWeight(e) ,edgetocalc,uncalculated);<br>
> - }<br>
> - for (;bbi != bbe; ++bbi) {<br>
> - if (pred_visited.insert(*bbi)) {<br>
> - Edge e = getEdge(*bbi,BB);<br>
> - incount += readEdgeOrRemember(e, getEdgeWeight(e) ,edgetocalc,uncalculated);<br>
> - }<br>
> - }<br>
> -<br>
> - double outcount = 0;<br>
> - SmallSet<const BasicBlock*,8> succ_visited;<br>
> - succ_const_iterator sbbi = succ_begin(BB), sbbe = succ_end(BB);<br>
> - if (sbbi==sbbe) {<br>
> - Edge e = getEdge(BB,0);<br>
> - if (getEdgeWeight(e) == MissingValue) {<br>
> - double w = getExecutionCount(BB);<br>
> - if (w != MissingValue) {<br>
> - setEdgeWeight(e,w);<br>
> - removed = e;<br>
> - }<br>
> - }<br>
> - outcount += readEdgeOrRemember(e, getEdgeWeight(e), edgetocalc, uncalculated);<br>
> - }<br>
> - for (;sbbi != sbbe; ++sbbi) {<br>
> - if (succ_visited.insert(*sbbi)) {<br>
> - Edge e = getEdge(BB,*sbbi);<br>
> - outcount += readEdgeOrRemember(e, getEdgeWeight(e), edgetocalc, uncalculated);<br>
> - }<br>
> - }<br>
> -<br>
> - // if exactly one edge weight was missing, calculate it and remove it from<br>
> - // spanning tree<br>
> - if (uncalculated == 0 ) {<br>
> - return true;<br>
> - } else<br>
> - if (uncalculated == 1) {<br>
> - if (incount < outcount) {<br>
> - EdgeInformation[BB->getParent()][edgetocalc] = outcount-incount;<br>
> - } else {<br>
> - EdgeInformation[BB->getParent()][edgetocalc] = incount-outcount;<br>
> - }<br>
> - DEBUG(dbgs() << "--Calc Edge Counter for " << edgetocalc << ": "<br>
> - << format("%.20g", getEdgeWeight(edgetocalc)) << "\n");<br>
> - removed = edgetocalc;<br>
> - return true;<br>
> - } else<br>
> - if (uncalculated == 2 && assumeEmptySelf && edgetocalc.first == edgetocalc.second && incount == outcount) {<br>
> - setEdgeWeight(edgetocalc, incount * 10);<br>
> - removed = edgetocalc;<br>
> - return true;<br>
> - } else {<br>
> - return false;<br>
> - }<br>
> -}<br>
> -<br>
> -static void readEdge(ProfileInfo *PI, ProfileInfo::Edge e, double &calcw, std::set<ProfileInfo::Edge> &misscount) {<br>
> - double w = PI->getEdgeWeight(e);<br>
> - if (w != ProfileInfo::MissingValue) {<br>
> - calcw += w;<br>
> - } else {<br>
> - misscount.insert(e);<br>
> - }<br>
> -}<br>
> -<br>
> -template<><br>
> -bool ProfileInfoT<Function,BasicBlock>::EstimateMissingEdges(const BasicBlock *BB) {<br>
> - double inWeight = 0;<br>
> - std::set<Edge> inMissing;<br>
> - std::set<const BasicBlock*> ProcessedPreds;<br>
> - const_pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB);<br>
> - if (bbi == bbe) {<br>
> - readEdge(this,getEdge(0,BB),inWeight,inMissing);<br>
> - }<br>
> - for( ; bbi != bbe; ++bbi ) {<br>
> - if (ProcessedPreds.insert(*bbi).second) {<br>
> - readEdge(this,getEdge(*bbi,BB),inWeight,inMissing);<br>
> - }<br>
> - }<br>
> -<br>
> - double outWeight = 0;<br>
> - std::set<Edge> outMissing;<br>
> - std::set<const BasicBlock*> ProcessedSuccs;<br>
> - succ_const_iterator sbbi = succ_begin(BB), sbbe = succ_end(BB);<br>
> - if (sbbi == sbbe)<br>
> - readEdge(this,getEdge(BB,0),outWeight,outMissing);<br>
> - for ( ; sbbi != sbbe; ++sbbi ) {<br>
> - if (ProcessedSuccs.insert(*sbbi).second) {<br>
> - readEdge(this,getEdge(BB,*sbbi),outWeight,outMissing);<br>
> - }<br>
> - }<br>
> -<br>
> - double share;<br>
> - std::set<Edge>::iterator ei,ee;<br>
> - if (inMissing.size() == 0 && outMissing.size() > 0) {<br>
> - ei = outMissing.begin();<br>
> - ee = outMissing.end();<br>
> - share = inWeight/outMissing.size();<br>
> - setExecutionCount(BB,inWeight);<br>
> - } else<br>
> - if (inMissing.size() > 0 && outMissing.size() == 0 && outWeight == 0) {<br>
> - ei = inMissing.begin();<br>
> - ee = inMissing.end();<br>
> - share = 0;<br>
> - setExecutionCount(BB,0);<br>
> - } else<br>
> - if (inMissing.size() == 0 && outMissing.size() == 0) {<br>
> - setExecutionCount(BB,outWeight);<br>
> - return true;<br>
> - } else {<br>
> - return false;<br>
> - }<br>
> - for ( ; ei != ee; ++ei ) {<br>
> - setEdgeWeight(*ei,share);<br>
> - }<br>
> - return true;<br>
> -}<br>
> -<br>
> -template<><br>
> -void ProfileInfoT<Function,BasicBlock>::repair(const Function *F) {<br>
> -// if (getExecutionCount(&(F->getEntryBlock())) == 0) {<br>
> -// for (Function::const_iterator FI = F->begin(), FE = F->end();<br>
> -// FI != FE; ++FI) {<br>
> -// const BasicBlock* BB = &(*FI);<br>
> -// {<br>
> -// const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB);<br>
> -// if (NBB == End) {<br>
> -// setEdgeWeight(getEdge(0,BB),0);<br>
> -// }<br>
> -// for(;NBB != End; ++NBB) {<br>
> -// setEdgeWeight(getEdge(*NBB,BB),0);<br>
> -// }<br>
> -// }<br>
> -// {<br>
> -// succ_const_iterator NBB = succ_begin(BB), End = succ_end(BB);<br>
> -// if (NBB == End) {<br>
> -// setEdgeWeight(getEdge(0,BB),0);<br>
> -// }<br>
> -// for(;NBB != End; ++NBB) {<br>
> -// setEdgeWeight(getEdge(*NBB,BB),0);<br>
> -// }<br>
> -// }<br>
> -// }<br>
> -// return;<br>
> -// }<br>
> - // The set of BasicBlocks that are still unvisited.<br>
> - std::set<const BasicBlock*> Unvisited;<br>
> -<br>
> - // The set of return edges (Edges with no successors).<br>
> - std::set<Edge> ReturnEdges;<br>
> - double ReturnWeight = 0;<br>
> -<br>
> - // First iterate over the whole function and collect:<br>
> - // 1) The blocks in this function in the Unvisited set.<br>
> - // 2) The return edges in the ReturnEdges set.<br>
> - // 3) The flow that is leaving the function already via return edges.<br>
> -<br>
> - // Data structure for searching the function.<br>
> - std::queue<const BasicBlock *> BFS;<br>
> - const BasicBlock *BB = &(F->getEntryBlock());<br>
> - BFS.push(BB);<br>
> - Unvisited.insert(BB);<br>
> -<br>
> - while (BFS.size()) {<br>
> - BB = BFS.front(); BFS.pop();<br>
> - succ_const_iterator NBB = succ_begin(BB), End = succ_end(BB);<br>
> - if (NBB == End) {<br>
> - Edge e = getEdge(BB,0);<br>
> - double w = getEdgeWeight(e);<br>
> - if (w == MissingValue) {<br>
> - // If the return edge has no value, try to read value from block.<br>
> - double bw = getExecutionCount(BB);<br>
> - if (bw != MissingValue) {<br>
> - setEdgeWeight(e,bw);<br>
> - ReturnWeight += bw;<br>
> - } else {<br>
> - // If both return edge and block provide no value, collect edge.<br>
> - ReturnEdges.insert(e);<br>
> - }<br>
> - } else {<br>
> - // If the return edge has a proper value, collect it.<br>
> - ReturnWeight += w;<br>
> - }<br>
> - }<br>
> - for (;NBB != End; ++NBB) {<br>
> - if (Unvisited.insert(*NBB).second) {<br>
> - BFS.push(*NBB);<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - while (Unvisited.size() > 0) {<br>
> - unsigned oldUnvisitedCount = Unvisited.size();<br>
> - bool FoundPath = false;<br>
> -<br>
> - // If there is only one edge left, calculate it.<br>
> - if (ReturnEdges.size() == 1) {<br>
> - ReturnWeight = getExecutionCount(&(F->getEntryBlock())) - ReturnWeight;<br>
> -<br>
> - Edge e = *ReturnEdges.begin();<br>
> - setEdgeWeight(e,ReturnWeight);<br>
> - setExecutionCount(e.first,ReturnWeight);<br>
> -<br>
> - Unvisited.erase(e.first);<br>
> - ReturnEdges.erase(e);<br>
> - continue;<br>
> - }<br>
> -<br>
> - // Calculate all blocks where only one edge is missing, this may also<br>
> - // resolve furhter return edges.<br>
> - std::set<const BasicBlock *>::iterator FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE) {<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> - Edge e;<br>
> - if(CalculateMissingEdge(BB,e,true)) {<br>
> - if (BlockInformation[F].find(BB) == BlockInformation[F].end()) {<br>
> - setExecutionCount(BB,getExecutionCount(BB));<br>
> - }<br>
> - Unvisited.erase(BB);<br>
> - if (e.first != 0 && e.second == 0) {<br>
> - ReturnEdges.erase(e);<br>
> - ReturnWeight += getEdgeWeight(e);<br>
> - }<br>
> - }<br>
> - }<br>
> - if (oldUnvisitedCount > Unvisited.size()) continue;<br>
> -<br>
> - // Estimate edge weights by dividing the flow proportionally.<br>
> - FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE) {<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> - const BasicBlock *Dest = 0;<br>
> - bool AllEdgesHaveSameReturn = true;<br>
> - // Check each Successor, these must all end up in the same or an empty<br>
> - // return block otherwise its dangerous to do an estimation on them.<br>
> - for (succ_const_iterator Succ = succ_begin(BB), End = succ_end(BB);<br>
> - Succ != End; ++Succ) {<br>
> - Path P;<br>
> - GetPath(*Succ, 0, P, GetPathToExit);<br>
> - if (Dest && Dest != P[(const BasicBlock*)0]) {<br>
> - AllEdgesHaveSameReturn = false;<br>
> - }<br>
> - Dest = P[(const BasicBlock*)0];<br>
> - }<br>
> - if (AllEdgesHaveSameReturn) {<br>
> - if(EstimateMissingEdges(BB)) {<br>
> - Unvisited.erase(BB);<br>
> - break;<br>
> - }<br>
> - }<br>
> - }<br>
> - if (oldUnvisitedCount > Unvisited.size()) continue;<br>
> -<br>
> - // Check if there is a path to an block that has a known value and redirect<br>
> - // flow accordingly.<br>
> - FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE && !FoundPath) {<br>
> - // Fetch path.<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> - Path P;<br>
> - const BasicBlock *Dest = GetPath(BB, 0, P, GetPathToValue);<br>
> -<br>
> - // Calculate incoming flow.<br>
> - double iw = 0; unsigned inmissing = 0; unsigned incount = 0; unsigned invalid = 0;<br>
> - std::set<const BasicBlock *> Processed;<br>
> - for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - if (Processed.insert(*NBB).second) {<br>
> - Edge e = getEdge(*NBB, BB);<br>
> - double ew = getEdgeWeight(e);<br>
> - if (ew != MissingValue) {<br>
> - iw += ew;<br>
> - invalid++;<br>
> - } else {<br>
> - // If the path contains the successor, this means its a backedge,<br>
> - // do not count as missing.<br>
> - if (P.find(*NBB) == P.end())<br>
> - inmissing++;<br>
> - }<br>
> - incount++;<br>
> - }<br>
> - }<br>
> - if (inmissing == incount) continue;<br>
> - if (invalid == 0) continue;<br>
> -<br>
> - // Subtract (already) outgoing flow.<br>
> - Processed.clear();<br>
> - for (succ_const_iterator NBB = succ_begin(BB), End = succ_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - if (Processed.insert(*NBB).second) {<br>
> - Edge e = getEdge(BB, *NBB);<br>
> - double ew = getEdgeWeight(e);<br>
> - if (ew != MissingValue) {<br>
> - iw -= ew;<br>
> - }<br>
> - }<br>
> - }<br>
> - if (iw < 0) continue;<br>
> -<br>
> - // Check the receiving end of the path if it can handle the flow.<br>
> - double ow = getExecutionCount(Dest);<br>
> - Processed.clear();<br>
> - for (succ_const_iterator NBB = succ_begin(BB), End = succ_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - if (Processed.insert(*NBB).second) {<br>
> - Edge e = getEdge(BB, *NBB);<br>
> - double ew = getEdgeWeight(e);<br>
> - if (ew != MissingValue) {<br>
> - ow -= ew;<br>
> - }<br>
> - }<br>
> - }<br>
> - if (ow < 0) continue;<br>
> -<br>
> - // Determine how much flow shall be used.<br>
> - double ew = getEdgeWeight(getEdge(P[Dest],Dest));<br>
> - if (ew != MissingValue) {<br>
> - ew = ew<ow?ew:ow;<br>
> - ew = ew<iw?ew:iw;<br>
> - } else {<br>
> - if (inmissing == 0)<br>
> - ew = iw;<br>
> - }<br>
> -<br>
> - // Create flow.<br>
> - if (ew != MissingValue) {<br>
> - do {<br>
> - Edge e = getEdge(P[Dest],Dest);<br>
> - if (getEdgeWeight(e) == MissingValue) {<br>
> - setEdgeWeight(e,ew);<br>
> - FoundPath = true;<br>
> - }<br>
> - Dest = P[Dest];<br>
> - } while (Dest != BB);<br>
> - }<br>
> - }<br>
> - if (FoundPath) continue;<br>
> -<br>
> - // Calculate a block with self loop.<br>
> - FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE && !FoundPath) {<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> - bool SelfEdgeFound = false;<br>
> - for (succ_const_iterator NBB = succ_begin(BB), End = succ_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - if (*NBB == BB) {<br>
> - SelfEdgeFound = true;<br>
> - break;<br>
> - }<br>
> - }<br>
> - if (SelfEdgeFound) {<br>
> - Edge e = getEdge(BB,BB);<br>
> - if (getEdgeWeight(e) == MissingValue) {<br>
> - double iw = 0;<br>
> - std::set<const BasicBlock *> Processed;<br>
> - for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - if (Processed.insert(*NBB).second) {<br>
> - Edge e = getEdge(*NBB, BB);<br>
> - double ew = getEdgeWeight(e);<br>
> - if (ew != MissingValue) {<br>
> - iw += ew;<br>
> - }<br>
> - }<br>
> - }<br>
> - setEdgeWeight(e,iw * 10);<br>
> - FoundPath = true;<br>
> - }<br>
> - }<br>
> - }<br>
> - if (FoundPath) continue;<br>
> -<br>
> - // Determine backedges, set them to zero.<br>
> - FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE && !FoundPath) {<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> - const BasicBlock *Dest = 0;<br>
> - Path P;<br>
> - bool BackEdgeFound = false;<br>
> - for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - Dest = GetPath(BB, *NBB, P, GetPathToDest | GetPathWithNewEdges);<br>
> - if (Dest == *NBB) {<br>
> - BackEdgeFound = true;<br>
> - break;<br>
> - }<br>
> - }<br>
> - if (BackEdgeFound) {<br>
> - Edge e = getEdge(Dest,BB);<br>
> - double w = getEdgeWeight(e);<br>
> - if (w == MissingValue) {<br>
> - setEdgeWeight(e,0);<br>
> - FoundPath = true;<br>
> - }<br>
> - do {<br>
> - Edge e = getEdge(P[Dest], Dest);<br>
> - double w = getEdgeWeight(e);<br>
> - if (w == MissingValue) {<br>
> - setEdgeWeight(e,0);<br>
> - FoundPath = true;<br>
> - }<br>
> - Dest = P[Dest];<br>
> - } while (Dest != BB);<br>
> - }<br>
> - }<br>
> - if (FoundPath) continue;<br>
> -<br>
> - // Channel flow to return block.<br>
> - FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE && !FoundPath) {<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> -<br>
> - Path P;<br>
> - const BasicBlock *Dest = GetPath(BB, 0, P, GetPathToExit | GetPathWithNewEdges);<br>
> - Dest = P[(const BasicBlock*)0];<br>
> - if (!Dest) continue;<br>
> -<br>
> - if (getEdgeWeight(getEdge(Dest,0)) == MissingValue) {<br>
> - // Calculate incoming flow.<br>
> - double iw = 0;<br>
> - std::set<const BasicBlock *> Processed;<br>
> - for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - if (Processed.insert(*NBB).second) {<br>
> - Edge e = getEdge(*NBB, BB);<br>
> - double ew = getEdgeWeight(e);<br>
> - if (ew != MissingValue) {<br>
> - iw += ew;<br>
> - }<br>
> - }<br>
> - }<br>
> - do {<br>
> - Edge e = getEdge(P[Dest], Dest);<br>
> - double w = getEdgeWeight(e);<br>
> - if (w == MissingValue) {<br>
> - setEdgeWeight(e,iw);<br>
> - FoundPath = true;<br>
> - } else {<br>
> - assert(0 && "Edge should not have value already!");<br>
> - }<br>
> - Dest = P[Dest];<br>
> - } while (Dest != BB);<br>
> - }<br>
> - }<br>
> - if (FoundPath) continue;<br>
> -<br>
> - // Speculatively set edges to zero.<br>
> - FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE && !FoundPath) {<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> -<br>
> - for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB);<br>
> - NBB != End; ++NBB) {<br>
> - Edge e = getEdge(*NBB,BB);<br>
> - double w = getEdgeWeight(e);<br>
> - if (w == MissingValue) {<br>
> - setEdgeWeight(e,0);<br>
> - FoundPath = true;<br>
> - break;<br>
> - }<br>
> - }<br>
> - }<br>
> - if (FoundPath) continue;<br>
> -<br>
> - errs() << "{";<br>
> - FI = Unvisited.begin(), FE = Unvisited.end();<br>
> - while(FI != FE) {<br>
> - const BasicBlock *BB = *FI; ++FI;<br>
> - dbgs() << BB->getName();<br>
> - if (FI != FE)<br>
> - dbgs() << ",";<br>
> - }<br>
> - errs() << "}";<br>
> -<br>
> - errs() << "ASSERT: could not repair function";<br>
> - assert(0 && "could not repair function");<br>
> - }<br>
> -<br>
> - EdgeWeights J = EdgeInformation[F];<br>
> - for (EdgeWeights::iterator EI = J.begin(), EE = J.end(); EI != EE; ++EI) {<br>
> - Edge e = EI->first;<br>
> -<br>
> - bool SuccFound = false;<br>
> - if (e.first != 0) {<br>
> - succ_const_iterator NBB = succ_begin(e.first), End = succ_end(e.first);<br>
> - if (NBB == End) {<br>
> - if (0 == e.second) {<br>
> - SuccFound = true;<br>
> - }<br>
> - }<br>
> - for (;NBB != End; ++NBB) {<br>
> - if (*NBB == e.second) {<br>
> - SuccFound = true;<br>
> - break;<br>
> - }<br>
> - }<br>
> - if (!SuccFound) {<br>
> - removeEdge(e);<br>
> - }<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -raw_ostream& operator<<(raw_ostream &O, const MachineFunction *MF) {<br>
> - return O << MF->getFunction()->getName() << "(MF)";<br>
> -}<br>
> -<br>
> -raw_ostream& operator<<(raw_ostream &O, const MachineBasicBlock *MBB) {<br>
> - return O << MBB->getBasicBlock()->getName() << "(MB)";<br>
> -}<br>
> -<br>
> -raw_ostream& operator<<(raw_ostream &O, std::pair<const MachineBasicBlock *, const MachineBasicBlock *> E) {<br>
> - O << "(";<br>
> -<br>
> - if (E.first)<br>
> - O << E.first;<br>
> - else<br>
> - O << "0";<br>
> -<br>
> - O << ",";<br>
> -<br>
> - if (E.second)<br>
> - O << E.second;<br>
> - else<br>
> - O << "0";<br>
> -<br>
> - return O << ")";<br>
> -}<br>
> -<br>
> -} // namespace llvm<br>
> -<br>
> -//===----------------------------------------------------------------------===//<br>
> -// NoProfile ProfileInfo implementation<br>
> -//<br>
> -<br>
> -namespace {<br>
> - struct NoProfileInfo : public ImmutablePass, public ProfileInfo {<br>
> - static char ID; // Class identification, replacement for typeinfo<br>
> - NoProfileInfo() : ImmutablePass(ID) {<br>
> - initializeNoProfileInfoPass(*PassRegistry::getPassRegistry());<br>
> - }<br>
> -<br>
> - /// getAdjustedAnalysisPointer - This method is used when a pass implements<br>
> - /// an analysis interface through multiple inheritance. If needed, it<br>
> - /// should override this to adjust the this pointer as needed for the<br>
> - /// specified pass info.<br>
> - virtual void *getAdjustedAnalysisPointer(AnalysisID PI) {<br>
> - if (PI == &ProfileInfo::ID)<br>
> - return (ProfileInfo*)this;<br>
> - return this;<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "NoProfileInfo";<br>
> - }<br>
> - };<br>
> -} // End of anonymous namespace<br>
> -<br>
> -char NoProfileInfo::ID = 0;<br>
> -// Register this pass...<br>
> -INITIALIZE_AG_PASS(NoProfileInfo, ProfileInfo, "no-profile",<br>
> - "No Profile Information", false, true, true)<br>
> -<br>
> -ImmutablePass *llvm::createNoProfileInfoPass() { return new NoProfileInfo(); }<br>
><br>
> Removed: llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp (removed)<br>
> @@ -1,155 +0,0 @@<br>
> -//===- ProfileInfoLoad.cpp - Load profile information from disk -----------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// The ProfileInfoLoader class is used to load and represent profiling<br>
> -// information read in from the dump file.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "llvm/Analysis/ProfileInfoLoader.h"<br>
> -#include "llvm/Analysis/ProfileInfoTypes.h"<br>
> -#include "llvm/IR/InstrTypes.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <cstdio><br>
> -#include <cstdlib><br>
> -using namespace llvm;<br>
> -<br>
> -// ByteSwap - Byteswap 'Var' if 'Really' is true.<br>
> -//<br>
> -static inline unsigned ByteSwap(unsigned Var, bool Really) {<br>
> - if (!Really) return Var;<br>
> - return ((Var & (255U<< 0U)) << 24U) |<br>
> - ((Var & (255U<< 8U)) << 8U) |<br>
> - ((Var & (255U<<16U)) >> 8U) |<br>
> - ((Var & (255U<<24U)) >> 24U);<br>
> -}<br>
> -<br>
> -static unsigned AddCounts(unsigned A, unsigned B) {<br>
> - // If either value is undefined, use the other.<br>
> - if (A == ProfileInfoLoader::Uncounted) return B;<br>
> - if (B == ProfileInfoLoader::Uncounted) return A;<br>
> - return A + B;<br>
> -}<br>
> -<br>
> -static void ReadProfilingBlock(const char *ToolName, FILE *F,<br>
> - bool ShouldByteSwap,<br>
> - std::vector<unsigned> &Data) {<br>
> - // Read the number of entries...<br>
> - unsigned NumEntries;<br>
> - if (fread(&NumEntries, sizeof(unsigned), 1, F) != 1) {<br>
> - errs() << ToolName << ": data packet truncated!\n";<br>
> - perror(0);<br>
> - exit(1);<br>
> - }<br>
> - NumEntries = ByteSwap(NumEntries, ShouldByteSwap);<br>
> -<br>
> - // Read the counts...<br>
> - std::vector<unsigned> TempSpace(NumEntries);<br>
> -<br>
> - // Read in the block of data...<br>
> - if (fread(&TempSpace[0], sizeof(unsigned)*NumEntries, 1, F) != 1) {<br>
> - errs() << ToolName << ": data packet truncated!\n";<br>
> - perror(0);<br>
> - exit(1);<br>
> - }<br>
> -<br>
> - // Make sure we have enough space... The space is initialised to -1 to<br>
> - // facitiltate the loading of missing values for OptimalEdgeProfiling.<br>
> - if (Data.size() < NumEntries)<br>
> - Data.resize(NumEntries, ProfileInfoLoader::Uncounted);<br>
> -<br>
> - // Accumulate the data we just read into the data.<br>
> - if (!ShouldByteSwap) {<br>
> - for (unsigned i = 0; i != NumEntries; ++i) {<br>
> - Data[i] = AddCounts(TempSpace[i], Data[i]);<br>
> - }<br>
> - } else {<br>
> - for (unsigned i = 0; i != NumEntries; ++i) {<br>
> - Data[i] = AddCounts(ByteSwap(TempSpace[i], true), Data[i]);<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -const unsigned ProfileInfoLoader::Uncounted = ~0U;<br>
> -<br>
> -// ProfileInfoLoader ctor - Read the specified profiling data file, exiting the<br>
> -// program if the file is invalid or broken.<br>
> -//<br>
> -ProfileInfoLoader::ProfileInfoLoader(const char *ToolName,<br>
> - const std::string &Filename)<br>
> - : Filename(Filename) {<br>
> - FILE *F = fopen(Filename.c_str(), "rb");<br>
> - if (F == 0) {<br>
> - errs() << ToolName << ": Error opening '" << Filename << "': ";<br>
> - perror(0);<br>
> - exit(1);<br>
> - }<br>
> -<br>
> - // Keep reading packets until we run out of them.<br>
> - unsigned PacketType;<br>
> - while (fread(&PacketType, sizeof(unsigned), 1, F) == 1) {<br>
> - // If the low eight bits of the packet are zero, we must be dealing with an<br>
> - // endianness mismatch. Byteswap all words read from the profiling<br>
> - // information.<br>
> - bool ShouldByteSwap = (char)PacketType == 0;<br>
> - PacketType = ByteSwap(PacketType, ShouldByteSwap);<br>
> -<br>
> - switch (PacketType) {<br>
> - case ArgumentInfo: {<br>
> - unsigned ArgLength;<br>
> - if (fread(&ArgLength, sizeof(unsigned), 1, F) != 1) {<br>
> - errs() << ToolName << ": arguments packet truncated!\n";<br>
> - perror(0);<br>
> - exit(1);<br>
> - }<br>
> - ArgLength = ByteSwap(ArgLength, ShouldByteSwap);<br>
> -<br>
> - // Read in the arguments...<br>
> - std::vector<char> Chars(ArgLength+4);<br>
> -<br>
> - if (ArgLength)<br>
> - if (fread(&Chars[0], (ArgLength+3) & ~3, 1, F) != 1) {<br>
> - errs() << ToolName << ": arguments packet truncated!\n";<br>
> - perror(0);<br>
> - exit(1);<br>
> - }<br>
> - CommandLines.push_back(std::string(&Chars[0], &Chars[ArgLength]));<br>
> - break;<br>
> - }<br>
> -<br>
> - case FunctionInfo:<br>
> - ReadProfilingBlock(ToolName, F, ShouldByteSwap, FunctionCounts);<br>
> - break;<br>
> -<br>
> - case BlockInfo:<br>
> - ReadProfilingBlock(ToolName, F, ShouldByteSwap, BlockCounts);<br>
> - break;<br>
> -<br>
> - case EdgeInfo:<br>
> - ReadProfilingBlock(ToolName, F, ShouldByteSwap, EdgeCounts);<br>
> - break;<br>
> -<br>
> - case OptEdgeInfo:<br>
> - ReadProfilingBlock(ToolName, F, ShouldByteSwap, OptimalEdgeCounts);<br>
> - break;<br>
> -<br>
> - case BBTraceInfo:<br>
> - ReadProfilingBlock(ToolName, F, ShouldByteSwap, BBTrace);<br>
> - break;<br>
> -<br>
> - default:<br>
> - errs() << ToolName << ": Unknown packet type #" << PacketType << "!\n";<br>
> - exit(1);<br>
> - }<br>
> - }<br>
> -<br>
> - fclose(F);<br>
> -}<br>
> -<br>
><br>
> Removed: llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp (removed)<br>
> @@ -1,267 +0,0 @@<br>
> -//===- ProfileInfoLoaderPass.cpp - LLVM Pass to load profile info ---------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file implements a concrete implementation of profiling information that<br>
> -// loads the information from a profile dump file.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "profile-loader"<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/ADT/SmallSet.h"<br>
> -#include "llvm/ADT/Statistic.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> -#include "llvm/Analysis/ProfileInfoLoader.h"<br>
> -#include "llvm/IR/BasicBlock.h"<br>
> -#include "llvm/IR/InstrTypes.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CFG.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/Format.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <set><br>
> -using namespace llvm;<br>
> -<br>
> -STATISTIC(NumEdgesRead, "The # of edges read.");<br>
> -<br>
> -static cl::opt<std::string><br>
> -ProfileInfoFilename("profile-info-file", cl::init("llvmprof.out"),<br>
> - cl::value_desc("filename"),<br>
> - cl::desc("Profile file loaded by -profile-loader"));<br>
> -<br>
> -namespace {<br>
> - class LoaderPass : public ModulePass, public ProfileInfo {<br>
> - std::string Filename;<br>
> - std::set<Edge> SpanningTree;<br>
> - std::set<const BasicBlock*> BBisUnvisited;<br>
> - unsigned ReadCount;<br>
> - public:<br>
> - static char ID; // Class identification, replacement for typeinfo<br>
> - explicit LoaderPass(const std::string &filename = "")<br>
> - : ModulePass(ID), Filename(filename) {<br>
> - initializeLoaderPassPass(*PassRegistry::getPassRegistry());<br>
> - if (filename.empty()) Filename = ProfileInfoFilename;<br>
> - }<br>
> -<br>
> - virtual void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> - AU.setPreservesAll();<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "Profiling information loader";<br>
> - }<br>
> -<br>
> - // recurseBasicBlock() - Calculates the edge weights for as much basic<br>
> - // blocks as possbile.<br>
> - virtual void recurseBasicBlock(const BasicBlock *BB);<br>
> - virtual void readEdgeOrRemember(Edge, Edge&, unsigned &, double &);<br>
> - virtual void readEdge(ProfileInfo::Edge, std::vector<unsigned>&);<br>
> -<br>
> - /// getAdjustedAnalysisPointer - This method is used when a pass implements<br>
> - /// an analysis interface through multiple inheritance. If needed, it<br>
> - /// should override this to adjust the this pointer as needed for the<br>
> - /// specified pass info.<br>
> - virtual void *getAdjustedAnalysisPointer(AnalysisID PI) {<br>
> - if (PI == &ProfileInfo::ID)<br>
> - return (ProfileInfo*)this;<br>
> - return this;<br>
> - }<br>
> -<br>
> - /// run - Load the profile information from the specified file.<br>
> - virtual bool runOnModule(Module &M);<br>
> - };<br>
> -} // End of anonymous namespace<br>
> -<br>
> -char LoaderPass::ID = 0;<br>
> -INITIALIZE_AG_PASS(LoaderPass, ProfileInfo, "profile-loader",<br>
> - "Load profile information from llvmprof.out", false, true, false)<br>
> -<br>
> -char &llvm::ProfileLoaderPassID = LoaderPass::ID;<br>
> -<br>
> -ModulePass *llvm::createProfileLoaderPass() { return new LoaderPass(); }<br>
> -<br>
> -/// createProfileLoaderPass - This function returns a Pass that loads the<br>
> -/// profiling information for the module from the specified filename, making it<br>
> -/// available to the optimizers.<br>
> -Pass *llvm::createProfileLoaderPass(const std::string &Filename) {<br>
> - return new LoaderPass(Filename);<br>
> -}<br>
> -<br>
> -void LoaderPass::readEdgeOrRemember(Edge edge, Edge &tocalc,<br>
> - unsigned &uncalc, double &count) {<br>
> - double w;<br>
> - if ((w = getEdgeWeight(edge)) == MissingValue) {<br>
> - tocalc = edge;<br>
> - uncalc++;<br>
> - } else {<br>
> - count+=w;<br>
> - }<br>
> -}<br>
> -<br>
> -// recurseBasicBlock - Visits all neighbours of a block and then tries to<br>
> -// calculate the missing edge values.<br>
> -void LoaderPass::recurseBasicBlock(const BasicBlock *BB) {<br>
> -<br>
> - // break recursion if already visited<br>
> - if (BBisUnvisited.find(BB) == BBisUnvisited.end()) return;<br>
> - BBisUnvisited.erase(BB);<br>
> - if (!BB) return;<br>
> -<br>
> - for (succ_const_iterator bbi = succ_begin(BB), bbe = succ_end(BB);<br>
> - bbi != bbe; ++bbi) {<br>
> - recurseBasicBlock(*bbi);<br>
> - }<br>
> - for (const_pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB);<br>
> - bbi != bbe; ++bbi) {<br>
> - recurseBasicBlock(*bbi);<br>
> - }<br>
> -<br>
> - Edge tocalc;<br>
> - if (CalculateMissingEdge(BB, tocalc)) {<br>
> - SpanningTree.erase(tocalc);<br>
> - }<br>
> -}<br>
> -<br>
> -void LoaderPass::readEdge(ProfileInfo::Edge e,<br>
> - std::vector<unsigned> &ECs) {<br>
> - if (ReadCount < ECs.size()) {<br>
> - double weight = ECs[ReadCount++];<br>
> - if (weight != ProfileInfoLoader::Uncounted) {<br>
> - // Here the data realm changes from the unsigned of the file to the<br>
> - // double of the ProfileInfo. This conversion is save because we know<br>
> - // that everything thats representable in unsinged is also representable<br>
> - // in double.<br>
> - EdgeInformation[getFunction(e)][e] += (double)weight;<br>
> -<br>
> - DEBUG(dbgs() << "--Read Edge Counter for " << e<br>
> - << " (# "<< (ReadCount-1) << "): "<br>
> - << (unsigned)getEdgeWeight(e) << "\n");<br>
> - } else {<br>
> - // This happens only if reading optimal profiling information, not when<br>
> - // reading regular profiling information.<br>
> - SpanningTree.insert(e);<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -bool LoaderPass::runOnModule(Module &M) {<br>
> - ProfileInfoLoader PIL("profile-loader", Filename);<br>
> -<br>
> - EdgeInformation.clear();<br>
> - std::vector<unsigned> Counters = PIL.getRawEdgeCounts();<br>
> - if (Counters.size() > 0) {<br>
> - ReadCount = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - DEBUG(dbgs() << "Working on " << F->getName() << "\n");<br>
> - readEdge(getEdge(0,&F->getEntryBlock()), Counters);<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - TerminatorInst *TI = BB->getTerminator();<br>
> - for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {<br>
> - readEdge(getEdge(BB,TI->getSuccessor(s)), Counters);<br>
> - }<br>
> - }<br>
> - }<br>
> - if (ReadCount != Counters.size()) {<br>
> - errs() << "WARNING: profile information is inconsistent with "<br>
> - << "the current program!\n";<br>
> - }<br>
> - NumEdgesRead = ReadCount;<br>
> - }<br>
> -<br>
> - Counters = PIL.getRawOptimalEdgeCounts();<br>
> - if (Counters.size() > 0) {<br>
> - ReadCount = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - DEBUG(dbgs() << "Working on " << F->getName() << "\n");<br>
> - readEdge(getEdge(0,&F->getEntryBlock()), Counters);<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - TerminatorInst *TI = BB->getTerminator();<br>
> - if (TI->getNumSuccessors() == 0) {<br>
> - readEdge(getEdge(BB,0), Counters);<br>
> - }<br>
> - for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {<br>
> - readEdge(getEdge(BB,TI->getSuccessor(s)), Counters);<br>
> - }<br>
> - }<br>
> - while (SpanningTree.size() > 0) {<br>
> -<br>
> - unsigned size = SpanningTree.size();<br>
> -<br>
> - BBisUnvisited.clear();<br>
> - for (std::set<Edge>::iterator ei = SpanningTree.begin(),<br>
> - ee = SpanningTree.end(); ei != ee; ++ei) {<br>
> - BBisUnvisited.insert(ei->first);<br>
> - BBisUnvisited.insert(ei->second);<br>
> - }<br>
> - while (BBisUnvisited.size() > 0) {<br>
> - recurseBasicBlock(*BBisUnvisited.begin());<br>
> - }<br>
> -<br>
> - if (SpanningTree.size() == size) {<br>
> - DEBUG(dbgs()<<"{");<br>
> - for (std::set<Edge>::iterator ei = SpanningTree.begin(),<br>
> - ee = SpanningTree.end(); ei != ee; ++ei) {<br>
> - DEBUG(dbgs()<< *ei <<",");<br>
> - }<br>
> - assert(0 && "No edge calculated!");<br>
> - }<br>
> -<br>
> - }<br>
> - }<br>
> - if (ReadCount != Counters.size()) {<br>
> - errs() << "WARNING: profile information is inconsistent with "<br>
> - << "the current program!\n";<br>
> - }<br>
> - NumEdgesRead = ReadCount;<br>
> - }<br>
> -<br>
> - BlockInformation.clear();<br>
> - Counters = PIL.getRawBlockCounts();<br>
> - if (Counters.size() > 0) {<br>
> - ReadCount = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)<br>
> - if (ReadCount < Counters.size())<br>
> - // Here the data realm changes from the unsigned of the file to the<br>
> - // double of the ProfileInfo. This conversion is save because we know<br>
> - // that everything thats representable in unsinged is also<br>
> - // representable in double.<br>
> - BlockInformation[F][BB] = (double)Counters[ReadCount++];<br>
> - }<br>
> - if (ReadCount != Counters.size()) {<br>
> - errs() << "WARNING: profile information is inconsistent with "<br>
> - << "the current program!\n";<br>
> - }<br>
> - }<br>
> -<br>
> - FunctionInformation.clear();<br>
> - Counters = PIL.getRawFunctionCounts();<br>
> - if (Counters.size() > 0) {<br>
> - ReadCount = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - if (ReadCount < Counters.size())<br>
> - // Here the data realm changes from the unsigned of the file to the<br>
> - // double of the ProfileInfo. This conversion is save because we know<br>
> - // that everything thats representable in unsinged is also<br>
> - // representable in double.<br>
> - FunctionInformation[F] = (double)Counters[ReadCount++];<br>
> - }<br>
> - if (ReadCount != Counters.size()) {<br>
> - errs() << "WARNING: profile information is inconsistent with "<br>
> - << "the current program!\n";<br>
> - }<br>
> - }<br>
> -<br>
> - return false;<br>
> -}<br>
><br>
> Removed: llvm/trunk/lib/Analysis/ProfileVerifierPass.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileVerifierPass.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileVerifierPass.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/ProfileVerifierPass.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ProfileVerifierPass.cpp (removed)<br>
> @@ -1,383 +0,0 @@<br>
> -//===- ProfileVerifierPass.cpp - LLVM Pass to estimate profile info -------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file implements a pass that checks profiling information for<br>
> -// plausibility.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "profile-verifier"<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> -#include "llvm/IR/Instructions.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CFG.h"<br>
> -#include "llvm/Support/CallSite.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/Format.h"<br>
> -#include "llvm/Support/InstIterator.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <set><br>
> -using namespace llvm;<br>
> -<br>
> -static cl::opt<bool,false><br>
> -ProfileVerifierDisableAssertions("profile-verifier-noassert",<br>
> - cl::desc("Disable assertions"));<br>
> -<br>
> -namespace {<br>
> - template<class FType, class BType><br>
> - class ProfileVerifierPassT : public FunctionPass {<br>
> -<br>
> - struct DetailedBlockInfo {<br>
> - const BType *BB;<br>
> - double BBWeight;<br>
> - double inWeight;<br>
> - int inCount;<br>
> - double outWeight;<br>
> - int outCount;<br>
> - };<br>
> -<br>
> - ProfileInfoT<FType, BType> *PI;<br>
> - std::set<const BType*> BBisVisited;<br>
> - std::set<const FType*> FisVisited;<br>
> - bool DisableAssertions;<br>
> -<br>
> - // When debugging is enabled, the verifier prints a whole slew of debug<br>
> - // information, otherwise its just the assert. These are all the helper<br>
> - // functions.<br>
> - bool PrintedDebugTree;<br>
> - std::set<const BType*> BBisPrinted;<br>
> - void debugEntry(DetailedBlockInfo*);<br>
> - void printDebugInfo(const BType *BB);<br>
> -<br>
> - public:<br>
> - static char ID; // Class identification, replacement for typeinfo<br>
> -<br>
> - explicit ProfileVerifierPassT () : FunctionPass(ID) {<br>
> - initializeProfileVerifierPassPass(*PassRegistry::getPassRegistry());<br>
> - DisableAssertions = ProfileVerifierDisableAssertions;<br>
> - }<br>
> - explicit ProfileVerifierPassT (bool da) : FunctionPass(ID),<br>
> - DisableAssertions(da) {<br>
> - initializeProfileVerifierPassPass(*PassRegistry::getPassRegistry());<br>
> - }<br>
> -<br>
> - void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> - AU.setPreservesAll();<br>
> - AU.addRequired<ProfileInfoT<FType, BType> >();<br>
> - }<br>
> -<br>
> - const char *getPassName() const {<br>
> - return "Profiling information verifier";<br>
> - }<br>
> -<br>
> - /// run - Verify the profile information.<br>
> - bool runOnFunction(FType &F);<br>
> - void recurseBasicBlock(const BType*);<br>
> -<br>
> - bool exitReachable(const FType*);<br>
> - double ReadOrAssert(typename ProfileInfoT<FType, BType>::Edge);<br>
> - void CheckValue(bool, const char*, DetailedBlockInfo*);<br>
> - };<br>
> -<br>
> - typedef ProfileVerifierPassT<Function, BasicBlock> ProfileVerifierPass;<br>
> -<br>
> - template<class FType, class BType><br>
> - void ProfileVerifierPassT<FType, BType>::printDebugInfo(const BType *BB) {<br>
> -<br>
> - if (BBisPrinted.find(BB) != BBisPrinted.end()) return;<br>
> -<br>
> - double BBWeight = PI->getExecutionCount(BB);<br>
> - if (BBWeight == ProfileInfoT<FType, BType>::MissingValue) { BBWeight = 0; }<br>
> - double inWeight = 0;<br>
> - int inCount = 0;<br>
> - std::set<const BType*> ProcessedPreds;<br>
> - for (const_pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB);<br>
> - bbi != bbe; ++bbi ) {<br>
> - if (ProcessedPreds.insert(*bbi).second) {<br>
> - typename ProfileInfoT<FType, BType>::Edge E = PI->getEdge(*bbi,BB);<br>
> - double EdgeWeight = PI->getEdgeWeight(E);<br>
> - if (EdgeWeight == ProfileInfoT<FType, BType>::MissingValue) { EdgeWeight = 0; }<br>
> - dbgs() << "calculated in-edge " << E << ": "<br>
> - << format("%20.20g",EdgeWeight) << "\n";<br>
> - inWeight += EdgeWeight;<br>
> - inCount++;<br>
> - }<br>
> - }<br>
> - double outWeight = 0;<br>
> - int outCount = 0;<br>
> - std::set<const BType*> ProcessedSuccs;<br>
> - for ( succ_const_iterator bbi = succ_begin(BB), bbe = succ_end(BB);<br>
> - bbi != bbe; ++bbi ) {<br>
> - if (ProcessedSuccs.insert(*bbi).second) {<br>
> - typename ProfileInfoT<FType, BType>::Edge E = PI->getEdge(BB,*bbi);<br>
> - double EdgeWeight = PI->getEdgeWeight(E);<br>
> - if (EdgeWeight == ProfileInfoT<FType, BType>::MissingValue) { EdgeWeight = 0; }<br>
> - dbgs() << "calculated out-edge " << E << ": "<br>
> - << format("%20.20g",EdgeWeight) << "\n";<br>
> - outWeight += EdgeWeight;<br>
> - outCount++;<br>
> - }<br>
> - }<br>
> - dbgs() << "Block " << BB->getName() << " in "<br>
> - << BB->getParent()->getName() << ":"<br>
> - << "BBWeight=" << format("%20.20g",BBWeight) << ","<br>
> - << "inWeight=" << format("%20.20g",inWeight) << ","<br>
> - << "inCount=" << inCount << ","<br>
> - << "outWeight=" << format("%20.20g",outWeight) << ","<br>
> - << "outCount" << outCount << "\n";<br>
> -<br>
> - // mark as visited and recurse into subnodes<br>
> - BBisPrinted.insert(BB);<br>
> - for ( succ_const_iterator bbi = succ_begin(BB), bbe = succ_end(BB);<br>
> - bbi != bbe; ++bbi ) {<br>
> - printDebugInfo(*bbi);<br>
> - }<br>
> - }<br>
> -<br>
> - template<class FType, class BType><br>
> - void ProfileVerifierPassT<FType, BType>::debugEntry (DetailedBlockInfo *DI) {<br>
> - dbgs() << "TROUBLE: Block " << DI->BB->getName() << " in "<br>
> - << DI->BB->getParent()->getName() << ":"<br>
> - << "BBWeight=" << format("%20.20g",DI->BBWeight) << ","<br>
> - << "inWeight=" << format("%20.20g",DI->inWeight) << ","<br>
> - << "inCount=" << DI->inCount << ","<br>
> - << "outWeight=" << format("%20.20g",DI->outWeight) << ","<br>
> - << "outCount=" << DI->outCount << "\n";<br>
> - if (!PrintedDebugTree) {<br>
> - PrintedDebugTree = true;<br>
> - printDebugInfo(&(DI->BB->getParent()->getEntryBlock()));<br>
> - }<br>
> - }<br>
> -<br>
> - // This compares A and B for equality.<br>
> - static bool Equals(double A, double B) {<br>
> - return A == B;<br>
> - }<br>
> -<br>
> - // This checks if the function "exit" is reachable from an given function<br>
> - // via calls, this is necessary to check if a profile is valid despite the<br>
> - // counts not fitting exactly.<br>
> - template<class FType, class BType><br>
> - bool ProfileVerifierPassT<FType, BType>::exitReachable(const FType *F) {<br>
> - if (!F) return false;<br>
> -<br>
> - if (FisVisited.count(F)) return false;<br>
> -<br>
> - FType *Exit = F->getParent()->getFunction("exit");<br>
> - if (Exit == F) {<br>
> - return true;<br>
> - }<br>
> -<br>
> - FisVisited.insert(F);<br>
> - bool exits = false;<br>
> - for (const_inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {<br>
> - if (const CallInst *CI = dyn_cast<CallInst>(&*I)) {<br>
> - FType *F = CI->getCalledFunction();<br>
> - if (F) {<br>
> - exits |= exitReachable(F);<br>
> - } else {<br>
> - // This is a call to a pointer, all bets are off...<br>
> - exits = true;<br>
> - }<br>
> - if (exits) break;<br>
> - }<br>
> - }<br>
> - return exits;<br>
> - }<br>
> -<br>
> - #define ASSERTMESSAGE(M) \<br>
> - { dbgs() << "ASSERT:" << (M) << "\n"; \<br>
> - if (!DisableAssertions) assert(0 && (M)); }<br>
> -<br>
> - template<class FType, class BType><br>
> - double ProfileVerifierPassT<FType, BType>::ReadOrAssert(typename ProfileInfoT<FType, BType>::Edge E) {<br>
> - double EdgeWeight = PI->getEdgeWeight(E);<br>
> - if (EdgeWeight == ProfileInfoT<FType, BType>::MissingValue) {<br>
> - dbgs() << "Edge " << E << " in Function "<br>
> - << ProfileInfoT<FType, BType>::getFunction(E)->getName() << ": ";<br>
> - ASSERTMESSAGE("Edge has missing value");<br>
> - return 0;<br>
> - } else {<br>
> - if (EdgeWeight < 0) {<br>
> - dbgs() << "Edge " << E << " in Function "<br>
> - << ProfileInfoT<FType, BType>::getFunction(E)->getName() << ": ";<br>
> - ASSERTMESSAGE("Edge has negative value");<br>
> - }<br>
> - return EdgeWeight;<br>
> - }<br>
> - }<br>
> -<br>
> - template<class FType, class BType><br>
> - void ProfileVerifierPassT<FType, BType>::CheckValue(bool Error,<br>
> - const char *Message,<br>
> - DetailedBlockInfo *DI) {<br>
> - if (Error) {<br>
> - DEBUG(debugEntry(DI));<br>
> - dbgs() << "Block " << DI->BB->getName() << " in Function "<br>
> - << DI->BB->getParent()->getName() << ": ";<br>
> - ASSERTMESSAGE(Message);<br>
> - }<br>
> - return;<br>
> - }<br>
> -<br>
> - // This calculates the Information for a block and then recurses into the<br>
> - // successors.<br>
> - template<class FType, class BType><br>
> - void ProfileVerifierPassT<FType, BType>::recurseBasicBlock(const BType *BB) {<br>
> -<br>
> - // Break the recursion by remembering all visited blocks.<br>
> - if (BBisVisited.find(BB) != BBisVisited.end()) return;<br>
> -<br>
> - // Use a data structure to store all the information, this can then be handed<br>
> - // to debug printers.<br>
> - DetailedBlockInfo DI;<br>
> - <a href="http://DI.BB" target="_blank">DI.BB</a> = BB;<br>
> - DI.outCount = DI.inCount = 0;<br>
> - DI.inWeight = DI.outWeight = 0;<br>
> -<br>
> - // Read predecessors.<br>
> - std::set<const BType*> ProcessedPreds;<br>
> - const_pred_iterator bpi = pred_begin(BB), bpe = pred_end(BB);<br>
> - // If there are none, check for (0,BB) edge.<br>
> - if (bpi == bpe) {<br>
> - DI.inWeight += ReadOrAssert(PI->getEdge(0,BB));<br>
> - DI.inCount++;<br>
> - }<br>
> - for (;bpi != bpe; ++bpi) {<br>
> - if (ProcessedPreds.insert(*bpi).second) {<br>
> - DI.inWeight += ReadOrAssert(PI->getEdge(*bpi,BB));<br>
> - DI.inCount++;<br>
> - }<br>
> - }<br>
> -<br>
> - // Read successors.<br>
> - std::set<const BType*> ProcessedSuccs;<br>
> - succ_const_iterator bbi = succ_begin(BB), bbe = succ_end(BB);<br>
> - // If there is an (0,BB) edge, consider it too. (This is done not only when<br>
> - // there are no successors, but every time; not every function contains<br>
> - // return blocks with no successors (think loop latch as return block)).<br>
> - double w = PI->getEdgeWeight(PI->getEdge(BB,0));<br>
> - if (w != ProfileInfoT<FType, BType>::MissingValue) {<br>
> - DI.outWeight += w;<br>
> - DI.outCount++;<br>
> - }<br>
> - for (;bbi != bbe; ++bbi) {<br>
> - if (ProcessedSuccs.insert(*bbi).second) {<br>
> - DI.outWeight += ReadOrAssert(PI->getEdge(BB,*bbi));<br>
> - DI.outCount++;<br>
> - }<br>
> - }<br>
> -<br>
> - // Read block weight.<br>
> - DI.BBWeight = PI->getExecutionCount(BB);<br>
> - CheckValue(DI.BBWeight == ProfileInfoT<FType, BType>::MissingValue,<br>
> - "BasicBlock has missing value", &DI);<br>
> - CheckValue(DI.BBWeight < 0,<br>
> - "BasicBlock has negative value", &DI);<br>
> -<br>
> - // Check if this block is a setjmp target.<br>
> - bool isSetJmpTarget = false;<br>
> - if (DI.outWeight > DI.inWeight) {<br>
> - for (typename BType::const_iterator i = BB->begin(), ie = BB->end();<br>
> - i != ie; ++i) {<br>
> - if (const CallInst *CI = dyn_cast<CallInst>(&*i)) {<br>
> - FType *F = CI->getCalledFunction();<br>
> - if (F && (F->getName() == "_setjmp")) {<br>
> - isSetJmpTarget = true; break;<br>
> - }<br>
> - }<br>
> - }<br>
> - }<br>
> - // Check if this block is eventually reaching exit.<br>
> - bool isExitReachable = false;<br>
> - if (DI.inWeight > DI.outWeight) {<br>
> - for (typename BType::const_iterator i = BB->begin(), ie = BB->end();<br>
> - i != ie; ++i) {<br>
> - if (const CallInst *CI = dyn_cast<CallInst>(&*i)) {<br>
> - FType *F = CI->getCalledFunction();<br>
> - if (F) {<br>
> - FisVisited.clear();<br>
> - isExitReachable |= exitReachable(F);<br>
> - } else {<br>
> - // This is a call to a pointer, all bets are off...<br>
> - isExitReachable = true;<br>
> - }<br>
> - if (isExitReachable) break;<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - if (DI.inCount > 0 && DI.outCount == 0) {<br>
> - // If this is a block with no successors.<br>
> - if (!isSetJmpTarget) {<br>
> - CheckValue(!Equals(DI.inWeight,DI.BBWeight),<br>
> - "inWeight and BBWeight do not match", &DI);<br>
> - }<br>
> - } else if (DI.inCount == 0 && DI.outCount > 0) {<br>
> - // If this is a block with no predecessors.<br>
> - if (!isExitReachable)<br>
> - CheckValue(!Equals(DI.BBWeight,DI.outWeight),<br>
> - "BBWeight and outWeight do not match", &DI);<br>
> - } else {<br>
> - // If this block has successors and predecessors.<br>
> - if (DI.inWeight > DI.outWeight && !isExitReachable)<br>
> - CheckValue(!Equals(DI.inWeight,DI.outWeight),<br>
> - "inWeight and outWeight do not match", &DI);<br>
> - if (DI.inWeight < DI.outWeight && !isSetJmpTarget)<br>
> - CheckValue(!Equals(DI.inWeight,DI.outWeight),<br>
> - "inWeight and outWeight do not match", &DI);<br>
> - }<br>
> -<br>
> -<br>
> - // Mark this block as visited, rescurse into successors.<br>
> - BBisVisited.insert(BB);<br>
> - for ( succ_const_iterator bbi = succ_begin(BB), bbe = succ_end(BB);<br>
> - bbi != bbe; ++bbi ) {<br>
> - recurseBasicBlock(*bbi);<br>
> - }<br>
> - }<br>
> -<br>
> - template<class FType, class BType><br>
> - bool ProfileVerifierPassT<FType, BType>::runOnFunction(FType &F) {<br>
> - PI = getAnalysisIfAvailable<ProfileInfoT<FType, BType> >();<br>
> - if (!PI)<br>
> - ASSERTMESSAGE("No ProfileInfo available");<br>
> -<br>
> - // Prepare global variables.<br>
> - PrintedDebugTree = false;<br>
> - BBisVisited.clear();<br>
> -<br>
> - // Fetch entry block and recurse into it.<br>
> - const BType *entry = &F.getEntryBlock();<br>
> - recurseBasicBlock(entry);<br>
> -<br>
> - if (PI->getExecutionCount(&F) != PI->getExecutionCount(entry))<br>
> - ASSERTMESSAGE("Function count and entry block count do not match");<br>
> -<br>
> - return false;<br>
> - }<br>
> -<br>
> - template<class FType, class BType><br>
> - char ProfileVerifierPassT<FType, BType>::ID = 0;<br>
> -}<br>
> -<br>
> -INITIALIZE_PASS_BEGIN(ProfileVerifierPass, "profile-verifier",<br>
> - "Verify profiling information", false, true)<br>
> -INITIALIZE_AG_DEPENDENCY(ProfileInfo)<br>
> -INITIALIZE_PASS_END(ProfileVerifierPass, "profile-verifier",<br>
> - "Verify profiling information", false, true)<br>
> -<br>
> -namespace llvm {<br>
> - FunctionPass *createProfileVerifierPass() {<br>
> - return new ProfileVerifierPass(ProfileVerifierDisableAssertions);<br>
> - }<br>
> -}<br>
> -<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp Wed Oct 2 10:42:23 2013<br>
> @@ -24,7 +24,6 @@<br>
> #include "llvm/ADT/DepthFirstIterator.h"<br>
> #include "llvm/ADT/SmallPtrSet.h"<br>
> #include "llvm/Analysis/Dominators.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> #include "llvm/CodeGen/MachineDominators.h"<br>
> #include "llvm/CodeGen/MachineFunctionPass.h"<br>
> #include "llvm/CodeGen/MachineLoopInfo.h"<br>
> @@ -50,7 +49,6 @@ namespace {<br>
><br>
> virtual void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> AU.addPreserved<DominatorTree>();<br>
> - AU.addPreserved<ProfileInfo>();<br>
> }<br>
> };<br>
> }<br>
> @@ -87,9 +85,7 @@ bool UnreachableBlockElim::runOnFunction<br>
> }<br>
><br>
> // Actually remove the blocks now.<br>
> - ProfileInfo *PI = getAnalysisIfAvailable<ProfileInfo>();<br>
> for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) {<br>
> - if (PI) PI->removeBlock(DeadBlocks[i]);<br>
> DeadBlocks[i]->eraseFromParent();<br>
> }<br>
><br>
><br>
> Modified: llvm/trunk/lib/Transforms/Instrumentation/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Instrumentation/CMakeLists.txt (original)<br>
> +++ llvm/trunk/lib/Transforms/Instrumentation/CMakeLists.txt Wed Oct 2 10:42:23 2013<br>
> @@ -3,12 +3,9 @@ add_llvm_library(LLVMInstrumentation<br>
> BoundsChecking.cpp<br>
> DataFlowSanitizer.cpp<br>
> DebugIR.cpp<br>
> - EdgeProfiling.cpp<br>
> GCOVProfiling.cpp<br>
> MemorySanitizer.cpp<br>
> Instrumentation.cpp<br>
> - OptimalEdgeProfiling.cpp<br>
> - PathProfiling.cpp<br>
> ProfilingUtils.cpp<br>
> ThreadSanitizer.cpp<br>
> )<br>
><br>
> Removed: llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp (removed)<br>
> @@ -1,117 +0,0 @@<br>
> -//===- EdgeProfiling.cpp - Insert counters for edge profiling -------------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This pass instruments the specified program with counters for edge profiling.<br>
> -// Edge profiling can give a reasonable approximation of the hot paths through a<br>
> -// program, and is used for a wide variety of program transformations.<br>
> -//<br>
> -// Note that this implementation is very naive. We insert a counter for *every*<br>
> -// edge in the program, instead of using control flow information to prune the<br>
> -// number of counters inserted.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "insert-edge-profiling"<br>
> -<br>
> -#include "llvm/Transforms/Instrumentation.h"<br>
> -#include "ProfilingUtils.h"<br>
> -#include "llvm/ADT/Statistic.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include "llvm/Transforms/Utils/BasicBlockUtils.h"<br>
> -#include <set><br>
> -using namespace llvm;<br>
> -<br>
> -STATISTIC(NumEdgesInserted, "The # of edges inserted.");<br>
> -<br>
> -namespace {<br>
> - class EdgeProfiler : public ModulePass {<br>
> - bool runOnModule(Module &M);<br>
> - public:<br>
> - static char ID; // Pass identification, replacement for typeid<br>
> - EdgeProfiler() : ModulePass(ID) {<br>
> - initializeEdgeProfilerPass(*PassRegistry::getPassRegistry());<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "Edge Profiler";<br>
> - }<br>
> - };<br>
> -}<br>
> -<br>
> -char EdgeProfiler::ID = 0;<br>
> -INITIALIZE_PASS(EdgeProfiler, "insert-edge-profiling",<br>
> - "Insert instrumentation for edge profiling", false, false)<br>
> -<br>
> -ModulePass *llvm::createEdgeProfilerPass() { return new EdgeProfiler(); }<br>
> -<br>
> -bool EdgeProfiler::runOnModule(Module &M) {<br>
> - Function *Main = M.getFunction("main");<br>
> - if (Main == 0) {<br>
> - errs() << "WARNING: cannot insert edge profiling into a module"<br>
> - << " with no main function!\n";<br>
> - return false; // No main, no instrumentation!<br>
> - }<br>
> -<br>
> - std::set<BasicBlock*> BlocksToInstrument;<br>
> - unsigned NumEdges = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - // Reserve space for (0,entry) edge.<br>
> - ++NumEdges;<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - // Keep track of which blocks need to be instrumented. We don't want to<br>
> - // instrument blocks that are added as the result of breaking critical<br>
> - // edges!<br>
> - BlocksToInstrument.insert(BB);<br>
> - NumEdges += BB->getTerminator()->getNumSuccessors();<br>
> - }<br>
> - }<br>
> -<br>
> - Type *ATy = ArrayType::get(Type::getInt32Ty(M.getContext()), NumEdges);<br>
> - GlobalVariable *Counters =<br>
> - new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,<br>
> - Constant::getNullValue(ATy), "EdgeProfCounters");<br>
> - NumEdgesInserted = NumEdges;<br>
> -<br>
> - // Instrument all of the edges...<br>
> - unsigned i = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - // Create counter for (0,entry) edge.<br>
> - IncrementCounterInBlock(&F->getEntryBlock(), i++, Counters);<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)<br>
> - if (BlocksToInstrument.count(BB)) { // Don't instrument inserted blocks<br>
> - // Okay, we have to add a counter of each outgoing edge. If the<br>
> - // outgoing edge is not critical don't split it, just insert the counter<br>
> - // in the source or destination of the edge.<br>
> - TerminatorInst *TI = BB->getTerminator();<br>
> - for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {<br>
> - // If the edge is critical, split it.<br>
> - SplitCriticalEdge(TI, s, this);<br>
> -<br>
> - // Okay, we are guaranteed that the edge is no longer critical. If we<br>
> - // only have a single successor, insert the counter in this block,<br>
> - // otherwise insert it in the successor block.<br>
> - if (TI->getNumSuccessors() == 1) {<br>
> - // Insert counter at the start of the block<br>
> - IncrementCounterInBlock(BB, i++, Counters, false);<br>
> - } else {<br>
> - // Insert counter at the start of the block<br>
> - IncrementCounterInBlock(TI->getSuccessor(s), i++, Counters);<br>
> - }<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - // Add the initialization call to main.<br>
> - InsertProfilingInitCall(Main, "llvm_start_edge_profiling", Counters);<br>
> - return true;<br>
> -}<br>
> -<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp Wed Oct 2 10:42:23 2013<br>
> @@ -24,10 +24,7 @@ void llvm::initializeInstrumentation(Pas<br>
> initializeAddressSanitizerPass(Registry);<br>
> initializeAddressSanitizerModulePass(Registry);<br>
> initializeBoundsCheckingPass(Registry);<br>
> - initializeEdgeProfilerPass(Registry);<br>
> initializeGCOVProfilerPass(Registry);<br>
> - initializeOptimalEdgeProfilerPass(Registry);<br>
> - initializePathProfilerPass(Registry);<br>
> initializeMemorySanitizerPass(Registry);<br>
> initializeThreadSanitizerPass(Registry);<br>
> initializeDataFlowSanitizerPass(Registry);<br>
><br>
> Removed: llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp (removed)<br>
> @@ -1,225 +0,0 @@<br>
> -//===- OptimalEdgeProfiling.cpp - Insert counters for opt. edge profiling -===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This pass instruments the specified program with counters for edge profiling.<br>
> -// Edge profiling can give a reasonable approximation of the hot paths through a<br>
> -// program, and is used for a wide variety of program transformations.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "insert-optimal-edge-profiling"<br>
> -#include "llvm/Transforms/Instrumentation.h"<br>
> -#include "MaximumSpanningTree.h"<br>
> -#include "ProfilingUtils.h"<br>
> -#include "llvm/ADT/DenseSet.h"<br>
> -#include "llvm/ADT/Statistic.h"<br>
> -#include "llvm/Analysis/Passes.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> -#include "llvm/Analysis/ProfileInfoLoader.h"<br>
> -#include "llvm/IR/Constants.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include "llvm/Transforms/Utils/BasicBlockUtils.h"<br>
> -using namespace llvm;<br>
> -<br>
> -STATISTIC(NumEdgesInserted, "The # of edges inserted.");<br>
> -<br>
> -namespace {<br>
> - class OptimalEdgeProfiler : public ModulePass {<br>
> - bool runOnModule(Module &M);<br>
> - public:<br>
> - static char ID; // Pass identification, replacement for typeid<br>
> - OptimalEdgeProfiler() : ModulePass(ID) {<br>
> - initializeOptimalEdgeProfilerPass(*PassRegistry::getPassRegistry());<br>
> - }<br>
> -<br>
> - void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> - AU.addRequiredID(ProfileEstimatorPassID);<br>
> - AU.addRequired<ProfileInfo>();<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "Optimal Edge Profiler";<br>
> - }<br>
> - };<br>
> -}<br>
> -<br>
> -char OptimalEdgeProfiler::ID = 0;<br>
> -INITIALIZE_PASS_BEGIN(OptimalEdgeProfiler, "insert-optimal-edge-profiling",<br>
> - "Insert optimal instrumentation for edge profiling",<br>
> - false, false)<br>
> -INITIALIZE_PASS_DEPENDENCY(ProfileEstimatorPass)<br>
> -INITIALIZE_AG_DEPENDENCY(ProfileInfo)<br>
> -INITIALIZE_PASS_END(OptimalEdgeProfiler, "insert-optimal-edge-profiling",<br>
> - "Insert optimal instrumentation for edge profiling",<br>
> - false, false)<br>
> -<br>
> -ModulePass *llvm::createOptimalEdgeProfilerPass() {<br>
> - return new OptimalEdgeProfiler();<br>
> -}<br>
> -<br>
> -inline static void printEdgeCounter(ProfileInfo::Edge e,<br>
> - BasicBlock* b,<br>
> - unsigned i) {<br>
> - DEBUG(dbgs() << "--Edge Counter for " << (e) << " in " \<br>
> - << ((b)?(b)->getName():"0") << " (# " << (i) << ")\n");<br>
> -}<br>
> -<br>
> -bool OptimalEdgeProfiler::runOnModule(Module &M) {<br>
> - Function *Main = M.getFunction("main");<br>
> - if (Main == 0) {<br>
> - errs() << "WARNING: cannot insert edge profiling into a module"<br>
> - << " with no main function!\n";<br>
> - return false; // No main, no instrumentation!<br>
> - }<br>
> -<br>
> - // NumEdges counts all the edges that may be instrumented. Later on its<br>
> - // decided which edges to actually instrument, to achieve optimal profiling.<br>
> - // For the entry block a virtual edge (0,entry) is reserved, for each block<br>
> - // with no successors an edge (BB,0) is reserved. These edges are necessary<br>
> - // to calculate a truly optimal maximum spanning tree and thus an optimal<br>
> - // instrumentation.<br>
> - unsigned NumEdges = 0;<br>
> -<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - // Reserve space for (0,entry) edge.<br>
> - ++NumEdges;<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - // Keep track of which blocks need to be instrumented. We don't want to<br>
> - // instrument blocks that are added as the result of breaking critical<br>
> - // edges!<br>
> - if (BB->getTerminator()->getNumSuccessors() == 0) {<br>
> - // Reserve space for (BB,0) edge.<br>
> - ++NumEdges;<br>
> - } else {<br>
> - NumEdges += BB->getTerminator()->getNumSuccessors();<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - // In the profiling output a counter for each edge is reserved, but only few<br>
> - // are used. This is done to be able to read back in the profile without<br>
> - // calulating the maximum spanning tree again, instead each edge counter that<br>
> - // is not used is initialised with -1 to signal that this edge counter has to<br>
> - // be calculated from other edge counters on reading the profile info back<br>
> - // in.<br>
> -<br>
> - Type *Int32 = Type::getInt32Ty(M.getContext());<br>
> - ArrayType *ATy = ArrayType::get(Int32, NumEdges);<br>
> - GlobalVariable *Counters =<br>
> - new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,<br>
> - Constant::getNullValue(ATy), "OptEdgeProfCounters");<br>
> - NumEdgesInserted = 0;<br>
> -<br>
> - std::vector<Constant*> Initializer(NumEdges);<br>
> - Constant *Zero = ConstantInt::get(Int32, 0);<br>
> - Constant *Uncounted = ConstantInt::get(Int32, ProfileInfoLoader::Uncounted);<br>
> -<br>
> - // Instrument all of the edges not in MST...<br>
> - unsigned i = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {<br>
> - if (F->isDeclaration()) continue;<br>
> - DEBUG(dbgs() << "Working on " << F->getName() << "\n");<br>
> -<br>
> - // Calculate a Maximum Spanning Tree with the edge weights determined by<br>
> - // ProfileEstimator. ProfileEstimator also assign weights to the virtual<br>
> - // edges (0,entry) and (BB,0) (for blocks with no successors) and this<br>
> - // edges also participate in the maximum spanning tree calculation.<br>
> - // The third parameter of MaximumSpanningTree() has the effect that not the<br>
> - // actual MST is returned but the edges _not_ in the MST.<br>
> -<br>
> - ProfileInfo::EdgeWeights ECs =<br>
> - getAnalysis<ProfileInfo>(*F).getEdgeWeights(F);<br>
> - std::vector<ProfileInfo::EdgeWeight> EdgeVector(ECs.begin(), ECs.end());<br>
> - MaximumSpanningTree<BasicBlock> MST(EdgeVector);<br>
> - std::stable_sort(MST.begin(), MST.end());<br>
> -<br>
> - // Check if (0,entry) not in the MST. If not, instrument edge<br>
> - // (IncrementCounterInBlock()) and set the counter initially to zero, if<br>
> - // the edge is in the MST the counter is initialised to -1.<br>
> -<br>
> - BasicBlock *entry = &(F->getEntryBlock());<br>
> - ProfileInfo::Edge edge = ProfileInfo::getEdge(0, entry);<br>
> - if (!std::binary_search(MST.begin(), MST.end(), edge)) {<br>
> - printEdgeCounter(edge, entry, i);<br>
> - IncrementCounterInBlock(entry, i, Counters); ++NumEdgesInserted;<br>
> - Initializer[i++] = (Zero);<br>
> - } else{<br>
> - Initializer[i++] = (Uncounted);<br>
> - }<br>
> -<br>
> - // InsertedBlocks contains all blocks that were inserted for splitting an<br>
> - // edge, this blocks do not have to be instrumented.<br>
> - DenseSet<BasicBlock*> InsertedBlocks;<br>
> - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {<br>
> - // Check if block was not inserted and thus does not have to be<br>
> - // instrumented.<br>
> - if (InsertedBlocks.count(BB)) continue;<br>
> -<br>
> - // Okay, we have to add a counter of each outgoing edge not in MST. If<br>
> - // the outgoing edge is not critical don't split it, just insert the<br>
> - // counter in the source or destination of the edge. Also, if the block<br>
> - // has no successors, the virtual edge (BB,0) is processed.<br>
> - TerminatorInst *TI = BB->getTerminator();<br>
> - if (TI->getNumSuccessors() == 0) {<br>
> - ProfileInfo::Edge edge = ProfileInfo::getEdge(BB, 0);<br>
> - if (!std::binary_search(MST.begin(), MST.end(), edge)) {<br>
> - printEdgeCounter(edge, BB, i);<br>
> - IncrementCounterInBlock(BB, i, Counters); ++NumEdgesInserted;<br>
> - Initializer[i++] = (Zero);<br>
> - } else{<br>
> - Initializer[i++] = (Uncounted);<br>
> - }<br>
> - }<br>
> - for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {<br>
> - BasicBlock *Succ = TI->getSuccessor(s);<br>
> - ProfileInfo::Edge edge = ProfileInfo::getEdge(BB,Succ);<br>
> - if (!std::binary_search(MST.begin(), MST.end(), edge)) {<br>
> -<br>
> - // If the edge is critical, split it.<br>
> - bool wasInserted = SplitCriticalEdge(TI, s, this);<br>
> - Succ = TI->getSuccessor(s);<br>
> - if (wasInserted)<br>
> - InsertedBlocks.insert(Succ);<br>
> -<br>
> - // Okay, we are guaranteed that the edge is no longer critical. If<br>
> - // we only have a single successor, insert the counter in this block,<br>
> - // otherwise insert it in the successor block.<br>
> - if (TI->getNumSuccessors() == 1) {<br>
> - // Insert counter at the start of the block<br>
> - printEdgeCounter(edge, BB, i);<br>
> - IncrementCounterInBlock(BB, i, Counters); ++NumEdgesInserted;<br>
> - } else {<br>
> - // Insert counter at the start of the block<br>
> - printEdgeCounter(edge, Succ, i);<br>
> - IncrementCounterInBlock(Succ, i, Counters); ++NumEdgesInserted;<br>
> - }<br>
> - Initializer[i++] = (Zero);<br>
> - } else {<br>
> - Initializer[i++] = (Uncounted);<br>
> - }<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - // Check if the number of edges counted at first was the number of edges we<br>
> - // considered for instrumentation.<br>
> - assert(i == NumEdges && "the number of edges in counting array is wrong");<br>
> -<br>
> - // Assign the now completely defined initialiser to the array.<br>
> - Constant *init = ConstantArray::get(ATy, Initializer);<br>
> - Counters->setInitializer(init);<br>
> -<br>
> - // Add the initialization call to main.<br>
> - InsertProfilingInitCall(Main, "llvm_start_opt_edge_profiling", Counters);<br>
> - return true;<br>
> -}<br>
> -<br>
><br>
> Removed: llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp?rev=191834&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp?rev=191834&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Instrumentation/PathProfiling.cpp (removed)<br>
> @@ -1,1424 +0,0 @@<br>
> -//===- PathProfiling.cpp - Inserts counters for path profiling ------------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This pass instruments functions for Ball-Larus path profiling. Ball-Larus<br>
> -// profiling converts the CFG into a DAG by replacing backedges with edges<br>
> -// from entry to the start block and from the end block to exit. The paths<br>
> -// along the new DAG are enumrated, i.e. each path is given a path number.<br>
> -// Edges are instrumented to increment the path number register, such that the<br>
> -// path number register will equal the path number of the path taken at the<br>
> -// exit.<br>
> -//<br>
> -// This file defines classes for building a CFG for use with different stages<br>
> -// in the Ball-Larus path profiling instrumentation [Ball96]. The<br>
> -// requirements are formatting the llvm CFG into the Ball-Larus DAG, path<br>
> -// numbering, finding a spanning tree, moving increments from the spanning<br>
> -// tree to chords.<br>
> -//<br>
> -// Terms:<br>
> -// DAG - Directed Acyclic Graph.<br>
> -// Ball-Larus DAG - A CFG with an entry node, an exit node, and backedges<br>
> -// removed in the following manner. For every backedge<br>
> -// v->w, insert edge ENTRY->w and edge v->EXIT.<br>
> -// Path Number - The number corresponding to a specific path through a<br>
> -// Ball-Larus DAG.<br>
> -// Spanning Tree - A subgraph, S, is a spanning tree if S covers all<br>
> -// vertices and is a tree.<br>
> -// Chord - An edge not in the spanning tree.<br>
> -//<br>
> -// [Ball96]<br>
> -// T. Ball and J. R. Larus. "Efficient Path Profiling."<br>
> -// International Symposium on Microarchitecture, pages 46-57, 1996.<br>
> -// <a href="http://portal.acm.org/citation.cfm?id=243857" target="_blank">http://portal.acm.org/citation.cfm?id=243857</a><br>
> -//<br>
> -// [Ball94]<br>
> -// Thomas Ball. "Efficiently Counting Program Events with Support for<br>
> -// On-line queries."<br>
> -// ACM Transactions on Programmmg Languages and Systems, Vol 16, No 5,<br>
> -// September 1994, Pages 1399-1410.<br>
> -//===----------------------------------------------------------------------===//<br>
> -#define DEBUG_TYPE "insert-path-profiling"<br>
> -<br>
> -#include "llvm/Transforms/Instrumentation.h"<br>
> -#include "ProfilingUtils.h"<br>
> -#include "llvm/Analysis/PathNumbering.h"<br>
> -#include "llvm/IR/Constants.h"<br>
> -#include "llvm/IR/DerivedTypes.h"<br>
> -#include "llvm/IR/InstrTypes.h"<br>
> -#include "llvm/IR/Instructions.h"<br>
> -#include "llvm/IR/LLVMContext.h"<br>
> -#include "llvm/IR/Module.h"<br>
> -#include "llvm/IR/TypeBuilder.h"<br>
> -#include "llvm/Pass.h"<br>
> -#include "llvm/Support/CFG.h"<br>
> -#include "llvm/Support/CommandLine.h"<br>
> -#include "llvm/Support/Compiler.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include "llvm/Transforms/Utils/BasicBlockUtils.h"<br>
> -#include <vector><br>
> -<br>
> -#define HASH_THRESHHOLD 100000<br>
> -<br>
> -using namespace llvm;<br>
> -<br>
> -namespace {<br>
> -class BLInstrumentationNode;<br>
> -class BLInstrumentationEdge;<br>
> -class BLInstrumentationDag;<br>
> -<br>
> -// ---------------------------------------------------------------------------<br>
> -// BLInstrumentationNode extends BallLarusNode with member used by the<br>
> -// instrumentation algortihms.<br>
> -// ---------------------------------------------------------------------------<br>
> -class BLInstrumentationNode : public BallLarusNode {<br>
> -public:<br>
> - // Creates a new BLInstrumentationNode from a BasicBlock.<br>
> - BLInstrumentationNode(BasicBlock* BB);<br>
> -<br>
> - // Get/sets the Value corresponding to the pathNumber register,<br>
> - // constant or phinode. Used by the instrumentation code to remember<br>
> - // path number Values.<br>
> - Value* getStartingPathNumber();<br>
> - void setStartingPathNumber(Value* pathNumber);<br>
> -<br>
> - Value* getEndingPathNumber();<br>
> - void setEndingPathNumber(Value* pathNumber);<br>
> -<br>
> - // Get/set the PHINode Instruction for this node.<br>
> - PHINode* getPathPHI();<br>
> - void setPathPHI(PHINode* pathPHI);<br>
> -<br>
> -private:<br>
> -<br>
> - Value* _startingPathNumber; // The Value for the current pathNumber.<br>
> - Value* _endingPathNumber; // The Value for the current pathNumber.<br>
> - PHINode* _pathPHI; // The PHINode for current pathNumber.<br>
> -};<br>
> -<br>
> -// --------------------------------------------------------------------------<br>
> -// BLInstrumentationEdge extends BallLarusEdge with data about the<br>
> -// instrumentation that will end up on each edge.<br>
> -// --------------------------------------------------------------------------<br>
> -class BLInstrumentationEdge : public BallLarusEdge {<br>
> -public:<br>
> - BLInstrumentationEdge(BLInstrumentationNode* source,<br>
> - BLInstrumentationNode* target);<br>
> -<br>
> - // Sets the target node of this edge. Required to split edges.<br>
> - void setTarget(BallLarusNode* node);<br>
> -<br>
> - // Get/set whether edge is in the spanning tree.<br>
> - bool isInSpanningTree() const;<br>
> - void setIsInSpanningTree(bool isInSpanningTree);<br>
> -<br>
> - // Get/ set whether this edge will be instrumented with a path number<br>
> - // initialization.<br>
> - bool isInitialization() const;<br>
> - void setIsInitialization(bool isInitialization);<br>
> -<br>
> - // Get/set whether this edge will be instrumented with a path counter<br>
> - // increment. Notice this is incrementing the path counter<br>
> - // corresponding to the path number register. The path number<br>
> - // increment is determined by getIncrement().<br>
> - bool isCounterIncrement() const;<br>
> - void setIsCounterIncrement(bool isCounterIncrement);<br>
> -<br>
> - // Get/set the path number increment that this edge will be instrumented<br>
> - // with. This is distinct from the path counter increment and the<br>
> - // weight. The counter increment counts the number of executions of<br>
> - // some path, whereas the path number keeps track of which path number<br>
> - // the program is on.<br>
> - long getIncrement() const;<br>
> - void setIncrement(long increment);<br>
> -<br>
> - // Get/set whether the edge has been instrumented.<br>
> - bool hasInstrumentation();<br>
> - void setHasInstrumentation(bool hasInstrumentation);<br>
> -<br>
> - // Returns the successor number of this edge in the source.<br>
> - unsigned getSuccessorNumber();<br>
> -<br>
> -private:<br>
> - // The increment that the code will be instrumented with.<br>
> - long long _increment;<br>
> -<br>
> - // Whether this edge is in the spanning tree.<br>
> - bool _isInSpanningTree;<br>
> -<br>
> - // Whether this edge is an initialiation of the path number.<br>
> - bool _isInitialization;<br>
> -<br>
> - // Whether this edge is a path counter increment.<br>
> - bool _isCounterIncrement;<br>
> -<br>
> - // Whether this edge has been instrumented.<br>
> - bool _hasInstrumentation;<br>
> -};<br>
> -<br>
> -// ---------------------------------------------------------------------------<br>
> -// BLInstrumentationDag extends BallLarusDag with algorithms that<br>
> -// determine where instrumentation should be placed.<br>
> -// ---------------------------------------------------------------------------<br>
> -class BLInstrumentationDag : public BallLarusDag {<br>
> -public:<br>
> - BLInstrumentationDag(Function &F);<br>
> -<br>
> - // Returns the Exit->Root edge. This edge is required for creating<br>
> - // directed cycles in the algorithm for moving instrumentation off of<br>
> - // the spanning tree<br>
> - BallLarusEdge* getExitRootEdge();<br>
> -<br>
> - // Returns an array of phony edges which mark those nodes<br>
> - // with function calls<br>
> - BLEdgeVector getCallPhonyEdges();<br>
> -<br>
> - // Gets/sets the path counter array<br>
> - GlobalVariable* getCounterArray();<br>
> - void setCounterArray(GlobalVariable* c);<br>
> -<br>
> - // Calculates the increments for the chords, thereby removing<br>
> - // instrumentation from the spanning tree edges. Implementation is based<br>
> - // on the algorithm in Figure 4 of [Ball94]<br>
> - void calculateChordIncrements();<br>
> -<br>
> - // Updates the state when an edge has been split<br>
> - void splitUpdate(BLInstrumentationEdge* formerEdge, BasicBlock* newBlock);<br>
> -<br>
> - // Calculates a spanning tree of the DAG ignoring cycles. Whichever<br>
> - // edges are in the spanning tree will not be instrumented, but this<br>
> - // implementation does not try to minimize the instrumentation overhead<br>
> - // by trying to find hot edges.<br>
> - void calculateSpanningTree();<br>
> -<br>
> - // Pushes initialization further down in order to group the first<br>
> - // increment and initialization.<br>
> - void pushInitialization();<br>
> -<br>
> - // Pushes the path counter increments up in order to group the last path<br>
> - // number increment.<br>
> - void pushCounters();<br>
> -<br>
> - // Removes phony edges from the successor list of the source, and the<br>
> - // predecessor list of the target.<br>
> - void unlinkPhony();<br>
> -<br>
> - // Generate dot graph for the function<br>
> - void generateDotGraph();<br>
> -<br>
> -protected:<br>
> - // BLInstrumentationDag creates BLInstrumentationNode objects in this<br>
> - // method overriding the creation of BallLarusNode objects.<br>
> - //<br>
> - // Allows subclasses to determine which type of Node is created.<br>
> - // Override this method to produce subclasses of BallLarusNode if<br>
> - // necessary.<br>
> - virtual BallLarusNode* createNode(BasicBlock* BB);<br>
> -<br>
> - // BLInstrumentationDag create BLInstrumentationEdges.<br>
> - //<br>
> - // Allows subclasses to determine which type of Edge is created.<br>
> - // Override this method to produce subclasses of BallLarusEdge if<br>
> - // necessary. Parameters source and target will have been created by<br>
> - // createNode and can be cast to the subclass of BallLarusNode*<br>
> - // returned by createNode.<br>
> - virtual BallLarusEdge* createEdge(<br>
> - BallLarusNode* source, BallLarusNode* target, unsigned edgeNumber);<br>
> -<br>
> -private:<br>
> - BLEdgeVector _treeEdges; // All edges in the spanning tree.<br>
> - BLEdgeVector _chordEdges; // All edges not in the spanning tree.<br>
> - GlobalVariable* _counterArray; // Array to store path counters<br>
> -<br>
> - // Removes the edge from the appropriate predecessor and successor lists.<br>
> - void unlinkEdge(BallLarusEdge* edge);<br>
> -<br>
> - // Makes an edge part of the spanning tree.<br>
> - void makeEdgeSpanning(BLInstrumentationEdge* edge);<br>
> -<br>
> - // Pushes initialization and calls itself recursively.<br>
> - void pushInitializationFromEdge(BLInstrumentationEdge* edge);<br>
> -<br>
> - // Pushes path counter increments up recursively.<br>
> - void pushCountersFromEdge(BLInstrumentationEdge* edge);<br>
> -<br>
> - // Depth first algorithm for determining the chord increments.f<br>
> - void calculateChordIncrementsDfs(<br>
> - long weight, BallLarusNode* v, BallLarusEdge* e);<br>
> -<br>
> - // Determines the relative direction of two edges.<br>
> - int calculateChordIncrementsDir(BallLarusEdge* e, BallLarusEdge* f);<br>
> -};<br>
> -<br>
> -// ---------------------------------------------------------------------------<br>
> -// PathProfiler is a module pass which instruments path profiling instructions<br>
> -// ---------------------------------------------------------------------------<br>
> -class PathProfiler : public ModulePass {<br>
> -private:<br>
> - // Current context for multi threading support.<br>
> - LLVMContext* Context;<br>
> -<br>
> - // Which function are we currently instrumenting<br>
> - unsigned currentFunctionNumber;<br>
> -<br>
> - // The function prototype in the profiling runtime for incrementing a<br>
> - // single path counter in a hash table.<br>
> - Constant* llvmIncrementHashFunction;<br>
> - Constant* llvmDecrementHashFunction;<br>
> -<br>
> - // Instruments each function with path profiling. 'main' is instrumented<br>
> - // with code to save the profile to disk.<br>
> - bool runOnModule(Module &M);<br>
> -<br>
> - // Analyzes the function for Ball-Larus path profiling, and inserts code.<br>
> - void runOnFunction(std::vector<Constant*> &ftInit, Function &F, Module &M);<br>
> -<br>
> - // Creates an increment constant representing incr.<br>
> - ConstantInt* createIncrementConstant(long incr, int bitsize);<br>
> -<br>
> - // Creates an increment constant representing the value in<br>
> - // edge->getIncrement().<br>
> - ConstantInt* createIncrementConstant(BLInstrumentationEdge* edge);<br>
> -<br>
> - // Finds the insertion point after pathNumber in block. PathNumber may<br>
> - // be NULL.<br>
> - BasicBlock::iterator getInsertionPoint(<br>
> - BasicBlock* block, Value* pathNumber);<br>
> -<br>
> - // Inserts source's pathNumber Value* into target. Target may or may not<br>
> - // have multiple predecessors, and may or may not have its phiNode<br>
> - // initalized.<br>
> - void pushValueIntoNode(<br>
> - BLInstrumentationNode* source, BLInstrumentationNode* target);<br>
> -<br>
> - // Inserts source's pathNumber Value* into the appropriate slot of<br>
> - // target's phiNode.<br>
> - void pushValueIntoPHI(<br>
> - BLInstrumentationNode* target, BLInstrumentationNode* source);<br>
> -<br>
> - // The Value* in node, oldVal, is updated with a Value* correspodning to<br>
> - // oldVal + addition.<br>
> - void insertNumberIncrement(BLInstrumentationNode* node, Value* addition,<br>
> - bool atBeginning);<br>
> -<br>
> - // Creates a counter increment in the given node. The Value* in node is<br>
> - // taken as the index into a hash table.<br>
> - void insertCounterIncrement(<br>
> - Value* incValue,<br>
> - BasicBlock::iterator insertPoint,<br>
> - BLInstrumentationDag* dag,<br>
> - bool increment = true);<br>
> -<br>
> - // A PHINode is created in the node, and its values initialized to -1U.<br>
> - void preparePHI(BLInstrumentationNode* node);<br>
> -<br>
> - // Inserts instrumentation for the given edge<br>
> - //<br>
> - // Pre: The edge's source node has pathNumber set if edge is non zero<br>
> - // path number increment.<br>
> - //<br>
> - // Post: Edge's target node has a pathNumber set to the path number Value<br>
> - // corresponding to the value of the path register after edge's<br>
> - // execution.<br>
> - void insertInstrumentationStartingAt(<br>
> - BLInstrumentationEdge* edge,<br>
> - BLInstrumentationDag* dag);<br>
> -<br>
> - // If this edge is a critical edge, then inserts a node at this edge.<br>
> - // This edge becomes the first edge, and a new BallLarusEdge is created.<br>
> - bool splitCritical(BLInstrumentationEdge* edge, BLInstrumentationDag* dag);<br>
> -<br>
> - // Inserts instrumentation according to the marked edges in dag. Phony<br>
> - // edges must be unlinked from the DAG, but accessible from the<br>
> - // backedges. Dag must have initializations, path number increments, and<br>
> - // counter increments present.<br>
> - //<br>
> - // Counter storage is created here.<br>
> - void insertInstrumentation( BLInstrumentationDag& dag, Module &M);<br>
> -<br>
> -public:<br>
> - static char ID; // Pass identification, replacement for typeid<br>
> - PathProfiler() : ModulePass(ID) {<br>
> - initializePathProfilerPass(*PassRegistry::getPassRegistry());<br>
> - }<br>
> -<br>
> - virtual const char *getPassName() const {<br>
> - return "Path Profiler";<br>
> - }<br>
> -};<br>
> -} // end anonymous namespace<br>
> -<br>
> -// Should we print the dot-graphs<br>
> -static cl::opt<bool> DotPathDag("path-profile-pathdag", cl::Hidden,<br>
> - cl::desc("Output the path profiling DAG for each function."));<br>
> -<br>
> -// Register the path profiler as a pass<br>
> -char PathProfiler::ID = 0;<br>
> -INITIALIZE_PASS(PathProfiler, "insert-path-profiling",<br>
> - "Insert instrumentation for Ball-Larus path profiling",<br>
> - false, false)<br>
> -<br>
> -ModulePass *llvm::createPathProfilerPass() { return new PathProfiler(); }<br>
> -<br>
> -namespace llvm {<br>
> - class PathProfilingFunctionTable {};<br>
> -<br>
> - // Type for global array storing references to hashes or arrays<br>
> - template<bool xcompile> class TypeBuilder<PathProfilingFunctionTable,<br>
> - xcompile> {<br>
> - public:<br>
> - static StructType *get(LLVMContext& C) {<br>
> - return( StructType::get(<br>
> - TypeBuilder<types::i<32>, xcompile>::get(C), // type<br>
> - TypeBuilder<types::i<32>, xcompile>::get(C), // array size<br>
> - TypeBuilder<types::i<8>*, xcompile>::get(C), // array/hash ptr<br>
> - NULL));<br>
> - }<br>
> - };<br>
> -<br>
> - typedef TypeBuilder<PathProfilingFunctionTable, true><br>
> - ftEntryTypeBuilder;<br>
> -<br>
> - // BallLarusEdge << operator overloading<br>
> - raw_ostream& operator<<(raw_ostream& os,<br>
> - const BLInstrumentationEdge& edge)<br>
> - LLVM_ATTRIBUTE_USED;<br>
> - raw_ostream& operator<<(raw_ostream& os,<br>
> - const BLInstrumentationEdge& edge) {<br>
> - os << "[" << edge.getSource()->getName() << " -> "<br>
> - << edge.getTarget()->getName() << "] init: "<br>
> - << (edge.isInitialization() ? "yes" : "no")<br>
> - << " incr:" << edge.getIncrement() << " cinc: "<br>
> - << (edge.isCounterIncrement() ? "yes" : "no");<br>
> - return(os);<br>
> - }<br>
> -}<br>
> -<br>
> -// Creates a new BLInstrumentationNode from a BasicBlock.<br>
> -BLInstrumentationNode::BLInstrumentationNode(BasicBlock* BB) :<br>
> - BallLarusNode(BB),<br>
> - _startingPathNumber(NULL), _endingPathNumber(NULL), _pathPHI(NULL) {}<br>
> -<br>
> -// Constructor for BLInstrumentationEdge.<br>
> -BLInstrumentationEdge::BLInstrumentationEdge(BLInstrumentationNode* source,<br>
> - BLInstrumentationNode* target)<br>
> - : BallLarusEdge(source, target, 0),<br>
> - _increment(0), _isInSpanningTree(false), _isInitialization(false),<br>
> - _isCounterIncrement(false), _hasInstrumentation(false) {}<br>
> -<br>
> -// Sets the target node of this edge. Required to split edges.<br>
> -void BLInstrumentationEdge::setTarget(BallLarusNode* node) {<br>
> - _target = node;<br>
> -}<br>
> -<br>
> -// Returns whether this edge is in the spanning tree.<br>
> -bool BLInstrumentationEdge::isInSpanningTree() const {<br>
> - return(_isInSpanningTree);<br>
> -}<br>
> -<br>
> -// Sets whether this edge is in the spanning tree.<br>
> -void BLInstrumentationEdge::setIsInSpanningTree(bool isInSpanningTree) {<br>
> - _isInSpanningTree = isInSpanningTree;<br>
> -}<br>
> -<br>
> -// Returns whether this edge will be instrumented with a path number<br>
> -// initialization.<br>
> -bool BLInstrumentationEdge::isInitialization() const {<br>
> - return(_isInitialization);<br>
> -}<br>
> -<br>
> -// Sets whether this edge will be instrumented with a path number<br>
> -// initialization.<br>
> -void BLInstrumentationEdge::setIsInitialization(bool isInitialization) {<br>
> - _isInitialization = isInitialization;<br>
> -}<br>
> -<br>
> -// Returns whether this edge will be instrumented with a path counter<br>
> -// increment. Notice this is incrementing the path counter<br>
> -// corresponding to the path number register. The path number<br>
> -// increment is determined by getIncrement().<br>
> -bool BLInstrumentationEdge::isCounterIncrement() const {<br>
> - return(_isCounterIncrement);<br>
> -}<br>
> -<br>
> -// Sets whether this edge will be instrumented with a path counter<br>
> -// increment.<br>
> -void BLInstrumentationEdge::setIsCounterIncrement(bool isCounterIncrement) {<br>
> - _isCounterIncrement = isCounterIncrement;<br>
> -}<br>
> -<br>
> -// Gets the path number increment that this edge will be instrumented<br>
> -// with. This is distinct from the path counter increment and the<br>
> -// weight. The counter increment is counts the number of executions of<br>
> -// some path, whereas the path number keeps track of which path number<br>
> -// the program is on.<br>
> -long BLInstrumentationEdge::getIncrement() const {<br>
> - return(_increment);<br>
> -}<br>
> -<br>
> -// Set whether this edge will be instrumented with a path number<br>
> -// increment.<br>
> -void BLInstrumentationEdge::setIncrement(long increment) {<br>
> - _increment = increment;<br>
> -}<br>
> -<br>
> -// True iff the edge has already been instrumented.<br>
> -bool BLInstrumentationEdge::hasInstrumentation() {<br>
> - return(_hasInstrumentation);<br>
> -}<br>
> -<br>
> -// Set whether this edge has been instrumented.<br>
> -void BLInstrumentationEdge::setHasInstrumentation(bool hasInstrumentation) {<br>
> - _hasInstrumentation = hasInstrumentation;<br>
> -}<br>
> -<br>
> -// Returns the successor number of this edge in the source.<br>
> -unsigned BLInstrumentationEdge::getSuccessorNumber() {<br>
> - BallLarusNode* sourceNode = getSource();<br>
> - BallLarusNode* targetNode = getTarget();<br>
> - BasicBlock* source = sourceNode->getBlock();<br>
> - BasicBlock* target = targetNode->getBlock();<br>
> -<br>
> - if(source == NULL || target == NULL)<br>
> - return(0);<br>
> -<br>
> - TerminatorInst* terminator = source->getTerminator();<br>
> -<br>
> - unsigned i;<br>
> - for(i=0; i < terminator->getNumSuccessors(); i++) {<br>
> - if(terminator->getSuccessor(i) == target)<br>
> - break;<br>
> - }<br>
> -<br>
> - return(i);<br>
> -}<br>
> -<br>
> -// BLInstrumentationDag constructor initializes a DAG for the given Function.<br>
> -BLInstrumentationDag::BLInstrumentationDag(Function &F) : BallLarusDag(F),<br>
> - _counterArray(0) {<br>
> -}<br>
> -<br>
> -// Returns the Exit->Root edge. This edge is required for creating<br>
> -// directed cycles in the algorithm for moving instrumentation off of<br>
> -// the spanning tree<br>
> -BallLarusEdge* BLInstrumentationDag::getExitRootEdge() {<br>
> - BLEdgeIterator erEdge = getExit()->succBegin();<br>
> - return(*erEdge);<br>
> -}<br>
> -<br>
> -BLEdgeVector BLInstrumentationDag::getCallPhonyEdges () {<br>
> - BLEdgeVector callEdges;<br>
> -<br>
> - for( BLEdgeIterator edge = _edges.begin(), end = _edges.end();<br>
> - edge != end; edge++ ) {<br>
> - if( (*edge)->getType() == BallLarusEdge::CALLEDGE_PHONY )<br>
> - callEdges.push_back(*edge);<br>
> - }<br>
> -<br>
> - return callEdges;<br>
> -}<br>
> -<br>
> -// Gets the path counter array<br>
> -GlobalVariable* BLInstrumentationDag::getCounterArray() {<br>
> - return _counterArray;<br>
> -}<br>
> -<br>
> -void BLInstrumentationDag::setCounterArray(GlobalVariable* c) {<br>
> - _counterArray = c;<br>
> -}<br>
> -<br>
> -// Calculates the increment for the chords, thereby removing<br>
> -// instrumentation from the spanning tree edges. Implementation is based on<br>
> -// the algorithm in Figure 4 of [Ball94]<br>
> -void BLInstrumentationDag::calculateChordIncrements() {<br>
> - calculateChordIncrementsDfs(0, getRoot(), NULL);<br>
> -<br>
> - BLInstrumentationEdge* chord;<br>
> - for(BLEdgeIterator chordEdge = _chordEdges.begin(),<br>
> - end = _chordEdges.end(); chordEdge != end; chordEdge++) {<br>
> - chord = (BLInstrumentationEdge*) *chordEdge;<br>
> - chord->setIncrement(chord->getIncrement() + chord->getWeight());<br>
> - }<br>
> -}<br>
> -<br>
> -// Updates the state when an edge has been split<br>
> -void BLInstrumentationDag::splitUpdate(BLInstrumentationEdge* formerEdge,<br>
> - BasicBlock* newBlock) {<br>
> - BallLarusNode* oldTarget = formerEdge->getTarget();<br>
> - BallLarusNode* newNode = addNode(newBlock);<br>
> - formerEdge->setTarget(newNode);<br>
> - newNode->addPredEdge(formerEdge);<br>
> -<br>
> - DEBUG(dbgs() << " Edge split: " << *formerEdge << "\n");<br>
> -<br>
> - oldTarget->removePredEdge(formerEdge);<br>
> - BallLarusEdge* newEdge = addEdge(newNode, oldTarget,0);<br>
> -<br>
> - if( formerEdge->getType() == BallLarusEdge::BACKEDGE ||<br>
> - formerEdge->getType() == BallLarusEdge::SPLITEDGE) {<br>
> - newEdge->setType(formerEdge->getType());<br>
> - newEdge->setPhonyRoot(formerEdge->getPhonyRoot());<br>
> - newEdge->setPhonyExit(formerEdge->getPhonyExit());<br>
> - formerEdge->setType(BallLarusEdge::NORMAL);<br>
> - formerEdge->setPhonyRoot(NULL);<br>
> - formerEdge->setPhonyExit(NULL);<br>
> - }<br>
> -}<br>
> -<br>
> -// Calculates a spanning tree of the DAG ignoring cycles. Whichever<br>
> -// edges are in the spanning tree will not be instrumented, but this<br>
> -// implementation does not try to minimize the instrumentation overhead<br>
> -// by trying to find hot edges.<br>
> -void BLInstrumentationDag::calculateSpanningTree() {<br>
> - std::stack<BallLarusNode*> dfsStack;<br>
> -<br>
> - for(BLNodeIterator nodeIt = _nodes.begin(), end = _nodes.end();<br>
> - nodeIt != end; nodeIt++) {<br>
> - (*nodeIt)->setColor(BallLarusNode::WHITE);<br>
> - }<br>
> -<br>
> - dfsStack.push(getRoot());<br>
> - while(dfsStack.size() > 0) {<br>
> - BallLarusNode* node = dfsStack.top();<br>
> - dfsStack.pop();<br>
> -<br>
> - if(node->getColor() == BallLarusNode::WHITE)<br>
> - continue;<br>
> -<br>
> - BallLarusNode* nextNode;<br>
> - bool forward = true;<br>
> - BLEdgeIterator succEnd = node->succEnd();<br>
> -<br>
> - node->setColor(BallLarusNode::WHITE);<br>
> - // first iterate over successors then predecessors<br>
> - for(BLEdgeIterator edge = node->succBegin(), predEnd = node->predEnd();<br>
> - edge != predEnd; edge++) {<br>
> - if(edge == succEnd) {<br>
> - edge = node->predBegin();<br>
> - forward = false;<br>
> - }<br>
> -<br>
> - // Ignore split edges<br>
> - if ((*edge)->getType() == BallLarusEdge::SPLITEDGE)<br>
> - continue;<br>
> -<br>
> - nextNode = forward? (*edge)->getTarget(): (*edge)->getSource();<br>
> - if(nextNode->getColor() != BallLarusNode::WHITE) {<br>
> - nextNode->setColor(BallLarusNode::WHITE);<br>
> - makeEdgeSpanning((BLInstrumentationEdge*)(*edge));<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - for(BLEdgeIterator edge = _edges.begin(), end = _edges.end();<br>
> - edge != end; edge++) {<br>
> - BLInstrumentationEdge* instEdge = (BLInstrumentationEdge*) (*edge);<br>
> - // safe since createEdge is overriden<br>
> - if(!instEdge->isInSpanningTree() && (*edge)->getType()<br>
> - != BallLarusEdge::SPLITEDGE)<br>
> - _chordEdges.push_back(instEdge);<br>
> - }<br>
> -}<br>
> -<br>
> -// Pushes initialization further down in order to group the first<br>
> -// increment and initialization.<br>
> -void BLInstrumentationDag::pushInitialization() {<br>
> - BLInstrumentationEdge* exitRootEdge =<br>
> - (BLInstrumentationEdge*) getExitRootEdge();<br>
> - exitRootEdge->setIsInitialization(true);<br>
> - pushInitializationFromEdge(exitRootEdge);<br>
> -}<br>
> -<br>
> -// Pushes the path counter increments up in order to group the last path<br>
> -// number increment.<br>
> -void BLInstrumentationDag::pushCounters() {<br>
> - BLInstrumentationEdge* exitRootEdge =<br>
> - (BLInstrumentationEdge*) getExitRootEdge();<br>
> - exitRootEdge->setIsCounterIncrement(true);<br>
> - pushCountersFromEdge(exitRootEdge);<br>
> -}<br>
> -<br>
> -// Removes phony edges from the successor list of the source, and the<br>
> -// predecessor list of the target.<br>
> -void BLInstrumentationDag::unlinkPhony() {<br>
> - BallLarusEdge* edge;<br>
> -<br>
> - for(BLEdgeIterator next = _edges.begin(),<br>
> - end = _edges.end(); next != end; next++) {<br>
> - edge = (*next);<br>
> -<br>
> - if( edge->getType() == BallLarusEdge::BACKEDGE_PHONY ||<br>
> - edge->getType() == BallLarusEdge::SPLITEDGE_PHONY ||<br>
> - edge->getType() == BallLarusEdge::CALLEDGE_PHONY ) {<br>
> - unlinkEdge(edge);<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -// Generate a .dot graph to represent the DAG and pathNumbers<br>
> -void BLInstrumentationDag::generateDotGraph() {<br>
> - std::string errorInfo;<br>
> - std::string functionName = getFunction().getName().str();<br>
> - std::string filename = "pathdag." + functionName + ".dot";<br>
> -<br>
> - DEBUG (dbgs() << "Writing '" << filename << "'...\n");<br>
> - raw_fd_ostream dotFile(filename.c_str(), errorInfo);<br>
> -<br>
> - if (!errorInfo.empty()) {<br>
> - errs() << "Error opening '" << filename.c_str() <<"' for writing!";<br>
> - errs() << "\n";<br>
> - return;<br>
> - }<br>
> -<br>
> - dotFile << "digraph " << functionName << " {\n";<br>
> -<br>
> - for( BLEdgeIterator edge = _edges.begin(), end = _edges.end();<br>
> - edge != end; edge++) {<br>
> - std::string sourceName = (*edge)->getSource()->getName();<br>
> - std::string targetName = (*edge)->getTarget()->getName();<br>
> -<br>
> - dotFile << "\t\"" << sourceName.c_str() << "\" -> \""<br>
> - << targetName.c_str() << "\" ";<br>
> -<br>
> - long inc = ((BLInstrumentationEdge*)(*edge))->getIncrement();<br>
> -<br>
> - switch( (*edge)->getType() ) {<br>
> - case BallLarusEdge::NORMAL:<br>
> - dotFile << "[label=" << inc << "] [color=black];\n";<br>
> - break;<br>
> -<br>
> - case BallLarusEdge::BACKEDGE:<br>
> - dotFile << "[color=cyan];\n";<br>
> - break;<br>
> -<br>
> - case BallLarusEdge::BACKEDGE_PHONY:<br>
> - dotFile << "[label=" << inc<br>
> - << "] [color=blue];\n";<br>
> - break;<br>
> -<br>
> - case BallLarusEdge::SPLITEDGE:<br>
> - dotFile << "[color=violet];\n";<br>
> - break;<br>
> -<br>
> - case BallLarusEdge::SPLITEDGE_PHONY:<br>
> - dotFile << "[label=" << inc << "] [color=red];\n";<br>
> - break;<br>
> -<br>
> - case BallLarusEdge::CALLEDGE_PHONY:<br>
> - dotFile << "[label=" << inc << "] [color=green];\n";<br>
> - break;<br>
> - }<br>
> - }<br>
> -<br>
> - dotFile << "}\n";<br>
> -}<br>
> -<br>
> -// Allows subclasses to determine which type of Node is created.<br>
> -// Override this method to produce subclasses of BallLarusNode if<br>
> -// necessary. The destructor of BallLarusDag will call free on each pointer<br>
> -// created.<br>
> -BallLarusNode* BLInstrumentationDag::createNode(BasicBlock* BB) {<br>
> - return( new BLInstrumentationNode(BB) );<br>
> -}<br>
> -<br>
> -// Allows subclasses to determine which type of Edge is created.<br>
> -// Override this method to produce subclasses of BallLarusEdge if<br>
> -// necessary. The destructor of BallLarusDag will call free on each pointer<br>
> -// created.<br>
> -BallLarusEdge* BLInstrumentationDag::createEdge(BallLarusNode* source,<br>
> - BallLarusNode* target, unsigned edgeNumber) {<br>
> - // One can cast from BallLarusNode to BLInstrumentationNode since createNode<br>
> - // is overriden to produce BLInstrumentationNode.<br>
> - return( new BLInstrumentationEdge((BLInstrumentationNode*)source,<br>
> - (BLInstrumentationNode*)target) );<br>
> -}<br>
> -<br>
> -// Sets the Value corresponding to the pathNumber register, constant,<br>
> -// or phinode. Used by the instrumentation code to remember path<br>
> -// number Values.<br>
> -Value* BLInstrumentationNode::getStartingPathNumber(){<br>
> - return(_startingPathNumber);<br>
> -}<br>
> -<br>
> -// Sets the Value of the pathNumber. Used by the instrumentation code.<br>
> -void BLInstrumentationNode::setStartingPathNumber(Value* pathNumber) {<br>
> - DEBUG(dbgs() << " SPN-" << getName() << " <-- " << (pathNumber ?<br>
> - pathNumber->getName() :<br>
> - "unused") << "\n");<br>
> - _startingPathNumber = pathNumber;<br>
> -}<br>
> -<br>
> -Value* BLInstrumentationNode::getEndingPathNumber(){<br>
> - return(_endingPathNumber);<br>
> -}<br>
> -<br>
> -void BLInstrumentationNode::setEndingPathNumber(Value* pathNumber) {<br>
> - DEBUG(dbgs() << " EPN-" << getName() << " <-- "<br>
> - << (pathNumber ? pathNumber->getName() : "unused") << "\n");<br>
> - _endingPathNumber = pathNumber;<br>
> -}<br>
> -<br>
> -// Get the PHINode Instruction for this node. Used by instrumentation<br>
> -// code.<br>
> -PHINode* BLInstrumentationNode::getPathPHI() {<br>
> - return(_pathPHI);<br>
> -}<br>
> -<br>
> -// Set the PHINode Instruction for this node. Used by instrumentation<br>
> -// code.<br>
> -void BLInstrumentationNode::setPathPHI(PHINode* pathPHI) {<br>
> - _pathPHI = pathPHI;<br>
> -}<br>
> -<br>
> -// Removes the edge from the appropriate predecessor and successor<br>
> -// lists.<br>
> -void BLInstrumentationDag::unlinkEdge(BallLarusEdge* edge) {<br>
> - if(edge == getExitRootEdge())<br>
> - DEBUG(dbgs() << " Removing exit->root edge\n");<br>
> -<br>
> - edge->getSource()->removeSuccEdge(edge);<br>
> - edge->getTarget()->removePredEdge(edge);<br>
> -}<br>
> -<br>
> -// Makes an edge part of the spanning tree.<br>
> -void BLInstrumentationDag::makeEdgeSpanning(BLInstrumentationEdge* edge) {<br>
> - edge->setIsInSpanningTree(true);<br>
> - _treeEdges.push_back(edge);<br>
> -}<br>
> -<br>
> -// Pushes initialization and calls itself recursively.<br>
> -void BLInstrumentationDag::pushInitializationFromEdge(<br>
> - BLInstrumentationEdge* edge) {<br>
> - BallLarusNode* target;<br>
> -<br>
> - target = edge->getTarget();<br>
> - if( target->getNumberPredEdges() > 1 || target == getExit() ) {<br>
> - return;<br>
> - } else {<br>
> - for(BLEdgeIterator next = target->succBegin(),<br>
> - end = target->succEnd(); next != end; next++) {<br>
> - BLInstrumentationEdge* intoEdge = (BLInstrumentationEdge*) *next;<br>
> -<br>
> - // Skip split edges<br>
> - if (intoEdge->getType() == BallLarusEdge::SPLITEDGE)<br>
> - continue;<br>
> -<br>
> - intoEdge->setIncrement(intoEdge->getIncrement() +<br>
> - edge->getIncrement());<br>
> - intoEdge->setIsInitialization(true);<br>
> - pushInitializationFromEdge(intoEdge);<br>
> - }<br>
> -<br>
> - edge->setIncrement(0);<br>
> - edge->setIsInitialization(false);<br>
> - }<br>
> -}<br>
> -<br>
> -// Pushes path counter increments up recursively.<br>
> -void BLInstrumentationDag::pushCountersFromEdge(BLInstrumentationEdge* edge) {<br>
> - BallLarusNode* source;<br>
> -<br>
> - source = edge->getSource();<br>
> - if(source->getNumberSuccEdges() > 1 || source == getRoot()<br>
> - || edge->isInitialization()) {<br>
> - return;<br>
> - } else {<br>
> - for(BLEdgeIterator previous = source->predBegin(),<br>
> - end = source->predEnd(); previous != end; previous++) {<br>
> - BLInstrumentationEdge* fromEdge = (BLInstrumentationEdge*) *previous;<br>
> -<br>
> - // Skip split edges<br>
> - if (fromEdge->getType() == BallLarusEdge::SPLITEDGE)<br>
> - continue;<br>
> -<br>
> - fromEdge->setIncrement(fromEdge->getIncrement() +<br>
> - edge->getIncrement());<br>
> - fromEdge->setIsCounterIncrement(true);<br>
> - pushCountersFromEdge(fromEdge);<br>
> - }<br>
> -<br>
> - edge->setIncrement(0);<br>
> - edge->setIsCounterIncrement(false);<br>
> - }<br>
> -}<br>
> -<br>
> -// Depth first algorithm for determining the chord increments.<br>
> -void BLInstrumentationDag::calculateChordIncrementsDfs(long weight,<br>
> - BallLarusNode* v, BallLarusEdge* e) {<br>
> - BLInstrumentationEdge* f;<br>
> -<br>
> - for(BLEdgeIterator treeEdge = _treeEdges.begin(),<br>
> - end = _treeEdges.end(); treeEdge != end; treeEdge++) {<br>
> - f = (BLInstrumentationEdge*) *treeEdge;<br>
> - if(e != f && v == f->getTarget()) {<br>
> - calculateChordIncrementsDfs(<br>
> - calculateChordIncrementsDir(e,f)*(weight) +<br>
> - f->getWeight(), f->getSource(), f);<br>
> - }<br>
> - if(e != f && v == f->getSource()) {<br>
> - calculateChordIncrementsDfs(<br>
> - calculateChordIncrementsDir(e,f)*(weight) +<br>
> - f->getWeight(), f->getTarget(), f);<br>
> - }<br>
> - }<br>
> -<br>
> - for(BLEdgeIterator chordEdge = _chordEdges.begin(),<br>
> - end = _chordEdges.end(); chordEdge != end; chordEdge++) {<br>
> - f = (BLInstrumentationEdge*) *chordEdge;<br>
> - if(v == f->getSource() || v == f->getTarget()) {<br>
> - f->setIncrement(f->getIncrement() +<br>
> - calculateChordIncrementsDir(e,f)*weight);<br>
> - }<br>
> - }<br>
> -}<br>
> -<br>
> -// Determines the relative direction of two edges.<br>
> -int BLInstrumentationDag::calculateChordIncrementsDir(BallLarusEdge* e,<br>
> - BallLarusEdge* f) {<br>
> - if( e == NULL)<br>
> - return(1);<br>
> - else if(e->getSource() == f->getTarget()<br>
> - || e->getTarget() == f->getSource())<br>
> - return(1);<br>
> -<br>
> - return(-1);<br>
> -}<br>
> -<br>
> -// Creates an increment constant representing incr.<br>
> -ConstantInt* PathProfiler::createIncrementConstant(long incr,<br>
> - int bitsize) {<br>
> - return(ConstantInt::get(IntegerType::get(*Context, 32), incr));<br>
> -}<br>
> -<br>
> -// Creates an increment constant representing the value in<br>
> -// edge->getIncrement().<br>
> -ConstantInt* PathProfiler::createIncrementConstant(<br>
> - BLInstrumentationEdge* edge) {<br>
> - return(createIncrementConstant(edge->getIncrement(), 32));<br>
> -}<br>
> -<br>
> -// Finds the insertion point after pathNumber in block. PathNumber may<br>
> -// be NULL.<br>
> -BasicBlock::iterator PathProfiler::getInsertionPoint(BasicBlock* block, Value*<br>
> - pathNumber) {<br>
> - if(pathNumber == NULL || isa<ConstantInt>(pathNumber)<br>
> - || (((Instruction*)(pathNumber))->getParent()) != block) {<br>
> - return(block->getFirstInsertionPt());<br>
> - } else {<br>
> - Instruction* pathNumberInst = (Instruction*) (pathNumber);<br>
> - BasicBlock::iterator insertPoint;<br>
> - BasicBlock::iterator end = block->end();<br>
> -<br>
> - for(insertPoint = block->begin();<br>
> - insertPoint != end; insertPoint++) {<br>
> - Instruction* insertInst = &(*insertPoint);<br>
> -<br>
> - if(insertInst == pathNumberInst)<br>
> - return(++insertPoint);<br>
> - }<br>
> -<br>
> - return(insertPoint);<br>
> - }<br>
> -}<br>
> -<br>
> -// A PHINode is created in the node, and its values initialized to -1U.<br>
> -void PathProfiler::preparePHI(BLInstrumentationNode* node) {<br>
> - BasicBlock* block = node->getBlock();<br>
> - BasicBlock::iterator insertPoint = block->getFirstInsertionPt();<br>
> - pred_iterator PB = pred_begin(node->getBlock()),<br>
> - PE = pred_end(node->getBlock());<br>
> - PHINode* phi = PHINode::Create(Type::getInt32Ty(*Context),<br>
> - std::distance(PB, PE), "pathNumber",<br>
> - insertPoint );<br>
> - node->setPathPHI(phi);<br>
> - node->setStartingPathNumber(phi);<br>
> - node->setEndingPathNumber(phi);<br>
> -<br>
> - for(pred_iterator predIt = PB; predIt != PE; predIt++) {<br>
> - BasicBlock* pred = (*predIt);<br>
> -<br>
> - if(pred != NULL)<br>
> - phi->addIncoming(createIncrementConstant((long)-1, 32), pred);<br>
> - }<br>
> -}<br>
> -<br>
> -// Inserts source's pathNumber Value* into target. Target may or may not<br>
> -// have multiple predecessors, and may or may not have its phiNode<br>
> -// initalized.<br>
> -void PathProfiler::pushValueIntoNode(BLInstrumentationNode* source,<br>
> - BLInstrumentationNode* target) {<br>
> - if(target->getBlock() == NULL)<br>
> - return;<br>
> -<br>
> -<br>
> - if(target->getNumberPredEdges() <= 1) {<br>
> - assert(target->getStartingPathNumber() == NULL &&<br>
> - "Target already has path number");<br>
> - target->setStartingPathNumber(source->getEndingPathNumber());<br>
> - target->setEndingPathNumber(source->getEndingPathNumber());<br>
> - DEBUG(dbgs() << " Passing path number"<br>
> - << (source->getEndingPathNumber() ? "" : " (null)")<br>
> - << " value through.\n");<br>
> - } else {<br>
> - if(target->getPathPHI() == NULL) {<br>
> - DEBUG(dbgs() << " Initializing PHI node for block '"<br>
> - << target->getName() << "'\n");<br>
> - preparePHI(target);<br>
> - }<br>
> - pushValueIntoPHI(target, source);<br>
> - DEBUG(dbgs() << " Passing number value into PHI for block '"<br>
> - << target->getName() << "'\n");<br>
> - }<br>
> -}<br>
> -<br>
> -// Inserts source's pathNumber Value* into the appropriate slot of<br>
> -// target's phiNode.<br>
> -void PathProfiler::pushValueIntoPHI(BLInstrumentationNode* target,<br>
> - BLInstrumentationNode* source) {<br>
> - PHINode* phi = target->getPathPHI();<br>
> - assert(phi != NULL && " Tried to push value into node with PHI, but node"<br>
> - " actually had no PHI.");<br>
> - phi->removeIncomingValue(source->getBlock(), false);<br>
> - phi->addIncoming(source->getEndingPathNumber(), source->getBlock());<br>
> -}<br>
> -<br>
> -// The Value* in node, oldVal, is updated with a Value* correspodning to<br>
> -// oldVal + addition.<br>
> -void PathProfiler::insertNumberIncrement(BLInstrumentationNode* node,<br>
> - Value* addition, bool atBeginning) {<br>
> - BasicBlock* block = node->getBlock();<br>
> - assert(node->getStartingPathNumber() != NULL);<br>
> - assert(node->getEndingPathNumber() != NULL);<br>
> -<br>
> - BasicBlock::iterator insertPoint;<br>
> -<br>
> - if( atBeginning )<br>
> - insertPoint = block->getFirstInsertionPt();<br>
> - else<br>
> - insertPoint = block->getTerminator();<br>
> -<br>
> - DEBUG(errs() << " Creating addition instruction.\n");<br>
> - Value* newpn = BinaryOperator::Create(Instruction::Add,<br>
> - node->getStartingPathNumber(),<br>
> - addition, "pathNumber", insertPoint);<br>
> -<br>
> - node->setEndingPathNumber(newpn);<br>
> -<br>
> - if( atBeginning )<br>
> - node->setStartingPathNumber(newpn);<br>
> -}<br>
> -<br>
> -// Creates a counter increment in the given node. The Value* in node is<br>
> -// taken as the index into an array or hash table. The hash table access<br>
> -// is a call to the runtime.<br>
> -void PathProfiler::insertCounterIncrement(Value* incValue,<br>
> - BasicBlock::iterator insertPoint,<br>
> - BLInstrumentationDag* dag,<br>
> - bool increment) {<br>
> - // Counter increment for array<br>
> - if( dag->getNumberOfPaths() <= HASH_THRESHHOLD ) {<br>
> - // Get pointer to the array location<br>
> - std::vector<Value*> gepIndices(2);<br>
> - gepIndices[0] = Constant::getNullValue(Type::getInt32Ty(*Context));<br>
> - gepIndices[1] = incValue;<br>
> -<br>
> - GetElementPtrInst* pcPointer =<br>
> - GetElementPtrInst::Create(dag->getCounterArray(), gepIndices,<br>
> - "counterInc", insertPoint);<br>
> -<br>
> - // Load from the array - call it oldPC<br>
> - LoadInst* oldPc = new LoadInst(pcPointer, "oldPC", insertPoint);<br>
> -<br>
> - // Test to see whether adding 1 will overflow the counter<br>
> - ICmpInst* isMax = new ICmpInst(insertPoint, CmpInst::ICMP_ULT, oldPc,<br>
> - createIncrementConstant(0xffffffff, 32),<br>
> - "isMax");<br>
> -<br>
> - // Select increment for the path counter based on overflow<br>
> - SelectInst* inc =<br>
> - SelectInst::Create( isMax, createIncrementConstant(increment?1:-1,32),<br>
> - createIncrementConstant(0,32),<br>
> - "pathInc", insertPoint);<br>
> -<br>
> - // newPc = oldPc + inc<br>
> - BinaryOperator* newPc = BinaryOperator::Create(Instruction::Add,<br>
> - oldPc, inc, "newPC",<br>
> - insertPoint);<br>
> -<br>
> - // Store back in to the array<br>
> - new StoreInst(newPc, pcPointer, insertPoint);<br>
> - } else { // Counter increment for hash<br>
> - std::vector<Value*> args(2);<br>
> - args[0] = ConstantInt::get(Type::getInt32Ty(*Context),<br>
> - currentFunctionNumber);<br>
> - args[1] = incValue;<br>
> -<br>
> - CallInst::Create(<br>
> - increment ? llvmIncrementHashFunction : llvmDecrementHashFunction,<br>
> - args, "", insertPoint);<br>
> - }<br>
> -}<br>
> -<br>
> -// Inserts instrumentation for the given edge<br>
> -//<br>
> -// Pre: The edge's source node has pathNumber set if edge is non zero<br>
> -// path number increment.<br>
> -//<br>
> -// Post: Edge's target node has a pathNumber set to the path number Value<br>
> -// corresponding to the value of the path register after edge's<br>
> -// execution.<br>
> -//<br>
> -// FIXME: This should be reworked so it's not recursive.<br>
> -void PathProfiler::insertInstrumentationStartingAt(BLInstrumentationEdge* edge,<br>
> - BLInstrumentationDag* dag) {<br>
> - // Mark the edge as instrumented<br>
> - edge->setHasInstrumentation(true);<br>
> - DEBUG(dbgs() << "\nInstrumenting edge: " << (*edge) << "\n");<br>
> -<br>
> - // create a new node for this edge's instrumentation<br>
> - splitCritical(edge, dag);<br>
> -<br>
> - BLInstrumentationNode* sourceNode = (BLInstrumentationNode*)edge->getSource();<br>
> - BLInstrumentationNode* targetNode = (BLInstrumentationNode*)edge->getTarget();<br>
> - BLInstrumentationNode* instrumentNode;<br>
> - BLInstrumentationNode* nextSourceNode;<br>
> -<br>
> - bool atBeginning = false;<br>
> -<br>
> - // Source node has only 1 successor so any information can be simply<br>
> - // inserted in to it without splitting<br>
> - if( sourceNode->getBlock() && sourceNode->getNumberSuccEdges() <= 1) {<br>
> - DEBUG(dbgs() << " Potential instructions to be placed in: "<br>
> - << sourceNode->getName() << " (at end)\n");<br>
> - instrumentNode = sourceNode;<br>
> - nextSourceNode = targetNode; // ... since we never made any new nodes<br>
> - }<br>
> -<br>
> - // The target node only has one predecessor, so we can safely insert edge<br>
> - // instrumentation into it. If there was splitting, it must have been<br>
> - // successful.<br>
> - else if( targetNode->getNumberPredEdges() == 1 ) {<br>
> - DEBUG(dbgs() << " Potential instructions to be placed in: "<br>
> - << targetNode->getName() << " (at beginning)\n");<br>
> - pushValueIntoNode(sourceNode, targetNode);<br>
> - instrumentNode = targetNode;<br>
> - nextSourceNode = NULL; // ... otherwise we'll just keep splitting<br>
> - atBeginning = true;<br>
> - }<br>
> -<br>
> - // Somehow, splitting must have failed.<br>
> - else {<br>
> - errs() << "Instrumenting could not split a critical edge.\n";<br>
> - DEBUG(dbgs() << " Couldn't split edge " << (*edge) << ".\n");<br>
> - return;<br>
> - }<br>
> -<br>
> - // Insert instrumentation if this is a back or split edge<br>
> - if( edge->getType() == BallLarusEdge::BACKEDGE ||<br>
> - edge->getType() == BallLarusEdge::SPLITEDGE ) {<br>
> - BLInstrumentationEdge* top =<br>
> - (BLInstrumentationEdge*) edge->getPhonyRoot();<br>
> - BLInstrumentationEdge* bottom =<br>
> - (BLInstrumentationEdge*) edge->getPhonyExit();<br>
> -<br>
> - assert( top->isInitialization() && " Top phony edge did not"<br>
> - " contain a path number initialization.");<br>
> - assert( bottom->isCounterIncrement() && " Bottom phony edge"<br>
> - " did not contain a path counter increment.");<br>
> -<br>
> - // split edge has yet to be initialized<br>
> - if( !instrumentNode->getEndingPathNumber() ) {<br>
> - instrumentNode->setStartingPathNumber(createIncrementConstant(0,32));<br>
> - instrumentNode->setEndingPathNumber(createIncrementConstant(0,32));<br>
> - }<br>
> -<br>
> - BasicBlock::iterator insertPoint = atBeginning ?<br>
> - instrumentNode->getBlock()->getFirstInsertionPt() :<br>
> - instrumentNode->getBlock()->getTerminator();<br>
> -<br>
> - // add information from the bottom edge, if it exists<br>
> - if( bottom->getIncrement() ) {<br>
> - Value* newpn =<br>
> - BinaryOperator::Create(Instruction::Add,<br>
> - instrumentNode->getStartingPathNumber(),<br>
> - createIncrementConstant(bottom),<br>
> - "pathNumber", insertPoint);<br>
> - instrumentNode->setEndingPathNumber(newpn);<br>
> - }<br>
> -<br>
> - insertCounterIncrement(instrumentNode->getEndingPathNumber(),<br>
> - insertPoint, dag);<br>
> -<br>
> - if( atBeginning )<br>
> - instrumentNode->setStartingPathNumber(createIncrementConstant(top));<br>
> -<br>
> - instrumentNode->setEndingPathNumber(createIncrementConstant(top));<br>
> -<br>
> - // Check for path counter increments<br>
> - if( top->isCounterIncrement() ) {<br>
> - insertCounterIncrement(instrumentNode->getEndingPathNumber(),<br>
> - instrumentNode->getBlock()->getTerminator(),dag);<br>
> - instrumentNode->setEndingPathNumber(0);<br>
> - }<br>
> - }<br>
> -<br>
> - // Insert instrumentation if this is a normal edge<br>
> - else {<br>
> - BasicBlock::iterator insertPoint = atBeginning ?<br>
> - instrumentNode->getBlock()->getFirstInsertionPt() :<br>
> - instrumentNode->getBlock()->getTerminator();<br>
> -<br>
> - if( edge->isInitialization() ) { // initialize path number<br>
> - instrumentNode->setEndingPathNumber(createIncrementConstant(edge));<br>
> - } else if( edge->getIncrement() ) {// increment path number<br>
> - Value* newpn =<br>
> - BinaryOperator::Create(Instruction::Add,<br>
> - instrumentNode->getStartingPathNumber(),<br>
> - createIncrementConstant(edge),<br>
> - "pathNumber", insertPoint);<br>
> - instrumentNode->setEndingPathNumber(newpn);<br>
> -<br>
> - if( atBeginning )<br>
> - instrumentNode->setStartingPathNumber(newpn);<br>
> - }<br>
> -<br>
> - // Check for path counter increments<br>
> - if( edge->isCounterIncrement() ) {<br>
> - insertCounterIncrement(instrumentNode->getEndingPathNumber(),<br>
> - insertPoint, dag);<br>
> - instrumentNode->setEndingPathNumber(0);<br>
> - }<br>
> - }<br>
> -<br>
> - // Push it along<br>
> - if (nextSourceNode && instrumentNode->getEndingPathNumber())<br>
> - pushValueIntoNode(instrumentNode, nextSourceNode);<br>
> -<br>
> - // Add all the successors<br>
> - for( BLEdgeIterator next = targetNode->succBegin(),<br>
> - end = targetNode->succEnd(); next != end; next++ ) {<br>
> - // So long as it is un-instrumented, add it to the list<br>
> - if( !((BLInstrumentationEdge*)(*next))->hasInstrumentation() )<br>
> - insertInstrumentationStartingAt((BLInstrumentationEdge*)*next,dag);<br>
> - else<br>
> - DEBUG(dbgs() << " Edge " << *(BLInstrumentationEdge*)(*next)<br>
> - << " already instrumented.\n");<br>
> - }<br>
> -}<br>
> -<br>
> -// Inserts instrumentation according to the marked edges in dag. Phony edges<br>
> -// must be unlinked from the DAG, but accessible from the backedges. Dag<br>
> -// must have initializations, path number increments, and counter increments<br>
> -// present.<br>
> -//<br>
> -// Counter storage is created here.<br>
> -void PathProfiler::insertInstrumentation(<br>
> - BLInstrumentationDag& dag, Module &M) {<br>
> -<br>
> - BLInstrumentationEdge* exitRootEdge =<br>
> - (BLInstrumentationEdge*) dag.getExitRootEdge();<br>
> - insertInstrumentationStartingAt(exitRootEdge, &dag);<br>
> -<br>
> - // Iterate through each call edge and apply the appropriate hash increment<br>
> - // and decrement functions<br>
> - BLEdgeVector callEdges = dag.getCallPhonyEdges();<br>
> - for( BLEdgeIterator edge = callEdges.begin(),<br>
> - end = callEdges.end(); edge != end; edge++ ) {<br>
> - BLInstrumentationNode* node =<br>
> - (BLInstrumentationNode*)(*edge)->getSource();<br>
> - BasicBlock::iterator insertPoint = node->getBlock()->getFirstInsertionPt();<br>
> -<br>
> - // Find the first function call<br>
> - while( ((Instruction&)(*insertPoint)).getOpcode() != Instruction::Call )<br>
> - insertPoint++;<br>
> -<br>
> - DEBUG(dbgs() << "\nInstrumenting method call block '"<br>
> - << node->getBlock()->getName() << "'\n");<br>
> - DEBUG(dbgs() << " Path number initialized: "<br>
> - << ((node->getStartingPathNumber()) ? "yes" : "no") << "\n");<br>
> -<br>
> - Value* newpn;<br>
> - if( node->getStartingPathNumber() ) {<br>
> - long inc = ((BLInstrumentationEdge*)(*edge))->getIncrement();<br>
> - if ( inc )<br>
> - newpn = BinaryOperator::Create(Instruction::Add,<br>
> - node->getStartingPathNumber(),<br>
> - createIncrementConstant(inc,32),<br>
> - "pathNumber", insertPoint);<br>
> - else<br>
> - newpn = node->getStartingPathNumber();<br>
> - } else {<br>
> - newpn = (Value*)createIncrementConstant(<br>
> - ((BLInstrumentationEdge*)(*edge))->getIncrement(), 32);<br>
> - }<br>
> -<br>
> - insertCounterIncrement(newpn, insertPoint, &dag);<br>
> - insertCounterIncrement(newpn, node->getBlock()->getTerminator(),<br>
> - &dag, false);<br>
> - }<br>
> -}<br>
> -<br>
> -// Entry point of the module<br>
> -void PathProfiler::runOnFunction(std::vector<Constant*> &ftInit,<br>
> - Function &F, Module &M) {<br>
> - // Build DAG from CFG<br>
> - BLInstrumentationDag dag = BLInstrumentationDag(F);<br>
> - dag.init();<br>
> -<br>
> - // give each path a unique integer value<br>
> - dag.calculatePathNumbers();<br>
> -<br>
> - // modify path increments to increase the efficiency<br>
> - // of instrumentation<br>
> - dag.calculateSpanningTree();<br>
> - dag.calculateChordIncrements();<br>
> - dag.pushInitialization();<br>
> - dag.pushCounters();<br>
> - dag.unlinkPhony();<br>
> -<br>
> - // potentially generate .dot graph for the dag<br>
> - if (DotPathDag)<br>
> - dag.generateDotGraph ();<br>
> -<br>
> - // Should we store the information in an array or hash<br>
> - if( dag.getNumberOfPaths() <= HASH_THRESHHOLD ) {<br>
> - Type* t = ArrayType::get(Type::getInt32Ty(*Context),<br>
> - dag.getNumberOfPaths());<br>
> -<br>
> - dag.setCounterArray(new GlobalVariable(M, t, false,<br>
> - GlobalValue::InternalLinkage,<br>
> - Constant::getNullValue(t), ""));<br>
> - }<br>
> -<br>
> - insertInstrumentation(dag, M);<br>
> -<br>
> - // Add to global function reference table<br>
> - unsigned type;<br>
> - Type* voidPtr = TypeBuilder<types::i<8>*, true>::get(*Context);<br>
> -<br>
> - if( dag.getNumberOfPaths() <= HASH_THRESHHOLD )<br>
> - type = ProfilingArray;<br>
> - else<br>
> - type = ProfilingHash;<br>
> -<br>
> - std::vector<Constant*> entryArray(3);<br>
> - entryArray[0] = createIncrementConstant(type,32);<br>
> - entryArray[1] = createIncrementConstant(dag.getNumberOfPaths(),32);<br>
> - entryArray[2] = dag.getCounterArray() ?<br>
> - ConstantExpr::getBitCast(dag.getCounterArray(), voidPtr) :<br>
> - Constant::getNullValue(voidPtr);<br>
> -<br>
> - StructType* at = ftEntryTypeBuilder::get(*Context);<br>
> - ConstantStruct* functionEntry =<br>
> - (ConstantStruct*)ConstantStruct::get(at, entryArray);<br>
> - ftInit.push_back(functionEntry);<br>
> -}<br>
> -<br>
> -// Output the bitcode if we want to observe instrumentation changess<br>
> -#define PRINT_MODULE dbgs() << \<br>
> - "\n\n============= MODULE BEGIN ===============\n" << M << \<br>
> - "\n============== MODULE END ================\n"<br>
> -<br>
> -bool PathProfiler::runOnModule(Module &M) {<br>
> - Context = &M.getContext();<br>
> -<br>
> - DEBUG(dbgs()<br>
> - << "****************************************\n"<br>
> - << "****************************************\n"<br>
> - << "** **\n"<br>
> - << "** PATH PROFILING INSTRUMENTATION **\n"<br>
> - << "** **\n"<br>
> - << "****************************************\n"<br>
> - << "****************************************\n");<br>
> -<br>
> - // No main, no instrumentation!<br>
> - Function *Main = M.getFunction("main");<br>
> -<br>
> - // Using fortran? ... this kind of works<br>
> - if (!Main)<br>
> - Main = M.getFunction("MAIN__");<br>
> -<br>
> - if (!Main) {<br>
> - errs() << "WARNING: cannot insert path profiling into a module"<br>
> - << " with no main function!\n";<br>
> - return false;<br>
> - }<br>
> -<br>
> - llvmIncrementHashFunction = M.getOrInsertFunction(<br>
> - "llvm_increment_path_count",<br>
> - Type::getVoidTy(*Context), // return type<br>
> - Type::getInt32Ty(*Context), // function number<br>
> - Type::getInt32Ty(*Context), // path number<br>
> - NULL );<br>
> -<br>
> - llvmDecrementHashFunction = M.getOrInsertFunction(<br>
> - "llvm_decrement_path_count",<br>
> - Type::getVoidTy(*Context), // return type<br>
> - Type::getInt32Ty(*Context), // function number<br>
> - Type::getInt32Ty(*Context), // path number<br>
> - NULL );<br>
> -<br>
> - std::vector<Constant*> ftInit;<br>
> - unsigned functionNumber = 0;<br>
> - for (Module::iterator F = M.begin(), E = M.end(); F != E; F++) {<br>
> - if (F->isDeclaration())<br>
> - continue;<br>
> -<br>
> - DEBUG(dbgs() << "Function: " << F->getName() << "\n");<br>
> - functionNumber++;<br>
> -<br>
> - // set function number<br>
> - currentFunctionNumber = functionNumber;<br>
> - runOnFunction(ftInit, *F, M);<br>
> - }<br>
> -<br>
> - Type *t = ftEntryTypeBuilder::get(*Context);<br>
> - ArrayType* ftArrayType = ArrayType::get(t, ftInit.size());<br>
> - Constant* ftInitConstant = ConstantArray::get(ftArrayType, ftInit);<br>
> -<br>
> - DEBUG(dbgs() << " ftArrayType:" << *ftArrayType << "\n");<br>
> -<br>
> - GlobalVariable* functionTable =<br>
> - new GlobalVariable(M, ftArrayType, false, GlobalValue::InternalLinkage,<br>
> - ftInitConstant, "functionPathTable");<br>
> - Type *eltType = ftArrayType->getTypeAtIndex((unsigned)0);<br>
> - InsertProfilingInitCall(Main, "llvm_start_path_profiling", functionTable,<br>
> - PointerType::getUnqual(eltType));<br>
> -<br>
> - DEBUG(PRINT_MODULE);<br>
> -<br>
> - return true;<br>
> -}<br>
> -<br>
> -// If this edge is a critical edge, then inserts a node at this edge.<br>
> -// This edge becomes the first edge, and a new BallLarusEdge is created.<br>
> -// Returns true if the edge was split<br>
> -bool PathProfiler::splitCritical(BLInstrumentationEdge* edge,<br>
> - BLInstrumentationDag* dag) {<br>
> - unsigned succNum = edge->getSuccessorNumber();<br>
> - BallLarusNode* sourceNode = edge->getSource();<br>
> - BallLarusNode* targetNode = edge->getTarget();<br>
> - BasicBlock* sourceBlock = sourceNode->getBlock();<br>
> - BasicBlock* targetBlock = targetNode->getBlock();<br>
> -<br>
> - if(sourceBlock == NULL || targetBlock == NULL<br>
> - || sourceNode->getNumberSuccEdges() <= 1<br>
> - || targetNode->getNumberPredEdges() == 1 ) {<br>
> - return(false);<br>
> - }<br>
> -<br>
> - TerminatorInst* terminator = sourceBlock->getTerminator();<br>
> -<br>
> - if( SplitCriticalEdge(terminator, succNum, this, false)) {<br>
> - BasicBlock* newBlock = terminator->getSuccessor(succNum);<br>
> - dag->splitUpdate(edge, newBlock);<br>
> - return(true);<br>
> - } else<br>
> - return(false);<br>
> -}<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Wed Oct 2 10:42:23 2013<br>
> @@ -22,7 +22,6 @@<br>
> #include "llvm/Analysis/DominatorInternals.h"<br>
> #include "llvm/Analysis/Dominators.h"<br>
> #include "llvm/Analysis/InstructionSimplify.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> #include "llvm/Assembly/Writer.h"<br>
> #include "llvm/IR/Constants.h"<br>
> #include "llvm/IR/DataLayout.h"<br>
> @@ -80,7 +79,6 @@ namespace {<br>
> const TargetLowering *TLI;<br>
> const TargetLibraryInfo *TLInfo;<br>
> DominatorTree *DT;<br>
> - ProfileInfo *PFI;<br>
><br>
> /// CurInstIterator - As we scan instructions optimizing them, this is the<br>
> /// next instruction to optimize. Xforms that can invalidate this should<br>
> @@ -111,7 +109,6 @@ namespace {<br>
><br>
> virtual void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> AU.addPreserved<DominatorTree>();<br>
> - AU.addPreserved<ProfileInfo>();<br>
> AU.addRequired<TargetLibraryInfo>();<br>
> }<br>
><br>
> @@ -151,7 +148,6 @@ bool CodeGenPrepare::runOnFunction(Funct<br>
> if (TM) TLI = TM->getTargetLowering();<br>
> TLInfo = &getAnalysis<TargetLibraryInfo>();<br>
> DT = getAnalysisIfAvailable<DominatorTree>();<br>
> - PFI = getAnalysisIfAvailable<ProfileInfo>();<br>
> OptSize = F.getAttributes().hasAttribute(AttributeSet::FunctionIndex,<br>
> Attribute::OptimizeForSize);<br>
><br>
> @@ -442,10 +438,6 @@ void CodeGenPrepare::EliminateMostlyEmpt<br>
> DT->changeImmediateDominator(DestBB, NewIDom);<br>
> DT->eraseNode(BB);<br>
> }<br>
> - if (PFI) {<br>
> - PFI->replaceAllUses(BB, DestBB);<br>
> - PFI->removeEdge(ProfileInfo::getEdge(BB, DestBB));<br>
> - }<br>
> BB->eraseFromParent();<br>
> ++NumBlocksElim;<br>
><br>
><br>
> Modified: llvm/trunk/lib/Transforms/Utils/BreakCriticalEdges.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BreakCriticalEdges.cpp?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BreakCriticalEdges.cpp?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Utils/BreakCriticalEdges.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Utils/BreakCriticalEdges.cpp Wed Oct 2 10:42:23 2013<br>
> @@ -22,7 +22,6 @@<br>
> #include "llvm/Analysis/CFG.h"<br>
> #include "llvm/Analysis/Dominators.h"<br>
> #include "llvm/Analysis/LoopInfo.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> #include "llvm/IR/Function.h"<br>
> #include "llvm/IR/Instructions.h"<br>
> #include "llvm/IR/Type.h"<br>
> @@ -45,7 +44,6 @@ namespace {<br>
> virtual void getAnalysisUsage(AnalysisUsage &AU) const {<br>
> AU.addPreserved<DominatorTree>();<br>
> AU.addPreserved<LoopInfo>();<br>
> - AU.addPreserved<ProfileInfo>();<br>
><br>
> // No loop canonicalization guarantees are broken by this pass.<br>
> AU.addPreservedID(LoopSimplifyID);<br>
> @@ -213,10 +211,9 @@ BasicBlock *llvm::SplitCriticalEdge(Term<br>
><br>
> DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>();<br>
> LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>();<br>
> - ProfileInfo *PI = P->getAnalysisIfAvailable<ProfileInfo>();<br>
><br>
> // If we have nothing to update, just return.<br>
> - if (DT == 0 && LI == 0 && PI == 0)<br>
> + if (DT == 0 && LI == 0)<br>
> return NewBB;<br>
><br>
> // Now update analysis information. Since the only predecessor of NewBB is<br>
> @@ -369,9 +366,5 @@ BasicBlock *llvm::SplitCriticalEdge(Term<br>
> }<br>
> }<br>
><br>
> - // Update ProfileInfo if it is around.<br>
> - if (PI)<br>
> - PI->splitEdge(TIBB, DestBB, NewBB, MergeIdenticalEdges);<br>
> -<br>
> return NewBB;<br>
> }<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Utils/Local.cpp Wed Oct 2 10:42:23 2013<br>
> @@ -20,7 +20,6 @@<br>
> #include "llvm/Analysis/Dominators.h"<br>
> #include "llvm/Analysis/InstructionSimplify.h"<br>
> #include "llvm/Analysis/MemoryBuiltins.h"<br>
> -#include "llvm/Analysis/ProfileInfo.h"<br>
> #include "llvm/Analysis/ValueTracking.h"<br>
> #include "llvm/DIBuilder.h"<br>
> #include "llvm/DebugInfo.h"<br>
> @@ -513,11 +512,6 @@ void llvm::MergeBasicBlockIntoOnlyPred(B<br>
> DT->changeImmediateDominator(DestBB, PredBBIDom);<br>
> DT->eraseNode(PredBB);<br>
> }<br>
> - ProfileInfo *PI = P->getAnalysisIfAvailable<ProfileInfo>();<br>
> - if (PI) {<br>
> - PI->replaceAllUses(PredBB, DestBB);<br>
> - PI->removeEdge(ProfileInfo::getEdge(PredBB, DestBB));<br>
> - }<br>
> }<br>
> // Nuke BB.<br>
> PredBB->eraseFromParent();<br>
><br>
> Modified: llvm/trunk/test/lit.cfg<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/lit.cfg (original)<br>
> +++ llvm/trunk/test/lit.cfg Wed Oct 2 10:42:23 2013<br>
> @@ -226,7 +226,6 @@ for pattern in [r"\bbugpoint\b(?!-)",<br>
> r"\bllvm-mc\b",<br>
> r"\bllvm-nm\b",<br>
> r"\bllvm-objdump\b",<br>
> - r"\bllvm-prof\b",<br>
> r"\bllvm-ranlib\b",<br>
> r"\bllvm-readobj\b",<br>
> r"\bllvm-rtdyld\b",<br>
><br>
> Modified: llvm/trunk/tools/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/CMakeLists.txt?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/CMakeLists.txt (original)<br>
> +++ llvm/trunk/tools/CMakeLists.txt Wed Oct 2 10:42:23 2013<br>
> @@ -15,7 +15,6 @@ add_llvm_tool_subdirectory(llvm-nm)<br>
> add_llvm_tool_subdirectory(llvm-size)<br>
><br>
> add_llvm_tool_subdirectory(llvm-cov)<br>
> -add_llvm_tool_subdirectory(llvm-prof)<br>
> add_llvm_tool_subdirectory(llvm-link)<br>
> add_llvm_tool_subdirectory(lli)<br>
><br>
><br>
> Modified: llvm/trunk/tools/LLVMBuild.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/LLVMBuild.txt?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/LLVMBuild.txt?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/LLVMBuild.txt (original)<br>
> +++ llvm/trunk/tools/LLVMBuild.txt Wed Oct 2 10:42:23 2013<br>
> @@ -16,7 +16,7 @@<br>
> ;===------------------------------------------------------------------------===;<br>
><br>
> [common]<br>
> -subdirectories = bugpoint llc lli llvm-ar llvm-as llvm-bcanalyzer llvm-cov llvm-diff llvm-dis llvm-dwarfdump llvm-extract llvm-jitlistener llvm-link llvm-lto llvm-mc llvm-nm llvm-objdump llvm-prof llvm-rtdyld llvm-size macho-dump opt llvm-mcmarkup<br>
> +subdirectories = bugpoint llc lli llvm-ar llvm-as llvm-bcanalyzer llvm-cov llvm-diff llvm-dis llvm-dwarfdump llvm-extract llvm-jitlistener llvm-link llvm-lto llvm-mc llvm-nm llvm-objdump llvm-rtdyld llvm-size macho-dump opt llvm-mcmarkup<br>
><br>
> [component_0]<br>
> type = Group<br>
><br>
> Modified: llvm/trunk/tools/Makefile<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/Makefile?rev=191835&r1=191834&r2=191835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/Makefile?rev=191835&r1=191834&r2=191835&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/Makefile (original)<br>
> +++ llvm/trunk/tools/Makefile Wed Oct 2 10:42:23 2013<br>
> @@ -27,7 +27,7 @@ OPTIONAL_DIRS := lldb<br>
> # large and three small executables. This is done to minimize memory load<br>
> # in parallel builds. Please retain this ordering.<br>
> DIRS := llvm-config<br>
> -PARALLEL_DIRS := opt llvm-as llvm-dis llc llvm-ar llvm-nm llvm-prof llvm-link \<br>
> +PARALLEL_DIRS := opt llvm-as llvm-dis llc llvm-ar llvm-nm llvm-link \<br>
> lli llvm-extract llvm-mc bugpoint llvm-bcanalyzer llvm-diff \<br>
> macho-dump llvm-objdump llvm-readobj llvm-rtdyld \<br>
> llvm-dwarfdump llvm-cov llvm-size llvm-stress llvm-mcmarkup \<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div>