@@ -4163,9 +4163,6 @@ void createOpenACCRoutineConstruct(
41634163 llvm::SmallVector<mlir::Attribute> &workerDeviceTypes,
41644164 llvm::SmallVector<mlir::Attribute> &vectorDeviceTypes) {
41654165
4166- std::stringstream routineOpName;
4167- routineOpName << accRoutinePrefix.str () << routineCounter++;
4168-
41694166 for (auto routineOp : mod.getOps <mlir::acc::RoutineOp>()) {
41704167 if (routineOp.getFuncName ().str ().compare (funcName) == 0 ) {
41714168 // If the routine is already specified with the same clauses, just skip
@@ -4179,6 +4176,8 @@ void createOpenACCRoutineConstruct(
41794176 mlir::emitError (loc, " Routine already specified with different clauses" );
41804177 }
41814178 }
4179+ std::stringstream routineOpName;
4180+ routineOpName << accRoutinePrefix.str () << routineCounter++;
41824181 std::string routineOpStr = routineOpName.str ();
41834182 mlir::OpBuilder modBuilder (mod.getBodyRegion ());
41844183 fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
@@ -4192,16 +4191,7 @@ void createOpenACCRoutineConstruct(
41924191 getArrayAttrOrNull (builder, gangDimValues),
41934192 getArrayAttrOrNull (builder, gangDimDeviceTypes));
41944193
4195- auto symbolRefAttr = builder.getSymbolRefAttr (routineOpStr);
4196- if (funcOp) {
4197-
4198- attachRoutineInfo (funcOp, symbolRefAttr);
4199- } else {
4200- // FuncOp is not lowered yet. Keep the information so the routine info
4201- // can be attached later to the funcOp.
4202- converter.getAccDelayedRoutines ().push_back (
4203- std::make_pair (funcName, symbolRefAttr));
4204- }
4194+ attachRoutineInfo (funcOp, builder.getSymbolRefAttr (routineOpStr));
42054195}
42064196
42074197static void interpretRoutineDeviceInfo (
@@ -4299,145 +4289,6 @@ void Fortran::lower::genOpenACCRoutineConstruct(
42994289 seqDeviceTypes, workerDeviceTypes, vectorDeviceTypes);
43004290}
43014291
4302- void Fortran::lower::genOpenACCRoutineConstruct (
4303- Fortran::lower::AbstractConverter &converter,
4304- Fortran::semantics::SemanticsContext &semanticsContext, mlir::ModuleOp mod,
4305- const Fortran::parser::OpenACCRoutineConstruct &routineConstruct) {
4306- fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
4307- mlir::Location loc = converter.genLocation (routineConstruct.source );
4308- std::optional<Fortran::parser::Name> name =
4309- std::get<std::optional<Fortran::parser::Name>>(routineConstruct.t );
4310- const auto &clauses =
4311- std::get<Fortran::parser::AccClauseList>(routineConstruct.t );
4312- mlir::func::FuncOp funcOp;
4313- std::string funcName;
4314- if (name) {
4315- funcName = converter.mangleName (*name->symbol );
4316- funcOp =
4317- builder.getNamedFunction (mod, builder.getMLIRSymbolTable (), funcName);
4318- } else {
4319- Fortran::semantics::Scope &scope =
4320- semanticsContext.FindScope (routineConstruct.source );
4321- const Fortran::semantics::Scope &progUnit{GetProgramUnitContaining (scope)};
4322- const auto *subpDetails{
4323- progUnit.symbol ()
4324- ? progUnit.symbol ()
4325- ->detailsIf <Fortran::semantics::SubprogramDetails>()
4326- : nullptr };
4327- if (subpDetails && subpDetails->isInterface ()) {
4328- funcName = converter.mangleName (*progUnit.symbol ());
4329- funcOp =
4330- builder.getNamedFunction (mod, builder.getMLIRSymbolTable (), funcName);
4331- } else {
4332- funcOp = builder.getFunction ();
4333- funcName = funcOp.getName ();
4334- }
4335- }
4336- // TODO: Refactor this to use the OpenACCRoutineInfo
4337- bool hasNohost = false ;
4338-
4339- llvm::SmallVector<mlir::Attribute> seqDeviceTypes, vectorDeviceTypes,
4340- workerDeviceTypes, bindNameDeviceTypes, bindNames, gangDeviceTypes,
4341- gangDimDeviceTypes, gangDimValues;
4342-
4343- // device_type attribute is set to `none` until a device_type clause is
4344- // encountered.
4345- llvm::SmallVector<mlir::Attribute> crtDeviceTypes;
4346- crtDeviceTypes.push_back (mlir::acc::DeviceTypeAttr::get (
4347- builder.getContext (), mlir::acc::DeviceType::None));
4348-
4349- for (const Fortran::parser::AccClause &clause : clauses.v ) {
4350- if (std::get_if<Fortran::parser::AccClause::Seq>(&clause.u )) {
4351- for (auto crtDeviceTypeAttr : crtDeviceTypes)
4352- seqDeviceTypes.push_back (crtDeviceTypeAttr);
4353- } else if (const auto *gangClause =
4354- std::get_if<Fortran::parser::AccClause::Gang>(&clause.u )) {
4355- if (gangClause->v ) {
4356- const Fortran::parser::AccGangArgList &x = *gangClause->v ;
4357- for (const Fortran::parser::AccGangArg &gangArg : x.v ) {
4358- if (const auto *dim =
4359- std::get_if<Fortran::parser::AccGangArg::Dim>(&gangArg.u )) {
4360- const std::optional<int64_t > dimValue = Fortran::evaluate::ToInt64 (
4361- *Fortran::semantics::GetExpr (dim->v ));
4362- if (!dimValue)
4363- mlir::emitError (loc,
4364- " dim value must be a constant positive integer" );
4365- mlir::Attribute gangDimAttr =
4366- builder.getIntegerAttr (builder.getI64Type (), *dimValue);
4367- for (auto crtDeviceTypeAttr : crtDeviceTypes) {
4368- gangDimValues.push_back (gangDimAttr);
4369- gangDimDeviceTypes.push_back (crtDeviceTypeAttr);
4370- }
4371- }
4372- }
4373- } else {
4374- for (auto crtDeviceTypeAttr : crtDeviceTypes)
4375- gangDeviceTypes.push_back (crtDeviceTypeAttr);
4376- }
4377- } else if (std::get_if<Fortran::parser::AccClause::Vector>(&clause.u )) {
4378- for (auto crtDeviceTypeAttr : crtDeviceTypes)
4379- vectorDeviceTypes.push_back (crtDeviceTypeAttr);
4380- } else if (std::get_if<Fortran::parser::AccClause::Worker>(&clause.u )) {
4381- for (auto crtDeviceTypeAttr : crtDeviceTypes)
4382- workerDeviceTypes.push_back (crtDeviceTypeAttr);
4383- } else if (std::get_if<Fortran::parser::AccClause::Nohost>(&clause.u )) {
4384- hasNohost = true ;
4385- } else if (const auto *bindClause =
4386- std::get_if<Fortran::parser::AccClause::Bind>(&clause.u )) {
4387- if (const auto *name =
4388- std::get_if<Fortran::parser::Name>(&bindClause->v .u )) {
4389- mlir::Attribute bindNameAttr =
4390- builder.getStringAttr (converter.mangleName (*name->symbol ));
4391- for (auto crtDeviceTypeAttr : crtDeviceTypes) {
4392- bindNames.push_back (bindNameAttr);
4393- bindNameDeviceTypes.push_back (crtDeviceTypeAttr);
4394- }
4395- } else if (const auto charExpr =
4396- std::get_if<Fortran::parser::ScalarDefaultCharExpr>(
4397- &bindClause->v .u )) {
4398- const std::optional<std::string> name =
4399- Fortran::semantics::GetConstExpr<std::string>(semanticsContext,
4400- *charExpr);
4401- if (!name)
4402- mlir::emitError (loc, " Could not retrieve the bind name" );
4403-
4404- mlir::Attribute bindNameAttr = builder.getStringAttr (*name);
4405- for (auto crtDeviceTypeAttr : crtDeviceTypes) {
4406- bindNames.push_back (bindNameAttr);
4407- bindNameDeviceTypes.push_back (crtDeviceTypeAttr);
4408- }
4409- }
4410- } else if (const auto *deviceTypeClause =
4411- std::get_if<Fortran::parser::AccClause::DeviceType>(
4412- &clause.u )) {
4413- crtDeviceTypes.clear ();
4414- gatherDeviceTypeAttrs (builder, deviceTypeClause, crtDeviceTypes);
4415- }
4416- }
4417-
4418- createOpenACCRoutineConstruct (
4419- converter, loc, mod, funcOp, funcName, hasNohost, bindNames,
4420- bindNameDeviceTypes, gangDeviceTypes, gangDimValues, gangDimDeviceTypes,
4421- seqDeviceTypes, workerDeviceTypes, vectorDeviceTypes);
4422- }
4423-
4424- void Fortran::lower::finalizeOpenACCRoutineAttachment (
4425- mlir::ModuleOp mod,
4426- Fortran::lower::AccRoutineInfoMappingList &accRoutineInfos) {
4427- for (auto &mapping : accRoutineInfos) {
4428- mlir::func::FuncOp funcOp =
4429- mod.lookupSymbol <mlir::func::FuncOp>(mapping.first );
4430- if (!funcOp)
4431- mlir::emitWarning (mod.getLoc (),
4432- llvm::Twine (" function '" ) + llvm::Twine (mapping.first ) +
4433- llvm::Twine (" ' in acc routine directive is not "
4434- " found in this translation unit." ));
4435- else
4436- attachRoutineInfo (funcOp, mapping.second );
4437- }
4438- accRoutineInfos.clear ();
4439- }
4440-
44414292static void
44424293genACC (Fortran::lower::AbstractConverter &converter,
44434294 Fortran::lower::pft::Evaluation &eval,
@@ -4551,8 +4402,7 @@ void Fortran::lower::genOpenACCDeclarativeConstruct(
45514402 Fortran::lower::AbstractConverter &converter,
45524403 Fortran::semantics::SemanticsContext &semanticsContext,
45534404 Fortran::lower::StatementContext &openAccCtx,
4554- const Fortran::parser::OpenACCDeclarativeConstruct &accDeclConstruct,
4555- Fortran::lower::AccRoutineInfoMappingList &accRoutineInfos) {
4405+ const Fortran::parser::OpenACCDeclarativeConstruct &accDeclConstruct) {
45564406
45574407 Fortran::common::visit (
45584408 common::visitors{
@@ -4561,13 +4411,7 @@ void Fortran::lower::genOpenACCDeclarativeConstruct(
45614411 genACC (converter, semanticsContext, openAccCtx,
45624412 standaloneDeclarativeConstruct);
45634413 },
4564- [&](const Fortran::parser::OpenACCRoutineConstruct
4565- &routineConstruct) {
4566- fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
4567- mlir::ModuleOp mod = builder.getModule ();
4568- Fortran::lower::genOpenACCRoutineConstruct (
4569- converter, semanticsContext, mod, routineConstruct);
4570- },
4414+ [&](const Fortran::parser::OpenACCRoutineConstruct &x) {},
45714415 },
45724416 accDeclConstruct.u );
45734417}
0 commit comments