From 538552d9d02f1f2d2f80d0009beebf6972ac754d Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Thu, 27 Feb 2025 02:24:47 -0800 Subject: [PATCH] update codegen --- .../include/flang/Optimizer/Dialect/FIROps.h | 2 +- .../include/flang/Optimizer/Dialect/FIROps.td | 10 +- flang/lib/Lower/OpenMP/Utils.cpp | 10 +- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 253 +++++++++--------- flang/lib/Optimizer/Dialect/FIROps.cpp | 29 +- .../Optimizer/OpenMP/MapInfoFinalization.cpp | 9 +- flang/test/Fir/Todo/coordinate_of_2.fir | 3 +- flang/test/Fir/Todo/coordinate_of_3.fir | 3 +- .../Fir/convert-to-llvm-openmp-and-fir.fir | 37 ++- flang/test/Fir/convert-to-llvm.fir | 26 +- flang/test/Fir/field-index.fir | 9 +- flang/test/Fir/pdt.fir | 6 +- .../OpenMP/map-types-and-sizes.f90 | 11 +- flang/test/Lower/OpenMP/declare-mapper.f90 | 6 +- .../OpenMP/derived-type-allocatable-map.f90 | 27 +- ...p-map-info-finalization-implicit-field.fir | 2 +- 16 files changed, 223 insertions(+), 220 deletions(-) diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.h b/flang/include/flang/Optimizer/Dialect/FIROps.h index 6a4a9d7f37d27..ed301016ad01c 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.h +++ b/flang/include/flang/Optimizer/Dialect/FIROps.h @@ -51,6 +51,7 @@ struct DebuggingResource }; class CoordinateIndicesAdaptor; +using IntOrValue = llvm::PointerUnion; } // namespace fir @@ -60,7 +61,6 @@ class CoordinateIndicesAdaptor; namespace fir { class CoordinateIndicesAdaptor { public: - using IntOrValue = llvm::PointerUnion; using value_type = IntOrValue; CoordinateIndicesAdaptor(mlir::DenseI32ArrayAttr fieldIndices, diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index fabd672fd625f..c83c57186b46d 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -1748,10 +1748,16 @@ def fir_CoordinateOp : fir_Op<"coordinate_of", [NoMemoryEffect]> { Unlike LLVM's GEP instruction, one cannot stride over the outermost reference; therefore, the leading 0 index must be omitted. + This operation can be used to index derived type fields, in which case + the operand is the name of the index field. + ``` %i = ... : index %h = ... : !fir.heap> %p = fir.coordinate_of %h, %i : (!fir.heap>, index) -> !fir.ref + + %d = ... : !fir.ref> + %f = fir.coordinate_of %d, field2 : (!fir.ref>) -> !fir.ref ``` In the example, `%p` will be a pointer to the `%i`-th f32 value in the @@ -1772,7 +1778,9 @@ def fir_CoordinateOp : fir_Op<"coordinate_of", [NoMemoryEffect]> { let builders = [ OpBuilder<(ins "mlir::Type":$resultType, - "mlir::Value":$ref, "mlir::ValueRange":$coor)> + "mlir::Value":$ref, "mlir::ValueRange":$coor)>, + OpBuilder<(ins "mlir::Type":$resultType, + "mlir::Value":$ref, "llvm::ArrayRef":$coor)> ]; let extraClassDeclaration = [{ constexpr static int32_t kDynamicIndex = std::numeric_limits::min(); diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index fa1975dac789b..48bcf492fd368 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -354,14 +354,12 @@ mlir::Value createParentSymAndGenIntermediateMaps( // type. if (fir::RecordType recordType = mlir::dyn_cast( fir::unwrapPassByRefType(curValue.getType()))) { - mlir::Value idxConst = firOpBuilder.createIntegerConstant( - clauseLocation, firOpBuilder.getIndexType(), - indices[currentIndicesIdx]); - mlir::Type memberTy = - recordType.getTypeList().at(indices[currentIndicesIdx]).second; + fir::IntOrValue idxConst = mlir::IntegerAttr::get( + firOpBuilder.getI32Type(), indices[currentIndicesIdx]); + mlir::Type memberTy = recordType.getType(indices[currentIndicesIdx]); curValue = firOpBuilder.create( clauseLocation, firOpBuilder.getRefType(memberTy), curValue, - idxConst); + llvm::SmallVector{idxConst}); // Skip mapping and the subsequent load if we're the final member or not // a type with a descriptor such as a pointer/allocatable. If we're a diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index aaefe675730e1..a2743edd7844a 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -2653,57 +2653,78 @@ struct CoordinateOpConversion return mlir::isa(type); } - /// Check whether this form of `!fir.coordinate_of` is supported. These - /// additional checks are required, because we are not yet able to convert - /// all valid forms of `!fir.coordinate_of`. - /// TODO: Either implement the unsupported cases or extend the verifier - /// in FIROps.cpp instead. - static bool supportedCoordinate(mlir::Type type, mlir::ValueRange coors) { - const std::size_t numOfCoors = coors.size(); - std::size_t i = 0; - bool subEle = false; - bool ptrEle = false; - for (; i < numOfCoors; ++i) { - mlir::Value nxtOpnd = coors[i]; - if (auto arrTy = mlir::dyn_cast(type)) { - subEle = true; - i += arrTy.getDimension() - 1; - type = arrTy.getEleTy(); - } else if (auto recTy = mlir::dyn_cast(type)) { - subEle = true; - type = recTy.getType(getFieldNumber(recTy, nxtOpnd)); - } else if (auto tupTy = mlir::dyn_cast(type)) { - subEle = true; - type = tupTy.getType(getConstantIntValue(nxtOpnd)); - } else { - ptrEle = true; - } - } - if (ptrEle) - return (!subEle) && (numOfCoors == 1); - return subEle && (i >= numOfCoors); - } + // Helper structure to analyze the CoordinateOp path and decide if and how + // the GEP should be generated for it. + struct ShapeAnalysis { + bool hasKnownShape; + bool columnIsDeferred; + }; /// Walk the abstract memory layout and determine if the path traverses any /// array types with unknown shape. Return true iff all the array types have a /// constant shape along the path. - static bool arraysHaveKnownShape(mlir::Type type, mlir::ValueRange coors) { - for (std::size_t i = 0, sz = coors.size(); i < sz; ++i) { - mlir::Value nxtOpnd = coors[i]; + /// TODO: move the verification logic into the verifier. + static std::optional + arraysHaveKnownShape(mlir::Type type, fir::CoordinateOp coor) { + fir::CoordinateIndicesAdaptor indices = coor.getIndices(); + auto begin = indices.begin(); + bool hasKnownShape = true; + bool columnIsDeferred = false; + for (auto it = begin, end = indices.end(); it != end;) { if (auto arrTy = mlir::dyn_cast(type)) { - if (fir::sequenceWithNonConstantShape(arrTy)) - return false; - i += arrTy.getDimension() - 1; + bool addressingStart = (it == begin); + unsigned arrayDim = arrTy.getDimension(); + for (auto dimExtent : llvm::enumerate(arrTy.getShape())) { + if (dimExtent.value() == fir::SequenceType::getUnknownExtent()) { + hasKnownShape = false; + if (addressingStart && dimExtent.index() + 1 == arrayDim) { + // If this point was reached, the raws of the first array have + // constant extents. + columnIsDeferred = true; + } else { + // One of the array dimension that is not the column of the first + // array has dynamic extent. It will not possible to do + // code generation for the CoordinateOp if the base is not a + // fir.box containing the value of that extent. + return ShapeAnalysis{false, false}; + } + } + // There may be less operands than the array size if the + // fir.coordinate_of result is not an element but a sub-array. + if (it != end) + ++it; + } type = arrTy.getEleTy(); - } else if (auto strTy = mlir::dyn_cast(type)) { - type = strTy.getType(getFieldNumber(strTy, nxtOpnd)); + continue; + } + if (auto strTy = mlir::dyn_cast(type)) { + auto intAttr = llvm::dyn_cast(*it); + if (!intAttr) { + mlir::emitError(coor.getLoc(), + "expected field name in fir.coordinate_of"); + return std::nullopt; + } + type = strTy.getType(intAttr.getInt()); } else if (auto strTy = mlir::dyn_cast(type)) { - type = strTy.getType(getConstantIntValue(nxtOpnd)); - } else { - return true; + auto value = llvm::dyn_cast(*it); + if (!value) { + mlir::emitError( + coor.getLoc(), + "expected constant value to address tuple in fir.coordinate_of"); + return std::nullopt; + } + type = strTy.getType(getConstantIntValue(value)); + } else if (auto charType = mlir::dyn_cast(type)) { + // Addressing character in string. Fortran strings degenerate to arrays + // in LLVM, so they are handled like arrays of characters here. + if (charType.getLen() == fir::CharacterType::unknownLen()) + return ShapeAnalysis{false, true}; + type = fir::CharacterType::getSingleton(charType.getContext(), + charType.getFKind()); } + ++it; } - return true; + return ShapeAnalysis{hasKnownShape, columnIsDeferred}; } private: @@ -2754,9 +2775,11 @@ struct CoordinateOpConversion mlir::LLVM::IntegerOverflowFlags nsw = mlir::LLVM::IntegerOverflowFlags::nsw; - for (unsigned i = 1, last = operands.size(); i < last; ++i) { + int nextIndexValue = 1; + fir::CoordinateIndicesAdaptor indices = coor.getIndices(); + for (auto it = indices.begin(), end = indices.end(); it != end;) { if (auto arrTy = mlir::dyn_cast(cpnTy)) { - if (i != 1) + if (it != indices.begin()) TODO(loc, "fir.array nested inside other array and/or derived type"); // Applies byte strides from the box. Ignore lower bound from box // since fir.coordinate_of indexes are zero based. Lowering takes care @@ -2764,26 +2787,31 @@ struct CoordinateOpConversion // types and non contiguous arrays. auto idxTy = lowerTy().indexType(); mlir::Value off = genConstantIndex(loc, idxTy, rewriter, 0); - for (unsigned index = i, lastIndex = i + arrTy.getDimension(); - index < lastIndex; ++index) { - mlir::Value stride = getStrideFromBox(loc, boxTyPair, operands[0], - index - i, rewriter); + unsigned arrayDim = arrTy.getDimension(); + for (unsigned dim = 0; dim < arrayDim && it != end; ++dim, ++it) { + mlir::Value stride = + getStrideFromBox(loc, boxTyPair, operands[0], dim, rewriter); auto sc = rewriter.create( - loc, idxTy, operands[index], stride, nsw); + loc, idxTy, operands[nextIndexValue + dim], stride, nsw); off = rewriter.create(loc, idxTy, sc, off, nsw); } + nextIndexValue += arrayDim; resultAddr = rewriter.create( loc, llvmPtrTy, byteTy, resultAddr, llvm::ArrayRef{off}); - i += arrTy.getDimension() - 1; cpnTy = arrTy.getEleTy(); } else if (auto recTy = mlir::dyn_cast(cpnTy)) { - mlir::Value nxtOpnd = operands[i]; - cpnTy = recTy.getType(getFieldNumber(recTy, nxtOpnd)); + auto intAttr = llvm::dyn_cast(*it); + if (!intAttr) + return mlir::emitError(loc, + "expected field name in fir.coordinate_of"); + int fieldIndex = intAttr.getInt(); + ++it; + cpnTy = recTy.getType(fieldIndex); auto llvmRecTy = lowerTy().convertType(recTy); resultAddr = rewriter.create( loc, llvmPtrTy, llvmRecTy, resultAddr, - llvm::ArrayRef{0, nxtOpnd}); + llvm::ArrayRef{0, fieldIndex}); } else { fir::emitFatalError(loc, "unexpected type in coordinate_of"); } @@ -2801,92 +2829,71 @@ struct CoordinateOpConversion // Component Type mlir::Type cpnTy = fir::dyn_cast_ptrOrBoxEleTy(baseObjectTy); - bool hasSubdimension = hasSubDimensions(cpnTy); - bool columnIsDeferred = !hasSubdimension; - - if (!supportedCoordinate(cpnTy, operands.drop_front(1))) - TODO(loc, "unsupported combination of coordinate operands"); - - const bool hasKnownShape = - arraysHaveKnownShape(cpnTy, operands.drop_front(1)); - - // If only the column is `?`, then we can simply place the column value in - // the 0-th GEP position. - if (auto arrTy = mlir::dyn_cast(cpnTy)) { - if (!hasKnownShape) { - const unsigned sz = arrTy.getDimension(); - if (arraysHaveKnownShape(arrTy.getEleTy(), - operands.drop_front(1 + sz))) { - fir::SequenceType::ShapeRef shape = arrTy.getShape(); - bool allConst = true; - for (unsigned i = 0; i < sz - 1; ++i) { - if (shape[i] < 0) { - allConst = false; - break; - } - } - if (allConst) - columnIsDeferred = true; - } - } - } + + const std::optional shapeAnalysis = + arraysHaveKnownShape(cpnTy, coor); + if (!shapeAnalysis) + return mlir::failure(); if (fir::hasDynamicSize(fir::unwrapSequenceType(cpnTy))) return mlir::emitError( loc, "fir.coordinate_of with a dynamic element size is unsupported"); - if (hasKnownShape || columnIsDeferred) { + if (shapeAnalysis->hasKnownShape || shapeAnalysis->columnIsDeferred) { llvm::SmallVector offs; - if (hasKnownShape && hasSubdimension) { + if (shapeAnalysis->hasKnownShape) { offs.push_back(0); } + // Else, only the column is `?` and we can simply place the column value + // in the 0-th GEP position. + std::optional dims; llvm::SmallVector arrIdx; - for (std::size_t i = 1, sz = operands.size(); i < sz; ++i) { - mlir::Value nxtOpnd = operands[i]; - - if (!cpnTy) - return mlir::emitError(loc, "invalid coordinate/check failed"); - - // check if the i-th coordinate relates to an array - if (dims) { - arrIdx.push_back(nxtOpnd); - int dimsLeft = *dims; - if (dimsLeft > 1) { - dims = dimsLeft - 1; - continue; - } - cpnTy = mlir::cast(cpnTy).getElementType(); - // append array range in reverse (FIR arrays are column-major) - offs.append(arrIdx.rbegin(), arrIdx.rend()); - arrIdx.clear(); - dims.reset(); + int nextIndexValue = 1; + for (auto index : coor.getIndices()) { + if (auto intAttr = llvm::dyn_cast(index)) { + // Addressing derived type component. + auto recordType = llvm::dyn_cast(cpnTy); + if (!recordType) + return mlir::emitError( + loc, + "fir.coordinate base type is not consistent with operands"); + int fieldId = intAttr.getInt(); + cpnTy = recordType.getType(fieldId); + offs.push_back(fieldId); continue; } - if (auto arrTy = mlir::dyn_cast(cpnTy)) { - int d = arrTy.getDimension() - 1; - if (d > 0) { - dims = d; - arrIdx.push_back(nxtOpnd); - continue; + // Value index (addressing array, tuple, or complex part). + mlir::Value indexValue = operands[nextIndexValue++]; + if (auto tupTy = mlir::dyn_cast(cpnTy)) { + cpnTy = tupTy.getType(getConstantIntValue(indexValue)); + offs.push_back(indexValue); + } else { + if (!dims) { + if (auto arrayType = llvm::dyn_cast(cpnTy)) { + // Starting addressing array or array component. + dims = arrayType.getDimension(); + cpnTy = arrayType.getElementType(); + } + } + if (dims) { + arrIdx.push_back(indexValue); + if (--(*dims) == 0) { + // Append array range in reverse (FIR arrays are column-major). + offs.append(arrIdx.rbegin(), arrIdx.rend()); + arrIdx.clear(); + dims.reset(); + } + } else { + offs.push_back(indexValue); } - cpnTy = mlir::cast(cpnTy).getElementType(); - offs.push_back(nxtOpnd); - continue; } - - // check if the i-th coordinate relates to a field - if (auto recTy = mlir::dyn_cast(cpnTy)) - cpnTy = recTy.getType(getFieldNumber(recTy, nxtOpnd)); - else if (auto tupTy = mlir::dyn_cast(cpnTy)) - cpnTy = tupTy.getType(getConstantIntValue(nxtOpnd)); - else - cpnTy = nullptr; - - offs.push_back(nxtOpnd); } - if (dims) + // It is possible the fir.coordinate_of result is a sub-array, in which + // case there may be some "unfinished" array indices to reverse and push. + if (!arrIdx.empty()) offs.append(arrIdx.rbegin(), arrIdx.rend()); + mlir::Value base = operands[0]; mlir::Value retval = genGEP(loc, llvmObjectTy, rewriter, base, offs); rewriter.replaceOp(coor, retval); diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index f26b70c2b43c3..7efb733eb565c 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -1486,6 +1486,33 @@ void fir::CoordinateOp::build(mlir::OpBuilder &builder, } } +void fir::CoordinateOp::build(mlir::OpBuilder &builder, + mlir::OperationState &result, + mlir::Type resultType, mlir::Value ref, + llvm::ArrayRef coor) { + llvm::SmallVector fieldIndices; + llvm::SmallVector dynamicIndices; + bool anyField = false; + for (fir::IntOrValue index : coor) { + llvm::TypeSwitch(index) + .Case([&](mlir::IntegerAttr intAttr) { + fieldIndices.push_back(intAttr.getInt()); + anyField = true; + }) + .Case([&](mlir::Value value) { + dynamicIndices.push_back(value); + fieldIndices.push_back(fir::CoordinateOp::kDynamicIndex); + }); + } + auto typeAttr = mlir::TypeAttr::get(ref.getType()); + if (anyField) { + build(builder, result, resultType, ref, dynamicIndices, typeAttr, + builder.getDenseI32ArrayAttr(fieldIndices)); + } else { + build(builder, result, resultType, ref, dynamicIndices, typeAttr, nullptr); + } +} + void fir::CoordinateOp::print(mlir::OpAsmPrinter &p) { p << ' ' << getRef(); if (!getFieldIndicesAttr()) { @@ -1494,7 +1521,7 @@ void fir::CoordinateOp::print(mlir::OpAsmPrinter &p) { mlir::Type eleTy = fir::getFortranElementType(getRef().getType()); for (auto index : getIndices()) { p << ", "; - llvm::TypeSwitch(index) + llvm::TypeSwitch(index) .Case([&](mlir::IntegerAttr intAttr) { if (auto recordType = llvm::dyn_cast(eleTy)) { int fieldId = intAttr.getInt(); diff --git a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp index beea7543e54b3..ab4dc582d5804 100644 --- a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp +++ b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp @@ -579,7 +579,7 @@ class MapInfoFinalizationPass if (!shouldMapField) continue; - int64_t fieldIdx = recordType.getFieldIndex(field); + int32_t fieldIdx = recordType.getFieldIndex(field); bool alreadyMapped = [&]() { if (op.getMembersIndexAttr()) for (auto indexList : op.getMembersIndexAttr()) { @@ -597,12 +597,11 @@ class MapInfoFinalizationPass continue; builder.setInsertionPoint(op); - mlir::Value fieldIdxVal = builder.createIntegerConstant( - op.getLoc(), mlir::IndexType::get(builder.getContext()), - fieldIdx); + fir::IntOrValue idxConst = + mlir::IntegerAttr::get(builder.getI32Type(), fieldIdx); auto fieldCoord = builder.create( op.getLoc(), builder.getRefType(memTy), op.getVarPtr(), - fieldIdxVal); + llvm::SmallVector{idxConst}); fir::factory::AddrAndBoundsInfo info = fir::factory::getDataOperandBaseAddr( builder, fieldCoord, /*isOptional=*/false, op.getLoc()); diff --git a/flang/test/Fir/Todo/coordinate_of_2.fir b/flang/test/Fir/Todo/coordinate_of_2.fir index 7ceead8de5279..759f2eab097e9 100644 --- a/flang/test/Fir/Todo/coordinate_of_2.fir +++ b/flang/test/Fir/Todo/coordinate_of_2.fir @@ -4,7 +4,6 @@ // `!fir.coordinate_of` - `!fir.array` inside "boxed" `!fir.type` func.func @coordinate_box_array_inside_derived(%arg0: !fir.box, field_2:i32}>>, %arg1 : index) { - %idx0 = arith.constant 0 : i32 - %q = fir.coordinate_of %arg0, %idx0, %arg1 : (!fir.box, field_2:i32}>>, i32, index) -> !fir.ref + %q = fir.coordinate_of %arg0, field_1, %arg1 : (!fir.box, field_2:i32}>>, index) -> !fir.ref return } diff --git a/flang/test/Fir/Todo/coordinate_of_3.fir b/flang/test/Fir/Todo/coordinate_of_3.fir index 305422052be27..aff936d0e1a41 100644 --- a/flang/test/Fir/Todo/coordinate_of_3.fir +++ b/flang/test/Fir/Todo/coordinate_of_3.fir @@ -4,7 +4,6 @@ // `fir.coordinate_of` - `fir.array` inside "boxed" `!fir.type}` (i.e. nested `!fir.type`) func.func @coordinate_box_array_inside_derived(%arg0: !fir.box}>}>>, %arg1 : index) { - %idx0 = arith.constant 0 : i32 - %q = fir.coordinate_of %arg0, %idx0, %idx0, %arg1 : (!fir.box}>}>>, i32, i32, index) -> !fir.ref + %q = fir.coordinate_of %arg0, field_1, field_2, %arg1 : (!fir.box}>}>>, index) -> !fir.ref return } diff --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir index 7cdcd2a10e975..a429a14518182 100644 --- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir +++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir @@ -948,13 +948,11 @@ func.func @omp_map_info_descriptor_type_conversion(%arg0 : !fir.ref,int:i32}>>) { // CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG_0]][0, 2] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)> - %0 = fir.field_index int, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}> - %1 = fir.coordinate_of %arg0, %0 : (!fir.ref,int:i32}>>, !fir.field) -> !fir.ref + %1 = fir.coordinate_of %arg0, int : (!fir.ref,int:i32}>>) -> !fir.ref // CHECK: %[[MAP_MEMBER_1:.*]] = omp.map.info var_ptr(%[[GEP]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "dtype%int"} %2 = omp.map.info var_ptr(%1 : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "dtype%int"} // CHECK: %[[GEP_2:.*]] = llvm.getelementptr %[[ARG_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)> - %3 = fir.field_index real, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}> - %4 = fir.coordinate_of %arg0, %3 : (!fir.ref,int:i32}>>, !fir.field) -> !fir.ref + %4 = fir.coordinate_of %arg0, real : (!fir.ref,int:i32}>>) -> !fir.ref // CHECK: %[[MAP_MEMBER_2:.*]] = omp.map.info var_ptr(%[[GEP_2]] : !llvm.ptr, f32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "dtype%real"} %5 = omp.map.info var_ptr(%4 : !fir.ref, f32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "dtype%real"} // CHECK: %[[MAP_PARENT:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [2], [0] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "dtype", partial_map = true} @@ -973,16 +971,13 @@ func.func @omp_map_info_derived_type_explicit_member_conversion(%arg0 : !fir.ref func.func @omp_map_info_nested_derived_type_explicit_member_conversion(%arg0 : !fir.ref,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>) { // CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG_0]][0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFTtop_layer", (array<10 x i32>, struct<"_QFTbottom_layer", (array<10 x f32>, f64)>, i32)> - %0 = fir.field_index nested, !fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}> - %1 = fir.coordinate_of %arg0, %0 : (!fir.ref,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>, !fir.field) -> !fir.ref,i2:f64}>> + %1 = fir.coordinate_of %arg0, nested : (!fir.ref,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>) -> !fir.ref,i2:f64}>> // CHECK: %[[GEP_2:.*]] = llvm.getelementptr %[[GEP]][0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFTbottom_layer", (array<10 x f32>, f64)> - %2 = fir.field_index i2, !fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}> - %3 = fir.coordinate_of %1, %2 : (!fir.ref,i2:f64}>>, !fir.field) -> !fir.ref + %3 = fir.coordinate_of %1, i2 : (!fir.ref,i2:f64}>>) -> !fir.ref // CHECK: %[[MAP_MEMBER_1:.*]] = omp.map.info var_ptr(%[[GEP_2]] : !llvm.ptr, f64) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr %4 = omp.map.info var_ptr(%3 : !fir.ref, f64) map_clauses(tofrom) capture(ByRef) -> !fir.ref // CHECK: %[[GEP_3:.*]] = llvm.getelementptr %[[ARG_0]][0, 2] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFTtop_layer", (array<10 x i32>, struct<"_QFTbottom_layer", (array<10 x f32>, f64)>, i32)> - %5 = fir.field_index k, !fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}> - %6 = fir.coordinate_of %arg0, %5 : (!fir.ref,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>, !fir.field) -> !fir.ref + %6 = fir.coordinate_of %arg0, k : (!fir.ref,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>) -> !fir.ref // CHECK: %[[MAP_MEMBER_2:.*]] = omp.map.info var_ptr(%[[GEP_3]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr %7 = omp.map.info var_ptr(%6 : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref // CHECK: %[[PARENT_MAP:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFTtop_layer", (array<10 x i32>, struct<"_QFTbottom_layer", (array<10 x f32>, f64)>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [1, 1], [2] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {partial_map = true} @@ -1131,7 +1126,7 @@ func.func @map_dtype_alloca_mem(%arg0 : !fir.ref !llvm.ptr, [[STRUCT_TY:!llvm.struct<"_QFRecTy", \(f32, struct<\(ptr, i64, i32, i8, i8, i8, i8\)>, array<10 x i32>, f32, struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>, i32\)>]] - %1 = fir.coordinate_of %arg0, %c4 : (!fir.ref>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32}>>, index) -> !fir.ref>>> + %1 = fir.coordinate_of %arg0, array_j : (!fir.ref>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32}>>) -> !fir.ref>>> // CHECK: %[[BADDR_GEP:.*]] = llvm.getelementptr %[[GEP]][0, 0] : (!llvm.ptr) -> !llvm.ptr, [[STRUCT_TY2:!llvm.struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>]] %2 = fir.box_offset %1 base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> // CHECK: %[[MAP_MEMBER_BADDR:.*]] = omp.map.info var_ptr(%[[GEP]] : !llvm.ptr, i32) var_ptr_ptr(%[[BADDR_GEP]] : !llvm.ptr) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !llvm.ptr @@ -1165,7 +1160,7 @@ func.func @map_dtype_alloca_mem2(%arg0 : !fir.ref !llvm.ptr, [[DESC_TY]] // CHECK: %[[LOAD_DTYPE_BADDR:.*]] = llvm.load %[[GEP_DTYPE_BADDR]] : !llvm.ptr -> !llvm.ptr // CHECK: %[[GEP_DTYPE_MEMBER:.*]] = llvm.getelementptr %[[LOAD_DTYPE_BADDR]][0, 4] : (!llvm.ptr) -> !llvm.ptr, [[REC_TY:!llvm.struct<"_QFRecTy", \(f32, struct<\(ptr, i64, i32, i8, i8, i8, i8\)>, array<10 x i32>, f32, struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>, i32\)>]] - %2 = fir.coordinate_of %1, %c4 : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32}>>>, index) -> !fir.ref>>> + %2 = fir.coordinate_of %1, array_j : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32}>>>) -> !fir.ref>>> // CHECK: %[[DTYPE_MEMBER_BADDR:.*]] = llvm.getelementptr %[[GEP_DTYPE_MEMBER]][0, 0] : (!llvm.ptr) -> !llvm.ptr, [[DESC_TY2:!llvm.struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>]] %3 = fir.box_offset %2 base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> // CHECK: %[[MAP_MEMBER_BADDR:.*]] = omp.map.info var_ptr(%[[GEP_DTYPE_MEMBER]] : !llvm.ptr, i32) var_ptr_ptr(%[[DTYPE_MEMBER_BADDR]] : !llvm.ptr) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !llvm.ptr @@ -1177,7 +1172,7 @@ func.func @map_dtype_alloca_mem2(%arg0 : !fir.ref !llvm.ptr, [[DESC_TY]] // CHECK: %[[LOAD_DTYPE_BADDR:.*]] = llvm.load %[[GEP_DTYPE_BADDR]] : !llvm.ptr -> !llvm.ptr // CHECK: %[[GEP_DTYPE_REGULAR_MEMBER:.*]] = llvm.getelementptr %[[LOAD_DTYPE_BADDR]][0, 5] : (!llvm.ptr) -> !llvm.ptr, [[REC_TY]] - %7 = fir.coordinate_of %6, %c5 : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32}>>>, index) -> !fir.ref + %7 = fir.coordinate_of %6, k : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32}>>>) -> !fir.ref // CHECK: %[[MAP_REGULAR_MEMBER:.*]] = omp.map.info var_ptr(%[[GEP_DTYPE_REGULAR_MEMBER]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr %8 = omp.map.info var_ptr(%7 : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref // CHECK: %[[GEP_DTYPE_BADDR:.*]] = llvm.getelementptr %[[ARG_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, [[DESC_TY]] @@ -1213,9 +1208,9 @@ func.func @map_nested_dtype_alloca_mem(%arg0 : !fir.ref !llvm.ptr, [[DESC_TY]] // CHECK: %[[LOAD_GEP_DTYPE_BADDR:.*]] = llvm.load %[[GEP_DTYPE_BADDR]] : !llvm.ptr -> !llvm.ptr // CHECK: %[[LOAD_NESTED_DTYPE:.*]] = llvm.getelementptr %[[LOAD_GEP_DTYPE_BADDR]][0, 6] : (!llvm.ptr) -> !llvm.ptr, [[REC_TY:!llvm.struct<"_QFRecTy", \(f32, struct<\(ptr, i64, i32, i8, i8, i8, i8\)>, array<10 x i32>, f32, struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>, i32, struct<"_QFRecTy2", \(f32, array<10 x i32>, struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>, i32\)>\)>]] - %2 = fir.coordinate_of %1, %c6 : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFRecTy2{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}>>>, index) -> !fir.ref,array_k:!fir.box>>,k:i32}>> + %2 = fir.coordinate_of %1, nest : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFRecTy2{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}>>>) -> !fir.ref,array_k:!fir.box>>,k:i32}>> // CHECK: %[[GEP_NESTED_DTYPE_ALLOCATABLE_MEMBER:.*]] = llvm.getelementptr %[[LOAD_NESTED_DTYPE]][0, 2] : (!llvm.ptr) -> !llvm.ptr, [[REC_TY2:!llvm.struct<"_QFRecTy2", \(f32, array<10 x i32>, struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>, i32\)>]] - %3 = fir.coordinate_of %2, %c2 : (!fir.ref,array_k:!fir.box>>,k:i32}>>, index) -> !fir.ref>>> + %3 = fir.coordinate_of %2, array_k : (!fir.ref,array_k:!fir.box>>,k:i32}>>) -> !fir.ref>>> // CHECK: %[[GEP_NESTED_DTYPE_ALLOCATABLE_MEMBER_BADDR:.*]] = llvm.getelementptr %[[GEP_NESTED_DTYPE_ALLOCATABLE_MEMBER]][0, 0] : (!llvm.ptr) -> !llvm.ptr, [[DESC_TY2:!llvm.struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>]] %4 = fir.box_offset %3 base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> // CHECK: %[[MAP_NESTED_MEMBER_BADDR:.*]] = omp.map.info var_ptr(%[[GEP_NESTED_DTYPE_ALLOCATABLE_MEMBER]] : !llvm.ptr, i32) var_ptr_ptr(%[[GEP_NESTED_DTYPE_ALLOCATABLE_MEMBER_BADDR]] : !llvm.ptr) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !llvm.ptr @@ -1227,9 +1222,9 @@ func.func @map_nested_dtype_alloca_mem(%arg0 : !fir.ref !llvm.ptr %7 = fir.load %arg0 : !fir.ref>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFRecTy2{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}>>>> // CHECK: %[[LOAD_NESTED_DTYPE:.*]] = llvm.getelementptr %[[LOAD_GEP_DTYPE_BADDR]][0, 6] : (!llvm.ptr) -> !llvm.ptr, [[REC_TY]] - %8 = fir.coordinate_of %7, %c6 : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFRecTy2{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}>>>, index) -> !fir.ref,array_k:!fir.box>>,k:i32}>> + %8 = fir.coordinate_of %7, nest : (!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFRecTy2{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}>>>) -> !fir.ref,array_k:!fir.box>>,k:i32}>> // CHECK: %[[NESTED_DTYPE_REGULAR_MEMBER_GEP:.*]] = llvm.getelementptr %[[LOAD_NESTED_DTYPE]][0, 3] : (!llvm.ptr) -> !llvm.ptr, [[REC_TY2]] - %9 = fir.coordinate_of %8, %c3 : (!fir.ref,array_k:!fir.box>>,k:i32}>>, index) -> !fir.ref + %9 = fir.coordinate_of %8, k : (!fir.ref,array_k:!fir.box>>,k:i32}>>) -> !fir.ref // CHECK: %[[MAP_REGULAR_NESTED_MEMBER:.*]] = omp.map.info var_ptr(%[[NESTED_DTYPE_REGULAR_MEMBER_GEP]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr %10 = omp.map.info var_ptr(%9 : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref // CHECK: %[[DTYPE_BADDR_GEP:.*]] = llvm.getelementptr %[[ARG_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, [[DESC_TY]] @@ -1258,9 +1253,9 @@ func.func @map_nested_dtype_alloca_mem2(%arg0 : !fir.ref !llvm.ptr, [[REC_TY:!llvm.struct<"_QFRecTy", \(f32, struct<\(ptr, i64, i32, i8, i8, i8, i8\)>, array<10 x i32>, f32, struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>, i32, struct<"_QFRecTy2", \(f32, array<10 x i32>, struct<\(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>\)>, i32\)>\)>]] - %1 = fir.coordinate_of %arg0, %c6 : (!fir.ref>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFRecTy2{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}>>, index) -> !fir.ref,array_k:!fir.box>>,k:i32}>> + %1 = fir.coordinate_of %arg0, nest : (!fir.ref>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFRecTy2{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}>>) -> !fir.ref,array_k:!fir.box>>,k:i32}>> // CHECK: %[[NESTED_ALLOCATABLE_MEMBER_GEP:.*]] = llvm.getelementptr %[[NESTED_DTYPE_MEMBER_GEP]][0, 2] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFRecTy2", (f32, array<10 x i32>, struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>, i32)> - %2 = fir.coordinate_of %1, %c2 : (!fir.ref,array_k:!fir.box>>,k:i32}>>, index) -> !fir.ref>>> + %2 = fir.coordinate_of %1, array_k : (!fir.ref,array_k:!fir.box>>,k:i32}>>) -> !fir.ref>>> // CHECK: %[[NESTED_ALLOCATABLE_MEMBER_BADDR_GEP:.*]] = llvm.getelementptr %[[NESTED_ALLOCATABLE_MEMBER_GEP]][0, 0] : (!llvm.ptr) -> !llvm.ptr, [[DESC_TY2]] %3 = fir.box_offset %2 base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> // CHECK: %[[MAP_NESTED_ALLOCATABLE_MEMBER_BADDR:.*]] = omp.map.info var_ptr(%[[NESTED_ALLOCATABLE_MEMBER_GEP]] : !llvm.ptr, i32) var_ptr_ptr(%[[NESTED_ALLOCATABLE_MEMBER_BADDR_GEP]] : !llvm.ptr) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !llvm.ptr @@ -1282,10 +1277,8 @@ func.func @map_nested_dtype_alloca_mem2(%arg0 : !fir.ref { // CHECK: ^bb0(%[[VAL_0:.*]]: !llvm.ptr): ^bb0(%0: !fir.ref>): -// CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(0 : i32) : i32 - %1 = fir.field_index data, !fir.type<_QFdeclare_mapperTmy_type{data:i32}> // CHECK: %[[VAL_2:.*]] = llvm.getelementptr %[[VAL_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFdeclare_mapperTmy_type", (i32)> - %2 = fir.coordinate_of %0, %1 : (!fir.ref>, !fir.field) -> !fir.ref + %2 = fir.coordinate_of %0, data : (!fir.ref>) -> !fir.ref // CHECK: %[[VAL_3:.*]] = omp.map.info var_ptr(%[[VAL_2]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "var%[[VAL_4:.*]]"} %3 = omp.map.info var_ptr(%2 : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "var%data"} // CHECK: %[[VAL_5:.*]] = omp.map.info var_ptr(%[[VAL_0]] : !llvm.ptr, !llvm.struct<"_QFdeclare_mapperTmy_type", (i32)>) map_clauses(tofrom) capture(ByRef) members(%[[VAL_3]] : [0] : !llvm.ptr) -> !llvm.ptr {name = "var", partial_map = true} diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir index 8727c0ab08e70..c7037019ee701 100644 --- a/flang/test/Fir/convert-to-llvm.fir +++ b/flang/test/Fir/convert-to-llvm.fir @@ -2575,13 +2575,11 @@ func.func @coordinate_box_complex(%arg0: !fir.box>) { // 2. BOX TYPE (objects wrapped in `fir.box`) // Derived type - basic case (1 index) func.func @coordinate_box_derived_1(%arg0: !fir.box>) { - %idx = fir.field_index field_2, !fir.type - %q = fir.coordinate_of %arg0, %idx : (!fir.box>, !fir.field) -> !fir.ref + %q = fir.coordinate_of %arg0, field_2 : (!fir.box>) -> !fir.ref return } // CHECK-LABEL: llvm.func @coordinate_box_derived_1 // CHECK-SAME: %[[BOX:.*]]: !llvm.ptr) -// CHECK: %[[COORDINATE:.*]] = llvm.mlir.constant(1 : i32) : i32 // CHECK: %[[DERIVED_ADDR:.*]] = llvm.getelementptr %[[BOX]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(ptr, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i64>)> // CHECK: %[[DERIVED_VAL:.*]] = llvm.load %[[DERIVED_ADDR]] : !llvm.ptr -> !llvm.ptr // CHECK: %[[SUBOBJECT_ADDR:.*]] = llvm.getelementptr %[[DERIVED_VAL]][0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"derived_1", (i32, i32)> @@ -2589,16 +2587,12 @@ func.func @coordinate_box_derived_1(%arg0: !fir.box, field_2:i32}>>) { - %idx0 = fir.field_index field_1, !fir.type, field_2:i32}> - %idx1 = fir.field_index inner2, !fir.type - %q = fir.coordinate_of %arg0, %idx0, %idx1 : (!fir.box, field_2:i32}>>, !fir.field, !fir.field) -> !fir.ref + %q = fir.coordinate_of %arg0, field_1, inner2 : (!fir.box, field_2:i32}>>) -> !fir.ref return } // CHECK-LABEL: llvm.func @coordinate_box_derived_2 // CHECK-SAME: (%[[BOX:.*]]: !llvm.ptr) -// CHECK-NEXT: %[[C0_0:.*]] = llvm.mlir.constant(0 : i32) : i32 -// CHECK-NEXT: %[[C1:.*]] = llvm.mlir.constant(1 : i32) : i32 // CHECK: %[[DERIVED_ADDR:.*]] = llvm.getelementptr %[[BOX]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(ptr, i{{.*}}, i{{.*}}32, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i64>)> // CHECK-NEXT: %[[DERIVED_VAL:.*]] = llvm.load %[[DERIVED_ADDR]] : !llvm.ptr -> !llvm.ptr // CHECK-NEXT: %[[ANOTHER_DERIVED_ADDR:.*]] = llvm.getelementptr %[[DERIVED_VAL]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"derived_2", (struct<"another_derived", (i32, f32)>, i32)> @@ -2683,8 +2677,7 @@ func.func @coordinate_box_array_2d(%arg0: !fir.box>, % // 4. BOX TYPE - `fir.derived` inside `fir.array` func.func @coordinate_box_derived_inside_array(%arg0: !fir.box>>, %arg1 : index) { - %idx0 = fir.field_index field_2, !fir.type - %q = fir.coordinate_of %arg0, %arg1, %idx0 : (!fir.box>>, index, !fir.field) -> !fir.ref + %q = fir.coordinate_of %arg0, %arg1, field_2 : (!fir.box>>, index) -> !fir.ref return } // CHECK-LABEL: llvm.func @coordinate_box_derived_inside_array( @@ -2761,8 +2754,7 @@ func.func @coordinate_array_known_size_2d_get_array(%arg0: !fir.ref>) { - %idx = fir.field_index field_2, !fir.type - %q = fir.coordinate_of %arg0, %idx : (!fir.ref>, !fir.field) -> !fir.ref + %q = fir.coordinate_of %arg0, field_2 : (!fir.ref>) -> !fir.ref return } // CHECK-LABEL: llvm.func @coordinate_ref_derived( @@ -2774,9 +2766,7 @@ func.func @coordinate_ref_derived(%arg0: !fir.ref, field_2:i32}>>) { - %idx0 = fir.field_index field_1, !fir.type, field_2:i32}> - %idx1 = fir.field_index inner2, !fir.type - %q = fir.coordinate_of %arg0, %idx0, %idx1 : (!fir.ref, field_2:i32}>>, !fir.field, !fir.field) -> !fir.ref + %q = fir.coordinate_of %arg0, field_1, inner2 : (!fir.ref, field_2:i32}>>) -> !fir.ref return } // CHECK-LABEL: llvm.func @coordinate_ref_derived_nested( @@ -2788,15 +2778,15 @@ func.func @coordinate_ref_derived_nested(%arg0: !fir.ref>) { +func.func @test_coordinate_of_char(%arr : !fir.ref>) { %1 = arith.constant 10 : i32 - %2 = fir.coordinate_of %arr, %1 : (!fir.ref>, i32) -> !fir.ref> + %2 = fir.coordinate_of %arr, %1 : (!fir.ref>, i32) -> !fir.ref> return } // CHECK-LABEL: llvm.func @test_coordinate_of_char( // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr) { // CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(10 : i32) : i32 -// CHECK: %[[VAL_2:.*]] = llvm.getelementptr %[[VAL_0]]{{\[}}%[[VAL_1]]] : (!llvm.ptr, i32) -> !llvm.ptr, !llvm.array<2 x i80> +// CHECK: %[[VAL_2:.*]] = llvm.getelementptr %[[VAL_0]]{{\[}}0, %[[VAL_1]]] : (!llvm.ptr, i32) -> !llvm.ptr, !llvm.array<10 x i16> // CHECK: llvm.return // CHECK: } diff --git a/flang/test/Fir/field-index.fir b/flang/test/Fir/field-index.fir index 4f2551b380d55..55d173201f29a 100644 --- a/flang/test/Fir/field-index.fir +++ b/flang/test/Fir/field-index.fir @@ -1,4 +1,4 @@ -// Test fir.field_index llvm code generation +// Test llvm code generation of fir.coordinate_of with field names // RUN: fir-opt %s | tco | FileCheck %s @@ -9,9 +9,8 @@ // CHECK-LABEL: @simple_field // CHECK-SAME: (ptr captures(none) %[[arg0:.*]]) func.func @simple_field(%arg0: !fir.ref>) -> i32 { - %1 = fir.field_index i, !fir.type // CHECK: %[[GEP:.*]] = getelementptr %a, ptr %[[arg0]], i32 0, i32 1 - %2 = fir.coordinate_of %arg0, %1 : (!fir.ref>, !fir.field) -> !fir.ref + %2 = fir.coordinate_of %arg0, i : (!fir.ref>) -> !fir.ref // CHECK: load i32, ptr %[[GEP]] %3 = fir.load %2 : !fir.ref return %3 : i32 @@ -20,10 +19,8 @@ func.func @simple_field(%arg0: !fir.ref>) -> i32 { // CHECK-LABEL: @derived_field // CHECK-SAME: (ptr captures(none) %[[arg0:.*]]) func.func @derived_field(%arg0: !fir.ref}>>) -> i32 { - %1 = fir.field_index some_b, !fir.type}> - %2 = fir.field_index i, !fir.type // CHECK: %[[GEP:.*]] = getelementptr %c, ptr %[[arg0]], i32 0, i32 1, i32 1 - %3 = fir.coordinate_of %arg0, %1, %2 : (!fir.ref}>>, !fir.field, !fir.field) -> !fir.ref + %3 = fir.coordinate_of %arg0, some_b, i : (!fir.ref}>>) -> !fir.ref // CHECK: load i32, ptr %[[GEP]] %4 = fir.load %3 : !fir.ref return %4 : i32 diff --git a/flang/test/Fir/pdt.fir b/flang/test/Fir/pdt.fir index ce1fb7a379b8b..a200cd7e7cc03 100644 --- a/flang/test/Fir/pdt.fir +++ b/flang/test/Fir/pdt.fir @@ -49,8 +49,7 @@ func.func @_QQmain(%arg0 : i32, %arg1 : i16) { // CHECK: %[[size:.*]] = call i64 @_QTtP.mem.size(i32 %0, i16 %1) // CHECK: %[[alloc:.*]] = alloca i8, i64 %[[size]] %0 = fir.alloca !fir.type<_QTt(p1:i32,p2:i16){f1:i32,f2:f32}>(%arg0, %arg1 : i32, i16) {name = "_QEvar"} - %1 = fir.field_index f1, !fir.type<_QTt(p1:i32,p2:i16){f1:i32,f2:f32}>(%arg0, %arg1 : i32, i16) - %2 = fir.coordinate_of %0, %1 : (!fir.ref>, !fir.field) -> !fir.ref + %2 = fir.coordinate_of %0, f1 : (!fir.ref>) -> !fir.ref %c4_i32 = arith.constant 4 : i32 fir.store %c4_i32 to %2 : !fir.ref return @@ -102,8 +101,7 @@ func.func @_QPfoo(%arg0 : i32, %arg1 : i32) { // CHECK: %[[size:.*]] = call i64 @_QTt1P.mem.size(i32 %0, i32 %1) // CHECK: %[[alloc:.*]] = alloca i8, i64 %[[size]] %0 = fir.alloca !fir.type<_QTt1(p1:i32,p2:i32){f1:!fir.char<1,?>,f2:!fir.char<1,?>}>(%arg0, %arg1 : i32, i32) - %1 = fir.field_index f2, !fir.type<_QTt1>(%arg0, %arg1 : i32, i32) - //%2 = fir.coordinate_of %0, %1 : (!fir.ref>, !fir.field) -> !fir.ref> + //%2 = fir.coordinate_of %0, f2 : (!fir.ref>) -> !fir.ref> %2 = fir.zero_bits !fir.ref> fir.call @bar(%2) : (!fir.ref>) -> () return diff --git a/flang/test/Integration/OpenMP/map-types-and-sizes.f90 b/flang/test/Integration/OpenMP/map-types-and-sizes.f90 index e0221ef254192..70ae353ced214 100644 --- a/flang/test/Integration/OpenMP/map-types-and-sizes.f90 +++ b/flang/test/Integration/OpenMP/map-types-and-sizes.f90 @@ -504,10 +504,10 @@ end subroutine mapType_common_block_members !CHECK-LABEL: define {{.*}} @{{.*}}maptype_derived_type_alloca_{{.*}} !CHECK: %[[ALLOCATABLE_DESC_ALLOCA:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8 !CHECK: %[[ALLOCA:.*]] = alloca %_QFmaptype_derived_type_allocaTone_layer, i64 1, align 8 +!CHECK: %[[MEMBER_ACCESS:.*]] = getelementptr %_QFmaptype_derived_type_allocaTone_layer, ptr %[[ALLOCA]], i32 0, i32 4 !CHECK: %[[DESC_BOUND_ACCESS:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[ALLOCATABLE_DESC_ALLOCA]], i32 0, i32 7, i64 0, i32 1 !CHECK: %[[DESC_BOUND_ACCESS_LOAD:.*]] = load i64, ptr %[[DESC_BOUND_ACCESS]], align 8 !CHECK: %[[OFFSET_UB:.*]] = sub i64 %[[DESC_BOUND_ACCESS_LOAD]], 1 -!CHECK: %[[MEMBER_ACCESS:.*]] = getelementptr %_QFmaptype_derived_type_allocaTone_layer, ptr %[[ALLOCA]], i32 0, i32 4 !CHECK: %[[MEMBER_DESCRIPTOR_BASE_ADDR:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[MEMBER_ACCESS]], i32 0, i32 0 !CHECK: %[[CALCULATE_DIM_SIZE:.*]] = sub i64 %[[OFFSET_UB]], 0 !CHECK: %[[RESTORE_OFFSET:.*]] = add i64 %[[CALCULATE_DIM_SIZE]], 1 @@ -549,12 +549,12 @@ end subroutine mapType_common_block_members !CHECK: %[[DTYPE_ARRAY_MEMBER_DESC_ALLOCA:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8 !CHECK: %[[DTYPE_DESC_ALLOCA_2:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, align 8 !CHECK: %[[DTYPE_DESC_ALLOCA_3:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, i64 1, align 8 -!CHECK: %[[ACCESS_DESC_MEMBER_UB:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[DTYPE_ARRAY_MEMBER_DESC_ALLOCA]], i32 0, i32 7, i64 0, i32 1 -!CHECK: %[[LOAD_DESC_MEMBER_UB:.*]] = load i64, ptr %[[ACCESS_DESC_MEMBER_UB]], align 8 -!CHECK: %[[OFFSET_MEMBER_UB:.*]] = sub i64 %[[LOAD_DESC_MEMBER_UB]], 1 !CHECK: %[[DTYPE_BASE_ADDR_ACCESS:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, ptr %[[DTYPE_DESC_ALLOCA_2]], i32 0, i32 0 !CHECK: %[[DTYPE_BASE_ADDR_LOAD:.*]] = load ptr, ptr %[[DTYPE_BASE_ADDR_ACCESS]], align 8 !CHECK: %[[DTYPE_ALLOCA_MEMBER_ACCESS:.*]] = getelementptr %_QFmaptype_alloca_derived_typeTone_layer, ptr %[[DTYPE_BASE_ADDR_LOAD]], i32 0, i32 4 +!CHECK: %[[ACCESS_DESC_MEMBER_UB:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[DTYPE_ARRAY_MEMBER_DESC_ALLOCA]], i32 0, i32 7, i64 0, i32 1 +!CHECK: %[[LOAD_DESC_MEMBER_UB:.*]] = load i64, ptr %[[ACCESS_DESC_MEMBER_UB]], align 8 +!CHECK: %[[OFFSET_MEMBER_UB:.*]] = sub i64 %[[LOAD_DESC_MEMBER_UB]], 1 !CHECK: %[[DTYPE_ALLOCA_MEMBER_BASE_ADDR_ACCESS:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[DTYPE_ALLOCA_MEMBER_ACCESS]], i32 0, i32 0 !CHECK: %[[DTYPE_BASE_ADDR_ACCESS_2:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, ptr %[[DTYPE_DESC_ALLOCA]], i32 0, i32 0 !CHECK: %[[DTYPE_BASE_ADDR_LOAD_2:.*]] = load ptr, ptr %[[DTYPE_BASE_ADDR_ACCESS_2]], align 8 @@ -729,13 +729,12 @@ end subroutine mapType_common_block_members !CHECK: %[[ALLOCA_1:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8 !CHECK: %[[ALLOCA:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, align 8 !CHECK: %[[BASE_PTR_1:.*]] = alloca %_QFmaptype_nested_derived_type_member_idxTdtype, i64 1, align 8 -!CHECK: %{{.*}} = getelementptr %_QFmaptype_nested_derived_type_member_idxTdtype, ptr %[[BASE_PTR_1]], i32 0, i32 1 +!CHECK: %[[OFF_PTR_1:.*]] = getelementptr %_QFmaptype_nested_derived_type_member_idxTdtype, ptr %[[BASE_PTR_1]], i32 0, i32 1 !CHECK: %[[BOUNDS_ACC:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, ptr %[[ALLOCA]], i32 0, i32 7, i64 0, i32 1 !CHECK: %[[BOUNDS_LD:.*]] = load i64, ptr %[[BOUNDS_ACC]], align 8 !CHECK: %[[BOUNDS_ACC_2:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[ALLOCA_1]], i32 0, i32 7, i64 0, i32 1 !CHECK: %[[BOUNDS_LD_2:.*]] = load i64, ptr %[[BOUNDS_ACC_2]], align 8 !CHECK: %[[BOUNDS_CALC:.*]] = sub i64 %[[BOUNDS_LD_2]], 1 -!CHECK: %[[OFF_PTR_1:.*]] = getelementptr %_QFmaptype_nested_derived_type_member_idxTdtype, ptr %[[BASE_PTR_1]], i32 0, i32 1 !CHECK: %[[OFF_PTR_CALC_0:.*]] = sub i64 %[[BOUNDS_LD]], 1 !CHECK: %[[OFF_PTR_2:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, ptr %[[OFF_PTR_1]], i32 0, i32 0 !CHECK: %[[GEP_DESC_PTR:.*]] = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, ptr %[[ALLOCA_0]], i32 0, i32 0 diff --git a/flang/test/Lower/OpenMP/declare-mapper.f90 b/flang/test/Lower/OpenMP/declare-mapper.f90 index fa7f23c182a68..e12becbc5d9a9 100644 --- a/flang/test/Lower/OpenMP/declare-mapper.f90 +++ b/flang/test/Lower/OpenMP/declare-mapper.f90 @@ -39,8 +39,7 @@ subroutine declare_mapper_1 !CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i64) -> index !CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_6]]#0 : index !CHECK: %[[VAL_16:.*]] = omp.map.bounds lower_bound(%[[VAL_10]] : index) upper_bound(%[[VAL_15]] : index) extent(%[[VAL_6]]#1 : index) stride(%[[VAL_8]] : index) start_idx(%[[VAL_6]]#0 : index) - !CHECK: %[[VAL_17:.*]] = arith.constant 1 : index - !CHECK: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_1]]#0, %[[VAL_17]] : (!fir.ref<[[MY_TYPE]]>, index) -> !fir.ref>>> + !CHECK: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_1]]#0, values : (!fir.ref<[[MY_TYPE]]>) -> !fir.ref>>> !CHECK: %[[VAL_19:.*]] = fir.box_offset %[[VAL_18]] base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> !CHECK: %[[VAL_20:.*]] = omp.map.info var_ptr(%[[VAL_18]] : !fir.ref>>>, i32) var_ptr_ptr(%[[VAL_19]] : !fir.llvm_ptr>>) map_clauses(tofrom) capture(ByRef) bounds(%[[VAL_16]]) -> !fir.llvm_ptr>> {name = ""} !CHECK: %[[VAL_21:.*]] = omp.map.info var_ptr(%[[VAL_18]] : !fir.ref>>>, !fir.box>>) map_clauses(to) capture(ByRef) -> !fir.ref>>> {name = "var%[[VAL_22:.*]](1:var%[[VAL_23:.*]])"} @@ -132,8 +131,7 @@ subroutine declare_mapper_3 !CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i64) -> index !CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_6]]#0 : index !CHECK: %[[VAL_16:.*]] = omp.map.bounds lower_bound(%[[VAL_10]] : index) upper_bound(%[[VAL_15]] : index) extent(%[[VAL_6]]#1 : index) stride(%[[VAL_8]] : index) start_idx(%[[VAL_6]]#0 : index) - !CHECK: %[[VAL_17:.*]] = arith.constant 1 : index - !CHECK: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_1]]#0, %[[VAL_17]] : (!fir.ref<[[MY_TYPE]]>, index) -> !fir.ref>>> + !CHECK: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_1]]#0, values : (!fir.ref<[[MY_TYPE]]>) -> !fir.ref>>> !CHECK: %[[VAL_19:.*]] = fir.box_offset %[[VAL_18]] base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> !CHECK: %[[VAL_20:.*]] = omp.map.info var_ptr(%[[VAL_18]] : !fir.ref>>>, i32) var_ptr_ptr(%[[VAL_19]] : !fir.llvm_ptr>>) map_clauses(tofrom) capture(ByRef) bounds(%[[VAL_16]]) -> !fir.llvm_ptr>> {name = ""} !CHECK: %[[VAL_21:.*]] = omp.map.info var_ptr(%[[VAL_18]] : !fir.ref>>>, !fir.box>>) map_clauses(to) capture(ByRef) -> !fir.ref>>> {name = "var%[[VAL_22:.*]](1:var%[[VAL_23:.*]])"} diff --git a/flang/test/Lower/OpenMP/derived-type-allocatable-map.f90 b/flang/test/Lower/OpenMP/derived-type-allocatable-map.f90 index 28a2b9b5b967b..768d782848b53 100644 --- a/flang/test/Lower/OpenMP/derived-type-allocatable-map.f90 +++ b/flang/test/Lower/OpenMP/derived-type-allocatable-map.f90 @@ -3,8 +3,7 @@ !CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.type<[[ONE_LAYER_TY:_QFdtype_alloca_map_op_blockTone_layer{i:f32,scalar:!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32}]]> {{.*}} !CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {{{.*}}} : (!fir.ref>) -> (!fir.ref>, !fir.ref>) !CHECK: %[[BOUNDS:.*]] = omp.map.bounds lower_bound({{.*}}) upper_bound({{.*}}) extent({{.*}}) stride({{.*}}) start_idx({{.*}}) {stride_in_bytes = true} -!CHECK: %[[MEMBER_INDEX:.*]] = arith.constant 4 : index -!CHECK: %[[MEMBER_COORD:.*]] = fir.coordinate_of %[[DECLARE]]#0, %[[MEMBER_INDEX]] : (!fir.ref>, index) -> !fir.ref>>> +!CHECK: %[[MEMBER_COORD:.*]] = fir.coordinate_of %[[DECLARE]]#0, array_j : (!fir.ref>) -> !fir.ref>>> !CHECK: %[[MEMBER_BASE_ADDR:.*]] = fir.box_offset %[[MEMBER_COORD]] base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> !CHECK: %[[MAP_MEMBER_BASE_ADDR:.*]] = omp.map.info var_ptr(%[[MEMBER_COORD]] : !fir.ref>>>, i32) var_ptr_ptr(%[[MEMBER_BASE_ADDR]] : !fir.llvm_ptr>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !fir.llvm_ptr>> {{.*}} !CHECK: %[[MAP_MEMBER_DESCRIPTOR:.*]] = omp.map.info var_ptr(%[[MEMBER_COORD]] : !fir.ref>>>, !fir.box>>) map_clauses(to) capture(ByRef) -> !fir.ref>>> {{.*}} @@ -34,14 +33,12 @@ subroutine dtype_alloca_map_op_block() !CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {{{.*}}} : (!fir.ref>>>) -> (!fir.ref>>>, !fir.ref>>>) !CHECK: %[[BOUNDS:.*]] = omp.map.bounds lower_bound({{.*}}) upper_bound({{.*}}) extent({{.*}}) stride({{.*}}) start_idx({{.*}}) {stride_in_bytes = true} !CHECK: %[[LOAD_DTYPE:.*]] = fir.load %[[DECLARE]]#0 : !fir.ref>>> -!CHECK: %[[MEMBER_INDEX:.*]] = arith.constant 4 : index -!CHECK: %[[MEMBER_COORD:.*]] = fir.coordinate_of %[[LOAD_DTYPE]], %[[MEMBER_INDEX]] : (!fir.box>>, index) -> !fir.ref>>> +!CHECK: %[[MEMBER_COORD:.*]] = fir.coordinate_of %[[LOAD_DTYPE]], array_j : (!fir.box>>) -> !fir.ref>>> !CHECK: %[[MEMBER_BASE_ADDR:.*]] = fir.box_offset %[[MEMBER_COORD]] base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> !CHECK: %[[MAP_MEMBER_BASE_ADDR:.*]] = omp.map.info var_ptr(%[[MEMBER_COORD]] : !fir.ref>>>, i32) var_ptr_ptr(%[[MEMBER_BASE_ADDR]] : !fir.llvm_ptr>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !fir.llvm_ptr>> {{.*}} !CHECK: %[[MAP_MEMBER_DESC:.*]] = omp.map.info var_ptr(%[[MEMBER_COORD]] : !fir.ref>>>, !fir.box>>) map_clauses(to) capture(ByRef) -> !fir.ref>>> {{.*}} !CHECK: %[[LOAD_DTYPE:.*]] = fir.load %[[DECLARE]]#0 : !fir.ref>>> -!CHECK: %[[MEMBER_COORD:.*]] = arith.constant 5 : index -!CHECK: %[[REGULAR_MEMBER:.*]] = fir.coordinate_of %[[LOAD_DTYPE]], %[[MEMBER_COORD]] : (!fir.box>>, index) -> !fir.ref +!CHECK: %[[REGULAR_MEMBER:.*]] = fir.coordinate_of %[[LOAD_DTYPE]], k : (!fir.box>>) -> !fir.ref !CHECK: %[[MAP_REGULAR_MEMBER:.*]] = omp.map.info var_ptr(%[[REGULAR_MEMBER]] : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {{.*}} !CHECK: %[[DTYPE_BASE_ADDR:.*]] = fir.box_offset %[[DECLARE]]#1 base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> !CHECK: %[[MAP_DTYPE_BASE_ADDR:.*]] = omp.map.info var_ptr(%[[DECLARE]]#1 : !fir.ref>>>, !fir.type<[[REC_TY]]>) var_ptr_ptr(%[[DTYPE_BASE_ADDR]] : !fir.llvm_ptr>>) map_clauses(tofrom) capture(ByRef) -> !fir.llvm_ptr>> {{.*}} @@ -73,18 +70,14 @@ subroutine alloca_dtype_op_block_add() !CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA]] {{.*}} : (!fir.ref}>>>>) -> (!fir.ref}>>>>, !fir.ref}>>>>) !CHECK: %[[BOUNDS:.*]] = omp.map.bounds lower_bound({{.*}}) upper_bound({{.*}}) extent({{.*}}) stride({{.*}}) start_idx({{.*}}) {stride_in_bytes = true} !CHECK: %[[LOAD:.*]] = fir.load %[[DECLARE]]#0 : !fir.ref}>>>> -!CHECK: %[[NESTED_DTYPE_INDEX:.*]] = arith.constant 6 : index -!CHECK: %[[NESTED_DTYPE_COORD:.*]] = fir.coordinate_of %[[LOAD]], %[[NESTED_DTYPE_INDEX]] : (!fir.box}>>>, index) -> !fir.ref,array_k:!fir.box>>,k:i32}]]>> -!CHECK: %[[NESTED_MEMBER_INDEX:.*]] = arith.constant 2 : index -!CHECK: %[[NESTED_MEMBER_COORD:.*]] = fir.coordinate_of %[[NESTED_DTYPE_COORD]], %[[NESTED_MEMBER_INDEX]] : (!fir.ref>, index) -> !fir.ref>>> +!CHECK: %[[NESTED_DTYPE_COORD:.*]] = fir.coordinate_of %[[LOAD]], nest : (!fir.box}>>>) -> !fir.ref,array_k:!fir.box>>,k:i32}]]>> +!CHECK: %[[NESTED_MEMBER_COORD:.*]] = fir.coordinate_of %[[NESTED_DTYPE_COORD]], array_k : (!fir.ref>) -> !fir.ref>>> !CHECK: %[[NESTED_MEMBER_BASE_ADDR:.*]] = fir.box_offset %[[NESTED_MEMBER_COORD]] base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> !CHECK: %[[MAP_NESTED_MEMBER_BASE_ADDR:.*]] = omp.map.info var_ptr(%[[NESTED_MEMBER_COORD]] : !fir.ref>>>, i32) var_ptr_ptr(%[[NESTED_MEMBER_BASE_ADDR]] : !fir.llvm_ptr>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !fir.llvm_ptr>> {{.*}} !CHECK: %[[MAP_NESTED_MEMBER_COORD:.*]] = omp.map.info var_ptr(%[[NESTED_MEMBER_COORD]] : !fir.ref>>>, !fir.box>>) map_clauses(to) capture(ByRef) -> !fir.ref>>> {{.*}} !CHECK: %[[LOAD:.*]] = fir.load %[[DECLARE]]#0 : !fir.ref}>>>> -!CHECK: %[[NESTED_DTYPE_INDEX:.*]] = arith.constant 6 : index -!CHECK: %[[NESTED_DTYPE_COORD:.*]] = fir.coordinate_of %[[LOAD]], %[[NESTED_DTYPE_INDEX]] : (!fir.box}>>>, index) -> !fir.ref> -!CHECK: %[[NESTED_MEMBER_INDEX:.*]] = arith.constant 3 : index -!CHECK: %[[REGULAR_NESTED_MEMBER_COORD:.*]] = fir.coordinate_of %[[NESTED_DTYPE_COORD]], %[[NESTED_MEMBER_INDEX]] : (!fir.ref>, index) -> !fir.ref +!CHECK: %[[NESTED_DTYPE_COORD:.*]] = fir.coordinate_of %[[LOAD]], nest : (!fir.box}>>>) -> !fir.ref> +!CHECK: %[[REGULAR_NESTED_MEMBER_COORD:.*]] = fir.coordinate_of %[[NESTED_DTYPE_COORD]], k : (!fir.ref>) -> !fir.ref !CHECK: %[[MAP_REGULAR_NESTED_MEMBER:.*]] = omp.map.info var_ptr(%[[REGULAR_NESTED_MEMBER_COORD]] : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {{.*}} !CHECK: %[[DTYPE_BASE_ADDR:.*]] = fir.box_offset %[[DECLARE]]#1 base_addr : (!fir.ref}>>>>) -> !fir.llvm_ptr}>>> !CHECK: %[[MAP_DTYPE_BASE_ADDR:.*]] = omp.map.info var_ptr(%[[DECLARE]]#1 : !fir.ref}>>>>, !fir.type<[[REC_TY]]>}>) var_ptr_ptr(%[[DTYPE_BASE_ADDR]] : !fir.llvm_ptr}>>>) map_clauses(tofrom) capture(ByRef) -> !fir.llvm_ptr}>>> {{.*}} @@ -123,10 +116,8 @@ subroutine alloca_nest_dype_map_op_block_add() !CHECK: %[[ALLOCA]] = fir.alloca !fir.type<[[REC_TY:_QFnest_dtype_alloca_map_op_block_addTtop_layer{i:f32,scalar:!fir.box>,array_i:!fir.array<10xi32>,j:f32,array_j:!fir.box>>,k:i32,nest:!fir.type<_QFnest_dtype_alloca_map_op_block_addTmiddle_layer{i:f32,array_i:!fir.array<10xi32>,array_k:!fir.box>>,k:i32}>}]]> {{.*}} !CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOCA:.*]] {{.*}} : (!fir.ref>) -> (!fir.ref>, !fir.ref>) !CHECK: %[[BOUNDS:.*]] = omp.map.bounds lower_bound({{.*}}) upper_bound({{.*}}) extent({{.*}}) stride({{.*}}) start_idx({{.*}}) {stride_in_bytes = true} -!CHECK: %[[NESTED_DTYPE_INDEX:.*]] = arith.constant 6 : index -!CHECK: %[[NESTED_DTYPE_COORD:.*]] = fir.coordinate_of %[[DECLARE]]#0, %[[NESTED_DTYPE_INDEX]] : (!fir.ref>, index) -> !fir.ref,array_k:!fir.box>>,k:i32}]]>> -!CHECK: %[[NESTED_MEMBER_INDEX:.*]] = arith.constant 2 : index -!CHECK: %[[NESTED_MEMBER_COORD:.*]] = fir.coordinate_of %[[NESTED_DTYPE_COORD]], %[[NESTED_MEMBER_INDEX]] : (!fir.ref>, index) -> !fir.ref>>> +!CHECK: %[[NESTED_DTYPE_COORD:.*]] = fir.coordinate_of %[[DECLARE]]#0, nest : (!fir.ref>) -> !fir.ref,array_k:!fir.box>>,k:i32}]]>> +!CHECK: %[[NESTED_MEMBER_COORD:.*]] = fir.coordinate_of %[[NESTED_DTYPE_COORD]], array_k : (!fir.ref>) -> !fir.ref>>> !CHECK: %[[NESTED_MEMBER_BASE_ADDR:.*]] = fir.box_offset %[[NESTED_MEMBER_COORD]] base_addr : (!fir.ref>>>) -> !fir.llvm_ptr>> !CHECK: %[[MAP_NESTED_MEMBER_BASE_ADDR:.*]] = omp.map.info var_ptr(%[[NESTED_MEMBER_COORD]] : !fir.ref>>>, i32) var_ptr_ptr(%[[NESTED_MEMBER_BASE_ADDR]] : !fir.llvm_ptr>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !fir.llvm_ptr>> {{.*}} !CHECK: %[[MAP_NESTED_MEMBER_DESC:.*]] = omp.map.info var_ptr(%[[NESTED_MEMBER_COORD]] : !fir.ref>>>, !fir.box>>) map_clauses(to) capture(ByRef) -> !fir.ref>>> {{.*}} diff --git a/flang/test/Transforms/omp-map-info-finalization-implicit-field.fir b/flang/test/Transforms/omp-map-info-finalization-implicit-field.fir index bcf8b63075dbf..121ee553b51e2 100644 --- a/flang/test/Transforms/omp-map-info-finalization-implicit-field.fir +++ b/flang/test/Transforms/omp-map-info-finalization-implicit-field.fir @@ -28,7 +28,7 @@ func.func @_QQmain() { } // CHECK: %[[RECORD_DECL:.*]]:2 = hlfir.declare %0 {uniq_name = "_QFEdst_record"} -// CHECK: %[[FIELD_COORD:.*]] = fir.coordinate_of %[[RECORD_DECL]]#1, %{{c1.*}} +// CHECK: %[[FIELD_COORD:.*]] = fir.coordinate_of %[[RECORD_DECL]]#1, to_implicitly_map // CHECK: %[[UPPER_BOUND:.*]] = arith.subi %{{.*}}#1, %{{c1.*}} : index