diff options
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/Core.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Function.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Globals.cpp | 45 |
3 files changed, 25 insertions, 28 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index e5b98b89db6..e3a445800c7 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1307,7 +1307,7 @@ const char *LLVMGetSection(LLVMValueRef Global) { } void LLVMSetSection(LLVMValueRef Global, const char *Section) { - unwrap<GlobalValue>(Global)->setSection(Section); + unwrap<GlobalObject>(Global)->setSection(Section); } LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) { @@ -1357,7 +1357,7 @@ unsigned LLVMGetAlignment(LLVMValueRef V) { void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) { Value *P = unwrap<Value>(V); - if (GlobalValue *GV = dyn_cast<GlobalValue>(P)) + if (GlobalObject *GV = dyn_cast<GlobalObject>(P)) GV->setAlignment(Bytes); else if (AllocaInst *AI = dyn_cast<AllocaInst>(P)) AI->setAlignment(Bytes); diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index c1a09686b02..de8e66f1bca 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -209,7 +209,7 @@ void Function::eraseFromParent() { Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name, Module *ParentModule) - : GlobalValue(PointerType::getUnqual(Ty), + : GlobalObject(PointerType::getUnqual(Ty), Value::FunctionVal, nullptr, 0, Linkage, name) { assert(FunctionType::isValidReturnType(getReturnType()) && "invalid return type"); @@ -361,7 +361,7 @@ void Function::clearGC() { /// create a Function) from the Function Src to this one. void Function::copyAttributesFrom(const GlobalValue *Src) { assert(isa<Function>(Src) && "Expected a Function!"); - GlobalValue::copyAttributesFrom(Src); + GlobalObject::copyAttributesFrom(Src); const Function *SrcF = cast<Function>(Src); setCallingConv(SrcF->getCallingConv()); setAttributes(SrcF->getAttributes()); diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 0138a223817..0ec54fe3c08 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -53,11 +53,6 @@ void GlobalValue::destroyConstant() { /// copyAttributesFrom - copy all additional attributes (those not needed to /// create a GlobalValue) from the GlobalValue Src to this one. void GlobalValue::copyAttributesFrom(const GlobalValue *Src) { - if (!isa<GlobalAlias>(this)) { - setAlignment(Src->getAlignment()); - setSection(Src->getSection()); - } - setVisibility(Src->getVisibility()); setUnnamedAddr(Src->hasUnnamedAddr()); setDLLStorageClass(Src->getDLLStorageClass()); @@ -67,29 +62,31 @@ unsigned GlobalValue::getAlignment() const { if (auto *GA = dyn_cast<GlobalAlias>(this)) return GA->getAliasedGlobal()->getAlignment(); - return (1u << Alignment) >> 1; + return cast<GlobalObject>(this)->getAlignment(); } -void GlobalValue::setAlignment(unsigned Align) { - assert((!isa<GlobalAlias>(this)) && - "GlobalAlias should not have an alignment!"); +void GlobalObject::setAlignment(unsigned Align) { assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); assert(Align <= MaximumAlignment && "Alignment is greater than MaximumAlignment!"); - Alignment = Log2_32(Align) + 1; + setGlobalValueSubClassData(Log2_32(Align) + 1); assert(getAlignment() == Align && "Alignment representation error!"); } +void GlobalObject::copyAttributesFrom(const GlobalValue *Src) { + const auto *GV = cast<GlobalObject>(Src); + GlobalValue::copyAttributesFrom(GV); + setAlignment(GV->getAlignment()); + setSection(GV->getSection()); +} + const std::string &GlobalValue::getSection() const { if (auto *GA = dyn_cast<GlobalAlias>(this)) return GA->getAliasedGlobal()->getSection(); - return Section; + return cast<GlobalObject>(this)->getSection(); } -void GlobalValue::setSection(StringRef S) { - assert(!isa<GlobalAlias>(this) && "GlobalAlias should not have a section!"); - Section = S; -} +void GlobalObject::setSection(StringRef S) { Section = S; } bool GlobalValue::isDeclaration() const { // Globals are definitions if they have an initializer. @@ -113,9 +110,9 @@ GlobalVariable::GlobalVariable(Type *Ty, bool constant, LinkageTypes Link, Constant *InitVal, const Twine &Name, ThreadLocalMode TLMode, unsigned AddressSpace, bool isExternallyInitialized) - : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal, - OperandTraits<GlobalVariable>::op_begin(this), - InitVal != nullptr, Link, Name), + : GlobalObject(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal, + OperandTraits<GlobalVariable>::op_begin(this), + InitVal != nullptr, Link, Name), isConstantGlobal(constant), threadLocalMode(TLMode), isExternallyInitializedConstant(isExternallyInitialized) { if (InitVal) { @@ -132,9 +129,9 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant, const Twine &Name, GlobalVariable *Before, ThreadLocalMode TLMode, unsigned AddressSpace, bool isExternallyInitialized) - : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal, - OperandTraits<GlobalVariable>::op_begin(this), - InitVal != nullptr, Link, Name), + : GlobalObject(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal, + OperandTraits<GlobalVariable>::op_begin(this), + InitVal != nullptr, Link, Name), isConstantGlobal(constant), threadLocalMode(TLMode), isExternallyInitializedConstant(isExternallyInitialized) { if (InitVal) { @@ -206,7 +203,7 @@ void GlobalVariable::setInitializer(Constant *InitVal) { /// create a GlobalVariable) from the GlobalVariable Src to this one. void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) { assert(isa<GlobalVariable>(Src) && "Expected a GlobalVariable!"); - GlobalValue::copyAttributesFrom(Src); + GlobalObject::copyAttributesFrom(Src); const GlobalVariable *SrcVar = cast<GlobalVariable>(Src); setThreadLocalMode(SrcVar->getThreadLocalMode()); } @@ -269,7 +266,7 @@ static GlobalValue *getAliaseeGV(GlobalAlias *GA) { return cast<GlobalValue>(CE->getOperand(0)); } -GlobalValue *GlobalAlias::getAliasedGlobal() { +GlobalObject *GlobalAlias::getAliasedGlobal() { SmallPtrSet<GlobalValue*, 3> Visited; GlobalAlias *GA = this; @@ -282,6 +279,6 @@ GlobalValue *GlobalAlias::getAliasedGlobal() { // Iterate over aliasing chain. GA = dyn_cast<GlobalAlias>(GV); if (!GA) - return GV; + return cast<GlobalObject>(GV); } } |