diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /lib/CodeGen/GlobalMerge.cpp | |
parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) |
Notes
Diffstat (limited to 'lib/CodeGen/GlobalMerge.cpp')
-rw-r--r-- | lib/CodeGen/GlobalMerge.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/CodeGen/GlobalMerge.cpp b/lib/CodeGen/GlobalMerge.cpp index 9f7f5e392a9a..d3364952f244 100644 --- a/lib/CodeGen/GlobalMerge.cpp +++ b/lib/CodeGen/GlobalMerge.cpp @@ -461,6 +461,8 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, unsigned CurIdx = 0; for (j = i; j != -1; j = GlobalSet.find_next(j)) { Type *Ty = Globals[j]->getValueType(); + + // Make sure we use the same alignment AsmPrinter would use. unsigned Align = DL.getPreferredAlignment(Globals[j]); unsigned Padding = alignTo(MergedSize, Align) - MergedSize; MergedSize += Padding; @@ -516,6 +518,7 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, GlobalVariable::NotThreadLocal, AddrSpace); MergedGV->setAlignment(MaxAlign); + MergedGV->setSection(Globals[i]->getSection()); const StructLayout *MergedLayout = DL.getStructLayout(MergedTy); for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k), ++idx) { @@ -599,16 +602,15 @@ bool GlobalMerge::doInitialization(Module &M) { IsMachO = Triple(M.getTargetTriple()).isOSBinFormatMachO(); auto &DL = M.getDataLayout(); - DenseMap<unsigned, SmallVector<GlobalVariable *, 16>> Globals, ConstGlobals, - BSSGlobals; + DenseMap<std::pair<unsigned, StringRef>, SmallVector<GlobalVariable *, 16>> + Globals, ConstGlobals, BSSGlobals; bool Changed = false; setMustKeepGlobalVariables(M); // Grab all non-const globals. for (auto &GV : M.globals()) { // Merge is safe for "normal" internal or external globals only - if (GV.isDeclaration() || GV.isThreadLocal() || - GV.hasSection() || GV.hasImplicitSection()) + if (GV.isDeclaration() || GV.isThreadLocal() || GV.hasImplicitSection()) continue; // It's not safe to merge globals that may be preempted @@ -623,6 +625,7 @@ bool GlobalMerge::doInitialization(Module &M) { assert(PT && "Global variable is not a pointer!"); unsigned AddressSpace = PT->getAddressSpace(); + StringRef Section = GV.getSection(); // Ignore all 'special' globals. if (GV.getName().startswith("llvm.") || @@ -636,27 +639,27 @@ bool GlobalMerge::doInitialization(Module &M) { Type *Ty = GV.getValueType(); if (DL.getTypeAllocSize(Ty) < MaxOffset) { if (TM && - TargetLoweringObjectFile::getKindForGlobal(&GV, *TM).isBSSLocal()) - BSSGlobals[AddressSpace].push_back(&GV); + TargetLoweringObjectFile::getKindForGlobal(&GV, *TM).isBSS()) + BSSGlobals[{AddressSpace, Section}].push_back(&GV); else if (GV.isConstant()) - ConstGlobals[AddressSpace].push_back(&GV); + ConstGlobals[{AddressSpace, Section}].push_back(&GV); else - Globals[AddressSpace].push_back(&GV); + Globals[{AddressSpace, Section}].push_back(&GV); } } for (auto &P : Globals) if (P.second.size() > 1) - Changed |= doMerge(P.second, M, false, P.first); + Changed |= doMerge(P.second, M, false, P.first.first); for (auto &P : BSSGlobals) if (P.second.size() > 1) - Changed |= doMerge(P.second, M, false, P.first); + Changed |= doMerge(P.second, M, false, P.first.first); if (EnableGlobalMergeOnConst) for (auto &P : ConstGlobals) if (P.second.size() > 1) - Changed |= doMerge(P.second, M, true, P.first); + Changed |= doMerge(P.second, M, true, P.first.first); return Changed; } |