diff options
Diffstat (limited to 'flang/lib/Optimizer/CodeGen/CodeGen.cpp')
| -rw-r--r-- | flang/lib/Optimizer/CodeGen/CodeGen.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 99f1453f1314..7934f1fdad2a 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -23,6 +23,8 @@ #include "flang/Optimizer/Support/InternalNames.h" #include "flang/Optimizer/Support/TypeCode.h" #include "flang/Optimizer/Support/Utils.h" +#include "flang/Runtime/allocator-registry.h" +#include "flang/Runtime/descriptor.h" #include "flang/Semantics/runtime-type-info.h" #include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h" #include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h" @@ -1224,8 +1226,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> { fir::BaseBoxType boxTy, mlir::Type inputType, mlir::ConversionPatternRewriter &rewriter, unsigned rank, mlir::Value eleSize, - mlir::Value cfiTy, - mlir::Value typeDesc) const { + mlir::Value cfiTy, mlir::Value typeDesc, + int allocatorIdx = kDefaultAllocator) const { auto llvmBoxTy = this->lowerTy().convertBoxTypeAsStruct(boxTy, rank); bool isUnlimitedPolymorphic = fir::isUnlimitedPolymorphicType(boxTy); bool useInputType = fir::isPolymorphicType(boxTy) || isUnlimitedPolymorphic; @@ -1241,10 +1243,19 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> { descriptor = insertField(rewriter, loc, descriptor, {kAttributePosInBox}, this->genI32Constant(loc, rewriter, getCFIAttr(boxTy))); + const bool hasAddendum = fir::boxHasAddendum(boxTy); + + // Descriptor used to set the correct value of the extra field. + Fortran::runtime::StaticDescriptor<0> staticDescriptor; + Fortran::runtime::Descriptor &desc{staticDescriptor.descriptor()}; + desc.raw().extra = 0; + desc.SetAllocIdx(allocatorIdx); + if (hasAddendum) + desc.SetHasAddendum(); descriptor = - insertField(rewriter, loc, descriptor, {kF18AddendumPosInBox}, - this->genI32Constant(loc, rewriter, hasAddendum ? 1 : 0)); + insertField(rewriter, loc, descriptor, {kExtraPosInBox}, + this->genI32Constant(loc, rewriter, desc.raw().extra)); if (hasAddendum) { unsigned typeDescFieldId = getTypeDescFieldId(boxTy); @@ -1299,6 +1310,13 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> { typeparams.push_back(substrParams[1]); } + int allocatorIdx = 0; + if constexpr (std::is_same_v<BOX, fir::EmboxOp> || + std::is_same_v<BOX, fir::cg::XEmboxOp>) { + if (box.getAllocatorIdx()) + allocatorIdx = *box.getAllocatorIdx(); + } + // Write each of the fields with the appropriate values. // When emboxing an element to a polymorphic descriptor, use the // input type since the destination descriptor type has not the exact @@ -1320,8 +1338,9 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> { cfiTy.getType(), rewriter, kTypePosInBox); } auto mod = box->template getParentOfType<mlir::ModuleOp>(); - mlir::Value descriptor = populateDescriptor( - loc, mod, boxTy, inputType, rewriter, rank, eleSize, cfiTy, typeDesc); + mlir::Value descriptor = + populateDescriptor(loc, mod, boxTy, inputType, rewriter, rank, eleSize, + cfiTy, typeDesc, allocatorIdx); return {boxTy, descriptor, eleSize}; } |
