#include "OpClass.h"
#include "OpFormatGen.h"
#include "OpGenHelpers.h"
#include "mlir/TableGen/Argument.h"
#include "mlir/TableGen/Attribute.h"
#include "mlir/TableGen/Class.h"
#include "mlir/TableGen/CodeGenHelpers.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
#include "mlir/TableGen/Interfaces.h"
#include "mlir/TableGen/Operator.h"
#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"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#define DEBUG_TYPE …
usingnamespacellvm;
usingnamespacemlir;
usingnamespacemlir::tblgen;
static const char *const tblgenNamePrefix = …;
static const char *const generatedArgName = …;
static const char *const odsBuilder = …;
static const char *const builderOpState = …;
static const char *const propertyStorage = …;
static const char *const propertyValue = …;
static const char *const propertyAttr = …;
static const char *const propertyDiag = …;
static const char *const operandSegmentAttrName = …;
static const char *const resultSegmentAttrName = …;
static const char *const subrangeGetAttr = …;
static const char *const sameVariadicSizeValueRangeCalcCode = …;
static const char *const attrSizedSegmentValueRangeCalcCode = …;
static const char *const adapterSegmentSizeAttrInitCode = …;
static const char *const adapterSegmentSizeAttrInitCodeProperties = …;
static const char *const opSegmentSizeAttrInitCode = …;
static const char *const variadicOfVariadicAdaptorCalcCode = …;
static const char *const valueRangeReturnCode = …;
static const char *const parseTextualSegmentSizeFormat = …;
static const char *const printTextualSegmentSize = …;
static const char *const readBytecodeSegmentSizeNative = …;
static const char *const readBytecodeSegmentSizeLegacy = …;
static const char *const writeBytecodeSegmentSizeNative = …;
static const char *const writeBytecodeSegmentSizeLegacy = …;
static const char *const opCommentHeader = …;
static std::string replaceAllSubstrs(std::string str, const std::string &match,
const std::string &substitute) { … }
static inline bool hasStringAttribute(const Record &record,
StringRef fieldName) { … }
static std::string getArgumentName(const Operator &op, int index) { … }
static bool canUseUnwrappedRawValue(const tblgen::Attribute &attr) { … }
static std::string constBuildAttrFromParam(const tblgen::Attribute &attr,
FmtContext &fctx,
StringRef paramName) { … }
namespace {
struct AttributeMetadata { … };
class OpOrAdaptorHelper { … };
}
void OpOrAdaptorHelper::computeAttrMetadata() { … }
namespace {
class OpEmitter { … };
}
static void populateSubstitutions(const OpOrAdaptorHelper &emitHelper,
FmtContext &ctx) { … }
static void genNativeTraitAttrVerifier(MethodBody &body,
const OpOrAdaptorHelper &emitHelper) { … }
static bool canEmitAttrVerifier(Attribute attr, bool isEmittingForOp) { … }
static void
genAttributeVerifier(const OpOrAdaptorHelper &emitHelper, FmtContext &ctx,
MethodBody &body,
const StaticVerifierFunctionEmitter &staticVerifierEmitter,
bool useProperties) { … }
static std::string formatExtraDeclarations(const Operator &op) { … }
static std::string formatExtraDefinitions(const Operator &op) { … }
OpEmitter::OpEmitter(const Operator &op,
const StaticVerifierFunctionEmitter &staticVerifierEmitter)
: … { … }
void OpEmitter::emitDecl(
const Operator &op, raw_ostream &os,
const StaticVerifierFunctionEmitter &staticVerifierEmitter) { … }
void OpEmitter::emitDef(
const Operator &op, raw_ostream &os,
const StaticVerifierFunctionEmitter &staticVerifierEmitter) { … }
void OpEmitter::emitDecl(raw_ostream &os) { … }
void OpEmitter::emitDef(raw_ostream &os) { … }
static void errorIfPruned(size_t line, Method *m, const Twine &methodName,
const Operator &op) { … }
#define ERROR_IF_PRUNED(M, N, O) …
void OpEmitter::genAttrNameGetters() { … }
template <typename OpClassOrAdaptor>
static void emitPropGetter(OpClassOrAdaptor &opClass, const Operator &op,
StringRef name, const Property &prop) { … }
template <typename OpClassOrAdaptor>
static void emitAttrGetterWithReturnType(FmtContext &fctx,
OpClassOrAdaptor &opClass,
const Operator &op, StringRef name,
Attribute attr) { … }
void OpEmitter::genPropertiesSupport() { … }
void OpEmitter::genPropertiesSupportForBytecode(
ArrayRef<ConstArgument> attrOrProperties) { … }
void OpEmitter::genPropGetters() { … }
void OpEmitter::genPropSetters() { … }
void OpEmitter::genAttrGetters() { … }
void OpEmitter::genAttrSetters() { … }
void OpEmitter::genOptionalAttrRemovers() { … }
template <typename RangeT>
static void generateValueRangeStartAndEnd(
Class &opClass, bool isGenericAdaptorBase, StringRef methodName,
int numVariadic, int numNonVariadic, StringRef rangeSizeCall,
bool hasAttrSegmentSize, StringRef sizeAttrInit, RangeT &&odsValues) { … }
static std::string generateTypeForGetter(const NamedTypeConstraint &value) { … }
static void
generateNamedOperandGetters(const Operator &op, Class &opClass,
Class *genericAdaptorBase, StringRef sizeAttrInit,
StringRef rangeType, StringRef rangeElementType,
StringRef rangeBeginCall, StringRef rangeSizeCall,
StringRef getOperandCallPattern) { … }
void OpEmitter::genNamedOperandGetters() { … }
void OpEmitter::genNamedOperandSetters() { … }
void OpEmitter::genNamedResultGetters() { … }
void OpEmitter::genNamedRegionGetters() { … }
void OpEmitter::genNamedSuccessorGetters() { … }
static bool canGenerateUnwrappedBuilder(const Operator &op) { … }
static bool canInferType(const Operator &op) { … }
void OpEmitter::genSeparateArgParamBuilder() { … }
void OpEmitter::genUseOperandAsResultTypeCollectiveParamBuilder() { … }
void OpEmitter::genPopulateDefaultAttributes() { … }
void OpEmitter::genInferredTypeCollectiveParamBuilder() { … }
void OpEmitter::genUseOperandAsResultTypeSeparateParamBuilder() { … }
void OpEmitter::genUseAttrAsResultTypeBuilder() { … }
static SmallVector<MethodParameter>
getBuilderSignature(const Builder &builder) { … }
void OpEmitter::genBuilder() { … }
void OpEmitter::genCollectiveParamBuilder() { … }
void OpEmitter::buildParamList(SmallVectorImpl<MethodParameter> ¶mList,
llvm::StringSet<> &inferredAttributes,
SmallVectorImpl<std::string> &resultTypeNames,
TypeParamKind typeParamKind,
AttrParamKind attrParamKind) { … }
void OpEmitter::genCodeForAddingArgAndRegionForBuilder(
MethodBody &body, llvm::StringSet<> &inferredAttributes,
bool isRawValueAttr) { … }
void OpEmitter::genCanonicalizerDecls() { … }
void OpEmitter::genFolderDecls() { … }
void OpEmitter::genOpInterfaceMethods(const tblgen::InterfaceTrait *opTrait) { … }
Method *OpEmitter::genOpInterfaceMethod(const InterfaceMethod &method,
bool declaration) { … }
void OpEmitter::genOpInterfaceMethods() { … }
void OpEmitter::genSideEffectInterfaceMethods() { … }
void OpEmitter::genTypeInterfaceMethods() { … }
void OpEmitter::genParser() { … }
void OpEmitter::genPrinter() { … }
void OpEmitter::genVerifier() { … }
void OpEmitter::genCustomVerifier() { … }
void OpEmitter::genOperandResultVerifier(MethodBody &body,
Operator::const_value_range values,
StringRef valueKind) { … }
void OpEmitter::genRegionVerifier(MethodBody &body) { … }
void OpEmitter::genSuccessorVerifier(MethodBody &body) { … }
static void addSizeCountTrait(OpClass &opClass, StringRef traitKind,
int numTotal, int numVariadic) { … }
void OpEmitter::genTraits() { … }
void OpEmitter::genOpNameGetter() { … }
void OpEmitter::genOpAsmInterface() { … }
namespace {
class OpOperandAdaptorEmitter { … };
}
OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
const Operator &op,
const StaticVerifierFunctionEmitter &staticVerifierEmitter)
: … { … }
void OpOperandAdaptorEmitter::addVerification() { … }
void OpOperandAdaptorEmitter::emitDecl(
const Operator &op,
const StaticVerifierFunctionEmitter &staticVerifierEmitter,
raw_ostream &os) { … }
void OpOperandAdaptorEmitter::emitDef(
const Operator &op,
const StaticVerifierFunctionEmitter &staticVerifierEmitter,
raw_ostream &os) { … }
static void
emitOpClasses(const RecordKeeper &records,
const std::vector<const Record *> &defs, raw_ostream &os,
const StaticVerifierFunctionEmitter &staticVerifierEmitter,
bool emitDecl) { … }
static void emitOpClassDecls(const RecordKeeper &records,
const std::vector<const Record *> &defs,
raw_ostream &os) { … }
static void emitOpClassDefs(const RecordKeeper &records,
ArrayRef<const Record *> defs, raw_ostream &os,
StringRef constraintPrefix = "") { … }
static bool emitOpDecls(const RecordKeeper &records, raw_ostream &os) { … }
static void emitOpDefShard(const RecordKeeper &records,
ArrayRef<const Record *> defs,
const Dialect &dialect, unsigned shardIndex,
unsigned shardCount, raw_ostream &os) { … }
static bool emitOpDefs(const RecordKeeper &records, raw_ostream &os) { … }
static mlir::GenRegistration
genOpDecls("gen-op-decls", "Generate op declarations",
[](const RecordKeeper &records, raw_ostream &os) { … });
static mlir::GenRegistration genOpDefs("gen-op-defs", "Generate op definitions",
[](const RecordKeeper &records,
raw_ostream &os) { … });