#define LLVM_IR_GLOBALVALUE_H
#include "llvm/IR/Constant.h"
+#include "llvm/IR/DerivedTypes.h"
namespace llvm {
AvailableExternallyLinkage, ///< Available for inspection, not emission.
LinkOnceAnyLinkage, ///< Keep one copy of function when linking (inline)
LinkOnceODRLinkage, ///< Same, but only replaced by something equivalent.
- LinkOnceODRAutoHideLinkage, ///< Like LinkOnceODRLinkage but addr not taken.
WeakAnyLinkage, ///< Keep one copy of named function when linking (weak)
WeakODRLinkage, ///< Same, but only replaced by something equivalent.
AppendingLinkage, ///< Special purpose, only applies to global arrays
InternalLinkage, ///< Rename collisions when linking (static functions).
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.
};
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(nullptr) {
setName(Name);
}
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:
removeDeadConstantUsers(); // remove any dead constants using this.
}
- unsigned getAlignment() const {
- return (1u << Alignment) >> 1;
- }
+ unsigned getAlignment() const;
void setAlignment(unsigned Align);
bool hasUnnamedAddr() const { return UnnamedAddr; }
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; }
-
- /// 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.
- /// @brief Determine if the usage of this global value is empty except
- /// for transitively dead constants.
- bool use_empty_except_constants();
+ void setSection(StringRef S);
/// getType - Global values are always pointers.
inline PointerType *getType() const {
- return reinterpret_cast<PointerType*>(User::getType());
+ return cast<PointerType>(User::getType());
}
static LinkageTypes getLinkOnceLinkage(bool ODR) {
return Linkage == AvailableExternallyLinkage;
}
static bool isLinkOnceLinkage(LinkageTypes Linkage) {
- return Linkage == LinkOnceAnyLinkage ||
- Linkage == LinkOnceODRLinkage ||
- Linkage == LinkOnceODRAutoHideLinkage;
- }
- static bool isLinkOnceODRAutoHideLinkage(LinkageTypes Linkage) {
- return Linkage == LinkOnceODRAutoHideLinkage;
+ return Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage;
}
static bool isWeakLinkage(LinkageTypes Linkage) {
return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage;
static bool isPrivateLinkage(LinkageTypes Linkage) {
return Linkage == PrivateLinkage;
}
- static bool isLinkerPrivateLinkage(LinkageTypes Linkage) {
- return Linkage == LinkerPrivateLinkage;
- }
- static bool isLinkerPrivateWeakLinkage(LinkageTypes Linkage) {
- return Linkage == LinkerPrivateWeakLinkage;
- }
static bool isLocalLinkage(LinkageTypes Linkage) {
- 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;
+ return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage);
}
static bool isExternalWeakLinkage(LinkageTypes Linkage) {
return Linkage == ExternalWeakLinkage;
/// by something non-equivalent at link time. For example, if a function has
/// weak linkage then the code defining it may be replaced by different code.
static bool mayBeOverridden(LinkageTypes Linkage) {
- return Linkage == WeakAnyLinkage ||
- Linkage == LinkOnceAnyLinkage ||
- Linkage == CommonLinkage ||
- Linkage == ExternalWeakLinkage ||
- Linkage == LinkerPrivateWeakLinkage;
+ return Linkage == WeakAnyLinkage || Linkage == LinkOnceAnyLinkage ||
+ Linkage == CommonLinkage || Linkage == ExternalWeakLinkage;
}
/// isWeakForLinker - Whether the definition of this global may be replaced at
/// always a 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 == LinkOnceODRAutoHideLinkage ||
- Linkage == CommonLinkage ||
- Linkage == ExternalWeakLinkage ||
- Linkage == LinkerPrivateWeakLinkage;
+ return Linkage == AvailableExternallyLinkage || Linkage == WeakAnyLinkage ||
+ Linkage == WeakODRLinkage || Linkage == LinkOnceAnyLinkage ||
+ Linkage == LinkOnceODRLinkage || Linkage == CommonLinkage ||
+ Linkage == ExternalWeakLinkage;
}
bool hasExternalLinkage() const { return isExternalLinkage(Linkage); }
bool hasLinkOnceLinkage() const {
return isLinkOnceLinkage(Linkage);
}
- bool hasLinkOnceODRAutoHideLinkage() const {
- return isLinkOnceODRAutoHideLinkage(Linkage);
- }
bool hasWeakLinkage() const {
return isWeakLinkage(Linkage);
}
bool hasAppendingLinkage() const { return isAppendingLinkage(Linkage); }
bool hasInternalLinkage() const { return isInternalLinkage(Linkage); }
bool hasPrivateLinkage() const { return isPrivateLinkage(Linkage); }
- bool hasLinkerPrivateLinkage() const { return isLinkerPrivateLinkage(Linkage); }
- bool hasLinkerPrivateWeakLinkage() const {
- 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); }
/// create a GlobalValue) from the GlobalValue Src to this one.
virtual void copyAttributesFrom(const GlobalValue *Src);
+ /// getRealLinkageName - If special LLVM prefix that is used to inform the asm
+ /// printer to not emit usual symbol prefix before the symbol name is used
+ /// then return linkage name after skipping this special LLVM prefix.
+ static StringRef getRealLinkageName(StringRef Name) {
+ if (!Name.empty() && Name[0] == '\1')
+ return Name.substr(1);
+ return Name;
+ }
+
/// @name Materialization
/// Materialization is used to construct functions only as they're needed. This
/// is useful to reduce memory usage in LLVM or parsing work done by the
/// Materialize - 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.
- bool Materialize(std::string *ErrInfo = 0);
+ bool Materialize(std::string *ErrInfo = nullptr);
/// Dematerialize - If this GlobalValue is read in, and if the GVMaterializer
/// supports it, release the memory for the function, and set it up to be
/// @}
/// Override from Constant class.
- virtual void destroyConstant();
+ void destroyConstant() override;
/// isDeclaration - Return true if the primary definition of this global
/// value is outside of the current translation unit.
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 ||