aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Module.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2025-05-27 12:23:12 -0700
committerGitHub <noreply@github.com>2025-05-27 12:23:12 -0700
commit645f0e6723f21aef8099d8d65f5719fd9feb125e (patch)
treef39b5cfe6a4d9c59ab7cd07c77943ae2c4275c12 /llvm/lib/IR/Module.cpp
parentea8838446678a1163b361b0598b1259e9f476900 (diff)
downloadllvm-645f0e6723f21aef8099d8d65f5719fd9feb125e.zip
llvm-645f0e6723f21aef8099d8d65f5719fd9feb125e.tar.gz
llvm-645f0e6723f21aef8099d8d65f5719fd9feb125e.tar.bz2
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
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r--llvm/lib/IR/Module.cpp11
1 files changed, 4 insertions, 7 deletions
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<GlobalVariable *()> 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);