diff options
Diffstat (limited to 'contrib/llvm/lib/IR/Globals.cpp')
-rw-r--r-- | contrib/llvm/lib/IR/Globals.cpp | 75 |
1 files changed, 59 insertions, 16 deletions
diff --git a/contrib/llvm/lib/IR/Globals.cpp b/contrib/llvm/lib/IR/Globals.cpp index 6715484..6f73565 100644 --- a/contrib/llvm/lib/IR/Globals.cpp +++ b/contrib/llvm/lib/IR/Globals.cpp @@ -15,25 +15,39 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Triple.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/ConstantRange.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" +#include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" +#include "LLVMContextImpl.h" using namespace llvm; //===----------------------------------------------------------------------===// // GlobalValue Class //===----------------------------------------------------------------------===// +// GlobalValue should be a Constant, plus a type, a module, some flags, and an +// intrinsic ID. Add an assert to prevent people from accidentally growing +// GlobalValue while adding flags. +static_assert(sizeof(GlobalValue) == + sizeof(Constant) + 2 * sizeof(void *) + 2 * sizeof(unsigned), + "unexpected GlobalValue size growth"); + +// GlobalObject adds a comdat. +static_assert(sizeof(GlobalObject) == sizeof(GlobalValue) + sizeof(void *), + "unexpected GlobalObject size growth"); + bool GlobalValue::isMaterializable() const { if (const Function *F = dyn_cast<Function>(this)) return F->isMaterializable(); return false; } -std::error_code GlobalValue::materialize() { +Error GlobalValue::materialize() { return getParent()->materialize(this); } @@ -151,11 +165,24 @@ Comdat *GlobalValue::getComdat() { return cast<GlobalObject>(this)->getComdat(); } +StringRef GlobalObject::getSectionImpl() const { + assert(hasSection()); + return getContext().pImpl->GlobalObjectSections[this]; +} + void GlobalObject::setSection(StringRef S) { - Section = S; + // Do nothing if we're clearing the section and it is already empty. + if (!hasSection() && S.empty()) + return; + + // Get or create a stable section name string and put it in the table in the + // context. + S = getContext().pImpl->SectionStrings.insert(S).first->first(); + getContext().pImpl->GlobalObjectSections[this] = S; - // The C api requires this to be null terminated. - Section.c_str(); + // Update the HasSectionHashEntryBit. Setting the section to the empty string + // means this global no longer has a section. + setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty()); } bool GlobalValue::isDeclaration() const { @@ -213,6 +240,34 @@ bool GlobalValue::canIncreaseAlignment() const { return true; } +GlobalObject *GlobalValue::getBaseObject() { + if (auto *GO = dyn_cast<GlobalObject>(this)) + return GO; + if (auto *GA = dyn_cast<GlobalAlias>(this)) + return GA->getBaseObject(); + return nullptr; +} + +bool GlobalValue::isAbsoluteSymbolRef() const { + auto *GO = dyn_cast<GlobalObject>(this); + if (!GO) + return false; + + return GO->getMetadata(LLVMContext::MD_absolute_symbol); +} + +Optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const { + auto *GO = dyn_cast<GlobalObject>(this); + if (!GO) + return None; + + MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol); + if (!MD) + return None; + + return getConstantRangeFromMetadata(*MD); +} + //===----------------------------------------------------------------------===// // GlobalVariable Implementation //===----------------------------------------------------------------------===// @@ -257,10 +312,6 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant, M.getGlobalList().push_back(this); } -void GlobalVariable::setParent(Module *parent) { - Parent = parent; -} - void GlobalVariable::removeFromParent() { getParent()->getGlobalList().remove(getIterator()); } @@ -359,10 +410,6 @@ GlobalAlias *GlobalAlias::create(const Twine &Name, GlobalValue *Aliasee) { return create(Aliasee->getLinkage(), Name, Aliasee); } -void GlobalAlias::setParent(Module *parent) { - Parent = parent; -} - void GlobalAlias::removeFromParent() { getParent()->getAliasList().remove(getIterator()); } @@ -396,10 +443,6 @@ GlobalIFunc *GlobalIFunc::create(Type *Ty, unsigned AddressSpace, return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule); } -void GlobalIFunc::setParent(Module *parent) { - Parent = parent; -} - void GlobalIFunc::removeFromParent() { getParent()->getIFuncList().remove(getIterator()); } |