15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/TypeSwitch.h"
20 #include "mlir/Dialect/Complex/IR/ComplexOpsDialect.cpp.inc"
34 void complex::ComplexDialect::initialize() {
37 #include "mlir/Dialect/Complex/IR/ComplexOps.cpp.inc"
40 #define GET_ATTRDEF_LIST
41 #include "mlir/Dialect/Complex/IR/ComplexAttributes.cpp.inc"
43 declarePromisedInterface<ConvertToLLVMPatternInterface, ComplexDialect>();
44 addInterfaces<ComplexInlinerInterface>();
51 if (complex::ConstantOp::isBuildableWith(value, type)) {
52 return builder.
create<complex::ConstantOp>(loc, type,
53 llvm::cast<ArrayAttr>(value));
55 return arith::ConstantOp::materialize(builder, value, type, loc);
58 #define GET_ATTRDEF_CLASSES
59 #include "mlir/Dialect/Complex/IR/ComplexAttributes.cpp.inc"
63 ::llvm::APFloat real, ::llvm::APFloat imag, ::
mlir::Type type) {
65 if (!llvm::isa<ComplexType>(type))
66 return emitError() <<
"complex attribute must be a complex type.";
68 Type elementType = llvm::cast<ComplexType>(type).getElementType();
69 if (!llvm::isa<FloatType>(elementType))
71 <<
"element type of the complex attribute must be float like type.";
73 const auto &typeFloatSemantics =
74 llvm::cast<FloatType>(elementType).getFloatSemantics();
75 if (&real.getSemantics() != &typeFloatSemantics)
77 <<
"type doesn't match the type implied by its `real` value";
78 if (&imag.getSemantics() != &typeFloatSemantics)
80 <<
"type doesn't match the type implied by its `imag` value";
86 printer <<
"<:" << llvm::cast<ComplexType>(
getType()).getElementType() <<
" "
87 << getReal() <<
", " << getImag() <<
">";
static Operation * materializeConstant(Dialect *dialect, OpBuilder &builder, Attribute value, Type type, Location loc)
A utility function used to materialize a constant for a given attribute and type.
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.
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
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 is a utility class for mapping one set of IR entities to another.
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 * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
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,...