32 Type &produceTokenType) {
51 if (failed(parser.
parseType(produceTokenType)))
62 Type produceTokenType) {
63 if (consumeTokens.empty() && !produceTokenType)
67 if (consumeTokens.empty())
71 if (produceTokenType) {
117 StringAttr &symVisibilityAttr) {
118 StringRef symVisibility;
120 {
"public",
"private",
"nested"});
121 if (symVisibility.empty())
122 return parser.emitError(parser.getCurrentLocation())
123 <<
"expected 'public', 'private', or 'nested'";
124 if (!symVisibility.empty())
125 symVisibilityAttr = parser.getBuilder().getStringAttr(symVisibility);
130 StringAttr symVisibilityAttr) {
131 if (!symVisibilityAttr)
134 p << symVisibilityAttr.getValue();
141 #define GET_OP_CLASSES
142 #include "mlir/Dialect/MLProgram/IR/MLProgramOps.cpp.inc"
155 parser, result,
false,
156 getFunctionTypeAttrName(result.
name), buildFuncType,
157 getArgAttrsAttrName(result.
name), getResAttrsAttrName(result.
name));
162 p, *
this,
false, getFunctionTypeAttrName(),
163 getArgAttrsAttrName(), getResAttrsAttrName());
171 if (!getIsMutable() && !getValue())
172 return emitOpError() <<
"immutable global must have an initial value";
181 for (
auto *parent = getOperation()->getParentOp(); parent;
182 parent = parent->getParentOp()) {
184 parent, getGlobalAttr())) {
193 GlobalOp referrent = getGlobalOp(symbolTable);
195 return emitOpError() <<
"undefined global: " << getGlobal();
197 if (referrent.getType() != getResult().
getType()) {
198 return emitOpError() <<
"cannot load from global typed "
199 << referrent.getType() <<
" as "
200 << getResult().getType();
212 getOperation()->getParentOp(), getGlobalAttr());
217 GlobalOp referrent = getGlobalOp(symbolTable);
219 return emitOpError() <<
"undefined global: " << getGlobal();
221 if (referrent.getIsMutable())
222 return emitOpError() <<
"cannot load as const from mutable global "
225 if (referrent.getType() != getResult().
getType())
226 return emitOpError() <<
"cannot load from global typed "
227 << referrent.getType() <<
" as "
228 << getResult().getType();
239 getOperation()->getParentOp(), getGlobalAttr());
244 GlobalOp referrent = getGlobalOp(symbolTable);
246 return emitOpError() <<
"undefined global: " << getGlobal();
248 if (referrent.getType() != getResult().
getType()) {
249 return emitOpError() <<
"cannot load from global typed "
250 << referrent.getType() <<
" as "
251 << getResult().getType();
262 for (
auto *parent = getOperation()->getParentOp(); parent;) {
264 parent, getGlobalAttr())) {
267 parent = parent->getParentOp();
274 GlobalOp referrent = getGlobalOp(symbolTable);
276 return emitOpError() <<
"undefined global: " << getGlobal();
278 if (!referrent.getIsMutable()) {
279 return emitOpError() <<
"cannot store to an immutable global "
283 if (referrent.getType() != getValue().
getType()) {
284 return emitOpError() <<
"cannot store to a global typed "
285 << referrent.getType() <<
" from "
286 << getValue().getType();
298 getOperation()->getParentOp(), getGlobalAttr());
303 GlobalOp referrent = getGlobalOp(symbolTable);
305 return emitOpError() <<
"undefined global: " << getGlobal();
307 if (!referrent.getIsMutable()) {
308 return emitOpError() <<
"cannot store to an immutable global "
312 if (referrent.getType() != getValue().
getType()) {
313 return emitOpError() <<
"cannot store to a global typed "
314 << referrent.getType() <<
" from "
315 << getValue().getType();
332 parser, result,
false,
333 getFunctionTypeAttrName(result.
name), buildFuncType,
334 getArgAttrsAttrName(result.
name), getResAttrsAttrName(result.
name));
339 p, *
this,
false, getFunctionTypeAttrName(),
340 getArgAttrsAttrName(), getResAttrsAttrName());
348 auto function = cast<SubgraphOp>((*this)->getParentOp());
351 const auto &results =
function.getFunctionType().getResults();
352 if (getNumOperands() != results.size())
353 return emitOpError(
"has ")
354 << getNumOperands() <<
" operands, but enclosing function (@"
355 <<
function.getName() <<
") outputs " << results.size();
357 for (
unsigned i = 0, e = results.size(); i != e; ++i)
358 if (getOperand(i).
getType() != results[i])
359 return emitError() <<
"type of output operand " << i <<
" ("
360 << getOperand(i).getType()
361 <<
") doesn't match function result type ("
363 <<
" in function @" <<
function.getName();
373 auto function = cast<FuncOp>((*this)->getParentOp());
376 const auto &results =
function.getFunctionType().getResults();
377 if (getNumOperands() != results.size())
378 return emitOpError(
"has ")
379 << getNumOperands() <<
" operands, but enclosing function (@"
380 <<
function.getName() <<
") returns " << results.size();
382 for (
unsigned i = 0, e = results.size(); i != e; ++i)
383 if (getOperand(i).
getType() != results[i])
384 return emitError() <<
"type of return operand " << i <<
" ("
385 << getOperand(i).getType()
386 <<
") doesn't match function result type ("
388 <<
" in function @" <<
function.getName();
static void printTypedInitialValue(OpAsmPrinter &p, Operation *op, TypeAttr type, Attribute attr)
static void printTokenOrdering(OpAsmPrinter &p, Operation *op, OperandRange consumeTokens, Type produceTokenType)
static void printSymbolVisibility(OpAsmPrinter &p, Operation *op, StringAttr symVisibilityAttr)
static ParseResult parseTypedInitialValue(OpAsmParser &parser, TypeAttr &typeAttr, Attribute &attr)
some.op custom<TypeOrAttr>($type, $attr)
static ParseResult parseTokenOrdering(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &consumeTokens, Type &produceTokenType)
Parse and print an ordering clause for a variadic of consuming tokens and an producing token.
static ParseResult parseSymbolVisibility(OpAsmParser &parser, StringAttr &symVisibilityAttr)
some.op custom<SymbolVisibility>($sym_visibility) $sym_name -> some.op public @foo some....
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual ParseResult parseColonType(Type &result)=0
Parse a colon followed by a type.
virtual ParseResult parseArrow()=0
Parse a '->' token.
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseType(Type &result)=0
Parse a type.
virtual ParseResult parseOptionalLParen()=0
Parse a ( token if present.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
virtual void printType(Type type)
virtual void printAttribute(Attribute attr)
Attributes are known-constant values of operations.
This class is a general helper class for creating context-global objects like types,...
FunctionType getFunctionType(TypeRange inputs, TypeRange results)
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual ParseResult parseOperandList(SmallVectorImpl< UnresolvedOperand > &result, Delimiter delimiter=Delimiter::None, bool allowResultNumber=true, int requiredOperandCount=-1)=0
Parse zero or more SSA comma-separated operand references with a specified surrounding delimiter,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
void printOperands(const ContainerType &container)
Print a comma separated list of operands.
This class implements the operand iterators for the Operation class.
Operation is the basic unit of execution within MLIR.
This class represents a collection of SymbolTables.
Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
A named class for passing around the variadic flag.
void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic, StringRef typeAttrName, StringAttr argAttrsName, StringAttr resAttrsName)
Printer implementation for function-like operations.
ParseResult parseFunctionOp(OpAsmParser &parser, OperationState &result, bool allowVariadic, StringAttr typeAttrName, FuncTypeBuilder funcTypeBuilder, StringAttr argAttrsName, StringAttr resAttrsName)
Parser implementation for function-like operations.
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
This represents an operation in an abstracted form, suitable for use with the builder APIs.