6060#include " llvm/Transforms/IPO/WholeProgramDevirt.h"
6161#include " llvm/Transforms/ObjCARC.h"
6262#include " llvm/Transforms/Utils/FunctionImportUtils.h"
63+ #include " llvm/Transforms/Utils/ModuleUtils.h"
6364
6465#include < numeric>
6566
@@ -577,7 +578,8 @@ void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) {
577578}
578579
579580// TargetMachine factory
580- std::unique_ptr<TargetMachine> TargetMachineBuilder::create () const {
581+ std::unique_ptr<TargetMachine>
582+ TargetMachineBuilder::create (const StringRef TargetABI) const {
581583 std::string ErrMsg;
582584 const Target *TheTarget =
583585 TargetRegistry::lookupTarget (TheTriple.str (), ErrMsg);
@@ -587,7 +589,7 @@ std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
587589
588590 // Use MAttr as the default set of features.
589591 SubtargetFeatures Features (MAttr);
590- Features.getDefaultSubtargetFeatures (TheTriple);
592+ Features.getDefaultSubtargetFeatures (TheTriple, TargetABI );
591593 std::string FeatureStr = Features.getString ();
592594
593595 std::unique_ptr<TargetMachine> TM (
@@ -912,10 +914,11 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
912914 */
913915void ThinLTOCodeGenerator::optimize (Module &TheModule) {
914916 initTMBuilder (TMBuilder, Triple (TheModule.getTargetTriple ()));
917+ StringRef TargetABI = TMBuilder.Options .MCOptions .getABIName ();
915918
916919 // Optimize now
917- optimizeModule (TheModule, *TMBuilder.create (), OptLevel, Freestanding ,
918- DebugPassManager, nullptr );
920+ optimizeModule (TheModule, *TMBuilder.create (TargetABI ), OptLevel,
921+ Freestanding, DebugPassManager, nullptr );
919922}
920923
921924// / Write out the generated object file, either from CacheEntryPath or from
@@ -989,9 +992,11 @@ void ThinLTOCodeGenerator::run() {
989992 // Parse module now
990993 auto TheModule = loadModuleFromInput (Mod.get (), Context, false ,
991994 /* IsImporting*/ false );
995+ StringRef TargetABI = TMBuilder.Options .MCOptions .getABIName ();
992996
993997 // CodeGen
994- auto OutputBuffer = codegenModule (*TheModule, *TMBuilder.create ());
998+ auto OutputBuffer =
999+ codegenModule (*TheModule, *TMBuilder.create (TargetABI));
9951000 if (SavedObjectsDirectoryPath.empty ())
9961001 ProducedBinaries[count] = std::move (OutputBuffer);
9971002 else
@@ -1176,10 +1181,12 @@ void ThinLTOCodeGenerator::run() {
11761181 saveTempBitcode (*TheModule, SaveTempsDir, count, " .0.original.bc" );
11771182
11781183 auto &ImportList = ImportLists[ModuleIdentifier];
1184+ StringRef TargetABI = TMBuilder.Options .MCOptions .getABIName ();
1185+
11791186 // Run the main process now, and generates a binary
11801187 auto OutputBuffer = ProcessThinLTOModule (
1181- *TheModule, *Index, ModuleMap, *TMBuilder.create (), ImportList ,
1182- ExportList, GUIDPreservedSymbols,
1188+ *TheModule, *Index, ModuleMap, *TMBuilder.create (TargetABI) ,
1189+ ImportList, ExportList, GUIDPreservedSymbols,
11831190 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
11841191 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
11851192 DebugPassManager);
0 commit comments