mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-08 21:37:35 +00:00
Code Cleanup.
Removed inverted flag form MaximumSpanningTree, also do not handle so much information to MaximumSpanningTree. llvm-svn: 80911
This commit is contained in:
parent
28838cdd68
commit
c389a5dd4a
@ -14,8 +14,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
#define DEBUG_TYPE "maximum-spanning-tree"
|
#define DEBUG_TYPE "maximum-spanning-tree"
|
||||||
#include "MaximumSpanningTree.h"
|
#include "MaximumSpanningTree.h"
|
||||||
#include "llvm/Pass.h"
|
|
||||||
#include "llvm/Analysis/Passes.h"
|
|
||||||
#include "llvm/ADT/EquivalenceClasses.h"
|
#include "llvm/ADT/EquivalenceClasses.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
@ -64,12 +62,9 @@ static void inline printMSTEdge(ProfileInfo::EdgeWeight E,
|
|||||||
// MaximumSpanningTree() - Takes a function and returns a spanning tree
|
// MaximumSpanningTree() - Takes a function and returns a spanning tree
|
||||||
// according to the currently active profiling information, the leaf edges are
|
// according to the currently active profiling information, the leaf edges are
|
||||||
// NOT in the MST. MaximumSpanningTree uses the algorithm of Kruskal.
|
// NOT in the MST. MaximumSpanningTree uses the algorithm of Kruskal.
|
||||||
MaximumSpanningTree::MaximumSpanningTree(Function *F, ProfileInfo *PI,
|
MaximumSpanningTree::MaximumSpanningTree(std::vector<ProfileInfo::EdgeWeight>
|
||||||
bool inverted = false) {
|
&EdgeVector) {
|
||||||
|
|
||||||
// Copy edges to vector, sort them biggest first.
|
|
||||||
ProfileInfo::EdgeWeights ECs = PI->getEdgeWeights(F);
|
|
||||||
std::vector<ProfileInfo::EdgeWeight> EdgeVector(ECs.begin(), ECs.end());
|
|
||||||
std::sort(EdgeVector.begin(), EdgeVector.end(), EdgeWeightCompare());
|
std::sort(EdgeVector.begin(), EdgeVector.end(), EdgeWeightCompare());
|
||||||
|
|
||||||
// Create spanning tree, Forest contains a special data structure
|
// Create spanning tree, Forest contains a special data structure
|
||||||
@ -92,12 +87,11 @@ MaximumSpanningTree::MaximumSpanningTree(Function *F, ProfileInfo *PI,
|
|||||||
Forest.unionSets(e.first, e.second);
|
Forest.unionSets(e.first, e.second);
|
||||||
// So we know now that the edge is not already in a subtree (and not
|
// So we know now that the edge is not already in a subtree (and not
|
||||||
// (0,entry)), so we push the edge to the MST if it has some successors.
|
// (0,entry)), so we push the edge to the MST if it has some successors.
|
||||||
if (!inverted) { MST.push_back(e); }
|
MST.push_back(e);
|
||||||
printMSTEdge(*bbi,"in MST");
|
printMSTEdge(*bbi,"in MST");
|
||||||
} else {
|
} else {
|
||||||
// This edge is either (0,entry) or (BB,0) or would create a circle in a
|
// This edge is either (0,entry) or (BB,0) or would create a circle in a
|
||||||
// subtree.
|
// subtree.
|
||||||
if (inverted) { MST.push_back(e); }
|
|
||||||
printMSTEdge(*bbi,"*not* in MST");
|
printMSTEdge(*bbi,"*not* in MST");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ namespace llvm {
|
|||||||
// special also all leaf edges of the MST are not included, this makes it
|
// special also all leaf edges of the MST are not included, this makes it
|
||||||
// easier for the OptimalEdgeProfileInstrumentation to use this MST to do
|
// easier for the OptimalEdgeProfileInstrumentation to use this MST to do
|
||||||
// an optimal profiling.
|
// an optimal profiling.
|
||||||
MaximumSpanningTree(Function *F, ProfileInfo *PI, bool invert);
|
MaximumSpanningTree(std::vector<ProfileInfo::EdgeWeight>&);
|
||||||
virtual ~MaximumSpanningTree() {}
|
virtual ~MaximumSpanningTree() {}
|
||||||
|
|
||||||
virtual MaxSpanTree::iterator begin();
|
virtual MaxSpanTree::iterator begin();
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
#include "llvm/Transforms/Instrumentation.h"
|
#include "llvm/Transforms/Instrumentation.h"
|
||||||
|
#include "llvm/ADT/DenseSet.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "MaximumSpanningTree.h"
|
#include "MaximumSpanningTree.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -32,7 +33,6 @@ STATISTIC(NumEdgesInserted, "The # of edges inserted.");
|
|||||||
namespace {
|
namespace {
|
||||||
class VISIBILITY_HIDDEN OptimalEdgeProfiler : public ModulePass {
|
class VISIBILITY_HIDDEN OptimalEdgeProfiler : public ModulePass {
|
||||||
bool runOnModule(Module &M);
|
bool runOnModule(Module &M);
|
||||||
ProfileInfo *PI;
|
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
OptimalEdgeProfiler() : ModulePass(&ID) {}
|
OptimalEdgeProfiler() : ModulePass(&ID) {}
|
||||||
@ -128,8 +128,10 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
|||||||
// The third parameter of MaximumSpanningTree() has the effect that not the
|
// The third parameter of MaximumSpanningTree() has the effect that not the
|
||||||
// actual MST is returned but the edges _not_ in the MST.
|
// actual MST is returned but the edges _not_ in the MST.
|
||||||
|
|
||||||
PI = &getAnalysisID<ProfileInfo>(ProfileEstimatorPassID, *F);
|
ProfileInfo::EdgeWeights ECs =
|
||||||
MaximumSpanningTree MST = MaximumSpanningTree(&(*F), PI, true);
|
getAnalysisID<ProfileInfo>(ProfileEstimatorPassID, *F).getEdgeWeights(F);
|
||||||
|
std::vector<ProfileInfo::EdgeWeight> EdgeVector(ECs.begin(), ECs.end());
|
||||||
|
MaximumSpanningTree MST = MaximumSpanningTree(EdgeVector);
|
||||||
|
|
||||||
// Check if (0,entry) not in the MST. If not, instrument edge
|
// Check if (0,entry) not in the MST. If not, instrument edge
|
||||||
// (IncrementCounterInBlock()) and set the counter initially to zero, if
|
// (IncrementCounterInBlock()) and set the counter initially to zero, if
|
||||||
@ -137,7 +139,7 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
|||||||
|
|
||||||
BasicBlock *entry = &(F->getEntryBlock());
|
BasicBlock *entry = &(F->getEntryBlock());
|
||||||
ProfileInfo::Edge edge = ProfileInfo::getEdge(0,entry);
|
ProfileInfo::Edge edge = ProfileInfo::getEdge(0,entry);
|
||||||
if (std::binary_search(MST.begin(), MST.end(), edge)) {
|
if (!std::binary_search(MST.begin(), MST.end(), edge)) {
|
||||||
printEdgeCounter(edge,entry,i);
|
printEdgeCounter(edge,entry,i);
|
||||||
IncrementCounterInBlock(entry, i, Counters); NumEdgesInserted++;
|
IncrementCounterInBlock(entry, i, Counters); NumEdgesInserted++;
|
||||||
Initializer[i++] = (zeroc);
|
Initializer[i++] = (zeroc);
|
||||||
@ -147,7 +149,7 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
|||||||
|
|
||||||
// InsertedBlocks contains all blocks that were inserted for splitting an
|
// InsertedBlocks contains all blocks that were inserted for splitting an
|
||||||
// edge, this blocks do not have to be instrumented.
|
// edge, this blocks do not have to be instrumented.
|
||||||
std::set<BasicBlock*> InsertedBlocks;
|
DenseSet<BasicBlock*> InsertedBlocks;
|
||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
||||||
// Check if block was not inserted and thus does not have to be
|
// Check if block was not inserted and thus does not have to be
|
||||||
// instrumented.
|
// instrumented.
|
||||||
@ -160,7 +162,7 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
|||||||
TerminatorInst *TI = BB->getTerminator();
|
TerminatorInst *TI = BB->getTerminator();
|
||||||
if (TI->getNumSuccessors() == 0) {
|
if (TI->getNumSuccessors() == 0) {
|
||||||
ProfileInfo::Edge edge = ProfileInfo::getEdge(BB,0);
|
ProfileInfo::Edge edge = ProfileInfo::getEdge(BB,0);
|
||||||
if (std::binary_search(MST.begin(), MST.end(), edge)) {
|
if (!std::binary_search(MST.begin(), MST.end(), edge)) {
|
||||||
printEdgeCounter(edge,BB,i);
|
printEdgeCounter(edge,BB,i);
|
||||||
IncrementCounterInBlock(BB, i, Counters); NumEdgesInserted++;
|
IncrementCounterInBlock(BB, i, Counters); NumEdgesInserted++;
|
||||||
Initializer[i++] = (zeroc);
|
Initializer[i++] = (zeroc);
|
||||||
@ -171,12 +173,12 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
|||||||
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
||||||
BasicBlock *Succ = TI->getSuccessor(s);
|
BasicBlock *Succ = TI->getSuccessor(s);
|
||||||
ProfileInfo::Edge edge = ProfileInfo::getEdge(BB,Succ);
|
ProfileInfo::Edge edge = ProfileInfo::getEdge(BB,Succ);
|
||||||
if (std::binary_search(MST.begin(), MST.end(), edge)) {
|
if (!std::binary_search(MST.begin(), MST.end(), edge)) {
|
||||||
|
|
||||||
// If the edge is critical, split it.
|
// If the edge is critical, split it.
|
||||||
bool wasInserted = SplitCriticalEdge(TI, s, this);
|
bool wasInserted = SplitCriticalEdge(TI, s, this);
|
||||||
Succ = TI->getSuccessor(s);
|
Succ = TI->getSuccessor(s);
|
||||||
if(wasInserted)
|
if (wasInserted)
|
||||||
InsertedBlocks.insert(Succ);
|
InsertedBlocks.insert(Succ);
|
||||||
|
|
||||||
// Okay, we are guaranteed that the edge is no longer critical. If
|
// Okay, we are guaranteed that the edge is no longer critical. If
|
||||||
|
Loading…
x
Reference in New Issue
Block a user