[clang] [CIR] Upstream global variable replacement (PR #184686)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 4 12:51:52 PST 2026
================
@@ -674,6 +674,49 @@ static void setLinkageForGV(cir::GlobalOp &gv, const NamedDecl *nd) {
gv.setLinkage(cir::GlobalLinkageKind::ExternalWeakLinkage);
}
+// We want to replace a global value, but because of CIR's typed pointers,
+// we need to update the existing uses to reflect the new type, not just replace
+// them directly.
+void CIRGenModule::replaceGlobal(cir::GlobalOp oldGV, cir::GlobalOp newGV) {
+ assert(oldGV.getSymName() == newGV.getSymName() && "symbol names must match");
+
+ mlir::Type oldTy = oldGV.getSymType();
+ mlir::Type newTy = newGV.getSymType();
+
+ assert(!cir::MissingFeatures::addressSpace());
+
+ // If the type didn't change, why are we here?
+ assert(oldTy != newTy && "expected type change in replaceGlobal");
+
+ // Otherwise, visit all uses and add handling to fix up the types.
+ std::optional<mlir::SymbolTable::UseRange> oldSymUses =
+ oldGV.getSymbolUses(theModule);
+ if (oldSymUses) {
----------------
erichkeane wrote:
This `if` is unnecessary, thanks to the range-for.
https://github.com/llvm/llvm-project/pull/184686
More information about the cfe-commits
mailing list