1
Fork 0

Rollup merge of #132590 - Zalathar:z-timings-stats, r=jieyouxu

Simplify FFI calls for `-Ztime-llvm-passes` and `-Zprint-codegen-stats`

The existing code for these unstable LLVM-infodump flags was jumping through hoops to pass an allocated C string across the FFI boundary, when it's much simpler to just write to a `&RustString` instead.
This commit is contained in:
Stuart Cook 2024-11-08 18:51:30 +11:00 committed by GitHub
commit 3a48d80155
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 45 deletions

View file

@ -140,26 +140,14 @@ extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
unwrap(M)->setTargetTriple(Triple::normalize(Triple));
}
extern "C" const char *LLVMRustPrintPassTimings(size_t *Len) {
std::string buf;
auto SS = raw_string_ostream(buf);
TimerGroup::printAll(SS);
SS.flush();
*Len = buf.length();
char *CStr = (char *)malloc(*Len);
memcpy(CStr, buf.c_str(), *Len);
return CStr;
extern "C" void LLVMRustPrintPassTimings(RustStringRef OutBuf) {
auto OS = RawRustStringOstream(OutBuf);
TimerGroup::printAll(OS);
}
extern "C" const char *LLVMRustPrintStatistics(size_t *Len) {
std::string buf;
auto SS = raw_string_ostream(buf);
llvm::PrintStatistics(SS);
SS.flush();
*Len = buf.length();
char *CStr = (char *)malloc(*Len);
memcpy(CStr, buf.c_str(), *Len);
return CStr;
extern "C" void LLVMRustPrintStatistics(RustStringRef OutBuf) {
auto OS = RawRustStringOstream(OutBuf);
llvm::PrintStatistics(OS);
}
extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M, const char *Name,