]>
git.proxmox.com Git - rustc.git/blob - compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
1 #include "LLVMWrapper.h"
2 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
3 #include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"
4 #include "llvm/ProfileData/InstrProf.h"
5 #include "llvm/ADT/ArrayRef.h"
11 extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
12 const char* const Filenames
[],
14 RustStringRef BufferOut
) {
15 SmallVector
<StringRef
,32> FilenameRefs
;
16 for (size_t i
= 0; i
< FilenamesLen
; i
++) {
17 FilenameRefs
.push_back(StringRef(Filenames
[i
]));
19 auto FilenamesWriter
= coverage::CoverageFilenamesSectionWriter(
20 makeArrayRef(FilenameRefs
));
21 RawRustStringOstream
OS(BufferOut
);
22 FilenamesWriter
.write(OS
);
25 extern "C" void LLVMRustCoverageWriteMappingToBuffer(
26 const unsigned *VirtualFileMappingIDs
,
27 unsigned NumVirtualFileMappingIDs
,
28 const coverage::CounterExpression
*Expressions
,
29 unsigned NumExpressions
,
30 coverage::CounterMappingRegion
*MappingRegions
,
31 unsigned NumMappingRegions
,
32 RustStringRef BufferOut
) {
33 auto CoverageMappingWriter
= coverage::CoverageMappingWriter(
34 makeArrayRef(VirtualFileMappingIDs
, NumVirtualFileMappingIDs
),
35 makeArrayRef(Expressions
, NumExpressions
),
36 makeMutableArrayRef(MappingRegions
, NumMappingRegions
));
37 RawRustStringOstream
OS(BufferOut
);
38 CoverageMappingWriter
.write(OS
);
41 extern "C" LLVMValueRef
LLVMRustCoverageCreatePGOFuncNameVar(LLVMValueRef F
, const char *FuncName
) {
42 StringRef
FuncNameRef(FuncName
);
43 return wrap(createPGOFuncNameVar(*cast
<Function
>(unwrap(F
)), FuncNameRef
));
46 extern "C" uint64_t LLVMRustCoverageHashCString(const char *StrVal
) {
47 StringRef
StrRef(StrVal
);
48 return IndexedInstrProf::ComputeHash(StrRef
);
51 extern "C" uint64_t LLVMRustCoverageHashByteArray(
54 StringRef
StrRef(Bytes
, NumBytes
);
55 return IndexedInstrProf::ComputeHash(StrRef
);
58 static void WriteSectionNameToString(LLVMModuleRef M
,
61 Triple
TargetTriple(unwrap(M
)->getTargetTriple());
62 auto name
= getInstrProfSectionName(SK
, TargetTriple
.getObjectFormat());
63 RawRustStringOstream
OS(Str
);
67 extern "C" void LLVMRustCoverageWriteMapSectionNameToString(LLVMModuleRef M
,
69 WriteSectionNameToString(M
, IPSK_covmap
, Str
);
72 extern "C" void LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M
,
74 #if LLVM_VERSION_GE(11, 0)
75 WriteSectionNameToString(M
, IPSK_covfun
, Str
);
76 // else do nothing; the `Version` check will abort codegen on the Rust side
80 extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str
) {
81 auto name
= getCoverageMappingVarName();
82 RawRustStringOstream
OS(Str
);
86 extern "C" uint32_t LLVMRustCoverageMappingVersion() {
87 #if LLVM_VERSION_GE(11, 0)
88 return coverage::CovMapVersion::Version4
;
90 return coverage::CovMapVersion::Version3
;