50 return fir::ConvertOp::create(builder, loc, type, inputs[0]);
56 return fir::ConvertOp::create(builder, loc, type, inputs[0]);
69 if (
auto refTy = mlir::dyn_cast<fir::ReferenceType>(ty))
71 else if (
auto pointerTy = mlir::dyn_cast<fir::PointerType>(ty))
73 else if (
auto heapTy = mlir::dyn_cast<fir::HeapType>(ty))
75 else if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty))
77 else if (
auto boxTy = mlir::dyn_cast<fir::BoxType>(ty))
89 if (
auto refTy = mlir::dyn_cast<fir::ReferenceType>(ty))
91 else if (
auto pointerTy = mlir::dyn_cast<fir::PointerType>(ty))
93 else if (
auto heapTy = mlir::dyn_cast<fir::HeapType>(ty))
95 else if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty)) {
97 for (
auto shape : firShape)
108 if (!convertScalarTypesOnly) {
109 if (
auto refTy = mlir::dyn_cast<fir::ReferenceType>(type)) {
110 auto elTy = refTy.getElementType();
111 if (mlir::isa<fir::SequenceType>(elTy))
116 if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(type))
121 if (mlir::isa<fir::LogicalType>(type))
126 if (type.isUnsignedInteger())
129 if (mlir::isa<mlir::ComplexType>(type))
130 return convertComplexTypes;
132 if (mlir::isa<mlir::FunctionType>(type))
135 if (mlir::isa<mlir::TupleType>(type))
143 auto convertBaseType = [&](mlir::Type firTy) -> mlir::MemRefType {
144 if (
auto charTy = mlir::dyn_cast<fir::CharacterType>(firTy)) {
145 unsigned kind = charTy.getFKind();
146 unsigned bitWidth = kindMapping.getCharacterBitsize(kind);
147 mlir::Type elTy = mlir::IntegerType::get(charTy.getContext(), bitWidth);
149 if (charTy.hasConstantLen() && charTy.getLen() == 1) {
150 return mlir::MemRefType::get({}, elTy);
151 }
else if (charTy.hasConstantLen()) {
152 int64_t len = charTy.getLen();
153 return mlir::MemRefType::get({len}, elTy);
155 return mlir::MemRefType::get({mlir::ShapedType::kDynamic}, elTy);
159 if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(firTy)) {
160 auto elTy = seqTy.getElementType();
161 mlir::Type ty = convertType(elTy);
165 for (
auto it = firShape.rbegin(); it != firShape.rend(); ++it)
166 shape.push_back(*it);
168 assert(mlir::BaseMemRefType::isValidElementType(ty) &&
169 "got invalid memref element type from array fir type");
170 return mlir::MemRefType::get(shape, ty);
173 mlir::Type ty = convertType(firTy);
174 assert(mlir::BaseMemRefType::isValidElementType(ty) &&
175 "got invalid memref element type from scalar fir type");
176 return mlir::MemRefType::get({}, ty);
179 if (
auto refTy = mlir::dyn_cast<fir::ReferenceType>(firTy))
180 return convertBaseType(refTy.getElementType());
182 if (
auto pointerTy = mlir::dyn_cast<fir::PointerType>(firTy))
183 return convertBaseType(pointerTy.getElementType());
185 if (
auto heapTy = mlir::dyn_cast<fir::HeapType>(firTy))
186 return convertBaseType(heapTy.getElementType());
188 if (
auto boxTy = mlir::dyn_cast<fir::BoxType>(firTy)) {
189 auto elTy = boxTy.getElementType();
192 mlir::MemRefType dynTy = mlir::MemRefType::Builder(memRefTy).setLayout(
193 mlir::StridedLayoutAttr::get(
194 memRefTy.getContext(), mlir::ShapedType::kDynamic,
196 mlir::ShapedType::kDynamic)));
200 return convertBaseType(firTy);