Skip to content

Commit 1b825b5

Browse files
committed
cleaning up unused code
1 parent c260936 commit 1b825b5

File tree

5 files changed

+32
-210
lines changed

5 files changed

+32
-210
lines changed

flang/include/flang/Lower/AbstractConverter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,6 @@ class AbstractConverter {
358358
/// functions in order to be in sync).
359359
virtual mlir::SymbolTable *getMLIRSymbolTable() = 0;
360360

361-
virtual Fortran::lower::AccRoutineInfoMappingList &
362-
getAccDelayedRoutines() = 0;
363-
364361
private:
365362
/// Options controlling lowering behavior.
366363
const Fortran::lower::LoweringOptions &loweringOptions;

flang/include/flang/Lower/OpenACC.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ namespace pft {
6363
struct Evaluation;
6464
} // namespace pft
6565

66-
using AccRoutineInfoMappingList =
67-
llvm::SmallVector<std::pair<std::string, mlir::SymbolRefAttr>>;
68-
6966
static constexpr llvm::StringRef declarePostAllocSuffix =
7067
"_acc_declare_update_desc_post_alloc";
7168
static constexpr llvm::StringRef declarePreDeallocSuffix =
@@ -82,22 +79,13 @@ mlir::Value genOpenACCConstruct(AbstractConverter &,
8279
Fortran::semantics::SemanticsContext &,
8380
pft::Evaluation &,
8481
const parser::OpenACCConstruct &);
85-
void genOpenACCDeclarativeConstruct(AbstractConverter &,
86-
Fortran::semantics::SemanticsContext &,
87-
StatementContext &,
88-
const parser::OpenACCDeclarativeConstruct &,
89-
AccRoutineInfoMappingList &);
90-
void genOpenACCRoutineConstruct(AbstractConverter &,
91-
Fortran::semantics::SemanticsContext &,
92-
mlir::ModuleOp,
93-
const parser::OpenACCRoutineConstruct &);
82+
void genOpenACCDeclarativeConstruct(
83+
AbstractConverter &, Fortran::semantics::SemanticsContext &,
84+
StatementContext &, const parser::OpenACCDeclarativeConstruct &);
9485
void genOpenACCRoutineConstruct(
9586
AbstractConverter &, mlir::ModuleOp, mlir::func::FuncOp,
9687
const std::vector<Fortran::semantics::OpenACCRoutineInfo> &);
9788

98-
void finalizeOpenACCRoutineAttachment(mlir::ModuleOp,
99-
AccRoutineInfoMappingList &);
100-
10189
/// Get a acc.private.recipe op for the given type or create it if it does not
10290
/// exist yet.
10391
mlir::acc::PrivateRecipeOp createOrGetPrivateRecipe(mlir::OpBuilder &,

flang/lib/Lower/Bridge.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,25 @@ class FirConverter : public Fortran::lower::AbstractConverter {
458458
Fortran::common::LanguageFeature::CUDA));
459459
});
460460

461-
finalizeOpenACCLowering();
462461
finalizeOpenMPLowering(globalOmpRequiresSymbol);
463462
}
464463

465464
/// Declare a function.
466465
void declareFunction(Fortran::lower::pft::FunctionLikeUnit &funit) {
466+
// Since this is a recursive function, we only need to create a new builder
467+
// for each top-level declaration. It would be simpler to have a single
468+
// builder for the entire translation unit, but that requires a lot of
469+
// changes to the code.
470+
// FIXME: Once createGlobalOutsideOfFunctionLowering is fixed, we can
471+
// remove this code and share the module builder.
472+
bool newBuilder = false;
473+
if (!builder) {
474+
newBuilder = true;
475+
builder = new fir::FirOpBuilder(bridge.getModule(), bridge.getKindMap(),
476+
&mlirSymbolTable);
477+
}
478+
CHECK(builder && "FirOpBuilder did not instantiate");
467479
setCurrentPosition(funit.getStartingSourceLoc());
468-
builder = new fir::FirOpBuilder(bridge.getModule(), bridge.getKindMap(),
469-
&mlirSymbolTable);
470480
for (int entryIndex = 0, last = funit.entryPointList.size();
471481
entryIndex < last; ++entryIndex) {
472482
funit.setActiveEntry(entryIndex);
@@ -493,7 +503,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
493503
for (Fortran::lower::pft::ContainedUnit &unit : funit.containedUnitList)
494504
if (auto *f = std::get_if<Fortran::lower::pft::FunctionLikeUnit>(&unit))
495505
declareFunction(*f);
496-
builder = nullptr;
506+
507+
if (newBuilder) {
508+
delete builder;
509+
builder = nullptr;
510+
}
497511
}
498512

499513
/// Get the scope that is defining or using \p sym. The returned scope is not
@@ -3017,8 +3031,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
30173031

30183032
void genFIR(const Fortran::parser::OpenACCDeclarativeConstruct &accDecl) {
30193033
genOpenACCDeclarativeConstruct(*this, bridge.getSemanticsContext(),
3020-
bridge.openAccCtx(), accDecl,
3021-
accRoutineInfos);
3034+
bridge.openAccCtx(), accDecl);
30223035
for (Fortran::lower::pft::Evaluation &e : getEval().getNestedEvaluations())
30233036
genFIR(e);
30243037
}
@@ -4286,11 +4299,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
42864299
return Fortran::lower::createMutableBox(loc, *this, expr, localSymbols);
42874300
}
42884301

4289-
Fortran::lower::AccRoutineInfoMappingList &
4290-
getAccDelayedRoutines() override final {
4291-
return accRoutineInfos;
4292-
}
4293-
42944302
// Create the [newRank] array with the lower bounds to be passed to the
42954303
// runtime as a descriptor.
42964304
mlir::Value createLboundArray(llvm::ArrayRef<mlir::Value> lbounds,
@@ -5889,7 +5897,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
58895897
/// Helper to generate GlobalOps when the builder is not positioned in any
58905898
/// region block. This is required because the FirOpBuilder assumes it is
58915899
/// always positioned inside a region block when creating globals, the easiest
5892-
/// way comply is to create a dummy function and to throw it afterwards.
5900+
/// way comply is to create a dummy function and to throw it away afterwards.
58935901
void createGlobalOutsideOfFunctionLowering(
58945902
const std::function<void()> &createGlobals) {
58955903
// FIXME: get rid of the bogus function context and instantiate the
@@ -5902,6 +5910,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
59025910
mlir::FunctionType::get(context, std::nullopt, std::nullopt),
59035911
symbolTable);
59045912
func.addEntryBlock();
5913+
CHECK(!builder && "Expected builder to be uninitialized");
59055914
builder = new fir::FirOpBuilder(func, bridge.getKindMap(), symbolTable);
59065915
assert(builder && "FirOpBuilder did not instantiate");
59075916
builder->setFastMathFlags(bridge.getLoweringOptions().getMathOptions());
@@ -6331,13 +6340,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
63316340
expr.u);
63326341
}
63336342

6334-
/// Performing OpenACC lowering action that were deferred to the end of
6335-
/// lowering.
6336-
void finalizeOpenACCLowering() {
6337-
Fortran::lower::finalizeOpenACCRoutineAttachment(getModuleOp(),
6338-
accRoutineInfos);
6339-
}
6340-
63416343
/// Performing OpenMP lowering actions that were deferred to the end of
63426344
/// lowering.
63436345
void finalizeOpenMPLowering(
@@ -6429,9 +6431,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
64296431
/// A counter for uniquing names in `literalNamesMap`.
64306432
std::uint64_t uniqueLitId = 0;
64316433

6432-
/// Deferred OpenACC routine attachment.
6433-
Fortran::lower::AccRoutineInfoMappingList accRoutineInfos;
6434-
64356434
/// Whether an OpenMP target region or declare target function/subroutine
64366435
/// intended for device offloading has been detected
64376436
bool ompDeviceCodeFound = false;

flang/lib/Lower/OpenACC.cpp

Lines changed: 5 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -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

42074197
static 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-
44414292
static void
44424293
genACC(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
}

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,8 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
10411041
if (const auto *dTypeClause =
10421042
std::get_if<Fortran::parser::AccClause::DeviceType>(&clause.u)) {
10431043
currentDevices.clear();
1044-
for (const auto &deviceTypeExpr : dTypeClause->v.v) {
1044+
for (const auto &deviceTypeExpr : dTypeClause->v.v)
10451045
currentDevices.push_back(&info.add_deviceTypeInfo(deviceTypeExpr.v));
1046-
}
10471046
} else if (std::get_if<Fortran::parser::AccClause::Nohost>(&clause.u)) {
10481047
info.set_isNohost();
10491048
} else if (std::get_if<Fortran::parser::AccClause::Seq>(&clause.u)) {
@@ -1080,9 +1079,8 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
10801079
std::get_if<Fortran::parser::Name>(&bindClause->v.u)) {
10811080
if (Symbol *sym = ResolveFctName(*name)) {
10821081
Symbol &ultimate{sym->GetUltimate()};
1083-
for (auto &device : currentDevices) {
1082+
for (auto &device : currentDevices)
10841083
device->set_bindName(SymbolRef(ultimate));
1085-
}
10861084
} else {
10871085
context_.Say((*name).source,
10881086
"No function or subroutine declared for '%s'"_err_en_US,
@@ -1095,16 +1093,12 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
10951093
Fortran::parser::Unwrap<Fortran::parser::CharLiteralConstant>(
10961094
*charExpr);
10971095
std::string str{std::get<std::string>(charConst->t)};
1098-
for (auto &device : currentDevices) {
1096+
for (auto &device : currentDevices)
10991097
device->set_bindName(std::string(str));
1100-
}
11011098
}
11021099
}
11031100
}
11041101
symbol.get<SubprogramDetails>().add_openACCRoutineInfo(info);
1105-
} else {
1106-
llvm::errs() << "Couldnot add routine info to symbol: " << symbol.name()
1107-
<< "\n";
11081102
}
11091103
}
11101104

0 commit comments

Comments
 (0)