File tree Expand file tree Collapse file tree 3 files changed +18
-47
lines changed Expand file tree Collapse file tree 3 files changed +18
-47
lines changed Original file line number Diff line number Diff line change 2222
2323use std:: any:: Any ;
2424use std:: ffi:: CStr ;
25- use std:: io:: Write ;
2625use std:: mem:: ManuallyDrop ;
2726
2827use back:: owned_target_machine:: OwnedTargetMachine ;
@@ -165,30 +164,12 @@ impl WriteBackendMethods for LlvmCodegenBackend {
165164 type ThinData = back:: lto:: ThinData ;
166165 type ThinBuffer = back:: lto:: ThinBuffer ;
167166 fn print_pass_timings ( & self ) {
168- unsafe {
169- let mut size = 0 ;
170- let cstr = llvm:: LLVMRustPrintPassTimings ( & raw mut size) ;
171- if cstr. is_null ( ) {
172- println ! ( "failed to get pass timings" ) ;
173- } else {
174- let timings = std:: slice:: from_raw_parts ( cstr as * const u8 , size) ;
175- std:: io:: stdout ( ) . write_all ( timings) . unwrap ( ) ;
176- libc:: free ( cstr as * mut _ ) ;
177- }
178- }
167+ let timings = llvm:: build_string ( |s| unsafe { llvm:: LLVMRustPrintPassTimings ( s) } ) . unwrap ( ) ;
168+ print ! ( "{timings}" ) ;
179169 }
180170 fn print_statistics ( & self ) {
181- unsafe {
182- let mut size = 0 ;
183- let cstr = llvm:: LLVMRustPrintStatistics ( & raw mut size) ;
184- if cstr. is_null ( ) {
185- println ! ( "failed to get pass stats" ) ;
186- } else {
187- let stats = std:: slice:: from_raw_parts ( cstr as * const u8 , size) ;
188- std:: io:: stdout ( ) . write_all ( stats) . unwrap ( ) ;
189- libc:: free ( cstr as * mut _ ) ;
190- }
191- }
171+ let stats = llvm:: build_string ( |s| unsafe { llvm:: LLVMRustPrintStatistics ( s) } ) . unwrap ( ) ;
172+ print ! ( "{stats}" ) ;
192173 }
193174 fn run_link (
194175 cgcx : & CodegenContext < Self > ,
Original file line number Diff line number Diff line change @@ -1765,11 +1765,13 @@ unsafe extern "C" {
17651765 /// Returns a string describing the last error caused by an LLVMRust* call.
17661766 pub fn LLVMRustGetLastError ( ) -> * const c_char ;
17671767
1768- /// Print the pass timings since static dtors aren't picking them up.
1769- pub fn LLVMRustPrintPassTimings ( size : * const size_t ) -> * const c_char ;
1768+ /// Prints the timing information collected by `-Ztime-llvm-passes`.
1769+ #[ expect( improper_ctypes) ]
1770+ pub ( crate ) fn LLVMRustPrintPassTimings ( OutStr : & RustString ) ;
17701771
1771- /// Print the statistics since static dtors aren't picking them up.
1772- pub fn LLVMRustPrintStatistics ( size : * const size_t ) -> * const c_char ;
1772+ /// Prints the statistics collected by `-Zprint-codegen-stats`.
1773+ #[ expect( improper_ctypes) ]
1774+ pub ( crate ) fn LLVMRustPrintStatistics ( OutStr : & RustString ) ;
17731775
17741776 /// Prepares inline assembly.
17751777 pub fn LLVMRustInlineAsm (
Original file line number Diff line number Diff line change @@ -140,26 +140,14 @@ extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
140140 unwrap (M)->setTargetTriple (Triple::normalize (Triple));
141141}
142142
143- extern " C" const char *LLVMRustPrintPassTimings (size_t *Len) {
144- std::string buf;
145- auto SS = raw_string_ostream (buf);
146- TimerGroup::printAll (SS);
147- SS.flush ();
148- *Len = buf.length ();
149- char *CStr = (char *)malloc (*Len);
150- memcpy (CStr, buf.c_str (), *Len);
151- return CStr;
152- }
153-
154- extern " C" const char *LLVMRustPrintStatistics (size_t *Len) {
155- std::string buf;
156- auto SS = raw_string_ostream (buf);
157- llvm::PrintStatistics (SS);
158- SS.flush ();
159- *Len = buf.length ();
160- char *CStr = (char *)malloc (*Len);
161- memcpy (CStr, buf.c_str (), *Len);
162- return CStr;
143+ extern " C" void LLVMRustPrintPassTimings (RustStringRef OutBuf) {
144+ auto OS = RawRustStringOstream (OutBuf);
145+ TimerGroup::printAll (OS);
146+ }
147+
148+ extern " C" void LLVMRustPrintStatistics (RustStringRef OutBuf) {
149+ auto OS = RawRustStringOstream (OutBuf);
150+ llvm::PrintStatistics (OS);
163151}
164152
165153extern " C" LLVMValueRef LLVMRustGetNamedValue (LLVMModuleRef M, const char *Name,
You can’t perform that action at this time.
0 commit comments