@@ -44,8 +44,8 @@ using namespace lld::wasm;
44
44
using namespace lld ;
45
45
46
46
static std::string getThinLTOOutputFile (StringRef modulePath) {
47
- return lto::getThinLTOOutputFile (modulePath, config-> thinLTOPrefixReplaceOld ,
48
- config-> thinLTOPrefixReplaceNew );
47
+ return lto::getThinLTOOutputFile (modulePath, ctx. arg . thinLTOPrefixReplaceOld ,
48
+ ctx. arg . thinLTOPrefixReplaceNew );
49
49
}
50
50
51
51
static lto::Config createConfig () {
@@ -56,23 +56,23 @@ static lto::Config createConfig() {
56
56
c.Options .FunctionSections = true ;
57
57
c.Options .DataSections = true ;
58
58
59
- c.DisableVerify = config-> disableVerify ;
59
+ c.DisableVerify = ctx. arg . disableVerify ;
60
60
c.DiagHandler = diagnosticHandler;
61
- c.OptLevel = config-> ltoo ;
61
+ c.OptLevel = ctx. arg . ltoo ;
62
62
c.MAttrs = getMAttrs ();
63
- c.CGOptLevel = config-> ltoCgo ;
64
- c.DebugPassManager = config-> ltoDebugPassManager ;
65
- c.AlwaysEmitRegularLTOObj = !config-> ltoObjPath .empty ();
63
+ c.CGOptLevel = ctx. arg . ltoCgo ;
64
+ c.DebugPassManager = ctx. arg . ltoDebugPassManager ;
65
+ c.AlwaysEmitRegularLTOObj = !ctx. arg . ltoObjPath .empty ();
66
66
67
- if (config-> relocatable )
67
+ if (ctx. arg . relocatable )
68
68
c.RelocModel = std::nullopt;
69
69
else if (ctx.isPic )
70
70
c.RelocModel = Reloc::PIC_;
71
71
else
72
72
c.RelocModel = Reloc::Static;
73
73
74
- if (config-> saveTemps )
75
- checkError (c.addSaveTemps (config-> outputFile .str () + " ." ,
74
+ if (ctx. arg . saveTemps )
75
+ checkError (c.addSaveTemps (ctx. arg . outputFile .str () + " ." ,
76
76
/* UseInputModulePath*/ true ));
77
77
return c;
78
78
}
@@ -81,27 +81,27 @@ namespace lld::wasm {
81
81
82
82
BitcodeCompiler::BitcodeCompiler () {
83
83
// Initialize indexFile.
84
- if (!config-> thinLTOIndexOnlyArg .empty ())
85
- indexFile = openFile (config-> thinLTOIndexOnlyArg );
84
+ if (!ctx. arg . thinLTOIndexOnlyArg .empty ())
85
+ indexFile = openFile (ctx. arg . thinLTOIndexOnlyArg );
86
86
87
87
// Initialize ltoObj.
88
88
lto::ThinBackend backend;
89
89
auto onIndexWrite = [&](StringRef s) { thinIndices.erase (s); };
90
- if (config-> thinLTOIndexOnly ) {
90
+ if (ctx. arg . thinLTOIndexOnly ) {
91
91
backend = lto::createWriteIndexesThinBackend (
92
- llvm::hardware_concurrency (config-> thinLTOJobs ),
93
- std::string (config-> thinLTOPrefixReplaceOld ),
94
- std::string (config-> thinLTOPrefixReplaceNew ),
95
- std::string (config-> thinLTOPrefixReplaceNativeObject ),
96
- config-> thinLTOEmitImportsFiles , indexFile.get (), onIndexWrite);
92
+ llvm::hardware_concurrency (ctx. arg . thinLTOJobs ),
93
+ std::string (ctx. arg . thinLTOPrefixReplaceOld ),
94
+ std::string (ctx. arg . thinLTOPrefixReplaceNew ),
95
+ std::string (ctx. arg . thinLTOPrefixReplaceNativeObject ),
96
+ ctx. arg . thinLTOEmitImportsFiles , indexFile.get (), onIndexWrite);
97
97
} else {
98
98
backend = lto::createInProcessThinBackend (
99
- llvm::heavyweight_hardware_concurrency (config-> thinLTOJobs ),
100
- onIndexWrite, config-> thinLTOEmitIndexFiles ,
101
- config-> thinLTOEmitImportsFiles );
99
+ llvm::heavyweight_hardware_concurrency (ctx. arg . thinLTOJobs ),
100
+ onIndexWrite, ctx. arg . thinLTOEmitIndexFiles ,
101
+ ctx. arg . thinLTOEmitImportsFiles );
102
102
}
103
103
ltoObj = std::make_unique<lto::LTO>(createConfig (), backend,
104
- config-> ltoPartitions );
104
+ ctx. arg . ltoPartitions );
105
105
}
106
106
107
107
BitcodeCompiler::~BitcodeCompiler () = default ;
@@ -123,7 +123,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
123
123
ArrayRef<Symbol *> syms = f.getSymbols ();
124
124
std::vector<lto::SymbolResolution> resols (syms.size ());
125
125
126
- if (config-> thinLTOEmitIndexFiles ) {
126
+ if (ctx. arg . thinLTOEmitIndexFiles ) {
127
127
thinIndices.insert (obj.getName ());
128
128
}
129
129
@@ -139,7 +139,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
139
139
// Once IRObjectFile is fixed to report only one symbol this hack can
140
140
// be removed.
141
141
r.Prevailing = !objSym.isUndefined () && sym->getFile () == &f;
142
- r.VisibleToRegularObj = config-> relocatable || sym->isUsedInRegularObj ||
142
+ r.VisibleToRegularObj = ctx. arg . relocatable || sym->isUsedInRegularObj ||
143
143
sym->isNoStrip () ||
144
144
(r.Prevailing && sym->isExported ());
145
145
if (r.Prevailing )
@@ -175,7 +175,7 @@ static void thinLTOCreateEmptyIndexFiles() {
175
175
ModuleSummaryIndex m (/* HaveGVs*/ false );
176
176
m.setSkipModuleByDistributedBackend ();
177
177
writeIndexToFile (m, *os);
178
- if (config-> thinLTOEmitImportsFiles )
178
+ if (ctx. arg . thinLTOEmitImportsFiles )
179
179
openFile (path + " .imports" );
180
180
}
181
181
}
@@ -191,8 +191,8 @@ std::vector<StringRef> BitcodeCompiler::compile() {
191
191
// to cache native object files for ThinLTO incremental builds. If a path was
192
192
// specified, configure LTO to use it as the cache directory.
193
193
FileCache cache;
194
- if (!config-> thinLTOCacheDir .empty ())
195
- cache = check (localCache (" ThinLTO" , " Thin" , config-> thinLTOCacheDir ,
194
+ if (!ctx. arg . thinLTOCacheDir .empty ())
195
+ cache = check (localCache (" ThinLTO" , " Thin" , ctx. arg . thinLTOCacheDir ,
196
196
[&](size_t task, const Twine &moduleName,
197
197
std::unique_ptr<MemoryBuffer> mb) {
198
198
files[task] = std::move (mb);
@@ -210,16 +210,16 @@ std::vector<StringRef> BitcodeCompiler::compile() {
210
210
for (StringRef s : thinIndices) {
211
211
std::string path (s);
212
212
openFile (path + " .thinlto.bc" );
213
- if (config-> thinLTOEmitImportsFiles )
213
+ if (ctx. arg . thinLTOEmitImportsFiles )
214
214
openFile (path + " .imports" );
215
215
}
216
216
217
- if (config-> thinLTOEmitIndexFiles )
217
+ if (ctx. arg . thinLTOEmitIndexFiles )
218
218
thinLTOCreateEmptyIndexFiles ();
219
219
220
- if (config-> thinLTOIndexOnly ) {
221
- if (!config-> ltoObjPath .empty ())
222
- saveBuffer (buf[0 ].second , config-> ltoObjPath );
220
+ if (ctx. arg . thinLTOIndexOnly ) {
221
+ if (!ctx. arg . ltoObjPath .empty ())
222
+ saveBuffer (buf[0 ].second , ctx. arg . ltoObjPath );
223
223
224
224
// ThinLTO with index only option is required to generate only the index
225
225
// files. After that, we exit from linker and ThinLTO backend runs in a
@@ -229,8 +229,8 @@ std::vector<StringRef> BitcodeCompiler::compile() {
229
229
return {};
230
230
}
231
231
232
- if (!config-> thinLTOCacheDir .empty ())
233
- pruneCache (config-> thinLTOCacheDir , config-> thinLTOCachePolicy , files);
232
+ if (!ctx. arg . thinLTOCacheDir .empty ())
233
+ pruneCache (ctx. arg . thinLTOCacheDir , ctx. arg . thinLTOCachePolicy , files);
234
234
235
235
std::vector<StringRef> ret;
236
236
for (unsigned i = 0 ; i != maxTasks; ++i) {
@@ -239,7 +239,7 @@ std::vector<StringRef> BitcodeCompiler::compile() {
239
239
if (objBuf.empty ())
240
240
continue ;
241
241
ret.emplace_back (objBuf.data (), objBuf.size ());
242
- if (!config-> saveTemps )
242
+ if (!ctx. arg . saveTemps )
243
243
continue ;
244
244
245
245
// If the input bitcode file is path/to/x.o and -o specifies a.out, the
@@ -248,7 +248,7 @@ std::vector<StringRef> BitcodeCompiler::compile() {
248
248
StringRef ltoObjName;
249
249
if (bitcodeFilePath == " ld-temp.o" ) {
250
250
ltoObjName =
251
- saver ().save (Twine (config-> outputFile ) + " .lto" +
251
+ saver ().save (Twine (ctx. arg . outputFile ) + " .lto" +
252
252
(i == 0 ? Twine (" " ) : Twine (' .' ) + Twine (i)) + " .o" );
253
253
} else {
254
254
StringRef directory = sys::path::parent_path (bitcodeFilePath);
@@ -258,7 +258,7 @@ std::vector<StringRef> BitcodeCompiler::compile() {
258
258
StringRef baseName = bitcodeFilePath.ends_with (" )" )
259
259
? sys::path::filename (bitcodeFilePath)
260
260
: sys::path::stem (bitcodeFilePath);
261
- StringRef outputFileBaseName = sys::path::filename (config-> outputFile );
261
+ StringRef outputFileBaseName = sys::path::filename (ctx. arg . outputFile );
262
262
SmallString<256 > path;
263
263
sys::path::append (path, directory,
264
264
outputFileBaseName + " .lto." + baseName + " .o" );
@@ -268,10 +268,10 @@ std::vector<StringRef> BitcodeCompiler::compile() {
268
268
saveBuffer (objBuf, ltoObjName);
269
269
}
270
270
271
- if (!config-> ltoObjPath .empty ()) {
272
- saveBuffer (buf[0 ].second , config-> ltoObjPath );
271
+ if (!ctx. arg . ltoObjPath .empty ()) {
272
+ saveBuffer (buf[0 ].second , ctx. arg . ltoObjPath );
273
273
for (unsigned i = 1 ; i != maxTasks; ++i)
274
- saveBuffer (buf[i].second , config-> ltoObjPath + Twine (i));
274
+ saveBuffer (buf[i].second , ctx. arg . ltoObjPath + Twine (i));
275
275
}
276
276
277
277
for (std::unique_ptr<MemoryBuffer> &file : files)
0 commit comments