Use DataLayout from the module when easily available.
[oota-llvm.git] / include / llvm / IR / GlobalValue.h
index 4f20a31a294b577da063e78f7e0745d12424016f..32108b153cd8bda4323a18655e7c2410a49a1f10 100644 (file)
@@ -42,8 +42,6 @@ public:
     PrivateLinkage,     ///< Like Internal, but omit from symbol table.
     LinkerPrivateLinkage, ///< Like Private, but linker removes.
     LinkerPrivateWeakLinkage, ///< Like LinkerPrivate, but weak.
-    DLLImportLinkage,   ///< Function to be imported from DLL
-    DLLExportLinkage,   ///< Function to be accessible from DLL.
     ExternalWeakLinkage,///< ExternalWeak linkage description.
     CommonLinkage       ///< Tentative definitions.
   };
@@ -55,11 +53,19 @@ public:
     ProtectedVisibility     ///< The GV is protected
   };
 
+  /// @brief Storage classes of global values for PE targets.
+  enum DLLStorageClassTypes {
+    DefaultStorageClass   = 0,
+    DLLImportStorageClass = 1, ///< Function to be imported from DLL
+    DLLExportStorageClass = 2  ///< Function to be accessible from DLL.
+  };
+
 protected:
   GlobalValue(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps,
               LinkageTypes linkage, const Twine &Name)
     : Constant(ty, vty, Ops, NumOps), Linkage(linkage),
-      Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0), Parent(0) {
+      Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0),
+      DllStorageClass(DefaultStorageClass), Parent(0) {
     setName(Name);
   }
 
@@ -69,6 +75,7 @@ protected:
   unsigned Visibility : 2;    // The visibility style of this global
   unsigned Alignment : 16;    // Alignment of this symbol, must be power of two
   unsigned UnnamedAddr : 1;   // This value's address is not significant
+  unsigned DllStorageClass : 2; // DLL storage class
   Module *Parent;             // The containing module.
   std::string Section;        // Section to emit this into, empty mean default
 public:
@@ -91,11 +98,26 @@ public:
     return Visibility == ProtectedVisibility;
   }
   void setVisibility(VisibilityTypes V) { Visibility = V; }
-  
+
+  DLLStorageClassTypes getDLLStorageClass() const {
+    return DLLStorageClassTypes(DllStorageClass);
+  }
+  bool hasDLLImportStorageClass() const {
+    return DllStorageClass == DLLImportStorageClass;
+  }
+  bool hasDLLExportStorageClass() const {
+    return DllStorageClass == DLLExportStorageClass;
+  }
+  void setDLLStorageClass(DLLStorageClassTypes C) { DllStorageClass = C; }
+
   bool hasSection() const { return !Section.empty(); }
   const std::string &getSection() const { return Section; }
-  void setSection(StringRef S) { Section = S; }
-  
+  void setSection(StringRef S) {
+    assert((getValueID() != Value::GlobalAliasVal || S.empty()) &&
+           "GlobalAlias should not have a section!");
+    Section = S;
+  }
+
   /// If the usage is empty (except transitively dead constants), then this
   /// global value can be safely deleted since the destructor will
   /// delete the dead constants as well.
@@ -146,12 +168,6 @@ public:
     return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage) ||
       isLinkerPrivateLinkage(Linkage) || isLinkerPrivateWeakLinkage(Linkage);
   }
-  static bool isDLLImportLinkage(LinkageTypes Linkage) {
-    return Linkage == DLLImportLinkage;
-  }
-  static bool isDLLExportLinkage(LinkageTypes Linkage) {
-    return Linkage == DLLExportLinkage;
-  }
   static bool isExternalWeakLinkage(LinkageTypes Linkage) {
     return Linkage == ExternalWeakLinkage;
   }
@@ -209,8 +225,6 @@ public:
     return isLinkerPrivateWeakLinkage(Linkage);
   }
   bool hasLocalLinkage() const { return isLocalLinkage(Linkage); }
-  bool hasDLLImportLinkage() const { return isDLLImportLinkage(Linkage); }
-  bool hasDLLExportLinkage() const { return isDLLExportLinkage(Linkage); }
   bool hasExternalWeakLinkage() const { return isExternalWeakLinkage(Linkage); }
   bool hasCommonLinkage() const { return isCommonLinkage(Linkage); }
 
@@ -286,6 +300,8 @@ public:
   inline Module *getParent() { return Parent; }
   inline const Module *getParent() const { return Parent; }
 
+  const DataLayout *getDataLayout() const;
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Value *V) {
     return V->getValueID() == Value::FunctionVal ||