@@ -582,7 +582,8 @@ void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) {
582582}
583583
584584// TargetMachine factory
585- std::unique_ptr<TargetMachine> TargetMachineBuilder::create () const {
585+ std::unique_ptr<TargetMachine>
586+ TargetMachineBuilder::create (const StringRef TargetABI) const {
586587 std::string ErrMsg;
587588 const Target *TheTarget =
588589 TargetRegistry::lookupTarget (TheTriple.str (), ErrMsg);
@@ -592,7 +593,7 @@ std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
592593
593594 // Use MAttr as the default set of features.
594595 SubtargetFeatures Features (MAttr);
595- Features.getDefaultSubtargetFeatures (TheTriple);
596+ Features.getDefaultSubtargetFeatures (TheTriple, TargetABI );
596597 std::string FeatureStr = Features.getString ();
597598
598599 std::unique_ptr<TargetMachine> TM (
@@ -918,10 +919,13 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
918919 */
919920void ThinLTOCodeGenerator::optimize (Module &TheModule) {
920921 initTMBuilder (TMBuilder, Triple (TheModule.getTargetTriple ()));
921-
922+ StringRef TargetABI = " " ;
923+ if (auto TargetABIMD =
924+ dyn_cast_or_null<MDString>(TheModule.getModuleFlag (" target-abi" )))
925+ TargetABI = TargetABIMD->getString ();
922926 // Optimize now
923- optimizeModule (TheModule, *TMBuilder.create (), OptLevel, Freestanding ,
924- DebugPassManager, nullptr );
927+ optimizeModule (TheModule, *TMBuilder.create (TargetABI ), OptLevel,
928+ Freestanding, DebugPassManager, nullptr );
925929}
926930
927931// / Write out the generated object file, either from CacheEntryPath or from
@@ -996,8 +1000,13 @@ void ThinLTOCodeGenerator::run() {
9961000 auto TheModule = loadModuleFromInput (Mod.get (), Context, false ,
9971001 /* IsImporting*/ false );
9981002
1003+ StringRef TargetABI = " " ;
1004+ if (auto TargetABIMD = dyn_cast_or_null<MDString>(
1005+ TheModule->getModuleFlag (" target-abi" )))
1006+ TargetABI = TargetABIMD->getString ();
9991007 // CodeGen
1000- auto OutputBuffer = codegenModule (*TheModule, *TMBuilder.create ());
1008+ auto OutputBuffer =
1009+ codegenModule (*TheModule, *TMBuilder.create (TargetABI));
10011010 if (SavedObjectsDirectoryPath.empty ())
10021011 ProducedBinaries[count] = std::move (OutputBuffer);
10031012 else
@@ -1185,10 +1194,14 @@ void ThinLTOCodeGenerator::run() {
11851194 saveTempBitcode (*TheModule, SaveTempsDir, count, " .0.original.bc" );
11861195
11871196 auto &ImportList = ImportLists[ModuleIdentifier];
1197+ StringRef TargetABI = " " ;
1198+ if (auto TargetABIMD = dyn_cast_or_null<MDString>(
1199+ TheModule->getModuleFlag (" target-abi" )))
1200+ TargetABI = TargetABIMD->getString ();
11881201 // Run the main process now, and generates a binary
11891202 auto OutputBuffer = ProcessThinLTOModule (
1190- *TheModule, *Index, ModuleMap, *TMBuilder.create (), ImportList ,
1191- ExportList, GUIDPreservedSymbols,
1203+ *TheModule, *Index, ModuleMap, *TMBuilder.create (TargetABI) ,
1204+ ImportList, ExportList, GUIDPreservedSymbols,
11921205 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
11931206 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
11941207 DebugPassManager);
0 commit comments