[PATCH] D129952: [ORC][COFF] Handle COFF import files of static archive.

Sunho Kim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 11:34:06 PDT 2022


sunho updated this revision to Diff 447776.
sunho added a comment.
Herald added a subscriber: mgrang.

Optimize code a bit. I don't think this part of code needs optimization but I couldn't help it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129952/new/

https://reviews.llvm.org/D129952

Files:
  llvm/tools/llvm-jitlink/llvm-jitlink.cpp


Index: llvm/tools/llvm-jitlink/llvm-jitlink.cpp
===================================================================
--- llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -14,6 +14,7 @@
 
 #include "llvm-jitlink.h"
 
+#include "llvm/ADT/PriorityQueue.h"
 #include "llvm/BinaryFormat/Magic.h"
 #include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
 #include "llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h"
@@ -51,7 +52,6 @@
 
 #include <cstring>
 #include <list>
-#include <stack>
 #include <string>
 
 #ifdef LLVM_ON_UNIX
@@ -1587,7 +1587,14 @@
     StringRef *CandidateExtensions;
     enum { Standard, Hidden } Modifier;
   };
-  std::vector<LibraryLoad> LibraryLoads;
+
+  // Stack to load library one by one with an option to push another library
+  // load.
+  auto Comp = [](const LibraryLoad &LHS, const LibraryLoad &RHS) -> bool {
+    return LHS.Position > RHS.Position;
+  };
+  llvm::PriorityQueue<LibraryLoad, SmallVector<LibraryLoad, 2>, decltype(Comp)>
+      LibraryLoadStack(Comp);
   // Add archive files from the inputs to LibraryLoads.
   for (auto InputFileItr = InputFiles.begin(), InputFileEnd = InputFiles.end();
        InputFileItr != InputFileEnd; ++InputFileItr) {
@@ -1600,7 +1607,7 @@
     LL.Position = InputFiles.getPosition(InputFileItr - InputFiles.begin());
     LL.CandidateExtensions = nullptr;
     LL.Modifier = LibraryLoad::Standard;
-    LibraryLoads.push_back(std::move(LL));
+    LibraryLoadStack.push(std::move(LL));
   }
 
   // Add -load_hidden arguments to LibraryLoads.
@@ -1612,7 +1619,7 @@
     LL.Position = LoadHidden.getPosition(LibItr - LoadHidden.begin());
     LL.CandidateExtensions = nullptr;
     LL.Modifier = LibraryLoad::Hidden;
-    LibraryLoads.push_back(std::move(LL));
+    LibraryLoadStack.push(std::move(LL));
   }
   StringRef StandardExtensions[] = {".so", ".dylib", ".dll", ".a", ".lib"};
   StringRef DynLibExtensionsOnly[] = {".so", ".dylib", ".dll"};
@@ -1626,7 +1633,7 @@
     LL.Position = Libraries.getPosition(LibItr - Libraries.begin());
     LL.CandidateExtensions = StandardExtensions;
     LL.Modifier = LibraryLoad::Standard;
-    LibraryLoads.push_back(std::move(LL));
+    LibraryLoadStack.push(std::move(LL));
   }
 
   // Add -hidden-lx arguments to LibraryLoads.
@@ -1639,7 +1646,7 @@
         LibrariesHidden.getPosition(LibHiddenItr - LibrariesHidden.begin());
     LL.CandidateExtensions = ArchiveExtensionsOnly;
     LL.Modifier = LibraryLoad::Hidden;
-    LibraryLoads.push_back(std::move(LL));
+    LibraryLoadStack.push(std::move(LL));
   }
 
   // If there are any load-<modified> options then turn on flag overrides
@@ -1647,17 +1654,6 @@
   if (!LibrariesHidden.empty() || !LoadHidden.empty())
     S.ObjLayer.setOverrideObjectFlagsWithResponsibilityFlags(true);
 
-  // Sort library loads by position in the argument list.
-  llvm::sort(LibraryLoads, [](const LibraryLoad &LHS, const LibraryLoad &RHS) {
-    return LHS.Position < RHS.Position;
-  });
-
-  // Stack to load library one by one with an option to push another library
-  // load.
-  std::stack<LibraryLoad> LibraryLoadStack;
-  for (auto It = LibraryLoads.rbegin(); It != LibraryLoads.rend(); ++It)
-    LibraryLoadStack.push(*It);
-
   // 3. Process library loads.
   auto AddArchive = [&](const char *Path, const LibraryLoad &LL)
       -> Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>> {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129952.447776.patch
Type: text/x-patch
Size: 3416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220726/abdfcb11/attachment.bin>


More information about the llvm-commits mailing list