From 645f0e6723f21aef8099d8d65f5719fd9feb125e Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 27 May 2025 12:23:12 -0700 Subject: IR: Make Module::getOrInsertGlobal() return a GlobalVariable. After pointer element types were removed this function can only return a GlobalVariable, so reflect that in the type and comments and clean up callers. Reviewers: nikic Reviewed By: nikic Pull Request: https://github.com/llvm/llvm-project/pull/141323 --- llvm/lib/IR/Module.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'llvm/lib/IR/Module.cpp') diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index c7daaaf..eb635dc 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -250,12 +250,9 @@ GlobalVariable *Module::getGlobalVariable(StringRef Name, } /// getOrInsertGlobal - Look up the specified global in the module symbol table. -/// 1. If it does not exist, add a declaration of the global and return it. -/// 2. Else, the global exists but has the wrong type: return the function -/// with a constantexpr cast to the right type. -/// 3. Finally, if the existing global is the correct declaration, return the -/// existing global. -Constant *Module::getOrInsertGlobal( +/// If it does not exist, add a declaration of the global and return it. +/// Otherwise, return the existing global. +GlobalVariable *Module::getOrInsertGlobal( StringRef Name, Type *Ty, function_ref CreateGlobalCallback) { // See if we have a definition for the specified global already. @@ -269,7 +266,7 @@ Constant *Module::getOrInsertGlobal( } // Overload to construct a global variable using its constructor's defaults. -Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) { +GlobalVariable *Module::getOrInsertGlobal(StringRef Name, Type *Ty) { return getOrInsertGlobal(Name, Ty, [&] { return new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage, nullptr, Name); -- cgit v1.1