@@ -310,6 +310,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
310
310
pub no_landing_pads : bool ,
311
311
pub save_temps : bool ,
312
312
pub fewer_names : bool ,
313
+ pub time_trace : bool ,
313
314
pub exported_symbols : Option < Arc < ExportedSymbols > > ,
314
315
pub opts : Arc < config:: Options > ,
315
316
pub crate_types : Vec < CrateType > ,
@@ -1039,6 +1040,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1039
1040
no_landing_pads : sess. panic_strategy ( ) == PanicStrategy :: Abort ,
1040
1041
fewer_names : sess. fewer_names ( ) ,
1041
1042
save_temps : sess. opts . cg . save_temps ,
1043
+ time_trace : sess. opts . debugging_opts . llvm_time_trace ,
1042
1044
opts : Arc :: new ( sess. opts . clone ( ) ) ,
1043
1045
prof : sess. prof . clone ( ) ,
1044
1046
exported_symbols,
@@ -1198,7 +1200,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1198
1200
// Each LLVM module is automatically sent back to the coordinator for LTO if
1199
1201
// necessary. There's already optimizations in place to avoid sending work
1200
1202
// back to the coordinator if LTO isn't requested.
1201
- return thread :: spawn ( move || {
1203
+ return B :: spawn_thread ( cgcx . time_trace , move || {
1202
1204
let mut worker_id_counter = 0 ;
1203
1205
let mut free_worker_ids = Vec :: new ( ) ;
1204
1206
let mut get_worker_id = |free_worker_ids : & mut Vec < usize > | {
@@ -1615,59 +1617,57 @@ fn start_executing_work<B: ExtraBackendMethods>(
1615
1617
pub struct WorkerFatalError ;
1616
1618
1617
1619
fn 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) ) ) ;
1651
1650
}
1651
+ }
1652
1652
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
+ } ;
1658
1658
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" ) ;
1671
1671
}
1672
1672
1673
1673
enum SharedEmitterMessage {
0 commit comments