[llvm] [IR] Name unnamed values after each pass (PR #221519)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 20:04:00 PDT 2026


================
@@ -42,3 +66,31 @@ PreservedAnalyses InstructionNamerPass::run(Function &F,
   nameInstructions(F);
   return PreservedAnalyses::all();
 }
+
+static void nameIRUnit(IRUnitRef IR, std::atomic<uint64_t> &NextID) {
+  if (const auto *M = dyn_cast<Module>(IR)) {
+    for (Function &F : *const_cast<Module *>(M))
+      nameInstructions(F, &NextID);
+  } else if (const auto *F = dyn_cast<Function>(IR)) {
+    nameInstructions(*const_cast<Function *>(F), &NextID);
+  } else if (const auto *C = dyn_cast<LazyCallGraph::SCC>(IR)) {
+    for (const LazyCallGraph::Node &N : *C)
+      nameInstructions(N.getFunction(), &NextID);
+  } else if (const auto *L = dyn_cast<Loop>(IR)) {
+    nameInstructions(*L->getHeader()->getParent(), &NextID);
+  }
+}
+
+void InstructionNamerPass::registerCallbacks(
+    PassInstrumentationCallbacks &PIC) {
+  if (!InstNamerAfterEachPass)
+    return;
+
+  auto NextID = std::make_shared<std::atomic<uint64_t>>(0);
----------------
aeubanks wrote:

I was thinking that if you could get the pre-instnamer IR and the post-instnamer IR then you could track this at the consumer level. but I suppose it's very weird to expose two identical IRs to the consumer. I think this is fine

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


More information about the llvm-commits mailing list