-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LLVM Code Coverage Instrumentation #1088
base: master
Are you sure you want to change the base?
LLVM Code Coverage Instrumentation #1088
Conversation
hey @corbanvilla, first of all, thx for your contribution. This PR is pretty big, and also the topics are quite new to rusty, so I guess we should discuss further on how we best integrate these things. I'm afraid if we keep such a big PR pending for too long it will diverge more and more. I'll see if I can talk to the other maintainers soon but I really like that you already suggested some discussion points. ghaith already contributed into inkwell in the past, it should be failry streight forward to decide if this can be suggested to the inkwell project right away. I'll poke ghaith today when I see him. thx again! we'll keep in touch |
Hello @corbanvilla, Thank you for the PR. I didn't get the chance to look into it in details, but from your comments and first glance I just have a few small points.
|
Overview
Related Issue
Description
This PR includes all of the necessary code to introduce code coverage instrumentation into Rusty. It's a large PR with still lots of work to be done, but provides a proof of concept and reference point for some necessary discussions.
Code Coverage Instrumentation Process
CodeGen::new(...)
: Create aCoverageInstrumentationBuilder
CodeGen::generate_llvm_index(...)
: add increment function tollvm_index
.CodeGen::generate(...)
:CodeGen::generate(...) -> PouGenerator::generate_implementation(...)
:CodeGen::generate(...)
: call the LLVM instrumentation coverage pass (instrprof
) to run on the IR.increment
calls with other instructions, and theincrement
function calls are not actually callable.Overview of Changes
Add two new sub-packages, derived from the rust compiler:
compiler/rustc_llvm
: this contains cpp files that include the necessary classes and functions from the LLVM project, through rust-friendly wrappers. This is necessary because many of the code coverage features are not exposed through the LLVM C-API, and have to be called through this.build.rs
: taken directly from the rust compiler.compiler/rustc_llvm_coverage
: this package contains files and type definitions from the rust compiler, which have been modified to use Inkwell's type system:interface.rs
: function interfaces taken from the rust compiler, adapted to Inkwell typing (taken from rustc version1.64
, the last version to support LLVM 14).lib.rs
: includes slightly higher-level abstractions for interfacing with Inkwell in a more convenient way.ffi.rs
: exposes therustc_llvm
functions and links against the binary produced.types.rs
: coverage instrumentation type definitions, consolidated from different parts of the rust compiler.Create new
CoverageInstrumentationBuilder
(instrument.rs
), which is used similar toDebugBuilder
.CoverageInstrumentationBuilder
tries to encapsulate as much of the coverage instrumentation process as possible, to minimize changes to the Rusty. It's called throughout the code generation process at various stages.Temporarily uses a forked version of Inkwell, which exposes a global value constructor. This was fixed in Inkwell here.
Discussion Points
rustc_llvm
andrustc_llvm_coverage
don't necessarily fit into Rusty, and it would probably make more sense to integrate them into Inkwell, or into an extension of Inkwell (since the functions they reference are kind of undocumented and not exposed in the LLVM C-API). @ghaith would definitely be interested to know your thoughts on this.CoverageInstrumentationBuilder
throughout the codegen process.TODOs
build.rs
script inllvm_rustc
Examples