mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 07:24:25 +00:00
IR: Add COMDATs to the IR
This new IR facility allows us to represent the object-file semantic of a COMDAT group. COMDATs allow us to tie together sections and make the inclusion of one dependent on another. This is required to implement features like MS ABI VFTables and optimizing away certain kinds of initialization in C++. This functionality is only representable in COFF and ELF, Mach-O has no similar mechanism. Differential Revision: http://reviews.llvm.org/D4178 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211920 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -77,13 +77,19 @@ bool GlobalDCE::runOnModule(Module &M) {
|
||||
// Remove empty functions from the global ctors list.
|
||||
Changed |= optimizeGlobalCtorsList(M, isEmptyFunction);
|
||||
|
||||
typedef std::multimap<const Comdat *, GlobalValue *> ComdatGVPairsTy;
|
||||
ComdatGVPairsTy ComdatGVPairs;
|
||||
|
||||
// Loop over the module, adding globals which are obviously necessary.
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
||||
Changed |= RemoveUnusedGlobalValue(*I);
|
||||
// Functions with external linkage are needed if they have a body
|
||||
if (!I->isDiscardableIfUnused() &&
|
||||
!I->isDeclaration() && !I->hasAvailableExternallyLinkage())
|
||||
GlobalIsNeeded(I);
|
||||
if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) {
|
||||
if (!I->isDiscardableIfUnused())
|
||||
GlobalIsNeeded(I);
|
||||
else if (const Comdat *C = I->getComdat())
|
||||
ComdatGVPairs.insert(std::make_pair(C, I));
|
||||
}
|
||||
}
|
||||
|
||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||
@ -91,17 +97,38 @@ bool GlobalDCE::runOnModule(Module &M) {
|
||||
Changed |= RemoveUnusedGlobalValue(*I);
|
||||
// Externally visible & appending globals are needed, if they have an
|
||||
// initializer.
|
||||
if (!I->isDiscardableIfUnused() &&
|
||||
!I->isDeclaration() && !I->hasAvailableExternallyLinkage())
|
||||
GlobalIsNeeded(I);
|
||||
if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) {
|
||||
if (!I->isDiscardableIfUnused())
|
||||
GlobalIsNeeded(I);
|
||||
else if (const Comdat *C = I->getComdat())
|
||||
ComdatGVPairs.insert(std::make_pair(C, I));
|
||||
}
|
||||
}
|
||||
|
||||
for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
|
||||
I != E; ++I) {
|
||||
Changed |= RemoveUnusedGlobalValue(*I);
|
||||
// Externally visible aliases are needed.
|
||||
if (!I->isDiscardableIfUnused())
|
||||
if (!I->isDiscardableIfUnused()) {
|
||||
GlobalIsNeeded(I);
|
||||
} else if (const Comdat *C = I->getComdat()) {
|
||||
ComdatGVPairs.insert(std::make_pair(C, I));
|
||||
}
|
||||
}
|
||||
|
||||
for (ComdatGVPairsTy::iterator I = ComdatGVPairs.begin(),
|
||||
E = ComdatGVPairs.end();
|
||||
I != E;) {
|
||||
ComdatGVPairsTy::iterator UB = ComdatGVPairs.upper_bound(I->first);
|
||||
bool CanDiscard = std::all_of(I, UB, [](ComdatGVPairsTy::value_type Pair) {
|
||||
return Pair.second->isDiscardableIfUnused();
|
||||
});
|
||||
if (!CanDiscard) {
|
||||
std::for_each(I, UB, [this](ComdatGVPairsTy::value_type Pair) {
|
||||
GlobalIsNeeded(Pair.second);
|
||||
});
|
||||
}
|
||||
I = UB;
|
||||
}
|
||||
|
||||
// Now that all globals which are needed are in the AliveGlobals set, we loop
|
||||
|
Reference in New Issue
Block a user