21 #define DEBUG_TYPE "call-promotion-utils" 51 int Idx = Phi.getBasicBlockIndex(OrigBlock);
54 Phi.setIncomingBlock(Idx, MergeBlock);
83 int Idx = Phi.getBasicBlockIndex(OrigBlock);
86 auto *V = Phi.getIncomingValue(Idx);
87 Phi.setIncomingBlock(Idx, ThenBlock);
88 Phi.addIncoming(V, ElseBlock);
116 for (
User *U : UsersToUpdate)
117 U->replaceUsesOfWith(OrigInst, Phi);
175 &
SplitEdge(Invoke->getParent(), Invoke->getNormalDest())->front();
186 for (
User *U : UsersToUpdate)
262 BasicBlock *OrigBlock = OrigInst->getParent();
279 BasicBlock *MergeBlock = OrigInst->getParent();
281 ThenBlock->setName(
"if.true.direct_targ");
282 ElseBlock->
setName(
"if.false.orig_indirect");
283 MergeBlock->
setName(
"if.end.icp");
286 OrigInst->moveBefore(ElseTerm);
292 if (
auto *OrigInvoke = dyn_cast<InvokeInst>(OrigInst)) {
293 auto *NewInvoke = cast<InvokeInst>(NewInst);
298 ElseTerm->eraseFromParent();
301 Builder.SetInsertPoint(MergeBlock);
302 Builder.CreateBr(OrigInvoke->getNormalDest());
310 OrigInvoke->setNormalDest(MergeBlock);
311 NewInvoke->setNormalDest(MergeBlock);
321 const char **FailureReason) {
330 if (CallRetTy != FuncRetTy)
333 *FailureReason =
"Return type mismatch";
344 *FailureReason =
"The number of arguments mismatch";
351 for (
unsigned I = 0;
I < NumParams; ++
I) {
354 if (FormalTy == ActualTy)
358 *FailureReason =
"Argument type mismatch";
401 bool AttributeChanged =
false;
403 for (
unsigned ArgNo = 0; ArgNo < CalleeParamNum; ++ArgNo) {
405 Type *FormalTy = CalleeType->getParamType(ArgNo);
407 if (FormalTy != ActualTy) {
416 AttributeChanged =
true;
425 if (!CallSiteRetTy->
isVoidTy() && CallSiteRetTy != CalleeRetTy) {
428 AttributeChanged =
true;
432 if (AttributeChanged)
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
unsigned arg_size() const
This class represents lattice values for constants.
void push_back(const T &Elt)
bool isLegalToPromote(CallSite CS, Function *Callee, const char **FailureReason=nullptr)
Return true if the given indirect call site can be made to call Callee.
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op...
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Split the edge connecting specified block.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This is the base class for all instructions that perform data casts.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
InstrTy * getInstruction() const
void setName(const Twine &Name)
Change the name of the value.
Type * getFunctionParamType(unsigned i) const
void setArgument(unsigned ArgNo, Value *newVal)
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Type * getType() const
All values are typed, get the type of this value.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
bool isVoidTy() const
Return true if this is 'void'.
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
Type * getReturnType() const
Returns the type of the ret val.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
const Instruction & front() const
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Instruction * promoteCall(CallSite CS, Function *Callee, CastInst **RetBitCast=nullptr)
Promote the given indirect call site to unconditionally call Callee.
self_iterator getIterator()
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
BasicBlock * getNormalDest() const
Instruction * promoteCallWithIfThenElse(CallSite CS, Function *Callee, MDNode *BranchWeights=nullptr)
Promote the given indirect call site to conditionally call Callee.
ValTy * getArgument(unsigned ArgNo) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
FunctionType * getFunctionType() const
Returns the FunctionType for me.
iterator_range< user_iterator > users()
amdgpu Simplify well known AMD library false Value Value * Arg
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
const Function * getParent() const
Return the enclosing method, or null if none.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BasicBlock * getUnwindDest() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
FunctionType * getFunctionType() const
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
AttributeSet getFnAttributes() const
The function attributes are returned.
AttributeList getAttributes() const
Get the parameter attributes of the call.
void setCalledFunction(Value *V)
Set the callee to the specified value.
void mutateFunctionType(FunctionType *Ty) const
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
const BasicBlock * getParent() const