mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-16 12:24:03 +00:00
Split GlobalValue into GlobalValue and GlobalObject.
This allows code to statically accept a Function or a GlobalVariable, but not an alias. This is already a cleanup by itself IMHO, but the main reason for it is that it gives a lot more confidence that the refactoring to fix the design of GlobalAlias is correct. That will be a followup patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1173,9 +1173,10 @@ LLVMTypeRef LLVMX86MMXType(void);
|
|||||||
macro(ConstantStruct) \
|
macro(ConstantStruct) \
|
||||||
macro(ConstantVector) \
|
macro(ConstantVector) \
|
||||||
macro(GlobalValue) \
|
macro(GlobalValue) \
|
||||||
macro(Function) \
|
|
||||||
macro(GlobalAlias) \
|
macro(GlobalAlias) \
|
||||||
macro(GlobalVariable) \
|
macro(GlobalObject) \
|
||||||
|
macro(Function) \
|
||||||
|
macro(GlobalVariable) \
|
||||||
macro(UndefValue) \
|
macro(UndefValue) \
|
||||||
macro(Instruction) \
|
macro(Instruction) \
|
||||||
macro(BinaryOperator) \
|
macro(BinaryOperator) \
|
||||||
|
@ -233,7 +233,7 @@ public:
|
|||||||
/// requested, it will override the alignment request if required for
|
/// requested, it will override the alignment request if required for
|
||||||
/// correctness.
|
/// correctness.
|
||||||
///
|
///
|
||||||
void EmitAlignment(unsigned NumBits, const GlobalValue *GV = nullptr) const;
|
void EmitAlignment(unsigned NumBits, const GlobalObject *GO = nullptr) const;
|
||||||
|
|
||||||
/// This method prints the label for the specified MachineBasicBlock, an
|
/// This method prints the label for the specified MachineBasicBlock, an
|
||||||
/// alignment (if present) and a comment describing it if appropriate.
|
/// alignment (if present) and a comment describing it if appropriate.
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "llvm/IR/Attributes.h"
|
#include "llvm/IR/Attributes.h"
|
||||||
#include "llvm/IR/BasicBlock.h"
|
#include "llvm/IR/BasicBlock.h"
|
||||||
#include "llvm/IR/CallingConv.h"
|
#include "llvm/IR/CallingConv.h"
|
||||||
#include "llvm/IR/GlobalValue.h"
|
#include "llvm/IR/GlobalObject.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -68,7 +68,7 @@ private:
|
|||||||
mutable ilist_half_node<Argument> Sentinel;
|
mutable ilist_half_node<Argument> Sentinel;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Function : public GlobalValue, public ilist_node<Function> {
|
class Function : public GlobalObject, public ilist_node<Function> {
|
||||||
public:
|
public:
|
||||||
typedef iplist<Argument> ArgumentListType;
|
typedef iplist<Argument> ArgumentListType;
|
||||||
typedef iplist<BasicBlock> BasicBlockListType;
|
typedef iplist<BasicBlock> BasicBlockListType;
|
||||||
|
@ -68,8 +68,8 @@ public:
|
|||||||
/// This method tries to ultimately resolve the alias by going through the
|
/// This method tries to ultimately resolve the alias by going through the
|
||||||
/// aliasing chain and trying to find the very last global. Returns NULL if a
|
/// aliasing chain and trying to find the very last global. Returns NULL if a
|
||||||
/// cycle was found.
|
/// cycle was found.
|
||||||
GlobalValue *getAliasedGlobal();
|
GlobalObject *getAliasedGlobal();
|
||||||
const GlobalValue *getAliasedGlobal() const {
|
const GlobalObject *getAliasedGlobal() const {
|
||||||
return const_cast<GlobalAlias *>(this)->getAliasedGlobal();
|
return const_cast<GlobalAlias *>(this)->getAliasedGlobal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
include/llvm/IR/GlobalObject.h
Normal file
58
include/llvm/IR/GlobalObject.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
//===-- llvm/GlobalObject.h - Class to represent a global object *- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This represents an independent object. That is, a function or a global
|
||||||
|
// variable, but not an alias.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_IR_GLOBALOBJECT_H
|
||||||
|
#define LLVM_IR_GLOBALOBJECT_H
|
||||||
|
|
||||||
|
#include "llvm/IR/Constant.h"
|
||||||
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
|
#include "llvm/IR/GlobalValue.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
class Module;
|
||||||
|
|
||||||
|
class GlobalObject : public GlobalValue {
|
||||||
|
GlobalObject(const GlobalObject &) LLVM_DELETED_FUNCTION;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
|
||||||
|
LinkageTypes Linkage, const Twine &Name)
|
||||||
|
: GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name) {
|
||||||
|
setGlobalValueSubClassData(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Section; // Section to emit this into, empty means default
|
||||||
|
public:
|
||||||
|
unsigned getAlignment() const {
|
||||||
|
return (1u << getGlobalValueSubClassData()) >> 1;
|
||||||
|
}
|
||||||
|
void setAlignment(unsigned Align);
|
||||||
|
|
||||||
|
bool hasSection() const { return !getSection().empty(); }
|
||||||
|
const std::string &getSection() const { return Section; }
|
||||||
|
void setSection(StringRef S);
|
||||||
|
|
||||||
|
void copyAttributesFrom(const GlobalValue *Src) override;
|
||||||
|
|
||||||
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
|
static inline bool classof(const Value *V) {
|
||||||
|
return V->getValueID() == Value::FunctionVal ||
|
||||||
|
V->getValueID() == Value::GlobalVariableVal;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End llvm namespace
|
||||||
|
|
||||||
|
#endif
|
@ -62,7 +62,7 @@ protected:
|
|||||||
GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
|
GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
|
||||||
LinkageTypes Linkage, const Twine &Name)
|
LinkageTypes Linkage, const Twine &Name)
|
||||||
: Constant(Ty, VTy, Ops, NumOps), Linkage(Linkage),
|
: Constant(Ty, VTy, Ops, NumOps), Linkage(Linkage),
|
||||||
Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0),
|
Visibility(DefaultVisibility), UnnamedAddr(0),
|
||||||
DllStorageClass(DefaultStorageClass), Parent(nullptr) {
|
DllStorageClass(DefaultStorageClass), Parent(nullptr) {
|
||||||
setName(Name);
|
setName(Name);
|
||||||
}
|
}
|
||||||
@ -71,18 +71,29 @@ protected:
|
|||||||
// Linkage and Visibility from turning into negative values.
|
// Linkage and Visibility from turning into negative values.
|
||||||
LinkageTypes Linkage : 5; // The linkage of this global
|
LinkageTypes Linkage : 5; // The linkage of this global
|
||||||
unsigned Visibility : 2; // The visibility style of this global
|
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 UnnamedAddr : 1; // This value's address is not significant
|
||||||
unsigned DllStorageClass : 2; // DLL storage class
|
unsigned DllStorageClass : 2; // DLL storage class
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Give subclasses access to what otherwise would be wasted padding.
|
||||||
|
// (22 + 2 + 1 + 2 + 5) == 32.
|
||||||
|
unsigned SubClassData : 22;
|
||||||
|
protected:
|
||||||
|
unsigned getGlobalValueSubClassData() const {
|
||||||
|
return SubClassData;
|
||||||
|
}
|
||||||
|
void setGlobalValueSubClassData(unsigned V) {
|
||||||
|
assert(V < (1 << 22) && "It will not fit");
|
||||||
|
SubClassData = V;
|
||||||
|
}
|
||||||
|
|
||||||
Module *Parent; // The containing module.
|
Module *Parent; // The containing module.
|
||||||
std::string Section; // Section to emit this into, empty mean default
|
|
||||||
public:
|
public:
|
||||||
~GlobalValue() {
|
~GlobalValue() {
|
||||||
removeDeadConstantUsers(); // remove any dead constants using this.
|
removeDeadConstantUsers(); // remove any dead constants using this.
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned getAlignment() const;
|
unsigned getAlignment() const;
|
||||||
void setAlignment(unsigned Align);
|
|
||||||
|
|
||||||
bool hasUnnamedAddr() const { return UnnamedAddr; }
|
bool hasUnnamedAddr() const { return UnnamedAddr; }
|
||||||
void setUnnamedAddr(bool Val) { UnnamedAddr = Val; }
|
void setUnnamedAddr(bool Val) { UnnamedAddr = Val; }
|
||||||
@ -112,7 +123,6 @@ public:
|
|||||||
|
|
||||||
bool hasSection() const { return !getSection().empty(); }
|
bool hasSection() const { return !getSection().empty(); }
|
||||||
const std::string &getSection() const;
|
const std::string &getSection() const;
|
||||||
void setSection(StringRef S);
|
|
||||||
|
|
||||||
/// Global values are always pointers.
|
/// Global values are always pointers.
|
||||||
inline PointerType *getType() const {
|
inline PointerType *getType() const {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/Twine.h"
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/ADT/ilist_node.h"
|
#include "llvm/ADT/ilist_node.h"
|
||||||
#include "llvm/IR/GlobalValue.h"
|
#include "llvm/IR/GlobalObject.h"
|
||||||
#include "llvm/IR/OperandTraits.h"
|
#include "llvm/IR/OperandTraits.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -32,7 +32,7 @@ class Constant;
|
|||||||
template<typename ValueSubClass, typename ItemParentClass>
|
template<typename ValueSubClass, typename ItemParentClass>
|
||||||
class SymbolTableListTraits;
|
class SymbolTableListTraits;
|
||||||
|
|
||||||
class GlobalVariable : public GlobalValue, public ilist_node<GlobalVariable> {
|
class GlobalVariable : public GlobalObject, public ilist_node<GlobalVariable> {
|
||||||
friend class SymbolTableListTraits<GlobalVariable, Module>;
|
friend class SymbolTableListTraits<GlobalVariable, Module>;
|
||||||
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
||||||
void operator=(const GlobalVariable &) LLVM_DELETED_FUNCTION;
|
void operator=(const GlobalVariable &) LLVM_DELETED_FUNCTION;
|
||||||
|
@ -31,6 +31,7 @@ class Constant;
|
|||||||
class DataLayout;
|
class DataLayout;
|
||||||
class Function;
|
class Function;
|
||||||
class GlobalAlias;
|
class GlobalAlias;
|
||||||
|
class GlobalObject;
|
||||||
class GlobalValue;
|
class GlobalValue;
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
class InlineAsm;
|
class InlineAsm;
|
||||||
@ -526,8 +527,13 @@ template <> struct isa_impl<GlobalAlias, Value> {
|
|||||||
|
|
||||||
template <> struct isa_impl<GlobalValue, Value> {
|
template <> struct isa_impl<GlobalValue, Value> {
|
||||||
static inline bool doit(const Value &Val) {
|
static inline bool doit(const Value &Val) {
|
||||||
return isa<GlobalVariable>(Val) || isa<Function>(Val) ||
|
return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
|
||||||
isa<GlobalAlias>(Val);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> struct isa_impl<GlobalObject, Value> {
|
||||||
|
static inline bool doit(const Value &Val) {
|
||||||
|
return isa<GlobalVariable>(Val) || isa<Function>(Val);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1458,7 +1458,7 @@ void AsmPrinter::EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset,
|
|||||||
// an explicit alignment requested, it will override the alignment request
|
// an explicit alignment requested, it will override the alignment request
|
||||||
// if required for correctness.
|
// if required for correctness.
|
||||||
//
|
//
|
||||||
void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
|
void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalObject *GV) const {
|
||||||
if (GV) NumBits = getGVAlignmentLog2(GV, *TM.getDataLayout(), NumBits);
|
if (GV) NumBits = getGVAlignmentLog2(GV, *TM.getDataLayout(), NumBits);
|
||||||
|
|
||||||
if (NumBits == 0) return; // 1-byte aligned: no need to emit alignment.
|
if (NumBits == 0) return; // 1-byte aligned: no need to emit alignment.
|
||||||
|
@ -1307,7 +1307,7 @@ const char *LLVMGetSection(LLVMValueRef Global) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LLVMSetSection(LLVMValueRef Global, const char *Section) {
|
void LLVMSetSection(LLVMValueRef Global, const char *Section) {
|
||||||
unwrap<GlobalValue>(Global)->setSection(Section);
|
unwrap<GlobalObject>(Global)->setSection(Section);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
|
LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
|
||||||
@ -1357,7 +1357,7 @@ unsigned LLVMGetAlignment(LLVMValueRef V) {
|
|||||||
|
|
||||||
void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
|
void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
|
||||||
Value *P = unwrap<Value>(V);
|
Value *P = unwrap<Value>(V);
|
||||||
if (GlobalValue *GV = dyn_cast<GlobalValue>(P))
|
if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
|
||||||
GV->setAlignment(Bytes);
|
GV->setAlignment(Bytes);
|
||||||
else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
|
else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
|
||||||
AI->setAlignment(Bytes);
|
AI->setAlignment(Bytes);
|
||||||
|
@ -209,7 +209,7 @@ void Function::eraseFromParent() {
|
|||||||
|
|
||||||
Function::Function(FunctionType *Ty, LinkageTypes Linkage,
|
Function::Function(FunctionType *Ty, LinkageTypes Linkage,
|
||||||
const Twine &name, Module *ParentModule)
|
const Twine &name, Module *ParentModule)
|
||||||
: GlobalValue(PointerType::getUnqual(Ty),
|
: GlobalObject(PointerType::getUnqual(Ty),
|
||||||
Value::FunctionVal, nullptr, 0, Linkage, name) {
|
Value::FunctionVal, nullptr, 0, Linkage, name) {
|
||||||
assert(FunctionType::isValidReturnType(getReturnType()) &&
|
assert(FunctionType::isValidReturnType(getReturnType()) &&
|
||||||
"invalid return type");
|
"invalid return type");
|
||||||
@ -361,7 +361,7 @@ void Function::clearGC() {
|
|||||||
/// create a Function) from the Function Src to this one.
|
/// create a Function) from the Function Src to this one.
|
||||||
void Function::copyAttributesFrom(const GlobalValue *Src) {
|
void Function::copyAttributesFrom(const GlobalValue *Src) {
|
||||||
assert(isa<Function>(Src) && "Expected a Function!");
|
assert(isa<Function>(Src) && "Expected a Function!");
|
||||||
GlobalValue::copyAttributesFrom(Src);
|
GlobalObject::copyAttributesFrom(Src);
|
||||||
const Function *SrcF = cast<Function>(Src);
|
const Function *SrcF = cast<Function>(Src);
|
||||||
setCallingConv(SrcF->getCallingConv());
|
setCallingConv(SrcF->getCallingConv());
|
||||||
setAttributes(SrcF->getAttributes());
|
setAttributes(SrcF->getAttributes());
|
||||||
|
@ -53,11 +53,6 @@ void GlobalValue::destroyConstant() {
|
|||||||
/// copyAttributesFrom - copy all additional attributes (those not needed to
|
/// copyAttributesFrom - copy all additional attributes (those not needed to
|
||||||
/// create a GlobalValue) from the GlobalValue Src to this one.
|
/// create a GlobalValue) from the GlobalValue Src to this one.
|
||||||
void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
|
void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
|
||||||
if (!isa<GlobalAlias>(this)) {
|
|
||||||
setAlignment(Src->getAlignment());
|
|
||||||
setSection(Src->getSection());
|
|
||||||
}
|
|
||||||
|
|
||||||
setVisibility(Src->getVisibility());
|
setVisibility(Src->getVisibility());
|
||||||
setUnnamedAddr(Src->hasUnnamedAddr());
|
setUnnamedAddr(Src->hasUnnamedAddr());
|
||||||
setDLLStorageClass(Src->getDLLStorageClass());
|
setDLLStorageClass(Src->getDLLStorageClass());
|
||||||
@ -67,29 +62,31 @@ unsigned GlobalValue::getAlignment() const {
|
|||||||
if (auto *GA = dyn_cast<GlobalAlias>(this))
|
if (auto *GA = dyn_cast<GlobalAlias>(this))
|
||||||
return GA->getAliasedGlobal()->getAlignment();
|
return GA->getAliasedGlobal()->getAlignment();
|
||||||
|
|
||||||
return (1u << Alignment) >> 1;
|
return cast<GlobalObject>(this)->getAlignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalValue::setAlignment(unsigned Align) {
|
void GlobalObject::setAlignment(unsigned Align) {
|
||||||
assert((!isa<GlobalAlias>(this)) &&
|
|
||||||
"GlobalAlias should not have an alignment!");
|
|
||||||
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
|
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
|
||||||
assert(Align <= MaximumAlignment &&
|
assert(Align <= MaximumAlignment &&
|
||||||
"Alignment is greater than MaximumAlignment!");
|
"Alignment is greater than MaximumAlignment!");
|
||||||
Alignment = Log2_32(Align) + 1;
|
setGlobalValueSubClassData(Log2_32(Align) + 1);
|
||||||
assert(getAlignment() == Align && "Alignment representation error!");
|
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 {
|
const std::string &GlobalValue::getSection() const {
|
||||||
if (auto *GA = dyn_cast<GlobalAlias>(this))
|
if (auto *GA = dyn_cast<GlobalAlias>(this))
|
||||||
return GA->getAliasedGlobal()->getSection();
|
return GA->getAliasedGlobal()->getSection();
|
||||||
return Section;
|
return cast<GlobalObject>(this)->getSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalValue::setSection(StringRef S) {
|
void GlobalObject::setSection(StringRef S) { Section = S; }
|
||||||
assert(!isa<GlobalAlias>(this) && "GlobalAlias should not have a section!");
|
|
||||||
Section = S;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GlobalValue::isDeclaration() const {
|
bool GlobalValue::isDeclaration() const {
|
||||||
// Globals are definitions if they have an initializer.
|
// 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,
|
Constant *InitVal, const Twine &Name,
|
||||||
ThreadLocalMode TLMode, unsigned AddressSpace,
|
ThreadLocalMode TLMode, unsigned AddressSpace,
|
||||||
bool isExternallyInitialized)
|
bool isExternallyInitialized)
|
||||||
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
|
: GlobalObject(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
|
||||||
OperandTraits<GlobalVariable>::op_begin(this),
|
OperandTraits<GlobalVariable>::op_begin(this),
|
||||||
InitVal != nullptr, Link, Name),
|
InitVal != nullptr, Link, Name),
|
||||||
isConstantGlobal(constant), threadLocalMode(TLMode),
|
isConstantGlobal(constant), threadLocalMode(TLMode),
|
||||||
isExternallyInitializedConstant(isExternallyInitialized) {
|
isExternallyInitializedConstant(isExternallyInitialized) {
|
||||||
if (InitVal) {
|
if (InitVal) {
|
||||||
@ -132,9 +129,9 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
|
|||||||
const Twine &Name, GlobalVariable *Before,
|
const Twine &Name, GlobalVariable *Before,
|
||||||
ThreadLocalMode TLMode, unsigned AddressSpace,
|
ThreadLocalMode TLMode, unsigned AddressSpace,
|
||||||
bool isExternallyInitialized)
|
bool isExternallyInitialized)
|
||||||
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
|
: GlobalObject(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
|
||||||
OperandTraits<GlobalVariable>::op_begin(this),
|
OperandTraits<GlobalVariable>::op_begin(this),
|
||||||
InitVal != nullptr, Link, Name),
|
InitVal != nullptr, Link, Name),
|
||||||
isConstantGlobal(constant), threadLocalMode(TLMode),
|
isConstantGlobal(constant), threadLocalMode(TLMode),
|
||||||
isExternallyInitializedConstant(isExternallyInitialized) {
|
isExternallyInitializedConstant(isExternallyInitialized) {
|
||||||
if (InitVal) {
|
if (InitVal) {
|
||||||
@ -206,7 +203,7 @@ void GlobalVariable::setInitializer(Constant *InitVal) {
|
|||||||
/// create a GlobalVariable) from the GlobalVariable Src to this one.
|
/// create a GlobalVariable) from the GlobalVariable Src to this one.
|
||||||
void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
|
void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
|
||||||
assert(isa<GlobalVariable>(Src) && "Expected a GlobalVariable!");
|
assert(isa<GlobalVariable>(Src) && "Expected a GlobalVariable!");
|
||||||
GlobalValue::copyAttributesFrom(Src);
|
GlobalObject::copyAttributesFrom(Src);
|
||||||
const GlobalVariable *SrcVar = cast<GlobalVariable>(Src);
|
const GlobalVariable *SrcVar = cast<GlobalVariable>(Src);
|
||||||
setThreadLocalMode(SrcVar->getThreadLocalMode());
|
setThreadLocalMode(SrcVar->getThreadLocalMode());
|
||||||
}
|
}
|
||||||
@ -269,7 +266,7 @@ static GlobalValue *getAliaseeGV(GlobalAlias *GA) {
|
|||||||
return cast<GlobalValue>(CE->getOperand(0));
|
return cast<GlobalValue>(CE->getOperand(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalValue *GlobalAlias::getAliasedGlobal() {
|
GlobalObject *GlobalAlias::getAliasedGlobal() {
|
||||||
SmallPtrSet<GlobalValue*, 3> Visited;
|
SmallPtrSet<GlobalValue*, 3> Visited;
|
||||||
|
|
||||||
GlobalAlias *GA = this;
|
GlobalAlias *GA = this;
|
||||||
@ -282,6 +279,6 @@ GlobalValue *GlobalAlias::getAliasedGlobal() {
|
|||||||
// Iterate over aliasing chain.
|
// Iterate over aliasing chain.
|
||||||
GA = dyn_cast<GlobalAlias>(GV);
|
GA = dyn_cast<GlobalAlias>(GV);
|
||||||
if (!GA)
|
if (!GA)
|
||||||
return GV;
|
return cast<GlobalObject>(GV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -495,15 +495,15 @@ static void forceRenaming(GlobalValue *GV, StringRef Name) {
|
|||||||
/// a GlobalValue) from the SrcGV to the DestGV.
|
/// a GlobalValue) from the SrcGV to the DestGV.
|
||||||
static void copyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
|
static void copyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
|
||||||
// Use the maximum alignment, rather than just copying the alignment of SrcGV.
|
// Use the maximum alignment, rather than just copying the alignment of SrcGV.
|
||||||
|
auto *DestGO = dyn_cast<GlobalObject>(DestGV);
|
||||||
unsigned Alignment;
|
unsigned Alignment;
|
||||||
bool IsAlias = isa<GlobalAlias>(DestGV);
|
if (DestGO)
|
||||||
if (!IsAlias)
|
Alignment = std::max(DestGO->getAlignment(), SrcGV->getAlignment());
|
||||||
Alignment = std::max(DestGV->getAlignment(), SrcGV->getAlignment());
|
|
||||||
|
|
||||||
DestGV->copyAttributesFrom(SrcGV);
|
DestGV->copyAttributesFrom(SrcGV);
|
||||||
|
|
||||||
if (!IsAlias)
|
if (DestGO)
|
||||||
DestGV->setAlignment(Alignment);
|
DestGO->setAlignment(Alignment);
|
||||||
|
|
||||||
forceRenaming(DestGV, SrcGV->getName());
|
forceRenaming(DestGV, SrcGV->getName());
|
||||||
}
|
}
|
||||||
|
@ -896,26 +896,26 @@ static unsigned enforceKnownAlignment(Value *V, unsigned Align,
|
|||||||
return PrefAlign;
|
return PrefAlign;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto *GV = dyn_cast<GlobalValue>(V)) {
|
if (auto *GO = dyn_cast<GlobalObject>(V)) {
|
||||||
// If there is a large requested alignment and we can, bump up the alignment
|
// If there is a large requested alignment and we can, bump up the alignment
|
||||||
// of the global.
|
// of the global.
|
||||||
if (GV->isDeclaration())
|
if (GO->isDeclaration())
|
||||||
return Align;
|
return Align;
|
||||||
// If the memory we set aside for the global may not be the memory used by
|
// If the memory we set aside for the global may not be the memory used by
|
||||||
// the final program then it is impossible for us to reliably enforce the
|
// the final program then it is impossible for us to reliably enforce the
|
||||||
// preferred alignment.
|
// preferred alignment.
|
||||||
if (GV->isWeakForLinker())
|
if (GO->isWeakForLinker())
|
||||||
return Align;
|
return Align;
|
||||||
|
|
||||||
if (GV->getAlignment() >= PrefAlign)
|
if (GO->getAlignment() >= PrefAlign)
|
||||||
return GV->getAlignment();
|
return GO->getAlignment();
|
||||||
// We can only increase the alignment of the global if it has no alignment
|
// We can only increase the alignment of the global if it has no alignment
|
||||||
// specified or if it is not assigned a section. If it is assigned a
|
// specified or if it is not assigned a section. If it is assigned a
|
||||||
// section, the global could be densely packed with other objects in the
|
// section, the global could be densely packed with other objects in the
|
||||||
// section, increasing the alignment could cause padding issues.
|
// section, increasing the alignment could cause padding issues.
|
||||||
if (!GV->hasSection() || GV->getAlignment() == 0)
|
if (!GO->hasSection() || GO->getAlignment() == 0)
|
||||||
GV->setAlignment(PrefAlign);
|
GO->setAlignment(PrefAlign);
|
||||||
return GV->getAlignment();
|
return GO->getAlignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Align;
|
return Align;
|
||||||
|
Reference in New Issue
Block a user