Skip to content

[flang][openacc] Allow open acc routines from other modules. #136012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 9, 2025
Prev Previous commit
Next Next commit
more consistent use of builders
  • Loading branch information
akuhlens committed May 1, 2025
commit 8f6ae035147336c4ed04b5b25487f72ebc52c757
40 changes: 13 additions & 27 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,21 @@ class FirConverter : public Fortran::lower::AbstractConverter {
[&](Fortran::lower::pft::FunctionLikeUnit &f) {
if (f.isMainProgram())
hasMainProgram = true;
declareFunction(f);
createGlobalOutsideOfFunctionLowering(
[&]() { declareFunction(f); });
if (!globalOmpRequiresSymbol)
globalOmpRequiresSymbol = f.getScope().symbol();
},
[&](Fortran::lower::pft::ModuleLikeUnit &m) {
lowerModuleDeclScope(m);
for (Fortran::lower::pft::ContainedUnit &unit :
m.containedUnitList)
if (auto *f =
std::get_if<Fortran::lower::pft::FunctionLikeUnit>(
&unit))
declareFunction(*f);
createGlobalOutsideOfFunctionLowering([&]() {
for (Fortran::lower::pft::ContainedUnit &unit :
m.containedUnitList)
if (auto *f =
std::get_if<Fortran::lower::pft::FunctionLikeUnit>(
&unit))
declareFunction(*f);
});
},
[&](Fortran::lower::pft::BlockDataUnit &b) {
if (!globalOmpRequiresSymbol)
Expand Down Expand Up @@ -463,19 +466,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {

/// Declare a function.
void declareFunction(Fortran::lower::pft::FunctionLikeUnit &funit) {
// Since this is a recursive function, we only need to create a new builder
// for each top-level declaration. It would be simpler to have a single
// builder for the entire translation unit, but that requires a lot of
// changes to the code.
// FIXME: Once createGlobalOutsideOfFunctionLowering is fixed, we can
// remove this code and share the module builder.
bool newBuilder = false;
if (!builder) {
newBuilder = true;
builder = new fir::FirOpBuilder(bridge.getModule(), bridge.getKindMap(),
&mlirSymbolTable);
}
CHECK(builder && "FirOpBuilder did not instantiate");
CHECK(builder && "declareFunction called with uninitialized builder");
setCurrentPosition(funit.getStartingSourceLoc());
for (int entryIndex = 0, last = funit.entryPointList.size();
entryIndex < last; ++entryIndex) {
Expand Down Expand Up @@ -503,11 +494,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
for (Fortran::lower::pft::ContainedUnit &unit : funit.containedUnitList)
if (auto *f = std::get_if<Fortran::lower::pft::FunctionLikeUnit>(&unit))
declareFunction(*f);

if (newBuilder) {
delete builder;
builder = nullptr;
}
}

/// Get the scope that is defining or using \p sym. The returned scope is not
Expand Down Expand Up @@ -5624,9 +5610,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
LLVM_DEBUG(llvm::dbgs() << "\n[bridge - startNewFunction]";
if (auto *sym = scope.symbol()) llvm::dbgs() << " " << *sym;
llvm::dbgs() << "\n");
// I don't think setting the builder is necessary here, because callee
// Setting the builder is not necessary here, because callee
// always looks up the FuncOp from the module. If there was a function that
// was not declared yet. This call to callee will cause an assertion
// was not declared yet, this call to callee will cause an assertion
// failure.
Fortran::lower::CalleeInterface callee(funit, *this);
mlir::func::FuncOp func = callee.addEntryBlockAndMapArguments();
Expand Down
1 change: 0 additions & 1 deletion flang/lib/Lower/CallInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Optimizer/Support/Utils.h"
#include "flang/Parser/parse-tree.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
#include "flang/Support/Fortran.h"
Expand Down
Loading