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<LLVMLabelType>([&](
Type) {
return "label"; })
40 .Case<LLVMMetadataType>([&](
Type) {
return "metadata"; })
41 .Case<LLVMFunctionType>([&](
Type) {
return "func"; })
42 .Case<LLVMPointerType>([&](
Type) {
return "ptr"; })
43 .Case<LLVMArrayType>([&](
Type) {
return "array"; })
44 .Case<LLVMByteType>([&](
Type) {
return "byte"; })
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, LLVMByteType, LLVMFunctionType,
107 LLVMTargetExtType, LLVMStructType>(
108 [&](
auto type) { type.
print(printer); });
122 for (
Type t : subtypes) {
123 if (!LLVMStructType::isValidElementType(t)) {
125 <<
"invalid LLVM structure element type: " << t;
126 return LLVMStructType();
130 if (succeeded(type.setBody(subtypes, isPacked)))
134 <<
"identified type already used with a different body";
135 return LLVMStructType();
147 return LLVMStructType();
157 auto type = LLVMStructType::getIdentifiedChecked(
162 "struct without a body only allowed in a recursive struct");
169 return LLVMStructType();
176 return parser.
emitError(kwLoc,
"only identified structs can be opaque"),
179 return LLVMStructType();
180 auto type = LLVMStructType::getOpaqueChecked(
182 if (!type.isOpaque()) {
183 parser.
emitError(kwLoc,
"redeclaring defined struct as opaque");
184 return LLVMStructType();
189 FailureOr<AsmParser::CyclicParseReset> cyclicParse;
194 if (
failed(cyclicParse)) {
196 "identifier already used for an enclosing struct");
204 return LLVMStructType();
209 return LLVMStructType();
211 return LLVMStructType::getLiteralChecked([loc] {
return emitError(loc); },
213 auto type = LLVMStructType::getIdentifiedChecked(
225 return LLVMStructType();
226 subtypes.push_back(type);
230 return LLVMStructType();
234 return LLVMStructType::getLiteralChecked(
236 auto type = LLVMStructType::getIdentifiedChecked(
252 if (failed(
result.value()))
255 parser.
emitError(keyLoc) <<
"unexpected type, expected keyword";
268 .Case(
"void", [&] {
return LLVMVoidType::get(ctx); })
269 .Case(
"ppc_fp128", [&] {
return LLVMPPCFP128Type::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(
"byte", [&] {
return LLVMByteType::parse(parser); })
276 .Case(
"struct", [&] {
return LLVMStructType::parse(parser); })
277 .Case(
"target", [&] {
return LLVMTargetExtType::parse(parser); })
278 .Case(
"x86_amx", [&] {
return LLVMX86AMXType::get(ctx); })
280 parser.
emitError(keyLoc) <<
"unknown LLVM type: " << key;
288 return success(type !=
nullptr);
298 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