[PATCH] D41581: [COFF] Do not parse args twice if no rsp files exists

Takuto Ikuta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 26 20:46:05 PST 2017


takuto.ikuta updated this revision to Diff 128188.
takuto.ikuta added a comment.

Thank you for review.
I made parseDirectives in ArgParser and extend parse() to receive flag for rsp file instead of copying.
How do you think?


https://reviews.llvm.org/D41581

Files:
  lld/COFF/Driver.cpp
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp


Index: lld/COFF/DriverUtils.cpp
===================================================================
--- lld/COFF/DriverUtils.cpp
+++ lld/COFF/DriverUtils.cpp
@@ -716,7 +716,7 @@
 }
 
 // Parses a given list of options.
-opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv) {
+opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv, bool ExpandRsp) {
   // Make InputArgList from string vectors.
   unsigned MissingIndex;
   unsigned MissingCount;
@@ -727,10 +727,12 @@
   // --rsp-quoting.
   opt::InputArgList Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
 
-  // Expand response files (arguments in the form of @<filename>)
-  // and then parse the argument again.
-  cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec);
-  Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
+  if (ExpandRsp) {
+    // Expand response files (arguments in the form of @<filename>)
+    // and then parse the argument again.
+    cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec);
+    Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
+  }
 
   // Print the real command line if response files are expanded.
   if (Args.hasArg(OPT_verbose) && Argv.size() != Vec.size()) {
@@ -763,7 +765,7 @@
     std::vector<const char *> V = tokenize(*S);
     Argv.insert(Argv.begin(), V.begin(), V.end());
   }
-  return parse(Argv);
+  return parse(Argv, true);
 }
 
 std::vector<const char *> ArgParser::tokenize(StringRef S) {
Index: lld/COFF/Driver.h
===================================================================
--- lld/COFF/Driver.h
+++ lld/COFF/Driver.h
@@ -52,11 +52,19 @@
   llvm::opt::InputArgList parseLINK(std::vector<const char *> Args);
 
   // Tokenizes a given string and then parses as command line options.
-  llvm::opt::InputArgList parse(StringRef S) { return parse(tokenize(S)); }
+  llvm::opt::InputArgList parse(StringRef S) {
+    return parse(tokenize(S), true);
+  }
+
+  // Tokenizes a given string and then parses as command line options in
+  // .drectve section.
+  llvm::opt::InputArgList parseDirectives(StringRef S) {
+    return parse(tokenize(S), false);
+  }
 
 private:
   // Parses command line options.
-  llvm::opt::InputArgList parse(llvm::ArrayRef<const char *> Args);
+  llvm::opt::InputArgList parse(llvm::ArrayRef<const char *> Args, bool ExpandRsp);
 
   std::vector<const char *> tokenize(StringRef S);
 
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -227,7 +227,7 @@
 void LinkerDriver::parseDirectives(StringRef S) {
   ArgParser Parser;
   // .drectve is always tokenized using Windows shell rules.
-  opt::InputArgList Args = Parser.parse(S);
+  opt::InputArgList Args = Parser.parseDirectives(S);
 
   for (auto *Arg : Args) {
     switch (Arg->getOption().getUnaliasedOption().getID()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41581.128188.patch
Type: text/x-patch
Size: 2878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171227/6d2304ce/attachment.bin>


More information about the llvm-commits mailing list