GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "flags.h"
#include "function.h"
#include "gimple-pretty-print.h"
#include "bitmap.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
#include "tree-ssanames.h"
#include "tree-inline.h"
#include "timevar.h"
#include "dumpfile.h"
#include "ggc.h"
#include "langhooks.h"
#include "diagnostic-core.h"
Macros | |
#define | opf_use 0 |
#define | opf_def (1 << 0) |
#define | opf_no_vops (1 << 1) |
#define | opf_implicit (1 << 2) |
#define | opf_non_addressable (1 << 3) |
#define | opf_not_non_addressable (1 << 4) |
#define | OP_SIZE_INIT 0 |
#define | OP_SIZE_1 (1024 - sizeof (void *)) |
#define | OP_SIZE_2 (1024 * 4 - sizeof (void *)) |
#define | OP_SIZE_3 (1024 * 16 - sizeof (void *)) |
Variables | |
static vec< tree > | build_uses |
static tree | build_vdef |
static tree | build_vuse |
static bitmap_obstack | operands_bitmap_obstack |
static int | n_initialized = 0 |
#define OP_SIZE_1 (1024 - sizeof (void *)) |
#define OP_SIZE_2 (1024 * 4 - sizeof (void *)) |
#define OP_SIZE_3 (1024 * 16 - sizeof (void *)) |
#define OP_SIZE_INIT 0 |
These are the sizes of the operand memory buffer in bytes which gets allocated each time more operands space is required. The final value is the amount that is allocated every time after that. In 1k we can fit 25 use operands (or 63 def operands) on a host with 8 byte pointers, that would be 10 statements each with 1 def and 2 uses.
#define opf_def (1 << 0) |
Operand is the target of an assignment expression or a call-clobbered variable.
#define opf_implicit (1 << 2) |
Operand is an implicit reference. This is used to distinguish explicit assignments in the form of MODIFY_EXPR from clobbering sites like function calls or ASM_EXPRs.
#define opf_no_vops (1 << 1) |
No virtual operands should be created in the expression. This is used when traversing ADDR_EXPR nodes which have different semantics than other expressions. Inside an ADDR_EXPR node, the only operands that we need to consider are indices into arrays. For instance, &a.b[i] should generate a USE of 'i' but it should not generate a VUSE for 'a' nor a VUSE for 'b'.
Referenced by append_use(), and get_asm_expr_operands().
#define opf_non_addressable (1 << 3) |
Operand is in a place where address-taken does not imply addressable.
Referenced by get_asm_expr_operands().
#define opf_not_non_addressable (1 << 4) |
Operand is in a place where opf_non_addressable does not apply.
Referenced by get_asm_expr_operands().
#define opf_use 0 |
SSA operands management for trees. Copyright (C) 2003-2013 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/. This file contains the code required to manage the operands cache of the SSA optimizer. For every stmt, we maintain an operand cache in the stmt annotation. This cache contains operands that will be of interest to optimizers and other passes wishing to manipulate the IL.
The operand type are broken up into REAL and VIRTUAL operands. The real operands are represented as pointers into the stmt's operand tree. Thus any manipulation of the real operands will be reflected in the actual tree. Virtual operands are represented solely in the cache, although the base variable for the SSA_NAME may, or may not occur in the stmt's tree. Manipulation of the virtual operands will not be reflected in the stmt tree.
The routines in this file are concerned with creating this operand cache from a stmt tree.
The operand tree is the parsed by the various get_* routines which look through the stmt tree for the occurrence of operands which may be of interest, and calls are made to the append_* routines whenever one is found. There are 4 of these routines, each representing one of the 4 types of operands. Defs, Uses, Virtual Uses, and Virtual May Defs.
The append_* routines check for duplication, and simply keep a list of unique objects for each operand type in the build_* extendable vectors.
Once the stmt tree is completely parsed, the finalize_ssa_operands() routine is called, which proceeds to perform the finalization routine on each of the 4 operand vectors which have been built up.
If the stmt had a previous operand cache, the finalization routines attempt to match up the new operands with the old ones. If it's a perfect match, the old vector is simply reused. If it isn't a perfect match, then a new vector is created and the new operands are placed there. For virtual operands, if the previous cache had SSA_NAME version of a variable, and that same variable occurs in the same operands cache, then the new cache vector will also get the same SSA_NAME.
i.e., if a stmt had a VUSE of 'a_5', and 'a' occurs in the new operand vector for VUSE, then the new vector will also be modified such that it contains 'a_5' rather than 'a'. Flags to describe operand properties in helpers. By default, operands are loaded.
Referenced by get_asm_expr_operands(), and mark_address_taken().
|
static |
Add *VAR_P to the appropriate operand array for statement STMT. FLAGS is as in get_expr_operands. If *VAR_P is a GIMPLE register, it will be added to the statement's real operands, otherwise it is added to virtual operands.
The variable is a GIMPLE register. Add it to real operands.
Mark statements with volatile operands.
The variable is a memory access. Add virtual operands.
Referenced by get_asm_expr_operands().
|
inlinestatic |
Adds OP to the list of uses of statement STMT after LAST.
|
static |
Add virtual operands for STMT. FLAGS is as in get_expr_operands.
Add virtual operands to the stmt, unless the caller has specifically requested not to do that (used when adding operands inside an ADDR_EXPR expression).
Referenced by mark_address_taken().
|
staticread |
Allocate a USE operand.
|
inlinestatic |
Add USE_P to the list of pointers to operands.
References opf_no_vops.
|
inlinestatic |
Add VAR to the set of variables that require a VDEF operator.
|
inlinestatic |
Add VAR to the set of variables that require a VUSE operator.
|
static |
Create an operands cache for STMT.
Initially assume that the statement has no volatile operands.
References debug_generic_expr(), and error().
|
inlinestatic |
Clear the in_list bits and empty the build array for VDEFs and VUSEs.
|
static |
Create the VOP variable, an artificial global variable to act as a representative of all of the virtual operands FUD chain.
DEBUG_FUNCTION void debug_immediate_uses | ( | void | ) |
Dump def-use edges on stderr.
DEBUG_FUNCTION void debug_immediate_uses_for | ( | ) |
Dump def-use edges on stderr.
void dump_immediate_uses | ( | ) |
Dump all the immediate uses to FILE.
void dump_immediate_uses_for | ( | ) |
Dump all the immediate uses to FILE.
References is_gimple_debug(), ssa_use_operand_d::next, and USE_STMT.
|
inlinestatic |
Takes elements from build_defs and turns them into def operands of STMT. TODO – Make build_defs vec of tree *.
Pre-pend the vdef we may have built.
Clear and unlink a no longer necessary VDEF.
If we have a non-SSA_NAME VDEF, mark it for renaming.
References cfun.
|
inlinestatic |
Finalize all the build vectors, fill the new ones into INFO.
|
inlinestatic |
Takes elements from build_uses and turns them into use operands of STMT. TODO – Make build_uses vec of tree *.
Pre-pend the VUSE we may have built.
Clear a no longer necessary VUSE.
If there is anything in the old list, free it.
If we added a VUSE, make sure to set the operand if it is not already present and mark it for renaming.
Now create nodes for all the new nodes.
Now set the stmt's operands.
References cfun, delink_imm_use(), ssa_operands::free_uses, gimple_ssa_operands(), and USE_OP_PTR.
void fini_ssa_operands | ( | void | ) |
Dispose of anything required by the operand routines.
Referenced by execute_init_datastructures().
void free_stmt_operands | ( | ) |
Releases the operands of STMT back to their freelists, and clears the stmt operand lists.
|
static |
Scan operands in the ASM_EXPR stmt referred to in INFO.
Gather all output operands.
This should have been split in gimplify_asm_expr.
Memory operands are addressable. Note that STMT needs the address of this operand.
Gather all input operands.
Memory operands are addressable. Note that STMT needs the address of this operand.
Clobber all memory and addressable symbols for asm ("" : : : "memory");
References add_stmt_operand(), gcc_assert, get_expr_operands(), get_indirect_ref_operands(), get_tmr_operands(), gimple_debug_bind_p(), is_gimple_debug(), is_gimple_min_invariant(), mark_address_taken(), NULL, opf_no_vops, opf_non_addressable, opf_not_non_addressable, opf_use, TREE_CODE, TREE_CODE_CLASS, and TREE_OPERAND.
Referenced by get_asm_expr_operands(), get_expr_operands(), and mark_address_taken().
|
static |
Recursively scan the expression pointed to by EXPR_P in statement STMT. FLAGS is one of the OPF_* constants modifying how to interpret the operands found.
Taking the address of a variable does not represent a reference to it, but the fact that the statement takes its address will be of interest to some passes (e.g. alias resolution).
If the address is invariant, there may be no interesting variable references inside.
Otherwise, there may be variables referenced inside but there should be no VUSEs created, since the referenced objects are not really accessed. The only operands that we should find here are ARRAY_REF indices which will always be real operands (GIMPLE does not allow non-registers as array indices).
WITH_SIZE_EXPR is a pass-through reference to its first argument, and an rvalue reference to its second argument.
General aggregate CONSTRUCTORs have been decomposed, but they are still in use as the COMPLEX_EXPR equivalent for vectors.
A volatile constructor is actually TREE_CLOBBER_P, transfer the volatility to the statement, don't use TREE_CLOBBER_P for mirroring the other uses of THIS_VOLATILE in this file.
FALLTHRU
Expressions that make no memory references.
If we get here, something has gone wrong.
References get_expr_operands(), gimple_set_has_volatile_ops(), TREE_OPERAND, and TREE_THIS_VOLATILE.
|
static |
A subroutine of get_expr_operands to handle MEM_REF.
STMT is the statement being processed, EXPR is the MEM_REF that got us here.
FLAGS is as in get_expr_operands.
Add the VOP.
If requested, add a USE operand for the base pointer.
Referenced by get_asm_expr_operands().
|
static |
A subroutine of get_expr_operands to handle TARGET_MEM_REF.
First record the real operands.
Referenced by get_asm_expr_operands().
|
staticread |
Accessor to tree-ssa-operands.c caches.
Referenced by finalize_ssa_uses(), and init_ssa_operands().
bool has_zero_uses_1 | ( | ) |
Return true if the var whose chain of uses starts at PTR has no nondebug uses.
void init_ssa_operands | ( | ) |
Initialize the operand cache routines.
References build_vdef, build_vuse, cfun, ssa_operands::free_uses, ggc_free(), gimple_ssa_operands(), n_initialized, ssa_operand_memory_d::next, NULL, NULL_TREE, and ssa_operands::operand_memory.
|
static |
Mark the base address of REF as having its address taken. REF may be a single variable whose address has been taken or any other valid GIMPLE memory reference (structure reference, array, etc).
Note that it is NOT OKAY to use the target of a COMPONENT_REF as the only thing we take the address of. If VAR is a structure, taking the address of a field means that the whole structure may be referenced using pointer arithmetic. See PR 21407 and the ensuing mailing list discussion.
References add_virtual_operand(), get_expr_operands(), gimple_set_has_volatile_ops(), opf_use, TMR_BASE, TMR_INDEX, TMR_INDEX2, and TREE_THIS_VOLATILE.
Referenced by get_asm_expr_operands().
|
static |
If STMT is a call that may clobber globals and other symbols that escape, add them to the VDEF/VUSE lists for it.
If aliases have been computed already, add VDEF or VUSE operands for all the symbols that have been found to be call-clobbered.
A 'pure' or a 'const' function never call-clobbers anything. A 'noreturn' function might, but since we don't return anyway there is no point in recording that.
|
static |
Parse STMT looking for operands. When finished, the various build_* operand vectors will have potential operands in them.
The start of a transaction is a memory barrier.
Add call-clobbered operands, if needed.
FALLTHRU
FALLTHRU
bool single_imm_use_1 | ( | const ssa_use_operand_t * | head, |
use_operand_p * | use_p, | ||
gimple * | stmt | ||
) |
Return true if the var whose chain of uses starts at PTR has a single nondebug use. Set USE_P and STMT to that single nondebug use, if so, or to NULL otherwise.
Referenced by next_readonly_imm_use().
|
inlinestatic |
Return memory for an operand of size SIZE.
bool ssa_operands_active | ( | ) |
Return true if the SSA operands cache is active.
Referenced by execute_init_datastructures().
|
inlinestatic |
Start the process of building up operands vectors in INFO.
References build_vuse, gcc_assert, and NULL_TREE.
void swap_ssa_operands | ( | ) |
Swap operands EXP0 and EXP1 in statement STMT. No attempt is done to test the validity of the swap operation.
Attempt to preserve the relative positions of these two operands in their * respective immediate use lists by adjusting their use pointer to point to the new operand position.
Find the 2 operands in the cache, if they are there.
And adjust their location to point to the new position of the operand.
Now swap the data.
References error(), ssa_use_operand_d::next, and ssa_use_operand_d::prev.
void unlink_stmt_vdef | ( | ) |
Unlink STMTs virtual definition from the IL by propagating its use.
Referenced by dse_optimize_stmt(), execute_lower_resx(), fold_gimple_cond(), handle_pointer_plus(), stmt_is_power_of_op(), and update_call_from_tree().
void update_stmt_operands | ( | ) |
Get the operands of statement STMT.
If update_stmt_operands is called before SSA is initialized, do nothing.
If the stmt is a noreturn call queue it to be processed by split_bbs_on_noreturn_calls during cfg cleanup.
References gcc_assert, ssa_use_operand_d::next, and NULL.
DEBUG_FUNCTION bool verify_imm_links | ( | ) |
Scan the immediate_use list for VAR making sure its linked properly. Return TRUE if there is a problem and emit an error message to F.
Avoid infinite loops. 50,000,000 uses probably indicates a problem.
Verify list in the other direction.
Referenced by release_ssa_name().
DEBUG_FUNCTION bool verify_ssa_operands | ( | ) |
Verifies SSA statement operands.
build_ssa_operands w/o finalizing them.
Now verify the built operands are the same as present in STMT.
|
static |
The built VDEF operand.
Referenced by init_ssa_operands().
|
static |
The built VUSE operand.
Referenced by init_ssa_operands(), and start_ssa_stmt_operands().
|
static |
Number of functions with initialized ssa_operands.
Referenced by init_ssa_operands().
|
static |
Bitmap obstack for our datastructures that needs to survive across compilations of multiple functions.