Auto merge of #114005 - Zalathar:no-cstr, r=jackh726
coverage: Don't convert filename/symbol strings to `CString` for FFI LLVM APIs are usually perfectly happy to accept pointer/length strings, as long as we supply a suitable length value when creating a `StringRef` or `std::string`. This lets us avoid quite a few intermediate `CString` copies during coverage codegen. It also lets us use an `IndexSet<Symbol>` (instead of an `IndexSet<CString>`) when building the deduplicated filename table.
This commit is contained in:
commit
a9b2c6a0ce
4 changed files with 52 additions and 26 deletions
|
@ -103,12 +103,20 @@ fromRust(LLVMRustCounterExprKind Kind) {
|
|||
}
|
||||
|
||||
extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
|
||||
const char* const Filenames[],
|
||||
const char *const Filenames[],
|
||||
size_t FilenamesLen,
|
||||
const size_t *const Lengths,
|
||||
size_t LengthsLen,
|
||||
RustStringRef BufferOut) {
|
||||
if (FilenamesLen != LengthsLen) {
|
||||
report_fatal_error(
|
||||
"Mismatched lengths in LLVMRustCoverageWriteFilenamesSectionToBuffer");
|
||||
}
|
||||
|
||||
SmallVector<std::string,32> FilenameRefs;
|
||||
FilenameRefs.reserve(FilenamesLen);
|
||||
for (size_t i = 0; i < FilenamesLen; i++) {
|
||||
FilenameRefs.push_back(std::string(Filenames[i]));
|
||||
FilenameRefs.emplace_back(Filenames[i], Lengths[i]);
|
||||
}
|
||||
auto FilenamesWriter =
|
||||
coverage::CoverageFilenamesSectionWriter(ArrayRef<std::string>(FilenameRefs));
|
||||
|
@ -153,8 +161,11 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
|
|||
CoverageMappingWriter.write(OS);
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustCoverageCreatePGOFuncNameVar(LLVMValueRef F, const char *FuncName) {
|
||||
StringRef FuncNameRef(FuncName);
|
||||
extern "C" LLVMValueRef LLVMRustCoverageCreatePGOFuncNameVar(
|
||||
LLVMValueRef F,
|
||||
const char *FuncName,
|
||||
size_t FuncNameLen) {
|
||||
StringRef FuncNameRef(FuncName, FuncNameLen);
|
||||
return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue