Change add_mlir_doc CMake macro to take the tablegen command as last argument to allow extra flags

This is useful for expressing specific table-gen options, like selecting
a particular dialect to print.
Use it to fix the documentation for the `pdl_interp` dialect which is now
generating the first dialect it finds in its input which is `pdl`.

Differential Revision: https://reviews.llvm.org/D100517
This commit is contained in:
Mehdi Amini 2021-04-15 01:04:59 +00:00
parent 2e3a78b8ca
commit 90ae4d9030
43 changed files with 59 additions and 53 deletions

View File

@ -28,9 +28,9 @@ endfunction()
# Generate Documentation
function(add_mlir_doc doc_filename command output_file output_directory)
function(add_mlir_doc doc_filename output_file output_directory command)
set(LLVM_TARGET_DEFINITIONS ${doc_filename}.td)
tablegen(MLIR ${output_file}.md ${command})
tablegen(MLIR ${output_file}.md ${command} ${ARGN})
set(GEN_DOC_FILE ${MLIR_BINARY_DIR}/docs/${output_directory}${output_file}.md)
add_custom_command(
OUTPUT ${GEN_DOC_FILE}

View File

@ -1,3 +1,3 @@
add_mlir_dialect(StandaloneOps standalone)
add_mlir_doc(StandaloneDialect -gen-dialect-doc StandaloneDialect Standalone/)
add_mlir_doc(StandaloneOps -gen-op-doc StandaloneOps Standalone/)
add_mlir_doc(StandaloneDialect StandaloneDialect Standalone/ -gen-dialect-doc)
add_mlir_doc(StandaloneOps StandaloneOps Standalone/ -gen-op-doc)

View File

@ -5,4 +5,4 @@ mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix Conversion)
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix Conversion)
add_public_tablegen_target(MLIRConversionPassIncGen)
add_mlir_doc(Passes -gen-pass-doc ConversionPasses ./)
add_mlir_doc(Passes ConversionPasses ./ -gen-pass-doc)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(AMX amx)
add_mlir_doc(AMX -gen-dialect-doc AMX Dialects/)
add_mlir_doc(AMX AMX Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS AMX.td)
mlir_tablegen(AMXConversions.inc -gen-llvmir-conversions)

View File

@ -4,4 +4,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Affine)
add_public_tablegen_target(MLIRAffinePassIncGen)
add_mlir_doc(Passes -gen-pass-doc AffinePasses ./)
add_mlir_doc(Passes AffinePasses ./ -gen-pass-doc)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(AffineOps affine)
add_mlir_doc(AffineOps -gen-op-doc AffineOps Dialects/)
add_mlir_doc(AffineOps AffineOps Dialects/ -gen-op-doc)
add_mlir_interface(AffineMemoryOpInterfaces)
add_dependencies(MLIRAffineOpsIncGen MLIRAffineMemoryOpInterfacesIncGen)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(ArmNeon arm_neon)
add_mlir_doc(ArmNeon -gen-dialect-doc ArmNeon Dialects/)
add_mlir_doc(ArmNeon ArmNeon Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS ArmNeon.td)
mlir_tablegen(ArmNeonConversions.inc -gen-llvmir-conversions)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(ArmSVE arm_sve ArmSVE)
add_mlir_doc(ArmSVE -gen-dialect-doc ArmSVE Dialects/)
add_mlir_doc(ArmSVE ArmSVE Dialects/ -gen-dialect-doc)

View File

@ -4,4 +4,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Async)
add_public_tablegen_target(MLIRAsyncPassIncGen)
add_mlir_doc(Passes -gen-pass-doc AsyncPasses ./)
add_mlir_doc(Passes AsyncPasses ./ -gen-pass-doc)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(AsyncOps async)
add_mlir_doc(AsyncOps -gen-dialect-doc AsyncDialect Dialects/)
add_mlir_doc(AsyncOps AsyncDialect Dialects/ -gen-dialect-doc)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(ComplexOps complex)
add_mlir_doc(ComplexOps -gen-dialect-doc ComplexOps Dialects/)
add_mlir_doc(ComplexOps ComplexOps Dialects/ -gen-dialect-doc)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(DLTI dlti)
add_mlir_doc(DLTI -gen-dialect-doc DLTIDialect Dialects/)
add_mlir_doc(DLTI DLTIDialect Dialects/ -gen-dialect-doc)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(GPUOps gpu)
add_mlir_doc(GPUOps -gen-op-doc GPUOps Dialects/)
add_mlir_doc(GPUOps GPUOps Dialects/ -gen-op-doc)
set(LLVM_TARGET_DEFINITIONS GPUBase.td)
mlir_tablegen(GPUOpInterfaces.h.inc -gen-op-interface-decls)
@ -20,4 +20,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name GPU)
add_public_tablegen_target(MLIRGPUPassIncGen)
add_mlir_doc(Passes -gen-pass-doc GPUPasses ./)
add_mlir_doc(Passes GPUPasses ./ -gen-pass-doc)

View File

@ -13,7 +13,7 @@ mlir_tablegen(LLVMOpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(LLVMOpsEnums.cpp.inc -gen-enum-defs)
add_public_tablegen_target(MLIRLLVMOpsIncGen)
add_mlir_doc(LLVMOps -gen-op-doc LLVMOps Dialects/)
add_mlir_doc(LLVMOps LLVMOps Dialects/ -gen-op-doc)
add_mlir_interface(LLVMOpsInterfaces)
@ -24,19 +24,19 @@ mlir_tablegen(LLVMConversionEnumsFromLLVM.inc -gen-enum-from-llvmir-conversions)
add_public_tablegen_target(MLIRLLVMConversionsIncGen)
add_mlir_dialect(NVVMOps nvvm)
add_mlir_doc(NVVMOps -gen-dialect-doc NVVMDialect Dialects/)
add_mlir_doc(NVVMOps NVVMDialect Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS NVVMOps.td)
mlir_tablegen(NVVMConversions.inc -gen-llvmir-conversions)
add_public_tablegen_target(MLIRNVVMConversionsIncGen)
add_mlir_dialect(ROCDLOps rocdl)
add_mlir_doc(ROCDLOps -gen-dialect-doc ROCDLDialect Dialects/)
add_mlir_doc(ROCDLOps ROCDLDialect Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS ROCDLOps.td)
mlir_tablegen(ROCDLConversions.inc -gen-llvmir-conversions)
add_public_tablegen_target(MLIRROCDLConversionsIncGen)
add_mlir_dialect(LLVMArmSVE llvm_arm_sve LLVMArmSVE)
add_mlir_doc(LLVMArmSVE -gen-dialect-doc LLVMArmSve Dialects/)
add_mlir_doc(LLVMArmSVE LLVMArmSve Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS LLVMArmSVE.td)
mlir_tablegen(LLVMArmSVEConversions.inc -gen-llvmir-conversions)
add_public_tablegen_target(MLIRLLVMArmSVEConversionsIncGen)

View File

@ -2,4 +2,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name LLVM)
add_public_tablegen_target(MLIRLLVMPassIncGen)
add_mlir_doc(Passes -gen-pass-doc LLVMPasses ./)
add_mlir_doc(Passes LLVMPasses ./ -gen-pass-doc)

View File

@ -6,4 +6,4 @@ mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix Linalg)
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix Linalg)
add_public_tablegen_target(MLIRLinalgPassIncGen)
add_mlir_doc(Passes -gen-pass-doc LinalgPasses ./)
add_mlir_doc(Passes LinalgPasses ./ -gen-pass-doc)

View File

@ -70,7 +70,7 @@ add_dependencies(mlir-headers LinalgOdsGen)
add_mlir_dialect(LinalgOps linalg)
add_mlir_doc(LinalgDoc -gen-op-doc LinalgOps Dialects/)
add_mlir_doc(LinalgDoc LinalgOps Dialects/ -gen-op-doc)
add_dependencies(LinalgOpsDocGen LinalgOdsGen)
set(LLVM_TARGET_DEFINITIONS LinalgStructuredOps.td)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(MathOps math)
add_mlir_doc(MathOps -gen-dialect-doc MathOps Dialects/)
add_mlir_doc(MathOps MathOps Dialects/ -gen-dialect-doc)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(MemRefOps memref)
add_mlir_doc(MemRefOps -gen-dialect-doc MemRefOps Dialects/)
add_mlir_doc(MemRefOps MemRefOps Dialects/ -gen-dialect-doc)

View File

@ -3,4 +3,4 @@ mlir_tablegen(Passes.h.inc -gen-pass-decls -name MemRef)
add_public_tablegen_target(MLIRMemRefPassIncGen)
add_dependencies(mlir-headers MLIRMemRefPassIncGen)
add_mlir_doc(Passes -gen-pass-doc MemRefPasses ./)
add_mlir_doc(Passes MemRefPasses ./ -gen-pass-doc)

View File

@ -8,6 +8,6 @@ mlir_tablegen(OpenACCOps.h.inc -gen-op-decls)
mlir_tablegen(OpenACCOps.cpp.inc -gen-op-defs)
mlir_tablegen(OpenACCOpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(OpenACCOpsEnums.cpp.inc -gen-enum-defs)
add_mlir_doc(OpenACCOps -gen-dialect-doc OpenACCDialect Dialects/)
add_mlir_doc(OpenACCOps OpenACCDialect Dialects/ -gen-dialect-doc)
add_public_tablegen_target(MLIROpenACCOpsIncGen)
add_dependencies(OpenACCDialectDocGen acc_common_td)

View File

@ -8,6 +8,6 @@ mlir_tablegen(OpenMPOps.h.inc -gen-op-decls)
mlir_tablegen(OpenMPOps.cpp.inc -gen-op-defs)
mlir_tablegen(OpenMPOpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(OpenMPOpsEnums.cpp.inc -gen-enum-defs)
add_mlir_doc(OpenMPOps -gen-dialect-doc OpenMPDialect Dialects/)
add_mlir_doc(OpenMPOps OpenMPDialect Dialects/ -gen-dialect-doc)
add_public_tablegen_target(MLIROpenMPOpsIncGen)
add_dependencies(OpenMPDialectDocGen omp_common_td)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(PDLOps pdl)
add_mlir_doc(PDLOps -gen-dialect-doc PDLOps Dialects/)
add_mlir_doc(PDLOps PDLOps Dialects/ -gen-dialect-doc)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(PDLInterpOps pdl_interp)
add_mlir_doc(PDLInterpOps -gen-dialect-doc PDLInterpOps Dialects/)
add_mlir_doc(PDLInterpOps PDLInterpOps Dialects/ -gen-dialect-doc -dialect=pdl_interp)

View File

@ -1,8 +1,8 @@
add_mlir_dialect(QuantOps quant)
add_mlir_doc(QuantOps -gen-dialect-doc QuantDialect Dialects/)
add_mlir_doc(QuantOps QuantDialect Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Quant)
add_public_tablegen_target(MLIRQuantPassIncGen)
add_mlir_doc(Passes -gen-pass-doc QuantPasses ./)
add_mlir_doc(Passes QuantPasses ./ -gen-pass-doc)

View File

@ -1,9 +1,9 @@
add_mlir_dialect(SCFOps scf Ops)
add_mlir_doc(SCFOps -gen-dialect-doc SCFDialect Dialects/)
add_mlir_doc(SCFOps SCFDialect Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name SCF)
add_public_tablegen_target(MLIRSCFPassIncGen)
add_dependencies(mlir-headers MLIRSCFPassIncGen)
add_mlir_doc(Passes -gen-pass-doc SCFPasses ./)
add_mlir_doc(Passes SCFPasses ./ -gen-pass-doc)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(SPIRVOps spv)
add_mlir_doc(SPIRVOps -gen-op-doc SPIRVOps Dialects/)
add_mlir_doc(SPIRVOps SPIRVOps Dialects/ -gen-op-doc)
set(LLVM_TARGET_DEFINITIONS SPIRVBase.td)
mlir_tablegen(SPIRVEnums.h.inc -gen-enum-decls)

View File

@ -3,5 +3,5 @@ mlir_tablegen(Passes.h.inc -gen-pass-decls -name SPIRV)
add_public_tablegen_target(MLIRSPIRVPassIncGen)
add_dependencies(mlir-headers MLIRSPIRVPassIncGen)
add_mlir_doc(Passes -gen-pass-doc SPIRVPasses ./)
add_mlir_doc(Passes SPIRVPasses ./ -gen-pass-doc)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(ShapeOps shape)
add_mlir_doc(ShapeOps -gen-dialect-doc ShapeDialect Dialects/)
add_mlir_doc(ShapeOps ShapeDialect Dialects/ -gen-dialect-doc)

View File

@ -2,4 +2,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Shape)
add_public_tablegen_target(MLIRShapeTransformsIncGen)
add_mlir_doc(Passes -gen-pass-doc ShapePasses ./)
add_mlir_doc(Passes ShapePasses ./ -gen-pass-doc)

View File

@ -6,4 +6,4 @@ mlir_tablegen(OpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(OpsEnums.cpp.inc -gen-enum-defs)
add_public_tablegen_target(MLIRStandardOpsIncGen)
add_mlir_doc(Ops -gen-op-doc StandardOps Dialects/)
add_mlir_doc(Ops StandardOps Dialects/ -gen-op-doc)

View File

@ -2,4 +2,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Standard)
add_public_tablegen_target(MLIRStandardTransformsIncGen)
add_mlir_doc(Passes -gen-pass-doc StandardPasses ./)
add_mlir_doc(Passes StandardPasses ./ -gen-pass-doc)

View File

@ -1,2 +1,2 @@
add_mlir_dialect(TensorOps tensor)
add_mlir_doc(TensorOps -gen-dialect-doc TensorOps Dialects/)
add_mlir_doc(TensorOps TensorOps Dialects/ -gen-dialect-doc)

View File

@ -2,4 +2,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Tensor)
add_public_tablegen_target(MLIRTensorTransformsIncGen)
add_mlir_doc(Passes -gen-pass-doc TensorPasses ./)
add_mlir_doc(Passes TensorPasses ./ -gen-pass-doc)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(TosaOps tosa)
add_mlir_doc(TosaOps -gen-op-doc TosaOps Dialects/)
add_mlir_doc(TosaOps TosaOps Dialects/ -gen-op-doc)
add_mlir_interface(TosaInterfaces)
set(LLVM_TARGET_DEFINITIONS TosaOps.td)

View File

@ -3,4 +3,4 @@ mlir_tablegen(Passes.h.inc -gen-pass-decls -name TosaOpt)
add_public_tablegen_target(MLIRTosaPassIncGen)
add_dependencies(mlir-headers MLIRTosaPassIncGen)
add_mlir_doc(Passes -gen-pass-doc TosaPasses ./)
add_mlir_doc(Passes TosaPasses ./ -gen-pass-doc)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(VectorOps vector)
add_mlir_doc(VectorOps -gen-op-doc VectorOps Dialects/)
add_mlir_doc(VectorOps VectorOps Dialects/ -gen-op-doc)
set(LLVM_TARGET_DEFINITIONS VectorOps.td)
mlir_tablegen(VectorOpsEnums.h.inc -gen-enum-decls)

View File

@ -1,5 +1,5 @@
add_mlir_dialect(X86Vector x86vector)
add_mlir_doc(X86Vector -gen-dialect-doc X86Vector Dialects/)
add_mlir_doc(X86Vector X86Vector Dialects/ -gen-dialect-doc)
set(LLVM_TARGET_DEFINITIONS X86Vector.td)
mlir_tablegen(X86VectorConversions.inc -gen-llvmir-conversions)

View File

@ -26,7 +26,7 @@ mlir_tablegen(BuiltinTypes.h.inc -gen-typedef-decls)
mlir_tablegen(BuiltinTypes.cpp.inc -gen-typedef-defs)
add_public_tablegen_target(MLIRBuiltinTypesIncGen)
add_mlir_doc(BuiltinAttributes -gen-attrdef-doc BuiltinAttributes Dialects/)
add_mlir_doc(BuiltinLocationAttributes -gen-attrdef-doc BuiltinLocationAttributes Dialects/)
add_mlir_doc(BuiltinOps -gen-op-doc BuiltinOps Dialects/)
add_mlir_doc(BuiltinTypes -gen-typedef-doc BuiltinTypes Dialects/)
add_mlir_doc(BuiltinAttributes BuiltinAttributes Dialects/ -gen-attrdef-doc)
add_mlir_doc(BuiltinLocationAttributes BuiltinLocationAttributes Dialects/ -gen-attrdef-doc)
add_mlir_doc(BuiltinOps BuiltinOps Dialects/ -gen-op-doc)
add_mlir_doc(BuiltinTypes BuiltinTypes Dialects/ -gen-typedef-doc)

View File

@ -2,4 +2,4 @@ set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Reducer)
add_public_tablegen_target(MLIRReducerIncGen)
add_mlir_doc(Passes -gen-pass-doc ReducerPasses ./)
add_mlir_doc(Passes ReducerPasses ./ -gen-pass-doc)

View File

@ -5,4 +5,4 @@ mlir_tablegen(Transforms.capi.h.inc -gen-pass-capi-header --prefix Transforms)
mlir_tablegen(Transforms.capi.cpp.inc -gen-pass-capi-impl --prefix Transforms)
add_public_tablegen_target(MLIRTransformsPassIncGen)
add_mlir_doc(Passes -gen-pass-doc GeneralPasses ./)
add_mlir_doc(Passes GeneralPasses ./ -gen-pass-doc)

View File

@ -31,7 +31,7 @@ using namespace mlir;
using namespace mlir::tblgen;
static llvm::cl::OptionCategory dialectGenCat("Options for -gen-dialect-*");
static llvm::cl::opt<std::string>
llvm::cl::opt<std::string>
selectedDialect("dialect", llvm::cl::desc("The dialect to gen for"),
llvm::cl::cat(dialectGenCat), llvm::cl::CommaSeparated);

View File

@ -19,6 +19,7 @@
#include "mlir/TableGen/Operator.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Signals.h"
#include "llvm/TableGen/Error.h"
@ -33,6 +34,8 @@ using namespace mlir::tblgen;
using mlir::tblgen::Operator;
extern llvm::cl::opt<std::string> selectedDialect;
// Emit the description by aligning the text to the left per line (e.g.,
// removing the minimum indentation across the block).
//
@ -237,6 +240,9 @@ static void emitAttrOrTypeDefDoc(const RecordKeeper &recordKeeper,
static void emitDialectDoc(const Dialect &dialect, ArrayRef<AttrDef> attrDefs,
ArrayRef<Operator> ops, ArrayRef<Type> types,
ArrayRef<TypeDef> typeDefs, raw_ostream &os) {
if (selectedDialect.getNumOccurrences() &&
dialect.getName() != selectedDialect)
return;
os << "# '" << dialect.getName() << "' Dialect\n\n";
emitIfNotEmpty(dialect.getSummary(), os);
emitIfNotEmpty(dialect.getDescription(), os);