[lld] r195516 - [InputGraph] Add capability to process Hidden nodes.

Shankar Easwaran shankare at codeaurora.org
Fri Nov 22 15:19:53 PST 2013


Author: shankare
Date: Fri Nov 22 17:19:53 2013
New Revision: 195516

URL: http://llvm.org/viewvc/llvm-project?rev=195516&view=rev
Log:
[InputGraph] Add capability to process Hidden nodes.

Hidden nodes could be a result of expansion, where a flavor might decide to keep
the node that we want to expand but discard it from being processed by the
resolver.

Verifies with unittests.

Modified:
    lld/trunk/include/lld/Core/InputGraph.h
    lld/trunk/lib/Core/InputGraph.cpp
    lld/trunk/lib/Driver/Driver.cpp
    lld/trunk/unittests/DriverTests/InputGraphTest.cpp

Modified: lld/trunk/include/lld/Core/InputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=195516&r1=195515&r2=195516&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/InputGraph.h (original)
+++ lld/trunk/include/lld/Core/InputGraph.h Fri Nov 22 17:19:53 2013
@@ -185,6 +185,10 @@ public:
   /// \brief Reset the next index
   virtual void resetNextIndex() = 0;
 
+  /// \brief Is this a hidden node, hidden nodes are not part of
+  /// of the resolver.
+  virtual bool isHidden() const { return false; }
+
   /// Normalize functions
 
   /// \brief How do we want to expand the current node ?

Modified: lld/trunk/lib/Core/InputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=195516&r1=195515&r2=195516&view=diff
==============================================================================
--- lld/trunk/lib/Core/InputGraph.cpp (original)
+++ lld/trunk/lib/Core/InputGraph.cpp Fri Nov 22 17:19:53 2013
@@ -75,7 +75,11 @@ void InputGraph::insertOneElementAt(std:
 ErrorOr<InputElement *> InputGraph::getNextInputElement() {
   if (_nextElementIndex >= _inputArgs.size())
     return make_error_code(InputGraphError::no_more_elements);
-  return _inputArgs[_nextElementIndex++].get();
+  auto elem = _inputArgs[_nextElementIndex++].get();
+  // Do not return Hidden elements.
+  if (!elem->isHidden())
+    return elem;
+  return getNextInputElement();
 }
 
 /// \brief Set the index on what inputElement has to be returned

Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=195516&r1=195515&r2=195516&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Fri Nov 22 17:19:53 2013
@@ -54,6 +54,9 @@ bool Driver::link(LinkingContext &contex
   TaskGroup tg;
   std::mutex diagnosticsMutex;
   for (auto &ie : inputGraph.inputElements()) {
+    // Skip Hidden elements.
+    if (ie->isHidden())
+      continue;
     tg.spawn([&] {
       // Writes to the same output stream is not guaranteed to be thread-safe.
       // We buffer the diagnostics output to a separate string-backed output

Modified: lld/trunk/unittests/DriverTests/InputGraphTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/InputGraphTest.cpp?rev=195516&r1=195515&r2=195516&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/InputGraphTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/InputGraphTest.cpp Fri Nov 22 17:19:53 2013
@@ -80,8 +80,11 @@ public:
 
 class MyExpandFileNode : public FileNode {
 public:
-  MyExpandFileNode(StringRef path, int64_t ordinal, ExpandType expandType)
-      : FileNode(path, ordinal), _expandType(expandType) {}
+  MyExpandFileNode(StringRef path, int64_t ordinal,
+                   ExpandType expandType, bool isHidden=false)
+      : FileNode(path, ordinal), _expandType(expandType),
+        _isHidden(isHidden)
+  {}
 
   bool validate() { return true; }
 
@@ -111,9 +114,13 @@ public:
     return true;
   }
 
+  // Is hidden node
+  virtual bool isHidden() const { return _isHidden; }
+
 private:
   InputGraph::InputElementVectorT _expandElements;
   ExpandType _expandType;
+  bool _isHidden;
 };
 
 class MyObjFile : public SimpleFile {
@@ -550,4 +557,77 @@ TEST_F(InputGraphTest, ExpandAndReplaceI
   nextElement = inputGraph().getNextInputElement();
   EXPECT_EQ(InputGraphError::no_more_elements, error_code(nextElement));
 }
+
+// Hidden Node tests
+TEST_F(InputGraphTest, HiddenNodeTests) {
+  std::unique_ptr<MyFileNode> myfile(new MyFileNode("multi_files1", 0));
+  std::vector<std::unique_ptr<File> > objfiles;
+  std::unique_ptr<MyObjFile> obj1(new MyObjFile(_context, "objfile1"));
+  std::unique_ptr<MyObjFile> obj2(new MyObjFile(_context, "objfile2"));
+  objfiles.push_back(std::move(obj1));
+  objfiles.push_back(std::move(obj2));
+  myfile->addFiles(std::move(objfiles));
+  EXPECT_EQ(true, inputGraph().addInputElement(std::move(myfile)));
+  objfiles.clear();
+
+  std::unique_ptr<MyExpandFileNode> expandFile(new MyExpandFileNode(
+      "expand_node", 1, InputElement::ExpandType::ExpandOnly, true));
+
+  std::unique_ptr<MyFileNode> filenode1(new MyFileNode("expand_file1", 2));
+  std::unique_ptr<MyObjFile> obj3(new MyObjFile(_context, "objfile3"));
+  objfiles.push_back(std::move(obj3));
+  filenode1->addFiles(std::move(objfiles));
+  expandFile->addElement(std::move(filenode1));
+  objfiles.clear();
+
+  std::unique_ptr<MyFileNode> filenode2(new MyFileNode("expand_file2", 3));
+  std::unique_ptr<MyObjFile> obj4(new MyObjFile(_context, "objfile4"));
+  objfiles.push_back(std::move(obj4));
+  filenode2->addFiles(std::move(objfiles));
+  expandFile->addElement(std::move(filenode2));
+  objfiles.clear();
+
+  // Add expand file to InputGraph
+  EXPECT_EQ(true, inputGraph().addInputElement(std::move(expandFile)));
+
+  std::unique_ptr<MyFileNode> filenode3(new MyFileNode("obj_after_expand", 4));
+  std::unique_ptr<MyObjFile> obj5(new MyObjFile(_context, "objfile5"));
+  std::unique_ptr<MyObjFile> obj6(new MyObjFile(_context, "objfile6"));
+  objfiles.push_back(std::move(obj5));
+  objfiles.push_back(std::move(obj6));
+  filenode3->addFiles(std::move(objfiles));
+
+  // Add an extra obj after the expand node
+  EXPECT_EQ(true, inputGraph().addInputElement(std::move(filenode3)));
+
+  inputGraph().normalize();
+
+  ErrorOr<InputElement *> nextElement = inputGraph().getNextInputElement();
+  EXPECT_NE(InputGraphError::no_more_elements, error_code(nextElement));
+  EXPECT_EQ(InputElement::Kind::File, (*nextElement)->kind());
+  FileNode *fileNode = llvm::dyn_cast<FileNode>(*nextElement);
+  EXPECT_EQ("multi_files1", (*fileNode).getUserPath());
+
+  nextElement = inputGraph().getNextInputElement();
+  EXPECT_NE(InputGraphError::no_more_elements, error_code(nextElement));
+  EXPECT_EQ(InputElement::Kind::File, (*nextElement)->kind());
+  fileNode = llvm::dyn_cast<FileNode>(*nextElement);
+  EXPECT_EQ("expand_file1", (*fileNode).getUserPath());
+
+  nextElement = inputGraph().getNextInputElement();
+  EXPECT_NE(InputGraphError::no_more_elements, error_code(nextElement));
+  EXPECT_EQ(InputElement::Kind::File, (*nextElement)->kind());
+  fileNode = llvm::dyn_cast<FileNode>(*nextElement);
+  EXPECT_EQ("expand_file2", (*fileNode).getUserPath());
+
+  nextElement = inputGraph().getNextInputElement();
+  EXPECT_NE(InputGraphError::no_more_elements, error_code(nextElement));
+  EXPECT_EQ(InputElement::Kind::File, (*nextElement)->kind());
+  fileNode = llvm::dyn_cast<FileNode>(*nextElement);
+  EXPECT_EQ("obj_after_expand", (*fileNode).getUserPath());
+
+  nextElement = inputGraph().getNextInputElement();
+  EXPECT_EQ(InputGraphError::no_more_elements, error_code(nextElement));
+}
+
 }





More information about the llvm-commits mailing list