GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "gimple.h"
#include "flags.h"
#include "basic-block.h"
#include "function.h"
#include "tree-pretty-print.h"
#include "bitmap.h"
#include "gimple-ssa.h"
#include "tree-ssanames.h"
#include "tree-dfa.h"
#include "tree-inline.h"
#include "hashtab.h"
#include "tree-ssa-live.h"
#include "tree-pass.h"
#include "langhooks.h"
Functions | |
static void | copy_rename_partition_coalesce () |
static unsigned int | rename_ssa_copies () |
static bool | gate_copyrename () |
gimple_opt_pass * | make_pass_rename_ssa_copies () |
Variables | |
struct { | |
int coalesced | |
} | stats |
|
static |
The following routines implement the SSA copy renaming phase.
This optimization looks for copies between 2 SSA_NAMES, either through a direct copy, or an implicit one via a PHI node result and its arguments.
Each copy is examined to determine if it is possible to rename the base variable of one of the operands to the same variable as the other operand. i.e. T.3_5 = <blah> a_1 = T.3_5
If this copy couldn't be copy propagated, it could possibly remain in the program throughout the optimization phases. After SSA->normal, it would become:
T.3 = <blah> a = T.3
Since T.3_5 is distinct from all other SSA versions of T.3, there is no fundamental reason why the base variable needs to be T.3, subject to certain restrictions. This optimization attempts to determine if we can change the base variable on copies like this, and result in code such as:
a_5 = <blah> a_1 = a_5
This gives the SSA->normal pass a shot at coalescing a_1 and a_5. If it is possible, the copy goes away completely. If it isn't possible, a new temp will be created for a_5, and you will end up with the exact same code:
a.8 = <blah> a = a.8
The other benefit of performing this optimization relates to what variables are chosen in copies. Gimplification of the program uses temporaries for a lot of things. expressions like
a_1 = <blah> <blah2> = a_1
get turned into
T.3_5 = <blah> a_1 = T.3_5 <blah2> = a_1
Copy propagation is done in a forward direction, and if we can propagate through the copy, we end up with:
T.3_5 = <blah> <blah2> = T.3_5
The copy is gone, but so is all reference to the user variable 'a'. By performing this optimization, we would see the sequence:
a_5 = <blah> a_1 = a_5 <blah2> = a_1
which copy propagation would then turn into:
a_5 = <blah> <blah2> = a_5
and so we still retain the user variable whenever possible. Coalesce the partitions in MAP representing VAR1 and VAR2 if it is valid. Choose a representative for the partition, and send debug info to DEBUG.
Don't coalesce if one of the variables occurs in an abnormal PHI.
Partitions already have the same root, simply merge them.
Never attempt to coalesce 2 different parameters.
Refrain from coalescing user variables, if requested.
If both values have default defs, we can't coalesce. If only one has a tag, make sure that variable is the new root partition.
Do not coalesce if we cannot assign a symbol to the partition.
Don't coalesce if the new chosen root variable would be read-only. If both ign1 && ign2, then the root var of the larger partition wins, so reject in that case if any of the root vars is TREE_READONLY. Otherwise reject only if the root var, on which replace_ssa_name_symbol will be called below, is readonly.
Don't coalesce if the two variables aren't type compatible .
There is a disconnect between the middle-end type-system and VRP, avoid coalescing enum types with different bounds.
Merge the two partitions.
Set the root variable of the partition to the better choice, if there is one.
|
static |
Return true if copy rename is to be performed.
References opt_pass::clone(), opt_pass::execute(), opt_pass::gate(), gimple_opt_pass::gimple_opt_pass(), and rename_ssa_copies().
gimple_opt_pass* make_pass_rename_ssa_copies | ( | ) |
|
static |
This function will make a pass through the IL, and attempt to coalesce any SSA versions which occur in PHI's or copies. Coalescing is accomplished by changing the underlying root variable of all coalesced version. This will then cause the SSA->normal pass to attempt to coalesce them all to the same variable.
Scan for real copies.
Treat PHI nodes as copies between the result and each argument.
Do not process virtual SSA_NAMES.
Make sure to only use the same partition for an argument as the result but never the other way around.
Else if all arguments are in the same partition try to merge it with the result.
Now one more pass to make all elements of a partition share the same root variable.
Referenced by gate_copyrename().
int coalesced |
Number of copies coalesced.
struct { ... } stats |
Rename SSA copies. Copyright (C) 2004-2013 Free Software Foundation, Inc. Contributed by Andrew MacLeod amacl eod@ redha t.co m
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/.