From 7b1f1048e86ebf78bb2f04232261813077b541ae Mon Sep 17 00:00:00 2001
From: David Blaikie <dblaikie@gmail.com>
Date: Fri, 21 Aug 2015 21:35:28 +0000
Subject: [PATCH] [opaque pointer types] Push the passing of value types up
 from Function/GlobalVariable to GlobalObject

(coming next, pushing this up into GlobalValue, so it can store the
value type directly)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245742 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/llvm/IR/GlobalObject.h | 9 +++++++--
 lib/IR/Function.cpp            | 2 +-
 lib/IR/Globals.cpp             | 8 ++++----
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/llvm/IR/GlobalObject.h b/include/llvm/IR/GlobalObject.h
index f0552410b61..4b671da193d 100644
--- a/include/llvm/IR/GlobalObject.h
+++ b/include/llvm/IR/GlobalObject.h
@@ -28,8 +28,13 @@ class GlobalObject : public GlobalValue {
 
 protected:
   GlobalObject(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
-               LinkageTypes Linkage, const Twine &Name)
-      : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name), ObjComdat(nullptr) {
+               LinkageTypes Linkage, const Twine &Name) = delete;
+  GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
+               LinkageTypes Linkage, const Twine &Name,
+               unsigned AddressSpace = 0)
+      : GlobalValue(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps,
+                    Linkage, Name),
+        ObjComdat(nullptr) {
     setGlobalValueSubClassData(0);
   }
 
diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp
index b50ad1262c6..7d150bfe89f 100644
--- a/lib/IR/Function.cpp
+++ b/lib/IR/Function.cpp
@@ -248,7 +248,7 @@ void Function::eraseFromParent() {
 
 Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name,
                    Module *ParentModule)
-    : GlobalObject(PointerType::getUnqual(Ty), Value::FunctionVal,
+    : GlobalObject(Ty, Value::FunctionVal,
                    OperandTraits<Function>::op_begin(this), 0, Linkage, name),
       Ty(Ty) {
   assert(FunctionType::isValidReturnType(getReturnType()) &&
diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp
index 1d0282677bf..2cd1ea6b2d3 100644
--- a/lib/IR/Globals.cpp
+++ b/lib/IR/Globals.cpp
@@ -147,9 +147,9 @@ GlobalVariable::GlobalVariable(Type *Ty, bool constant, LinkageTypes Link,
                                Constant *InitVal, const Twine &Name,
                                ThreadLocalMode TLMode, unsigned AddressSpace,
                                bool isExternallyInitialized)
-    : GlobalObject(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
+    : GlobalObject(Ty, Value::GlobalVariableVal,
                    OperandTraits<GlobalVariable>::op_begin(this),
-                   InitVal != nullptr, Link, Name),
+                   InitVal != nullptr, Link, Name, AddressSpace),
       isConstantGlobal(constant),
       isExternallyInitializedConstant(isExternallyInitialized) {
   setThreadLocalMode(TLMode);
@@ -165,9 +165,9 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
                                const Twine &Name, GlobalVariable *Before,
                                ThreadLocalMode TLMode, unsigned AddressSpace,
                                bool isExternallyInitialized)
-    : GlobalObject(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
+    : GlobalObject(Ty, Value::GlobalVariableVal,
                    OperandTraits<GlobalVariable>::op_begin(this),
-                   InitVal != nullptr, Link, Name),
+                   InitVal != nullptr, Link, Name, AddressSpace),
       isConstantGlobal(constant),
       isExternallyInitializedConstant(isExternallyInitialized) {
   setThreadLocalMode(TLMode);
-- 
2.34.1