llvmc: Properly handle (error) in edge properties.
authorMikhail Glushenkov <foldr@codedgers.com>
Mon, 23 Aug 2010 19:24:08 +0000 (19:24 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Mon, 23 Aug 2010 19:24:08 +0000 (19:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111827 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CompilerDriver/Common.td
include/llvm/CompilerDriver/CompilationGraph.h
lib/CompilerDriver/CompilationGraph.cpp
utils/TableGen/LLVMCConfigurationEmitter.cpp

index d378bb74d22ffb9d10531621f01f8075dc329eab..46c60781cad8399abba802d01a9944b1ce9dd265 100644 (file)
@@ -93,9 +93,8 @@ def error;
 def set_option;
 def unset_option;
 
-// Increase/decrease the edge weight.
+// Increase the edge weight.
 def inc_weight;
-def dec_weight;
 
 // Empty DAG marker.
 def empty_dag_marker;
index e3b0cff19f676cf05cbc6e7e30c0e5319eeb3dc9..619c904f15d640d04d2427884dc9ab1a40944f13 100644 (file)
@@ -46,7 +46,7 @@ namespace llvmc {
     virtual ~Edge() {}
 
     const std::string& ToolName() const { return ToolName_; }
-    virtual unsigned Weight(const InputLanguagesSet& InLangs) const = 0;
+    virtual int Weight(const InputLanguagesSet& InLangs) const = 0;
   private:
     std::string ToolName_;
   };
@@ -55,7 +55,7 @@ namespace llvmc {
   class SimpleEdge : public Edge {
   public:
     SimpleEdge(const std::string& T) : Edge(T) {}
-    unsigned Weight(const InputLanguagesSet&) const { return 1; }
+    int Weight(const InputLanguagesSet&) const { return 1; }
   };
 
   /// Node - A node (vertex) of the compilation graph.
index 259911f713705981a6fdfaa4ab82f6db87c8a299..a217078ffabe70e8e2ac170eabec011c2ce4591b 100644 (file)
@@ -46,19 +46,24 @@ namespace llvmc {
 
 namespace {
 
-  /// ChooseEdge - Return the edge with the maximum weight.
+  /// ChooseEdge - Return the edge with the maximum weight. Returns 0 on error.
   template <class C>
   const Edge* ChooseEdge(const C& EdgesContainer,
                          const InputLanguagesSet& InLangs,
                          const std::string& NodeName = "root") {
     const Edge* MaxEdge = 0;
-    unsigned MaxWeight = 0;
+    int MaxWeight = 0;
     bool SingleMax = true;
 
     for (typename C::const_iterator B = EdgesContainer.begin(),
            E = EdgesContainer.end(); B != E; ++B) {
       const Edge* e = B->getPtr();
-      unsigned EW = e->Weight(InLangs);
+      int EW = e->Weight(InLangs);
+      if (EW < 0) {
+        // (error) invocation in TableGen -> we don't need to print an error
+        // message.
+        return 0;
+      }
       if (EW > MaxWeight) {
         MaxEdge = e;
         MaxWeight = EW;
@@ -474,7 +479,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
   for (const_nodes_iterator B = this->NodesMap.begin(),
          E = this->NodesMap.end(); B != E; ++B) {
     const Node& N = B->second;
-    unsigned MaxWeight = 0;
+    int MaxWeight = 0;
 
     // Ignore the root node.
     if (!N.ToolPtr)
@@ -482,7 +487,7 @@ int CompilationGraph::CheckMultipleDefaultEdges() const {
 
     for (Node::const_iterator EB = N.EdgesBegin(), EE = N.EdgesEnd();
          EB != EE; ++EB) {
-      unsigned EdgeWeight = (*EB)->Weight(Dummy);
+      int EdgeWeight = (*EB)->Weight(Dummy);
       if (EdgeWeight > MaxWeight) {
         MaxWeight = EdgeWeight;
       }
index 3aa94aaadbdfdb10177aa680ff1b0d8697c1b686..6927b01bd40e7ec81543ef7fe0cfdd73edb7119f 100644 (file)
@@ -1950,7 +1950,6 @@ struct ActionHandlingCallbackBase
 
 /// EmitActionHandlersCallback - Emit code that handles actions. Used by
 /// EmitGenerateActionMethod() as an argument to EmitCaseConstructHandler().
-
 class EmitActionHandlersCallback;
 
 typedef void (EmitActionHandlersCallback::* EmitActionHandlersCallbackHandler)
@@ -2649,21 +2648,18 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O)
   O << "}\n\n";
 }
 
-/// IncDecWeight - Helper function passed to EmitCaseConstructHandler()
-/// by EmitEdgeClass().
-void IncDecWeight (const Init* i, unsigned IndentLevel,
-                   raw_ostream& O) {
+/// EmitEdgePropertyHandlerCallback - Emits code that handles edge
+/// properties. Helper function passed to EmitCaseConstructHandler() by
+/// EmitEdgeClass().
+void EmitEdgePropertyHandlerCallback (const Init* i, unsigned IndentLevel,
+                                      raw_ostream& O) {
   const DagInit& d = InitPtrToDag(i);
   const std::string& OpName = GetOperatorName(d);
 
   if (OpName == "inc_weight") {
     O.indent(IndentLevel) << "ret += ";
   }
-  else if (OpName == "dec_weight") {
-    O.indent(IndentLevel) << "ret -= ";
-  }
   else if (OpName == "error") {
-    // TODO: fix this
     CheckNumberOfArguments(d, 1);
     O.indent(IndentLevel) << "PrintError(\""
                           << InitPtrToString(d.getArg(0))
@@ -2696,11 +2692,12 @@ void EmitEdgeClass (unsigned N, const std::string& Target,
 
   // Function Weight().
   O.indent(Indent1)
-    << "unsigned Weight(const InputLanguagesSet& InLangs) const {\n";
+    << "int Weight(const InputLanguagesSet& InLangs) const {\n";
   O.indent(Indent2) << "unsigned ret = 0;\n";
 
   // Handle the 'case' construct.
-  EmitCaseConstructHandler(Case, Indent2, IncDecWeight, false, OptDescs, O);
+  EmitCaseConstructHandler(Case, Indent2, EmitEdgePropertyHandlerCallback,
+                           false, OptDescs, O);
 
   O.indent(Indent2) << "return ret;\n";
   O.indent(Indent1) << "}\n\n};\n\n";