<div dir="ltr">We'd like to implement support for selectively enabling profile instrumentation only for certain files/functions.<div><br></div><div>The motivation is collecting code coverage information in presubmit testing, where we want to avoid instrumenting the entire build which would introduce a lot of overhead. Rather, we only want to instrument files/functions that were modified by the patch by passing this information to Clang.<br></div><div><br></div><div>Clang already has -fprofile-filter-files= and -fprofile-exclude-files=, but those flags are currently only supported by GCOV. Furthermore, they only work at the granularity of entire files. I'm also not a fan of using flags which increases the size of the command line as you keep adding more files.</div><div><br></div><div>The solution I'm considering for source-code coverage is use the special case list (see <a href="https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/Support/SpecialCaseList.h">https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/Support/SpecialCaseList.h</a>) which is already used by sanitizers and XRay and seems like a great fit for this case. Concretely, we would add a new flag, e.g. -fprofile-flter=path/to/special/case/list. The file would have the following format:</div><div><br></div><div>[include]</div><div>src:src:/path/to/source/*</div>fun:MyFooBar<div>[exclude]</div><div>src:src:/path/to/source/file.c<br></div><div><br></div><div>This is similar to <a href="https://clang.llvm.org/docs/SanitizerSpecialCaseList.html">https://clang.llvm.org/docs/SanitizerSpecialCaseList.html</a> and <a href="https://llvm.org/docs/XRay.html#special-case-file">https://llvm.org/docs/XRay.html#special-case-file</a>.</div><div><br></div><div>Does this sound reasonable?</div><div><br></div><div>Related question is whether this option should apply to both AST and IR based instrumentation and where to perform the filtering. We could do the filtering either when inserting the instrumentation instructions, i.e. in PGOInstrumentation.cpp and CodeGenPGO.cpp, or when lowering these instructions InstrProfiling.cpp (where we would just discard these instructions). The advantage of the latter approach is that we only need to implement the filtering once and it'd support both AST and IR based instrumentation, but it also means that we would unnecessarily insert extra instructions only to drop them later.</div><div><br></div><div>Does anyone have any preference or suggestion?</div></div>