This is an archive of the discontinued LLVM Phabricator instance.

[Flang][Driver] Add support for Rpass and related options
AbandonedPublic

Authored by victorkingi on Jul 26 2023, 5:13 AM.

Details

Summary

Allow flang to report what optimizations were and were not done by the LLVM compiler optimizer.

A BackendRemarkConsumer was implemented in reference to
clang BackendConsumer.

Added required fields in flang/include/flang/Frontend/CodeGenOptions.h which include
the OptRemark fields, OptRemark struct and the RemarkKind enum class.

The parseOptimizationRemark and printRemarkOption functions created
are identical to the ones used in Clang.

Since Flang doesn't have a SourceManager instance in the BackendRemarkConsumer class,
we pass the absolute path and file name in flang/lib/Frontend/FrontendActions.cpp
emitOptimizationMessage function, then process it in flang/lib/Frontend/TextDiagnosticPrinter.cpp

Depends on D157410. That patch adds the R family of options to FlangOption and FC1Option in
clang/include/clang/Driver/Options.td

Diff Detail

Event Timeline

victorkingi created this revision.Jul 26 2023, 5:13 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a subscriber: sunshaoce. · View Herald Transcript
victorkingi requested review of this revision.Jul 26 2023, 5:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 5:13 AM

rpass flag now prints remarks when requested but does not display
the passName used, i.e [-Rpass=inline]

added test file optimization-remark.f90

added frontend forwarding test for Rpass flags

removed unused header includes

rpass flag now prints remarks when requested but does not display
the passName used, i.e [-Rpass=inline]

I think the location information is also not printed. Please check the difference in implementation of the TextDiagnosticPrinter::HandleDiagnostic function in clang (https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/clang/lib/Frontend/TextDiagnosticPrinter.cpp#L109) and flang (https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/flang/lib/Frontend/TextDiagnosticPrinter.cpp#L32).
In particular, the passName is printed in the printDiagnosticOptions function https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/clang/lib/Frontend/TextDiagnosticPrinter.cpp#L85

clang/lib/Basic/DiagnosticIDs.cpp
796–797 ↗(On Diff #546831)

Looks like an unrelated change.

clang/lib/CodeGen/CodeGenAction.cpp
772 ↗(On Diff #546831)

Looks like an unrelated change.

tschuett added inline comments.Aug 3 2023, 11:58 PM
flang/include/flang/Frontend/CodeGenOptions.h
72

enum class?

Hey @victorkingi , thank you for working on this :)

There's quite a lot going on here and I am thinking that it might be good to split this into a few patches? Also, please note that Flang's driver, unlike Clang, uses MLIR's coding style (use camelCase instead of CamelCase).

A StandaloneBackendConsumer was implemented but the DiagnosticsEngine still doesn't print to console the remarks produced.

This could mean that it's not being deconstructed correctly. Or that it requires explicit flushing. Can you verify that it contains the expected remarks?

added extraction of absolute file path in TextDiagnosticPrinter

victorkingi edited the summary of this revision. (Show Details)Aug 7 2023, 9:02 AM

removed unnecessary code

code cleanup

Hey @victorkingi , thank you for working on this :)

There's quite a lot going on here and I am thinking that it might be good to split this into a few patches? Also, please note that Flang's driver, unlike Clang, uses MLIR's coding style (use camelCase instead of CamelCase).

A StandaloneBackendConsumer was implemented but the DiagnosticsEngine still doesn't print to console the remarks produced.

This could mean that it's not being deconstructed correctly. Or that it requires explicit flushing. Can you verify that it contains the expected remarks?

Hi @awarzynski thanks for the comments. Splitting it up makes sense, I will do that.

fixing failing tests

from CamelCase to camelCase variables

changed enum to enum class

victorkingi marked an inline comment as done.Aug 8 2023, 5:45 AM
victorkingi edited the summary of this revision. (Show Details)

rpass flag now prints remarks when requested but does not display
the passName used, i.e [-Rpass=inline]

I think the location information is also not printed. Please check the difference in implementation of the TextDiagnosticPrinter::HandleDiagnostic function in clang (https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/clang/lib/Frontend/TextDiagnosticPrinter.cpp#L109) and flang (https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/flang/lib/Frontend/TextDiagnosticPrinter.cpp#L32).
In particular, the passName is printed in the printDiagnosticOptions function https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/clang/lib/Frontend/TextDiagnosticPrinter.cpp#L85

Hi @kiranchandramohan location now gets printed as the absolute path. In certain situations, clang preserves the dots e.g. if the user provides "../my_location/my_file" it will print the exact same, while flang expands to absolute path. So that would be one difference.

split the patch into 2. This is the implementation patch

kiranchandramohan retitled this revision from [FLang] Add support for Rpass flag to [Flang][Driver] Add support for Rpass and related options.Aug 9 2023, 6:16 AM
kiranchandramohan edited the summary of this revision. (Show Details)
awarzynski added inline comments.Aug 9 2023, 8:00 AM
flang/lib/Frontend/CompilerInvocation.cpp
173–174

Could you add a test to exercise this diagnostic?

victorkingi edited the summary of this revision. (Show Details)

Added remark error test and color printing for remark errors

victorkingi marked an inline comment as done.Aug 9 2023, 10:24 AM
victorkingi added inline comments.
flang/lib/Frontend/CompilerInvocation.cpp
786

Apparently without forwarding the color option to the CompilerInvocation, flang doesn't print remark errors with color. Hence the need for this.
Also, a question, why do we have 2 instances of DiagnosticsEngine, one in CompilerInvocation and the other passed as an argument?

flang/test/Driver/optimization-remark.f90
18–19

Testing error produced given a bad regex

victorkingi edited the summary of this revision. (Show Details)Aug 9 2023, 10:26 AM
victorkingi edited the summary of this revision. (Show Details)Aug 9 2023, 10:42 AM

Removed false argument to ProcessWarningOption function to allow warning printing

victorkingi edited the summary of this revision. (Show Details)Aug 10 2023, 3:21 AM

Added warning tests in optimization-remark.f90

Thanks for the updates, more comments inline. Also:

The remarks printed miss carets.

Why and can you share an example?

The parseOptimizationRemark, addDiagnosticArgs and printDiagnosticOptions functions created are identical to the ones used in Clang.

In which case we should seriously consider moving this code somewhere where it can be shared. If outside the scope of this change, please document in code that there's scope for re-use.

flang/include/flang/Frontend/CodeGenOptions.h
72–118

From what I can see, this has been borrowed almost verbatim from Clang: https://github.com/llvm/llvm-project/blob/3a100ea901ed79d6a06a5f018be2b4d3bbca51e8/clang/include/clang/Basic/CodeGenOptions.h#L331-L376.

This is fine (and common throughout the driver), but please document more. In particular:

  • Highlight that ATM this code is identical that what Clang contains (and add a TODO to perhaps share with Clang at some point),
  • Highlight that the list of options in Flang and Clang is _identical - it is really good that the interfaces in Clang and Flang are consistent. That's a good reason to re-use the logic from Clang.
flang/lib/Frontend/CompilerInvocation.cpp
156–158

Could you give an example (and write a test ) for -Rgroup=regexp. Also, @kiranchandramohan , is this form actually needed? I am thinking that it's a complexity that could be avoided. It could definitely simplify this patch.

786

Apparently without forwarding the color option to the CompilerInvocation, flang doesn't print remark errors with color. Hence the need for this.

It is already "forwarded" here: https://github.com/llvm/llvm-project/blob/3a100ea901ed79d6a06a5f018be2b4d3bbca51e8/flang/lib/Frontend/CompilerInvocation.cpp#L117-L122. Could you explain why you need this change _here_?

Also, a question, why do we have 2 instances of DiagnosticsEngine, one in CompilerInvocation and the other passed as an argument?

One is for the driver itself, to generate diagnostics related to "driver errors" (e.g. option parsing errors). The other belongs to CompilerInstance rather than CompilerInvocation and is used to report compilation errors (e.g. semantic or parsing errors).

1070–1074

Is this specifically for parsing remarks options? Please add a comment

flang/lib/Frontend/FrontendActions.cpp
923

Why StandaloneBackendConsumer? Isn't this specifically for remarks? Also, could you document this class a bit?

flang/lib/Frontend/TextDiagnosticPrinter.cpp
37

Why is this method needed and can it be tested?

flang/lib/Frontend/CompilerInvocation.cpp
156–158

Rpass=regex is used, particularly Rpass=.. So this is required, but can be deferred to a separate patch to simplify this one.

awarzynski added inline comments.Aug 11 2023, 12:58 AM
flang/lib/Frontend/CompilerInvocation.cpp
156–158

can be deferred to a separate patch to simplify this one

That would be a small win - the complexity comes from the fact that we can't rely on TableGen to define all possible options.

victorkingi marked an inline comment as done.

addressing comments with code refactoring

Thanks for trimming this, it's much easier to review! A few more suggestions, but nothing major.

flang/lib/Frontend/CompilerInvocation.cpp
254–290
// coment
if (const llvm::opt::Arg *a =
        args.getLastArg(clang::driver::options::OPT_opt_record_passes))
  opts.OptRecordPasses = a->getValue();

// coment
if (const llvm::opt::Arg *a =
        args.getLastArg(clang::driver::options::OPT_opt_record_format))
  opts.OptRecordFormat = a->getValue();

// coment
opts.OptimizationRemark = parseOptimizationRemark(
    diags, args, clang::driver::options::OPT_Rpass_EQ, "pass");

// coment
opts.OptimizationRemarkMissed = parseOptimizationRemark(
    diags, args, clang::driver::options::OPT_Rpass_missed_EQ, "pass-missed");

// coment
opts.OptimizationRemarkAnalysis = parseOptimizationRemark(
    diags, args, clang::driver::options::OPT_Rpass_analysis_EQ,
    "pass-analysis");

if (opts.getDebugInfo() == llvm::codegenoptions::NoDebugInfo) {
  // If the user requested a flag that requires source locations available in
  // the backend, make sure that the backend tracks source location information.
  bool needLocTracking = !opts.OptRecordFile.empty() || opts.OptRecordPasses ||
                         !opts.OptRecordFormat.empty() ||
                         opts.OptimizationRemark.hasValidPattern() ||
                         opts.OptimizationRemarkMissed.hasValidPattern() ||
                         opts.OptimizationRemarkAnalysis.hasValidPattern();

  if (needLocTracking)
    opts.setDebugInfo(llvm::codegenoptions::LocTrackingOnly);
}

I might have made typos when editing this, but hopefully the overall logic makes sense. Basically, I am suggesting that "option parsing" is separated from the logic for setting up the location tracking in the backend.

flang/lib/Frontend/FrontendActions.cpp
978–1005

https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code

void
optimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &d) {
  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.OptimizationRemark.patternMatches(d.getPassName()))
      emitOptimizationMessage(
          d, clang::diag::remark_fe_backend_optimization_remark);
    return;
  }

  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.OptimizationRemarkMissed.patternMatches(d.getPassName()))
      emitOptimizationMessage(
          d, clang::diag::remark_fe_backend_optimization_remark_missed);
    return;
  }

  assert(d.isAnalysis() && "Unknown remark type");

  bool shouldAlwaysPrint = false;
  if (auto *ora = llvm::dyn_cast<llvm::OptimizationRemarkAnalysis>(&d))
    shouldAlwaysPrint = ora->shouldAlwaysPrint();

  if (shouldAlwaysPrint ||
      codeGenOpts.OptimizationRemarkAnalysis.patternMatches(
          d.getPassName()))
    emitOptimizationMessage(
        d, clang::diag::remark_fe_backend_optimization_remark_analysis);
}
1007–1024

Where is this method used?

1134

https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

Variable names should be nouns (as they represent state). The name should be camel case, and start with an upper case letter (e.g. Leader or Boats).

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
173–175

Is this calling https://github.com/llvm/llvm-project/blob/c52d9509d40d3048914b144618232213e6076e05/clang/include/clang/Basic/Diagnostic.h#L1840-L1842? That's part of the clangBasic library. The overall goal in the driver is to reduce the dependency on Clang and this would be a step in the opposite direction. IIUC, we only need a small subset of that function, right?

victorkingi marked 6 inline comments as done.

code refactoring in reference to comments

victorkingi edited the summary of this revision. (Show Details)Aug 14 2023, 4:43 AM

added tests for "no" variants of Rpass

added comment

flang/lib/Frontend/CompilerInvocation.cpp
156–158

Removed need for Rpass=regex

173–174

added the tests in optimization-remark.f90 These are the -Rno-pass, -Rno-pass-analysis and -Rno-pass-missed tests.

786

Thanks for the explanation, A bad regex error would be printed without color. But since we are getting rid of the regex option, might as well remove this.

flang/lib/Frontend/FrontendActions.cpp
1007–1024

llvm/include/llvm/IR/DiagnosticHandler.h specifies that this method needs to be overridden if one wants to setup custom diagnostic format reporting. llvm/lib/IR/LLVMContext.cpp then uses it for reporting in the diagnose function

void LLVMContext::diagnose(const DiagnosticInfo &DI) {
  if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
    if (LLVMRemarkStreamer *RS = getLLVMRemarkStreamer())
      RS->emit(*OptDiagBase);

  // If there is a report handler, use it.
  if (pImpl->DiagHandler &&
      (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
      pImpl->DiagHandler->handleDiagnostics(DI))
    return;
  .
  .
  .
flang/lib/Frontend/TextDiagnosticPrinter.cpp
37

This method prints out the pass that was done e.g. [-Rpass=inline ], [-Rpass=loop-delete] next to the optimization message.
It is tested by the full remark message emitted test in flang/test/Driver/optimization-remark.f90

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
173–175

Yes, we only need a small subset. I'll create a static function in this file to avoid the dependence

victorkingi added inline comments.Aug 14 2023, 5:18 AM
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
173–175

Yes, we only need a small subset. I'll create a static function in this file to avoid the dependence

I mean normal function not static

victorkingi marked 6 inline comments as done.Aug 14 2023, 5:20 AM
victorkingi added inline comments.
flang/lib/Frontend/FrontendActions.cpp
923

I've added a comment, does this give a good explanation of what it does?

Thanks for the updates - this is looking really good! A few more suggestions and then I'll scan the whole thing again (sorry, there's been quite a lot of code going back and forth).

flang/lib/Frontend/CompilerInvocation.cpp
1071
flang/lib/Frontend/FrontendActions.cpp
976–1011
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
116

?

flang/test/Driver/optimization-remark.f90
60

FIXME

Some high level comments:

  • The logic in parseCodeGenArgs in CompilerInvocation.cpp is a bit complex and quite specialized - could you move it to a dedicated method?
  • In a fair few places this patch make references to "diagnostic flags" or "diagnostic options". That's borrowed from Clang where there's one code path for -W<opt> and -R<opt> flags. Note that in Clang the logic for -W<opt> is vastly more complex. This is completely absent in Flang. So, everything that's added here is added specifically for "remarks" and it would be helpful to be explicit about that. For example, processWarningOptions is misleading. processRemakrsOptions would be more accurate.

Thank you :)

flang/lib/Frontend/CompilerInvocation.cpp
254

// Specifies what passes to include.

Could you be more specific, what passes are you referring to? Included where?

265
// Specify which missed passes should be reported using a regex.

Reported where?

flang/lib/Frontend/TextDiagnosticPrinter.cpp
37

Flang has very _very_ limited support for warning flags. So this is going to be used specifically for Remarks. Please update and document accordingly.

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
30

No longer needed, right? Also, please use the the format consistent with the other #includes.

116

I find this method quite confusing.

  1. It doesn't process warning options - it processes remarks options (so the name is inaccurate).
  2. It deals with -Rpass -Rno-pass cases (i.e. postive + negative flag), but that's normally done in CompilerInvocation when parsing other options. See e.g. https://github.com/llvm/llvm-project/blob/c52d9509d40d3048914b144618232213e6076e05/flang/lib/Frontend/CompilerInvocation.cpp#L161-L163. Why not use that logic instead?
  3. It's been extracted from Clang - it would be very helpful to note that and highlight the difference between this method and similar method in Clang.
  4. You can safely trim it to only deal with Remarks (so e.g. update const clang::DiagnosticOptions &opts, in the signature)

Now, I am not requesting any major refactor here - I appreciate that e.g. these remark flags are defined a bit differently to other flags. But this method can be simplified and should be documented.

victorkingi marked 5 inline comments as done.

code refactoring

victorkingi marked 4 inline comments as done.

code refactoring

code refactoring

victorkingi edited the summary of this revision. (Show Details)Aug 15 2023, 5:41 AM
victorkingi added inline comments.
flang/lib/Frontend/FrontendActions.cpp
976–1011

The if statement still needs to return if the pattern doesn't match, should I leave it the way it is?

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
30

It's needed in the case of clang::diag::warn_unknown_diag_option in emitUnknownDiagWarning function.

116

I found it difficult including it in CompilerInvocation.cpp parseCodeGenArgs function since we are updating the DiagnosticsEngine object belonging to CompilerInstance not the other. We would have to expose the DiagnosticsEngine in CompilerInvocation class to do this. Would there be another way?

hey @victorkingi , I am still unsure about parsing these remarks options in two places:

  • CompilerInvocation.cpp
  • ExecuteCompilerInvocation.cpp

I think that it is important to clarify the relations between the two. In particular, it's normally the job of CompilerInvocaiton to make sure that e.g. -Rpass -Rno-pass -Rpass == -Rpass (so that DiagnosticOptions::Remarks only contains -Rpass). This might be tricky in practice if we want to support Regex, but would be good to document when e.g. populating DiagnosticOptions::Remarks.

I am also under the impression that extra complexity comes from the fact that this patch strives to support -R<some-random-thing-here> on top of -R{no}pass, -R{no}pass-missed, -R{no}pass-analysis. I also see some code left to support regex versions of the flags. Can you clean that up?

flang/include/flang/Frontend/CodeGenOptions.h
76–81

I only see RK_Enabled and RK_Disabled being used, though I don't see -Rgroup nor -Rno-group being tested 🤔 .

flang/lib/Frontend/CompilerInvocation.cpp
254

Do you know whether that only includes middle-end, or also back-end passes?

262

optimizationRemarkHandler is a member method of DiagnosticHandler, that you specialise in FrontendActions.cpp, right?

1071–1074

How about:

Preserve all the remark options requested, e.g. -Rpass, -Rpass-missed or -Rpass-analysis. This will be used later when processing and outputting the remarks generated by LLVM in  ExecuteCompilerInvocation.cpp.
flang/lib/Frontend/FrontendActions.cpp
976–1011

Sorry, my bad, I missed that. Yeah, then leave it as is, but could you replace const llvm::DiagnosticInfoOptimizationBase &d with something with more descriptive name? (I am referring to d)

flang/lib/Frontend/TextDiagnosticPrinter.cpp
18
20
20

Is this needed?

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
116

Thanks for the explanation, this helps understand the wider context. So it sounds like:

  • this method has 2 important function: process the remark options _and_ update the DiagnosticEngine that belongs to this CompilerInstance
  • the logic in CompilerInvocation does some initial option parsing to configure the code-gen (that's e.g. used by BackendRemarkConsumer)

Is this correct? I am also suggesting some edits below.

121–145

I am suggesting a few changes here. Some simplifications, some more descriptive variable names. Most importantly, updated function name - IIUC the key purpose of this function is to update the input DiagnosticsEngine based on -R... options. IMHO, the name should reflect that.

static void updateDiagEngineForOptRemarks(clang::DiagnosticsEngine &diagsEng,
                                 const clang::DiagnosticOptions &opts) {
  llvm::SmallVector<clang::diag::kind, 10> diags;
  const llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs =
      diagsEng.getDiagnosticIDs();

  for (unsigned i = 0; i < opts.Remarks.size(); i++) {
    llvm::StringRef remarkOpt = opts.Remarks[i];
    const auto flavor = clang::diag::Flavor::Remark;

    // Check to see if this opt starts with "no-", if so, this is a
    // negative form of the option.
    bool isPositive = !remarkOpt.startswith("no-");
    if (!isPositive)
      remarkOpt = opt.substr(3);

    // Just issue a warning when encountering an unrecognised remark option.
    if (diagIDs->getDiagnosticsInGroup(flavor, remakrOpt, diags)) {
      emitUnknownDiagWarning(diagsEng, flavor, isPositive ? "-R" : "-Rno-", opt);
      continue; 
    }
    
    diags.setSeverityForGroup(flavor, remarkOpt,
                                isPositive ? clang::diag::Severity::Remark
                                           : clang::diag::Severity::Ignored);
  }
}
flang/test/Driver/optimization-remark.f90
8

How about something like this:

! RUN: %flang_fc1 %s -O1 -Runsupported_remark_opt -Rpass -emit-llvm -o - 2>&1 | FileCheck %s
tschuett added inline comments.Aug 16 2023, 1:37 AM
flang/lib/Frontend/CompilerInvocation.cpp
254

I use -Rpass-missed='gisel*' for GlobalIsel aka backend. I am interested in doing that exercise with Flang.

victorkingi marked 9 inline comments as done.

code refactoring

code refactoring

victorkingi added inline comments.Aug 16 2023, 6:29 AM
flang/include/flang/Frontend/CodeGenOptions.h
76–81

-Rgroup represents -Rpass, -Rpass-missed and -Rpass-analysis. Same applies to the no variation

flang/lib/Frontend/CompilerInvocation.cpp
254

Includes both middle and backend

262

No, it's just a member method of BackendRemarkConsumer

flang/lib/Frontend/TextDiagnosticPrinter.cpp
20

No it's not, I've removed it

tschuett added inline comments.Aug 16 2023, 8:00 AM
flang/lib/Frontend/CompilerInvocation.cpp
254

No. There are no middle-end passes that match that pattern.

victorkingi added inline comments.Aug 16 2023, 8:22 AM
flang/test/Driver/optimization-remark.f90
8

We are testing here if -Rno-pass is provided after -Rpass, nothing should be printed.

Unsupported value is tested at

! Check "unknown remark option" warning with suggestion
! RUN: %flang %s -O1 -Rpas 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-SUGGEST

added support for backend remarks

victorkingi added inline comments.Aug 16 2023, 10:20 AM
flang/lib/Frontend/FrontendActions.cpp
1031–1042

This cases should handle back-end passes as the previous cases only handled middle-end

Victor, this is proving quite tricky to review. There's already been a lot of updates and many of them are summarized as either "code refactor" or "clean-up". Please reduce traffic/noise and use more descriptive summaries.

Also, rather than adding new features in this already large change (I am referring to e.g. DK_MachineOptimizationRemarkMissed), please try to identify ways to split this patch further. Here are some suggestions (I've also made comments inline):

  1. In the first iteration (like you effectively do now), focus on OPT_R_Joined options (e.g. -Rpass, Rpass-analysis, -Rpass-missed). Focus on basic functionality that demonstrates that correct information is returned from the backend. No need to fine tune the remarks with e.g. full file path or relevant remark option.
  2. Next, add support for -Rpass=/-Rpass-missed=/-Rpass-analysis=. That's when e.g. llvm::opt::OptSpecifier optEq in parseOptimizationRemark would be needed (but not in Step 1).
  3. Fine tune how the report is printed (e.g. improve file name by adding full path, add valid remark option at the end etc).
  4. Add support for machine optimisations, e.g. DK_MachineOptimizationRemarkMissed.

This is easily 4 patches ;-)

flang/lib/Frontend/CompilerInvocation.cpp
158

optEq is not used, but it should be.

266–268

This is for -Rpass=, which is not tested. And the comment is inaccurate.

272–274

This is for -Rpass-missed=, which is not tested. And the comment is inaccurate.

278–279

This is for -Rpass-analysis=, which is not tested. And the comment is inaccurate.

flang/lib/Frontend/FrontendActions.cpp
1031–1042

Please move this to a dedicated patch with a test for each of these cases.

flang/lib/Frontend/TextDiagnosticPrinter.cpp
19

https://llvm.org/docs/CodingStandards.html#include-style

  1. Main Module Header
  2. Local/Private Headers
  3. LLVM project/subproject headers (clang/..., lldb/..., llvm/..., etc)
  4. System #includes
38–53

Move to a dedicated patch.

78–107

Move to a dedicated patch.

Victor, this is proving quite tricky to review. There's already been a lot of updates and many of them are summarized as either "code refactor" or "clean-up". Please reduce traffic/noise and use more descriptive summaries.

Also, rather than adding new features in this already large change (I am referring to e.g. DK_MachineOptimizationRemarkMissed), please try to identify ways to split this patch further. Here are some suggestions (I've also made comments inline):

  1. In the first iteration (like you effectively do now), focus on OPT_R_Joined options (e.g. -Rpass, Rpass-analysis, -Rpass-missed). Focus on basic functionality that demonstrates that correct information is returned from the backend. No need to fine tune the remarks with e.g. full file path or relevant remark option.
  2. Next, add support for -Rpass=/-Rpass-missed=/-Rpass-analysis=. That's when e.g. llvm::opt::OptSpecifier optEq in parseOptimizationRemark would be needed (but not in Step 1).
  3. Fine tune how the report is printed (e.g. improve file name by adding full path, add valid remark option at the end etc).
  4. Add support for machine optimisations, e.g. DK_MachineOptimizationRemarkMissed.

This is easily 4 patches ;-)

Hi Andrzej, splitting into 4 patches seems like a good idea. Here's the first patch that only handles the backend implementation https://reviews.llvm.org/D158174

victorkingi abandoned this revision.Aug 31 2023, 8:52 AM

Replaced by a series of patches already merged on github, starting from https://reviews.llvm.org/D157410