Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions mlir/include/mlir/TableGen/AttrOrTypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "mlir/TableGen/Builder.h"
#include "mlir/TableGen/Trait.h"

#include "llvm/TableGen/Record.h"

namespace llvm {
class DagInit;
class Record;
Expand Down Expand Up @@ -277,6 +279,67 @@ class TypeDef : public AttrOrTypeDef {
StringRef getTypeName() const;
};

//===----------------------------------------------------------------------===//
// DefGenerator
//===----------------------------------------------------------------------===//

/// This struct is the base generator used when processing tablegen interfaces.
class DefGenerator {
public:
bool emitDecls(StringRef selectedDialect);
bool emitDefs(StringRef selectedDialect);

protected:
DefGenerator(std::vector<llvm::Record *> &&defs, raw_ostream &os,
StringRef defType, StringRef valueType, bool isAttrGenerator,
bool formatErrorIsFatal)
: defRecords(std::move(defs)), os(os), defType(defType),
valueType(valueType), isAttrGenerator(isAttrGenerator),
formatErrorIsFatal(formatErrorIsFatal) {
// Sort by occurrence in file.
llvm::sort(defRecords, [](llvm::Record *lhs, llvm::Record *rhs) {
return lhs->getID() < rhs->getID();
});
}

/// Emit the list of def type names.
void emitTypeDefList(ArrayRef<AttrOrTypeDef> defs);
/// Emit the code to dispatch between different defs during parsing/printing.
void emitParsePrintDispatch(ArrayRef<AttrOrTypeDef> defs);

/// The set of def records to emit.
std::vector<llvm::Record *> defRecords;
/// The attribute or type class to emit.
/// The stream to emit to.
raw_ostream &os;
/// The prefix of the tablegen def name, e.g. Attr or Type.
StringRef defType;
/// The C++ base value type of the def, e.g. Attribute or Type.
StringRef valueType;
/// Flag indicating if this generator is for Attributes. False if the
/// generator is for types.
bool isAttrGenerator;
/// Whether a failure in parsing the assembly format should be a fatal error.
bool formatErrorIsFatal;
};

/// A specialized generator for AttrDefs.
struct AttrDefGenerator : public DefGenerator {
AttrDefGenerator(const llvm::RecordKeeper &records, raw_ostream &os,
bool formatErrorIsFatal)
: DefGenerator(records.getAllDerivedDefinitionsIfDefined("AttrDef"), os,
"Attr", "Attribute", /*isAttrGenerator=*/true,
formatErrorIsFatal) {}
};
/// A specialized generator for TypeDefs.
struct TypeDefGenerator : public DefGenerator {
TypeDefGenerator(const llvm::RecordKeeper &records, raw_ostream &os,
bool formatErrorIsFatal)
: DefGenerator(records.getAllDerivedDefinitionsIfDefined("TypeDef"), os,
"Type", "Type", /*isAttrGenerator=*/false,
formatErrorIsFatal) {}
};

} // namespace tblgen
} // namespace mlir

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AttrOrTypeDef;
/// Generate a parser and printer based on a custom assembly format for an
/// attribute or type.
void generateAttrOrTypeFormat(const AttrOrTypeDef &def, MethodBody &parser,
MethodBody &printer);
MethodBody &printer, bool formatErrorIsFatal);

} // namespace tblgen
} // namespace mlir
Expand Down
24 changes: 24 additions & 0 deletions mlir/include/mlir/TableGen/ByteCodeGen.h
Original file line number Diff line number Diff line change
@@ -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_
26 changes: 26 additions & 0 deletions mlir/include/mlir/TableGen/CAPIGen.h
Original file line number Diff line number Diff line change
@@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@

#include "mlir/Support/LLVM.h"

#include "llvm/Support/CommandLine.h"
#include "llvm/TableGen/Record.h"

namespace mlir {
namespace tblgen {
class Dialect;

/// Find the dialect selected by the user to generate for. Returns std::nullopt
/// if no dialect was found, or if more than one potential dialect was found.
std::optional<Dialect> findDialectToGenerate(ArrayRef<Dialect> dialects);
std::optional<Dialect>
findDialectToGenerate(ArrayRef<Dialect> 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand Down
24 changes: 24 additions & 0 deletions mlir/include/mlir/TableGen/EnumGen.h
Original file line number Diff line number Diff line change
@@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vector>

namespace llvm {
Expand Down Expand Up @@ -596,9 +598,6 @@ bool canFormatStringAsKeyword(StringRef value,
bool isValidLiteral(StringRef value,
function_ref<void(Twine)> emitError = nullptr);

/// Whether a failure in parsing the assembly format should be a fatal error.
extern llvm::cl::opt<bool> formatErrorIsFatal;

} // namespace tblgen
} // namespace mlir

Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/TableGen/GenInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#define MLIR_TABLEGEN_GENINFO_H_

#include "mlir/Support/LLVM.h"

#include "llvm/ADT/StringRef.h"

#include <functional>
#include <utility>

Expand Down
37 changes: 37 additions & 0 deletions mlir/include/mlir/TableGen/LLVMGen.h
Original file line number Diff line number Diff line change
@@ -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 ConvertTo>
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_
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class OpClass;
class Operator;

// Generate the assembly format for the given operator.
void generateOpFormat(const Operator &constOp, OpClass &opClass);
void generateOpFormat(const Operator &constOp, OpClass &opClass,
bool formatErrorIsFatal);

} // namespace tblgen
} // namespace mlir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#define MLIR_TOOLS_MLIRTBLGEN_OPGENHELPERS_H_

#include "mlir/Support/LLVM.h"

#include "llvm/TableGen/Record.h"

#include <vector>

namespace mlir {
Expand All @@ -23,15 +25,26 @@ namespace tblgen {
/// Returns all the op definitions filtered by the user. The filtering is via
/// command-line option "op-include-regex" and "op-exclude-regex".
std::vector<llvm::Record *>
getRequestedOpDefinitions(const llvm::RecordKeeper &recordKeeper);
getRequestedOpDefinitions(const llvm::RecordKeeper &recordKeeper,
const std::string &opIncFilter,
const std::string &opExcFilter);

/// Checks whether `str` is a Python keyword or would shadow builtin function.
/// Regenerate using python -c"print(set(sorted(__import__('keyword').kwlist)))"
bool isPythonReserved(llvm::StringRef str);

/// Shard the op defintions into the number of shards set by "op-shard-count".
void shardOpDefinitions(ArrayRef<llvm::Record *> defs,
SmallVectorImpl<ArrayRef<llvm::Record *>> &shardedDefs);
SmallVectorImpl<ArrayRef<llvm::Record *>> &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
Expand Down
Loading