diff options
author | Devang Patel <dpatel@apple.com> | 2008-03-04 21:15:15 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2008-03-04 21:15:15 +0000 |
commit | dc00d42bb18a6748f43c365d9bd30c1ed0e800ac (patch) | |
tree | dd9f24d6ef339a9acc0fa7ac3a56cc8c7c675e24 | |
parent | a76e2f0331108805228453bfa071cc43ce1aa31e (diff) | |
download | llvm-dc00d42bb18a6748f43c365d9bd30c1ed0e800ac.tar.gz llvm-dc00d42bb18a6748f43c365d9bd30c1ed0e800ac.tar.bz2 llvm-dc00d42bb18a6748f43c365d9bd30c1ed0e800ac.tar.xz |
Handle multiple return values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47904 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Utils/InlineFunction.cpp | 18 | ||||
-rw-r--r-- | test/Transforms/Inline/2008-03-04-StructRet.ll | 26 |
2 files changed, 41 insertions, 3 deletions
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index 552583042a..6dda6d3313 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -442,9 +442,21 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { // If the return instruction returned a value, replace uses of the call with // uses of the returned value. - if (!TheCall->use_empty()) - TheCall->replaceAllUsesWith(Returns[0]->getReturnValue()); - + if (!TheCall->use_empty()) { + ReturnInst *R = Returns[0]; + if (R->getNumOperands() > 1) { + // Multiple return values. + for (Value::use_iterator RUI = TheCall->use_begin(), + RUE = TheCall->use_end(); RUI != RUE; ) { + GetResultInst *GR = dyn_cast<GetResultInst>(RUI++); + assert (GR && "Invalid Call instruction use!"); + Value *RV = R->getOperand(GR->getIndex()); + GR->replaceAllUsesWith(RV); + GR->eraseFromParent(); + } + } else + TheCall->replaceAllUsesWith(R->getReturnValue()); + } // Since we are now done with the Call/Invoke, we can delete it. TheCall->getParent()->getInstList().erase(TheCall); diff --git a/test/Transforms/Inline/2008-03-04-StructRet.ll b/test/Transforms/Inline/2008-03-04-StructRet.ll new file mode 100644 index 0000000000..d919cf49fd --- /dev/null +++ b/test/Transforms/Inline/2008-03-04-StructRet.ll @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s | opt -inline -sretpromotion -disable-output + %struct.Benchmark = type { i32 (...)** } + %struct.Complex = type { double, double } + %struct.ComplexBenchmark = type { %struct.Benchmark } + +define void @_Zml7ComplexS_(%struct.Complex* sret %agg.result, double %a.0, double %a.1, double %b.0, double %b.1) nounwind { +entry: + ret void +} + +define void @_ZNK16ComplexBenchmark9oop_styleEv(%struct.ComplexBenchmark* %this) nounwind { +entry: + %tmp = alloca %struct.Complex ; <%struct.Complex*> [#uses=2] + br label %bb31 + +bb: ; preds = %bb31 + call void @_Zml7ComplexS_( %struct.Complex* sret %tmp, double 0.000000e+00, double 0.000000e+00, double 0.000000e+00, double 0.000000e+00 ) nounwind + %tmp21 = getelementptr %struct.Complex* %tmp, i32 0, i32 1 ; <double*> [#uses=0] + br label %bb31 + +bb31: ; preds = %bb, %entry + br i1 false, label %bb, label %return + +return: ; preds = %bb31 + ret void +} |