[clang] 396e944 - [Flang] Generate documentation for compiler flags
Author: Dylan Fleming Date: 2022-07-21T11:33:19Z New Revision: 396e944d82f3e212746cd241e4caba445523aff6 URL: https://github.com/llvm/llvm-project/commit/396e944d82f3e212746cd241e4caba445523aff6 DIFF: https://github.com/llvm/llvm-project/commit/396e944d82f3e212746cd241e4caba445523aff6.diff LOG: [Flang] Generate documentation for compiler flags 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. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D129864 Added: flang/include/flang/FlangOptionsDocs.td Modified: clang/utils/TableGen/ClangOptionDocEmitter.cpp flang/docs/CMakeLists.txt flang/docs/index.md Removed: diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp index 6c24ad2bdcc53..75f5d057c33a5 100644 --- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp +++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp @@ -168,6 +168,29 @@ bool hasFlag(const Record *OptionOrGroup, StringRef OptionFlag) { return false; } +bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) { + assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags"); + for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags")) +if (hasFlag(OptionOrGroup, Inclusion)) + return true; + return false; +} + +bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) { + if (isIncluded(Group.Group, DocInfo)) +return true; + for (auto &O : Group.Options) +if (isIncluded(O.Option, DocInfo)) + return true; + for (auto &G : Group.Groups) { +if (isIncluded(G.Group, DocInfo)) + return true; +if (isGroupIncluded(G, DocInfo)) + return true; + } + return false; +} + bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) { // FIXME: Provide a flag to specify the set of exclusions. for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags")) @@ -304,6 +327,8 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo, raw_ostream &OS) { if (isExcluded(Option.Option, DocInfo)) return; + if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, DocInfo)) +return; if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" || Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT") return; @@ -379,6 +404,9 @@ void emitGroup(int Depth, const DocumentedGroup &Group, const Record *DocInfo, if (isExcluded(Group.Group, DocInfo)) return; + if (DocInfo->getValue("IncludedFlags") && !isGroupIncluded(Group, DocInfo)) +return; + emitHeading(Depth, getRSTStringWithTextFallback(Group.Group, "DocName", "Name"), OS); diff --git a/flang/docs/CMakeLists.txt b/flang/docs/CMakeLists.txt index 044697a104507..077c01d3310ff 100644 --- a/flang/docs/CMakeLists.txt +++ b/flang/docs/CMakeLists.txt @@ -91,6 +91,16 @@ if (LLVM_ENABLE_DOXYGEN) endif() endif() +function (gen_rst_file_from_td output_file td_option source docs_target) + if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}") +message(FATAL_ERROR "Cannot find source file: ${source} in ${CMAKE_CURRENT_SOURCE_DIR}") + endif() + get_filename_component(TABLEGEN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY) + list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}") + clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file}") + add_dependencies(${docs_target} "gen-${output_file}") +endfunction() + if (LLVM_ENABLE_SPHINX) include(AddSphinxTarget) if (SPHINX_FOUND) @@ -114,6 +124,7 @@ if (LLVM_ENABLE_SPHINX) COMMAND "${Python3_EXECUTABLE}" ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py) + gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs ../include/flang/FlangOptionsDocs.td docs-flang-html) endif() if (${SPHINX_OUTPUT_MAN}) add_sphinx_target(man flang) diff --git a/flang/docs/index.md b/flang/docs/index.md index 3c3e2de2a8078..d6b05115f8611 100644 --- a/flang/docs/index.md +++ b/flang/docs/index.md @@ -45,6 +45,7 @@ on how to get in touch with us and to learn more about the current status. DoConcurrent Extensions FIRLangRef + FlangCommandLineReference FlangDriver FortranIR FortranLLVMTestSuite diff --git a/flang/include/flang/FlangOptionsDocs.td b/flang/include/flang/FlangOptionsDocs.td new file
[clang] 846439d - [Flang] Generate documentation for compiler flags
Author: Dylan Fleming Date: 2022-07-22T17:05:04Z New Revision: 846439dd97d45e0e08af14269708511646a9add1 URL: https://github.com/llvm/llvm-project/commit/846439dd97d45e0e08af14269708511646a9add1 DIFF: https://github.com/llvm/llvm-project/commit/846439dd97d45e0e08af14269708511646a9add1.diff LOG: [Flang] Generate documentation for compiler flags 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. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D129864 Added: flang/include/flang/FlangOptionsDocs.td Modified: clang/utils/TableGen/ClangOptionDocEmitter.cpp flang/docs/CMakeLists.txt flang/docs/index.md Removed: diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp index 6c24ad2bdcc53..75f5d057c33a5 100644 --- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp +++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp @@ -168,6 +168,29 @@ bool hasFlag(const Record *OptionOrGroup, StringRef OptionFlag) { return false; } +bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) { + assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags"); + for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags")) +if (hasFlag(OptionOrGroup, Inclusion)) + return true; + return false; +} + +bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) { + if (isIncluded(Group.Group, DocInfo)) +return true; + for (auto &O : Group.Options) +if (isIncluded(O.Option, DocInfo)) + return true; + for (auto &G : Group.Groups) { +if (isIncluded(G.Group, DocInfo)) + return true; +if (isGroupIncluded(G, DocInfo)) + return true; + } + return false; +} + bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) { // FIXME: Provide a flag to specify the set of exclusions. for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags")) @@ -304,6 +327,8 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo, raw_ostream &OS) { if (isExcluded(Option.Option, DocInfo)) return; + if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, DocInfo)) +return; if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" || Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT") return; @@ -379,6 +404,9 @@ void emitGroup(int Depth, const DocumentedGroup &Group, const Record *DocInfo, if (isExcluded(Group.Group, DocInfo)) return; + if (DocInfo->getValue("IncludedFlags") && !isGroupIncluded(Group, DocInfo)) +return; + emitHeading(Depth, getRSTStringWithTextFallback(Group.Group, "DocName", "Name"), OS); diff --git a/flang/docs/CMakeLists.txt b/flang/docs/CMakeLists.txt index 044697a104507..b742be5e12f42 100644 --- a/flang/docs/CMakeLists.txt +++ b/flang/docs/CMakeLists.txt @@ -91,6 +91,16 @@ if (LLVM_ENABLE_DOXYGEN) endif() endif() +function (gen_rst_file_from_td output_file td_option source docs_target) + if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}") +message(FATAL_ERROR "Cannot find source file: ${source} in ${CMAKE_CURRENT_SOURCE_DIR}") + endif() + get_filename_component(TABLEGEN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY) + list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}") + clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file}") + add_dependencies(${docs_target} "gen-${output_file}") +endfunction() + if (LLVM_ENABLE_SPHINX) include(AddSphinxTarget) if (SPHINX_FOUND) @@ -108,12 +118,15 @@ if (LLVM_ENABLE_SPHINX) "${CMAKE_CURRENT_BINARY_DIR}/Source" DEPENDS flang-doc) -# Runs a python script prior to HTML generation to prepend a header to FIRLangRef, -# Without the header, the page is incorrectly formatted, as it assumes the first entry is the page title. -add_custom_command(TARGET copy-flang-src-docs - COMMAND "${Python3_EXECUTABLE}" - ARGS
[clang] ef198cd - [SVE] Remove usage of getMaxVScale for AArch64, in favour of IR Attribute
Author: Dylan Fleming Date: 2021-08-17T14:42:47+01:00 New Revision: ef198cd99e6bac3a2e87adb6c8a18fb461056fa6 URL: https://github.com/llvm/llvm-project/commit/ef198cd99e6bac3a2e87adb6c8a18fb461056fa6 DIFF: https://github.com/llvm/llvm-project/commit/ef198cd99e6bac3a2e87adb6c8a18fb461056fa6.diff LOG: [SVE] Remove usage of getMaxVScale for AArch64, in favour of IR Attribute Removed AArch64 usage of the getMaxVScale interface, replacing it with the vscale_range(min, max) IR Attribute. Reviewed By: paulwalker-arm Differential Revision: https://reviews.llvm.org/D106277 Added: Modified: clang/include/clang/Basic/TargetInfo.h clang/lib/Basic/Targets/AArch64.cpp clang/lib/Basic/Targets/AArch64.h clang/lib/CodeGen/CodeGenFunction.cpp clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h llvm/lib/Transforms/Vectorize/LoopVectorize.cpp llvm/test/Analysis/CostModel/AArch64/sve-gather.ll llvm/test/Analysis/CostModel/AArch64/sve-scatter.ll llvm/test/Transforms/LoopVectorize/AArch64/first-order-recurrence.ll llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization.ll llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll Removed: diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index c7a57a7dba9a8..21289b0dfd04c 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -871,6 +871,11 @@ class TargetInfo : public virtual TransferrableTargetInfo, /// across the current set of primary and secondary targets. virtual ArrayRef getTargetBuiltins() const = 0; + /// Returns target-specific min and max values VScale_Range. + virtual Optional> + getVScaleRange(const LangOptions &LangOpts) const { +return None; + } /// The __builtin_clz* and __builtin_ctz* built-in /// functions are specified to have undefined results for zero inputs, but /// on targets that support these operations in a way that provides diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index e163ebfa2348b..2b5bf34a7b23f 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -424,6 +424,17 @@ ArrayRef AArch64TargetInfo::getTargetBuiltins() const { Builtin::FirstTSBuiltin); } +Optional> +AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts) const { + if (LangOpts.ArmSveVectorBits) { +unsigned VScale = LangOpts.ArmSveVectorBits / 128; +return std::pair(VScale, VScale); + } + if (hasFeature("sve")) +return std::pair(0, 16); + return None; +} + bool AArch64TargetInfo::hasFeature(StringRef Feature) const { return Feature == "aarch64" || Feature == "arm64" || Feature == "arm" || (Feature == "neon" && (FPU & NeonMode)) || diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h index 46882a808336b..12830348fb453 100644 --- a/clang/lib/Basic/Targets/AArch64.h +++ b/clang/lib/Basic/Targets/AArch64.h @@ -96,6 +96,9 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo { ArrayRef getTargetBuiltins() const override; + Optional> + getVScaleRange(const LangOptions &LangOpts) const override; + bool hasFeature(StringRef Feature) const override; bool handleTargetFeatures(std::vector &Features, DiagnosticsEngine &Diags) override; diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index f5eed8572daa3..dca42045325df 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -484,11 +484,13 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { //function. CurFn->addFnAttr("min-legal-vector-width", llvm::utostr(LargestVectorWidth)); - // Add vscale attribute if appropriate. - if (getLangOpts().ArmSveVectorBits) { -unsigned VScale = getLangOpts().ArmSveVectorBits / 128; -CurFn->addFnAttr(llvm::Attribute::getWithVScaleRangeArgs(getLLVMContext(), - VScale, VScale)); + // Add vscale_range attribute if appropriate. + Optional> VScaleRange = + getContext().getTargetInfo().getVScaleRange(getLangOpts()); +