jansvoboda11 created this revision. jansvoboda11 added reviewers: Bigcheese, dexonsmith. jansvoboda11 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Regular expression patterns passed through the command line are being used to create an instances of `llvm::Regex` and thrown away. There is no API to serialize `Regex` back to the original pattern. This means we have no way to reconstruct the original pattern from command line. This is necessary for serializing `CompilerInvocation`. This patch stores the original pattern string in `CodeGenOptions` alongside the `llvm::Regex` instance. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96036 Files: clang/include/clang/Basic/CodeGenOptions.h clang/lib/CodeGen/CodeGenAction.cpp 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/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -60,22 +60,19 @@ bool handleDiagnostics(const DiagnosticInfo &DI) override; bool isAnalysisRemarkEnabled(StringRef PassName) const override { - return (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName)); + return CodeGenOpts.OptimizationRemarkAnalysisPattern.match(PassName); } bool isMissedOptRemarkEnabled(StringRef PassName) const override { - return (CodeGenOpts.OptimizationRemarkMissedPattern && - CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName)); + return CodeGenOpts.OptimizationRemarkMissedPattern.match(PassName); } bool isPassedOptRemarkEnabled(StringRef PassName) const override { - return (CodeGenOpts.OptimizationRemarkPattern && - CodeGenOpts.OptimizationRemarkPattern->match(PassName)); + return CodeGenOpts.OptimizationRemarkPattern.match(PassName); } bool isAnyRemarkEnabled() const override { - return (CodeGenOpts.OptimizationRemarkAnalysisPattern || - CodeGenOpts.OptimizationRemarkMissedPattern || - CodeGenOpts.OptimizationRemarkPattern); + return (CodeGenOpts.OptimizationRemarkAnalysisPattern.isEnabled() || + CodeGenOpts.OptimizationRemarkMissedPattern.isEnabled() || + CodeGenOpts.OptimizationRemarkPattern.isEnabled()); } private: @@ -722,15 +719,13 @@ if (D.isPassed()) { // Optimization remarks are active only if the -Rpass flag has a regular // expression that matches the name of the pass name in \p D. - if (CodeGenOpts.OptimizationRemarkPattern && - CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName())) + if (CodeGenOpts.OptimizationRemarkPattern.match(D.getPassName())) EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark); } else if (D.isMissed()) { // Missed optimization remarks are active only if the -Rpass-missed // flag has a regular expression that matches the name of the pass // name in \p D. - if (CodeGenOpts.OptimizationRemarkMissedPattern && - CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName())) + if (CodeGenOpts.OptimizationRemarkMissedPattern.match(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_missed); } else { @@ -741,8 +736,7 @@ ShouldAlwaysPrint = ORA->shouldAlwaysPrint(); if (ShouldAlwaysPrint || - (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) + CodeGenOpts.OptimizationRemarkAnalysisPattern.match(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_analysis); } @@ -755,8 +749,7 @@ // regular expression that matches the name of the pass name in \p D. if (D.shouldAlwaysPrint() || - (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) + CodeGenOpts.OptimizationRemarkAnalysisPattern.match(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute); } @@ -768,8 +761,7 @@ // regular expression that matches the name of the pass name in \p D. if (D.shouldAlwaysPrint() || - (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) + CodeGenOpts.OptimizationRemarkAnalysisPattern.match(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_analysis_aliasing); } Index: clang/include/clang/Basic/CodeGenOptions.h =================================================================== --- clang/include/clang/Basic/CodeGenOptions.h +++ clang/include/clang/Basic/CodeGenOptions.h @@ -278,19 +278,32 @@ /// -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; + + bool isEnabled() const { return Regex != nullptr; } + + bool match(StringRef String, SmallVectorImpl<StringRef> *Matches = nullptr, + std::string *Error = nullptr) const { + return isEnabled() && Regex->match(String, Matches, Error); + } + }; + /// 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 +311,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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits