[clang] [CIR] Upstream global variable replacement (PR #184686)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 4 13:14: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.
----------------
andykaylor wrote:
Oops. The first-wise was handling replacement when the types were the same, but I don't think this function will be called unless the types are different.
https://github.com/llvm/llvm-project/pull/184686
More information about the cfe-commits
mailing list