[llvm-commits] [llvm] r50757 - in /llvm/trunk: tools/llvmc2/CompilationGraph.cpp tools/llvmc2/CompilationGraph.h utils/TableGen/LLVMCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Tue May 6 11:14:24 PDT 2008


Author: foldr
Date: Tue May  6 13:14:24 2008
New Revision: 50757

URL: http://llvm.org/viewvc/llvm-project?rev=50757&view=rev
Log:
Add weights to graph edges. Choose between edges based on their weight.

Modified:
    llvm/trunk/tools/llvmc2/CompilationGraph.cpp
    llvm/trunk/tools/llvmc2/CompilationGraph.h
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Modified: llvm/trunk/tools/llvmc2/CompilationGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.cpp?rev=50757&r1=50756&r2=50757&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.cpp (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.cpp Tue May  6 13:14:24 2008
@@ -33,35 +33,37 @@
 
 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;
   }
 
 }

Modified: llvm/trunk/tools/llvmc2/CompilationGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.h?rev=50757&r1=50756&r2=50757&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.h (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.h Tue May  6 13:14:24 2008
@@ -35,8 +35,7 @@
     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 @@
   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.

Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=50757&r1=50756&r2=50757&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Tue May  6 13:14:24 2008
@@ -974,9 +974,9 @@
     << Indent1 << "Edge" << N << "() : Edge(\"" << Target
     << "\") {}\n\n"
 
-    // Function isEnabled().
-    << Indent1 << "bool isEnabled() const {\n"
-    << Indent2 << "bool ret = false;\n";
+  // Function Weight().
+    << Indent1 << "unsigned Weight() const {\n"
+    << Indent2 << "unsigned ret = 0;\n";
 
   for (size_t i = 0, PropsSize = Props->size(); i < PropsSize; ++i) {
     const DagInit& Prop = dynamic_cast<DagInit&>(*Props->getElement(i));
@@ -985,7 +985,7 @@
     if (PropName == "default")
       IsDefault = true;
 
-    O << Indent2 << "if (ret || (";
+    O << Indent2 << "if ((";
     if (PropName == "and") {
       O << '(';
       for (unsigned j = 0, NumArgs = Prop.getNumArgs(); j < NumArgs; ++j) {
@@ -1002,19 +1002,14 @@
     else {
       EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
     }
-    O << "))\n" << Indent3 << "ret = true;\n";
+    O << "))\n" << Indent3 << "ret += 2;\n";
   }
 
-  O << Indent2 << "return ret;\n"
-    << Indent1 << "};\n\n"
-
-  // Function isDefault().
-    << Indent1 << "bool isDefault() const { return ";
   if (IsDefault)
-    O << "true";
-  else
-    O << "false";
-  O <<"; }\n};\n\n";
+    O << Indent2 << "ret += 1;\n";
+
+  O << Indent2 << "return ret;\n"
+    << Indent1 << "};\n\n};\n\n";
 }
 
 // Emit Edge* classes that represent graph edges.





More information about the llvm-commits mailing list