llvm.org GIT mirror llvm / 13456d6
[ThinLTO] Fix ThinLTOCodegenerator to export llvm.used symbols Summary: ThinLTOCodeGenerator currently does not preserve llvm.used symbols and it can internalize them. In order to pass the necessary information to the legacy ThinLTOCodeGenerator, the input to the code generator is rewritten to be based on lto::InputFile. This fixes: PR41236 rdar://problem/49293439 Reviewers: tejohnson, pcc, dexonsmith Reviewed By: tejohnson Subscribers: mehdi_amini, inglorion, eraman, hiraditya, jkorous, dang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60226 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357931 91177308-0d34-0410-b5e6-96231b3b80d8 Steven Wu 1 year, 7 months ago
7 changed file(s) with 191 addition(s) and 106 deletion(s). Raw diff Collapse all Expand all
130130 using irsymtab::Symbol::isWeak;
131131 using irsymtab::Symbol::isIndirect;
132132 using irsymtab::Symbol::getName;
133 using irsymtab::Symbol::getIRName;
133134 using irsymtab::Symbol::getVisibility;
134135 using irsymtab::Symbol::canBeOmittedFromSymbolTable;
135136 using irsymtab::Symbol::isTLS;
159160
160161 // Returns a table with all the comdats used by this file.
161162 ArrayRef getComdatTable() const { return ComdatTable; }
163
164 // Returns the only BitcodeModule from InputFile.
165 BitcodeModule &getSingleBitcodeModule();
162166
163167 private:
164168 ArrayRef module_symbols(unsigned I) const {
1818 #include "llvm/ADT/StringSet.h"
1919 #include "llvm/ADT/Triple.h"
2020 #include "llvm/IR/ModuleSummaryIndex.h"
21 #include "llvm/LTO/LTO.h"
2122 #include "llvm/Support/CachePruning.h"
2223 #include "llvm/Support/CodeGen.h"
2324 #include "llvm/Support/MemoryBuffer.h"
2930 class StringRef;
3031 class LLVMContext;
3132 class TargetMachine;
32
33 /// Wrapper around MemoryBufferRef, owning the identifier
34 class ThinLTOBuffer {
35 std::string OwnedIdentifier;
36 StringRef Buffer;
37
38 public:
39 ThinLTOBuffer(StringRef Buffer, StringRef Identifier)
40 : OwnedIdentifier(Identifier), Buffer(Buffer) {}
41
42 MemoryBufferRef getMemBuffer() const {
43 return MemoryBufferRef(Buffer,
44 {OwnedIdentifier.c_str(), OwnedIdentifier.size()});
45 }
46 StringRef getBuffer() const { return Buffer; }
47 StringRef getBufferIdentifier() const { return OwnedIdentifier; }
48 };
4933
5034 /// Helper to gather options relevant to the target machine creation
5135 struct TargetMachineBuilder {
266250 * and additionally resolve weak and linkonce symbols.
267251 * Index is updated to reflect linkage changes from weak resolution.
268252 */
269 void promote(Module &Module, ModuleSummaryIndex &Index);
253 void promote(Module &Module, ModuleSummaryIndex &Index,
254 const lto::InputFile &File);
270255
271256 /**
272257 * Compute and emit the imported files for module at \p ModulePath.
273258 */
274259 void emitImports(Module &Module, StringRef OutputName,
275 ModuleSummaryIndex &Index);
260 ModuleSummaryIndex &Index,
261 const lto::InputFile &File);
276262
277263 /**
278264 * Perform cross-module importing for the module identified by
279265 * ModuleIdentifier.
280266 */
281 void crossModuleImport(Module &Module, ModuleSummaryIndex &Index);
267 void crossModuleImport(Module &Module, ModuleSummaryIndex &Index,
268 const lto::InputFile &File);
282269
283270 /**
284271 * Compute the list of summaries needed for importing into module.
285272 */
286273 void gatherImportedSummariesForModule(
287274 Module &Module, ModuleSummaryIndex &Index,
288 std::map &ModuleToSummariesForIndex);
275 std::map &ModuleToSummariesForIndex,
276 const lto::InputFile &File);
289277
290278 /**
291279 * Perform internalization. Index is updated to reflect linkage changes.
292280 */
293 void internalize(Module &Module, ModuleSummaryIndex &Index);
281 void internalize(Module &Module, ModuleSummaryIndex &Index,
282 const lto::InputFile &File);
294283
295284 /**
296285 * Perform post-importing ThinLTO optimizations.
312301
313302 /// Vector holding the input buffers containing the bitcode modules to
314303 /// process.
315 std::vector<ThinLTOBuffer> Modules;
304 std::vector<std::unique_ptr> Modules;
316305
317306 /// Set of symbols that need to be preserved outside of the set of bitcode
318307 /// files.
419419 return Mods[0].getModuleIdentifier();
420420 }
421421
422 BitcodeModule &InputFile::getSingleBitcodeModule() {
423 assert(Mods.size() == 1 && "Expect only one bitcode module");
424 return Mods[0];
425 }
426
422427 LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
423428 Config &Conf)
424429 : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel),
134134 }
135135 }
136136
137 static StringMap
138 generateModuleMap(const std::vector &Modules) {
139 StringMap ModuleMap;
140 for (auto &ModuleBuffer : Modules) {
141 assert(ModuleMap.find(ModuleBuffer.getBufferIdentifier()) ==
142 ModuleMap.end() &&
137 static StringMap
138 generateModuleMap(std::vector> &Modules) {
139 StringMap ModuleMap;
140 for (auto &M : Modules) {
141 assert(ModuleMap.find(M->getName()) == ModuleMap.end() &&
143142 "Expect unique Buffer Identifier");
144 ModuleMap[ModuleBuffer.getBufferIdentifier()] = ModuleBuffer.getMemBuffer();
143 ModuleMap[M->getName()] = M.get();
145144 }
146145 return ModuleMap;
147146 }
174173 }
175174 }
176175
177 static std::unique_ptr
178 loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
179 bool Lazy, bool IsImporting) {
176 static std::unique_ptr loadModuleFromInput(lto::InputFile *Input,
177 LLVMContext &Context,
178 bool Lazy,
179 bool IsImporting) {
180 auto &Mod = Input->getSingleBitcodeModule();
180181 SMDiagnostic Err;
181182 Expected> ModuleOrErr =
182 Lazy
183 ? getLazyBitcodeModule(Buffer, Context,
184 /* ShouldLazyLoadMetadata */ true, IsImporting)
185 : parseBitcodeFile(Buffer, Context);
183 Lazy ? Mod.getLazyModule(Context,
184 /* ShouldLazyLoadMetadata */ true, IsImporting)
185 : Mod.parseModule(Context);
186186 if (!ModuleOrErr) {
187187 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
188 SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(),
188 SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
189189 SourceMgr::DK_Error, EIB.message());
190190 Err.print("ThinLTO", errs());
191191 });
193193 }
194194 if (!Lazy)
195195 verifyLoadedModule(*ModuleOrErr.get());
196 return std::move(ModuleOrErr.get());
196 return std::move(*ModuleOrErr);
197197 }
198198
199199 static void
200200 crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
201 StringMap<MemoryBufferRef> &ModuleMap,
201 StringMap<lto::InputFile*> &ModuleMap,
202202 const FunctionImporter::ImportMapTy &ImportList) {
203203 auto Loader = [&](StringRef Identifier) {
204 return loadModuleFromBuffer(ModuleMap[Identifier], TheModule.getContext(),
205 /*Lazy=*/true, /*IsImporting*/ true);
204 auto &Input = ModuleMap[Identifier];
205 return loadModuleFromInput(Input, TheModule.getContext(),
206 /*Lazy=*/true, /*IsImporting*/ true);
206207 };
207208
208209 FunctionImporter Importer(Index, Loader);
245246 PMB.populateThinLTOPassManager(PM);
246247
247248 PM.run(TheModule);
249 }
250
251 static void
252 addUsedSymbolToPreservedGUID(const lto::InputFile &File,
253 DenseSet &PreservedGUID) {
254 for (const auto &Sym : File.symbols()) {
255 if (Sym.isUsed())
256 PreservedGUID.insert(GlobalValue::getGUID(Sym.getIRName()));
257 }
248258 }
249259
250260 // Convert the PreservedSymbols map from "Name" based to "GUID" based.
380390
381391 static std::unique_ptr
382392 ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
383 StringMap<MemoryBufferRef> &ModuleMap, TargetMachine &TM,
393 StringMap<lto::InputFile *> &ModuleMap, TargetMachine &TM,
384394 const FunctionImporter::ImportMapTy &ImportList,
385395 const FunctionImporter::ExportSetTy &ExportList,
386396 const DenseSet &GUIDPreservedSymbols,
487497 } // end anonymous namespace
488498
489499 void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) {
490 ThinLTOBuffer Buffer(Data, Identifier);
491 LLVMContext Context;
492 StringRef TripleStr;
493 ErrorOr TripleOrErr = expectedToErrorOrAndEmitErrors(
494 Context, getBitcodeTargetTriple(Buffer.getMemBuffer()));
495
496 if (TripleOrErr)
497 TripleStr = *TripleOrErr;
498
500 MemoryBufferRef Buffer(Data, Identifier);
501
502 auto InputOrError = lto::InputFile::create(Buffer);
503 if (!InputOrError)
504 report_fatal_error("ThinLTO cannot create input file");
505
506 auto TripleStr = (*InputOrError)->getTargetTriple();
499507 Triple TheTriple(TripleStr);
500508
501509 if (Modules.empty())
507515 initTMBuilder(TMBuilder, Triple(TMBuilder.TheTriple.merge(TheTriple)));
508516 }
509517
510 Modules.push_back(Buffer);
518 Modules.emplace_back(std::move(*InputOrError));
511519 }
512520
513521 void ThinLTOCodeGenerator::preserveSymbol(StringRef Name) {
548556 std::unique_ptr CombinedIndex =
549557 llvm::make_unique(/*HaveGVs=*/false);
550558 uint64_t NextModuleId = 0;
551 for (auto &ModuleBuffer : Modules) {
552 if (Error Err = readModuleSummaryIndex(ModuleBuffer.getMemBuffer(),
553 *CombinedIndex, NextModuleId++)) {
559 for (auto &Mod : Modules) {
560 auto &M = Mod->getSingleBitcodeModule();
561 if (Error Err =
562 M.readSummary(*CombinedIndex, Mod->getName(), NextModuleId++)) {
554563 // FIXME diagnose
555564 logAllUnhandledErrors(
556565 std::move(Err), errs(),
592601 * Perform promotion and renaming of exported internal functions.
593602 * Index is updated to reflect linkage changes from weak resolution.
594603 */
595 void ThinLTOCodeGenerator::promote(Module &TheModule,
596 ModuleSummaryIndex &Index) {
604 void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index,
605 const lto::InputFile &File) {
597606 auto ModuleCount = Index.modulePaths().size();
598607 auto ModuleIdentifier = TheModule.getModuleIdentifier();
599608
604613 // Convert the preserved symbols set from string to GUID
605614 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
606615 PreservedSymbols, Triple(TheModule.getTargetTriple()));
616
617 // Add used symbol to the preserved symbols.
618 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
607619
608620 // Compute "dead" symbols, we don't want to import/export these!
609621 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
618630 StringMap> ResolvedODR;
619631 resolvePrevailingInIndex(Index, ResolvedODR);
620632
621 thinLTOResolvePrevailingInModule(
622 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
623
624633 // Promote the exported values in the index, so that they are promoted
625634 // in the module.
626635 internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, Index);
627636
628637 promoteModule(TheModule, Index);
638
639 thinLTOResolvePrevailingInModule(
640 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
629641 }
630642
631643 /**
632644 * Perform cross-module importing for the module identified by ModuleIdentifier.
633645 */
634646 void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
635 ModuleSummaryIndex &Index) {
647 ModuleSummaryIndex &Index,
648 const lto::InputFile &File) {
636649 auto ModuleMap = generateModuleMap(Modules);
637650 auto ModuleCount = Index.modulePaths().size();
638651
643656 // Convert the preserved symbols set from string to GUID
644657 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
645658 PreservedSymbols, Triple(TheModule.getTargetTriple()));
659
660 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
646661
647662 // Compute "dead" symbols, we don't want to import/export these!
648663 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
662677 */
663678 void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
664679 Module &TheModule, ModuleSummaryIndex &Index,
665 std::map &ModuleToSummariesForIndex) {
680 std::map &ModuleToSummariesForIndex,
681 const lto::InputFile &File) {
666682 auto ModuleCount = Index.modulePaths().size();
667683 auto ModuleIdentifier = TheModule.getModuleIdentifier();
668684
673689 // Convert the preserved symbols set from string to GUID
674690 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
675691 PreservedSymbols, Triple(TheModule.getTargetTriple()));
692
693 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
676694
677695 // Compute "dead" symbols, we don't want to import/export these!
678696 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
692710 * Emit the list of files needed for importing into module.
693711 */
694712 void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
695 ModuleSummaryIndex &Index) {
713 ModuleSummaryIndex &Index,
714 const lto::InputFile &File) {
696715 auto ModuleCount = Index.modulePaths().size();
697716 auto ModuleIdentifier = TheModule.getModuleIdentifier();
698717
703722 // Convert the preserved symbols set from string to GUID
704723 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
705724 PreservedSymbols, Triple(TheModule.getTargetTriple()));
725
726 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
706727
707728 // Compute "dead" symbols, we don't want to import/export these!
708729 computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
729750 * Perform internalization. Index is updated to reflect linkage changes.
730751 */
731752 void ThinLTOCodeGenerator::internalize(Module &TheModule,
732 ModuleSummaryIndex &Index) {
753 ModuleSummaryIndex &Index,
754 const lto::InputFile &File) {
733755 initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
734756 auto ModuleCount = Index.modulePaths().size();
735757 auto ModuleIdentifier = TheModule.getModuleIdentifier();
737759 // Convert the preserved symbols set from string to GUID
738760 auto GUIDPreservedSymbols =
739761 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
762
763 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
740764
741765 // Collect for each module the list of function it defines (GUID -> Summary).
742766 StringMap ModuleToDefinedGVSummaries(ModuleCount);
829853 // Perform only parallel codegen and return.
830854 ThreadPool Pool;
831855 int count = 0;
832 for (auto &ModuleBuffer : Modules) {
856 for (auto &Mod : Modules) {
833857 Pool.async([&](int count) {
834858 LLVMContext Context;
835859 Context.setDiscardValueNames(LTODiscardValueNames);
836860
837861 // Parse module now
838 auto TheModule =
839 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(), Context, false,
840 /*IsImporting*/ false);
862 auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
863 /*IsImporting*/ false);
841864
842865 // CodeGen
843866 auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.create());
880903 auto GUIDPreservedSymbols =
881904 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
882905
906 // Add used symbol from inputs to the preserved symbols.
907 for (const auto &M : Modules)
908 addUsedSymbolToPreservedGUID(*M, GUIDPreservedSymbols);
909
883910 // Compute "dead" symbols, we don't want to import/export these!
884911 computeDeadSymbolsInIndex(*Index, GUIDPreservedSymbols);
885912
912939 // GVSummary and ResolvedODR maps to enable threaded access to these maps
913940 // below.
914941 for (auto &Module : Modules) {
915 auto ModuleIdentifier = Module.getBufferIdentifier();
942 auto ModuleIdentifier = Module->getName();
916943 ExportLists[ModuleIdentifier];
917944 ImportLists[ModuleIdentifier];
918945 ResolvedODR[ModuleIdentifier];
926953 ModulesOrdering.resize(Modules.size());
927954 std::iota(ModulesOrdering.begin(), ModulesOrdering.end(), 0);
928955 llvm::sort(ModulesOrdering, [&](int LeftIndex, int RightIndex) {
929 auto LSize = Modules[LeftIndex].getBuffer().size();
930 auto RSize = Modules[RightIndex].getBuffer().size();
956 auto LSize =
957 Modules[LeftIndex]->getSingleBitcodeModule().getBuffer().size();
958 auto RSize =
959 Modules[RightIndex]->getSingleBitcodeModule().getBuffer().size();
931960 return LSize > RSize;
932961 });
933962
935964 {
936965 ThreadPool Pool(ThreadCount);
937966 for (auto IndexCount : ModulesOrdering) {
938 auto &ModuleBuffer = Modules[IndexCount];
967 auto &Mod = Modules[IndexCount];
939968 Pool.async([&](int count) {
940 auto ModuleIdentifier = ModuleBuffer.getBufferIdentifier();
969 auto ModuleIdentifier = Mod->getName();
941970 auto &ExportList = ExportLists[ModuleIdentifier];
942971
943972 auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
9811010 }
9821011
9831012 // Parse module now
984 auto TheModule =
985 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(), Context, false,
986 /*IsImporting*/ false);
1013 auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
1014 /*IsImporting*/ false);
9871015
9881016 // Save temps: original file.
9891017 saveTempBitcode(*TheModule, SaveTempsDir, count, ".0.original.bc");
0 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
1 target triple = "x86_64-apple-macosx10.15.0"
2
3 define i32 @main() {
4 entry:
5 %call = call i32 @bar()
6 ret i32 0
7 }
8
9 declare i32 @bar()
0 ; RUN: opt -module-summary -o %t.bc %s
1 ; RUN: opt -module-summary -o %t-main.bc %S/Inputs/thinlto-internalize-used2.ll
2 ; RUN: llvm-lto -thinlto-action=thinlink %t.bc %t-main.bc -o %t-index.bc
3 ; RUN: llvm-lto -thinlto-action=promote -thinlto-index %t-index.bc %t.bc -o %t.promote.bc
4 ; RUN: llvm-dis %t.promote.bc -o - | FileCheck %s
5
6 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-apple-macosx10.15.0"
8
9 @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @foo to i8*)], section "llvm.metadata"
10
11 ; Make sure foo is not internalized.
12 ; CHECK: define i32 @foo()
13 define i32 @foo() {
14 ret i32 0
15 }
16
17 define hidden i32 @bar() {
18 ret i32 0
19 }
20
448448 return ExitOnErr(getModuleSummaryIndexForFile(ThinLTOIndex));
449449 }
450450
451 static std::unique_ptr loadModule(StringRef Filename,
452 LLVMContext &Ctx) {
453 SMDiagnostic Err;
454 std::unique_ptr M(parseIRFile(Filename, Err, Ctx));
455 if (!M) {
456 Err.print("llvm-lto", errs());
457 report_fatal_error("Can't load module for file " + Filename);
458 }
459 maybeVerifyModule(*M);
460
451 static std::unique_ptr loadFile(StringRef Filename) {
452 ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename.str() +
453 "': ");
454 return ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(Filename)));
455 }
456
457 static std::unique_ptr loadInputFile(MemoryBufferRef Buffer) {
458 ExitOnError ExitOnErr("llvm-lto: error loading input '" +
459 Buffer.getBufferIdentifier().str() + "': ");
460 return ExitOnErr(lto::InputFile::create(Buffer));
461 }
462
463 static std::unique_ptr loadModuleFromInput(lto::InputFile &File,
464 LLVMContext &CTX) {
465 auto &Mod = File.getSingleBitcodeModule();
466 auto ModuleOrErr = Mod.parseModule(CTX);
467 if (!ModuleOrErr) {
468 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
469 SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
470 SourceMgr::DK_Error, EIB.message());
471 Err.print("llvm-lto", errs());
472 });
473 report_fatal_error("Can't load module, abort.");
474 }
475 maybeVerifyModule(**ModuleOrErr);
461476 if (ThinLTOModuleId.getNumOccurrences()) {
462477 if (InputFilenames.size() != 1)
463478 report_fatal_error("Can't override the module id for multiple files");
464 M->setModuleIdentifier(ThinLTOModuleId);
465 }
466 return M;
479 (*ModuleOrErr)->setModuleIdentifier(ThinLTOModuleId);
480 }
481 return std::move(*ModuleOrErr);
467482 }
468483
469484 static void writeModuleToFile(Module &TheModule, StringRef Filename) {
561576 auto Index = loadCombinedIndex();
562577 for (auto &Filename : InputFilenames) {
563578 LLVMContext Ctx;
564 auto TheModule = loadModule(Filename, Ctx);
579 auto Buffer = loadFile(Filename);
580 auto Input = loadInputFile(Buffer->getMemBufferRef());
581 auto TheModule = loadModuleFromInput(*Input, Ctx);
565582
566583 // Build a map of module to the GUIDs and summary objects that should
567584 // be written to its index.
568585 std::map ModuleToSummariesForIndex;
569 ThinGenerator.gatherImportedSummariesForModule(*TheModule, *Index,
570 ModuleToSummariesForIndex);
586 ThinGenerator.gatherImportedSummariesForModule(
587 *TheModule, *Index, ModuleToSummariesForIndex, *Input);
571588
572589 std::string OutputName = OutputFilename;
573590 if (OutputName.empty()) {
596613 auto Index = loadCombinedIndex();
597614 for (auto &Filename : InputFilenames) {
598615 LLVMContext Ctx;
599 auto TheModule = loadModule(Filename, Ctx);
616 auto Buffer = loadFile(Filename);
617 auto Input = loadInputFile(Buffer->getMemBufferRef());
618 auto TheModule = loadModuleFromInput(*Input, Ctx);
600619 std::string OutputName = OutputFilename;
601620 if (OutputName.empty()) {
602621 OutputName = Filename + ".imports";
603622 }
604 OutputName = getThinLTOOutputFile(OutputName, OldPrefix, NewPrefix);
605 ThinGenerator.emitImports(*TheModule, OutputName, *Index);
623 OutputName =
624 getThinLTOOutputFile(OutputName, OldPrefix, NewPrefix);
625 ThinGenerator.emitImports(*TheModule, OutputName, *Index, *Input);
606626 }
607627 }
608628
620640 auto Index = loadCombinedIndex();
621641 for (auto &Filename : InputFilenames) {
622642 LLVMContext Ctx;
623 auto TheModule = loadModule(Filename, Ctx);
624
625 ThinGenerator.promote(*TheModule, *Index);
643 auto Buffer = loadFile(Filename);
644 auto Input = loadInputFile(Buffer->getMemBufferRef());
645 auto TheModule = loadModuleFromInput(*Input, Ctx);
646
647 ThinGenerator.promote(*TheModule, *Index, *Input);
626648
627649 std::string OutputName = OutputFilename;
628650 if (OutputName.empty()) {
651673
652674 for (auto &Filename : InputFilenames) {
653675 LLVMContext Ctx;
654 auto TheModule = loadModule(Filename, Ctx);
655
656 ThinGenerator.crossModuleImport(*TheModule, *Index);
676 auto Buffer = loadFile(Filename);
677 auto Input = loadInputFile(Buffer->getMemBufferRef());
678 auto TheModule = loadModuleFromInput(*Input, Ctx);
679
680 ThinGenerator.crossModuleImport(*TheModule, *Index, *Input);
657681
658682 std::string OutputName = OutputFilename;
659683 if (OutputName.empty()) {
682706
683707 for (auto &Filename : InputFilenames) {
684708 LLVMContext Ctx;
685 auto TheModule = loadModule(Filename, Ctx);
686
687 ThinGenerator.internalize(*TheModule, *Index);
709 auto Buffer = loadFile(Filename);
710 auto Input = loadInputFile(Buffer->getMemBufferRef());
711 auto TheModule = loadModuleFromInput(*Input, Ctx);
712
713 ThinGenerator.internalize(*TheModule, *Index, *Input);
688714
689715 std::string OutputName = OutputFilename;
690716 if (OutputName.empty()) {
705731
706732 for (auto &Filename : InputFilenames) {
707733 LLVMContext Ctx;
708 auto TheModule = loadModule(Filename, Ctx);
734 auto Buffer = loadFile(Filename);
735 auto Input = loadInputFile(Buffer->getMemBufferRef());
736 auto TheModule = loadModuleFromInput(*Input, Ctx);
709737
710738 ThinGenerator.optimize(*TheModule);
711739