[llvm-commits] [llvm] r47904 - in /llvm/trunk: lib/Transforms/Utils/InlineFunction.cpp test/Transforms/Inline/2008-03-04-StructRet.ll
Chris Lattner
clattner at apple.com
Tue Mar 4 13:31:08 PST 2008
On Mar 4, 2008, at 1:15 PM, Devang Patel wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=47904&view=rev
> Log:
> Handle multiple return values.
Nice.
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Tue Mar 4
> 15:15:15 2008
> @@ -442,9 +442,21 @@
>
> // 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!");
Just use cast<> here instead of dyn_cast. cast<> doesn't have a cost
when assertions are disabled, dyn_cast does, this also allows you to
remove the assert.
Also, it isn't a big deal, but it is more idiomatic and simpler to
write the loop as:
while (!TheCall->use_empty()) {
GetResultInst *GR = cast<GetResultInst>(TheCall->use_back());
...
}
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/test/Transforms/Inline/2008-03-04-StructRet.ll (added)
> +++ llvm/trunk/test/Transforms/Inline/2008-03-04-StructRet.ll Tue
> Mar 4 15:15:15 2008
> @@ -0,0 +1,26 @@
> +; RUN: llvm-as < %s | opt -inline -sretpromotion -disable-output
This test should not run sretpromotion, just use a .ll file from after
sretpromotion is run.
-Chris
>
> + %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
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list