1212#include " InputFiles.h"
1313#include " Symbols.h"
1414#include " lld/Common/ErrorHandler.h"
15+ #include " lld/Common/Strings.h"
1516#include " lld/Common/TargetOptionsCommandFlags.h"
1617#include " llvm/ADT/STLExtras.h"
1718#include " llvm/ADT/SmallString.h"
@@ -40,53 +41,32 @@ using namespace llvm::object;
4041using namespace lld ;
4142using namespace lld ::coff;
4243
43- static void diagnosticHandler (const DiagnosticInfo &DI) {
44- SmallString<128 > ErrStorage;
45- raw_svector_ostream OS (ErrStorage);
46- DiagnosticPrinterRawOStream DP (OS);
47- DI.print (DP);
48- warn (ErrStorage);
49- }
50-
51- static void checkError (Error E) {
52- handleAllErrors (std::move (E),
53- [&](ErrorInfoBase &EIB) { error (EIB.message ()); });
54- }
55-
56- static void saveBuffer (StringRef Buffer, const Twine &Path) {
57- std::error_code EC;
58- raw_fd_ostream OS (Path.str (), EC, sys::fs::OpenFlags::F_None);
59- if (EC)
60- error (" cannot create " + Path + " : " + EC.message ());
61- OS << Buffer;
62- }
63-
6444static std::unique_ptr<lto::LTO> createLTO () {
65- lto::Config Conf ;
66- Conf .Options = InitTargetOptionsFromCodeGenFlags ();
45+ lto::Config C ;
46+ C .Options = InitTargetOptionsFromCodeGenFlags ();
6747
6848 // Always emit a section per function/datum with LTO. LLVM LTO should get most
6949 // of the benefit of linker GC, but there are still opportunities for ICF.
70- Conf .Options .FunctionSections = true ;
71- Conf .Options .DataSections = true ;
50+ C .Options .FunctionSections = true ;
51+ C .Options .DataSections = true ;
7252
7353 // Use static reloc model on 32-bit x86 because it usually results in more
7454 // compact code, and because there are also known code generation bugs when
7555 // using the PIC model (see PR34306).
7656 if (Config->Machine == COFF::IMAGE_FILE_MACHINE_I386)
77- Conf .RelocModel = Reloc::Static;
57+ C .RelocModel = Reloc::Static;
7858 else
79- Conf .RelocModel = Reloc::PIC_;
80- Conf .DisableVerify = true ;
81- Conf .DiagHandler = diagnosticHandler;
82- Conf .OptLevel = Config->LTOOptLevel ;
59+ C .RelocModel = Reloc::PIC_;
60+ C .DisableVerify = true ;
61+ C .DiagHandler = diagnosticHandler;
62+ C .OptLevel = Config->LTOO ;
8363 if (Config->SaveTemps )
84- checkError (Conf .addSaveTemps (std::string (Config->OutputFile ) + " ." ,
85- /* UseInputModulePath*/ true ));
64+ checkError (C .addSaveTemps (std::string (Config->OutputFile ) + " ." ,
65+ /* UseInputModulePath*/ true ));
8666 lto::ThinBackend Backend;
87- if (Config->LTOJobs != 0 )
88- Backend = lto::createInProcessThinBackend (Config->LTOJobs );
89- return llvm::make_unique<lto::LTO>(std::move (Conf ), Backend,
67+ if (Config->ThinLTOJobs != 0 )
68+ Backend = lto::createInProcessThinBackend (Config->ThinLTOJobs );
69+ return llvm::make_unique<lto::LTO>(std::move (C ), Backend,
9070 Config->LTOPartitions );
9171}
9272
@@ -125,7 +105,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
125105// and return the resulting objects.
126106std::vector<StringRef> BitcodeCompiler::compile () {
127107 unsigned MaxTasks = LTOObj->getMaxTasks ();
128- Buff .resize (MaxTasks);
108+ Buf .resize (MaxTasks);
129109 Files.resize (MaxTasks);
130110
131111 // The /lldltocache option specifies the path to a directory in which to cache
@@ -141,7 +121,7 @@ std::vector<StringRef> BitcodeCompiler::compile() {
141121 checkError (LTOObj->run (
142122 [&](size_t Task) {
143123 return llvm::make_unique<lto::NativeObjectStream>(
144- llvm::make_unique<raw_svector_ostream>(Buff [Task]));
124+ llvm::make_unique<raw_svector_ostream>(Buf [Task]));
145125 },
146126 Cache));
147127
@@ -150,15 +130,15 @@ std::vector<StringRef> BitcodeCompiler::compile() {
150130
151131 std::vector<StringRef> Ret;
152132 for (unsigned I = 0 ; I != MaxTasks; ++I) {
153- if (Buff [I].empty ())
133+ if (Buf [I].empty ())
154134 continue ;
155135 if (Config->SaveTemps ) {
156136 if (I == 0 )
157- saveBuffer (Buff [I], Config->OutputFile + " .lto.obj" );
137+ saveBuffer (Buf [I], Config->OutputFile + " .lto.obj" );
158138 else
159- saveBuffer (Buff [I], Config->OutputFile + Twine (I) + " .lto.obj" );
139+ saveBuffer (Buf [I], Config->OutputFile + Twine (I) + " .lto.obj" );
160140 }
161- Ret.emplace_back (Buff [I].data (), Buff [I].size ());
141+ Ret.emplace_back (Buf [I].data (), Buf [I].size ());
162142 }
163143
164144 for (std::unique_ptr<MemoryBuffer> &File : Files)
0 commit comments