1*0bfacb9bSmrg /* Integration of the analyzer with GCC's pass manager.
2*0bfacb9bSmrg Copyright (C) 2019-2020 Free Software Foundation, Inc.
3*0bfacb9bSmrg Contributed by David Malcolm <dmalcolm@redhat.com>.
4*0bfacb9bSmrg
5*0bfacb9bSmrg This file is part of GCC.
6*0bfacb9bSmrg
7*0bfacb9bSmrg GCC is free software; you can redistribute it and/or modify it
8*0bfacb9bSmrg under the terms of the GNU General Public License as published by
9*0bfacb9bSmrg the Free Software Foundation; either version 3, or (at your option)
10*0bfacb9bSmrg any later version.
11*0bfacb9bSmrg
12*0bfacb9bSmrg GCC is distributed in the hope that it will be useful, but
13*0bfacb9bSmrg WITHOUT ANY WARRANTY; without even the implied warranty of
14*0bfacb9bSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15*0bfacb9bSmrg General Public License for more details.
16*0bfacb9bSmrg
17*0bfacb9bSmrg You should have received a copy of the GNU General Public License
18*0bfacb9bSmrg along with GCC; see the file COPYING3. If not see
19*0bfacb9bSmrg <http://www.gnu.org/licenses/>. */
20*0bfacb9bSmrg
21*0bfacb9bSmrg #include "config.h"
22*0bfacb9bSmrg #include "system.h"
23*0bfacb9bSmrg #include "coretypes.h"
24*0bfacb9bSmrg #include "context.h"
25*0bfacb9bSmrg #include "tree-pass.h"
26*0bfacb9bSmrg #include "diagnostic.h"
27*0bfacb9bSmrg #include "options.h"
28*0bfacb9bSmrg #include "analyzer/engine.h"
29*0bfacb9bSmrg
30*0bfacb9bSmrg namespace {
31*0bfacb9bSmrg
32*0bfacb9bSmrg /* Data for the analyzer pass. */
33*0bfacb9bSmrg
34*0bfacb9bSmrg const pass_data pass_data_analyzer =
35*0bfacb9bSmrg {
36*0bfacb9bSmrg IPA_PASS, /* type */
37*0bfacb9bSmrg "analyzer", /* name */
38*0bfacb9bSmrg OPTGROUP_NONE, /* optinfo_flags */
39*0bfacb9bSmrg TV_ANALYZER, /* tv_id */
40*0bfacb9bSmrg PROP_ssa, /* properties_required */
41*0bfacb9bSmrg 0, /* properties_provided */
42*0bfacb9bSmrg 0, /* properties_destroyed */
43*0bfacb9bSmrg 0, /* todo_flags_start */
44*0bfacb9bSmrg 0, /* todo_flags_finish */
45*0bfacb9bSmrg };
46*0bfacb9bSmrg
47*0bfacb9bSmrg /* The analyzer pass. */
48*0bfacb9bSmrg
49*0bfacb9bSmrg class pass_analyzer : public ipa_opt_pass_d
50*0bfacb9bSmrg {
51*0bfacb9bSmrg public:
pass_analyzer(gcc::context * ctxt)52*0bfacb9bSmrg pass_analyzer(gcc::context *ctxt)
53*0bfacb9bSmrg : ipa_opt_pass_d (pass_data_analyzer, ctxt,
54*0bfacb9bSmrg NULL, /* generate_summary */
55*0bfacb9bSmrg NULL, /* write_summary */
56*0bfacb9bSmrg NULL, /* read_summary */
57*0bfacb9bSmrg NULL, /* write_optimization_summary */
58*0bfacb9bSmrg NULL, /* read_optimization_summary */
59*0bfacb9bSmrg NULL, /* stmt_fixup */
60*0bfacb9bSmrg 0, /* function_transform_todo_flags_start */
61*0bfacb9bSmrg NULL, /* function_transform */
62*0bfacb9bSmrg NULL) /* variable_transform */
63*0bfacb9bSmrg {}
64*0bfacb9bSmrg
65*0bfacb9bSmrg /* opt_pass methods: */
66*0bfacb9bSmrg bool gate (function *) FINAL OVERRIDE;
67*0bfacb9bSmrg unsigned int execute (function *) FINAL OVERRIDE;
68*0bfacb9bSmrg }; // class pass_analyzer
69*0bfacb9bSmrg
70*0bfacb9bSmrg /* Only run the analyzer if -fanalyzer. */
71*0bfacb9bSmrg
72*0bfacb9bSmrg bool
gate(function *)73*0bfacb9bSmrg pass_analyzer::gate (function *)
74*0bfacb9bSmrg {
75*0bfacb9bSmrg return flag_analyzer != 0;
76*0bfacb9bSmrg }
77*0bfacb9bSmrg
78*0bfacb9bSmrg /* Entrypoint for the analyzer pass. */
79*0bfacb9bSmrg
80*0bfacb9bSmrg unsigned int
execute(function *)81*0bfacb9bSmrg pass_analyzer::execute (function *)
82*0bfacb9bSmrg {
83*0bfacb9bSmrg #if ENABLE_ANALYZER
84*0bfacb9bSmrg ana::run_checkers ();
85*0bfacb9bSmrg #else
86*0bfacb9bSmrg sorry ("%qs was not enabled in this build of GCC"
87*0bfacb9bSmrg " (missing configure-time option %qs)",
88*0bfacb9bSmrg "-fanalyzer", "--enable-analyzer");
89*0bfacb9bSmrg #endif
90*0bfacb9bSmrg
91*0bfacb9bSmrg return 0;
92*0bfacb9bSmrg }
93*0bfacb9bSmrg
94*0bfacb9bSmrg } // anon namespace
95*0bfacb9bSmrg
96*0bfacb9bSmrg /* Make an instance of the analyzer pass. */
97*0bfacb9bSmrg
98*0bfacb9bSmrg ipa_opt_pass_d *
make_pass_analyzer(gcc::context * ctxt)99*0bfacb9bSmrg make_pass_analyzer (gcc::context *ctxt)
100*0bfacb9bSmrg {
101*0bfacb9bSmrg return new pass_analyzer (ctxt);
102*0bfacb9bSmrg }
103