@@ -97,6 +97,54 @@ void CompilerInstance::setVerboseOutputStream(std::unique_ptr<raw_ostream> Value
97
97
void CompilerInstance::setTarget (TargetInfo *Value) { Target = Value; }
98
98
void CompilerInstance::setAuxTarget (TargetInfo *Value) { AuxTarget = Value; }
99
99
100
+ bool CompilerInstance::createTarget () {
101
+ // Create the target instance.
102
+ setTarget (TargetInfo::CreateTargetInfo (getDiagnostics (),
103
+ getInvocation ().TargetOpts ));
104
+ if (!hasTarget ())
105
+ return false ;
106
+
107
+ // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
108
+ if ((getLangOpts ().CUDA || getLangOpts ().OpenMPIsDevice ||
109
+ getLangOpts ().SYCLIsDevice ) &&
110
+ !getFrontendOpts ().AuxTriple .empty ()) {
111
+ auto TO = std::make_shared<TargetOptions>();
112
+ TO->Triple = llvm::Triple::normalize (getFrontendOpts ().AuxTriple );
113
+ if (getFrontendOpts ().AuxTargetCPU )
114
+ TO->CPU = getFrontendOpts ().AuxTargetCPU .getValue ();
115
+ if (getFrontendOpts ().AuxTargetFeatures )
116
+ TO->FeaturesAsWritten = getFrontendOpts ().AuxTargetFeatures .getValue ();
117
+ TO->HostTriple = getTarget ().getTriple ().str ();
118
+ setAuxTarget (TargetInfo::CreateTargetInfo (getDiagnostics (), TO));
119
+ }
120
+
121
+ if (!getTarget ().hasStrictFP () && !getLangOpts ().ExpStrictFP ) {
122
+ if (getLangOpts ().getFPRoundingMode () !=
123
+ llvm::RoundingMode::NearestTiesToEven) {
124
+ getDiagnostics ().Report (diag::warn_fe_backend_unsupported_fp_rounding);
125
+ getLangOpts ().setFPRoundingMode (llvm::RoundingMode::NearestTiesToEven);
126
+ }
127
+ if (getLangOpts ().getFPExceptionMode () != LangOptions::FPE_Ignore) {
128
+ getDiagnostics ().Report (diag::warn_fe_backend_unsupported_fp_exceptions);
129
+ getLangOpts ().setFPExceptionMode (LangOptions::FPE_Ignore);
130
+ }
131
+ // FIXME: can we disable FEnvAccess?
132
+ }
133
+
134
+ // Inform the target of the language options.
135
+ // FIXME: We shouldn't need to do this, the target should be immutable once
136
+ // created. This complexity should be lifted elsewhere.
137
+ getTarget ().adjust (getLangOpts ());
138
+
139
+ // Adjust target options based on codegen options.
140
+ getTarget ().adjustTargetOptions (getCodeGenOpts (), getTargetOpts ());
141
+
142
+ if (auto *Aux = getAuxTarget ())
143
+ getTarget ().setAuxTarget (Aux);
144
+
145
+ return true ;
146
+ }
147
+
100
148
llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem () const {
101
149
return getFileManager ().getVirtualFileSystem ();
102
150
}
@@ -878,51 +926,9 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
878
926
if (!Act.PrepareToExecute (*this ))
879
927
return false ;
880
928
881
- // Create the target instance.
882
- setTarget (TargetInfo::CreateTargetInfo (getDiagnostics (),
883
- getInvocation ().TargetOpts ));
884
- if (!hasTarget ())
929
+ if (!createTarget ())
885
930
return false ;
886
931
887
- // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
888
- if ((getLangOpts ().CUDA || getLangOpts ().OpenMPIsDevice ||
889
- getLangOpts ().SYCLIsDevice ) &&
890
- !getFrontendOpts ().AuxTriple .empty ()) {
891
- auto TO = std::make_shared<TargetOptions>();
892
- TO->Triple = llvm::Triple::normalize (getFrontendOpts ().AuxTriple );
893
- if (getFrontendOpts ().AuxTargetCPU )
894
- TO->CPU = getFrontendOpts ().AuxTargetCPU .getValue ();
895
- if (getFrontendOpts ().AuxTargetFeatures )
896
- TO->FeaturesAsWritten = getFrontendOpts ().AuxTargetFeatures .getValue ();
897
- TO->HostTriple = getTarget ().getTriple ().str ();
898
- setAuxTarget (TargetInfo::CreateTargetInfo (getDiagnostics (), TO));
899
- }
900
-
901
- if (!getTarget ().hasStrictFP () && !getLangOpts ().ExpStrictFP ) {
902
- if (getLangOpts ().getFPRoundingMode () !=
903
- llvm::RoundingMode::NearestTiesToEven) {
904
- getDiagnostics ().Report (diag::warn_fe_backend_unsupported_fp_rounding);
905
- getLangOpts ().setFPRoundingMode (llvm::RoundingMode::NearestTiesToEven);
906
- }
907
- if (getLangOpts ().getFPExceptionMode () != LangOptions::FPE_Ignore) {
908
- getDiagnostics ().Report (diag::warn_fe_backend_unsupported_fp_exceptions);
909
- getLangOpts ().setFPExceptionMode (LangOptions::FPE_Ignore);
910
- }
911
- // FIXME: can we disable FEnvAccess?
912
- }
913
-
914
- // Inform the target of the language options.
915
- //
916
- // FIXME: We shouldn't need to do this, the target should be immutable once
917
- // created. This complexity should be lifted elsewhere.
918
- getTarget ().adjust (getLangOpts ());
919
-
920
- // Adjust target options based on codegen options.
921
- getTarget ().adjustTargetOptions (getCodeGenOpts (), getTargetOpts ());
922
-
923
- if (auto *Aux = getAuxTarget ())
924
- getTarget ().setAuxTarget (Aux);
925
-
926
932
// rewriter project will change target built-in bool type from its default.
927
933
if (getFrontendOpts ().ProgramAction == frontend::RewriteObjC)
928
934
getTarget ().noSignedCharForObjCBool ();
0 commit comments