[flang-commits] [flang] [flang][debug] Support assumed shape arrays. (PR #94644)

via flang-commits flang-commits at lists.llvm.org
Fri Jun 7 08:02:55 PDT 2024


================
@@ -22,6 +26,60 @@ namespace fir {
 DebugTypeGenerator::DebugTypeGenerator(mlir::ModuleOp m)
     : module(m), kindMapping(getKindMapping(m)) {
   LLVM_DEBUG(llvm::dbgs() << "DITypeAttr generator\n");
+
+  std::optional<mlir::DataLayout> dl =
+      fir::support::getOrSetDataLayout(module, /*allowDefaultLayout=*/true);
+  if (!dl)
+    mlir::emitError(module.getLoc(), "Missing data layout attribute in module");
+
+  mlir::MLIRContext *context = module.getContext();
+
+  // The debug information requires the offset of certain fields in the
+  // descriptors like lower_bound and extent for each dimension. The code
+  // below uses getDescFieldTypeModel to get the type representing each field
+  // and then use data layout to get its size. It adds the size to get the
+  // offset.
+  // As has been mentioned in DescriptorModel.h that code may be confusing
+  // host for the target in calculating the type of the descriptor fields. But
+  // debug info is using similar logic to what codegen is doing so it will
+  // atleast be representing the generated code correctly.
+  // My testing for a 32-bit shows that base_addr* is correctly given as a
+  // 32-bit entity. The index types are 64-bit so I am a bit uncertain how
+  // the alignment will effect the calculation of offsets in that case.
+
+  // base_addr*
+  dimsOffset =
+      dl->getTypeSizeInBits(getDescFieldTypeModel<kAddrPosInBox>()(context));
+
+  // elem_len
+  dimsOffset +=
+      dl->getTypeSizeInBits(getDescFieldTypeModel<kElemLenPosInBox>()(context));
+
+  // version
+  dimsOffset +=
+      dl->getTypeSizeInBits(getDescFieldTypeModel<kVersionPosInBox>()(context));
+
+  // rank
+  dimsOffset +=
+      dl->getTypeSizeInBits(getDescFieldTypeModel<kRankPosInBox>()(context));
+
+  // type
+  dimsOffset +=
+      dl->getTypeSizeInBits(getDescFieldTypeModel<kTypePosInBox>()(context));
+
+  // attribute
+  dimsOffset += dl->getTypeSizeInBits(
+      getDescFieldTypeModel<kAttributePosInBox>()(context));
+
+  // f18Addendum
+  dimsOffset += dl->getTypeSizeInBits(
+      getDescFieldTypeModel<kF18AddendumPosInBox>()(context));
+
+  // dims
+  dimsSize =
+      dl->getTypeSizeInBits(getDescFieldTypeModel<kDimsPosInBox>()(context));
----------------
jeanPerier wrote:

You can directly use getTypeSize() to avoid the /8 I think.

https://github.com/llvm/llvm-project/pull/94644


More information about the flang-commits mailing list