+/// NotInGraph - Helper function object for FilterNotInGraph.
+struct NotInGraph {
+private:
+ const llvm::StringSet<>& ToolsInGraph_;
+
+public:
+ NotInGraph(const llvm::StringSet<>& ToolsInGraph)
+ : ToolsInGraph_(ToolsInGraph)
+ {}
+
+ bool operator()(const IntrusiveRefCntPtr<ToolProperties>& x) {
+ return (ToolsInGraph_.count(x->Name) == 0);
+ }
+};
+
+/// FilterNotInGraph - Filter out from ToolProps all Tools not
+/// mentioned in the compilation graph definition.
+void FilterNotInGraph (const Record* CompilationGraph,
+ ToolPropertiesList& ToolProps) {
+
+ // List all tools mentioned in the graph.
+ llvm::StringSet<> ToolsInGraph;
+ ListInit* edges = CompilationGraph->getValueAsListInit("edges");
+
+ for (unsigned i = 0; i < edges->size(); ++i) {
+ const Record* Edge = edges->getElementAsRecord(i);
+ const std::string& A = Edge->getValueAsString("a");
+ const std::string& B = Edge->getValueAsString("b");
+
+ if (A != "root")
+ ToolsInGraph.insert(A);
+ ToolsInGraph.insert(B);
+ }
+
+ // Filter ToolPropertiesList.
+ ToolPropertiesList::iterator new_end =
+ std::remove_if(ToolProps.begin(), ToolProps.end(),
+ NotInGraph(ToolsInGraph));
+ ToolProps.erase(new_end, ToolProps.end());
+}
+