mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
Address comments from Frits van Bommel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127974 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -2706,9 +2706,10 @@ static Function *FindCXAAtExit(Module &M) {
|
|||||||
|
|
||||||
const FunctionType *FTy = Fn->getFunctionType();
|
const FunctionType *FTy = Fn->getFunctionType();
|
||||||
|
|
||||||
// Checking that the function has the right number of parameters and that they
|
// Checking that the function has the right return type, the right number of
|
||||||
// all have pointer types should be enough.
|
// parameters and that they all have pointer types should be enough.
|
||||||
if (FTy->getNumParams() != 3 ||
|
if (!FTy->getReturnType()->isIntegerTy() ||
|
||||||
|
FTy->getNumParams() != 3 ||
|
||||||
!FTy->getParamType(0)->isPointerTy() ||
|
!FTy->getParamType(0)->isPointerTy() ||
|
||||||
!FTy->getParamType(1)->isPointerTy() ||
|
!FTy->getParamType(1)->isPointerTy() ||
|
||||||
!FTy->getParamType(2)->isPointerTy())
|
!FTy->getParamType(2)->isPointerTy())
|
||||||
@ -2723,8 +2724,10 @@ static Function *FindCXAAtExit(Module &M) {
|
|||||||
/// the code so we only look for a function with a single basic block, where
|
/// the code so we only look for a function with a single basic block, where
|
||||||
/// the only allowed instructions are 'ret' or 'call' to empty C++ dtor.
|
/// the only allowed instructions are 'ret' or 'call' to empty C++ dtor.
|
||||||
static bool cxxDtorIsEmpty(const Function& Fn) {
|
static bool cxxDtorIsEmpty(const Function& Fn) {
|
||||||
if (Fn.empty())
|
// FIXME: We could eliminate C++ destructors if they're readonly/readnone and
|
||||||
return true;
|
// unwind, but that doesn't seem worth doing.
|
||||||
|
if (Fn.isDeclaration())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (++Fn.begin() != Fn.end())
|
if (++Fn.begin() != Fn.end())
|
||||||
return false;
|
return false;
|
||||||
@ -2738,6 +2741,10 @@ static bool cxxDtorIsEmpty(const Function& Fn) {
|
|||||||
if (!CalledFn)
|
if (!CalledFn)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Don't treat recursive functions as empty.
|
||||||
|
if (CalledFn == &Fn)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!cxxDtorIsEmpty(*CalledFn))
|
if (!cxxDtorIsEmpty(*CalledFn))
|
||||||
return false;
|
return false;
|
||||||
} else if (isa<ReturnInst>(*I))
|
} else if (isa<ReturnInst>(*I))
|
||||||
@ -2769,7 +2776,7 @@ bool GlobalOpt::OptimizeEmptyGlobalCXXDtors(Function *CXAAtExitFn) {
|
|||||||
for (Function::use_iterator I = CXAAtExitFn->use_begin(),
|
for (Function::use_iterator I = CXAAtExitFn->use_begin(),
|
||||||
E = CXAAtExitFn->use_end(); I != E;) {
|
E = CXAAtExitFn->use_end(); I != E;) {
|
||||||
CallSite CS(*I++);
|
CallSite CS(*I++);
|
||||||
if (!CS.getInstruction())
|
if (!CS)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Function *DtorFn =
|
Function *DtorFn =
|
||||||
@ -2781,7 +2788,9 @@ bool GlobalOpt::OptimizeEmptyGlobalCXXDtors(Function *CXAAtExitFn) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Just remove the call.
|
// Just remove the call.
|
||||||
CS.getInstruction()->eraseFromParent();
|
CS->replaceAllUsesWith(Constant::getNullValue(CS.getType()));
|
||||||
|
CS->eraseFromParent();
|
||||||
|
|
||||||
++NumCXXDtorsRemoved;
|
++NumCXXDtorsRemoved;
|
||||||
|
|
||||||
Changed |= true;
|
Changed |= true;
|
||||||
|
Reference in New Issue
Block a user