@@ -145,11 +145,10 @@ static bool isConstant(const Fortran::semantics::Symbol &sym) {
145
145
sym.test (Fortran::semantics::Symbol::Flag::ReadOnly);
146
146
}
147
147
148
- static fir::GlobalOp defineGlobal (Fortran::lower::AbstractConverter &converter,
149
- const Fortran::lower::pft::Variable &var,
150
- llvm::StringRef globalName,
151
- mlir::StringAttr linkage,
152
- cuf::DataAttributeAttr dataAttr = {});
148
+ // / Call \p genInit to generate code inside \p global initializer region.
149
+ static void
150
+ createGlobalInitialization (fir::FirOpBuilder &builder, fir::GlobalOp global,
151
+ std::function<void (fir::FirOpBuilder &)> genInit);
153
152
154
153
static mlir::Location genLocation (Fortran::lower::AbstractConverter &converter,
155
154
const Fortran::semantics::Symbol &sym) {
@@ -467,9 +466,9 @@ static bool globalIsInitialized(fir::GlobalOp global) {
467
466
}
468
467
469
468
// / Call \p genInit to generate code inside \p global initializer region.
470
- void Fortran::lower::createGlobalInitialization (
471
- fir::FirOpBuilder &builder, fir::GlobalOp global,
472
- std::function<void (fir::FirOpBuilder &)> genInit) {
469
+ static void
470
+ createGlobalInitialization ( fir::FirOpBuilder &builder, fir::GlobalOp global,
471
+ std::function<void (fir::FirOpBuilder &)> genInit) {
473
472
mlir::Region ®ion = global.getRegion ();
474
473
region.push_back (new mlir::Block);
475
474
mlir::Block &block = region.back ();
@@ -479,7 +478,7 @@ void Fortran::lower::createGlobalInitialization(
479
478
builder.restoreInsertionPoint (insertPt);
480
479
}
481
480
482
- static unsigned getAllocatorIdx (cuf::DataAttributeAttr dataAttr) {
481
+ static unsigned getAllocatorIdxFromDataAttr (cuf::DataAttributeAttr dataAttr) {
483
482
if (dataAttr) {
484
483
if (dataAttr.getValue () == cuf::DataAttribute::Pinned)
485
484
return kPinnedAllocatorPos ;
@@ -494,11 +493,10 @@ static unsigned getAllocatorIdx(cuf::DataAttributeAttr dataAttr) {
494
493
}
495
494
496
495
// / Create the global op and its init if it has one
497
- static fir::GlobalOp defineGlobal (Fortran::lower::AbstractConverter &converter,
498
- const Fortran::lower::pft::Variable &var,
499
- llvm::StringRef globalName,
500
- mlir::StringAttr linkage,
501
- cuf::DataAttributeAttr dataAttr) {
496
+ fir::GlobalOp Fortran::lower::defineGlobal (
497
+ Fortran::lower::AbstractConverter &converter,
498
+ const Fortran::lower::pft::Variable &var, llvm::StringRef globalName,
499
+ mlir::StringAttr linkage, cuf::DataAttributeAttr dataAttr) {
502
500
fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
503
501
const Fortran::semantics::Symbol &sym = var.getSymbol ();
504
502
mlir::Location loc = genLocation (converter, sym);
@@ -545,27 +543,25 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
545
543
sym.detailsIf <Fortran::semantics::ObjectEntityDetails>();
546
544
if (details && details->init ()) {
547
545
auto expr = *details->init ();
548
- Fortran::lower::createGlobalInitialization (
549
- builder, global, [&](fir::FirOpBuilder &b) {
550
- mlir::Value box = Fortran::lower::genInitialDataTarget (
551
- converter, loc, symTy, expr);
552
- b.create <fir::HasValueOp>(loc, box);
553
- });
546
+ createGlobalInitialization (builder, global, [&](fir::FirOpBuilder &b) {
547
+ mlir::Value box =
548
+ Fortran::lower::genInitialDataTarget (converter, loc, symTy, expr);
549
+ b.create <fir::HasValueOp>(loc, box);
550
+ });
554
551
} else {
555
552
// Create unallocated/disassociated descriptor if no explicit init
556
- Fortran::lower::createGlobalInitialization (
557
- builder, global, [&](fir::FirOpBuilder &b) {
558
- mlir::Value box = fir::factory::createUnallocatedBox (
559
- b, loc, symTy,
560
- /* nonDeferredParams=*/ std::nullopt,
561
- /* typeSourceBox=*/ {}, getAllocatorIdx (dataAttr));
562
- b.create <fir::HasValueOp>(loc, box);
563
- });
553
+ createGlobalInitialization (builder, global, [&](fir::FirOpBuilder &b) {
554
+ mlir::Value box = fir::factory::createUnallocatedBox (
555
+ b, loc, symTy,
556
+ /* nonDeferredParams=*/ std::nullopt,
557
+ /* typeSourceBox=*/ {}, getAllocatorIdxFromDataAttr (dataAttr));
558
+ b.create <fir::HasValueOp>(loc, box);
559
+ });
564
560
}
565
561
} else if (const auto *details =
566
562
sym.detailsIf <Fortran::semantics::ObjectEntityDetails>()) {
567
563
if (details->init ()) {
568
- Fortran::lower:: createGlobalInitialization (
564
+ createGlobalInitialization (
569
565
builder, global, [&](fir::FirOpBuilder &builder) {
570
566
Fortran::lower::StatementContext stmtCtx (
571
567
/* cleanupProhibited=*/ true );
@@ -576,7 +572,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
576
572
builder.create <fir::HasValueOp>(loc, castTo);
577
573
});
578
574
} else if (Fortran::lower::hasDefaultInitialization (sym)) {
579
- Fortran::lower:: createGlobalInitialization (
575
+ createGlobalInitialization (
580
576
builder, global, [&](fir::FirOpBuilder &builder) {
581
577
Fortran::lower::StatementContext stmtCtx (
582
578
/* cleanupProhibited=*/ true );
@@ -591,7 +587,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
591
587
if (details && details->init ()) {
592
588
auto sym{*details->init ()};
593
589
if (sym) // Has a procedure target.
594
- Fortran::lower:: createGlobalInitialization (
590
+ createGlobalInitialization (
595
591
builder, global, [&](fir::FirOpBuilder &b) {
596
592
Fortran::lower::StatementContext stmtCtx (
597
593
/* cleanupProhibited=*/ true );
@@ -601,19 +597,17 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
601
597
b.create <fir::HasValueOp>(loc, castTo);
602
598
});
603
599
else { // Has NULL() target.
604
- Fortran::lower::createGlobalInitialization (
605
- builder, global, [&](fir::FirOpBuilder &b) {
606
- auto box{fir::factory::createNullBoxProc (b, loc, symTy)};
607
- b.create <fir::HasValueOp>(loc, box);
608
- });
600
+ createGlobalInitialization (builder, global, [&](fir::FirOpBuilder &b) {
601
+ auto box{fir::factory::createNullBoxProc (b, loc, symTy)};
602
+ b.create <fir::HasValueOp>(loc, box);
603
+ });
609
604
}
610
605
} else {
611
606
// No initialization.
612
- Fortran::lower::createGlobalInitialization (
613
- builder, global, [&](fir::FirOpBuilder &b) {
614
- auto box{fir::factory::createNullBoxProc (b, loc, symTy)};
615
- b.create <fir::HasValueOp>(loc, box);
616
- });
607
+ createGlobalInitialization (builder, global, [&](fir::FirOpBuilder &b) {
608
+ auto box{fir::factory::createNullBoxProc (b, loc, symTy)};
609
+ b.create <fir::HasValueOp>(loc, box);
610
+ });
617
611
}
618
612
} else if (sym.has <Fortran::semantics::CommonBlockDetails>()) {
619
613
mlir::emitError (loc, " COMMON symbol processed elsewhere" );
@@ -634,7 +628,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
634
628
// file.
635
629
if (sym.attrs ().test (Fortran::semantics::Attr::BIND_C))
636
630
global.setLinkName (builder.createCommonLinkage ());
637
- Fortran::lower:: createGlobalInitialization (
631
+ createGlobalInitialization (
638
632
builder, global, [&](fir::FirOpBuilder &builder) {
639
633
mlir::Value initValue;
640
634
if (converter.getLoweringOptions ().getInitGlobalZero ())
@@ -826,7 +820,7 @@ void Fortran::lower::defaultInitializeAtRuntime(
826
820
/* isConst=*/ true ,
827
821
/* isTarget=*/ false ,
828
822
/* dataAttr=*/ {});
829
- Fortran::lower:: createGlobalInitialization (
823
+ createGlobalInitialization (
830
824
builder, global, [&](fir::FirOpBuilder &builder) {
831
825
Fortran::lower::StatementContext stmtCtx (
832
826
/* cleanupProhibited=*/ true );
@@ -842,7 +836,7 @@ void Fortran::lower::defaultInitializeAtRuntime(
842
836
/* isConst=*/ true ,
843
837
/* isTarget=*/ false ,
844
838
/* dataAttr=*/ {});
845
- Fortran::lower:: createGlobalInitialization (
839
+ createGlobalInitialization (
846
840
builder, global, [&](fir::FirOpBuilder &builder) {
847
841
Fortran::lower::StatementContext stmtCtx (
848
842
/* cleanupProhibited=*/ true );
@@ -1207,7 +1201,7 @@ static fir::GlobalOp defineGlobalAggregateStore(
1207
1201
if (const auto *objectDetails =
1208
1202
initSym->detailsIf <Fortran::semantics::ObjectEntityDetails>())
1209
1203
if (objectDetails->init ()) {
1210
- Fortran::lower:: createGlobalInitialization (
1204
+ createGlobalInitialization (
1211
1205
builder, global, [&](fir::FirOpBuilder &builder) {
1212
1206
Fortran::lower::StatementContext stmtCtx;
1213
1207
mlir::Value initVal = fir::getBase (genInitializerExprValue (
@@ -1219,12 +1213,11 @@ static fir::GlobalOp defineGlobalAggregateStore(
1219
1213
// Equivalence has no Fortran initial value. Create an undefined FIR initial
1220
1214
// value to ensure this is consider an object definition in the IR regardless
1221
1215
// of the linkage.
1222
- Fortran::lower::createGlobalInitialization (
1223
- builder, global, [&](fir::FirOpBuilder &builder) {
1224
- Fortran::lower::StatementContext stmtCtx;
1225
- mlir::Value initVal = builder.create <fir::ZeroOp>(loc, aggTy);
1226
- builder.create <fir::HasValueOp>(loc, initVal);
1227
- });
1216
+ createGlobalInitialization (builder, global, [&](fir::FirOpBuilder &builder) {
1217
+ Fortran::lower::StatementContext stmtCtx;
1218
+ mlir::Value initVal = builder.create <fir::ZeroOp>(loc, aggTy);
1219
+ builder.create <fir::HasValueOp>(loc, initVal);
1220
+ });
1228
1221
return global;
1229
1222
}
1230
1223
@@ -1543,7 +1536,7 @@ static void finalizeCommonBlockDefinition(
1543
1536
LLVM_DEBUG (llvm::dbgs () << " }\n " );
1544
1537
builder.create <fir::HasValueOp>(loc, cb);
1545
1538
};
1546
- Fortran::lower:: createGlobalInitialization (builder, global, initFunc);
1539
+ createGlobalInitialization (builder, global, initFunc);
1547
1540
}
1548
1541
1549
1542
void Fortran::lower::defineCommonBlocks (
0 commit comments