This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Generate documentation for compiler flags
ClosedPublic

Authored by DylanFleming-arm on Jul 15 2022, 8:33 AM.

Details

Summary

This patch aims to create a webpage to document
Flang's command line options on https://flang.llvm.org/docs/
in a similar way to Clang's
https://clang.llvm.org/docs/ClangCommandLineReference.html

This is done by using clang_tablegen to generate an .rst
file from Options.td (which is current shared with Clang)
For this to work, ClangOptionDocEmitter.cpp was updated
to allow specific Flang flags to be included,
rather than bulk excluding clang flags.

Note:
Some headings in the generated documentation will incorrectly
contain references to Clang, e.g.
"Flags controlling the behaviour of Clang during compilation"
This is because Options.td (Which is shared between both Clang and Flang)
contains hard-coded DocBrief sections. I couldn't find a non-intrusive way
to make this target-dependant, as such I've left this as is, and it will need revisiting later.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
DylanFleming-arm requested review of this revision.Jul 15 2022, 8:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 8:33 AM

Makes sense, thanks for working on this! Some minor comments below and inline.

From your summary:

This is done by using clang tablegen

What do you mean by "clang tablegen"? Is it Clang's clang_tablegen CMake function?

from options.td

Options.td ;-)

shared with clang

Most people associate "clang" with the executable. You may want to use "Clang" to avoid confusion (IIUC, you are referring to the sub-project rather than the executable here).

specific flang flags

Flang :) (same rationale as above)

clang/utils/TableGen/ClangOptionDocEmitter.cpp
328

I think that the way this is written at the moment is a bit counterintuitive (i.e. "if excluded or not included"). This is really down to how these include/exclude flags are used in various other places :( (i.e. there's little that we can do about it).

I think that it would make more sense to follow the style from OptTable.cpp. In particular (pseudo code):

if (excluded)
  return;
if (included_not_empty && !included)
  return;

This way it becomes clear that IncludedFlags (from "FlangOptionsDocs.td") is only taken into account when not empty. I would also add an assert in isIncluded:

assert(DocInfo->getValue("IncludedFlags") && Missing includeFlags);

WDYT?

Edited summary to be more clear.

I've also changed the format of the if(!included) as you suggested (and did the same for the call to isGroupIncluded)

I also added the assert you asked for, and then since there's an if statement checking for the opposite condition, I removed that as it's now unreachable.

DylanFleming-arm edited the summary of this revision. (Show Details)Jul 20 2022, 2:31 AM
awarzynski accepted this revision.Jul 20 2022, 3:57 AM

The change in ClangOptionDocEmitter.cpp is required for Flang as it heavily relies on these "include" flags defined in Options.td. This won't affect Clang as it does not use IncludeFlags in ClangOptionsDocs.td. If Clang devs were to use them in "ClangOptionsDocs.td", the required hooks in ClangOptionDocEmitter.cpp will already be there :)

LGTM, thanks for working on this! Give it another day before merging - in case Clang folks would like to chime in.

This revision is now accepted and ready to land.Jul 20 2022, 3:57 AM
awarzynski reopened this revision.Jul 22 2022, 7:59 AM
This revision is now accepted and ready to land.Jul 22 2022, 7:59 AM

After pushing to main, this patch cause a buildbot failure as CLANG_TABLEGEN_EXE could not be found.

I've updated flang/docs/CMakeLists.txt to set the parameter before making a call to clang_tablegen

DylanFleming-arm edited the summary of this revision. (Show Details)Jul 22 2022, 8:33 AM

LGTM, thanks!

(feel free to address my [nit] when merging or ignore altogether)

flang/docs/CMakeLists.txt
127

[nit] This is a bit out of place without a comment :) Could you mention that this CMake variable is required in clang_tablegen?