diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2021-02-25 09:05:08 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2021-02-25 11:02:49 +0100 |
commit | a25e4a6da3fe43f631782b1668e0ac023f6b5848 (patch) | |
tree | fcbd71e7d327272b027afd514c6a078b0321c3d3 /clang/lib/CodeGen/CodeGenAction.cpp | |
parent | 30cb9c03b53ee03af2cdf16f4ee645e5dcff7e21 (diff) | |
download | llvm-a25e4a6da3fe43f631782b1668e0ac023f6b5848.zip llvm-a25e4a6da3fe43f631782b1668e0ac023f6b5848.tar.gz llvm-a25e4a6da3fe43f631782b1668e0ac023f6b5848.tar.bz2 |
[clang][cli] Store additional optimization remarks info
After a revision of D96274 changed `DiagnosticOptions` to not store all remark arguments **as-written**, it is no longer possible to reconstruct the arguments accurately from the class.
This is caused by the fact that for `-Rpass=regexp` and friends, `DiagnosticOptions` store only the group name `pass` and not `regexp`. This is the same representation used for the plain `-Rpass` argument.
Note that each argument must be generated exactly once in `CompilerInvocation::generateCC1CommandLine`, otherwise each subsequent call would produce more arguments than the previous one. Currently this works out because of the way `RoundTrip` splits the responsibilities for certain arguments based on what arguments were queried during parsing. However, this invariant breaks when we move to single round-trip for the whole `CompilerInvocation`.
This patch ensures that for one `-Rpass=regexp` argument, we don't generate two arguments (`-Rpass` from `DiagnosticOptions` and `-Rpass=regexp` from `CodeGenOptions`) by shifting the responsibility for handling both cases to `CodeGenOptions`. To distinguish between the cases correctly, additional information is stored in `CodeGenOptions`.
The `CodeGenOptions` parser of `-Rpass[=regexp]` arguments also looks at `-Rno-pass` and `-R[no-]everything`, which is necessary for generating the correct argument regardless of the ordering of `CodeGenOptions`/`DiagnosticOptions` parsing/generation.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D96847
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index da35246..6853926 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -60,22 +60,19 @@ namespace clang { bool handleDiagnostics(const DiagnosticInfo &DI) override; bool isAnalysisRemarkEnabled(StringRef PassName) const override { - return (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName)); + return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName); } bool isMissedOptRemarkEnabled(StringRef PassName) const override { - return (CodeGenOpts.OptimizationRemarkMissedPattern && - CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName)); + return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName); } bool isPassedOptRemarkEnabled(StringRef PassName) const override { - return (CodeGenOpts.OptimizationRemarkPattern && - CodeGenOpts.OptimizationRemarkPattern->match(PassName)); + return CodeGenOpts.OptimizationRemark.patternMatches(PassName); } bool isAnyRemarkEnabled() const override { - return (CodeGenOpts.OptimizationRemarkAnalysisPattern || - CodeGenOpts.OptimizationRemarkMissedPattern || - CodeGenOpts.OptimizationRemarkPattern); + return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() || + CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() || + CodeGenOpts.OptimizationRemark.hasValidPattern(); } private: @@ -722,15 +719,13 @@ void BackendConsumer::OptimizationRemarkHandler( 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.OptimizationRemark.patternMatches(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.OptimizationRemarkMissed.patternMatches(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_missed); } else { @@ -741,8 +736,7 @@ void BackendConsumer::OptimizationRemarkHandler( ShouldAlwaysPrint = ORA->shouldAlwaysPrint(); if (ShouldAlwaysPrint || - (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) + CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_analysis); } @@ -755,8 +749,7 @@ void BackendConsumer::OptimizationRemarkHandler( // regular expression that matches the name of the pass name in \p D. if (D.shouldAlwaysPrint() || - (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) + CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute); } @@ -768,8 +761,7 @@ void BackendConsumer::OptimizationRemarkHandler( // regular expression that matches the name of the pass name in \p D. if (D.shouldAlwaysPrint() || - (CodeGenOpts.OptimizationRemarkAnalysisPattern && - CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) + CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(D.getPassName())) EmitOptimizationMessage( D, diag::remark_fe_backend_optimization_remark_analysis_aliasing); } |