Lines Matching refs:F
122 bool DeadArgumentEliminationPass::deleteDeadVarargs(Function &F) { in deleteDeadVarargs() argument
123 assert(F.getFunctionType()->isVarArg() && "Function isn't varargs!"); in deleteDeadVarargs()
124 if (F.isDeclaration() || !F.hasLocalLinkage()) in deleteDeadVarargs()
128 if (F.hasAddressTaken()) in deleteDeadVarargs()
134 if (F.hasFnAttribute(Attribute::Naked)) { in deleteDeadVarargs()
140 for (BasicBlock &BB : F) { in deleteDeadVarargs()
159 FunctionType *FTy = F.getFunctionType(); in deleteDeadVarargs()
166 Function *NF = Function::Create(NFTy, F.getLinkage(), F.getAddressSpace()); in deleteDeadVarargs()
167 NF->copyAttributesFrom(&F); in deleteDeadVarargs()
168 NF->setComdat(F.getComdat()); in deleteDeadVarargs()
169 F.getParent()->getFunctionList().insert(F.getIterator(), NF); in deleteDeadVarargs()
170 NF->takeName(&F); in deleteDeadVarargs()
176 for (User *U : llvm::make_early_inc_range(F.users())) { in deleteDeadVarargs()
190 PAL = AttributeList::get(F.getContext(), PAL.getFnAttrs(), in deleteDeadVarargs()
225 NF->getBasicBlockList().splice(NF->begin(), F.getBasicBlockList()); in deleteDeadVarargs()
230 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(), in deleteDeadVarargs()
240 F.getAllMetadata(MDs); in deleteDeadVarargs()
245 F.replaceAllUsesWith(ConstantExpr::getBitCast(NF, F.getType())); in deleteDeadVarargs()
250 F.eraseFromParent(); in deleteDeadVarargs()
256 bool DeadArgumentEliminationPass::removeDeadArgumentsFromCallers(Function &F) { in removeDeadArgumentsFromCallers() argument
268 if (!F.hasExactDefinition()) in removeDeadArgumentsFromCallers()
275 if ((F.hasLocalLinkage() && !LiveFunctions.count(&F)) && in removeDeadArgumentsFromCallers()
276 !F.getFunctionType()->isVarArg()) in removeDeadArgumentsFromCallers()
282 if (F.hasFnAttribute(Attribute::Naked)) in removeDeadArgumentsFromCallers()
285 if (F.use_empty()) in removeDeadArgumentsFromCallers()
293 for (Argument &Arg : F.args()) { in removeDeadArgumentsFromCallers()
301 F.removeParamAttrs(Arg.getArgNo(), UBImplyingAttributes); in removeDeadArgumentsFromCallers()
308 for (Use &U : F.uses()) { in removeDeadArgumentsFromCallers()
311 CB->getFunctionType() != F.getFunctionType()) in removeDeadArgumentsFromCallers()
333 static unsigned numRetVals(const Function *F) { in numRetVals() argument
334 Type *RetTy = F->getReturnType(); in numRetVals()
347 static Type *getRetComponentType(const Function *F, unsigned Idx) { in getRetComponentType() argument
348 Type *RetTy = F->getReturnType(); in getRetComponentType()
389 const Function *F = RI->getParent()->getParent(); in surveyUse() local
391 RetOrArg Use = createRet(F, RetValNum); in surveyUse()
397 for (unsigned Ri = 0; Ri < numRetVals(F); ++Ri) { in surveyUse()
398 RetOrArg Use = createRet(F, Ri); in surveyUse()
431 const Function *F = CB->getCalledFunction(); in surveyUse() local
432 if (F) { in surveyUse()
445 if (ArgNo >= F->getFunctionType()->getNumParams()) in surveyUse()
454 RetOrArg Use = createArg(F, ArgNo); in surveyUse()
488 void DeadArgumentEliminationPass::surveyFunction(const Function &F) { in surveyFunction() argument
491 if (F.getAttributes().hasAttrSomewhere(Attribute::InAlloca) || in surveyFunction()
492 F.getAttributes().hasAttrSomewhere(Attribute::Preallocated)) { in surveyFunction()
493 markLive(F); in surveyFunction()
500 if (F.hasFnAttribute(Attribute::Naked)) { in surveyFunction()
501 markLive(F); in surveyFunction()
505 unsigned RetCount = numRetVals(&F); in surveyFunction()
520 for (const BasicBlock &BB : F) { in surveyFunction()
528 LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName() in surveyFunction()
532 if (!F.hasLocalLinkage() && (!ShouldHackArguments || F.isIntrinsic())) { in surveyFunction()
533 markLive(F); in surveyFunction()
539 << F.getName() << "\n"); in surveyFunction()
547 for (const Use &U : F.uses()) { in surveyFunction()
552 CB->getFunctionType() != F.getFunctionType()) { in surveyFunction()
553 markLive(F); in surveyFunction()
600 LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName() in surveyFunction()
606 markValue(createRet(&F, Ri), RetValLiveness[Ri], MaybeLiveRetUses[Ri]); in surveyFunction()
609 << F.getName() << "\n"); in surveyFunction()
614 for (Function::const_arg_iterator AI = F.arg_begin(), E = F.arg_end(); in surveyFunction()
617 if (F.getFunctionType()->isVarArg() || HasMustTailCallers || in surveyFunction()
638 markValue(createArg(&F, ArgI), Result, MaybeLiveArgUses); in surveyFunction()
672 void DeadArgumentEliminationPass::markLive(const Function &F) { in markLive() argument
674 << F.getName() << "\n"); in markLive()
676 LiveFunctions.insert(&F); in markLive()
678 for (unsigned ArgI = 0, E = F.arg_size(); ArgI != E; ++ArgI) in markLive()
679 propagateLiveness(createArg(&F, ArgI)); in markLive()
681 for (unsigned Ri = 0, E = numRetVals(&F); Ri != E; ++Ri) in markLive()
682 propagateLiveness(createRet(&F, Ri)); in markLive()
699 return LiveFunctions.count(RA.F) || LiveValues.count(RA); in isLive()
722 bool DeadArgumentEliminationPass::removeDeadStuffFromFunction(Function *F) { in removeDeadStuffFromFunction() argument
724 if (LiveFunctions.count(F)) in removeDeadStuffFromFunction()
729 FunctionType *FTy = F->getFunctionType(); in removeDeadStuffFromFunction()
737 const AttributeList &PAL = F->getAttributes(); in removeDeadStuffFromFunction()
745 for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; in removeDeadStuffFromFunction()
747 RetOrArg Arg = createArg(F, ArgI); in removeDeadStuffFromFunction()
757 << F->getName() << "\n"); in removeDeadStuffFromFunction()
764 unsigned RetCount = numRetVals(F); in removeDeadStuffFromFunction()
794 RetOrArg Ret = createRet(F, Ri); in removeDeadStuffFromFunction()
796 RetTypes.push_back(getRetComponentType(F, Ri)); in removeDeadStuffFromFunction()
802 << Ri << " from " << F->getName() << "\n"); in removeDeadStuffFromFunction()
821 NRetTy = Type::getVoidTy(F->getContext()); in removeDeadStuffFromFunction()
827 AttrBuilder RAttrs(F->getContext(), PAL.getRetAttrs()); in removeDeadStuffFromFunction()
839 AttributeSet RetAttrs = AttributeSet::get(F->getContext(), RAttrs); in removeDeadStuffFromFunction()
843 PAL.getFnAttrs().removeAttribute(F->getContext(), Attribute::AllocSize); in removeDeadStuffFromFunction()
848 AttributeList::get(F->getContext(), FnAttrs, RetAttrs, ArgAttrVec); in removeDeadStuffFromFunction()
858 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getAddressSpace()); in removeDeadStuffFromFunction()
859 NF->copyAttributesFrom(F); in removeDeadStuffFromFunction()
860 NF->setComdat(F->getComdat()); in removeDeadStuffFromFunction()
864 F->getParent()->getFunctionList().insert(F->getIterator(), NF); in removeDeadStuffFromFunction()
865 NF->takeName(F); in removeDeadStuffFromFunction()
870 while (!F->use_empty()) { in removeDeadStuffFromFunction()
871 CallBase &CB = cast<CallBase>(*F->user_back()); in removeDeadStuffFromFunction()
878 AttrBuilder RAttrs(F->getContext(), CallPAL.getRetAttrs()); in removeDeadStuffFromFunction()
880 AttributeSet RetAttrs = AttributeSet::get(F->getContext(), RAttrs); in removeDeadStuffFromFunction()
900 F->getContext(), AttrBuilder(F->getContext(), Attrs) in removeDeadStuffFromFunction()
920 F->getContext(), Attribute::AllocSize); in removeDeadStuffFromFunction()
923 AttributeList::get(F->getContext(), FnAttrs, RetAttrs, ArgAttrVec); in removeDeadStuffFromFunction()
999 NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList()); in removeDeadStuffFromFunction()
1004 for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(), in removeDeadStuffFromFunction()
1022 if (F->getReturnType() != NF->getReturnType()) in removeDeadStuffFromFunction()
1057 auto *NewRet = ReturnInst::Create(F->getContext(), RetVal, RI); in removeDeadStuffFromFunction()
1064 F->getAllMetadata(MDs); in removeDeadStuffFromFunction()
1079 F->eraseFromParent(); in removeDeadStuffFromFunction()
1093 for (Function &F : llvm::make_early_inc_range(M)) in run()
1094 if (F.getFunctionType()->isVarArg()) in run()
1095 Changed |= deleteDeadVarargs(F); in run()
1101 for (auto &F : M) in run() local
1102 surveyFunction(F); in run()
1107 for (Function &F : llvm::make_early_inc_range(M)) in run()
1108 Changed |= removeDeadStuffFromFunction(&F); in run()
1112 for (auto &F : M) in run() local
1113 Changed |= removeDeadArgumentsFromCallers(F); in run()