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:
Richard Smith
2014-05-06 01:01:29 +00:00
parent 9331beb910
commit 245e8bdfba
7 changed files with 153 additions and 46 deletions

View File

@@ -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) {