aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorYu-Hsun Chiang <ty1208chiang@gmail.com>2021-02-26 09:12:32 +0100
committerSam McCall <sam.mccall@gmail.com>2021-02-26 09:29:11 +0100
commitd412dbe388819dd68bbe4a3967783fdf80400860 (patch)
tree947222f1a754621cba0b06caac7e92605f919078 /clang/lib/Frontend/CompilerInstance.cpp
parent2a42c759ae7bb09dd448d188138f310d014fcab6 (diff)
downloadllvm-d412dbe388819dd68bbe4a3967783fdf80400860.zip
llvm-d412dbe388819dd68bbe4a3967783fdf80400860.tar.gz
llvm-d412dbe388819dd68bbe4a3967783fdf80400860.tar.bz2
[clang][NFC] Extract Target and AuxTarget creation in CompilerInstance to new function
As @sammccall mentioned in [[ https://reviews.llvm.org/D97109 | D97109 ]], I've extract the logic of creating Target and AuxTarget into a new function called `createTargetAndAuxTarget`. Since there are many similar code in clang or other related tools, consolidating them into a single function may help others to maintain the logic handling target related things. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D97493
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp92
1 files changed, 49 insertions, 43 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 7c2b2bf..d40240b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -97,6 +97,54 @@ void CompilerInstance::setVerboseOutputStream(std::unique_ptr<raw_ostream> Value
void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
+bool CompilerInstance::createTarget() {
+ // Create the target instance.
+ setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
+ getInvocation().TargetOpts));
+ if (!hasTarget())
+ return false;
+
+ // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
+ if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
+ getLangOpts().SYCLIsDevice) &&
+ !getFrontendOpts().AuxTriple.empty()) {
+ auto TO = std::make_shared<TargetOptions>();
+ TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);
+ if (getFrontendOpts().AuxTargetCPU)
+ TO->CPU = getFrontendOpts().AuxTargetCPU.getValue();
+ if (getFrontendOpts().AuxTargetFeatures)
+ TO->FeaturesAsWritten = getFrontendOpts().AuxTargetFeatures.getValue();
+ TO->HostTriple = getTarget().getTriple().str();
+ setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO));
+ }
+
+ if (!getTarget().hasStrictFP() && !getLangOpts().ExpStrictFP) {
+ if (getLangOpts().getFPRoundingMode() !=
+ llvm::RoundingMode::NearestTiesToEven) {
+ getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_rounding);
+ getLangOpts().setFPRoundingMode(llvm::RoundingMode::NearestTiesToEven);
+ }
+ if (getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore) {
+ getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_exceptions);
+ getLangOpts().setFPExceptionMode(LangOptions::FPE_Ignore);
+ }
+ // FIXME: can we disable FEnvAccess?
+ }
+
+ // Inform the target of the language options.
+ // FIXME: We shouldn't need to do this, the target should be immutable once
+ // created. This complexity should be lifted elsewhere.
+ getTarget().adjust(getLangOpts());
+
+ // Adjust target options based on codegen options.
+ getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
+
+ if (auto *Aux = getAuxTarget())
+ getTarget().setAuxTarget(Aux);
+
+ return true;
+}
+
llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const {
return getFileManager().getVirtualFileSystem();
}
@@ -878,51 +926,9 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
if (!Act.PrepareToExecute(*this))
return false;
- // Create the target instance.
- setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
- getInvocation().TargetOpts));
- if (!hasTarget())
+ if (!createTarget())
return false;
- // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
- if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
- getLangOpts().SYCLIsDevice) &&
- !getFrontendOpts().AuxTriple.empty()) {
- auto TO = std::make_shared<TargetOptions>();
- TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);
- if (getFrontendOpts().AuxTargetCPU)
- TO->CPU = getFrontendOpts().AuxTargetCPU.getValue();
- if (getFrontendOpts().AuxTargetFeatures)
- TO->FeaturesAsWritten = getFrontendOpts().AuxTargetFeatures.getValue();
- TO->HostTriple = getTarget().getTriple().str();
- setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO));
- }
-
- if (!getTarget().hasStrictFP() && !getLangOpts().ExpStrictFP) {
- if (getLangOpts().getFPRoundingMode() !=
- llvm::RoundingMode::NearestTiesToEven) {
- getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_rounding);
- getLangOpts().setFPRoundingMode(llvm::RoundingMode::NearestTiesToEven);
- }
- if (getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore) {
- getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_exceptions);
- getLangOpts().setFPExceptionMode(LangOptions::FPE_Ignore);
- }
- // FIXME: can we disable FEnvAccess?
- }
-
- // Inform the target of the language options.
- //
- // FIXME: We shouldn't need to do this, the target should be immutable once
- // created. This complexity should be lifted elsewhere.
- getTarget().adjust(getLangOpts());
-
- // Adjust target options based on codegen options.
- getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
-
- if (auto *Aux = getAuxTarget())
- getTarget().setAuxTarget(Aux);
-
// rewriter project will change target built-in bool type from its default.
if (getFrontendOpts().ProgramAction == frontend::RewriteObjC)
getTarget().noSignedCharForObjCBool();