[clang] [Profile] Refactor profile correlation. (PR #69656)

Zequan Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 25 12:33:32 PDT 2023


================
@@ -24,15 +24,38 @@
 
 using namespace llvm;
 
-/// Get the __llvm_prf_cnts section.
-Expected<object::SectionRef> getCountersSection(const object::ObjectFile &Obj) {
+namespace llvm {
+// Deprecated. Use -profile-correlate=debug-info.
+cl::opt<bool> DebugInfoCorrelate(
+    "debug-info-correlate",
+    cl::desc("Use debug info to correlate profiles (Deprecated). Use "
+             "-profile-correlate=debug-info instead."),
+    cl::init(false));
+
+cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate(
+    "profile-correlate",
+    cl::desc("Use debug info or binary file to correlate profiles."),
+    cl::init(InstrProfCorrelator::NONE),
+    cl::values(clEnumValN(InstrProfCorrelator::NONE, "",
+                          "No profile correlation"),
+               clEnumValN(InstrProfCorrelator::DEBUG_INFO, "debug-info",
+                          "Use debug info to correlate")));
----------------
ZequanWu wrote:

> I guess the root of the problem is that `Instrumentation` depends on `ProfileData`, so we can't have `InstrProfCorrelator.cpp` use a symbol defined in `Instrumentation`. 

Probably I didn't make it clear. We can keep `-debug-info-correlate` in `InstrProfiling.cpp`. 

In my [PR](https://github.com/llvm/llvm-project/pull/69493/files#diff-db16d50e8b3efb345f2adca0c4071e8bc1e06dfea64386454586a436d887ecefR484), I added a check for `-profile-correlate=binary` in `TargetLoweringObjectFileImpl.cpp`: , to determine if we should mark profile name & data sections as strippable, which requires `-profile-correlate` flag being defined in `TargetLoweringObjectFileImpl.cpp` in order to linked successfully with other targets that doesn't use `InstrProfiling.cpp`. That makes two flags separated in two files, so I moved them together to `InstrProfCorrelator.cpp`.

> That is unfortunate because `-debug-info-correlate` (`-profile-correlate=debug-info`) is a codegen flag while `InstrProfCorrelator.cpp` is primarily used by `llvm-prodata` which will not use `-debug-info-correlate`.
> I really think `-debug-info-correlate` does not belong in `InstrProfCorrelator.cpp`. I'm fine with keeping `InstrProfCorrelator::ProfCorrelatorKind` in this file, but the the flags should stay in `InstrProfiling.cpp` and if needed we can pass `ProfCorrelatorKind` as a parameter.

I didn't thought about that before. I agree it makes less sense to put codegen flags in `InstrProfCorrelator.cpp`.  I think this can be avoided by moving this flag to llvm/lib/CodeGen/CommandFlags.cpp. I'll take a look later.



https://github.com/llvm/llvm-project/pull/69656


More information about the cfe-commits mailing list