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
@@ -576,7 +577,8 @@ void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) {
576577}
577578
578579// TargetMachine factory
579- std::unique_ptr<TargetMachine> TargetMachineBuilder::create () const {
580+ std::unique_ptr<TargetMachine>
581+ TargetMachineBuilder::create (const StringRef TargetABI) const {
580582 std::string ErrMsg;
581583 const Target *TheTarget =
582584 TargetRegistry::lookupTarget (TheTriple.str (), ErrMsg);
@@ -586,7 +588,7 @@ std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
586588
587589 // Use MAttr as the default set of features.
588590 SubtargetFeatures Features (MAttr);
589- Features.getDefaultSubtargetFeatures (TheTriple);
591+ Features.getDefaultSubtargetFeatures (TheTriple, TargetABI );
590592 std::string FeatureStr = Features.getString ();
591593
592594 std::unique_ptr<TargetMachine> TM (
@@ -911,10 +913,11 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
911913 */
912914void ThinLTOCodeGenerator::optimize (Module &TheModule) {
913915 initTMBuilder (TMBuilder, Triple (TheModule.getTargetTriple ()));
916+ StringRef TargetABI = TMBuilder.Options .MCOptions .getABIName ();
914917
915918 // Optimize now
916- optimizeModule (TheModule, *TMBuilder.create (), OptLevel, Freestanding ,
917- DebugPassManager, nullptr );
919+ optimizeModule (TheModule, *TMBuilder.create (TargetABI ), OptLevel,
920+ Freestanding, DebugPassManager, nullptr );
918921}
919922
920923// / Write out the generated object file, either from CacheEntryPath or from
@@ -988,9 +991,11 @@ void ThinLTOCodeGenerator::run() {
988991 // Parse module now
989992 auto TheModule = loadModuleFromInput (Mod.get (), Context, false ,
990993 /* IsImporting*/ false );
994+ StringRef TargetABI = TMBuilder.Options .MCOptions .getABIName ();
991995
992996 // CodeGen
993- auto OutputBuffer = codegenModule (*TheModule, *TMBuilder.create ());
997+ auto OutputBuffer =
998+ codegenModule (*TheModule, *TMBuilder.create (TargetABI));
994999 if (SavedObjectsDirectoryPath.empty ())
9951000 ProducedBinaries[count] = std::move (OutputBuffer);
9961001 else
@@ -1175,10 +1180,12 @@ void ThinLTOCodeGenerator::run() {
11751180 saveTempBitcode (*TheModule, SaveTempsDir, count, " .0.original.bc" );
11761181
11771182 auto &ImportList = ImportLists[ModuleIdentifier];
1183+ StringRef TargetABI = TMBuilder.Options .MCOptions .getABIName ();
1184+
11781185 // Run the main process now, and generates a binary
11791186 auto OutputBuffer = ProcessThinLTOModule (
1180- *TheModule, *Index, ModuleMap, *TMBuilder.create (), ImportList ,
1181- ExportList, GUIDPreservedSymbols,
1187+ *TheModule, *Index, ModuleMap, *TMBuilder.create (TargetABI) ,
1188+ ImportList, ExportList, GUIDPreservedSymbols,
11821189 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
11831190 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
11841191 DebugPassManager);
0 commit comments