[flang-commits] [flang] [flang][debug] Support fir.vector type. (PR #112951)
via flang-commits
flang-commits at lists.llvm.org
Fri Oct 18 11:15:00 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Abid Qadeer (abidh)
<details>
<summary>Changes</summary>
This PR converts the `fir.vector<>` to `DICompositeTypeAttr(DW_TAG_array_type)` with `vector` flag set.
---
Full diff: https://github.com/llvm/llvm-project/pull/112951.diff
3 Files Affected:
- (modified) flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp (+27)
- (modified) flang/lib/Optimizer/Transforms/DebugTypeGenerator.h (+4)
- (added) flang/test/Transforms/debug-vector-type.fir (+23)
``````````diff
diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
index 71e534b4f2e2a3..2845f0c9394988 100644
--- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
+++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
@@ -401,6 +401,31 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
/*associated=*/nullptr);
}
+mlir::LLVM::DITypeAttr DebugTypeGenerator::convertVectorType(
+ fir::VectorType vecTy, mlir::LLVM::DIFileAttr fileAttr,
+ mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp) {
+ mlir::MLIRContext *context = module.getContext();
+
+ llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
+ mlir::LLVM::DITypeAttr elemTy =
+ convertType(vecTy.getEleTy(), fileAttr, scope, declOp);
+ auto intTy = mlir::IntegerType::get(context, 64);
+ auto countAttr =
+ mlir::IntegerAttr::get(intTy, llvm::APInt(64, vecTy.getLen()));
+ auto subrangeTy = mlir::LLVM::DISubrangeAttr::get(
+ context, countAttr, /*lowerBound=*/nullptr, /*upperBound=*/nullptr,
+ /*stride=*/nullptr);
+ elements.push_back(subrangeTy);
+ mlir::Type llvmTy = llvmTypeConverter.convertType(vecTy.getEleTy());
+ uint64_t sizeInBits = dataLayout->getTypeSize(llvmTy) * vecTy.getLen() * 8;
+ return mlir::LLVM::DICompositeTypeAttr::get(
+ context, llvm::dwarf::DW_TAG_array_type, /*name=*/nullptr,
+ /*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
+ mlir::LLVM::DIFlags::Vector, sizeInBits, /*alignInBits=*/0, elements,
+ /*dataLocation=*/nullptr, /*rank=*/nullptr, /*allocated=*/nullptr,
+ /*associated=*/nullptr);
+}
+
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
fir::CharacterType charTy, mlir::LLVM::DIFileAttr fileAttr,
mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp,
@@ -511,6 +536,8 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
/*hasDescriptor=*/false);
} else if (auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(Ty)) {
return convertRecordType(recTy, fileAttr, scope, declOp);
+ } else if (auto vecTy = mlir::dyn_cast_or_null<fir::VectorType>(Ty)) {
+ return convertVectorType(vecTy, fileAttr, scope, declOp);
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(Ty)) {
auto elTy = boxTy.getElementType();
if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(elTy))
diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.h b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.h
index ff600e751eb0b1..eeefb6c463d936 100644
--- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.h
+++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.h
@@ -43,6 +43,10 @@ class DebugTypeGenerator {
mlir::LLVM::DIFileAttr fileAttr,
mlir::LLVM::DIScopeAttr scope,
fir::cg::XDeclareOp declOp);
+ mlir::LLVM::DITypeAttr convertVectorType(fir::VectorType vecTy,
+ mlir::LLVM::DIFileAttr fileAttr,
+ mlir::LLVM::DIScopeAttr scope,
+ fir::cg::XDeclareOp declOp);
/// The 'genAllocated' is true when we want to generate 'allocated' field
/// in the DICompositeType. It is needed for the allocatable arrays.
diff --git a/flang/test/Transforms/debug-vector-type.fir b/flang/test/Transforms/debug-vector-type.fir
new file mode 100644
index 00000000000000..01f68d87286dcf
--- /dev/null
+++ b/flang/test/Transforms/debug-vector-type.fir
@@ -0,0 +1,23 @@
+// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
+
+module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
+func.func private @foo1(%arg0: !fir.vector<20:bf16>)
+// CHECK-DAG: #[[F16:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 16, encoding = DW_ATE_float>
+// CHECK-DAG: #llvm.di_composite_type<tag = DW_TAG_array_type, baseType = #[[F16]], flags = Vector, sizeInBits = 320, elements = #llvm.di_subrange<count = 20 : i64>>
+
+func.func private @foo2(%arg0: !fir.vector<30:f32>)
+// CHECK-DAG: #[[F32:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 32, encoding = DW_ATE_float>
+// CHECK-DAG: #llvm.di_composite_type<tag = DW_TAG_array_type, baseType = #[[F32]], flags = Vector, sizeInBits = 960, elements = #llvm.di_subrange<count = 30 : i64>>
+
+func.func private @foo3(%arg0: !fir.vector<10:f64>)
+// CHECK-DAG: #[[F64:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 64, encoding = DW_ATE_float>
+// CHECK-DAG: #llvm.di_composite_type<tag = DW_TAG_array_type, baseType = #[[F64]], flags = Vector, sizeInBits = 640, elements = #llvm.di_subrange<count = 10 : i64>>
+
+func.func private @foo4(%arg0: !fir.vector<5:i32>)
+// CHECK-DAG: #[[I32:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
+// CHECK-DAG: #llvm.di_composite_type<tag = DW_TAG_array_type, baseType = #[[I32]], flags = Vector, sizeInBits = 160, elements = #llvm.di_subrange<count = 5 : i64>>
+
+func.func private @foo5(%arg0: !fir.vector<2:i64>)
+// CHECK-DAG: #[[I64:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 64, encoding = DW_ATE_signed>
+// CHECK-DAG: #llvm.di_composite_type<tag = DW_TAG_array_type, baseType = #[[I64]], flags = Vector, sizeInBits = 128, elements = #llvm.di_subrange<count = 2 : i64>>
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/112951
More information about the flang-commits
mailing list