@@ -578,7 +578,8 @@ void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) {
578578}
579579
580580// TargetMachine factory
581- std::unique_ptr<TargetMachine> TargetMachineBuilder::create () const {
581+ std::unique_ptr<TargetMachine>
582+ TargetMachineBuilder::create (const StringRef TargetABI) const {
582583 std::string ErrMsg;
583584 const Target *TheTarget =
584585 TargetRegistry::lookupTarget (TheTriple.str (), ErrMsg);
@@ -588,7 +589,7 @@ std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
588589
589590 // Use MAttr as the default set of features.
590591 SubtargetFeatures Features (MAttr);
591- Features.getDefaultSubtargetFeatures (TheTriple);
592+ Features.getDefaultSubtargetFeatures (TheTriple, TargetABI );
592593 std::string FeatureStr = Features.getString ();
593594
594595 std::unique_ptr<TargetMachine> TM (
@@ -914,10 +915,13 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
914915 */
915916void ThinLTOCodeGenerator::optimize (Module &TheModule) {
916917 initTMBuilder (TMBuilder, Triple (TheModule.getTargetTriple ()));
917-
918+ StringRef TargetABI = " " ;
919+ if (auto *TargetABIMD =
920+ dyn_cast_or_null<MDString>(TheModule.getModuleFlag (" target-abi" )))
921+ TargetABI = TargetABIMD->getString ();
918922 // Optimize now
919- optimizeModule (TheModule, *TMBuilder.create (), OptLevel, Freestanding ,
920- DebugPassManager, nullptr );
923+ optimizeModule (TheModule, *TMBuilder.create (TargetABI ), OptLevel,
924+ Freestanding, DebugPassManager, nullptr );
921925}
922926
923927// / Write out the generated object file, either from CacheEntryPath or from
@@ -992,8 +996,13 @@ void ThinLTOCodeGenerator::run() {
992996 auto TheModule = loadModuleFromInput (Mod.get (), Context, false ,
993997 /* IsImporting*/ false );
994998
999+ StringRef TargetABI = " " ;
1000+ if (auto *TargetABIMD = dyn_cast_or_null<MDString>(
1001+ TheModule->getModuleFlag (" target-abi" )))
1002+ TargetABI = TargetABIMD->getString ();
9951003 // CodeGen
996- auto OutputBuffer = codegenModule (*TheModule, *TMBuilder.create ());
1004+ auto OutputBuffer =
1005+ codegenModule (*TheModule, *TMBuilder.create (TargetABI));
9971006 if (SavedObjectsDirectoryPath.empty ())
9981007 ProducedBinaries[count] = std::move (OutputBuffer);
9991008 else
@@ -1181,10 +1190,14 @@ void ThinLTOCodeGenerator::run() {
11811190 saveTempBitcode (*TheModule, SaveTempsDir, count, " .0.original.bc" );
11821191
11831192 auto &ImportList = ImportLists[ModuleIdentifier];
1193+ StringRef TargetABI = " " ;
1194+ if (auto *TargetABIMD = dyn_cast_or_null<MDString>(
1195+ TheModule->getModuleFlag (" target-abi" )))
1196+ TargetABI = TargetABIMD->getString ();
11841197 // Run the main process now, and generates a binary
11851198 auto OutputBuffer = ProcessThinLTOModule (
1186- *TheModule, *Index, ModuleMap, *TMBuilder.create (), ImportList ,
1187- ExportList, GUIDPreservedSymbols,
1199+ *TheModule, *Index, ModuleMap, *TMBuilder.create (TargetABI) ,
1200+ ImportList, ExportList, GUIDPreservedSymbols,
11881201 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
11891202 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
11901203 DebugPassManager);
0 commit comments