[llvm] [PassInstrumentation] Replace llvm::Any with a tagged IRUnitRef. (NFC) (PR #215341)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 00:23:00 PDT 2026


================
@@ -0,0 +1,142 @@
+//===- llvm/IR/IRUnitRef.h - Reference to an IR unit ------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file defines IRUnitRef, a tagged pointer to the IR unit a pass or
+/// analysis is running on, and IRUnitKindTraits, which IR units specialize to
+/// opt into being referred to by one.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_IRUNITREF_H
+#define LLVM_IR_IRUNITREF_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/Support/Casting.h"
+#include <cstddef>
+#include <type_traits>
+
+namespace llvm {
+
+class Function;
+class Loop;
+class MachineFunction;
+class Module;
+
+/// The IR units a pass can run on.
+enum class IRUnitKind {
+  Module,
+  Function,
+  Loop,
+  MachineFunction,
+  LazyCallGraphSCC,
+};
+
+/// Map an IR unit type to its IRUnitKind.
+template <typename IRUnitT> struct IRUnitKindTraits {};
----------------
fhahn wrote:

Yep, I think it is also nested and cannot be forward declared AFAICT. Not sure if there's a better way

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


More information about the llvm-commits mailing list