aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend
diff options
context:
space:
mode:
authorSlava Zakharin <szakharin@nvidia.com>2022-07-19 20:39:58 -0700
committerSlava Zakharin <szakharin@nvidia.com>2022-08-05 11:29:45 -0700
commitf1eb945f9a5037b1fac6da02405047b24c0c2de5 (patch)
tree65fe255cbe27f7b8ac2ececf5cbc1f91f0ed6935 /flang/lib/Frontend
parent9c81b743e31a7dca288b37b6cf6cca3213bfd923 (diff)
downloadllvm-f1eb945f9a5037b1fac6da02405047b24c0c2de5.zip
llvm-f1eb945f9a5037b1fac6da02405047b24c0c2de5.tar.gz
llvm-f1eb945f9a5037b1fac6da02405047b24c0c2de5.tar.bz2
[flang] Propagate lowering options from driver.
This commit addresses concerns raised in D129497. Propagate lowering options from driver to expressions lowering via AbstractConverter instance. A single use case so far is using optimized TRANSPOSE lowering with O1/O2/O3. bbc does not support optimization level switches, so it uses default LoweringOptions (e.g. optimized TRANSPOSE lowering is enabled by default, but an engineering -opt-transpose=false option can still override this). Differential Revision: https://reviews.llvm.org/D130204
Diffstat (limited to 'flang/lib/Frontend')
-rw-r--r--flang/lib/Frontend/CompilerInstance.cpp2
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp9
-rw-r--r--flang/lib/Frontend/FrontendActions.cpp2
3 files changed, 12 insertions, 1 deletions
diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index 418c83c..5a33f5b 100644
--- a/flang/lib/Frontend/CompilerInstance.cpp
+++ b/flang/lib/Frontend/CompilerInstance.cpp
@@ -151,6 +151,8 @@ bool CompilerInstance::executeAction(FrontendAction &act) {
allSources->set_encoding(invoc.getFortranOpts().encoding);
// Create the semantics context and set semantic options.
invoc.setSemanticsOpts(*this->allCookedSources);
+ // Set options controlling lowering to FIR.
+ invoc.setLoweringOptions();
// Run the frontend action `act` for every input file.
for (const FrontendInputFile &fif : getFrontendOpts().inputs) {
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index f794eb7..a75c04d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -794,3 +794,12 @@ void CompilerInvocation::setSemanticsOpts(
.set_warningsAreErrors(getWarnAsErr())
.set_moduleFileSuffix(getModuleFileSuffix());
}
+
+/// Set \p loweringOptions controlling lowering behavior based
+/// on the \p optimizationLevel.
+void CompilerInvocation::setLoweringOptions() {
+ const auto &codegenOpts = getCodeGenOpts();
+
+ // Lower TRANSPOSE as a runtime call under -O0.
+ loweringOpts.setOptimizeTranspose(codegenOpts.OptimizationLevel > 0);
+}
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 7591e1a..4ebe2ea 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -148,7 +148,7 @@ bool CodeGenAction::beginSourceFileAction() {
*mlirCtx, defKinds, ci.getInvocation().getSemanticsContext().intrinsics(),
ci.getInvocation().getSemanticsContext().targetCharacteristics(),
ci.getParsing().allCooked(), ci.getInvocation().getTargetOpts().triple,
- kindMap);
+ kindMap, ci.getInvocation().getLoweringOpts());
// Create a parse tree and lower it to FIR
Fortran::parser::Program &parseTree{*ci.getParsing().parseTree()};