[opaque pointer types] Add an explicit value type to GlobalObject
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 14 Sep 2015 21:47:27 +0000 (21:47 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 14 Sep 2015 21:47:27 +0000 (21:47 +0000)
This is needed by all GlobalObjects (GlobalAlias, Function,
GlobalVariable), see the GlobalObject::getValueType which is used in
many places. If at some point that can be removed, then we can remove
this member.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247621 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/GlobalObject.h
include/llvm/IR/GlobalValue.h
lib/IR/Globals.cpp

index 4b671da193d40c1cb06249528661ecb50d047c43..ee111a046d7373d847ecf7e7bef148ddee4d85ed 100644 (file)
@@ -27,13 +27,10 @@ class GlobalObject : public GlobalValue {
   GlobalObject(const GlobalObject &) = delete;
 
 protected:
-  GlobalObject(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
-               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),
+      : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name, AddressSpace),
         ObjComdat(nullptr) {
     setGlobalValueSubClassData(0);
   }
index eb6af507816049c81c603d0868683a704d09c7d5..2f9172648a26a6d3f9cec216b7ef5be03b1c662e 100644 (file)
@@ -65,15 +65,16 @@ public:
   };
 
 protected:
-  GlobalValue(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
-              LinkageTypes Linkage, const Twine &Name)
-      : Constant(Ty, VTy, Ops, NumOps), Linkage(Linkage),
-        Visibility(DefaultVisibility), UnnamedAddr(0),
-        DllStorageClass(DefaultStorageClass),
+  GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
+              LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
+      : Constant(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps),
+        ValueType(Ty), Linkage(Linkage), Visibility(DefaultVisibility),
+        UnnamedAddr(0), DllStorageClass(DefaultStorageClass),
         ThreadLocal(NotThreadLocal), IntID((Intrinsic::ID)0U), Parent(nullptr) {
     setName(Name);
   }
 
+  Type *ValueType;
   // Note: VC++ treats enums as signed, so an extra bit is required to prevent
   // Linkage and Visibility from turning into negative values.
   LinkageTypes Linkage : 5;   // The linkage of this global
@@ -184,7 +185,7 @@ public:
   /// Global values are always pointers.
   PointerType *getType() const { return cast<PointerType>(User::getType()); }
 
-  Type *getValueType() const { return getType()->getElementType(); }
+  Type *getValueType() const { return ValueType; }
 
   static LinkageTypes getLinkOnceLinkage(bool ODR) {
     return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage;
index 28f223593a86487fa7a050eb9ddd8533197d132c..11ece2ed1b19c2f38a3cd1f6c01efb7790b10a8d 100644 (file)
@@ -234,8 +234,8 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
 GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
                          const Twine &Name, Constant *Aliasee,
                          Module *ParentModule)
-    : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalAliasVal,
-                  &Op<0>(), 1, Link, Name) {
+    : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name,
+                  AddressSpace) {
   Op<0>() = Aliasee;
 
   if (ParentModule)