UnifyFunctionExitNodes.cpp (193323) | UnifyFunctionExitNodes.cpp (198090) |
---|---|
1//===- UnifyFunctionExitNodes.cpp - Make all functions have a single exit -===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 52 unchanged lines hidden (view full) --- 61 UnreachableBlocks.push_back(I); 62 63 // Handle unwinding blocks first. 64 if (UnwindingBlocks.empty()) { 65 UnwindBlock = 0; 66 } else if (UnwindingBlocks.size() == 1) { 67 UnwindBlock = UnwindingBlocks.front(); 68 } else { | 1//===- UnifyFunctionExitNodes.cpp - Make all functions have a single exit -===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 52 unchanged lines hidden (view full) --- 61 UnreachableBlocks.push_back(I); 62 63 // Handle unwinding blocks first. 64 if (UnwindingBlocks.empty()) { 65 UnwindBlock = 0; 66 } else if (UnwindingBlocks.size() == 1) { 67 UnwindBlock = UnwindingBlocks.front(); 68 } else { |
69 UnwindBlock = BasicBlock::Create("UnifiedUnwindBlock", &F); 70 new UnwindInst(UnwindBlock); | 69 UnwindBlock = BasicBlock::Create(F.getContext(), "UnifiedUnwindBlock", &F); 70 new UnwindInst(F.getContext(), UnwindBlock); |
71 72 for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(), 73 E = UnwindingBlocks.end(); I != E; ++I) { 74 BasicBlock *BB = *I; 75 BB->getInstList().pop_back(); // Remove the unwind insn 76 BranchInst::Create(UnwindBlock, BB); 77 } 78 } 79 80 // Then unreachable blocks. 81 if (UnreachableBlocks.empty()) { 82 UnreachableBlock = 0; 83 } else if (UnreachableBlocks.size() == 1) { 84 UnreachableBlock = UnreachableBlocks.front(); 85 } else { | 71 72 for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(), 73 E = UnwindingBlocks.end(); I != E; ++I) { 74 BasicBlock *BB = *I; 75 BB->getInstList().pop_back(); // Remove the unwind insn 76 BranchInst::Create(UnwindBlock, BB); 77 } 78 } 79 80 // Then unreachable blocks. 81 if (UnreachableBlocks.empty()) { 82 UnreachableBlock = 0; 83 } else if (UnreachableBlocks.size() == 1) { 84 UnreachableBlock = UnreachableBlocks.front(); 85 } else { |
86 UnreachableBlock = BasicBlock::Create("UnifiedUnreachableBlock", &F); 87 new UnreachableInst(UnreachableBlock); | 86 UnreachableBlock = BasicBlock::Create(F.getContext(), 87 "UnifiedUnreachableBlock", &F); 88 new UnreachableInst(F.getContext(), UnreachableBlock); |
88 89 for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(), 90 E = UnreachableBlocks.end(); I != E; ++I) { 91 BasicBlock *BB = *I; 92 BB->getInstList().pop_back(); // Remove the unreachable inst. 93 BranchInst::Create(UnreachableBlock, BB); 94 } 95 } --- 6 unchanged lines hidden (view full) --- 102 ReturnBlock = ReturningBlocks.front(); // Already has a single return block 103 return false; 104 } 105 106 // Otherwise, we need to insert a new basic block into the function, add a PHI 107 // nodes (if the function returns values), and convert all of the return 108 // instructions into unconditional branches. 109 // | 89 90 for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(), 91 E = UnreachableBlocks.end(); I != E; ++I) { 92 BasicBlock *BB = *I; 93 BB->getInstList().pop_back(); // Remove the unreachable inst. 94 BranchInst::Create(UnreachableBlock, BB); 95 } 96 } --- 6 unchanged lines hidden (view full) --- 103 ReturnBlock = ReturningBlocks.front(); // Already has a single return block 104 return false; 105 } 106 107 // Otherwise, we need to insert a new basic block into the function, add a PHI 108 // nodes (if the function returns values), and convert all of the return 109 // instructions into unconditional branches. 110 // |
110 BasicBlock *NewRetBlock = BasicBlock::Create("UnifiedReturnBlock", &F); | 111 BasicBlock *NewRetBlock = BasicBlock::Create(F.getContext(), 112 "UnifiedReturnBlock", &F); |
111 112 PHINode *PN = 0; | 113 114 PHINode *PN = 0; |
113 if (F.getReturnType() == Type::VoidTy) { 114 ReturnInst::Create(NULL, NewRetBlock); | 115 if (F.getReturnType() == Type::getVoidTy(F.getContext())) { 116 ReturnInst::Create(F.getContext(), NULL, NewRetBlock); |
115 } else { 116 // If the function doesn't return void... add a PHI node to the block... 117 PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal"); 118 NewRetBlock->getInstList().push_back(PN); | 117 } else { 118 // If the function doesn't return void... add a PHI node to the block... 119 PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal"); 120 NewRetBlock->getInstList().push_back(PN); |
119 ReturnInst::Create(PN, NewRetBlock); | 121 ReturnInst::Create(F.getContext(), PN, NewRetBlock); |
120 } 121 122 // Loop over all of the blocks, replacing the return instruction with an 123 // unconditional branch. 124 // 125 for (std::vector<BasicBlock*>::iterator I = ReturningBlocks.begin(), 126 E = ReturningBlocks.end(); I != E; ++I) { 127 BasicBlock *BB = *I; --- 12 unchanged lines hidden --- | 122 } 123 124 // Loop over all of the blocks, replacing the return instruction with an 125 // unconditional branch. 126 // 127 for (std::vector<BasicBlock*>::iterator I = ReturningBlocks.begin(), 128 E = ReturningBlocks.end(); I != E; ++I) { 129 BasicBlock *BB = *I; --- 12 unchanged lines hidden --- |