aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorjeanPerier <jperier@nvidia.com>2023-12-06 14:20:06 +0100
committerGitHub <noreply@github.com>2023-12-06 14:20:06 +0100
commite59e848805f57bd52ebbb0f7f7d4d951e6af597c (patch)
treee83a8776a07bd467dc9d44547b1af660b2303f8d /flang/lib/Frontend/CompilerInvocation.cpp
parentd77067d08a3f56dc2d0e6c95bd2852c943df743a (diff)
downloadllvm-e59e848805f57bd52ebbb0f7f7d4d951e6af597c.zip
llvm-e59e848805f57bd52ebbb0f7f7d4d951e6af597c.tar.gz
llvm-e59e848805f57bd52ebbb0f7f7d4d951e6af597c.tar.bz2
[flang] Updating drivers to create data layout before semantics (#73301)
Preliminary patch to change lowering/code generation to use llvm::DataLayout information instead of generating "sizeof" GEP (see https://github.com/llvm/llvm-project/issues/71507). Fortran Semantic analysis needs to know about the target type size and alignment to deal with common blocks, and intrinsics like C_SIZEOF/TRANSFER. This information should be obtained from the llvm::DataLayout so that it is consistent during the whole compilation flow. This change is changing flang-new and bbc drivers to: 1. Create the llvm::TargetMachine so that the data layout of the target can be obtained before semantics. 2. Sharing bbc/flang-new set-up of the SemanticConstext.targetCharateristics from the llvm::TargetMachine. For now, the actual part that set-up the Fortran type size and alignment from the llvm::DataLayout is left TODO so that this change is mostly an NFC impacting the drivers. 3. Let the lowering bridge set-up the mlir::Module datalayout attributes since it is doing it for the target attribute, and that allows the llvm data layout information to be available during lowering. For flang-new, the changes are code shuffling: the `llvm::TargetMachine` instance is moved to `CompilerInvocation` class so that it can be used to set-up the semantic contexts. `setMLIRDataLayout` is moved to `flang/Optimizer/Support/DataLayout.h` (it will need to be used from codegen pass for fir-opt target independent testing.)), and the code setting-up semantics targetCharacteristics is moved to `Tools/TargetSetup.h` so that it can be shared with bbc. As a consequence, LLVM targets must be registered when running semantics, and it is not possible to run semantics for a target that is not registered with the -triple option (hence the power pc specific modules can only be built if the PowerPC target is available.
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp23
1 files changed, 7 insertions, 16 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index c623969..b3f32bb 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -18,6 +18,7 @@
#include "flang/Frontend/PreprocessorOptions.h"
#include "flang/Frontend/TargetOptions.h"
#include "flang/Semantics/semantics.h"
+#include "flang/Tools/TargetSetup.h"
#include "flang/Version.inc"
#include "clang/Basic/AllDiagnostics.h"
#include "clang/Basic/DiagnosticDriver.h"
@@ -1347,7 +1348,8 @@ void CompilerInvocation::setFortranOpts() {
std::unique_ptr<Fortran::semantics::SemanticsContext>
CompilerInvocation::getSemanticsCtx(
- Fortran::parser::AllCookedSources &allCookedSources) {
+ Fortran::parser::AllCookedSources &allCookedSources,
+ const llvm::TargetMachine &targetMachine) {
auto &fortranOptions = getFortranOpts();
auto semanticsContext = std::make_unique<semantics::SemanticsContext>(
@@ -1360,21 +1362,10 @@ CompilerInvocation::getSemanticsCtx(
.set_moduleFileSuffix(getModuleFileSuffix())
.set_underscoring(getCodeGenOpts().Underscoring);
- llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)};
- // FIXME: Handle real(3) ?
- if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64) {
- semanticsContext->targetCharacteristics().DisableType(
- Fortran::common::TypeCategory::Real, /*kind=*/10);
- }
-
- std::string version = Fortran::common::getFlangFullVersion();
- semanticsContext->targetCharacteristics()
- .set_compilerOptionsString(allCompilerInvocOpts)
- .set_compilerVersionString(version);
-
- if (targetTriple.isPPC())
- semanticsContext->targetCharacteristics().set_isPPC(true);
-
+ std::string compilerVersion = Fortran::common::getFlangFullVersion();
+ Fortran::tools::setUpTargetCharacteristics(
+ semanticsContext->targetCharacteristics(), targetMachine, compilerVersion,
+ allCompilerInvocOpts);
return semanticsContext;
}