2015-06-25 Zhouyi Zhou <yizhouzhou@ict.ac.cn>
[official-gcc.git] / gcc / target-globals.c
blob608601edb44569a7343c0696327795854bf70193
1 /* Target-dependent globals.
2 Copyright (C) 2010-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "insn-config.h"
25 #include "alias.h"
26 #include "symtab.h"
27 #include "tree.h"
28 #include "toplev.h"
29 #include "target-globals.h"
30 #include "flags.h"
31 #include "regs.h"
32 #include "rtl.h"
33 #include "hard-reg-set.h"
34 #include "reload.h"
35 #include "expmed.h"
36 #include "function.h"
37 #include "dojump.h"
38 #include "explow.h"
39 #include "calls.h"
40 #include "emit-rtl.h"
41 #include "varasm.h"
42 #include "stmt.h"
43 #include "expr.h"
44 #include "insn-codes.h"
45 #include "optabs.h"
46 #include "libfuncs.h"
47 #include "cfgloop.h"
48 #include "ira-int.h"
49 #include "builtins.h"
50 #include "gcse.h"
51 #include "bb-reorder.h"
52 #include "lower-subreg.h"
53 #include "recog.h"
55 #if SWITCHABLE_TARGET
56 struct target_globals default_target_globals = {
57 &default_target_flag_state,
58 &default_target_regs,
59 &default_target_rtl,
60 &default_target_recog,
61 &default_target_hard_regs,
62 &default_target_reload,
63 &default_target_expmed,
64 &default_target_optabs,
65 &default_target_libfuncs,
66 &default_target_cfgloop,
67 &default_target_ira,
68 &default_target_ira_int,
69 &default_target_builtins,
70 &default_target_gcse,
71 &default_target_bb_reorder,
72 &default_target_lower_subreg
75 struct target_globals *
76 save_target_globals (void)
78 struct target_globals *g = ggc_cleared_alloc <target_globals> ();
79 g->flag_state = XCNEW (struct target_flag_state);
80 g->regs = XCNEW (struct target_regs);
81 g->rtl = ggc_cleared_alloc<target_rtl> ();
82 g->recog = XCNEW (struct target_recog);
83 g->hard_regs = XCNEW (struct target_hard_regs);
84 g->reload = XCNEW (struct target_reload);
85 g->expmed = XCNEW (struct target_expmed);
86 g->optabs = XCNEW (struct target_optabs);
87 g->libfuncs = ggc_cleared_alloc<target_libfuncs> ();
88 g->cfgloop = XCNEW (struct target_cfgloop);
89 g->ira = XCNEW (struct target_ira);
90 g->ira_int = XCNEW (struct target_ira_int);
91 g->builtins = XCNEW (struct target_builtins);
92 g->gcse = XCNEW (struct target_gcse);
93 g->bb_reorder = XCNEW (struct target_bb_reorder);
94 g->lower_subreg = XCNEW (struct target_lower_subreg);
95 restore_target_globals (g);
96 init_reg_sets ();
97 target_reinit ();
98 return g;
101 /* Like save_target_globals() above, but set *this_target_optabs
102 correctly when a previous function has changed
103 *this_target_optabs. */
105 struct target_globals *
106 save_target_globals_default_opts ()
108 struct target_globals *globals;
110 if (optimization_current_node != optimization_default_node)
112 tree opts = optimization_current_node;
113 /* Temporarily switch to the default optimization node, so that
114 *this_target_optabs is set to the default, not reflecting
115 whatever a previous function used for the optimize
116 attribute. */
117 optimization_current_node = optimization_default_node;
118 cl_optimization_restore
119 (&global_options,
120 TREE_OPTIMIZATION (optimization_default_node));
121 globals = save_target_globals ();
122 optimization_current_node = opts;
123 cl_optimization_restore (&global_options,
124 TREE_OPTIMIZATION (opts));
125 return globals;
127 return save_target_globals ();
130 target_globals::~target_globals ()
132 /* default_target_globals points to static data so shouldn't be freed. */
133 if (this != &default_target_globals)
135 ira_int->~target_ira_int ();
136 hard_regs->finalize ();
137 XDELETE (flag_state);
138 XDELETE (regs);
139 XDELETE (recog);
140 XDELETE (hard_regs);
141 XDELETE (reload);
142 XDELETE (expmed);
143 XDELETE (optabs);
144 XDELETE (cfgloop);
145 XDELETE (ira);
146 XDELETE (ira_int);
147 XDELETE (builtins);
148 XDELETE (gcse);
149 XDELETE (bb_reorder);
150 XDELETE (lower_subreg);
154 #endif