#include "OpFormatGen.h"
#include "FormatGen.h"
#include "OpClass.h"
#include "mlir/Support/LLVM.h"
#include "mlir/TableGen/Class.h"
#include "mlir/TableGen/Format.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"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/TableGen/Record.h"
#define DEBUG_TYPE …
usingnamespacemlir;
usingnamespacemlir::tblgen;
formatv;
Record;
StringMap;
namespace {
template <typename VarT, VariableElement::Kind VariableKind>
class OpVariableElement : public VariableElementBase<VariableKind> { … };
struct AttributeVariable
: public OpVariableElement<NamedAttribute, VariableElement::Attribute> { … };
OperandVariable;
ResultVariable;
RegionVariable;
SuccessorVariable;
PropertyVariable;
struct AttributeLikeVariable : public VariableElement { … };
}
namespace {
OperandsDirective;
ResultsDirective;
RegionsDirective;
SuccessorsDirective;
class AttrDictDirective
: public DirectiveElementBase<DirectiveElement::AttrDict> { … };
class PropDictDirective
: public DirectiveElementBase<DirectiveElement::PropDict> { … };
class FunctionalTypeDirective
: public DirectiveElementBase<DirectiveElement::FunctionalType> { … };
class TypeDirective : public DirectiveElementBase<DirectiveElement::Type> { … };
class OIListElement : public DirectiveElementBase<DirectiveElement::OIList> { … };
}
namespace {
ConstArgument;
struct OperationFormat { … };
}
static bool canFormatEnumAttr(const NamedAttribute *attr) { … }
static bool shouldFormatSymbolNameAttr(const NamedAttribute *attr) { … }
const char *const attrParserCode = …;
const char *const genericAttrParserCode = …;
const char *const optionalAttrParserCode = …;
const char *const symbolNameAttrParserCode = …;
const char *const optionalSymbolNameAttrParserCode = …;
const char *const enumAttrParserCode = …;
const char *const propertyParserCode = …;
const char *const optionalPropertyParserCode = …;
const char *const variadicOperandParserCode = …;
const char *const optionalOperandParserCode = …;
const char *const operandParserCode = …;
const char *const variadicOfVariadicOperandParserCode = …;
const char *const variadicOfVariadicTypeParserCode = …;
const char *const variadicTypeParserCode = …;
const char *const optionalTypeParserCode = …;
const char *const typeParserCode = …;
const char *const qualifiedTypeParserCode = …;
const char *const functionalTypeParserCode = …;
const char *const inferReturnTypesParserCode = …;
const char *regionListParserCode = …;
const char *regionListEnsureTerminatorParserCode = …;
const char *regionListEnsureSingleBlockParserCode = …;
const char *optionalRegionParserCode = …;
const char *regionParserCode = …;
const char *regionEnsureTerminatorParserCode = …;
const char *regionEnsureSingleBlockParserCode = …;
const char *successorListParserCode = …;
const char *successorParserCode = …;
const char *oilistParserCode = …;
namespace {
enum class ArgumentLengthKind { … };
}
static ArgumentLengthKind
getArgumentLengthKind(const NamedTypeConstraint *var) { … }
static StringRef getTypeListName(FormatElement *arg,
ArgumentLengthKind &lengthKind) { … }
static void genLiteralParser(StringRef value, MethodBody &body) { … }
static void genElementParserStorage(FormatElement *element, const Operator &op,
MethodBody &body) { … }
static void genCustomParameterParser(FormatElement *param, MethodBody &body) { … }
static void genCustomDirectiveParser(CustomDirective *dir, MethodBody &body,
bool useProperties,
StringRef opCppClassName,
bool isOptional = false) { … }
static void genEnumAttrParser(const NamedAttribute *var, MethodBody &body,
FmtContext &attrTypeCtx, bool parseAsOptional,
bool useProperties, StringRef opCppClassName) { … }
static void genPropertyParser(PropertyVariable *propVar, MethodBody &body,
StringRef opCppClassName,
bool requireParse = true) { … }
static void genAttrParser(AttributeVariable *attr, MethodBody &body,
FmtContext &attrTypeCtx, bool parseAsOptional,
bool useProperties, StringRef opCppClassName) { … }
static void genParsedAttrPropertiesSetter(OperationFormat &fmt, Operator &op,
OpClass &opClass) { … }
void OperationFormat::genParser(Operator &op, OpClass &opClass) { … }
void OperationFormat::genElementParser(FormatElement *element, MethodBody &body,
FmtContext &attrTypeCtx,
GenContext genCtx) { … }
void OperationFormat::genParserTypeResolution(Operator &op, MethodBody &body) { … }
void OperationFormat::genParserOperandTypeResolution(
Operator &op, MethodBody &body,
function_ref<void(TypeResolution &, StringRef)> emitTypeResolver) { … }
void OperationFormat::genParserRegionResolution(Operator &op,
MethodBody &body) { … }
void OperationFormat::genParserSuccessorResolution(Operator &op,
MethodBody &body) { … }
void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
MethodBody &body) { … }
const char *regionSingleBlockImplicitTerminatorPrinterCode = …;
const char *enumAttrBeginPrinterCode = …;
static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
AttributeVariable &attrElement) { … }
static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
PropertyVariable &propElement) { … }
static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
MethodBody &body) { … }
static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
MethodBody &body, bool withKeyword) { … }
static void genLiteralPrinter(StringRef value, MethodBody &body,
bool &shouldEmitSpace, bool &lastWasPunctuation) { … }
static void genSpacePrinter(bool value, MethodBody &body, bool &shouldEmitSpace,
bool &lastWasPunctuation) { … }
static void genCustomDirectiveParameterPrinter(FormatElement *element,
const Operator &op,
MethodBody &body) { … }
static void genCustomDirectivePrinter(CustomDirective *customDir,
const Operator &op, MethodBody &body) { … }
static void genRegionPrinter(const Twine ®ionName, MethodBody &body,
bool hasImplicitTermTrait) { … }
static void genVariadicRegionPrinter(const Twine ®ionListName,
MethodBody &body,
bool hasImplicitTermTrait) { … }
static MethodBody &genTypeOperandPrinter(FormatElement *arg, const Operator &op,
MethodBody &body,
bool useArrayRef = true) { … }
static void genEnumAttrPrinter(const NamedAttribute *var, const Operator &op,
MethodBody &body) { … }
static void genOptionalGroupPrinterAnchor(FormatElement *anchor,
const Operator &op,
MethodBody &body) { … }
void collect(FormatElement *element,
SmallVectorImpl<VariableElement *> &variables) { … }
void OperationFormat::genElementPrinter(FormatElement *element,
MethodBody &body, Operator &op,
bool &shouldEmitSpace,
bool &lastWasPunctuation) { … }
void OperationFormat::genPrinter(Operator &op, OpClass &opClass) { … }
template <typename RangeT>
static auto findArg(RangeT &&range, StringRef name) { … }
namespace {
class OpFormatParser : public FormatParser { … };
}
LogicalResult OpFormatParser::verify(SMLoc loc,
ArrayRef<FormatElement *> elements) { … }
LogicalResult
OpFormatParser::verifyAttributes(SMLoc loc,
ArrayRef<FormatElement *> elements) { … }
static bool isOptionallyParsed(FormatElement *el) { … }
static std::optional<LogicalResult> checkRangeForElement(
FormatElement *base,
function_ref<bool(FormatElement *, FormatElement *)> isInvalid,
iterator_range<ArrayRef<FormatElement *>::iterator> elementRange,
FormatElement *optionalGuard = nullptr) { … }
static FailureOr<FormatElement *> verifyAdjacentElements(
function_ref<bool(FormatElement *)> isBase,
function_ref<bool(FormatElement *, FormatElement *)> isInvalid,
ArrayRef<FormatElement *> elements) { … }
LogicalResult
OpFormatParser::verifyAttributeColonType(SMLoc loc,
ArrayRef<FormatElement *> elements) { … }
LogicalResult
OpFormatParser::verifyAttrDictRegion(SMLoc loc,
ArrayRef<FormatElement *> elements) { … }
LogicalResult OpFormatParser::verifyOperands(
SMLoc loc, StringMap<TypeResolutionInstance> &variableTyResolver) { … }
LogicalResult OpFormatParser::verifyRegions(SMLoc loc) { … }
LogicalResult OpFormatParser::verifyResults(
SMLoc loc, StringMap<TypeResolutionInstance> &variableTyResolver) { … }
LogicalResult OpFormatParser::verifySuccessors(SMLoc loc) { … }
LogicalResult
OpFormatParser::verifyOIListElements(SMLoc loc,
ArrayRef<FormatElement *> elements) { … }
void OpFormatParser::handleAllTypesMatchConstraint(
ArrayRef<StringRef> values,
StringMap<TypeResolutionInstance> &variableTyResolver) { … }
void OpFormatParser::handleSameTypesConstraint(
StringMap<TypeResolutionInstance> &variableTyResolver,
bool includeResults) { … }
void OpFormatParser::handleTypesMatchConstraint(
StringMap<TypeResolutionInstance> &variableTyResolver, const Record &def) { … }
ConstArgument OpFormatParser::findSeenArg(StringRef name) { … }
FailureOr<FormatElement *>
OpFormatParser::parseVariableImpl(SMLoc loc, StringRef name, Context ctx) { … }
FailureOr<FormatElement *>
OpFormatParser::parseDirectiveImpl(SMLoc loc, FormatToken::Kind kind,
Context ctx) { … }
FailureOr<FormatElement *>
OpFormatParser::parseAttrDictDirective(SMLoc loc, Context context,
bool withKeyword) { … }
FailureOr<FormatElement *>
OpFormatParser::parsePropDictDirective(SMLoc loc, Context context) { … }
LogicalResult OpFormatParser::verifyCustomDirectiveArguments(
SMLoc loc, ArrayRef<FormatElement *> arguments) { … }
FailureOr<FormatElement *>
OpFormatParser::parseFunctionalTypeDirective(SMLoc loc, Context context) { … }
FailureOr<FormatElement *>
OpFormatParser::parseOperandsDirective(SMLoc loc, Context context) { … }
FailureOr<FormatElement *>
OpFormatParser::parseRegionsDirective(SMLoc loc, Context context) { … }
FailureOr<FormatElement *>
OpFormatParser::parseResultsDirective(SMLoc loc, Context context) { … }
FailureOr<FormatElement *>
OpFormatParser::parseSuccessorsDirective(SMLoc loc, Context context) { … }
FailureOr<FormatElement *>
OpFormatParser::parseOIListDirective(SMLoc loc, Context context) { … }
LogicalResult OpFormatParser::verifyOIListParsingElement(FormatElement *element,
SMLoc loc) { … }
FailureOr<FormatElement *> OpFormatParser::parseTypeDirective(SMLoc loc,
Context context) { … }
LogicalResult OpFormatParser::markQualified(SMLoc loc, FormatElement *element) { … }
FailureOr<FormatElement *>
OpFormatParser::parseTypeDirectiveOperand(SMLoc loc, bool isRefChild) { … }
LogicalResult OpFormatParser::verifyOptionalGroupElements(
SMLoc loc, ArrayRef<FormatElement *> elements, FormatElement *anchor) { … }
LogicalResult OpFormatParser::verifyOptionalGroupElement(SMLoc loc,
FormatElement *element,
bool isAnchor) { … }
void mlir::tblgen::generateOpFormat(const Operator &constOp, OpClass &opClass) { … }