abb226c954
2015-06-17 Andrew MacLeod <amacleod@redhat.com> * coretypes.h: Include input.h and as-a.h. * rtl.h: Include input.h and as-a.h for generator files. * hwint.c: Include input.h. * vec.c: Include input.h. * alias.c: Do not include input.h, line-map.h or is-a.h. * asan.c: Likewise. * attribs.c: Likewise. * auto-inc-dec.c: Likewise. * auto-profile.c: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * ccmp.c: Likewise. * cfg.c: Likewise. * cfganal.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloop.h: Likewise. * cfgloopanal.c: Likewise. * cfgloopmanip.c: Likewise. * cfgrtl.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * compare-elim.c: Likewise. * convert.c: Likewise. * coverage.c: Likewise. * cppbuiltin.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * data-streamer.c: Likewise. * dbxout.c: Likewise. * dce.c: Likewise. * ddg.c: Likewise. * debug.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * df.h: Likewise. * dfp.c: Likewise. * diagnostic-core.h: Likewise. * diagnostic.c: Likewise. * dojump.c: Likewise. * dominance.c: Likewise. * domwalk.c: Likewise. * double-int.c: Likewise. * dse.c: Likewise. * dumpfile.c: Likewise. * dumpfile.h: Likewise. * dwarf2asm.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * et-forest.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * fwprop.c: Likewise. * gcc-plugin.h: Likewise. * gcse.c: Likewise. * generic-match-head.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-match-head.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-streamer.h: Likewise. * gimple-walk.c: Likewise. * gimple.c: Likewise. * gimplify-me.c: Likewise. * gimplify.c: Likewise. * godump.c: Likewise. * graph.c: Likewise. * graphite-blocking.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-isl-ast-to-gimple.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * haifa-sched.c: Likewise. * hw-doloop.c: Likewise. * ifcvt.c: Likewise. * init-regs.c: Likewise. * input.c: Likewise. * internal-fn.c: Likewise. * ipa-chkp.c: Likewise. * ipa-comdats.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-icf-gimple.c: Likewise. * ipa-icf.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-polymorphic-call.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-ref.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * ipa-visibility.c: Likewise. * ipa.c: Likewise. * ira-build.c: Likewise. * ira-color.c: Likewise. * ira-conflicts.c: Likewise. * ira-costs.c: Likewise. * ira-emit.c: Likewise. * ira-lives.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * langhooks.c: Likewise. * lcm.c: Likewise. * loop-doloop.c: Likewise. * loop-init.c: Likewise. * loop-invariant.c: Likewise. * loop-iv.c: Likewise. * loop-unroll.c: Likewise. * lower-subreg.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-remat.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * mcf.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omega.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * opts-global.c: Likewise. * opts.h: Likewise. * passes.c: Likewise. * plugin.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * pretty-print.h: Likewise. * print-rtl.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * real.c: Likewise. * realmpfr.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * regstat.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtl-chkp.c: Likewise. * rtl-error.c: Likewise. * rtlanal.c: Likewise. * rtlhooks.c: Likewise. * sanopt.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sched-vis.c: Likewise. * sdbout.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * sese.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * stack-ptr-mod.c: Likewise. * statistics.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * streamer-hooks.c: Likewise. * stringpool.c: Likewise. * symtab.c: Likewise. * target-globals.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-browser.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chkp-opt.c: Likewise. * tree-chkp.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-diagnostic.c: Likewise. * tree-dump.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-scopedtables.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-streamer.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * valtrack.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. * varpool.c: Likewise. * vmsdbgout.c: Likewise. * vtable-verify.c: Likewise. * web.c: Likewise. * wide-int.cc: Likewise. * xcoffout.c: Likewise. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/aarch-common.c: Likewise. * config/arm/arm-builtins.c: Likewise. * config/arm/arm-c.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-c.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin-c.c: Likewise. * config/darwin.c: Likewise. * config/default-c.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/ft32/ft32.c: Likewise. * config/glibc-c.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386-c.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/msformat-c.c: Likewise. * config/i386/winnt-cxx.c: Likewise. * config/i386/winnt-stubs.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64-c.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c-pragma.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze-c.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430-c.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/nvptx/nvptx.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78-c.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000-c.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390-c.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh-c.c: Likewise. * config/sh/sh-mem.cc: Likewise. * config/sh/sh.c: Likewise. * config/sh/sh_optimize_sett_clrt.cc: Likewise. * config/sh/sh_treg_combine.cc: Likewise. * config/sol2-c.c: Likewise. * config/sol2-cxx.c: Likewise. * config/sol2-stubs.c: Likewise. * config/sol2.c: Likewise. * config/sparc/sparc-c.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu-c.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/mul-tables.c: Likewise. * config/tilegx/tilegx-c.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/mul-tables.c: Likewise. * config/tilepro/tilepro-c.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850-c.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/visium/visium.c: Likewise. * config/vms/vms-c.c: Likewise. * config/vms/vms.c: Likewise. * config/vxworks.c: Likewise. * config/winnt-c.c: Likewise. * config/xtensa/xtensa.c: Likewise. ada * ada/gcc-interface/cuintp.c: Do not include input.h, line-map.h or is-a.h. * ada/gcc-interface/decl.c: Likewise. * ada/gcc-interface/misc.c: Likewise. * ada/gcc-interface/targtyps.c: Likewise. * ada/gcc-interface/trans.c: Likewise. * ada/gcc-interface/utils.c: Likewise. * ada/gcc-interface/utils2.c: Likewise. c * c/c-array-notation.c: Do not include input.h, line-map.h or is-a.h. * c/c-aux-info.c: Likewise. * c/c-convert.c: Likewise. * c/c-decl.c: Likewise. * c/c-errors.c: Likewise. * c/c-lang.c: Likewise. * c/c-objc-common.c: Likewise. * c/c-parser.c: Likewise. * c/c-typeck.c: Likewise. c-family * c-family/array-notation-common.c: Do not include input.h, line-map.h or is-a.h. * c-family/c-ada-spec.c: Likewise. * c-family/c-cilkplus.c: Likewise. * c-family/c-common.c: Likewise. * c-family/c-common.h: Likewise. * c-family/c-cppbuiltin.c: Likewise. * c-family/c-dump.c: Likewise. * c-family/c-format.c: Likewise. * c-family/c-gimplify.c: Likewise. * c-family/c-indentation.c: Likewise. * c-family/c-lex.c: Likewise. * c-family/c-omp.c: Likewise. * c-family/c-opts.c: Likewise. * c-family/c-pch.c: Likewise. * c-family/c-ppoutput.c: Likewise. * c-family/c-pragma.c: Likewise. * c-family/c-pretty-print.c: Likewise. * c-family/c-semantics.c: Likewise. * c-family/c-ubsan.c: Likewise. * c-family/cilk.c: Likewise. * c-family/stub-objc.c: Likewise. common * common/common-target.h: Do not include input.h, line-map.h or is-a.h. * common/common-targhooks.c: Likewise. cp * cp/call.c: Do not include input.h, line-map.h or is-a.h. * cp/class.c: Likewise. * cp/constexpr.c: Likewise. * cp/cp-array-notation.c: Likewise. * cp/cp-gimplify.c: Likewise. * cp/cp-lang.c: Likewise. * cp/cp-objcp-common.c: Likewise. * cp/cp-tree.h: Likewise. * cp/cp-ubsan.c: Likewise. * cp/cvt.c: Likewise. * cp/decl.c: Likewise. * cp/decl2.c: Likewise. * cp/dump.c: Likewise. * cp/error.c: Likewise. * cp/except.c: Likewise. * cp/expr.c: Likewise. * cp/friend.c: Likewise. * cp/init.c: Likewise. * cp/lambda.c: Likewise. * cp/lex.c: Likewise. * cp/mangle.c: Likewise. * cp/method.c: Likewise. * cp/name-lookup.c: Likewise. * cp/optimize.c: Likewise. * cp/parser.c: Likewise. * cp/pt.c: Likewise. * cp/ptree.c: Likewise. * cp/repo.c: Likewise. * cp/rtti.c: Likewise. * cp/search.c: Likewise. * cp/semantics.c: Likewise. * cp/tree.c: Likewise. * cp/typeck.c: Likewise. * cp/typeck2.c: Likewise. * cp/vtable-class-hierarchy.c: Likewise. fortran * fortran/convert.c: Do not include input.h, line-map.h or is-a.h. * fortran/cpp.c: Likewise. * fortran/decl.c: Likewise. * fortran/f95-lang.c: Likewise. * fortran/gfortran.h: Likewise. * fortran/iresolve.c: Likewise. * fortran/match.c: Likewise. * fortran/module.c: Likewise. * fortran/options.c: Likewise. * fortran/target-memory.c: Likewise. * fortran/trans-array.c: Likewise. * fortran/trans-common.c: Likewise. * fortran/trans-const.c: Likewise. * fortran/trans-decl.c: Likewise. * fortran/trans-expr.c: Likewise. * fortran/trans-intrinsic.c: Likewise. * fortran/trans-io.c: Likewise. * fortran/trans-openmp.c: Likewise. * fortran/trans-stmt.c: Likewise. * fortran/trans-types.c: Likewise. * fortran/trans.c: Likewise. go * go/go-backend.c: Do not include input.h, line-map.h or is-a.h. * go/go-gcc.cc: Likewise. * go/go-lang.c: Likewise. * go/go-system.h: Likewise. java * java/boehm.c: Do not include input.h, line-map.h or is-a.h. * java/builtins.c: Likewise. * java/class.c: Likewise. * java/constants.c: Likewise. * java/decl.c: Likewise. * java/except.c: Likewise. * java/expr.c: Likewise. * java/java-gimplify.c: Likewise. * java/jcf-dump.c: Likewise. * java/jcf-io.c: Likewise. * java/jcf-parse.c: Likewise. * java/jvgenmain.c: Likewise. * java/lang.c: Likewise. * java/mangle.c: Likewise. * java/mangle_name.c: Likewise. * java/resource.c: Likewise. * java/typeck.c: Likewise. * java/verify-glue.c: Likewise. * java/verify-impl.c: Likewise. jit * jit/dummy-frontend.c: Do not include input.h, line-map.h or is-a.h. * jit/jit-common.h: Likewise. * jit/jit-playback.c: Likewise. lto * lto/lto-lang.c: Do not include input.h, line-map.h or is-a.h. * lto/lto-object.c: Likewise. * lto/lto-partition.c: Likewise. * lto/lto-symtab.c: Likewise. * lto/lto.c: Likewise. objc * objc/objc-act.c: Do not include input.h, line-map.h or is-a.h. * objc/objc-encoding.c: Likewise. * objc/objc-gnu-runtime-abi-01.c: Likewise. * objc/objc-lang.c: Likewise. * objc/objc-map.c: Likewise. * objc/objc-next-runtime-abi-01.c: Likewise. * objc/objc-next-runtime-abi-02.c: Likewise. * objc/objc-runtime-shared-support.c: Likewise. objcp * objcp/objcp-decl.c: Do not include input.h, line-map.h or is-a.h. * objcp/objcp-lang.c: Likewise. From-SVN: r224562
418 lines
12 KiB
C
418 lines
12 KiB
C
/* Language independent return value optimizations
|
|
Copyright (C) 2004-2015 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
GCC is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "tm.h"
|
|
#include "alias.h"
|
|
#include "symtab.h"
|
|
#include "tree.h"
|
|
#include "fold-const.h"
|
|
#include "hard-reg-set.h"
|
|
#include "function.h"
|
|
#include "predict.h"
|
|
#include "dominance.h"
|
|
#include "cfg.h"
|
|
#include "basic-block.h"
|
|
#include "tree-pretty-print.h"
|
|
#include "tree-ssa-alias.h"
|
|
#include "internal-fn.h"
|
|
#include "gimple-expr.h"
|
|
#include "gimple.h"
|
|
#include "gimple-iterator.h"
|
|
#include "gimple-walk.h"
|
|
#include "gimple-ssa.h"
|
|
#include "stringpool.h"
|
|
#include "tree-ssanames.h"
|
|
#include "tree-pass.h"
|
|
#include "langhooks.h"
|
|
#include "flags.h" /* For "optimize" in gate_pass_return_slot.
|
|
FIXME: That should be up to the pass manager,
|
|
but pass_nrv is not in pass_all_optimizations. */
|
|
|
|
/* This file implements return value optimizations for functions which
|
|
return aggregate types.
|
|
|
|
Basically this pass searches the function for return statements which
|
|
return a local aggregate. When converted to RTL such statements will
|
|
generate a copy from the local aggregate to final return value destination
|
|
mandated by the target's ABI.
|
|
|
|
That copy can often be avoided by directly constructing the return value
|
|
into the final destination mandated by the target's ABI.
|
|
|
|
This is basically a generic equivalent to the C++ front-end's
|
|
Named Return Value optimization. */
|
|
|
|
struct nrv_data_t
|
|
{
|
|
/* This is the temporary (a VAR_DECL) which appears in all of
|
|
this function's RETURN_EXPR statements. */
|
|
tree var;
|
|
|
|
/* This is the function's RESULT_DECL. We will replace all occurrences
|
|
of VAR with RESULT_DECL when we apply this optimization. */
|
|
tree result;
|
|
int modified;
|
|
};
|
|
|
|
static tree finalize_nrv_r (tree *, int *, void *);
|
|
|
|
/* Callback for the tree walker.
|
|
|
|
If TP refers to a RETURN_EXPR, then set the expression being returned
|
|
to nrv_data->result.
|
|
|
|
If TP refers to nrv_data->var, then replace nrv_data->var with
|
|
nrv_data->result.
|
|
|
|
If we reach a node where we know all the subtrees are uninteresting,
|
|
then set *WALK_SUBTREES to zero. */
|
|
|
|
static tree
|
|
finalize_nrv_r (tree *tp, int *walk_subtrees, void *data)
|
|
{
|
|
struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
|
|
struct nrv_data_t *dp = (struct nrv_data_t *) wi->info;
|
|
|
|
/* No need to walk into types. */
|
|
if (TYPE_P (*tp))
|
|
*walk_subtrees = 0;
|
|
|
|
/* Otherwise replace all occurrences of VAR with RESULT. */
|
|
else if (*tp == dp->var)
|
|
{
|
|
*tp = dp->result;
|
|
dp->modified = 1;
|
|
}
|
|
|
|
/* Keep iterating. */
|
|
return NULL_TREE;
|
|
}
|
|
|
|
/* Main entry point for return value optimizations.
|
|
|
|
If this function always returns the same local variable, and that
|
|
local variable is an aggregate type, then replace the variable with
|
|
the function's DECL_RESULT.
|
|
|
|
This is the equivalent of the C++ named return value optimization
|
|
applied to optimized trees in a language independent form. If we
|
|
ever encounter languages which prevent this kind of optimization,
|
|
then we could either have the languages register the optimization or
|
|
we could change the gating function to check the current language. */
|
|
|
|
namespace {
|
|
|
|
const pass_data pass_data_nrv =
|
|
{
|
|
GIMPLE_PASS, /* type */
|
|
"nrv", /* name */
|
|
OPTGROUP_NONE, /* optinfo_flags */
|
|
TV_TREE_NRV, /* tv_id */
|
|
( PROP_ssa | PROP_cfg ), /* properties_required */
|
|
0, /* properties_provided */
|
|
0, /* properties_destroyed */
|
|
0, /* todo_flags_start */
|
|
0, /* todo_flags_finish */
|
|
};
|
|
|
|
class pass_nrv : public gimple_opt_pass
|
|
{
|
|
public:
|
|
pass_nrv (gcc::context *ctxt)
|
|
: gimple_opt_pass (pass_data_nrv, ctxt)
|
|
{}
|
|
|
|
/* opt_pass methods: */
|
|
virtual bool gate (function *) { return optimize > 0; }
|
|
|
|
virtual unsigned int execute (function *);
|
|
|
|
}; // class pass_nrv
|
|
|
|
unsigned int
|
|
pass_nrv::execute (function *fun)
|
|
{
|
|
tree result = DECL_RESULT (current_function_decl);
|
|
tree result_type = TREE_TYPE (result);
|
|
tree found = NULL;
|
|
basic_block bb;
|
|
gimple_stmt_iterator gsi;
|
|
struct nrv_data_t data;
|
|
|
|
/* If this function does not return an aggregate type in memory, then
|
|
there is nothing to do. */
|
|
if (!aggregate_value_p (result, current_function_decl))
|
|
return 0;
|
|
|
|
/* If a GIMPLE type is returned in memory, finalize_nrv_r might create
|
|
non-GIMPLE. */
|
|
if (is_gimple_reg_type (result_type))
|
|
return 0;
|
|
|
|
/* If the front end already did something like this, don't do it here. */
|
|
if (DECL_NAME (result))
|
|
return 0;
|
|
|
|
/* If the result has its address taken then it might be modified
|
|
by means not detected in the following loop. Bail out in this
|
|
case. */
|
|
if (TREE_ADDRESSABLE (result))
|
|
return 0;
|
|
|
|
/* Look through each block for assignments to the RESULT_DECL. */
|
|
FOR_EACH_BB_FN (bb, fun)
|
|
{
|
|
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
|
|
{
|
|
gimple stmt = gsi_stmt (gsi);
|
|
tree ret_val;
|
|
|
|
if (greturn *return_stmt = dyn_cast <greturn *> (stmt))
|
|
{
|
|
/* In a function with an aggregate return value, the
|
|
gimplifier has changed all non-empty RETURN_EXPRs to
|
|
return the RESULT_DECL. */
|
|
ret_val = gimple_return_retval (return_stmt);
|
|
if (ret_val)
|
|
gcc_assert (ret_val == result);
|
|
}
|
|
else if (gimple_has_lhs (stmt)
|
|
&& gimple_get_lhs (stmt) == result)
|
|
{
|
|
tree rhs;
|
|
|
|
if (!gimple_assign_copy_p (stmt))
|
|
return 0;
|
|
|
|
rhs = gimple_assign_rhs1 (stmt);
|
|
|
|
/* Now verify that this return statement uses the same value
|
|
as any previously encountered return statement. */
|
|
if (found != NULL)
|
|
{
|
|
/* If we found a return statement using a different variable
|
|
than previous return statements, then we can not perform
|
|
NRV optimizations. */
|
|
if (found != rhs)
|
|
return 0;
|
|
}
|
|
else
|
|
found = rhs;
|
|
|
|
/* The returned value must be a local automatic variable of the
|
|
same type and alignment as the function's result. */
|
|
if (TREE_CODE (found) != VAR_DECL
|
|
|| TREE_THIS_VOLATILE (found)
|
|
|| !auto_var_in_fn_p (found, current_function_decl)
|
|
|| TREE_ADDRESSABLE (found)
|
|
|| DECL_ALIGN (found) > DECL_ALIGN (result)
|
|
|| !useless_type_conversion_p (result_type,
|
|
TREE_TYPE (found)))
|
|
return 0;
|
|
}
|
|
else if (gimple_has_lhs (stmt))
|
|
{
|
|
tree addr = get_base_address (gimple_get_lhs (stmt));
|
|
/* If there's any MODIFY of component of RESULT,
|
|
then bail out. */
|
|
if (addr && addr == result)
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!found)
|
|
return 0;
|
|
|
|
/* If dumping details, then note once and only the NRV replacement. */
|
|
if (dump_file && (dump_flags & TDF_DETAILS))
|
|
{
|
|
fprintf (dump_file, "NRV Replaced: ");
|
|
print_generic_expr (dump_file, found, dump_flags);
|
|
fprintf (dump_file, " with: ");
|
|
print_generic_expr (dump_file, result, dump_flags);
|
|
fprintf (dump_file, "\n");
|
|
}
|
|
|
|
/* At this point we know that all the return statements return the
|
|
same local which has suitable attributes for NRV. Copy debugging
|
|
information from FOUND to RESULT if it will be useful. But don't set
|
|
DECL_ABSTRACT_ORIGIN to point at another function. */
|
|
if (!DECL_IGNORED_P (found)
|
|
&& !(DECL_ABSTRACT_ORIGIN (found)
|
|
&& DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (found)) != current_function_decl))
|
|
{
|
|
DECL_NAME (result) = DECL_NAME (found);
|
|
DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (found);
|
|
DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (found);
|
|
}
|
|
|
|
TREE_ADDRESSABLE (result) |= TREE_ADDRESSABLE (found);
|
|
|
|
/* Now walk through the function changing all references to VAR to be
|
|
RESULT. */
|
|
data.var = found;
|
|
data.result = result;
|
|
FOR_EACH_BB_FN (bb, fun)
|
|
{
|
|
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); )
|
|
{
|
|
gimple stmt = gsi_stmt (gsi);
|
|
/* If this is a copy from VAR to RESULT, remove it. */
|
|
if (gimple_assign_copy_p (stmt)
|
|
&& gimple_assign_lhs (stmt) == result
|
|
&& gimple_assign_rhs1 (stmt) == found)
|
|
{
|
|
unlink_stmt_vdef (stmt);
|
|
gsi_remove (&gsi, true);
|
|
release_defs (stmt);
|
|
}
|
|
else
|
|
{
|
|
struct walk_stmt_info wi;
|
|
memset (&wi, 0, sizeof (wi));
|
|
wi.info = &data;
|
|
data.modified = 0;
|
|
walk_gimple_op (stmt, finalize_nrv_r, &wi);
|
|
if (data.modified)
|
|
update_stmt (stmt);
|
|
gsi_next (&gsi);
|
|
}
|
|
}
|
|
}
|
|
|
|
SET_DECL_VALUE_EXPR (found, result);
|
|
DECL_HAS_VALUE_EXPR_P (found) = 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
} // anon namespace
|
|
|
|
gimple_opt_pass *
|
|
make_pass_nrv (gcc::context *ctxt)
|
|
{
|
|
return new pass_nrv (ctxt);
|
|
}
|
|
|
|
/* Determine (pessimistically) whether DEST is available for NRV
|
|
optimization, where DEST is expected to be the LHS of a modify
|
|
expression where the RHS is a function returning an aggregate.
|
|
|
|
DEST is available if it is not clobbered or used by the call. */
|
|
|
|
static bool
|
|
dest_safe_for_nrv_p (gcall *call)
|
|
{
|
|
tree dest = gimple_call_lhs (call);
|
|
|
|
dest = get_base_address (dest);
|
|
if (! dest)
|
|
return false;
|
|
|
|
if (TREE_CODE (dest) == SSA_NAME)
|
|
return true;
|
|
|
|
if (call_may_clobber_ref_p (call, dest)
|
|
|| ref_maybe_used_by_stmt_p (call, dest))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
/* Walk through the function looking for GIMPLE_ASSIGNs with calls that
|
|
return in memory on the RHS. For each of these, determine whether it is
|
|
safe to pass the address of the LHS as the return slot, and mark the
|
|
call appropriately if so.
|
|
|
|
The NRV shares the return slot with a local variable in the callee; this
|
|
optimization shares the return slot with the target of the call within
|
|
the caller. If the NRV is performed (which we can't know in general),
|
|
this optimization is safe if the address of the target has not
|
|
escaped prior to the call. If it has, modifications to the local
|
|
variable will produce visible changes elsewhere, as in PR c++/19317. */
|
|
|
|
namespace {
|
|
|
|
const pass_data pass_data_return_slot =
|
|
{
|
|
GIMPLE_PASS, /* type */
|
|
"retslot", /* name */
|
|
OPTGROUP_NONE, /* optinfo_flags */
|
|
TV_NONE, /* tv_id */
|
|
PROP_ssa, /* properties_required */
|
|
0, /* properties_provided */
|
|
0, /* properties_destroyed */
|
|
0, /* todo_flags_start */
|
|
0, /* todo_flags_finish */
|
|
};
|
|
|
|
class pass_return_slot : public gimple_opt_pass
|
|
{
|
|
public:
|
|
pass_return_slot (gcc::context *ctxt)
|
|
: gimple_opt_pass (pass_data_return_slot, ctxt)
|
|
{}
|
|
|
|
/* opt_pass methods: */
|
|
virtual unsigned int execute (function *);
|
|
|
|
}; // class pass_return_slot
|
|
|
|
unsigned int
|
|
pass_return_slot::execute (function *fun)
|
|
{
|
|
basic_block bb;
|
|
|
|
FOR_EACH_BB_FN (bb, fun)
|
|
{
|
|
gimple_stmt_iterator gsi;
|
|
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
|
|
{
|
|
gcall *stmt;
|
|
bool slot_opt_p;
|
|
|
|
stmt = dyn_cast <gcall *> (gsi_stmt (gsi));
|
|
if (stmt
|
|
&& gimple_call_lhs (stmt)
|
|
&& !gimple_call_return_slot_opt_p (stmt)
|
|
&& aggregate_value_p (TREE_TYPE (gimple_call_lhs (stmt)),
|
|
gimple_call_fndecl (stmt)))
|
|
{
|
|
/* Check if the location being assigned to is
|
|
clobbered by the call. */
|
|
slot_opt_p = dest_safe_for_nrv_p (stmt);
|
|
gimple_call_set_return_slot_opt (stmt, slot_opt_p);
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
} // anon namespace
|
|
|
|
gimple_opt_pass *
|
|
make_pass_return_slot (gcc::context *ctxt)
|
|
{
|
|
return new pass_return_slot (ctxt);
|
|
}
|