Lines Matching defs:CB
168 static void createRetBitCast(CallBase &CB, Type *RetTy, CastInst **RetBitCast) {
172 SmallVector<User *, 16> UsersToUpdate(CB.users());
177 if (auto *Invoke = dyn_cast<InvokeInst>(&CB))
181 InsertBefore = std::next(CB.getIterator());
184 auto *Cast = CastInst::CreateBitOrPointerCast(&CB, RetTy, "", InsertBefore);
190 U->replaceUsesOfWith(&CB, Cast);
287 static CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
290 IRBuilder<> Builder(&CB);
291 CallBase *OrigInst = &CB;
298 SplitBlockAndInsertIfThen(Cond, &CB, false, BranchWeights);
337 SplitBlockAndInsertIfThenElse(Cond, &CB, &ThenTerm, &ElseTerm, BranchWeights);
381 // Predicate and clone the given call site using condition `CB.callee ==
383 CallBase &llvm::versionCallSite(CallBase &CB, Value *Callee,
386 IRBuilder<> Builder(&CB);
390 if (CB.getCalledOperand()->getType() != Callee->getType())
391 Callee = Builder.CreateBitCast(Callee, CB.getCalledOperand()->getType());
392 auto *Cond = Builder.CreateICmpEQ(CB.getCalledOperand(), Callee);
394 return versionCallSiteWithCond(CB, Cond, BranchWeights);
397 bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee,
399 assert(!CB.getCalledFunction() && "Only indirect call sites can be promoted");
405 Type *CallRetTy = CB.getType();
418 unsigned NumArgs = CB.arg_size();
436 CB.getAttributes().hasParamAttr(I, Attribute::ByVal)) {
442 CB.getAttributes().hasParamAttr(I, Attribute::InAlloca)) {
449 Type *ActualTy = CB.getArgOperand(I)->getType();
460 if (CB.isMustTailCall()) {
473 if (CB.paramHasAttr(I, Attribute::StructRet)) {
483 CallBase &llvm::promoteCall(CallBase &CB, Function *Callee,
485 assert(!CB.getCalledFunction() && "Only indirect call sites can be promoted");
489 CB.setCalledOperand(Callee);
494 CB.setMetadata(LLVMContext::MD_prof, nullptr);
495 CB.setMetadata(LLVMContext::MD_callees, nullptr);
499 if (CB.getFunctionType() == Callee->getFunctionType())
500 return CB;
503 Type *CallSiteRetTy = CB.getType();
507 CB.mutateFunctionType(Callee->getFunctionType());
516 const AttributeList &CallerPAL = CB.getAttributes();
522 auto *Arg = CB.getArgOperand(ArgNo);
527 CastInst::CreateBitOrPointerCast(Arg, FormalTy, "", CB.getIterator());
528 CB.setArgOperand(ArgNo, Cast);
552 createRetBitCast(CB, CallSiteRetTy, RetBitCast);
560 CB.setAttributes(AttributeList::get(Ctx, CallerPAL.getFnAttrs(),
564 return CB;
567 CallBase &llvm::promoteCallWithIfThenElse(CallBase &CB, Function *Callee,
573 CallBase &NewInst = versionCallSite(CB, Callee, BranchWeights);
579 CallBase *llvm::promoteCallWithIfThenElse(CallBase &CB, Function &Callee,
581 assert(CB.isIndirectCall());
584 auto &Caller = *CB.getFunction();
585 auto *CSInstr = CtxProfAnalysis::getCallsiteInstrumentation(CB);
591 versionCallSite(CB, &Callee, /*BranchWeights=*/nullptr), &Callee);
592 CSInstr->moveBefore(CB.getIterator());
599 auto &IndirectBB = *CB.getParent();
664 CallBase &llvm::promoteCallWithVTableCmp(CallBase &CB, Instruction *VPtr,
669 IRBuilder<> Builder(&CB);
679 CallBase &NewInst = versionCallSiteWithCond(CB, Cond, BranchWeights);
685 bool llvm::tryPromoteCall(CallBase &CB) {
686 assert(!CB.getCalledFunction());
687 Module *M = CB.getCaller()->getParent();
689 Value *Callee = CB.getCalledOperand();
733 if (!isLegalToPromote(CB, DirectCallee))
737 promoteCall(CB, DirectCallee);