@@ -310,6 +310,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
310310 pub no_landing_pads : bool ,
311311 pub save_temps : bool ,
312312 pub fewer_names : bool ,
313+ pub time_trace : bool ,
313314 pub exported_symbols : Option < Arc < ExportedSymbols > > ,
314315 pub opts : Arc < config:: Options > ,
315316 pub crate_types : Vec < CrateType > ,
@@ -1039,6 +1040,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
10391040 no_landing_pads : sess. panic_strategy ( ) == PanicStrategy :: Abort ,
10401041 fewer_names : sess. fewer_names ( ) ,
10411042 save_temps : sess. opts . cg . save_temps ,
1043+ time_trace : sess. opts . debugging_opts . llvm_time_trace ,
10421044 opts : Arc :: new ( sess. opts . clone ( ) ) ,
10431045 prof : sess. prof . clone ( ) ,
10441046 exported_symbols,
@@ -1198,7 +1200,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
11981200 // Each LLVM module is automatically sent back to the coordinator for LTO if
11991201 // necessary. There's already optimizations in place to avoid sending work
12001202 // back to the coordinator if LTO isn't requested.
1201- return thread :: spawn ( move || {
1203+ return B :: spawn_thread ( cgcx . time_trace , move || {
12021204 let mut worker_id_counter = 0 ;
12031205 let mut free_worker_ids = Vec :: new ( ) ;
12041206 let mut get_worker_id = |free_worker_ids : & mut Vec < usize > | {
@@ -1615,59 +1617,57 @@ fn start_executing_work<B: ExtraBackendMethods>(
16151617pub struct WorkerFatalError ;
16161618
16171619fn spawn_work < B : ExtraBackendMethods > ( cgcx : CodegenContext < B > , work : WorkItem < B > ) {
1618- let builder = thread:: Builder :: new ( ) . name ( work. short_description ( ) ) ;
1619- builder
1620- . spawn ( move || {
1621- // Set up a destructor which will fire off a message that we're done as
1622- // we exit.
1623- struct Bomb < B : ExtraBackendMethods > {
1624- coordinator_send : Sender < Box < dyn Any + Send > > ,
1625- result : Option < Result < WorkItemResult < B > , FatalError > > ,
1626- worker_id : usize ,
1627- }
1628- impl < B : ExtraBackendMethods > Drop for Bomb < B > {
1629- fn drop ( & mut self ) {
1630- let worker_id = self . worker_id ;
1631- let msg = match self . result . take ( ) {
1632- Some ( Ok ( WorkItemResult :: Compiled ( m) ) ) => {
1633- Message :: Done :: < B > { result : Ok ( m) , worker_id }
1634- }
1635- Some ( Ok ( WorkItemResult :: NeedsLink ( m) ) ) => {
1636- Message :: NeedsLink :: < B > { module : m, worker_id }
1637- }
1638- Some ( Ok ( WorkItemResult :: NeedsFatLTO ( m) ) ) => {
1639- Message :: NeedsFatLTO :: < B > { result : m, worker_id }
1640- }
1641- Some ( Ok ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) ) => {
1642- Message :: NeedsThinLTO :: < B > { name, thin_buffer, worker_id }
1643- }
1644- Some ( Err ( FatalError ) ) => {
1645- Message :: Done :: < B > { result : Err ( Some ( WorkerFatalError ) ) , worker_id }
1646- }
1647- None => Message :: Done :: < B > { result : Err ( None ) , worker_id } ,
1648- } ;
1649- drop ( self . coordinator_send . send ( Box :: new ( msg) ) ) ;
1650- }
1620+ B :: spawn_named_thread ( cgcx. time_trace , work. short_description ( ) , move || {
1621+ // Set up a destructor which will fire off a message that we're done as
1622+ // we exit.
1623+ struct Bomb < B : ExtraBackendMethods > {
1624+ coordinator_send : Sender < Box < dyn Any + Send > > ,
1625+ result : Option < Result < WorkItemResult < B > , FatalError > > ,
1626+ worker_id : usize ,
1627+ }
1628+ impl < B : ExtraBackendMethods > Drop for Bomb < B > {
1629+ fn drop ( & mut self ) {
1630+ let worker_id = self . worker_id ;
1631+ let msg = match self . result . take ( ) {
1632+ Some ( Ok ( WorkItemResult :: Compiled ( m) ) ) => {
1633+ Message :: Done :: < B > { result : Ok ( m) , worker_id }
1634+ }
1635+ Some ( Ok ( WorkItemResult :: NeedsLink ( m) ) ) => {
1636+ Message :: NeedsLink :: < B > { module : m, worker_id }
1637+ }
1638+ Some ( Ok ( WorkItemResult :: NeedsFatLTO ( m) ) ) => {
1639+ Message :: NeedsFatLTO :: < B > { result : m, worker_id }
1640+ }
1641+ Some ( Ok ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) ) => {
1642+ Message :: NeedsThinLTO :: < B > { name, thin_buffer, worker_id }
1643+ }
1644+ Some ( Err ( FatalError ) ) => {
1645+ Message :: Done :: < B > { result : Err ( Some ( WorkerFatalError ) ) , worker_id }
1646+ }
1647+ None => Message :: Done :: < B > { result : Err ( None ) , worker_id } ,
1648+ } ;
1649+ drop ( self . coordinator_send . send ( Box :: new ( msg) ) ) ;
16511650 }
1651+ }
16521652
1653- let mut bomb = Bomb :: < B > {
1654- coordinator_send : cgcx. coordinator_send . clone ( ) ,
1655- result : None ,
1656- worker_id : cgcx. worker ,
1657- } ;
1653+ let mut bomb = Bomb :: < B > {
1654+ coordinator_send : cgcx. coordinator_send . clone ( ) ,
1655+ result : None ,
1656+ worker_id : cgcx. worker ,
1657+ } ;
16581658
1659- // Execute the work itself, and if it finishes successfully then flag
1660- // ourselves as a success as well.
1661- //
1662- // Note that we ignore any `FatalError` coming out of `execute_work_item`,
1663- // as a diagnostic was already sent off to the main thread - just
1664- // surface that there was an error in this worker.
1665- bomb. result = {
1666- let _prof_timer = work. start_profiling ( & cgcx) ;
1667- Some ( execute_work_item ( & cgcx, work) )
1668- } ;
1669- } )
1670- . expect ( "failed to spawn thread" ) ;
1659+ // Execute the work itself, and if it finishes successfully then flag
1660+ // ourselves as a success as well.
1661+ //
1662+ // Note that we ignore any `FatalError` coming out of `execute_work_item`,
1663+ // as a diagnostic was already sent off to the main thread - just
1664+ // surface that there was an error in this worker.
1665+ bomb. result = {
1666+ let _prof_timer = work. start_profiling ( & cgcx) ;
1667+ Some ( execute_work_item ( & cgcx, work) )
1668+ } ;
1669+ } )
1670+ . expect ( "failed to spawn thread" ) ;
16711671}
16721672
16731673enum SharedEmitterMessage {
0 commit comments