Skip to content

Commit ee05fbe

Browse files
EricjeanPerier
authored andcommitted
review comments
1 parent 29b7c96 commit ee05fbe

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

flang/include/flang/Lower/PFTBuilder.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "flang/Common/template.h"
2222
#include "flang/Lower/Utils.h"
2323
#include "flang/Parser/parse-tree.h"
24+
#include "flang/Semantics/attr.h"
25+
#include "flang/Semantics/symbol.h"
2426
#include "llvm/Support/raw_ostream.h"
2527

2628
namespace mlir {
@@ -32,9 +34,11 @@ namespace semantics {
3234
class SemanticsContext;
3335
class Scope;
3436
} // namespace semantics
37+
3538
namespace lower {
3639

3740
bool definedInCommonBlock(const semantics::Symbol &sym);
41+
bool defaultRecursiveFunctionSetting();
3842

3943
namespace pft {
4044

@@ -551,7 +555,13 @@ struct FunctionLikeUnit : public ProgramUnit {
551555
FunctionLikeUnit(FunctionLikeUnit &&) = default;
552556
FunctionLikeUnit(const FunctionLikeUnit &) = delete;
553557

554-
bool isRecursive() { return isMainProgram() ? false : recursiveFunction; }
558+
bool isRecursive() const {
559+
auto sym = getSubprogramSymbol();
560+
return !isMainProgram() &&
561+
(sym.attrs().test(semantics::Attr::RECURSIVE) ||
562+
(!sym.attrs().test(semantics::Attr::NON_RECURSIVE) &&
563+
defaultRecursiveFunctionSetting()));
564+
}
555565

556566
std::vector<Variable> getOrderedSymbolTable() { return varList[0]; }
557567

@@ -618,7 +628,6 @@ struct FunctionLikeUnit : public ProgramUnit {
618628
/// Terminal basic block (if any)
619629
mlir::Block *finalBlock{};
620630
std::vector<std::vector<Variable>> varList;
621-
bool recursiveFunction{};
622631
};
623632

624633
/// Module-like units contain a list of function-like units.

flang/lib/Lower/Bridge.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
17321732
auto globalName = mangleName(sym);
17331733
bool isConst = sym.attrs().test(Fortran::semantics::Attr::PARAMETER);
17341734
auto loc = genLocation(sym.name());
1735-
auto idxTy = builder->getIndexType();
17361735
// FIXME: name returned does not consider subprogram's scope, is not unique
17371736
fir::GlobalOp global = builder->getNamedGlobal(globalName);
17381737
if (global) {

flang/lib/Lower/PFTBuilder.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@ static llvm::cl::opt<bool> clDisableStructuredFir(
2323
"no-structured-fir", llvm::cl::desc("disable generation of structured FIR"),
2424
llvm::cl::init(false), llvm::cl::Hidden);
2525

26-
// FIXME: should be set with switch such as `--std=2018`.
2726
static llvm::cl::opt<bool> nonRecursiveProcedures(
2827
"non-recursive-procedures",
2928
llvm::cl::desc("Make procedures non-recursive by default. This was the "
3029
"default for all Fortran standards prior to 2018."),
3130
llvm::cl::init(/*2018 standard=*/false));
3231

33-
static bool defaultRecursiveFunctionSetting() {
34-
return !nonRecursiveProcedures;
35-
}
36-
3732
using namespace Fortran;
3833

3934
namespace {
@@ -1286,17 +1281,6 @@ Fortran::lower::pft::FunctionLikeUnit::FunctionLikeUnit(
12861281
}
12871282
}
12881283

1289-
template <typename A>
1290-
static bool procedureIsRecursive(const A &stmt) {
1291-
for (const auto &p : std::get<std::list<parser::PrefixSpec>>(stmt.t)) {
1292-
if (std::holds_alternative<parser::PrefixSpec::Recursive>(p.u))
1293-
return true;
1294-
if (std::holds_alternative<parser::PrefixSpec::Non_Recursive>(p.u))
1295-
return false;
1296-
}
1297-
return defaultRecursiveFunctionSetting();
1298-
}
1299-
13001284
Fortran::lower::pft::FunctionLikeUnit::FunctionLikeUnit(
13011285
const parser::FunctionSubprogram &func,
13021286
const lower::pft::ParentVariant &parent,
@@ -1305,8 +1289,6 @@ Fortran::lower::pft::FunctionLikeUnit::FunctionLikeUnit(
13051289
beginStmt{getFunctionStmt<parser::FunctionStmt>(func)},
13061290
endStmt{getFunctionStmt<parser::EndFunctionStmt>(func)} {
13071291
auto symbol = getSymbol(*beginStmt);
1308-
recursiveFunction =
1309-
procedureIsRecursive(beginStmt->getStatement<parser::FunctionStmt>());
13101292
entryPointList[0].first = symbol;
13111293
processSymbolTable(*symbol->scope(), varList);
13121294
}
@@ -1319,8 +1301,6 @@ Fortran::lower::pft::FunctionLikeUnit::FunctionLikeUnit(
13191301
beginStmt{getFunctionStmt<parser::SubroutineStmt>(func)},
13201302
endStmt{getFunctionStmt<parser::EndSubroutineStmt>(func)} {
13211303
auto symbol = getSymbol(*beginStmt);
1322-
recursiveFunction =
1323-
procedureIsRecursive(beginStmt->getStatement<parser::SubroutineStmt>());
13241304
entryPointList[0].first = symbol;
13251305
processSymbolTable(*symbol->scope(), varList);
13261306
}
@@ -1331,8 +1311,7 @@ Fortran::lower::pft::FunctionLikeUnit::FunctionLikeUnit(
13311311
const semantics::SemanticsContext &)
13321312
: ProgramUnit{func, parent},
13331313
beginStmt{getFunctionStmt<parser::MpSubprogramStmt>(func)},
1334-
endStmt{getFunctionStmt<parser::EndMpSubprogramStmt>(func)},
1335-
recursiveFunction{defaultRecursiveFunctionSetting()} {
1314+
endStmt{getFunctionStmt<parser::EndMpSubprogramStmt>(func)} {
13361315
auto symbol = getSymbol(*beginStmt);
13371316
entryPointList[0].first = symbol;
13381317
processSymbolTable(*symbol->scope(), varList);
@@ -1371,6 +1350,14 @@ Fortran::lower::createPFT(const parser::Program &root,
13711350
return walker.result();
13721351
}
13731352

1353+
// FIXME: FlangDriver
1354+
// This option should be integrated with the real driver as the default of
1355+
// RECURSIVE vs. NON_RECURSIVE may be changed by other command line options,
1356+
// etc., etc.
1357+
bool Fortran::lower::defaultRecursiveFunctionSetting() {
1358+
return !nonRecursiveProcedures;
1359+
}
1360+
13741361
void Fortran::lower::dumpPFT(llvm::raw_ostream &outputStream,
13751362
const lower::pft::Program &pft) {
13761363
PFTDumper{}.dumpPFT(outputStream, pft);

0 commit comments

Comments
 (0)