mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
Add llvm::function_ref (and a couple of uses of it), representing a type-erased reference to a callable object.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208025 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -54,16 +54,16 @@ namespace {
|
||||
|
||||
bool RemoveUnusedGlobalValue(GlobalValue &GV);
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns true if F contains only a single "ret" instruction.
|
||||
bool isEmptyFunction(void *Context, Function *F) {
|
||||
static bool isEmptyFunction(Function *F) {
|
||||
BasicBlock &Entry = F->getEntryBlock();
|
||||
if (Entry.size() != 1 || !isa<ReturnInst>(Entry.front()))
|
||||
return false;
|
||||
ReturnInst &RI = cast<ReturnInst>(Entry.front());
|
||||
return RI.getReturnValue() == NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char GlobalDCE::ID = 0;
|
||||
INITIALIZE_PASS(GlobalDCE, "globaldce",
|
||||
@@ -75,7 +75,7 @@ bool GlobalDCE::runOnModule(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
// Remove empty functions from the global ctors list.
|
||||
Changed |= optimizeGlobalCtorsList(M, isEmptyFunction, nullptr);
|
||||
Changed |= optimizeGlobalCtorsList(M, isEmptyFunction);
|
||||
|
||||
// Loop over the module, adding globals which are obviously necessary.
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
||||
|
@@ -3022,10 +3022,9 @@ bool GlobalOpt::runOnModule(Module &M) {
|
||||
LocalChange |= OptimizeFunctions(M);
|
||||
|
||||
// Optimize global_ctors list.
|
||||
LocalChange |= optimizeGlobalCtorsList(M, [](void *C, Function *F) -> bool {
|
||||
GlobalOpt *self = static_cast<GlobalOpt *>(C);
|
||||
return EvaluateStaticConstructor(F, self->DL, self->TLI);
|
||||
}, this);
|
||||
LocalChange |= optimizeGlobalCtorsList(M, [&](Function *F) {
|
||||
return EvaluateStaticConstructor(F, DL, TLI);
|
||||
});
|
||||
|
||||
// Optimize non-address-taken globals.
|
||||
LocalChange |= OptimizeGlobalVars(M);
|
||||
|
@@ -132,8 +132,8 @@ GlobalVariable *findGlobalCtors(Module &M) {
|
||||
|
||||
/// Call "ShouldRemove" for every entry in M's global_ctor list and remove the
|
||||
/// entries for which it returns true. Return true if anything changed.
|
||||
bool optimizeGlobalCtorsList(Module &M, ShouldRemoveCtor ShouldRemove,
|
||||
void *Context) {
|
||||
bool optimizeGlobalCtorsList(Module &M,
|
||||
function_ref<bool(Function *)> ShouldRemove) {
|
||||
GlobalVariable *GlobalCtors = findGlobalCtors(M);
|
||||
if (!GlobalCtors)
|
||||
return false;
|
||||
@@ -163,7 +163,7 @@ bool optimizeGlobalCtorsList(Module &M, ShouldRemoveCtor ShouldRemove,
|
||||
continue;
|
||||
|
||||
// If we can evaluate the ctor at compile time, do.
|
||||
if (ShouldRemove(Context, F)) {
|
||||
if (ShouldRemove(F)) {
|
||||
Ctors.erase(Ctors.begin() + i);
|
||||
MadeChange = true;
|
||||
--i;
|
||||
|
Reference in New Issue
Block a user