Skip to content

Commit 7a08f40

Browse files
authored
Merge pull request #507 from schweitzpgi/ch-work2
Split out the target rewrite pass into its own source file.
2 parents 85f87d3 + 40e024c commit 7a08f40

File tree

6 files changed

+738
-685
lines changed

6 files changed

+738
-685
lines changed

flang/include/flang/Lower/PFTBuilder.h

Lines changed: 17 additions & 0 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

@@ -70,6 +74,10 @@ class ReferenceVariantBase {
7074
return std::get<Ref<B>>(u).get();
7175
}
7276
template <typename B>
77+
constexpr BaseType<B> &getStatement() const {
78+
return std::get<Ref<parser::Statement<B>>>(u).get().statement;
79+
}
80+
template <typename B>
7381
constexpr BaseType<B> *getIf() const {
7482
auto *ptr = std::get_if<Ref<B>>(&u);
7583
return ptr ? &ptr->get() : nullptr;
@@ -547,6 +555,14 @@ struct FunctionLikeUnit : public ProgramUnit {
547555
FunctionLikeUnit(FunctionLikeUnit &&) = default;
548556
FunctionLikeUnit(const FunctionLikeUnit &) = delete;
549557

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+
}
565+
550566
std::vector<Variable> getOrderedSymbolTable() { return varList[0]; }
551567

552568
bool isMainProgram() const {
@@ -574,6 +590,7 @@ struct FunctionLikeUnit : public ProgramUnit {
574590
assert(symbol && "not inside a procedure");
575591
return *symbol;
576592
}
593+
577594
/// Return a pointer to the current entry point Evaluation.
578595
/// This is null for a primary entry point.
579596
Evaluation *getEntryEval() const {

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +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+
static llvm::cl::opt<bool> nonRecursiveProcedures(
27+
"non-recursive-procedures",
28+
llvm::cl::desc("Make procedures non-recursive by default. This was the "
29+
"default for all Fortran standards prior to 2018."),
30+
llvm::cl::init(/*2018 standard=*/false));
31+
2632
using namespace Fortran;
2733

2834
namespace {
@@ -1344,6 +1350,14 @@ Fortran::lower::createPFT(const parser::Program &root,
13441350
return walker.result();
13451351
}
13461352

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+
13471361
void Fortran::lower::dumpPFT(llvm::raw_ostream &outputStream,
13481362
const lower::pft::Program &pft) {
13491363
PFTDumper{}.dumpPFT(outputStream, pft);

flang/lib/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_flang_library(FIROptimizer
1616
CodeGen/CodeGen.cpp
1717
CodeGen/PreCGRewrite.cpp
1818
CodeGen/Target.cpp
19+
CodeGen/TargetRewrite.cpp
1920

2021
Transforms/ControlFlowConverter.cpp
2122
Transforms/CSE.cpp

0 commit comments

Comments
 (0)