X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FIR%2FGlobalValue.h;h=4fa4e7daeab0e5634586290baa8f521818ea8f53;hb=f11617b0abb665433a65f40882ceaefda7bd8322;hp=92d531f198788d53d08cafff33830ff9f8ddeead;hpb=a641a4a89eaed4589962f9bdb18bfd88e1d8360a;p=oota-llvm.git diff --git a/include/llvm/IR/GlobalValue.h b/include/llvm/IR/GlobalValue.h index 92d531f1987..4fa4e7daeab 100644 --- a/include/llvm/IR/GlobalValue.h +++ b/include/llvm/IR/GlobalValue.h @@ -30,7 +30,7 @@ class Module; namespace Intrinsic { enum ID : unsigned; -}; +} class GlobalValue : public Constant { GlobalValue(const GlobalValue &) = delete; @@ -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 @@ -83,11 +84,16 @@ protected: unsigned ThreadLocal : 3; // Is this symbol "Thread Local", if so, what is // the desired model? + static const unsigned GlobalValueSubClassDataBits = 19; private: // Give subclasses access to what otherwise would be wasted padding. // (19 + 3 + 2 + 1 + 2 + 5) == 32. - unsigned SubClassData : 19; + unsigned SubClassData : GlobalValueSubClassDataBits; + + friend class Constant; + void destroyConstantImpl(); + Value *handleOperandChangeImpl(Value *From, Value *To, Use *U); protected: /// \brief The intrinsic ID for this subclass (which must be a Function). @@ -98,12 +104,11 @@ protected: /// This is stored here to save space in Function on 64-bit hosts. Intrinsic::ID IntID; - static const unsigned GlobalValueSubClassDataBits = 19; unsigned getGlobalValueSubClassData() const { return SubClassData; } void setGlobalValueSubClassData(unsigned V) { - assert(V < (1 << 19) && "It will not fit"); + assert(V < (1 << GlobalValueSubClassDataBits) && "It will not fit"); SubClassData = V; } @@ -180,7 +185,7 @@ public: /// Global values are always pointers. PointerType *getType() const { return cast(User::getType()); } - Type *getValueType() const { return getType()->getElementType(); } + Type *getValueType() const { return ValueType; } static LinkageTypes getLinkOnceLinkage(bool ODR) { return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage; @@ -232,7 +237,8 @@ public: /// Whether the definition of this global may be discarded if it is not used /// in its compilation unit. static bool isDiscardableIfUnused(LinkageTypes Linkage) { - return isLinkOnceLinkage(Linkage) || isLocalLinkage(Linkage); + return isLinkOnceLinkage(Linkage) || isLocalLinkage(Linkage) || + isAvailableExternallyLinkage(Linkage); } /// Whether the definition of this global may be replaced by something @@ -248,10 +254,9 @@ public: /// mistake: when working at the IR level use mayBeOverridden instead as it /// knows about ODR semantics. static bool isWeakForLinker(LinkageTypes Linkage) { - return Linkage == AvailableExternallyLinkage || Linkage == WeakAnyLinkage || - Linkage == WeakODRLinkage || Linkage == LinkOnceAnyLinkage || - Linkage == LinkOnceODRLinkage || Linkage == CommonLinkage || - Linkage == ExternalWeakLinkage; + return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage || + Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage || + Linkage == CommonLinkage || Linkage == ExternalWeakLinkage; } bool hasExternalLinkage() const { return isExternalLinkage(Linkage); } @@ -317,26 +322,13 @@ public: /// function has been read in yet or not. bool isMaterializable() const; - /// Returns true if this function was loaded from a GVMaterializer that's - /// still attached to its Module and that knows how to dematerialize the - /// function. - bool isDematerializable() const; - /// Make sure this GlobalValue is fully read. If the module is corrupt, this /// returns true and fills in the optional string with information about the /// problem. If successful, this returns false. std::error_code materialize(); - /// If this GlobalValue is read in, and if the GVMaterializer supports it, - /// release the memory for the function, and set it up to be materialized - /// lazily. If !isDematerializable(), this method is a noop. - void dematerialize(); - /// @} - /// Override from Constant class. - void destroyConstant() override; - /// Return true if the primary definition of this global value is outside of /// the current translation unit. bool isDeclaration() const; @@ -348,6 +340,12 @@ public: return isDeclaration(); } + /// Returns true if this global's definition will be the one chosen by the + /// linker. + bool isStrongDefinitionForLinker() const { + return !(isDeclarationForLinker() || isWeakForLinker()); + } + /// This method unlinks 'this' from the containing module, but does not delete /// it. virtual void removeFromParent() = 0;