diff options
author | Mikhail Glushenkov <foldr@codedgers.com> | 2010-08-23 19:24:08 +0000 |
---|---|---|
committer | Mikhail Glushenkov <foldr@codedgers.com> | 2010-08-23 19:24:08 +0000 |
commit | 7555f0a2bc8c6f052bb3563cd27c316bf68e7661 (patch) | |
tree | 0178c5707989637958769eb988472729c3fe7cfa | |
parent | c712edc785cf8a028115049ed7a05a4b4af15c00 (diff) |
llvmc: Properly handle (error) in edge properties.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111827 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/CompilerDriver/Common.td | 3 | ||||
-rw-r--r-- | include/llvm/CompilerDriver/CompilationGraph.h | 4 | ||||
-rw-r--r-- | lib/CompilerDriver/CompilationGraph.cpp | 15 | ||||
-rw-r--r-- | utils/TableGen/LLVMCConfigurationEmitter.cpp | 19 |
4 files changed, 21 insertions, 20 deletions
diff --git a/include/llvm/CompilerDriver/Common.td b/include/llvm/CompilerDriver/Common.td index d378bb74d2..46c60781ca 100644 --- a/include/llvm/CompilerDriver/Common.td +++ b/include/llvm/CompilerDriver/Common.td @@ -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; diff --git a/include/llvm/CompilerDriver/CompilationGraph.h b/include/llvm/CompilerDriver/CompilationGraph.h index e3b0cff19f..619c904f15 100644 --- a/include/llvm/CompilerDriver/CompilationGraph.h +++ b/include/llvm/CompilerDriver/CompilationGraph.h @@ -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. diff --git a/lib/CompilerDriver/CompilationGraph.cpp b/lib/CompilerDriver/CompilationGraph.cpp index 259911f713..a217078ffa 100644 --- a/lib/CompilerDriver/CompilationGraph.cpp +++ b/lib/CompilerDriver/CompilationGraph.cpp @@ -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; } diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index 3aa94aaadb..6927b01bd4 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -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"; |