mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[ConstantMerge] Factor out check for un-mergeable globals, NFC
llvm-svn: 351671
This commit is contained in:
parent
fbb246b9e8
commit
1e2c4114d8
@ -90,6 +90,16 @@ static unsigned getAlignment(GlobalVariable *GV) {
|
|||||||
return GV->getParent()->getDataLayout().getPreferredAlignment(GV);
|
return GV->getParent()->getDataLayout().getPreferredAlignment(GV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
isUnmergeableGlobal(GlobalVariable *GV,
|
||||||
|
const SmallPtrSetImpl<const GlobalValue *> &UsedGlobals) {
|
||||||
|
// Only process constants with initializers in the default address space.
|
||||||
|
return !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
|
||||||
|
GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
|
||||||
|
// Don't touch values marked with attribute(used).
|
||||||
|
UsedGlobals.count(GV);
|
||||||
|
}
|
||||||
|
|
||||||
enum class CanMerge { No, Yes };
|
enum class CanMerge { No, Yes };
|
||||||
static CanMerge makeMergeable(GlobalVariable *Old, GlobalVariable *New) {
|
static CanMerge makeMergeable(GlobalVariable *Old, GlobalVariable *New) {
|
||||||
if (!Old->hasGlobalUnnamedAddr() && !New->hasGlobalUnnamedAddr())
|
if (!Old->hasGlobalUnnamedAddr() && !New->hasGlobalUnnamedAddr())
|
||||||
@ -154,11 +164,7 @@ static bool mergeConstants(Module &M) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only process constants with initializers in the default address space.
|
if (isUnmergeableGlobal(GV, UsedGlobals))
|
||||||
if (!GV->isConstant() || !GV->hasDefinitiveInitializer() ||
|
|
||||||
GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
|
|
||||||
// Don't touch values marked with attribute(used).
|
|
||||||
UsedGlobals.count(GV))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// This transformation is legal for weak ODR globals in the sense it
|
// This transformation is legal for weak ODR globals in the sense it
|
||||||
@ -196,11 +202,7 @@ static bool mergeConstants(Module &M) {
|
|||||||
GVI != E; ) {
|
GVI != E; ) {
|
||||||
GlobalVariable *GV = &*GVI++;
|
GlobalVariable *GV = &*GVI++;
|
||||||
|
|
||||||
// Only process constants with initializers in the default address space.
|
if (isUnmergeableGlobal(GV, UsedGlobals))
|
||||||
if (!GV->isConstant() || !GV->hasDefinitiveInitializer() ||
|
|
||||||
GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
|
|
||||||
// Don't touch values marked with attribute(used).
|
|
||||||
UsedGlobals.count(GV))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// We can only replace constant with local linkage.
|
// We can only replace constant with local linkage.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user