[llvm-commits] [llvm] r50726 - in /llvm/trunk: tools/llvmc2/Common.td tools/llvmc2/CompilationGraph.cpp tools/llvmc2/CompilationGraph.h tools/llvmc2/Example.td tools/llvmc2/Makefile utils/TableGen/LLVMCCConfigurationEmitter.cpp
Tanya Lattner
lattner at apple.com
Tue May 6 10:52:56 PDT 2008
Please use doxygen style comments (///).
I'm going to stop responding to all the other patches, but you get
the idea. Please fix and add comments :)
-Tanya
On May 6, 2008, at 9:36 AM, Mikhail Glushenkov wrote:
> Author: foldr
> Date: Tue May 6 11:36:50 2008
> New Revision: 50726
>
> URL: http://llvm.org/viewvc/llvm-project?rev=50726&view=rev
> Log:
> More work on edge properties. Use Edge classes instead of strings
> in CompilationGraph.
>
> Modified:
> llvm/trunk/tools/llvmc2/Common.td
> llvm/trunk/tools/llvmc2/CompilationGraph.cpp
> llvm/trunk/tools/llvmc2/CompilationGraph.h
> llvm/trunk/tools/llvmc2/Example.td
> llvm/trunk/tools/llvmc2/Makefile
> llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
>
> Modified: llvm/trunk/tools/llvmc2/Common.td
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/
> Common.td?rev=50726&r1=50725&r2=50726&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/tools/llvmc2/Common.td (original)
> +++ llvm/trunk/tools/llvmc2/Common.td Tue May 6 11:36:50 2008
> @@ -50,10 +50,6 @@
> def switch_on;
> def parameter_equals;
> def element_in_list;
> -
> -// Property combinators
> -// TOFIX: implement
> -def and;
> def or;
>
> // Map from suffixes to language names
>
> Modified: llvm/trunk/tools/llvmc2/CompilationGraph.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/
> CompilationGraph.cpp?rev=50726&r1=50725&r2=50726&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/tools/llvmc2/CompilationGraph.cpp (original)
> +++ llvm/trunk/tools/llvmc2/CompilationGraph.cpp Tue May 6
> 11:36:50 2008
> @@ -32,14 +32,14 @@
> Node& CompilationGraph::getNode(const std::string& ToolName) {
> nodes_map_type::iterator I = NodesMap.find(ToolName);
> if (I == NodesMap.end())
> - throw std::runtime_error("Node " + ToolName + " is not in
> graph");
> + throw std::runtime_error("Node " + ToolName + " is not in the
> graph");
> return I->second;
> }
>
> const Node& CompilationGraph::getNode(const std::string& ToolName)
> const {
> nodes_map_type::const_iterator I = NodesMap.find(ToolName);
> if (I == NodesMap.end())
> - throw std::runtime_error("Node " + ToolName + " is not in
> graph!");
> + throw std::runtime_error("Node " + ToolName + " is not in the
> graph!");
> return I->second;
> }
>
> @@ -69,31 +69,23 @@
> }
> }
>
> -void CompilationGraph::insertEdge(const std::string& A,
> - const std::string& B) {
> - // TOTHINK: check this at compile-time?
> - if (B == "root")
> - throw std::runtime_error("Edges back to the root are not
> allowed!"
> - "Compilation graph should be acyclic!");
> -
> +void CompilationGraph::insertEdge(const std::string& A, Edge* E) {
> if (A == "root") {
> - const Node& N = getNode(B);
> + const Node& N = getNode(E->ToolName());
> const std::string& InputLanguage = N.ToolPtr->InputLanguage();
> - ToolsMap[InputLanguage].push_back(B);
> + ToolsMap[InputLanguage].push_back(E->ToolName());
>
> // Needed to support iteration via GraphTraits.
> - NodesMap["root"].AddEdge(new DefaultEdge(B));
> + NodesMap["root"].AddEdge(E);
> }
> else {
> Node& N = getNode(A);
> - // Check that there is a node at B.
> - getNode(B);
> - N.AddEdge(new DefaultEdge(B));
> + N.AddEdge(E);
> }
> }
>
> -// TOFIX: extend, add an ability to choose between different
> -// toolchains, support more interesting graph topologies.
> +// TOFIX: support edge properties.
> +// TOFIX: support more interesting graph topologies.
> int CompilationGraph::Build (const sys::Path& tempDir) const {
> PathVector JoinList;
> const Tool* JoinTool = 0;
> @@ -124,7 +116,11 @@
>
> // Is this the last tool?
> if (!N->HasChildren() || CurTool->IsLast()) {
> - Out.appendComponent(In.getBasename());
> + // Check if the first tool is also the last
> + if(Out.empty())
> + Out.set(In.getBasename());
> + else
> + Out.appendComponent(In.getBasename());
> Out.appendSuffix(CurTool->OutputSuffix());
> Last = true;
> }
> @@ -191,5 +187,5 @@
> }
>
> void CompilationGraph::viewGraph() {
> - llvm::ViewGraph(this, "CompilationGraph");
> + llvm::ViewGraph(this, "compilation-graph");
> }
>
> Modified: llvm/trunk/tools/llvmc2/CompilationGraph.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/
> CompilationGraph.h?rev=50726&r1=50725&r2=50726&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/tools/llvmc2/CompilationGraph.h (original)
> +++ llvm/trunk/tools/llvmc2/CompilationGraph.h Tue May 6 11:36:50
> 2008
> @@ -28,6 +28,7 @@
>
> namespace llvmcc {
>
> + // An edge in the graph.
> class Edge : public llvm::RefCountedBaseVPTR<Edge> {
> public:
> Edge(const std::string& T) : ToolName_(T) {}
> @@ -40,13 +41,15 @@
> std::string ToolName_;
> };
>
> - class DefaultEdge : public Edge {
> + // Edges with no properties are instances of this class.
> + class SimpleEdge : public Edge {
> public:
> - DefaultEdge(const std::string& T) : Edge(T) {}
> + SimpleEdge(const std::string& T) : Edge(T) {}
> bool isEnabled() const { return true;}
> bool isDefault() const { return true;}
> };
>
> + // A node in the graph.
> struct Node {
> typedef llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3>
> container_type;
> typedef container_type::iterator iterator;
> @@ -56,14 +59,14 @@
> Node(CompilationGraph* G) : OwningGraph(G) {}
> Node(CompilationGraph* G, Tool* T) : OwningGraph(G), ToolPtr
> (T) {}
>
> - bool HasChildren() const { return OutEdges.empty(); }
> + bool HasChildren() const { return !OutEdges.empty(); }
>
> iterator EdgesBegin() { return OutEdges.begin(); }
> const_iterator EdgesBegin() const { return OutEdges.begin(); }
> iterator EdgesEnd() { return OutEdges.end(); }
> const_iterator EdgesEnd() const { return OutEdges.end(); }
>
> - // E is a new-allocated pointer.
> + // Takes ownership of the object.
> void AddEdge(Edge* E)
> { OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
>
> @@ -93,16 +96,16 @@
>
> CompilationGraph();
>
> - // insertVertex - insert a new node into the graph.
> + // insertVertex - insert a new node into the graph. Takes
> + // ownership of the object.
> void insertNode(Tool* T);
>
> - // insertEdge - Insert a new edge into the graph. This function
> - // assumes that both A and B have been already inserted.
> - void insertEdge(const std::string& A, const std::string& B);
> -
> - // Build - Build the target(s) from the set of the input
> - // files. Command-line options are passed implicitly as global
> - // variables.
> + // insertEdge - Insert a new edge into the graph. Takes ownership
> + // of the object.
> + void insertEdge(const std::string& A, Edge* E);
> +
> + // Build - Build target(s) from the input file set. Command-line
> + // options are passed implicitly as global variables.
> int Build(llvm::sys::Path const& tempDir) const;
>
> // Return a reference to the node correponding to the given tool
>
> Modified: llvm/trunk/tools/llvmc2/Example.td
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/
> Example.td?rev=50726&r1=50725&r2=50726&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/tools/llvmc2/Example.td (original)
> +++ llvm/trunk/tools/llvmc2/Example.td Tue May 6 11:36:50 2008
> @@ -21,9 +21,16 @@
> Edge<root, llvm_gcc_assembler>,
> Edge<root, llvm_gcc_cpp>,
> Edge<root, llvm_as>,
> +
> Edge<llvm_gcc_c, llc>,
> Edge<llvm_gcc_cpp, llc>,
> Edge<llvm_as, llc>,
> +
> + OptionalEdge<llvm_gcc_c, opt, [(switch_on "opt")]>,
> + OptionalEdge<llvm_gcc_cpp, opt, [(switch_on "opt")]>,
> + OptionalEdge<llvm_as, opt, [(switch_on "opt")]>,
> + OptionalEdge<opt, llc, [(switch_on "opt")]>,
> +
> Edge<llc, llvm_gcc_assembler>,
> Edge<llvm_gcc_assembler, llvm_gcc_linker>
> ]>;
>
> Modified: llvm/trunk/tools/llvmc2/Makefile
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/
> Makefile?rev=50726&r1=50725&r2=50726&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/tools/llvmc2/Makefile (original)
> +++ llvm/trunk/tools/llvmc2/Makefile Tue May 6 11:36:50 2008
> @@ -14,12 +14,7 @@
>
> include $(LEVEL)/Makefile.common
>
> -TOOLS_TARGET=default
> -ifeq ($(TOOLS_TARGET), default)
> - TOOLS_SOURCE=Example.td
> -else
> - TOOLS_SOURCE=ExampleWithOpt.td
> -endif
> +TOOLS_SOURCE=Example.td
>
> # TOFIX: integrate this part into Makefile.rules?
> # The degree of horrorshowness in that file is too much for me atm.
>
> Modified: llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/
> LLVMCCConfigurationEmitter.cpp?rev=50726&r1=50725&r2=50726&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
> (original)
> +++ llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp Tue
> May 6 11:36:50 2008
> @@ -866,6 +866,8 @@
> }
>
> // Check that all output and input language names match.
> +// TOFIX: check for cycles.
> +// TOFIX: check for multiple default edges.
> void TypecheckGraph (Record* CompilationGraph,
> const ToolPropertiesList& TPList) {
> StringMap<std::string> ToolToInLang;
> @@ -889,22 +891,36 @@
> if(A->getName() != "root" && IA->second != IB->second)
> throw "Edge " + A->getName() + "->" + B->getName()
> + ": output->input language mismatch";
> + if(B->getName() == "root")
> + throw std::string("Edges back to the root are not allowed!");
> }
> }
>
> -// Emit Edge* classes used for.
> +// Emit Edge* classes that represent edges in the graph.
> +// TOFIX: add edge properties.
> void EmitEdgeClasses (Record* CompilationGraph,
> const GlobalOptionDescriptions& OptDescs,
> std::ostream& O) {
> ListInit* edges = CompilationGraph->getValueAsListInit("edges");
>
> for (unsigned i = 0; i < edges->size(); ++i) {
> - //Record* Edge = edges->getElementAsRecord(i);
> - //Record* A = Edge->getValueAsDef("a");
> - //Record* B = Edge->getValueAsDef("b");
> - //ListInit* Props = Edge->getValueAsListInit("props");
> + Record* Edge = edges->getElementAsRecord(i);
> + Record* B = Edge->getValueAsDef("b");
> + ListInit* Props = Edge->getValueAsListInit("props");
> +
> + if (Props->empty())
> + continue;
> +
> + O << "class Edge" << i << ": public Edge {\n"
> + << "public:\n"
> + << Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
> + << "\") {}\n";
> +
> + O << Indent1 << "bool isEnabled() const { return true; }\n";
>
> - O << "class Edge" << i << " {};\n\n";
> + O << Indent1 << "bool isDefault() const { return false; }\n";
> +
> + O << "};\n\n";
> }
> }
>
> @@ -937,8 +953,16 @@
> Record* Edge = edges->getElementAsRecord(i);
> Record* A = Edge->getValueAsDef("a");
> Record* B = Edge->getValueAsDef("b");
> - O << Indent1 << "G.insertEdge(\"" << A->getName() << "\", \""
> - << B->getName() << "\");\n";
> + ListInit* Props = Edge->getValueAsListInit("props");
> +
> + O << Indent1 << "G.insertEdge(\"" << A->getName() << "\", ";
> +
> + if (Props->empty())
> + O << "new SimpleEdge(\"" << B->getName() << "\")";
> + else
> + O << "new Edge" << i << "()";
> +
> + O << ");\n";
> }
>
> O << "}\n\n";
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list