aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-07-23 00:34:11 +0000
committerDan Gohman <gohman@apple.com>2008-07-23 00:34:11 +0000
commitfc74abfba5128544a750fce22fdf13eb0403e3ce (patch)
tree36ed972103bbbb170370e4e6688787ed5f1f9ac8 /lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
parent5e6ebaf4d1d3043d3428b65ee8054c71c24af930 (diff)
Enable first-class aggregates support.
Remove the GetResultInst instruction. It is still accepted in LLVM assembly and bitcode, where it is now auto-upgraded to ExtractValueInst. Also, remove support for return instructions with multiple values. These are auto-upgraded to use InsertValueInst instructions. The IRBuilder still accepts multiple-value returns, and auto-upgrades them to InsertValueInst instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53941 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/UnifyFunctionExitNodes.cpp')
-rw-r--r--lib/Transforms/Utils/UnifyFunctionExitNodes.cpp34
1 files changed, 6 insertions, 28 deletions
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index c024d32374..ba58fbd987 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -110,32 +110,13 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
//
BasicBlock *NewRetBlock = BasicBlock::Create("UnifiedReturnBlock", &F);
- SmallVector<Value *, 4> Phis;
- unsigned NumRetVals = ReturningBlocks[0]->getTerminator()->getNumOperands();
- if (NumRetVals == 0)
+ PHINode *PN = 0;
+ if (F.getReturnType() == Type::VoidTy) {
ReturnInst::Create(NULL, NewRetBlock);
- else if (const StructType *STy = dyn_cast<StructType>(F.getReturnType())) {
- Instruction *InsertPt = NULL;
- if (NumRetVals == 0)
- InsertPt = NewRetBlock->getFirstNonPHI();
- PHINode *PN = NULL;
- for (unsigned i = 0; i < NumRetVals; ++i) {
- if (InsertPt)
- PN = PHINode::Create(STy->getElementType(i), "UnifiedRetVal."
- + utostr(i), InsertPt);
- else
- PN = PHINode::Create(STy->getElementType(i), "UnifiedRetVal."
- + utostr(i), NewRetBlock);
- Phis.push_back(PN);
- InsertPt = PN;
- }
- ReturnInst::Create(&Phis[0], NumRetVals, NewRetBlock);
- }
- else {
+ } else {
// If the function doesn't return void... add a PHI node to the block...
- PHINode *PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal");
+ PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal");
NewRetBlock->getInstList().push_back(PN);
- Phis.push_back(PN);
ReturnInst::Create(PN, NewRetBlock);
}
@@ -148,11 +129,8 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
// Add an incoming element to the PHI node for every return instruction that
// is merging into this new block...
- if (!Phis.empty()) {
- for (unsigned i = 0; i < NumRetVals; ++i)
- cast<PHINode>(Phis[i])->addIncoming(BB->getTerminator()->getOperand(i),
- BB);
- }
+ if (PN)
+ PN->addIncoming(BB->getTerminator()->getOperand(0), BB);
BB->getInstList().pop_back(); // Remove the return insn
BranchInst::Create(NewRetBlock, BB);