[llvm] [PGO] Preserve analysis results when nothing was instrumented (PR #93421)

Pavel Samolysov via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 17:15:08 PDT 2024


================
@@ -405,9 +405,14 @@ static GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS) {
     ProfileVersion |= VARIANT_MASK_BYTE_COVERAGE;
   if (PGOTemporalInstrumentation)
     ProfileVersion |= VARIANT_MASK_TEMPORAL_PROF;
-  auto IRLevelVersionVariable = new GlobalVariable(
+  assert(!M.global_empty() &&
+         "If a module was instrumented, there must be defined global variables "
+         "at least for the counters.");
+  auto *InsertionPoint = &*M.global_begin();
+  auto *IRLevelVersionVariable = new GlobalVariable(
       M, IntTy64, true, GlobalValue::WeakAnyLinkage,
-      Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
+      Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName,
+      InsertionPoint);
----------------
samolisov wrote:

@aeubanks do you mean the `__llvm_profile_raw_version` variable generation? If to separate only insertion point adding, some lit test must be modified temporarily and then returned back. I think this work isn't necessary, better I'll split the patch to the compile time optimization and the variable not generation. Thank you for the suggestion.

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


More information about the llvm-commits mailing list