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();
181 RetTy,
"", InsertBefore);
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) {
328 if (CallRetTy != FuncRetTy)
331 *FailureReason =
"Return type mismatch";
342 *FailureReason =
"The number of arguments mismatch";
349 for (
unsigned I = 0;
I < NumParams; ++
I) {
352 if (FormalTy == ActualTy)
356 *FailureReason =
"Argument type mismatch";
394 for (
unsigned ArgNo = 0; ArgNo < CalleeParamNum; ++ArgNo) {
396 Type *FormalTy = CalleeType->getParamType(ArgNo);
398 if (FormalTy != ActualTy) {
407 if (!CallSiteRetTy->
isVoidTy() && CallSiteRetTy != CalleeRetTy)
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 push_back(const T &Elt)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, TerminatorInst **ThenTerm, TerminatorInst **ElseTerm, MDNode *BranchWeights=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
unsigned arg_size() const
Compute iterated dominance frontiers using a linear time algorithm.
bool isLegalToPromote(CallSite CS, Function *Callee, const char **FailureReason=nullptr)
Return true if the given indirect call site can be made to call Callee.
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.
amdgpu Simplify well known AMD library false Value * Callee
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'.
Type * getReturnType() const
Returns the type of the ret val.
Subclasses of this class are all able to terminate a basic block.
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...
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.
static bool isBitCastable(Type *SrcTy, Type *DestTy)
Check whether a bitcast between these types is valid.
self_iterator getIterator()
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
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
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
LLVM Value Representation.
FunctionType * getFunctionType() const
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the edge connecting specified block.
void setCalledFunction(Value *V)
Set the callee to the specified value.
void mutateFunctionType(FunctionType *Ty) const
const BasicBlock * getParent() const