[flang-commits] [flang] 4546397 - [flang] Introduce option to lower expression to HLFIR
Jean Perier via flang-commits
flang-commits at lists.llvm.org
Mon Oct 17 01:11:52 PDT 2022
Author: Jean Perier
Date: 2022-10-17T10:02:56+02:00
New Revision: 4546397e39589f0a6a707218349d1bf65fe54645
URL: https://github.com/llvm/llvm-project/commit/4546397e39589f0a6a707218349d1bf65fe54645
DIFF: https://github.com/llvm/llvm-project/commit/4546397e39589f0a6a707218349d1bf65fe54645.diff
LOG: [flang] Introduce option to lower expression to HLFIR
Preliminary work on HLFIR. Introduce option that will allow testing
lowering via HLFIR until this is ready to replace the current expression
lowering.
See https://reviews.llvm.org/D134285 for more context about the plan.
Differential Revision: https://reviews.llvm.org/D135959
Added:
flang/test/Lower/HLFIR/expr-addr.f90
flang/test/Lower/HLFIR/expr-box.f90
flang/test/Lower/HLFIR/expr-value.f90
Modified:
flang/include/flang/Lower/AbstractConverter.h
flang/include/flang/Lower/LoweringOptions.h
flang/lib/Lower/Bridge.cpp
flang/tools/bbc/bbc.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Lower/AbstractConverter.h b/flang/include/flang/Lower/AbstractConverter.h
index 6ab649ccf020a..a84e34f4bd8a4 100644
--- a/flang/include/flang/Lower/AbstractConverter.h
+++ b/flang/include/flang/Lower/AbstractConverter.h
@@ -128,7 +128,7 @@ class AbstractConverter {
/// expression value. The clean-up for this temporary is added to \p context.
virtual fir::ExtendedValue genExprAddr(const SomeExpr &expr,
StatementContext &context,
- mlir::Location *loc = nullptr) = 0;
+ mlir::Location *locPtr = nullptr) = 0;
/// Generate the address of the location holding the expression, \p expr.
fir::ExtendedValue genExprAddr(mlir::Location loc, const SomeExpr *expr,
@@ -143,7 +143,7 @@ class AbstractConverter {
/// Generate the computations of the expression to produce a value.
virtual fir::ExtendedValue genExprValue(const SomeExpr &expr,
StatementContext &context,
- mlir::Location *loc = nullptr) = 0;
+ mlir::Location *locPtr = nullptr) = 0;
/// Generate the computations of the expression, \p expr, to produce a value.
fir::ExtendedValue genExprValue(mlir::Location loc, const SomeExpr *expr,
diff --git a/flang/include/flang/Lower/LoweringOptions.h b/flang/include/flang/Lower/LoweringOptions.h
index 58736568362db..d882ff0fb233a 100644
--- a/flang/include/flang/Lower/LoweringOptions.h
+++ b/flang/include/flang/Lower/LoweringOptions.h
@@ -24,8 +24,14 @@ class LoweringOptions {
/// If true, enable polymorphic type lowering feature. Off by default.
unsigned polymorphicTypeImpl : 1;
+ /// If true, lower to High level FIR before lowering to FIR.
+ /// Off by default until fully ready.
+ unsigned lowerToHighLevelFIR : 1;
+
public:
- LoweringOptions() : optimizeTranspose(true), polymorphicTypeImpl(false) {}
+ LoweringOptions()
+ : optimizeTranspose(true), polymorphicTypeImpl(false),
+ lowerToHighLevelFIR(false) {}
bool getOptimizeTranspose() const { return optimizeTranspose; }
LoweringOptions &setOptimizeTranspose(bool v) {
@@ -38,6 +44,12 @@ class LoweringOptions {
polymorphicTypeImpl = v;
return *this;
}
+
+ bool getLowerToHighLevelFIR() const { return lowerToHighLevelFIR; }
+ LoweringOptions &setLowerToHighLevelFIR(bool v) {
+ lowerToHighLevelFIR = v;
+ return *this;
+ }
};
} // namespace Fortran::lower
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index b40dfd41b5c29..ac29207e31a43 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -416,23 +416,32 @@ class FirConverter : public Fortran::lower::AbstractConverter {
return iter->second;
}
- fir::ExtendedValue genExprAddr(const Fortran::lower::SomeExpr &expr,
- Fortran::lower::StatementContext &context,
- mlir::Location *loc = nullptr) override final {
- return Fortran::lower::createSomeExtendedAddress(
- loc ? *loc : toLocation(), *this, expr, localSymbols, context);
+ fir::ExtendedValue
+ genExprAddr(const Fortran::lower::SomeExpr &expr,
+ Fortran::lower::StatementContext &context,
+ mlir::Location *locPtr = nullptr) override final {
+ mlir::Location loc = locPtr ? *locPtr : toLocation();
+ if (bridge.getLoweringOptions().getLowerToHighLevelFIR())
+ TODO(loc, "lower expr to HLFIR address");
+ return Fortran::lower::createSomeExtendedAddress(loc, *this, expr,
+ localSymbols, context);
}
fir::ExtendedValue
genExprValue(const Fortran::lower::SomeExpr &expr,
Fortran::lower::StatementContext &context,
- mlir::Location *loc = nullptr) override final {
- return Fortran::lower::createSomeExtendedExpression(
- loc ? *loc : toLocation(), *this, expr, localSymbols, context);
+ mlir::Location *locPtr = nullptr) override final {
+ mlir::Location loc = locPtr ? *locPtr : toLocation();
+ if (bridge.getLoweringOptions().getLowerToHighLevelFIR())
+ TODO(loc, "lower expr to HLFIR value");
+ return Fortran::lower::createSomeExtendedExpression(loc, *this, expr,
+ localSymbols, context);
}
fir::ExtendedValue
genExprBox(mlir::Location loc, const Fortran::lower::SomeExpr &expr,
Fortran::lower::StatementContext &stmtCtx) override final {
+ if (bridge.getLoweringOptions().getLowerToHighLevelFIR())
+ TODO(loc, "lower expr to HLFIR box");
return Fortran::lower::createBoxValue(loc, *this, expr, localSymbols,
stmtCtx);
}
diff --git a/flang/test/Lower/HLFIR/expr-addr.f90 b/flang/test/Lower/HLFIR/expr-addr.f90
new file mode 100644
index 0000000000000..1af59e6cb0548
--- /dev/null
+++ b/flang/test/Lower/HLFIR/expr-addr.f90
@@ -0,0 +1,8 @@
+! Test lowering of of expressions as address
+! RUN: %not_todo_cmd bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
+
+subroutine foo(x)
+ integer :: x
+ ! CHECK: not yet implemented: lower expr to HLFIR address
+ read (*,*) x
+end subroutine
diff --git a/flang/test/Lower/HLFIR/expr-box.f90 b/flang/test/Lower/HLFIR/expr-box.f90
new file mode 100644
index 0000000000000..d011d79e4def2
--- /dev/null
+++ b/flang/test/Lower/HLFIR/expr-box.f90
@@ -0,0 +1,8 @@
+! Test lowering of of expressions as fir.box
+! RUN: %not_todo_cmd bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
+
+subroutine foo(x)
+ integer :: x(:)
+ ! CHECK: not yet implemented: lower expr to HLFIR box
+ print *, x
+end subroutine
diff --git a/flang/test/Lower/HLFIR/expr-value.f90 b/flang/test/Lower/HLFIR/expr-value.f90
new file mode 100644
index 0000000000000..0a993bc0c1d98
--- /dev/null
+++ b/flang/test/Lower/HLFIR/expr-value.f90
@@ -0,0 +1,7 @@
+! Test lowering of of expressions as values
+! RUN: %not_todo_cmd bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
+
+subroutine foo()
+ ! CHECK: not yet implemented: lower expr to HLFIR value
+ print *, 42
+end subroutine
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index bd40c9af5f894..796e7faa28807 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -131,6 +131,10 @@ static llvm::cl::opt<bool> enablePolymorphic(
llvm::cl::desc("enable polymorphic type lowering (experimental)"),
llvm::cl::init(false));
+static llvm::cl::opt<bool> useHLFIR("hlfir",
+ llvm::cl::desc("Lower to high level FIR"),
+ llvm::cl::init(false));
+
#define FLANG_EXCLUDE_CODEGEN
#include "flang/Tools/CLOptions.inc"
@@ -227,6 +231,7 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
// Use default lowering options for bbc.
Fortran::lower::LoweringOptions loweringOptions{};
loweringOptions.setPolymorphicTypeImpl(enablePolymorphic);
+ loweringOptions.setLowerToHighLevelFIR(useHLFIR);
auto burnside = Fortran::lower::LoweringBridge::create(
ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
semanticsContext.targetCharacteristics(), parsing.allCooked(), "",
More information about the flang-commits
mailing list