41
41
#include " flang/Optimizer/Support/Utils.h"
42
42
#include " flang/Semantics/runtime-type-info.h"
43
43
#include " flang/Semantics/tools.h"
44
+ #include " llvm/Support/CommandLine.h"
44
45
#include " llvm/Support/Debug.h"
45
46
#include < optional>
46
47
48
+ static llvm::cl::opt<bool > allowAssumedRank (
49
+ " allow-assumed-rank" ,
50
+ llvm::cl::desc (" Enable assumed rank lowering - experimental" ),
51
+ llvm::cl::init(false ));
52
+
47
53
#define DEBUG_TYPE " flang-lower-variable"
48
54
49
55
// / Helper to lower a scalar expression using a specific symbol mapping.
@@ -1885,7 +1891,8 @@ void Fortran::lower::mapSymbolAttributes(
1885
1891
return ;
1886
1892
}
1887
1893
1888
- if (Fortran::evaluate::IsAssumedRank (sym))
1894
+ const bool isAssumedRank = Fortran::evaluate::IsAssumedRank (sym);
1895
+ if (isAssumedRank && !allowAssumedRank)
1889
1896
TODO (loc, " assumed-rank variable in procedure implemented in Fortran" );
1890
1897
1891
1898
Fortran::lower::BoxAnalyzer ba;
@@ -1894,6 +1901,8 @@ void Fortran::lower::mapSymbolAttributes(
1894
1901
// First deal with pointers and allocatables, because their handling here
1895
1902
// is the same regardless of their rank.
1896
1903
if (Fortran::semantics::IsAllocatableOrPointer (sym)) {
1904
+ if (isAssumedRank)
1905
+ TODO (loc, " assumed-rank pointer or allocatable" );
1897
1906
// Get address of fir.box describing the entity.
1898
1907
// global
1899
1908
mlir::Value boxAlloc = preAlloc;
@@ -1942,7 +1951,7 @@ void Fortran::lower::mapSymbolAttributes(
1942
1951
if (mlir::Value len =
1943
1952
lowerExplicitCharLen (converter, loc, ba, symMap, stmtCtx))
1944
1953
explicitParams.push_back (len);
1945
- if (sym.Rank () == 0 ) {
1954
+ if (!isAssumedRank && sym.Rank () == 0 ) {
1946
1955
// Do not keep scalar characters as fir.box (even when optional).
1947
1956
// Lowering and FIR is not meant to deal with scalar characters as
1948
1957
// fir.box outside of calls.
@@ -1987,9 +1996,11 @@ void Fortran::lower::mapSymbolAttributes(
1987
1996
}
1988
1997
}
1989
1998
// TODO: derived type length parameters.
1990
- lowerExplicitLowerBounds (converter, loc, ba, lbounds, symMap, stmtCtx);
1991
- lowerExplicitExtents (converter, loc, ba, lbounds, explicitExtents, symMap,
1992
- stmtCtx);
1999
+ if (!isAssumedRank) {
2000
+ lowerExplicitLowerBounds (converter, loc, ba, lbounds, symMap, stmtCtx);
2001
+ lowerExplicitExtents (converter, loc, ba, lbounds, explicitExtents,
2002
+ symMap, stmtCtx);
2003
+ }
1993
2004
genBoxDeclare (converter, symMap, sym, dummyArg, lbounds, explicitParams,
1994
2005
explicitExtents, replace);
1995
2006
return ;
@@ -2021,6 +2032,11 @@ void Fortran::lower::mapSymbolAttributes(
2021
2032
if (isUnusedEntryDummy) {
2022
2033
assert (!Fortran::semantics::IsAllocatableOrPointer (sym) &&
2023
2034
" handled above" );
2035
+ // Need to add support for allocatable assumed-rank to use
2036
+ // logic below, or to simplify it and add codegen for fir.zero
2037
+ // !fir.box<> instead.
2038
+ if (isAssumedRank)
2039
+ TODO (loc, " assumed rank in ENTRY" );
2024
2040
// The box is read right away because lowering code does not expect
2025
2041
// a non pointer/allocatable symbol to be mapped to a MutableBox.
2026
2042
mlir::Type ty = converter.genType (var);
@@ -2042,6 +2058,13 @@ void Fortran::lower::mapSymbolAttributes(
2042
2058
return false ;
2043
2059
};
2044
2060
2061
+ if (isAssumedRank) {
2062
+ assert (isUnusedEntryDummy && " assumed rank must be pointers/allocatables "
2063
+ " or descriptor dummy arguments" );
2064
+ genUnusedEntryPointBox ();
2065
+ return ;
2066
+ }
2067
+
2045
2068
// Helper to generate scalars for the symbol properties.
2046
2069
auto genValue = [&](const Fortran::lower::SomeExpr &expr) {
2047
2070
return genScalarValue (converter, loc, expr, symMap, stmtCtx);
0 commit comments