summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-05-16 13:02:18 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-05-16 13:02:18 +0000
commit5a52b9f139c5bd36aa8abdd02446f2a4947f7873 (patch)
tree38628b7a5b9fc4433fe89498dd8481ebb4b18f49 /llvm/lib/Transforms
parent5a8c1e29007b98f26437a110020e7f27a3a5ac6c (diff)
downloadbcm5719-llvm-5a52b9f139c5bd36aa8abdd02446f2a4947f7873.tar.gz
bcm5719-llvm-5a52b9f139c5bd36aa8abdd02446f2a4947f7873.zip
Revert "Implement global merge optimization for global variables."
This reverts commit r208934. The patch depends on aliases to GEPs with non zero offsets. That is not supported and fairly broken. The good news is that GlobalAlias is being redesigned and will have support for offsets, so this patch should be a nice match for it. llvm-svn: 208978
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/GlobalMerge.cpp85
-rw-r--r--llvm/lib/Transforms/Scalar/Scalar.cpp1
2 files changed, 10 insertions, 76 deletions
diff --git a/llvm/lib/Transforms/Scalar/GlobalMerge.cpp b/llvm/lib/Transforms/Scalar/GlobalMerge.cpp
index 98061f5b9a8..dd9c3784cc2 100644
--- a/llvm/lib/Transforms/Scalar/GlobalMerge.cpp
+++ b/llvm/lib/Transforms/Scalar/GlobalMerge.cpp
@@ -72,7 +72,7 @@ using namespace llvm;
#define DEBUG_TYPE "global-merge"
static cl::opt<bool>
-EnableGlobalMerge("enable-global-merge", cl::NotHidden,
+EnableGlobalMerge("global-merge", cl::Hidden,
cl::desc("Enable global merge pass"),
cl::init(true));
@@ -81,16 +81,6 @@ EnableGlobalMergeOnConst("global-merge-on-const", cl::Hidden,
cl::desc("Enable global merge pass on constants"),
cl::init(false));
-static cl::opt<bool>
-EnableGlobalMergeOnExternal("global-merge-on-external", cl::Hidden,
- cl::desc("Enable global merge pass on external linkage"),
- cl::init(false));
-
-static cl::opt<bool>
-EnableGlobalMergeAligned("global-merge-aligned", cl::Hidden,
- cl::desc("Set target specific alignment for global merge pass"),
- cl::init(false));
-
STATISTIC(NumMerged , "Number of globals merged");
namespace {
class GlobalMerge : public FunctionPass {
@@ -139,21 +129,9 @@ namespace {
} // end anonymous namespace
char GlobalMerge::ID = 0;
+INITIALIZE_PASS(GlobalMerge, "global-merge",
+ "Global Merge", false, false)
-static void *initializeGlobalMergePassOnce(PassRegistry &Registry) {
- PassInfo *PI = new PassInfo(
- "Merge global variables",
- "global-merge", &GlobalMerge::ID,
- PassInfo::NormalCtor_t(callDefaultCtor<GlobalMerge>), false,
- false, PassInfo::TargetMachineCtor_t(
- callTargetMachineCtor<GlobalMerge>));
- Registry.registerPass(*PI, true);
- return PI;
-}
-
-void llvm::initializeGlobalMergePass(PassRegistry &Registry) {
- CALL_ONCE_INITIALIZATION(initializeGlobalMergePassOnce)
-}
bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
Module &M, bool isConst, unsigned AddrSpace) const {
@@ -176,16 +154,11 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
Type *Int32Ty = Type::getInt32Ty(M.getContext());
- assert (Globals.size() > 1);
-
for (size_t i = 0, e = Globals.size(); i != e; ) {
size_t j = 0;
uint64_t MergedSize = 0;
std::vector<Type*> Tys;
std::vector<Constant*> Inits;
-
- bool HasExternal = false;
- GlobalVariable *TheFirstExternal = 0;
for (j = i; j != e; ++j) {
Type *Ty = Globals[j]->getType()->getElementType();
MergedSize += DL->getTypeAllocSize(Ty);
@@ -194,45 +167,17 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
}
Tys.push_back(Ty);
Inits.push_back(Globals[j]->getInitializer());
-
- if (Globals[j]->hasExternalLinkage() && !HasExternal) {
- HasExternal = true;
- TheFirstExternal = Globals[j];
- }
}
- // If merged variables doesn't have external linkage, we needn't to expose
- // the symbol after merging.
- GlobalValue::LinkageTypes Linkage = HasExternal ?
- GlobalValue::ExternalLinkage :
- GlobalValue::InternalLinkage ;
-
- // If merged variables have external linkage, we use symbol name of the
- // first variable merged as the suffix of global symbol name. This would
- // be able to avoid the link-time naming conflict for globalm symbols.
- Twine MergedGVName = HasExternal ?
- "_MergedGlobals_" + TheFirstExternal->getName() :
- "_MergedGlobals" ;
-
StructType *MergedTy = StructType::get(M.getContext(), Tys);
Constant *MergedInit = ConstantStruct::get(MergedTy, Inits);
-
GlobalVariable *MergedGV = new GlobalVariable(M, MergedTy, isConst,
- Linkage, MergedInit, MergedGVName,
- nullptr, GlobalVariable::NotThreadLocal,
- AddrSpace);
-
- if (EnableGlobalMergeAligned) {
- unsigned Align = TLI->getGlobalMergeAlignment(MergedTy);
- assert(((Align % DL->getABITypeAlignment(MergedTy)) == 0) &&
- "Specified alignment doesn't meet natural alignment requirement.");
- MergedGV->setAlignment(Align);
- }
-
+ GlobalValue::InternalLinkage,
+ MergedInit, "_MergedGlobals",
+ nullptr,
+ GlobalVariable::NotThreadLocal,
+ AddrSpace);
for (size_t k = i; k < j; ++k) {
- GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
- std::string Name = Globals[k]->getName();
-
Constant *Idx[2] = {
ConstantInt::get(Int32Ty, 0),
ConstantInt::get(Int32Ty, k-i)
@@ -240,12 +185,6 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
Constant *GEP = ConstantExpr::getInBoundsGetElementPtr(MergedGV, Idx);
Globals[k]->replaceAllUsesWith(GEP);
Globals[k]->eraseFromParent();
-
- if (Linkage != GlobalValue::InternalLinkage) {
- // Generate a new alias...
- new GlobalAlias(GEP->getType(), Linkage, Name, GEP, &M);
- }
-
NumMerged++;
}
i = j;
@@ -306,12 +245,8 @@ bool GlobalMerge::doInitialization(Module &M) {
// Grab all non-const globals.
for (Module::global_iterator I = M.global_begin(),
E = M.global_end(); I != E; ++I) {
- // Merge is safe for "normal" internal or external globals only
- if (I->isDeclaration() || I->isThreadLocal() || I->hasSection())
- continue;
-
- if (!(EnableGlobalMergeOnExternal && I->hasExternalLinkage())
- && !I->hasInternalLinkage())
+ // Merge is safe for "normal" internal globals only
+ if (!I->hasLocalLinkage() || I->isThreadLocal() || I->hasSection())
continue;
PointerType *PT = dyn_cast<PointerType>(I->getType());
diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp
index 2cca7254806..f8f828c8405 100644
--- a/llvm/lib/Transforms/Scalar/Scalar.cpp
+++ b/llvm/lib/Transforms/Scalar/Scalar.cpp
@@ -38,7 +38,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
initializeDSEPass(Registry);
initializeGVNPass(Registry);
initializeEarlyCSEPass(Registry);
- initializeGlobalMergePass(Registry);
initializeIndVarSimplifyPass(Registry);
initializeJumpThreadingPass(Registry);
initializeLICMPass(Registry);
OpenPOWER on IntegriCloud