Page MenuHomePhabricator

[flang][driver] Add debug options not requiring semantic checks
ClosedPublic

Authored by awarzynski on Mar 31 2021, 2:45 AM.

Details

Summary

This patch adds two debugging options in the new Flang driver (flang-new):

  • -fdebug-unparse-no-sema
  • -fdebug-dump-parse-tree-no-sema

Each of these options combines two options from the "throwaway" driver (left: f18, right: flang-new):

  • -fdebug-uparse -fdebug-no-semantics --> -fdebug-unparse-no-sema
  • -fdebug-dump-parse-tree -fdebug-no-semantics --> -fdebug-dump-parse-tree-no-sema

There are no plans to implement -fdebug-no-semantics in the new driver. Such option would be too powerful. Also, it would only make sense when combined with specific frontend actions (-fdebug-unparse and -fdebug-dump-parse-tree). Instead, this patch adds 2 options that are more specialised and 2 dedicated FrontendActions.

The new frontend actions are implemented in terms of a new abstract base action: PrescanAndSemaAction. This new base class was required so that we can have finer control over what steps within the frontend are executed:

  • PrescanAction: run the _prescanner_
  • PrescanAndSemaAction: run the _prescanner_ and the _parser_ (new in this patch)
  • PrescanAndSemaAction: run the _prescanner_, _parser_ and run the _semantic checks_

This patch also introduces PrescanAndParseAction::BeginSourceFileAction. Apart from the semantic checks removed at the end, it is similar to PrescanAndSemaAction::BeginSourceFileAction.

Diff Detail

Event Timeline

awarzynski created this revision.Mar 31 2021, 2:45 AM
awarzynski requested review of this revision.Mar 31 2021, 2:45 AM
Herald added a project: Restricted Project. · View Herald Transcript
awarzynski edited the summary of this revision. (Show Details)Mar 31 2021, 2:50 AM
awarzynski added a project: Restricted Project.
awarzynski edited the summary of this revision. (Show Details)Mar 31 2021, 2:56 AM
arnamoy10 added inline comments.Mar 31 2021, 5:36 AM
flang/test/Parser/omp-allocate-unparse.f90
1

We probably need to add an alias to f18 to make the two tests succeed.

awarzynski updated this revision to Diff 335566.Apr 6 2021, 9:56 AM

Update f18.cpp and driver-help.f90 to improve testing

  • added -fdebug-unparse-no-sema and -fdebug-dump-parse-tree-no-sema in f18.cpp (for compatibility with flang-new)
  • updated driver-help.f90 with the new options
flang/lib/Frontend/FrontendActions.cpp
116

Is this variable unused?

awarzynski edited the summary of this revision. (Show Details)Apr 6 2021, 10:35 AM
awarzynski added inline comments.
flang/test/Parser/omp-allocate-unparse.f90
1

Updated, thank you!

Remove unused variable

flang/lib/Frontend/FrontendActions.cpp
116

How did it get here? :) Thank you, updated!

ashermancinelli accepted this revision.Apr 6 2021, 10:46 AM
This revision is now accepted and ready to land.Apr 6 2021, 10:46 AM
clang/include/clang/Driver/Options.td
4380

Does this flag actually mean, parse and construct the parse-tree and unparse and stop?

While the current name is OK now, when the rest of the pipeline (codegen, linking etc) is there will it be an issue?

awarzynski added inline comments.Apr 7 2021, 6:22 AM
clang/include/clang/Driver/Options.td
4380

Does this flag actually mean, parse and construct the parse-tree and unparse and stop?

Yes

While the current name is OK now, when the rest of the pipeline (codegen, linking etc) is there will it be an issue?

IIUC, there shouldn't be any. Currently, the -fdebug-unparse options have dedicated frontend actions

  • -fdebug-unparse runs DebugUnparseAction
  • -fdebug-unparse-no-sema will run DebugUnparseNoSemaAction (introduced here)

I don't see why we'd change these actions once codegen or linking are available. That's something that will be implemented separately.

Does this help?

awarzynski updated this revision to Diff 335820.Apr 7 2021, 8:29 AM

Add DocBrief descriptions in Options.td

I added the descriptions so that it's documented what the options are intended for and to avoid confusion in the future.

awarzynski added inline comments.Apr 7 2021, 8:39 AM
clang/include/clang/Driver/Options.td
4380

I added DocBrief descriptions to clarify the purpose of these options. Please note that currently these are not used anywhere. In Clang DocBrief descriptions are used to generate https://clang.llvm.org/docs/ClangCommandLineReference.html. We could set-up something similar for Flang.

LGTM.

Might be good to have a test for fdebug-dump-parse-tree-no-sema.

flang/include/flang/Frontend/FrontendOptions.h
54

Nit: semantics are not run here, i guess.

This revision was landed with ongoing or failed builds.Apr 8 2021, 2:45 AM
This revision was automatically updated to reflect the committed changes.

LGTM.

Might be good to have a test for fdebug-dump-parse-tree-no-sema.

Good point, added before merging into main! Thank you for reviewing.