@@ -945,7 +945,7 @@ struct ShardTimers {
945945};
946946
947947// Perform the actual optimization and emission of the output files
948- static void add_output_impl (Module &M, TargetMachine &SourceTM, std::string *outputs, StringRef *names,
948+ static void add_output_impl (Module &M, TargetMachine &SourceTM, std::string *outputs, const std::string *names,
949949 NewArchiveMember *unopt, NewArchiveMember *opt, NewArchiveMember *obj, NewArchiveMember *asm_,
950950 ShardTimers &timers, unsigned shardidx) {
951951 auto TM = std::unique_ptr<TargetMachine>(
@@ -965,6 +965,7 @@ static void add_output_impl(Module &M, TargetMachine &SourceTM, std::string *out
965965 AnalysisManagers AM{*TM, PB, OptimizationLevel::O0};
966966 ModulePassManager MPM;
967967 MPM.addPass (BitcodeWriterPass (OS));
968+ MPM.run (M, AM.MAM );
968969 *unopt = NewArchiveMember (MemoryBufferRef (*outputs++, *names++));
969970 timers.unopt .stopTimer ();
970971 }
@@ -1029,6 +1030,7 @@ static void add_output_impl(Module &M, TargetMachine &SourceTM, std::string *out
10291030 AnalysisManagers AM{*TM, PB, OptimizationLevel::O0};
10301031 ModulePassManager MPM;
10311032 MPM.addPass (BitcodeWriterPass (OS));
1033+ MPM.run (M, AM.MAM );
10321034 *opt = NewArchiveMember (MemoryBufferRef (*outputs++, *names++));
10331035 timers.opt .stopTimer ();
10341036 }
@@ -1224,6 +1226,8 @@ static void add_output(Module &M, TargetMachine &TM, std::vector<std::string> &o
12241226 unsigned outcount = unopt_out + opt_out + obj_out + asm_out;
12251227 assert (outcount);
12261228 outputs.resize (outputs.size () + outcount * threads * 2 );
1229+ auto names_start = outputs.data () + outputs.size () - outcount * threads * 2 ;
1230+ auto outputs_start = names_start + outcount * threads;
12271231 unopt.resize (unopt.size () + unopt_out * threads);
12281232 opt.resize (opt.size () + opt_out * threads);
12291233 obj.resize (obj.size () + obj_out * threads);
@@ -1264,7 +1268,7 @@ static void add_output(Module &M, TargetMachine &TM, std::vector<std::string> &o
12641268 }
12651269 }
12661270 for (unsigned i = 0 ; i < threads; ++i) {
1267- auto start = &outputs[outputs. size () - outcount * threads * 2 + i * outcount] ;
1271+ auto start = names_start + i * outcount;
12681272 auto istr = std::to_string (i);
12691273 if (unopt_out)
12701274 *start++ = (name + " _unopt#" + istr + " .bc" ).str ();
@@ -1278,10 +1282,7 @@ static void add_output(Module &M, TargetMachine &TM, std::vector<std::string> &o
12781282 // Single-threaded case
12791283 if (threads == 1 ) {
12801284 output_timer.startTimer ();
1281- SmallVector<StringRef, 4 > names;
1282- for (unsigned i = outputs.size () - outcount * 2 ; i < outputs.size () - outcount; ++i)
1283- names.push_back (outputs[i]);
1284- add_output_impl (M, TM, outputs.data () + outputs.size () - outcount, names.data (),
1285+ add_output_impl (M, TM, outputs_start, names_start,
12851286 unopt_out ? unopt.data () + unopt.size () - 1 : nullptr ,
12861287 opt_out ? opt.data () + opt.size () - 1 : nullptr ,
12871288 obj_out ? obj.data () + obj.size () - 1 : nullptr ,
@@ -1318,7 +1319,6 @@ static void add_output(Module &M, TargetMachine &TM, std::vector<std::string> &o
13181319
13191320 output_timer.startTimer ();
13201321
1321- auto outstart = outputs.data () + outputs.size () - outcount * threads;
13221322 auto unoptstart = unopt_out ? unopt.data () + unopt.size () - threads : nullptr ;
13231323 auto optstart = opt_out ? opt.data () + opt.size () - threads : nullptr ;
13241324 auto objstart = obj_out ? obj.data () + obj.size () - threads : nullptr ;
@@ -1347,11 +1347,7 @@ static void add_output(Module &M, TargetMachine &TM, std::vector<std::string> &o
13471347 dropUnusedDeclarations (*M);
13481348 timers[i].deletion .stopTimer ();
13491349
1350- SmallVector<StringRef, 4 > names (outcount);
1351- for (unsigned j = 0 ; j < outcount; ++j)
1352- names[j] = outputs[i * outcount + j];
1353-
1354- add_output_impl (*M, TM, outstart + i * outcount, names.data (),
1350+ add_output_impl (*M, TM, outputs_start + i * outcount, names_start + i * outcount,
13551351 unoptstart ? unoptstart + i : nullptr ,
13561352 optstart ? optstart + i : nullptr ,
13571353 objstart ? objstart + i : nullptr ,
@@ -1578,7 +1574,7 @@ void jl_dump_native_impl(void *native_code,
15781574 // DO NOT DELETE, this is necessary to ensure memorybuffers
15791575 // have a stable backing store for both their object files and
15801576 // their names
1581- outputs.reserve (threads * (!!unopt_bc_fname + !!bc_fname + !!obj_fname + !!asm_fname) * 2 + 2 );
1577+ outputs.reserve (( threads + 1 ) * (!!unopt_bc_fname + !!bc_fname + !!obj_fname + !!asm_fname) * 2 );
15821578
15831579 auto compile = [&](Module &M, StringRef name, unsigned threads) { add_output (
15841580 M, *SourceTM, outputs, name,
0 commit comments