[flang-commits] [flang] [flang][NFC] do not copy fields in fir::RecordType::getTypeList (PR #145530)
via flang-commits
flang-commits at lists.llvm.org
Tue Jun 24 08:18:26 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: None (jeanPerier)
<details>
<summary>Changes</summary>
For historical reason, `fir::RecordType::getTypeList` was returning an std::vector, causing the entire field list to be copied when called.
It is called a lot indirectly in all type helpers, which themselves are called a lot in derived type heavy code like WRF.
The `fir::hasDynamicType` helper is also called a lot, and it can just check for length parameters to avoid looping on all derived type components in most cases.
This fix should speed-up WRF compilation by 10-30%.
---
Full diff: https://github.com/llvm/llvm-project/pull/145530.diff
2 Files Affected:
- (modified) flang/include/flang/Optimizer/Dialect/FIRTypes.td (+2-1)
- (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+4-2)
``````````diff
diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index 6fad77dffd9bc..0ead54df3ca97 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -330,7 +330,8 @@ def fir_RecordType : FIR_Type<"Record", "type"> {
let extraClassDeclaration = [{
using TypePair = std::pair<std::string, mlir::Type>;
- using TypeList = std::vector<TypePair>;
+ using TypeList = llvm::ArrayRef<TypePair>;
+ using TypeVector = llvm::SmallVector<TypePair>;
TypeList getTypeList() const;
TypeList getLenParamList() const;
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 78571f1f4bc2d..2ff1d6d945ba3 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -261,6 +261,8 @@ mlir::Type dyn_cast_ptrOrBoxEleTy(mlir::Type t) {
}
static bool hasDynamicSize(fir::RecordType recTy) {
+ if (recTy.getLenParamList().empty())
+ return false;
for (auto field : recTy.getTypeList()) {
if (auto arr = mlir::dyn_cast<fir::SequenceType>(field.second)) {
if (sequenceWithNonConstantShape(arr))
@@ -1006,7 +1008,7 @@ mlir::Type fir::RecordType::parse(mlir::AsmParser &parser) {
return {};
RecordType result = RecordType::get(parser.getContext(), name);
- RecordType::TypeList lenParamList;
+ RecordType::TypeVector lenParamList;
if (!parser.parseOptionalLParen()) {
while (true) {
llvm::StringRef lenparam;
@@ -1024,7 +1026,7 @@ mlir::Type fir::RecordType::parse(mlir::AsmParser &parser) {
return {};
}
- RecordType::TypeList typeList;
+ RecordType::TypeVector typeList;
if (!parser.parseOptionalLess()) {
result.pack(true);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/145530
More information about the flang-commits
mailing list