]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/llvm_util.rs
Rollup merge of #68767 - kubo39:patch-macos, r=shepmaster
[rust.git] / src / librustc_codegen_llvm / llvm_util.rs
index 52613fef7e612b0def79aa7d451130e96adbc9c1..6d3498f8b800b90680f8a0ee852e3c9f50d2c596 100644 (file)
@@ -58,9 +58,10 @@ fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
 
     let cg_opts = sess.opts.cg.llvm_args.iter();
     let tg_opts = sess.target.target.options.llvm_args.iter();
+    let sess_args = cg_opts.chain(tg_opts);
 
     let user_specified_args: FxHashSet<_> =
-        cg_opts.chain(tg_opts).map(|s| llvm_arg_to_arg_name(s)).filter(|s| s.len() > 0).collect();
+        sess_args.clone().map(|s| llvm_arg_to_arg_name(s)).filter(|s| s.len() > 0).collect();
 
     {
         // This adds the given argument to LLVM. Unless `force` is true
@@ -107,11 +108,20 @@ fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
         // during inlining. Unfortunately these may block other optimizations.
         add("-preserve-alignment-assumptions-during-inlining=false", false);
 
-        for arg in &sess.opts.cg.llvm_args {
+        for arg in sess_args {
             add(&(*arg), true);
         }
     }
 
+    if sess.opts.debugging_opts.llvm_time_trace && get_major_version() >= 9 {
+        // time-trace is not thread safe and running it in parallel will cause seg faults.
+        if !sess.opts.debugging_opts.no_parallel_llvm {
+            bug!("`-Z llvm-time-trace` requires `-Z no-parallel-llvm")
+        }
+
+        llvm::LLVMTimeTraceProfilerInitialize();
+    }
+
     llvm::LLVMInitializePasses();
 
     ::rustc_llvm::initialize_available_targets();
@@ -119,6 +129,15 @@ fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
     llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr());
 }
 
+pub fn time_trace_profiler_finish(file_name: &str) {
+    unsafe {
+        if get_major_version() >= 9 {
+            let file_name = CString::new(file_name).unwrap();
+            llvm::LLVMTimeTraceProfilerFinish(file_name.as_ptr());
+        }
+    }
+}
+
 // WARNING: the features after applying `to_llvm_feature` must be known
 // to LLVM or the feature detection code will walk past the end of the feature
 // array, leading to crashes.