summaryrefslogtreecommitdiff
path: root/tools/llvmc2
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-05-06 18:14:24 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-05-06 18:14:24 +0000
commitbb8b58dcf3e1994beb458e777b306fa3805ee50f (patch)
treece39b38a87d9e75b283bee66bc1df981082eab94 /tools/llvmc2
parentd83038c9605c84e92b6052500405ac3903f0d6f1 (diff)
downloadllvm-bb8b58dcf3e1994beb458e777b306fa3805ee50f.tar.gz
llvm-bb8b58dcf3e1994beb458e777b306fa3805ee50f.tar.bz2
llvm-bb8b58dcf3e1994beb458e777b306fa3805ee50f.tar.xz
Add weights to graph edges. Choose between edges based on their weight.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50757 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvmc2')
-rw-r--r--tools/llvmc2/CompilationGraph.cpp40
-rw-r--r--tools/llvmc2/CompilationGraph.h6
2 files changed, 23 insertions, 23 deletions
diff --git a/tools/llvmc2/CompilationGraph.cpp b/tools/llvmc2/CompilationGraph.cpp
index 4b04d6f60b..310413b9f0 100644
--- a/tools/llvmc2/CompilationGraph.cpp
+++ b/tools/llvmc2/CompilationGraph.cpp
@@ -33,35 +33,37 @@ extern cl::list<std::string> Languages;
namespace {
- // Go through the list C and find the edge that isEnabled(); if
- // there is no such edge, return the default edge; if there is no
- // default edge, throw an exception.
+ // Return the edge with the maximum weight.
template <class C>
const Edge* ChooseEdge(const C& EdgesContainer,
const std::string& NodeName = "root") {
- const Edge* DefaultEdge = 0;
+ const Edge* MaxEdge = 0;
+ unsigned MaxWeight = 0;
+ bool SingleMax = true;
for (typename C::const_iterator B = EdgesContainer.begin(),
E = EdgesContainer.end(); B != E; ++B) {
const Edge* E = B->getPtr();
-
- if (E->isDefault())
- if (!DefaultEdge)
- DefaultEdge = E;
- else
- throw std::runtime_error("Node " + NodeName
- + ": multiple default outward edges found!"
- " Most probably a specification error.");
- if (E->isEnabled())
- return E;
+ unsigned EW = E->Weight();
+ if (EW > MaxWeight) {
+ MaxEdge = E;
+ MaxWeight = EW;
+ SingleMax = true;
+ }
+ else if (EW == MaxWeight) {
+ SingleMax = false;
+ }
}
- if (DefaultEdge)
- return DefaultEdge;
- else
- throw std::runtime_error("Node " + NodeName
- + ": no default outward edge found!"
+ if (!SingleMax)
+ throw std::runtime_error("Node " + NodeName +
+ ": multiple maximal outward edges found!"
+ " Most probably a specification error.");
+ if (!MaxEdge)
+ throw std::runtime_error("Node " + NodeName +
+ ": no maximal outward edge found!"
" Most probably a specification error.");
+ return MaxEdge;
}
}
diff --git a/tools/llvmc2/CompilationGraph.h b/tools/llvmc2/CompilationGraph.h
index 4692e5155d..3dc8bc0623 100644
--- a/tools/llvmc2/CompilationGraph.h
+++ b/tools/llvmc2/CompilationGraph.h
@@ -35,8 +35,7 @@ namespace llvmc {
virtual ~Edge() {};
const std::string& ToolName() const { return ToolName_; }
- virtual bool isEnabled() const = 0;
- virtual bool isDefault() const = 0;
+ virtual unsigned Weight() const = 0;
private:
std::string ToolName_;
};
@@ -45,8 +44,7 @@ namespace llvmc {
class SimpleEdge : public Edge {
public:
SimpleEdge(const std::string& T) : Edge(T) {}
- bool isEnabled() const { return false;}
- bool isDefault() const { return true;}
+ unsigned Weight() const { return 1; }
};
// A node of the compilation graph.