llvm.org GIT mirror llvm / 3641e51
[opaque pointer types] Pass function type for CallBase::setCalledFunction. Differential Revision: https://reviews.llvm.org/D57174 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352914 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 9 months ago
6 changed file(s) with 25 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
120120 return true;
121121 }
122122
123 /// Set the callee to the specified value.
123 /// Set the callee to the specified value. Unlike the function of the same
124 /// name on CallBase, does not modify the type!
124125 void setCalledFunction(Value *V) {
125126 assert(getInstruction() && "Not a call or invoke instruction!");
127 assert(cast(V->getType())->getElementType() ==
128 cast(getInstruction())->getFunctionType() &&
129 "New callee type does not match FunctionType on call");
126130 *getCallee() = V;
127131 }
128132
2626 #include "llvm/IR/CallingConv.h"
2727 #include "llvm/IR/Constants.h"
2828 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Function.h"
2930 #include "llvm/IR/Instruction.h"
3031 #include "llvm/IR/LLVMContext.h"
3132 #include "llvm/IR/OperandTraits.h"
12251226 void setCalledOperand(Value *V) { Op() = V; }
12261227
12271228 /// Sets the function called, including updating the function type.
1228 void setCalledFunction(Value *Fn) {
1229 setCalledFunction(
1230 cast(cast(Fn->getType())->getElementType()),
1231 Fn);
1229 void setCalledFunction(Function *Fn) {
1230 setCalledFunction(Fn->getFunctionType(), Fn);
12321231 }
12331232
12341233 /// Sets the function called, including updating the function type.
12421241 this->FTy = FTy;
12431242 assert(FTy == cast(
12441243 cast(Fn->getType())->getElementType()));
1244 // This function doesn't mutate the return type, only the function
1245 // type. Seems broken, but I'm just gonna stick an assert in for now.
1246 assert(getType() == FTy->getReturnType());
12451247 setCalledOperand(Fn);
12461248 }
12471249
42134213 // We cannot remove an invoke, because it would change the CFG, just
42144214 // change the callee to a null pointer.
42154215 cast(OldCall)->setCalledFunction(
4216 Constant::getNullValue(CalleeF->getType()));
4216 CalleeF->getFunctionType(),
4217 Constant::getNullValue(CalleeF->getType()));
42174218 return nullptr;
42184219 }
42194220 }
45544555 InstCombiner::transformCallThroughTrampoline(CallBase &Call,
45554556 IntrinsicInst &Tramp) {
45564557 Value *Callee = Call.getCalledValue();
4557 PointerType *PTy = cast(Callee->getType());
4558 FunctionType *FTy = cast(PTy->getElementType());
4558 Type *CalleeTy = Callee->getType();
4559 FunctionType *FTy = Call.getFunctionType();
45594560 AttributeList Attrs = Call.getAttributes();
45604561
45614562 // If the call already has the 'nest' attribute somewhere then give up -
45644565 return nullptr;
45654566
45664567 Function *NestF = cast(Tramp.getArgOperand(1)->stripPointerCasts());
4567 FunctionType *NestFTy = cast(NestF->getValueType());
4568 FunctionType *NestFTy = NestF->getFunctionType();
45684569
45694570 AttributeList NestAttrs = NestF->getAttributes();
45704571 if (!NestAttrs.isEmpty()) {
46884689 // Replace the trampoline call with a direct call. Since there is no 'nest'
46894690 // parameter, there is no need to adjust the argument list. Let the generic
46904691 // code sort out any function type mismatches.
4691 Constant *NewCallee =
4692 NestF->getType() == PTy ? NestF :
4693 ConstantExpr::getBitCast(NestF, PTy);
4694 Call.setCalledFunction(NewCallee);
4692 Constant *NewCallee = ConstantExpr::getBitCast(NestF, CalleeTy);
4693 Call.setCalledFunction(FTy, NewCallee);
46954694 return &Call;
46964695 }
138138
139139 // We do not have to worry about tail calls/does not throw since
140140 // retain/retainRV have the same properties.
141 Constant *Decl = EP.get(ARCRuntimeEntryPointKind::RetainRV);
141 Function *Decl = EP.get(ARCRuntimeEntryPointKind::RetainRV);
142142 cast(Retain)->setCalledFunction(Decl);
143143
144144 LLVM_DEBUG(dbgs() << "New: " << *Retain << "\n");
187187 " Retain: "
188188 << *Retain << "\n");
189189
190 Constant *Decl = EP.get(Class == ARCInstKind::AutoreleaseRV
190 Function *Decl = EP.get(Class == ARCInstKind::AutoreleaseRV
191191 ? ARCRuntimeEntryPointKind::RetainAutoreleaseRV
192192 : ARCRuntimeEntryPointKind::RetainAutorelease);
193193 Retain->setCalledFunction(Decl);
640640 "Old = "
641641 << *RetainRV << "\n");
642642
643 Constant *NewDecl = EP.get(ARCRuntimeEntryPointKind::Retain);
643 Function *NewDecl = EP.get(ARCRuntimeEntryPointKind::Retain);
644644 cast(RetainRV)->setCalledFunction(NewDecl);
645645
646646 LLVM_DEBUG(dbgs() << "New = " << *RetainRV << "\n");
689689 << *AutoreleaseRV << "\n");
690690
691691 CallInst *AutoreleaseRVCI = cast(AutoreleaseRV);
692 Constant *NewDecl = EP.get(ARCRuntimeEntryPointKind::Autorelease);
692 Function *NewDecl = EP.get(ARCRuntimeEntryPointKind::Autorelease);
693693 AutoreleaseRVCI->setCalledFunction(NewDecl);
694694 AutoreleaseRVCI->setTailCall(false); // Never tail call objc_autorelease.
695695 Class = ARCInstKind::Autorelease;
365365 CastInst **RetBitCast) {
366366 assert(!CS.getCalledFunction() && "Only indirect call sites can be promoted");
367367
368 // Set the called function of the call site to be the given callee.
369 CS.setCalledFunction(Callee);
368 // Set the called function of the call site to be the given callee (but don't
369 // change the type).
370 cast(CS.getInstruction())->setCalledOperand(Callee);
370371
371372 // Since the call site will no longer be direct, we must clear metadata that
372373 // is only appropriate for indirect calls. This includes !prof and !callees