[clang] [llvm] [LLVM] Use @llvm.compiler.used/@llvm.used helpers in Clang and BitcodeWriter (PR #162660)

Juan Manuel Martinez CaamaƱo via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 3 07:48:45 PST 2025


================
@@ -671,3 +672,80 @@ void GlobalIFunc::applyAlongResolverPath(
   DenseSet<const GlobalAlias *> Aliases;
   findBaseObject(getResolver(), Aliases, Op);
 }
+
+static void collectUsedGlobals(GlobalVariable *GV,
+                               SmallSetVector<Constant *, 16> &Init) {
+  if (!GV || !GV->hasInitializer())
+    return;
+
+  auto *CA = cast<ConstantArray>(GV->getInitializer());
+  for (Use &Op : CA->operands())
+    Init.insert(cast<Constant>(Op));
+}
+
+static void appendToUsedList(Module &M, StringRef Name,
+                             ArrayRef<GlobalValue *> Values) {
+  GlobalVariable *GV = M.getGlobalVariable(Name);
+
+  SmallSetVector<Constant *, 16> Init;
+  collectUsedGlobals(GV, Init);
+  Type *ArrayEltTy = GV ? GV->getValueType()->getArrayElementType()
+                        : PointerType::getUnqual(M.getContext());
----------------
jmmartinez wrote:

I've updated the PR since https://github.com/llvm/llvm-project/pull/164432 landed first. Now we should only handle the `Unqual`.

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


More information about the cfe-commits mailing list