12#include "llvm/ADT/StringExtras.h"
13#include "llvm/ADT/TypeSwitch.h"
27 !(llvm::isa<IntegerType, FloatType, VectorType>(type) ||
28 (llvm::isa<PtrLikeTypeInterface>(type) &&
29 !llvm::isa<LLVMPointerType>(type))))
37 .Case<LLVMVoidType>([&](
Type) {
return "void"; })
38 .Case<LLVMPPCFP128Type>([&](
Type) {
return "ppc_fp128"; })
39 .Case<LLVMTokenType>([&](
Type) {
return "token"; })
40 .Case<LLVMLabelType>([&](
Type) {
return "label"; })
41 .Case<LLVMMetadataType>([&](
Type) {
return "metadata"; })
42 .Case<LLVMFunctionType>([&](
Type) {
return "func"; })
43 .Case<LLVMPointerType>([&](
Type) {
return "ptr"; })
44 .Case<LLVMArrayType>([&](
Type) {
return "array"; })
45 .Case<LLVMStructType>([&](
Type) {
return "struct"; })
46 .Case<LLVMTargetExtType>([&](
Type) {
return "target"; })
47 .Case<LLVMX86AMXType>([&](
Type) {
return "x86_amx"; })
48 .DefaultUnreachable(
"unexpected 'llvm' type kind");
53void LLVMStructType::print(
AsmPrinter &printer)
const {
54 FailureOr<AsmPrinter::CyclicPrintReset> cyclicPrint;
61 llvm::printEscapedString(getName(), printer.
getStream());
72 if (isIdentified() && isOpaque()) {
82 llvm::interleaveComma(getBody(), printer.
getStream(),
83 [&](
Type subtype) { dispatchPrint(printer, subtype); });
99 printer <<
"<<NULL-TYPE>>";
106 .Case<LLVMPointerType, LLVMArrayType, LLVMFunctionType, LLVMTargetExtType,
107 LLVMStructType>([&](
auto type) { type.
print(printer); });
121 for (
Type t : subtypes) {
122 if (!LLVMStructType::isValidElementType(t)) {
124 <<
"invalid LLVM structure element type: " << t;
125 return LLVMStructType();
129 if (succeeded(type.setBody(subtypes, isPacked)))
133 <<
"identified type already used with a different body";
134 return LLVMStructType();
146 return LLVMStructType();
156 auto type = LLVMStructType::getIdentifiedChecked(
161 "struct without a body only allowed in a recursive struct");
168 return LLVMStructType();
175 return parser.
emitError(kwLoc,
"only identified structs can be opaque"),
178 return LLVMStructType();
179 auto type = LLVMStructType::getOpaqueChecked(
181 if (!type.isOpaque()) {
182 parser.
emitError(kwLoc,
"redeclaring defined struct as opaque");
183 return LLVMStructType();
188 FailureOr<AsmParser::CyclicParseReset> cyclicParse;
193 if (
failed(cyclicParse)) {
195 "identifier already used for an enclosing struct");
203 return LLVMStructType();
208 return LLVMStructType();
210 return LLVMStructType::getLiteralChecked([loc] {
return emitError(loc); },
212 auto type = LLVMStructType::getIdentifiedChecked(
224 return LLVMStructType();
225 subtypes.push_back(type);
229 return LLVMStructType();
233 return LLVMStructType::getLiteralChecked(
235 auto type = LLVMStructType::getIdentifiedChecked(
251 if (failed(
result.value()))
254 parser.
emitError(keyLoc) <<
"unexpected type, expected keyword";
267 .Case(
"void", [&] {
return LLVMVoidType::get(ctx); })
268 .Case(
"ppc_fp128", [&] {
return LLVMPPCFP128Type::get(ctx); })
269 .Case(
"token", [&] {
return LLVMTokenType::get(ctx); })
270 .Case(
"label", [&] {
return LLVMLabelType::get(ctx); })
271 .Case(
"metadata", [&] {
return LLVMMetadataType::get(ctx); })
272 .Case(
"func", [&] {
return LLVMFunctionType::parse(parser); })
273 .Case(
"ptr", [&] {
return LLVMPointerType::parse(parser); })
274 .Case(
"array", [&] {
return LLVMArrayType::parse(parser); })
275 .Case(
"struct", [&] {
return LLVMStructType::parse(parser); })
276 .Case(
"target", [&] {
return LLVMTargetExtType::parse(parser); })
277 .Case(
"x86_amx", [&] {
return LLVMX86AMXType::get(ctx); })
279 parser.
emitError(keyLoc) <<
"unknown LLVM type: " << key;
287 return success(type !=
nullptr);
297 parser.
emitError(loc) <<
"unexpected type, expected keyword";
static ParseResult dispatchParse(AsmParser &parser, Type &type)
Helper to use in parse lists.
static void dispatchPrint(AsmPrinter &printer, Type type)
If the given type is compatible with the LLVM dialect, prints it using internal functions to avoid ge...
static LLVMStructType trySetStructBody(LLVMStructType type, ArrayRef< Type > subtypes, bool isPacked, AsmParser &parser, SMLoc subtypesLoc)
Attempts to set the body of an identified structure type.
static StringRef getTypeKeyword(Type type)
Returns the keyword to use for the given type.
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
virtual OptionalParseResult parseOptionalType(Type &result)=0
Parse an optional type.
MLIRContext * getContext() const
virtual Location getEncodedSourceLoc(SMLoc loc)=0
Re-encode the given source location as an MLIR location and return it.
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseOptionalRParen()=0
Parse a ) token if present.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual ParseResult parseOptionalGreater()=0
Parse a '>' token if present.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseOptionalComma()=0
Parse a , token if present.
virtual ParseResult parseOptionalString(std::string *string)=0
Parse a quoted string token if present.
FailureOr< CyclicParseReset > tryStartCyclicParse(AttrOrTypeT attrOrType)
Attempts to start a cyclic parsing region for attrOrType.
virtual ParseResult parseGreater()=0
Parse a '>' token.
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseComma()=0
Parse a , token.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
This base class exposes generic asm printer hooks, usable across the various derived printers.
virtual void printType(Type type)
FailureOr< CyclicPrintReset > tryStartCyclicPrint(AttrOrTypeT attrOrType)
Attempts to start a cyclic printing region for attrOrType.
virtual raw_ostream & getStream() const
Return the raw output stream used by this printer.
The DialectAsmParser has methods for interacting with the asm parser when parsing attributes and type...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext * getContext() const
Return the context this location is uniqued in.
MLIRContext is the top-level object for a collection of MLIR operations.
This class implements Optional functionality for ParseResult.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void print(raw_ostream &os) const
Print the current type.
void printType(Type type, AsmPrinter &printer)
Prints an LLVM Dialect type.
Type parseType(DialectAsmParser &parser)
Parses an LLVM dialect type.
void printPrettyLLVMType(AsmPrinter &p, Type type)
Print any MLIR type or a concise syntax for LLVM types.
ParseResult parsePrettyLLVMType(AsmParser &p, Type &type)
Parse any MLIR type or a concise syntax for LLVM types.
bool isCompatibleOuterType(Type type)
Returns true if the given outer type is compatible with the LLVM dialect without checking its potenti...
bool isCompatibleType(Type type)
Returns true if the given type is compatible with the LLVM dialect.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::TypeSwitch< T, ResultT > TypeSwitch
llvm::StringSwitch< T, R > StringSwitch
llvm::function_ref< Fn > function_ref