27 "Unify function exit nodes",
false,
false)
50 std::vector<BasicBlock*> ReturningBlocks;
51 std::vector<BasicBlock*> UnreachableBlocks;
53 if (isa<ReturnInst>(
I.getTerminator()))
54 ReturningBlocks.push_back(&
I);
55 else if (isa<UnreachableInst>(
I.getTerminator()))
56 UnreachableBlocks.push_back(&
I);
59 if (UnreachableBlocks.empty()) {
61 }
else if (UnreachableBlocks.size() == 1) {
65 "UnifiedUnreachableBlock", &
F);
69 BB->getInstList().pop_back();
75 if (ReturningBlocks.empty()) {
78 }
else if (ReturningBlocks.size() == 1) {
88 "UnifiedReturnBlock", &
F);
91 if (F.getReturnType()->isVoidTy()) {
108 PN->addIncoming(BB->getTerminator()->getOperand(0), BB);
110 BB->getInstList().pop_back();
Pass interface - Implemented by all 'passes'.
This class represents lattice values for constants.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
AnalysisUsage & addPreservedID(const void *ID)
Pass * createUnifyFunctionExitNodesPass()
LLVM Basic Block Representation.
char & BreakCriticalEdgesID
This function has undefined behavior.
const Instruction & front() const
Represent the analysis usage information of a pass.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const InstListType & getInstList() const
Return the underlying instruction list container.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
void push_back(pointer val)
INITIALIZE_PASS(UnifyFunctionExitNodes, "mergereturn", "Unify function exit nodes", false, false) Pass *llvm
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
BasicBlock * UnreachableBlock