[flang][NFC] do not copy fields in fir::RecordType::getTypeList (#145530)
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 commit is contained in:
@@ -330,7 +330,8 @@ def fir_RecordType : FIR_Type<"Record", "type"> {
|
|||||||
|
|
||||||
let extraClassDeclaration = [{
|
let extraClassDeclaration = [{
|
||||||
using TypePair = std::pair<std::string, mlir::Type>;
|
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 getTypeList() const;
|
||||||
TypeList getLenParamList() const;
|
TypeList getLenParamList() const;
|
||||||
|
|
||||||
|
|||||||
@@ -261,6 +261,8 @@ mlir::Type dyn_cast_ptrOrBoxEleTy(mlir::Type t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool hasDynamicSize(fir::RecordType recTy) {
|
static bool hasDynamicSize(fir::RecordType recTy) {
|
||||||
|
if (recTy.getLenParamList().empty())
|
||||||
|
return false;
|
||||||
for (auto field : recTy.getTypeList()) {
|
for (auto field : recTy.getTypeList()) {
|
||||||
if (auto arr = mlir::dyn_cast<fir::SequenceType>(field.second)) {
|
if (auto arr = mlir::dyn_cast<fir::SequenceType>(field.second)) {
|
||||||
if (sequenceWithNonConstantShape(arr))
|
if (sequenceWithNonConstantShape(arr))
|
||||||
@@ -1006,7 +1008,7 @@ mlir::Type fir::RecordType::parse(mlir::AsmParser &parser) {
|
|||||||
return {};
|
return {};
|
||||||
RecordType result = RecordType::get(parser.getContext(), name);
|
RecordType result = RecordType::get(parser.getContext(), name);
|
||||||
|
|
||||||
RecordType::TypeList lenParamList;
|
RecordType::TypeVector lenParamList;
|
||||||
if (!parser.parseOptionalLParen()) {
|
if (!parser.parseOptionalLParen()) {
|
||||||
while (true) {
|
while (true) {
|
||||||
llvm::StringRef lenparam;
|
llvm::StringRef lenparam;
|
||||||
@@ -1024,7 +1026,7 @@ mlir::Type fir::RecordType::parse(mlir::AsmParser &parser) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordType::TypeList typeList;
|
RecordType::TypeVector typeList;
|
||||||
if (!parser.parseOptionalLess()) {
|
if (!parser.parseOptionalLess()) {
|
||||||
result.pack(true);
|
result.pack(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1817,8 +1817,8 @@ func.func private @custom_typeP.field_1.offset() -> i32
|
|||||||
func.func private @custom_typeP.field_2.offset() -> i32
|
func.func private @custom_typeP.field_2.offset() -> i32
|
||||||
|
|
||||||
func.func @field_index_dynamic_size() -> () {
|
func.func @field_index_dynamic_size() -> () {
|
||||||
%1 = fir.field_index field_1, !fir.type<custom_type{field_1:i32, field_2:!fir.array<?xf32>}>
|
%1 = fir.field_index field_1, !fir.type<custom_type(l:i32){field_1:i32, field_2:!fir.array<?xf32>}>
|
||||||
%2 = fir.field_index field_2, !fir.type<custom_type{field_1:i32, field_2:!fir.array<?xf32>}>
|
%2 = fir.field_index field_2, !fir.type<custom_type(l:i32){field_1:i32, field_2:!fir.array<?xf32>}>
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user