/* Pointer Bounds Checker optimization pass.
- Copyright (C) 2014 Free Software Foundation, Inc.
+ Copyright (C) 2014-2017 Free Software Foundation, Inc.
Contributed by Ilya Enkovich (ilya.enkovich@intel.com)
This file is part of GCC.
#include "config.h"
#include "system.h"
#include "coretypes.h"
-#include "tree-core.h"
-#include "tree.h"
+#include "backend.h"
#include "target.h"
-#include "tree-cfg.h"
-#include "tree-pass.h"
-#include "is-a.h"
-#include "cfgloop.h"
-#include "stringpool.h"
-#include "tree-ssa-alias.h"
-#include "tree-ssanames.h"
-#include "tree-ssa-operands.h"
-#include "tree-ssa-address.h"
-#include "tree-ssa.h"
-#include "predict.h"
-#include "dominance.h"
-#include "cfg.h"
-#include "basic-block.h"
-#include "tree-ssa-loop-niter.h"
-#include "gimple-expr.h"
+#include "rtl.h"
+#include "tree.h"
#include "gimple.h"
-#include "tree-phinodes.h"
-#include "gimple-ssa.h"
-#include "ssa-iterators.h"
+#include "tree-pass.h"
+#include "ssa.h"
#include "gimple-pretty-print.h"
+#include "diagnostic.h"
+#include "fold-const.h"
+#include "tree-cfg.h"
+#include "tree-ssa-loop-niter.h"
#include "gimple-iterator.h"
-#include "gimplify.h"
-#include "gimplify-me.h"
-#include "expr.h"
#include "tree-chkp.h"
#include "ipa-chkp.h"
-#include "diagnostic.h"
enum check_type
{
/* Bounds used for the check. */
tree bounds;
/* Check statement. Can be NULL for removed checks. */
- gimple stmt;
+ gimple *stmt;
};
/* Structure to hold checks information for BB. */
#define chkp_checku_fndecl \
(targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDCU))
-static vec<struct bb_checks, va_heap, vl_ptr> check_infos = vNULL;
+static vec<struct bb_checks, va_heap, vl_ptr> check_infos;
/* Comparator for pol_item structures I1 and I2 to be used
to find items with equal var. Also used for polynomial
static void
chkp_collect_value (tree ptr, address_t &res)
{
- gimple def_stmt;
+ gimple *def_stmt;
enum gimple_code code;
enum tree_code rhs_code;
address_t addr;
/* Fill check_info structure *CI with information about
check STMT. */
static void
-chkp_fill_check_info (gimple stmt, struct check_info *ci)
+chkp_fill_check_info (gimple *stmt, struct check_info *ci)
{
ci->addr.pol.create (0);
ci->bounds = gimple_call_arg (stmt, 1);
for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
{
- gimple stmt = gsi_stmt (i);
+ gimple *stmt = gsi_stmt (i);
if (gimple_code (stmt) != GIMPLE_CALL)
continue;
static int
chkp_get_check_result (struct check_info *ci, tree bounds)
{
- gimple bnd_def;
+ gimple *bnd_def;
address_t bound_val;
int sign, res = 0;
chkp_collect_value (DECL_INITIAL (bnd_var), bound_val);
if (ci->type == CHECK_UPPER_BOUND)
{
- if (TREE_CODE (var) == VAR_DECL)
+ if (VAR_P (var))
{
if (DECL_SIZE (var)
&& !chkp_variable_size_type (TREE_TYPE (var)))
static void
chkp_use_outer_bounds_if_possible (struct check_info *ci)
{
- gimple bnd_def;
+ gimple *bnd_def;
tree bnd1, bnd2, bnd_res = NULL;
int check_res1, check_res2;
for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
{
- gimple stmt = gsi_stmt (i);
+ gimple *stmt = gsi_stmt (i);
tree fndecl;
if (gimple_code (stmt) != GIMPLE_CALL
checks only when size is not zero. */
if (!known)
{
- gimple check = gimple_build_cond (NE_EXPR,
- size,
- size_zero_node,
- NULL_TREE,
- NULL_TREE);
+ gimple *check = gimple_build_cond (NE_EXPR,
+ size,
+ size_zero_node,
+ NULL_TREE,
+ NULL_TREE);
/* Split block before string function call. */
gsi_prev (&i);
for (i = gsi_start_bb (bb); !gsi_end_p (i); )
{
- gimple dom_use, use_stmt, stmt = gsi_stmt (i);
+ gimple *dom_use, *use_stmt, *stmt = gsi_stmt (i);
basic_block dom_bb;
ssa_op_iter iter;
imm_use_iterator use_iter;
FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, op)
{
+ if (is_gimple_debug (use_stmt))
+ continue;
+
if (dom_bb &&
dominated_by_p (CDI_DOMINATORS,
dom_bb, gimple_bb (use_stmt)))
gsi_move_before (&i, &gsi);
}
+ gimple_set_vdef (stmt, NULL_TREE);
+ gimple_set_vuse (stmt, NULL_TREE);
update_stmt (stmt);
}
}
chkp_opt_fini (void)
{
chkp_fix_cfg ();
+
+ free_dominance_info (CDI_POST_DOMINATORS);
}
/* Checker optimization pass function. */