13 #ifndef MLIR_IR_OPIMPLEMENTATION_H 14 #define MLIR_IR_OPIMPLEMENTATION_H 18 #include "llvm/ADT/Twine.h" 19 #include "llvm/Support/SMLoc.h" 20 #include "llvm/Support/raw_ostream.h" 36 virtual raw_ostream &
getStream()
const = 0;
42 template <
typename ContainerType>
48 template <
typename IteratorType>
53 for (++it; it != end; ++it) {
83 bool printBlockTerminators =
true) = 0;
103 bool wrapped = types.size() != 1 || types[0].isa<
FunctionType>();
149 template <
typename T,
150 typename std::enable_if<std::is_convertible<T &, ValueRange>::value &&
151 !std::is_convertible<T &, Value &>::value,
152 T>::type * =
nullptr>
171 template <
typename T,
typename std::enable_if<
172 !std::is_convertible<T &, Value &>::value &&
173 !std::is_convertible<T &, Type &>::value &&
174 !std::is_convertible<T &, Attribute &>::value &&
175 !std::is_convertible<T &, ValueRange>::value &&
176 !llvm::is_one_of<T, bool>::value,
177 T>::type * =
nullptr>
184 return p << (value ? StringRef(
"true") :
"false");
187 template <
typename IteratorT>
220 const Twine &message = {}) = 0;
224 virtual Builder &getBuilder()
const = 0;
228 virtual llvm::SMLoc getCurrentLocation() = 0;
230 *loc = getCurrentLocation();
235 virtual llvm::SMLoc getNameLoc()
const = 0;
282 auto loc = getCurrentLocation();
283 if (parseOptionalKeyword(keyword))
284 return emitError(loc,
"expected '") << keyword <<
"'" << msg;
290 auto loc = getCurrentLocation();
291 if (parseOptionalKeyword(keyword))
292 return emitError(loc,
"expected valid keyword");
297 virtual ParseResult parseOptionalKeyword(StringRef keyword) = 0;
300 virtual ParseResult parseOptionalKeyword(StringRef *keyword) = 0;
341 template <
typename AttrType>
355 template <
typename AttrType>
358 llvm::SMLoc loc = getCurrentLocation();
368 return emitError(loc,
"invalid kind of attribute specified");
390 if (
failed(parseOptionalSymbolName(result, attrName, attrs)))
392 <<
"expected valid '@'-identifier for symbol name";
399 parseOptionalSymbolName(
StringAttr &result, StringRef attrName,
435 int requiredOperandCount = -1,
439 return parseOperandList(result, -1, delimiter);
447 int requiredOperandCount = -1,
451 return parseTrailingOperandList(result, -1,
464 for (
auto elt : operands)
465 if (resolveOperand(elt, type, result))
476 if (operands.size() != types.size())
478 << operands.size() <<
" operands present, but expected " 481 for (
unsigned i = 0, e = operands.size(); i != e; ++i)
482 if (resolveOperand(operands[i], types[i], result))
509 bool enableNameShadowing =
false) = 0;
515 bool enableNameShadowing =
false) = 0;
527 int requiredOperandCount = -1,
532 return parseRegionArgumentList(result, -1,
563 llvm::SMLoc loc = getCurrentLocation();
567 if (parseColonType(type))
573 return emitError(loc,
"invalid kind of type specified");
595 result.push_back(type);
604 result.append(types.begin(), types.end());
613 int requiredOperandCount,
662 #include "mlir/IR/OpAsmInterface.h.inc" This is the representation of an operand reference.
Definition: OpImplementation.h:407
virtual ParseResult parseRegionArgumentList(SmallVectorImpl< OperandType > &result, Delimiter delimiter)
Definition: OpImplementation.h:530
Definition: InferTypeOpInterface.cpp:20
ParseResult resolveOperands(ArrayRef< OperandType > operands, ArrayRef< Type > types, llvm::SMLoc loc, SmallVectorImpl< Value > &result)
Definition: OpImplementation.h:473
Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context)
ParseResult resolveOperands(ArrayRef< OperandType > operands, Type type, SmallVectorImpl< Value > &result)
Definition: OpImplementation.h:462
ParseResult parseAttribute(AttrType &result, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
Parse an attribute of a specific kind and type.
Definition: OpImplementation.h:342
ParseResult addTypesToList(ArrayRef< Type > types, SmallVectorImpl< Type > &result)
Definition: OpImplementation.h:602
ParseResult parseTrailingOperandList(SmallVectorImpl< OperandType > &result, Delimiter delimiter)
Definition: OpImplementation.h:449
ParseResult parseAttribute(AttrType &result, Type type, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
Parse an attribute of a specific kind and type.
Definition: OpImplementation.h:356
Definition: Operation.h:27
void printFunctionalType(Operation *op)
Print the complete type of an operation in functional form.
Definition: OpImplementation.h:112
Definition: DialectInterface.h:27
Definition: Attributes.h:139
ParseResult parseKeyword(StringRef keyword, const Twine &msg="")
Parse a given keyword.
Definition: OpImplementation.h:281
Definition: Diagnostics.h:320
OpAsmPrinter()
Definition: OpImplementation.h:34
Block represents an ordered list of Operations.
Definition: Block.h:21
Definition: OpImplementation.h:625
virtual void shadowRegionArgs(Region ®ion, ValueRange namesToUse)=0
virtual void getAttributeAliases(SmallVectorImpl< std::pair< Attribute, StringRef >> &aliases) const
Definition: OpImplementation.h:640
bool failed(LogicalResult result)
Definition: LogicalResult.h:45
Function types map from a list of inputs to a list of results.
Definition: Types.h:190
Definition: OpImplementation.h:214
void printOperands(IteratorType it, IteratorType end)
Print a comma separated list of operands.
Definition: OpImplementation.h:49
virtual ~OpAsmPrinter()
Definition: AsmPrinter.cpp:50
ParseResult parseSymbolName(StringAttr &result, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
Definition: OpImplementation.h:388
unsigned number
Definition: OpImplementation.h:410
virtual void printSymbolName(StringRef symbolRef)=0
void printOperands(const ContainerType &container)
Print a comma separated list of operands.
Definition: OpImplementation.h:43
operand_range getNonSuccessorOperands()
Return the operands of this operation that are not successor arguments.
Definition: Operation.cpp:559
unsigned getNumResults()
Return the number of results held by this operation.
Definition: Operation.cpp:548
LogicalResult success(bool isSuccess=true)
Definition: LogicalResult.h:25
This class implements iteration on the types of a given range of values.
Definition: OperationSupport.h:540
LogicalResult failure(bool isFailure=true)
Definition: LogicalResult.h:32
virtual void printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true)=0
Prints a region.
OpListType::iterator iterator
Definition: Block.h:107
Type getType() const
Return the type of this value.
Definition: Value.cpp:34
virtual void printAffineMapOfSSAIds(AffineMapAttr mapAttr, ValueRange operands)=0
U dyn_cast() const
Definition: Types.h:258
Definition: Attributes.h:53
auto map(Fn fun, IterType begin, IterType end) -> SmallVector< typename std::result_of< Fn(decltype(*begin))>::type, 8 >
Map with iterators.
Definition: Functional.h:28
void interleaveComma(const Container &c, raw_ostream &os, UnaryFunctor each_fn)
Definition: STLExtras.h:81
ParseResult addTypeToList(Type type, SmallVectorImpl< Type > &result)
Definition: OpImplementation.h:594
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Definition: Operation.h:246
Definition: OpImplementation.h:32
Definition: Attributes.h:428
virtual raw_ostream & getStream() const =0
Type parseType(llvm::StringRef typeStr, MLIRContext *context)
ParseResult parseKeywordType(const char *keyword, Type &result)
Parse a keyword followed by a type.
Definition: OpImplementation.h:587
ParseResult parseOperandList(SmallVectorImpl< OperandType > &result, Delimiter delimiter)
Definition: OpImplementation.h:437
Delimiter
Definition: OpImplementation.h:418
Definition: Attributes.h:175
OpAsmDialectInterface(Dialect *dialect)
Definition: OpImplementation.h:628
ParseResult parseAttribute(Attribute &result, StringRef attrName, SmallVectorImpl< NamedAttribute > &attrs)
Definition: OpImplementation.h:335
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
Definition: Diagnostics.cpp:301
Definition: Builders.h:47
virtual void printAttribute(Attribute attr)=0
virtual void getAsmBlockArgumentNames(Block *block, OpAsmSetValueNameFn setNameFn) const
Definition: OpImplementation.h:653
U dyn_cast() const
Definition: Attributes.h:1347
virtual void printOperand(Value value)=0
Print implementations for various things an operation contains.
virtual void printOptionalAttrDictWithKeyword(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
ParseResult parseColonType(TypeType &result)
Parse a colon followed by a type of a specific kind, e.g. a FunctionType.
Definition: OpImplementation.h:562
llvm::SMLoc location
Definition: OpImplementation.h:408
virtual void getAsmResultNames(Operation *op, OpAsmSetValueNameFn setNameFn) const
Definition: OpImplementation.h:648
Definition: StandardTypes.h:63
void printOptionalArrowTypeList(ArrayRef< Type > types)
Print an optional arrow followed by a type list.
Definition: OpImplementation.h:99
virtual void printType(Type type)=0
raw_ostream & operator<<(raw_ostream &os, SubViewOp::Range &range)
Definition: Ops.cpp:2759
virtual void printGenericOp(Operation *op)=0
Print the entire operation with the default generic assembly form.
ParseResult parseKeyword(StringRef *keyword)
Parse a keyword into 'keyword'.
Definition: OpImplementation.h:289
bool isa() const
Definition: Types.h:254
virtual void getAttributeKindAliases(SmallVectorImpl< std::pair< unsigned, StringRef >> &aliases) const
Definition: OpImplementation.h:636
Definition: OpDefinition.h:36
virtual void printSuccessorAndUseList(Operation *term, unsigned index)=0
Definition: OperationSupport.h:640
StringRef name
Definition: OpImplementation.h:409
ParseResult getCurrentLocation(llvm::SMLoc *loc)
Definition: OpImplementation.h:229
result_type_range getResultTypes()
Definition: Operation.h:264
virtual void getTypeAliases(SmallVectorImpl< std::pair< Type, StringRef >> &aliases) const
Hook for defining Type aliases.
Definition: OpImplementation.h:644