15#include "llvm/ADT/TypeSwitch.h"
19#include "mlir/Dialect/Complex/IR/ComplexOpsDialect.cpp.inc"
27 bool isLegalToInline(Operation *, Region *,
bool, IRMapping &)
const final {
33void complex::ComplexDialect::initialize() {
36#include "mlir/Dialect/Complex/IR/ComplexOps.cpp.inc"
39#define GET_ATTRDEF_LIST
40#include "mlir/Dialect/Complex/IR/ComplexAttributes.cpp.inc"
42 declarePromisedInterface<ConvertToLLVMPatternInterface, ComplexDialect>();
43 addInterfaces<ComplexInlinerInterface>();
50 if (complex::ConstantOp::isBuildableWith(value, type)) {
51 return complex::ConstantOp::create(builder, loc, type,
52 llvm::cast<ArrayAttr>(value));
54 return arith::ConstantOp::materialize(builder, value, type, loc);
57#define GET_ATTRDEF_CLASSES
58#include "mlir/Dialect/Complex/IR/ComplexAttributes.cpp.inc"
60LogicalResult complex::NumberAttr::verify(
62 ::llvm::APFloat real, ::llvm::APFloat imag,
::mlir::Type type) {
64 if (!llvm::isa<ComplexType>(type))
65 return emitError() <<
"complex attribute must be a complex type.";
67 Type elementType = llvm::cast<ComplexType>(type).getElementType();
68 if (!llvm::isa<FloatType>(elementType))
70 <<
"element type of the complex attribute must be float like type.";
72 const auto &typeFloatSemantics =
73 llvm::cast<FloatType>(elementType).getFloatSemantics();
74 if (&real.getSemantics() != &typeFloatSemantics)
76 <<
"type doesn't match the type implied by its `real` value";
77 if (&imag.getSemantics() != &typeFloatSemantics)
79 <<
"type doesn't match the type implied by its `imag` value";
84void complex::NumberAttr::print(
AsmPrinter &printer)
const {
85 printer <<
"<:" << llvm::cast<ComplexType>(
getType()).getElementType() <<
" "
86 << getReal() <<
", " << getImag() <<
">";
97 return NumberAttr::get(ComplexType::get(type), real, imag);
static bool isLegalToInline(InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, IRMapping &valueMapping)
Utility to check that all of the operations within 'src' can be inlined.
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual ParseResult parseColon()=0
Parse a : token.
virtual ParseResult parseGreater()=0
Parse a '>' token.
virtual ParseResult parseType(Type &result)=0
Parse a type.
virtual ParseResult parseComma()=0
Parse a , token.
virtual ParseResult parseFloat(double &result)=0
Parse a floating point value from the stream.
This base class exposes generic asm printer hooks, usable across the various derived printers.
Attributes are known-constant values of operations.
This is the interface that must be implemented by the dialects of operations to be inlined.
DialectInlinerInterface(Dialect *dialect)
This class represents a diagnostic that is inflight and set to be reported.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
Operation is the basic unit of execution within MLIR.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
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.