[PATCH] D56130: Extend Module::getOrInsertGlobal to also take the default arguments accepted by the GlobalVariable constructor.

Philip Pfaffe via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 28 05:34:04 PST 2018


philip.pfaffe created this revision.
philip.pfaffe added a reviewer: chandlerc.
Herald added subscribers: bollu, hiraditya.

The default arguments are only used when creating a new global, not when
looking up an existing one.


https://reviews.llvm.org/D56130

Files:
  llvm/include/llvm/IR/Module.h
  llvm/lib/IR/Module.cpp


Index: llvm/lib/IR/Module.cpp
===================================================================
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -203,15 +203,20 @@
 ///      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(StringRef Name, Type *Ty) {
+Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty, bool isConstant,
+                                    GlobalValue::LinkageTypes Linkage,
+                                    Constant *Initializer,
+                                    GlobalValue::ThreadLocalMode TLM,
+                                    unsigned AddressSpace,
+                                    bool isExternallyInitialized) {
   // See if we have a definition for the specified global already.
   GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
   if (!GV) {
     // Nope, add it
     GlobalVariable *New =
-      new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
-                         nullptr, Name);
-     return New;                    // Return the new declaration.
+        new GlobalVariable(*this, Ty, isConstant, Linkage, Initializer, Name,
+                           nullptr, TLM, AddressSpace, isExternallyInitialized);
+    return New; // Return the new declaration.
   }
 
   // If the variable exists but has the wrong type, return a bitcast to the
Index: llvm/include/llvm/IR/Module.h
===================================================================
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -406,13 +406,19 @@
   ///   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
+  ///   3. Finally, if the existing global has the correct type, return
   ///      the existing global.
-  Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
+  /// Note that if optional arguments aren't considered for matching the global.
+  Constant *getOrInsertGlobal(
+      StringRef Name, Type *Ty, bool isConstant = false,
+      GlobalValue::LinkageTypes Linkage = GlobalVariable::ExternalLinkage,
+      Constant *Initializer = nullptr,
+      GlobalValue::ThreadLocalMode TLM = GlobalValue::NotThreadLocal,
+      unsigned AddressSpace = 0, bool isExternallyInitialized = false);
 
-/// @}
-/// @name Global Alias Accessors
-/// @{
+  /// @}
+  /// @name Global Alias Accessors
+  /// @{
 
   /// Return the global alias in the module with the specified name, of
   /// arbitrary type. This method returns null if a global with the specified


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56130.179629.patch
Type: text/x-patch
Size: 2851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181228/c5f09464/attachment.bin>


More information about the llvm-commits mailing list