From 9e507c8a56dfb3fff143fba27a1090ce42d39aa4 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 19 May 2024 23:29:31 -0500 Subject: [PATCH] factor header --- .../WebAssembly/WebAssemblyAsmPrinter.cpp | 2 +- mlir/include/mlir/TableGen/AttrOrTypeDef.h | 1 + mlir/include/mlir/TableGen/ByteCodeGen.h | 24 ++++++ mlir/include/mlir/TableGen/CAPIGen.h | 26 ++++++ .../mlir/TableGen/DialectGenUtilities.h | 9 ++ mlir/include/mlir/TableGen/DocGenUtilities.h | 17 ++++ mlir/include/mlir/TableGen/EnumGen.h | 24 ++++++ mlir/include/mlir/TableGen/FormatGen.h | 2 + mlir/include/mlir/TableGen/GenInfo.h | 84 +------------------ mlir/include/mlir/TableGen/LLVMGen.h | 37 ++++++++ mlir/include/mlir/TableGen/OpGenHelpers.h | 10 +++ mlir/include/mlir/TableGen/OpInterfacesGen.h | 5 ++ mlir/include/mlir/TableGen/PassGen.h | 25 ++++++ mlir/include/mlir/TableGen/PythonGen.h | 26 ++++++ mlir/include/mlir/TableGen/SPIRVGen.h | 38 +++++++++ mlir/lib/TableGen/AttrOrTypeDefGen.cpp | 2 +- mlir/lib/TableGen/AttrOrTypeFormatGen.cpp | 1 + mlir/lib/TableGen/BytecodeDialectGen.cpp | 5 +- mlir/lib/TableGen/Constraint.cpp | 2 +- mlir/lib/TableGen/DirectiveCommonGen.cpp | 2 +- mlir/lib/TableGen/EnumPythonBindingGen.cpp | 6 +- mlir/lib/TableGen/EnumsGen.cpp | 3 +- mlir/lib/TableGen/LLVMIRConversionGen.cpp | 2 +- mlir/lib/TableGen/LLVMIRIntrinsicGen.cpp | 2 +- mlir/lib/TableGen/OpDefinitionsGen.cpp | 10 +-- mlir/lib/TableGen/OpDocGen.cpp | 3 +- mlir/lib/TableGen/OpFormatGen.cpp | 1 + mlir/lib/TableGen/OpGenHelpers.cpp | 1 + mlir/lib/TableGen/OpInterfacesGen.cpp | 1 + mlir/lib/TableGen/OpPythonBindingGen.cpp | 4 +- mlir/lib/TableGen/Operator.cpp | 4 +- mlir/lib/TableGen/PassCAPIGen.cpp | 5 +- mlir/lib/TableGen/PassDocGen.cpp | 2 +- mlir/lib/TableGen/PassGen.cpp | 5 +- mlir/lib/TableGen/RewriterGen.cpp | 4 +- mlir/lib/TableGen/SPIRVUtilsGen.cpp | 4 +- mlir/tools/mlir-tblgen/mlir-tblgen.cpp | 63 +++++++------- 37 files changed, 315 insertions(+), 147 deletions(-) create mode 100644 mlir/include/mlir/TableGen/ByteCodeGen.h create mode 100644 mlir/include/mlir/TableGen/CAPIGen.h create mode 100644 mlir/include/mlir/TableGen/EnumGen.h create mode 100644 mlir/include/mlir/TableGen/LLVMGen.h create mode 100644 mlir/include/mlir/TableGen/PassGen.h create mode 100644 mlir/include/mlir/TableGen/PythonGen.h create mode 100644 mlir/include/mlir/TableGen/SPIRVGen.h diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index 2ba3bb6310df97..3524abba8990aa 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -387,7 +387,7 @@ void WebAssemblyAsmPrinter::emitDecls(const Module &M) { void WebAssemblyAsmPrinter::emitEndOfAsmFile(Module &M) { // This is required to emit external declarations (like .functypes) when // no functions are defined in the compilation unit and therefore, - // emitDirectiveDecls() is not called until now. + // emitDecls() is not called until now. emitDecls(M); // When a function's address is taken, a TABLE_INDEX relocation is emitted diff --git a/mlir/include/mlir/TableGen/AttrOrTypeDef.h b/mlir/include/mlir/TableGen/AttrOrTypeDef.h index 56fd0264774bed..cf9193f1e97b2b 100644 --- a/mlir/include/mlir/TableGen/AttrOrTypeDef.h +++ b/mlir/include/mlir/TableGen/AttrOrTypeDef.h @@ -17,6 +17,7 @@ #include "mlir/Support/LLVM.h" #include "mlir/TableGen/Builder.h" #include "mlir/TableGen/Trait.h" + #include "llvm/TableGen/Record.h" namespace llvm { diff --git a/mlir/include/mlir/TableGen/ByteCodeGen.h b/mlir/include/mlir/TableGen/ByteCodeGen.h new file mode 100644 index 00000000000000..a3f7f1929914ba --- /dev/null +++ b/mlir/include/mlir/TableGen/ByteCodeGen.h @@ -0,0 +1,24 @@ +//===- ByteCodeGen.h - Generator info ---------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TABLEGEN_BYTECODEGEN_H_ +#define MLIR_TABLEGEN_BYTECODEGEN_H_ + +#include "mlir/Support/LLVM.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" + +namespace mlir::tblgen { + +bool emitBCRW(const llvm::RecordKeeper &records, raw_ostream &os, + const std::string &selectedBcDialect); + +} // namespace mlir::tblgen + +#endif // MLIR_TABLEGEN_BYTECODEGEN_H_ diff --git a/mlir/include/mlir/TableGen/CAPIGen.h b/mlir/include/mlir/TableGen/CAPIGen.h new file mode 100644 index 00000000000000..595d72f1163777 --- /dev/null +++ b/mlir/include/mlir/TableGen/CAPIGen.h @@ -0,0 +1,26 @@ +//===- CAPIGen.h - Generator info -------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TABLEGEN_CAPIGEN_H_ +#define MLIR_TABLEGEN_CAPIGEN_H_ + +#include "mlir/Support/LLVM.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" + +namespace mlir::tblgen { + +bool emitCAPIHeader(const llvm::RecordKeeper &records, raw_ostream &os, + std::string groupPrefix); +bool emitCAPIImpl(const llvm::RecordKeeper &records, raw_ostream &os, + std::string groupPrefix); + +} // namespace mlir::tblgen + +#endif // MLIR_TABLEGEN_CAPIGEN_H_ diff --git a/mlir/include/mlir/TableGen/DialectGenUtilities.h b/mlir/include/mlir/TableGen/DialectGenUtilities.h index d0f7f3f6f8819f..483b5ba43efc6f 100644 --- a/mlir/include/mlir/TableGen/DialectGenUtilities.h +++ b/mlir/include/mlir/TableGen/DialectGenUtilities.h @@ -10,7 +10,9 @@ #define MLIR_TOOLS_MLIRTBLGEN_DIALECTGENUTILITIES_H_ #include "mlir/Support/LLVM.h" + #include "llvm/Support/CommandLine.h" +#include "llvm/TableGen/Record.h" namespace mlir { namespace tblgen { @@ -21,6 +23,13 @@ class Dialect; std::optional findDialectToGenerate(ArrayRef dialects, const std::string &selectedDialect); +bool emitDialectDecls(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, + const std::string &selectedDialect); +bool emitDialectDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, + const std::string &selectedDialect); +bool emitDirectiveDecls(const llvm::RecordKeeper &recordKeeper, + llvm::StringRef dialect, raw_ostream &os); + } // namespace tblgen } // namespace mlir diff --git a/mlir/include/mlir/TableGen/DocGenUtilities.h b/mlir/include/mlir/TableGen/DocGenUtilities.h index dd1dbbe243911f..90296062917bb9 100644 --- a/mlir/include/mlir/TableGen/DocGenUtilities.h +++ b/mlir/include/mlir/TableGen/DocGenUtilities.h @@ -15,6 +15,7 @@ #define MLIR_TOOLS_MLIRTBLGEN_DOCGENUTILITIES_H_ #include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" namespace llvm { class raw_ostream; @@ -39,6 +40,22 @@ void emitDescription(llvm::StringRef description, llvm::raw_ostream &os); void emitDescriptionComment(llvm::StringRef description, llvm::raw_ostream &os, llvm::StringRef prefix = ""); +void emitAttrOrTypeDefDoc(const llvm::RecordKeeper &recordKeeper, + llvm::raw_ostream &os, + llvm::StringRef recordTypeName); + +void emitOpDoc(const llvm::RecordKeeper &recordKeeper, llvm::raw_ostream &os, + const std::string &emitOpDoc, bool allowHugoSpecificFeatures, + const std::string &opIncFilter, const std::string &opExcFilter); + +bool emitDialectDoc(const llvm::RecordKeeper &recordKeeper, + llvm::raw_ostream &os, const std::string &selectedDialect, + const std::string &opIncFilter, + const std::string &opExcFilter, + const std::string &stripPrefix, + bool allowHugoSpecificFeatures); +void emitDocs(const llvm::RecordKeeper &recordKeeper, llvm::raw_ostream &os); + } // namespace tblgen } // namespace mlir diff --git a/mlir/include/mlir/TableGen/EnumGen.h b/mlir/include/mlir/TableGen/EnumGen.h new file mode 100644 index 00000000000000..824f2b1bb9d1e6 --- /dev/null +++ b/mlir/include/mlir/TableGen/EnumGen.h @@ -0,0 +1,24 @@ +//===- EnumGen.h - Generator info -------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TABLEGEN_ENUMGEN_H_ +#define MLIR_TABLEGEN_ENUMGEN_H_ + +#include "mlir/Support/LLVM.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" + +namespace mlir::tblgen { + +bool emitEnumDecls(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); +bool emitEnumDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); + +} // namespace mlir::tblgen + +#endif // MLIR_TABLEGEN_ENUMGEN_H_ diff --git a/mlir/include/mlir/TableGen/FormatGen.h b/mlir/include/mlir/TableGen/FormatGen.h index 2a05414e90f298..5fc790ebc24a11 100644 --- a/mlir/include/mlir/TableGen/FormatGen.h +++ b/mlir/include/mlir/TableGen/FormatGen.h @@ -16,11 +16,13 @@ #include "mlir/Support/LLVM.h" #include "mlir/Support/LogicalResult.h" + #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/SMLoc.h" + #include namespace llvm { diff --git a/mlir/include/mlir/TableGen/GenInfo.h b/mlir/include/mlir/TableGen/GenInfo.h index 57fc7f911eaef6..dff934a195e19b 100644 --- a/mlir/include/mlir/TableGen/GenInfo.h +++ b/mlir/include/mlir/TableGen/GenInfo.h @@ -10,8 +10,9 @@ #define MLIR_TABLEGEN_GENINFO_H_ #include "mlir/Support/LLVM.h" + #include "llvm/ADT/StringRef.h" -#include "llvm/Support/CommandLine.h" + #include #include @@ -70,87 +71,6 @@ struct GenRegistration { const GenFunction &function); }; -namespace tblgen { -bool emitBCRW(const llvm::RecordKeeper &records, raw_ostream &os, - const std::string &selectedBcDialect); - -bool emitOpDecls(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, - const std::string &opIncFilter, const std::string &opExcFilter, - unsigned opShardCount, bool formatErrorIsFatal); -bool emitOpDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, - const std::string &opIncFilter, const std::string &opExcFilter, - unsigned opShardCount, bool formatErrorIsFatal); - -bool emitDialectDecls(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, - const std::string &selectedDialect); -bool emitDialectDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, - const std::string &selectedDialect); -bool emitDirectiveDecls(const llvm::RecordKeeper &recordKeeper, - llvm::StringRef dialect, raw_ostream &os); - -bool emitPythonEnums(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); -bool emitAllPythonOps(const llvm::RecordKeeper &records, raw_ostream &os, - const std::string &clDialectName, - const std::string &clDialectExtensionName); - -bool emitEnumDecls(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); -bool emitEnumDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); - -bool emitLLVMBuilders(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); -bool emitLLVMOpMLIRBuilders(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitLLVMIntrMLIRBuilders(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -template -bool emitLLVMEnumConversionDefs(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitLLVMConvertibleIntrinsics(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitLLVMIntrinsics(const llvm::RecordKeeper &records, - llvm::raw_ostream &os, const std::string &nameFilter, - const std::string &accessGroupRegexp, - const std::string &aliasAnalysisRegexp, - const std::string &opBaseClass); - -void emitAttrOrTypeDefDoc(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os, StringRef recordTypeName); -void emitOpDoc(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, - const std::string &emitOpDoc, bool allowHugoSpecificFeatures, - const std::string &opIncFilter, const std::string &opExcFilter); -bool emitDialectDoc(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, - const std::string &selectedDialect, - const std::string &opIncFilter, - const std::string &opExcFilter, - const std::string &stripPrefix, - bool allowHugoSpecificFeatures); -void emitDocs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); - -bool emitCAPIHeader(const llvm::RecordKeeper &records, raw_ostream &os, - std::string groupPrefix); -bool emitCAPIImpl(const llvm::RecordKeeper &records, raw_ostream &os, - std::string groupPrefix); -void emitPasses(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, - const std::string &opIncFilter, const std::string &groupName); -void emitRewriters(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); - -bool emitSPIRVInterfaceDefs(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitSPIRVInterfaceDecls(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitSPIRVEnumDecls(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitSPIRVEnumDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); -bool emitSPIRVCapabilityImplication(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitSPIRVSerializationFns(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitSPIRVAttrUtils(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); -bool emitSPIRVAvailabilityImpl(const llvm::RecordKeeper &recordKeeper, - raw_ostream &os); - -} // namespace tblgen - } // namespace mlir #endif // MLIR_TABLEGEN_GENINFO_H_ diff --git a/mlir/include/mlir/TableGen/LLVMGen.h b/mlir/include/mlir/TableGen/LLVMGen.h new file mode 100644 index 00000000000000..030fbc2862932d --- /dev/null +++ b/mlir/include/mlir/TableGen/LLVMGen.h @@ -0,0 +1,37 @@ +//===- LLVMGen.h - Generator info -------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TABLEGEN_LLVMGEN_H_ +#define MLIR_TABLEGEN_LLVMGEN_H_ + +#include "mlir/Support/LLVM.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" + +namespace mlir::tblgen { + +bool emitLLVMBuilders(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); +bool emitLLVMOpMLIRBuilders(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitLLVMIntrMLIRBuilders(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +template +bool emitLLVMEnumConversionDefs(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitLLVMConvertibleIntrinsics(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitLLVMIntrinsics(const llvm::RecordKeeper &records, + llvm::raw_ostream &os, const std::string &nameFilter, + const std::string &accessGroupRegexp, + const std::string &aliasAnalysisRegexp, + const std::string &opBaseClass); + +} // namespace mlir::tblgen + +#endif // MLIR_TABLEGEN_LLVMGEN_H_ diff --git a/mlir/include/mlir/TableGen/OpGenHelpers.h b/mlir/include/mlir/TableGen/OpGenHelpers.h index 537a42770cfac5..da5b8a89c4ed8e 100644 --- a/mlir/include/mlir/TableGen/OpGenHelpers.h +++ b/mlir/include/mlir/TableGen/OpGenHelpers.h @@ -14,7 +14,9 @@ #define MLIR_TOOLS_MLIRTBLGEN_OPGENHELPERS_H_ #include "mlir/Support/LLVM.h" + #include "llvm/TableGen/Record.h" + #include namespace mlir { @@ -36,6 +38,14 @@ void shardOpDefinitions(ArrayRef defs, SmallVectorImpl> &shardedDefs, unsigned shardOpDefinitions); +bool emitOpDecls(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, + const std::string &opIncFilter, const std::string &opExcFilter, + unsigned opShardCount, bool formatErrorIsFatal); + +bool emitOpDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, + const std::string &opIncFilter, const std::string &opExcFilter, + unsigned opShardCount, bool formatErrorIsFatal); + } // namespace tblgen } // namespace mlir diff --git a/mlir/include/mlir/TableGen/OpInterfacesGen.h b/mlir/include/mlir/TableGen/OpInterfacesGen.h index f5d087941f5d67..eb8491ce5e5354 100644 --- a/mlir/include/mlir/TableGen/OpInterfacesGen.h +++ b/mlir/include/mlir/TableGen/OpInterfacesGen.h @@ -17,7 +17,9 @@ #include "mlir/TableGen/Format.h" #include "mlir/TableGen/GenInfo.h" #include "mlir/TableGen/Interfaces.h" + #include "llvm/TableGen/Record.h" + #include namespace mlir { @@ -105,6 +107,7 @@ struct AttrInterfaceGenerator : public InterfaceGenerator { extraDeclsFmt.addSubst(substVar, "(*this)"); } }; + /// A specialized generator for operation interfaces. struct OpInterfaceGenerator : public InterfaceGenerator { OpInterfaceGenerator(const llvm::RecordKeeper &records, raw_ostream &os) @@ -121,6 +124,7 @@ struct OpInterfaceGenerator : public InterfaceGenerator { extraDeclsFmt.addSubst(substVar, "(*this)"); } }; + /// A specialized generator for type interfaces. struct TypeInterfaceGenerator : public InterfaceGenerator { TypeInterfaceGenerator(const llvm::RecordKeeper &records, raw_ostream &os) @@ -136,6 +140,7 @@ struct TypeInterfaceGenerator : public InterfaceGenerator { extraDeclsFmt.addSubst(substVar, "(*this)"); } }; + } // namespace tblgen } // namespace mlir diff --git a/mlir/include/mlir/TableGen/PassGen.h b/mlir/include/mlir/TableGen/PassGen.h new file mode 100644 index 00000000000000..d57ade7b0c20d2 --- /dev/null +++ b/mlir/include/mlir/TableGen/PassGen.h @@ -0,0 +1,25 @@ +//===- Passgen.h - Generator info -------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TABLEGEN_PASSGEN_H_ +#define MLIR_TABLEGEN_PASSGEN_H_ + +#include "mlir/Support/LLVM.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" + +namespace mlir::tblgen { + +void emitPasses(const llvm::RecordKeeper &recordKeeper, raw_ostream &os, + const std::string &opIncFilter, const std::string &groupName); +void emitRewriters(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); + +} // namespace mlir::tblgen + +#endif // MLIR_TABLEGEN_PASSGEN_H_ diff --git a/mlir/include/mlir/TableGen/PythonGen.h b/mlir/include/mlir/TableGen/PythonGen.h new file mode 100644 index 00000000000000..c9001cce323f60 --- /dev/null +++ b/mlir/include/mlir/TableGen/PythonGen.h @@ -0,0 +1,26 @@ +//===- PythonGen.h - Generator info -----------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TABLEGEN_PYTHONGEN_H_ +#define MLIR_TABLEGEN_PYTHONGEN_H_ + +#include "mlir/Support/LLVM.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" + +namespace mlir::tblgen { + +bool emitPythonEnums(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); +bool emitAllPythonOps(const llvm::RecordKeeper &records, raw_ostream &os, + const std::string &clDialectName, + const std::string &clDialectExtensionName); + +} // namespace mlir::tblgen + +#endif // MLIR_TABLEGEN_PYTHONGEN_H_ diff --git a/mlir/include/mlir/TableGen/SPIRVGen.h b/mlir/include/mlir/TableGen/SPIRVGen.h new file mode 100644 index 00000000000000..cec6bde3d9b5f5 --- /dev/null +++ b/mlir/include/mlir/TableGen/SPIRVGen.h @@ -0,0 +1,38 @@ +//===- SPIRVGen.h - Generator info -------------------------------*- C++ +//-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TABLEGEN_SPIRVGEN_H_ +#define MLIR_TABLEGEN_SPIRVGEN_H_ + +#include "mlir/Support/LLVM.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/TableGen/Record.h" + +namespace mlir::tblgen { + +bool emitSPIRVInterfaceDefs(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitSPIRVInterfaceDecls(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitSPIRVEnumDecls(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitSPIRVEnumDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os); +bool emitSPIRVCapabilityImplication(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitSPIRVSerializationFns(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitSPIRVAttrUtils(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); +bool emitSPIRVAvailabilityImpl(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os); + +} // namespace mlir::tblgen + +#endif // MLIR_TABLEGEN_SPIRVGEN_H_ diff --git a/mlir/lib/TableGen/AttrOrTypeDefGen.cpp b/mlir/lib/TableGen/AttrOrTypeDefGen.cpp index 82208093a87a2a..c533940c09e23f 100644 --- a/mlir/lib/TableGen/AttrOrTypeDefGen.cpp +++ b/mlir/lib/TableGen/AttrOrTypeDefGen.cpp @@ -12,7 +12,7 @@ #include "mlir/TableGen/CodeGenHelpers.h" #include "mlir/TableGen/Format.h" #include "mlir/TableGen/Interfaces.h" -#include "llvm/ADT/StringSet.h" + #include "llvm/Support/CommandLine.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/TableGenBackend.h" diff --git a/mlir/lib/TableGen/AttrOrTypeFormatGen.cpp b/mlir/lib/TableGen/AttrOrTypeFormatGen.cpp index 5fc3194d615aec..ca1b77c2eac0d4 100644 --- a/mlir/lib/TableGen/AttrOrTypeFormatGen.cpp +++ b/mlir/lib/TableGen/AttrOrTypeFormatGen.cpp @@ -12,6 +12,7 @@ #include "mlir/TableGen/AttrOrTypeDef.h" #include "mlir/TableGen/Format.h" #include "mlir/TableGen/FormatGen.h" + #include "llvm/ADT/BitVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" diff --git a/mlir/lib/TableGen/BytecodeDialectGen.cpp b/mlir/lib/TableGen/BytecodeDialectGen.cpp index 115e817ae0ce25..acbdfb11d1c090 100644 --- a/mlir/lib/TableGen/BytecodeDialectGen.cpp +++ b/mlir/lib/TableGen/BytecodeDialectGen.cpp @@ -7,13 +7,14 @@ //===----------------------------------------------------------------------===// #include "mlir/Support/IndentedOstream.h" -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/ByteCodeGen.h" + #include "llvm/ADT/MapVector.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" + #include using namespace llvm; diff --git a/mlir/lib/TableGen/Constraint.cpp b/mlir/lib/TableGen/Constraint.cpp index bc184202238054..4ccbd0a685e09a 100644 --- a/mlir/lib/TableGen/Constraint.cpp +++ b/mlir/lib/TableGen/Constraint.cpp @@ -30,7 +30,7 @@ Constraint::Constraint(const llvm::Record *record) kind = CK_Region; } else if (def->isSubClassOf("SuccessorConstraint")) { kind = CK_Successor; - } else if (!def->isSubClassOf("Constraint")) { + } else if(!def->isSubClassOf("Constraint")) { llvm::errs() << "Expected a constraint but got: \n" << *def << "\n"; llvm::report_fatal_error("Abort"); } diff --git a/mlir/lib/TableGen/DirectiveCommonGen.cpp b/mlir/lib/TableGen/DirectiveCommonGen.cpp index 394427fa08b02e..63cff39929ecbd 100644 --- a/mlir/lib/TableGen/DirectiveCommonGen.cpp +++ b/mlir/lib/TableGen/DirectiveCommonGen.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/DialectGenUtilities.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/CommandLine.h" diff --git a/mlir/lib/TableGen/EnumPythonBindingGen.cpp b/mlir/lib/TableGen/EnumPythonBindingGen.cpp index eca60b45423ec9..26a76b96cdb0dd 100644 --- a/mlir/lib/TableGen/EnumPythonBindingGen.cpp +++ b/mlir/lib/TableGen/EnumPythonBindingGen.cpp @@ -10,12 +10,12 @@ // generate the corresponding Python binding classes. // //===----------------------------------------------------------------------===// -#include "mlir/TableGen/OpGenHelpers.h" - #include "mlir/TableGen/AttrOrTypeDef.h" #include "mlir/TableGen/Attribute.h" #include "mlir/TableGen/Dialect.h" -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/OpGenHelpers.h" +#include "mlir/TableGen/PythonGen.h" + #include "llvm/Support/FormatVariadic.h" #include "llvm/TableGen/Record.h" diff --git a/mlir/lib/TableGen/EnumsGen.cpp b/mlir/lib/TableGen/EnumsGen.cpp index 4eef7c79e704ae..2556fcf577fbe0 100644 --- a/mlir/lib/TableGen/EnumsGen.cpp +++ b/mlir/lib/TableGen/EnumsGen.cpp @@ -11,9 +11,10 @@ //===----------------------------------------------------------------------===// #include "mlir/TableGen/Attribute.h" +#include "mlir/TableGen/EnumGen.h" #include "mlir/TableGen/Format.h" #include "mlir/TableGen/FormatGen.h" -#include "mlir/TableGen/GenInfo.h" + #include "llvm/ADT/BitVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/lib/TableGen/LLVMIRConversionGen.cpp b/mlir/lib/TableGen/LLVMIRConversionGen.cpp index c8b9e3680577d5..fe3ff51fc9d29b 100644 --- a/mlir/lib/TableGen/LLVMIRConversionGen.cpp +++ b/mlir/lib/TableGen/LLVMIRConversionGen.cpp @@ -14,7 +14,7 @@ #include "mlir/Support/LogicalResult.h" #include "mlir/TableGen/Argument.h" #include "mlir/TableGen/Attribute.h" -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/LLVMGen.h" #include "mlir/TableGen/Operator.h" #include "llvm/ADT/Sequence.h" diff --git a/mlir/lib/TableGen/LLVMIRIntrinsicGen.cpp b/mlir/lib/TableGen/LLVMIRIntrinsicGen.cpp index 849165c462990b..97a5c5023d4b20 100644 --- a/mlir/lib/TableGen/LLVMIRIntrinsicGen.cpp +++ b/mlir/lib/TableGen/LLVMIRIntrinsicGen.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/LLVMGen.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/CodeGenTypes/MachineValueType.h" diff --git a/mlir/lib/TableGen/OpDefinitionsGen.cpp b/mlir/lib/TableGen/OpDefinitionsGen.cpp index 1900304a21b452..2adebb07814967 100644 --- a/mlir/lib/TableGen/OpDefinitionsGen.cpp +++ b/mlir/lib/TableGen/OpDefinitionsGen.cpp @@ -25,6 +25,7 @@ #include "mlir/TableGen/Property.h" #include "mlir/TableGen/SideEffects.h" #include "mlir/TableGen/Trait.h" + #include "llvm/ADT/BitVector.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/Sequence.h" @@ -736,9 +737,6 @@ class OpEmitter { // Helper for emitting op code. OpOrAdaptorHelper emitHelper; - - /// Whether a failure in parsing the assembly format should be a fatal error. - bool formatErrorIsFatal; }; } // namespace @@ -1031,8 +1029,7 @@ OpEmitter::OpEmitter(const Operator &op, opClass(op.getCppClassName(), formatExtraDeclarations(op), formatExtraDefinitions(op)), staticVerifierEmitter(staticVerifierEmitter), - emitHelper(op, /*emitForOp=*/true), - formatErrorIsFatal(formatErrorIsFatal) { + emitHelper(op, /*emitForOp=*/true) { verifyCtx.addSubst("_op", "(*this->getOperation())"); verifyCtx.addSubst("_ctxt", "this->getOperation()->getContext()"); @@ -2492,7 +2489,8 @@ void OpEmitter::genSeparateArgParamBuilder() { // Avoid emitting "resultTypes.size() >= 0u" which is always true. if (!hasVariadicResult || numNonVariadicResults != 0) - body << " " << "assert(resultTypes.size() " + body << " " + << "assert(resultTypes.size() " << (hasVariadicResult ? ">=" : "==") << " " << numNonVariadicResults << "u && \"mismatched number of results\");\n"; diff --git a/mlir/lib/TableGen/OpDocGen.cpp b/mlir/lib/TableGen/OpDocGen.cpp index 46e4582229542f..64a68f000c9931 100644 --- a/mlir/lib/TableGen/OpDocGen.cpp +++ b/mlir/lib/TableGen/OpDocGen.cpp @@ -216,7 +216,8 @@ static void emitOpDoc(const Operator &op, raw_ostream &os, // Expandable description. // This appears as just the summary, but when clicked shows the full // description. - os << "
" << "" << it.attr.getSummary() << "" + os << "
" + << "" << it.attr.getSummary() << "" << "{{% markdown %}}" << description << "{{% /markdown %}}" << "
"; } else { diff --git a/mlir/lib/TableGen/OpFormatGen.cpp b/mlir/lib/TableGen/OpFormatGen.cpp index f78b7d722b30f7..a80170f64c4559 100644 --- a/mlir/lib/TableGen/OpFormatGen.cpp +++ b/mlir/lib/TableGen/OpFormatGen.cpp @@ -14,6 +14,7 @@ #include "mlir/TableGen/OpClass.h" #include "mlir/TableGen/Operator.h" #include "mlir/TableGen/Trait.h" + #include "llvm/ADT/MapVector.h" #include "llvm/ADT/Sequence.h" #include "llvm/ADT/SetVector.h" diff --git a/mlir/lib/TableGen/OpGenHelpers.cpp b/mlir/lib/TableGen/OpGenHelpers.cpp index 658a78b6960d2e..40d5a75f79c6a1 100644 --- a/mlir/lib/TableGen/OpGenHelpers.cpp +++ b/mlir/lib/TableGen/OpGenHelpers.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "mlir/TableGen/OpGenHelpers.h" + #include "llvm/ADT/StringSet.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Regex.h" diff --git a/mlir/lib/TableGen/OpInterfacesGen.cpp b/mlir/lib/TableGen/OpInterfacesGen.cpp index a2fbb41064311d..cdc3d20943dcac 100644 --- a/mlir/lib/TableGen/OpInterfacesGen.cpp +++ b/mlir/lib/TableGen/OpInterfacesGen.cpp @@ -15,6 +15,7 @@ #include "mlir/TableGen/Format.h" #include "mlir/TableGen/GenInfo.h" #include "mlir/TableGen/Interfaces.h" + #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/FormatVariadic.h" diff --git a/mlir/lib/TableGen/OpPythonBindingGen.cpp b/mlir/lib/TableGen/OpPythonBindingGen.cpp index e30809e6cb5720..a88acc2b57c1f1 100644 --- a/mlir/lib/TableGen/OpPythonBindingGen.cpp +++ b/mlir/lib/TableGen/OpPythonBindingGen.cpp @@ -12,9 +12,9 @@ //===----------------------------------------------------------------------===// #include "mlir/TableGen/OpGenHelpers.h" - -#include "mlir/TableGen/GenInfo.h" #include "mlir/TableGen/Operator.h" +#include "mlir/TableGen/PythonGen.h" + #include "llvm/ADT/StringSet.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/TableGen/Error.h" diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp index 41b32b41812431..31a60bf379a2a5 100644 --- a/mlir/lib/TableGen/Operator.cpp +++ b/mlir/lib/TableGen/Operator.cpp @@ -12,9 +12,9 @@ #include "mlir/TableGen/Operator.h" #include "mlir/TableGen/Argument.h" -#include "mlir/TableGen/Predicate.h" #include "mlir/TableGen/Trait.h" #include "mlir/TableGen/Type.h" + #include "llvm/ADT/EquivalenceClasses.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Sequence.h" @@ -22,11 +22,9 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" -#include #define DEBUG_TYPE "mlir-tblgen-operator" diff --git a/mlir/lib/TableGen/PassCAPIGen.cpp b/mlir/lib/TableGen/PassCAPIGen.cpp index 8f2f41e672289d..d0e7c7a2571f83 100644 --- a/mlir/lib/TableGen/PassCAPIGen.cpp +++ b/mlir/lib/TableGen/PassCAPIGen.cpp @@ -10,12 +10,11 @@ // //===----------------------------------------------------------------------===// -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/CAPIGen.h" #include "mlir/TableGen/Pass.h" + #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/FormatVariadic.h" -#include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" using namespace mlir; diff --git a/mlir/lib/TableGen/PassDocGen.cpp b/mlir/lib/TableGen/PassDocGen.cpp index a1c3981f12c39d..cb52c34afa4ae4 100644 --- a/mlir/lib/TableGen/PassDocGen.cpp +++ b/mlir/lib/TableGen/PassDocGen.cpp @@ -11,8 +11,8 @@ //===----------------------------------------------------------------------===// #include "mlir/TableGen/DocGenUtilities.h" -#include "mlir/TableGen/GenInfo.h" #include "mlir/TableGen/Pass.h" + #include "llvm/Support/FormatVariadic.h" #include "llvm/TableGen/Record.h" diff --git a/mlir/lib/TableGen/PassGen.cpp b/mlir/lib/TableGen/PassGen.cpp index cc96d4bff76c34..03a3ec88362b1a 100644 --- a/mlir/lib/TableGen/PassGen.cpp +++ b/mlir/lib/TableGen/PassGen.cpp @@ -11,12 +11,11 @@ // //===----------------------------------------------------------------------===// -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/PassGen.h" #include "mlir/TableGen/Pass.h" + #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/FormatVariadic.h" -#include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" using namespace mlir; diff --git a/mlir/lib/TableGen/RewriterGen.cpp b/mlir/lib/TableGen/RewriterGen.cpp index 5c084df053c3e0..3c325cc891b575 100644 --- a/mlir/lib/TableGen/RewriterGen.cpp +++ b/mlir/lib/TableGen/RewriterGen.cpp @@ -15,12 +15,12 @@ #include "mlir/TableGen/Attribute.h" #include "mlir/TableGen/CodeGenHelpers.h" #include "mlir/TableGen/Format.h" -#include "mlir/TableGen/GenInfo.h" #include "mlir/TableGen/Operator.h" +#include "mlir/TableGen/PassGen.h" #include "mlir/TableGen/Pattern.h" #include "mlir/TableGen/Predicate.h" -#include "mlir/TableGen/Property.h" #include "mlir/TableGen/Type.h" + #include "llvm/ADT/FunctionExtras.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/lib/TableGen/SPIRVUtilsGen.cpp b/mlir/lib/TableGen/SPIRVUtilsGen.cpp index 36095adc62d724..172467258fc643 100644 --- a/mlir/lib/TableGen/SPIRVUtilsGen.cpp +++ b/mlir/lib/TableGen/SPIRVUtilsGen.cpp @@ -14,8 +14,9 @@ #include "mlir/TableGen/Attribute.h" #include "mlir/TableGen/CodeGenHelpers.h" #include "mlir/TableGen/Format.h" -#include "mlir/TableGen/GenInfo.h" #include "mlir/TableGen/Operator.h" +#include "mlir/TableGen/SPIRVGen.h" + #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallVector.h" @@ -30,7 +31,6 @@ #include "llvm/TableGen/TableGenBackend.h" #include -#include using llvm::ArrayRef; using llvm::formatv; diff --git a/mlir/tools/mlir-tblgen/mlir-tblgen.cpp b/mlir/tools/mlir-tblgen/mlir-tblgen.cpp index 2e9082278abd50..248679cbe1a8c1 100644 --- a/mlir/tools/mlir-tblgen/mlir-tblgen.cpp +++ b/mlir/tools/mlir-tblgen/mlir-tblgen.cpp @@ -11,9 +11,19 @@ //===----------------------------------------------------------------------===// #include "mlir/TableGen/AttrOrTypeDef.h" -#include "mlir/TableGen/GenInfo.h" +#include "mlir/TableGen/ByteCodeGen.h" +#include "mlir/TableGen/CAPIGen.h" +#include "mlir/TableGen/DialectGenUtilities.h" +#include "mlir/TableGen/DocGenUtilities.h" +#include "mlir/TableGen/EnumGen.h" +#include "mlir/TableGen/LLVMGen.h" +#include "mlir/TableGen/OpGenHelpers.h" #include "mlir/TableGen/OpInterfacesGen.h" +#include "mlir/TableGen/PassGen.h" +#include "mlir/TableGen/PythonGen.h" +#include "mlir/TableGen/SPIRVGen.h" #include "mlir/Tools/mlir-tblgen/MlirTblgenMain.h" + #include "llvm/Support/CommandLine.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" @@ -22,44 +32,22 @@ using namespace llvm; using namespace mlir; using namespace mlir::tblgen; -//===----------------------------------------------------------------------===// -// Commandline Options -//===----------------------------------------------------------------------===// - -static llvm::cl::opt formatErrorIsFatal( - "asmformat-error-is-fatal", - llvm::cl::desc("Emit a fatal error if format parsing fails"), - llvm::cl::init(true)); - -cl::OptionCategory opDefGenCat("Options for op definition generators"); - -static cl::opt opIncFilter( - "op-include-regex", - cl::desc("Regex of name of op's to include (no filter if empty)"), - cl::cat(opDefGenCat)); -static cl::opt opExcFilter( - "op-exclude-regex", - cl::desc("Regex of name of op's to exclude (no filter if empty)"), - cl::cat(opDefGenCat)); -static cl::opt opShardCount( - "op-shard-count", - cl::desc("The number of shards into which the op classes will be divided"), - cl::cat(opDefGenCat), cl::init(1)); - -//===----------------------------------------------------------------------===// -// GEN: Registration hooks -//===----------------------------------------------------------------------===// - //===----------------------------------------------------------------------===// // AttrDef //===----------------------------------------------------------------------===// static llvm::cl::OptionCategory attrdefGenCat("Options for -gen-attrdef-*"); + static llvm::cl::opt attrDialect("attrdefs-dialect", llvm::cl::desc("Generate attributes for this dialect"), llvm::cl::cat(attrdefGenCat), llvm::cl::CommaSeparated); +static llvm::cl::opt formatErrorIsFatal( + "asmformat-error-is-fatal", + llvm::cl::desc("Emit a fatal error if format parsing fails"), + llvm::cl::init(true)); + static mlir::GenRegistration genAttrDefs("gen-attrdef-defs", "Generate AttrDef definitions", [](const llvm::RecordKeeper &records, raw_ostream &os) { @@ -77,6 +65,21 @@ static mlir::GenRegistration // TypeDef //===----------------------------------------------------------------------===// +cl::OptionCategory opDefGenCat("Options for op definition generators"); + +static cl::opt opIncFilter( + "op-include-regex", + cl::desc("Regex of name of op's to include (no filter if empty)"), + cl::cat(opDefGenCat)); +static cl::opt opExcFilter( + "op-exclude-regex", + cl::desc("Regex of name of op's to exclude (no filter if empty)"), + cl::cat(opDefGenCat)); +static cl::opt opShardCount( + "op-shard-count", + cl::desc("The number of shards into which the op classes will be divided"), + cl::cat(opDefGenCat), cl::init(1)); + static llvm::cl::OptionCategory typedefGenCat("Options for -gen-typedef-*"); static llvm::cl::opt typeDialect("typedefs-dialect", @@ -459,7 +462,7 @@ static mlir::GenRegistration genSPIRVOpAvailabilityImpl( }); //===----------------------------------------------------------------------===// -// +// Generic //===----------------------------------------------------------------------===// // Generator that prints records.