This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add verifier for virtual SSA form
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 15 Aug 2016 15:08:44 +0200 (CEST)
- Subject: [PATCH] Add verifier for virtual SSA form
- Authentication-results: sourceware.org; auth=none
This adds a verifier that makes sure no overlapping life-ranges occur
for virtuals.
Bootstrap and regtest running on x86_64-unknown-linux-gnu.
Richard.
2016-08-15 Richard Biener <rguenther@suse.de>
* tree-ssa.c: Include tree-cfg.h and tree-dfa.h.
(verify_vssa): New function verifying virtual SSA form.
(verify_ssa): Call it.
Index: gcc/tree-ssa.c
===================================================================
*** gcc/tree-ssa.c (revision 239473)
--- gcc/tree-ssa.c (working copy)
*************** along with GCC; see the file COPYING3.
*** 39,44 ****
--- 39,46 ----
#include "tree-ssa.h"
#include "cfgloop.h"
#include "cfgexpand.h"
+ #include "tree-cfg.h"
+ #include "tree-dfa.h"
/* Pointer map of variable mappings, keyed by edge. */
static hash_map<edge, auto_vec<edge_var_map> > *edge_var_maps;
*************** release_defs_bitset (bitmap toremove)
*** 603,608 ****
--- 605,669 ----
}
}
+ /* Verify virtual SSA form. */
+
+ bool
+ verify_vssa (basic_block bb, tree current_vdef, sbitmap visited)
+ {
+ if (bitmap_bit_p (visited, bb->index))
+ return false;
+
+ bitmap_set_bit (visited, bb->index);
+
+ /* Pick up virtual PHI def. */
+ gphi *phi = get_virtual_phi (bb);
+ if (phi)
+ current_vdef = gimple_phi_result (phi);
+
+ /* Verify stmts. */
+ bool err = false;
+ for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
+ gsi_next (&gsi))
+ {
+ gimple *stmt = gsi_stmt (gsi);
+ tree vuse = gimple_vuse (stmt);
+ if (vuse)
+ {
+ if (vuse != current_vdef)
+ {
+ error ("stmt with wrong VUSE %qD, expected %qD",
+ vuse, current_vdef);
+ print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
+ err = true;
+ }
+ tree vdef = gimple_vdef (stmt);
+ if (vdef)
+ current_vdef = vdef;
+ }
+ }
+
+ /* Verify destination PHI uses and recurse. */
+ edge_iterator ei;
+ edge e;
+ FOR_EACH_EDGE (e, ei, bb->succs)
+ {
+ gphi *phi = get_virtual_phi (e->dest);
+ if (phi
+ && PHI_ARG_DEF_FROM_EDGE (phi, e) != current_vdef)
+ {
+ error ("PHI node with wrong VUSE %qD, expected %qD",
+ PHI_ARG_DEF_FROM_EDGE (phi, e), current_vdef);
+ print_gimple_stmt (stderr, phi, 0, TDF_VOPS);
+ err = true;
+ }
+
+ /* Recurse. */
+ err |= verify_vssa (e->dest, current_vdef, visited);
+ }
+
+ return err;
+ }
+
/* Return true if SSA_NAME is malformed and mark it visited.
IS_VIRTUAL is true if this SSA_NAME was found inside a virtual
*************** verify_ssa (bool check_modified_stmt, bo
*** 1024,1029 ****
--- 1110,1125 ----
free (definition_block);
+ if (gimple_vop (cfun)
+ && ssa_default_def (cfun, gimple_vop (cfun)))
+ {
+ auto_sbitmap visited (last_basic_block_for_fn (cfun) + 1);
+ bitmap_clear (visited);
+ if (verify_vssa (ENTRY_BLOCK_PTR_FOR_FN (cfun),
+ ssa_default_def (cfun, gimple_vop (cfun)), visited))
+ goto err;
+ }
+
/* Restore the dominance information to its prior known state, so
that we do not perturb the compiler's subsequent behavior. */
if (orig_dom_state == DOM_NONE)