[PATCH] D96036: [clang][codegen] Remember string used to create llvm::Regex for optimization remarks

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 8 07:28:20 PST 2021


jansvoboda11 updated this revision to Diff 322103.
jansvoboda11 added a comment.

Apply suggested change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96036

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1159,8 +1159,8 @@
 }
 
 /// Create a new Regex instance out of the string value in \p RpassArg.
-/// It returns a pointer to the newly generated Regex instance.
-static std::shared_ptr<llvm::Regex>
+/// It returns the string and a pointer to the newly generated Regex instance.
+static CodeGenOptions::RemarkPattern
 GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args,
                                 Arg *RpassArg) {
   StringRef Val = RpassArg->getValue();
@@ -1171,7 +1171,7 @@
         << RegexError << RpassArg->getAsString(Args);
     Pattern.reset();
   }
-  return Pattern;
+  return {std::string(Val), Pattern};
 }
 
 static bool parseDiagnosticLevelMask(StringRef FlagName,
Index: clang/include/clang/Basic/CodeGenOptions.h
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.h
+++ clang/include/clang/Basic/CodeGenOptions.h
@@ -278,19 +278,29 @@
   /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
   std::string SymbolPartition;
 
+  /// Regular expression and the string it was created from.
+  struct RemarkPattern {
+    std::string Pattern;
+    std::shared_ptr<llvm::Regex> Regex;
+
+    explicit operator bool() const { return Regex != nullptr; }
+
+    llvm::Regex *operator->() const { return Regex.get(); }
+  };
+
   /// Regular expression to select optimizations for which we should enable
   /// optimization remarks. Transformation passes whose name matches this
   /// expression (and support this feature), will emit a diagnostic
   /// whenever they perform a transformation. This is enabled by the
   /// -Rpass=regexp flag.
-  std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
+  RemarkPattern OptimizationRemarkPattern;
 
   /// Regular expression to select optimizations for which we should enable
   /// missed optimization remarks. Transformation passes whose name matches this
   /// expression (and support this feature), will emit a diagnostic
   /// whenever they tried but failed to perform a transformation. This is
   /// enabled by the -Rpass-missed=regexp flag.
-  std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
+  RemarkPattern OptimizationRemarkMissedPattern;
 
   /// Regular expression to select optimizations for which we should enable
   /// optimization analyses. Transformation passes whose name matches this
@@ -298,7 +308,7 @@
   /// whenever they want to explain why they decided to apply or not apply
   /// a given transformation. This is enabled by the -Rpass-analysis=regexp
   /// flag.
-  std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
+  RemarkPattern OptimizationRemarkAnalysisPattern;
 
   /// Set of files defining the rules for the symbol rewriting.
   std::vector<std::string> RewriteMapFiles;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96036.322103.patch
Type: text/x-patch
Size: 3012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210208/72496099/attachment.bin>


More information about the cfe-commits mailing list