GCC Middle and Back End API Reference
tree-ssa-strlen.c File Reference

Data Structures

struct  strinfo_struct
struct  stridxlist
struct  decl_stridxlist_map
struct  stridxlist_hasher
struct  laststmt_struct

Typedefs

typedef struct strinfo_structstrinfo

Functions

static int get_addr_stridx ()
static int get_stridx ()
static bool strinfo_shared ()
static void unshare_strinfo_vec ()
static int * addr_stridxptr ()
static int new_stridx ()
static int new_addr_stridx ()
static strinfo new_strinfo ()
static void free_strinfo ()
static strinfo get_strinfo ()
static void set_strinfo ()
static tree get_string_length ()
static bool maybe_invalidate ()
static strinfo unshare_strinfo ()
static strinfo verify_related_strinfos ()
static strinfo zero_length_string ()
static void adjust_related_strinfos ()
static void find_equal_ptrs ()
static void adjust_last_stmt ()
static void handle_builtin_strlen ()
static void handle_builtin_strchr ()
static void handle_builtin_strcpy ()
static void handle_builtin_memcpy ()
static void handle_builtin_strcat ()
static void handle_pointer_plus ()
static bool handle_char_store ()
static bool strlen_optimize_stmt ()
static void do_invalidate ()
static void strlen_enter_block (struct dom_walk_data *walk_data, basic_block bb)
static void strlen_leave_block (struct dom_walk_data *walk_data, basic_block bb)
static unsigned int tree_ssa_strlen ()
static bool gate_strlen ()
gimple_opt_passmake_pass_strlen ()

Variables

static vec< int > ssa_ver_to_stridx
static int max_stridx
static alloc_pool strinfo_pool
static vec< strinfo, va_heap,
vl_embed > * 
stridx_to_strinfo
static hash_table
< stridxlist_hasher
decl_to_stridxlist_htab
static struct obstack stridx_obstack
struct laststmt_struct laststmt

Typedef Documentation

typedef struct strinfo_struct * strinfo
String information record.   

Function Documentation

static int* addr_stridxptr ( )
static
Attempt to create a string index for exp, ADDR_EXPR's operand.
   Return a pointer to the location where the string index can
   be stored (if 0) or is stored, or NULL if this can't be tracked.   

References decl_stridxlist_map::base, hash_table< Descriptor, Allocator >::create(), hash_table< Descriptor, Allocator >::find_slot_with_hash(), tree_map_base::from, get_addr_base_and_unit_offset(), HOST_WIDE_INT, stridxlist::idx, hash_table< Descriptor, Allocator >::is_created(), decl_stridxlist_map::list, stridxlist::next, stridxlist::offset, and stridx_obstack.

Referenced by find_equal_ptrs(), new_addr_stridx(), and new_stridx().

static void adjust_related_strinfos ( )
static
static void do_invalidate ( )
static
Recursively call maybe_invalidate on stmts that might be executed
   in between dombb and current bb and that contain a vdef.  Stop when
   *count stmts are inspected, or if the whole strinfo vector has
   been invalidated.   

References bitmap_set_bit(), CDI_DOMINATORS, dominated_by_p(), gimple_bb(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_vuse(), basic_block_def::index, maybe_invalidate(), and laststmt_struct::stmt.

Referenced by strlen_enter_block().

static void find_equal_ptrs ( )
static
Find if there are other SSA_NAME pointers equal to PTR
   for which we don't track their string lengths yet.  If so, use
   IDX for them.   

References addr_stridxptr(), gimple_assign_rhs1(), gimple_assign_rhs_code(), and is_gimple_assign().

Referenced by handle_builtin_memcpy(), handle_builtin_strcat(), handle_builtin_strchr(), handle_builtin_strcpy(), and handle_builtin_strlen().

static void free_strinfo ( )
inlinestatic
Decrease strinfo refcount and free it if not referenced anymore.   

References pool_free(), and strinfo_struct::refcount.

Referenced by maybe_invalidate(), strlen_leave_block(), and unshare_strinfo().

static bool gate_strlen ( )
static
static void handle_builtin_strchr ( )
static
static void handle_builtin_strlen ( )
static
static void handle_pointer_plus ( )
static
Handle a POINTER_PLUS_EXPR statement.
   For p = "abcd" + 2; compute associated length, or if
   p = q + off is pointing to a '\0' character of a string, call
   zero_length_string on it.   

References strinfo_struct::endptr, get_stridx(), get_strinfo(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_set_rhs_with_ops(), gimple_assign_single_p(), gsi_stmt(), host_integerp(), HOST_WIDE_INT, strinfo_struct::length, operand_equal_p(), si, laststmt_struct::stmt, tree_low_cst(), update_stmt(), useless_type_conversion_p(), and zero_length_string().

Referenced by strlen_optimize_stmt().

gimple_opt_pass* make_pass_strlen ( )
static bool maybe_invalidate ( )
static
Invalidate string length information for strings whose length
   might change due to stores in stmt.   

References ao_ref_init_from_ptr_and_size(), strinfo_struct::dont_invalidate, free_strinfo(), strinfo_struct::ptr, set_strinfo(), si, stmt_may_clobber_ref_p_1(), and vec_safe_iterate().

Referenced by do_invalidate(), and strlen_optimize_stmt().

static int new_addr_stridx ( )
static
Like new_stridx, but for ADDR_EXPR's operand instead.   

References addr_stridxptr(), and max_stridx.

Referenced by handle_char_store().

static int new_stridx ( )
static
static bool strinfo_shared ( )
inlinestatic
Return true if strinfo vector is shared with the immediate dominator.   

References vec_safe_length().

Referenced by strlen_enter_block(), unshare_strinfo(), and unshare_strinfo_vec().

static void strlen_enter_block ( struct dom_walk_data walk_data,
basic_block  bb 
)
static
static void strlen_leave_block ( struct dom_walk_data walk_data,
basic_block  bb 
)
static
Callback for walk_dominator_tree.  Free strinfo vector if it is
   owned by the current bb, clear bb->aux.   

References basic_block_def::aux, free_strinfo(), si, vec_free(), vec_safe_iterate(), and vec_safe_length().

Referenced by tree_ssa_strlen().

static void unshare_strinfo_vec ( )
static
Unshare strinfo vector that is shared with the immediate dominator.   

References strinfo_struct::refcount, si, strinfo_shared(), vec_safe_copy(), and vec_safe_iterate().

Referenced by set_strinfo().

static strinfo verify_related_strinfos ( )
static
Return first strinfo in the related strinfo chain
   if all strinfos in between belong to the chain, otherwise
   NULL.   

References strinfo_struct::first, get_strinfo(), strinfo_struct::idx, strinfo_struct::prev, and si.

Referenced by adjust_last_stmt(), adjust_related_strinfos(), handle_builtin_strcpy(), and zero_length_string().

static strinfo zero_length_string ( )
static
Note that PTR, a pointer SSA_NAME initialized in the current stmt, points
   to a zero-length string and if possible chain it to a related strinfo
   chain whose part is or might be CHAINSI.   

References build_int_cst(), strinfo_struct::endptr, strinfo_struct::first, get_stridx(), get_strinfo(), strinfo_struct::idx, integer_zerop(), strinfo_struct::length, new_stridx(), new_strinfo(), strinfo_struct::next, strinfo_struct::prev, set_strinfo(), si, strinfo_struct::stmt, unshare_strinfo(), verify_related_strinfos(), and strinfo_struct::writable.

Referenced by handle_builtin_strchr(), handle_builtin_strcpy(), handle_char_store(), and handle_pointer_plus().


Variable Documentation

hash_table<stridxlist_hasher> decl_to_stridxlist_htab
static
Hash table for mapping decls to a chained list of offset -> idx
   mappings.   
int max_stridx
static
Number of currently active string indexes plus one.   

Referenced by new_addr_stridx(), new_stridx(), and tree_ssa_strlen().

vec<int> ssa_ver_to_stridx
static
@verbatim String length optimization

Copyright (C) 2011-2013 Free Software Foundation, Inc. Contributed by Jakub Jelinek jakub.nosp@m.@red.nosp@m.hat.c.nosp@m.om

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/.

A vector indexed by SSA_NAME_VERSION.  0 means unknown, positive value
   is an index into strinfo vector, negative value stands for
   string length of a string literal (~strlen).   
struct obstack stridx_obstack
static
Obstack for struct stridxlist and struct decl_stridxlist_map.   

Referenced by addr_stridxptr(), and tree_ssa_strlen().

vec<strinfo, va_heap, vl_embed>* stridx_to_strinfo
static
Vector mapping positive string indexes to strinfo, for the
   current basic block.  The first pointer in the vector is special,
   it is either NULL, meaning the vector isn't shared, or it is
   a basic block pointer to the owner basic_block if shared.
   If some other bb wants to modify the vector, the vector needs
   to be unshared first, and only the owner bb is supposed to free it.   

Referenced by strlen_enter_block().

alloc_pool strinfo_pool
static
Pool for allocating strinfo_struct entries.