* extend.texi: Improve documentation of volatile asms.
[official-gcc.git] / gcc / except.h
blobb6450d3535eacc3a5fd946f3a933f1569886a352
1 /* Exception Handling interface routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Mike Stump <mrs@cygnus.com>.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #if !defined(NULL_RTX) && !defined(rtx)
23 typedef struct rtx_def *_except_rtx;
24 #define rtx _except_rtx
25 #endif
27 #ifdef TREE_CODE
29 /* A stack of labels. CHAIN points to the next entry in the stack. */
31 struct label_node {
32 union {
33 rtx rlabel;
34 tree tlabel;
35 } u;
36 struct label_node *chain;
39 /* An eh_entry is used to describe one exception handling region.
41 OUTER_CONTEXT is the label used for rethrowing into the outer context.
43 EXCEPTION_HANDLER_LABEL is the label corresponding to the handler
44 for this region.
46 LABEL_USED indicates whether a CATCH block has already used this
47 label or not. New ones are needed for additional catch blocks if
48 it has.
50 FALSE_LABEL is used when either setjmp/longjmp exceptions are in
51 use, or old style table exceptions. It contains the label for
52 branching to the next runtime type check as handlers are processed.
54 FINALIZATION is the tree codes for the handler, or is NULL_TREE if
55 one hasn't been generated yet, or is integer_zero_node to mark the
56 end of a group of try blocks. */
58 struct eh_entry {
59 rtx outer_context;
60 rtx exception_handler_label;
61 tree finalization;
62 int label_used;
63 rtx false_label;
64 rtx rethrow_label;
65 /* If non-zero, this entry is for a handler created when we left an
66 exception-region via goto. */
67 unsigned goto_entry_p : 1;
69 #else
70 struct label_node;
71 struct eh_entry;
72 #endif
74 /* A list of EH_ENTRYs. ENTRY is the entry; CHAIN points to the next
75 entry in the list, or is NULL if this is the last entry. */
77 struct eh_node {
78 struct eh_entry *entry;
79 struct eh_node *chain;
82 /* A stack of EH_ENTRYs. TOP is the topmost entry on the stack. TOP is
83 NULL if the stack is empty. */
85 struct eh_stack {
86 struct eh_node *top;
89 /* A queue of EH_ENTRYs. HEAD is the front of the queue; TAIL is the
90 end (the latest entry). HEAD and TAIL are NULL if the queue is
91 empty. */
93 struct eh_queue {
94 struct eh_node *head;
95 struct eh_node *tail;
96 struct eh_queue *next;
99 /* Used to save exception handling status for each function. */
100 struct eh_status
102 /* A stack used for keeping track of the currently active exception
103 handling region. As each exception region is started, an entry
104 describing the region is pushed onto this stack. The current
105 region can be found by looking at the top of the stack, and as we
106 exit regions, the corresponding entries are popped.
108 Entries cannot overlap; they can be nested. So there is only one
109 entry at most that corresponds to the current instruction, and that
110 is the entry on the top of the stack. */
111 struct eh_stack x_ehstack;
112 /* This stack is used to represent what the current eh region is
113 for the catch blocks beings processed */
114 struct eh_stack x_catchstack;
115 /* A queue used for tracking which exception regions have closed.
116 As we exit a region, we enqueue a new entry. The entries are then
117 dequeued during expand_leftover_cleanups and
118 expand_start_all_catch. */
119 struct eh_queue *x_ehqueue;
120 /* Insns for all of the exception handlers for the current function.
121 They are currently emitted by the frontend code. */
122 rtx x_catch_clauses;
123 /* End of exception handler insn sequence. */
124 rtx x_catch_clauses_last;
125 /* A random data area for the front end's own use. */
126 struct label_node *x_false_label_stack;
127 /* Keeps track of the label to resume to should one want to resume
128 normal control flow out of a handler (instead of, say, returning to
129 the caller of the current function or exiting the program). */
130 struct label_node *x_caught_return_label_stack;
131 /* A stack (TREE_LIST) of lists of handlers. The TREE_VALUE of each
132 node is itself a TREE_CHAINed list of handlers for regions that
133 are not yet closed. The TREE_VALUE of each entry contains the
134 handler for the corresponding entry on the ehstack. */
135 union tree_node *x_protect_list;
136 /* The EH context. Nonzero if the function has already
137 fetched a pointer to the EH context for exception handling. */
138 rtx ehc;
139 /* The label generated by expand_builtin_eh_return. */
140 rtx x_eh_return_stub_label;
143 #define ehstack (cfun->eh->x_ehstack)
144 #define catchstack (cfun->eh->x_catchstack)
145 #define ehqueue (cfun->eh->x_ehqueue)
146 #define catch_clauses (cfun->eh->x_catch_clauses)
147 #define catch_clauses_last (cfun->eh->x_catch_clauses_last)
148 #define false_label_stack (cfun->eh->x_false_label_stack)
149 #define caught_return_label_stack (cfun->eh->x_caught_return_label_stack)
150 #define protect_list (cfun->eh->x_protect_list)
151 #define current_function_ehc (cfun->eh->ehc)
152 #define eh_return_stub_label (cfun->eh->x_eh_return_stub_label)
154 #ifdef TREE_CODE
155 /* Start an exception handling region. All instructions emitted after
156 this point are considered to be part of the region until
157 expand_eh_region_end () is invoked. */
159 extern void expand_eh_region_start PARAMS ((void));
161 /* Just like expand_eh_region_start, except if a cleanup action is
162 entered on the cleanup chain, the TREE_PURPOSE of the element put
163 on the chain is DECL. DECL should be the associated VAR_DECL, if
164 any, otherwise it should be NULL_TREE. */
166 extern void expand_eh_region_start_for_decl PARAMS ((tree));
168 /* Start an exception handling region for the given cleanup action.
169 All instructions emitted after this point are considered to be part
170 of the region until expand_eh_region_end () is invoked. CLEANUP is
171 the cleanup action to perform. The return value is true if the
172 exception region was optimized away. If that case,
173 expand_eh_region_end does not need to be called for this cleanup,
174 nor should it be.
176 This routine notices one particular common case in C++ code
177 generation, and optimizes it so as to not need the exception
178 region. */
180 extern int expand_eh_region_start_tree PARAMS ((tree, tree));
182 /* End an exception handling region. The information about the region
183 is found on the top of ehstack.
185 HANDLER is either the cleanup for the exception region, or if we're
186 marking the end of a try block, HANDLER is integer_zero_node.
188 HANDLER will be transformed to rtl when expand_leftover_cleanups ()
189 is invoked. */
191 extern void expand_eh_region_end PARAMS ((tree));
193 /* Push RLABEL or TLABEL onto LABELSTACK. Only one of RLABEL or TLABEL
194 should be set; the other must be NULL. */
196 extern void push_label_entry PARAMS ((struct label_node **labelstack,
197 rtx rlabel, tree tlabel));
199 /* Pop the topmost entry from LABELSTACK and return its value as an
200 rtx node. If LABELSTACK is empty, return NULL. */
202 extern rtx pop_label_entry PARAMS ((struct label_node **labelstack));
204 /* Return the topmost entry of LABELSTACK as a tree node, or return
205 NULL_TREE if LABELSTACK is empty. */
207 extern tree top_label_entry PARAMS ((struct label_node **labelstack));
209 #endif
211 /* Test: is exception handling turned on? */
213 extern int doing_eh PARAMS ((int));
215 /* Toplevel initialization for EH. */
217 void set_exception_lang_code PARAMS ((int));
218 void set_exception_version_code PARAMS ((int));
220 /* A list of handlers asocciated with an exception region. HANDLER_LABEL
221 is the the label that control should be transfered to if the data
222 in TYPE_INFO matches an exception. a value of NULL_TREE for TYPE_INFO
223 means This is a cleanup, and must always be called. A value of
224 CATCH_ALL_TYPE works like a cleanup, but a call to the runtime matcher
225 is still performed to avoid being caught by a different language
226 exception. NEXT is a pointer to the next handler for this region.
227 NULL means there are no more. */
229 typedef struct handler_info
231 rtx handler_label;
232 int handler_number;
233 void *type_info;
234 struct handler_info *next;
235 } handler_info;
238 /* Add new handler information to an exception range. The first parameter
239 specifies the range number (returned from new_eh_entry()). The second
240 parameter specifies the handler. By default the handler is inserted at
241 the end of the list. A handler list may contain only ONE NULL_TREE
242 typeinfo entry. Regardless where it is positioned, a NULL_TREE entry
243 is always output as the LAST handler in the exception table for a region. */
245 void add_new_handler PARAMS ((int, struct handler_info *));
247 /* Remove a handler label. The handler label is being deleted, so all
248 regions which reference this handler should have it removed from their
249 list of possible handlers. Any region which has the final handler
250 removed can be deleted. */
252 void remove_handler PARAMS ((rtx));
254 /* Create a new handler structure initialized with the handler label and
255 typeinfo fields passed in. */
257 struct handler_info *get_new_handler PARAMS ((rtx, void *));
259 /* Make a duplicate of an exception region by copying all the handlers
260 for an exception region. Return the new handler index. */
262 int duplicate_eh_handlers PARAMS ((int, int, rtx (*)(rtx)));
264 /* map symbol refs for rethrow */
266 rtx rethrow_symbol_map PARAMS ((rtx, rtx (*)(rtx)));
268 /* Is the rethrow label for a region used? */
270 int rethrow_used PARAMS ((int));
272 /* Update the rethrow references to reflect rethrows which have been
273 optimized away. */
275 void update_rethrow_references PARAMS ((void));
277 /* Get a pointer to the first handler in an exception region's list. */
279 struct handler_info *get_first_handler PARAMS ((int));
281 /* Find all the runtime handlers type matches currently referenced */
283 int find_all_handler_type_matches PARAMS ((void ***));
285 /* The eh_nesting_info structure is used to find a list of valid handlers
286 for any arbitrary exception region. When init_eh_nesting_info is called,
287 the information is all pre-calculated and entered in this structure.
288 REGION_INDEX is a vector over all possible region numbers. Since the
289 number of regions is typically much smaller than the range of block
290 numbers, this is a sparse vector and the other data structures are
291 represented as dense vectors. Indexed with an exception region number, this
292 returns the index to use in the other data structures to retreive the
293 correct information.
294 HANDLERS is an array of vectors which point to handler_info structures.
295 when indexed, it gives the list of all possible handlers which can
296 be reached by a throw from this exception region.
297 NUM_HANDLERS is the equivilent array indicating how many handler
298 pointers there are in the HANDLERS vector.
299 OUTER_INDEX indicates which index represents the information for the
300 outer block. 0 indicates there is no outer context.
301 REGION_COUNT is the number of regions. */
303 typedef struct eh_nesting
305 int *region_index;
306 handler_info ***handlers;
307 int *num_handlers;
308 int *outer_index;
309 int region_count;
310 } eh_nesting_info;
312 /* Initialize the eh_nesting_info structure. */
314 eh_nesting_info *init_eh_nesting_info PARAMS ((void));
316 /* Get a list of handlers reachable from a an exception region/insn. */
318 int reachable_handlers PARAMS ((int, eh_nesting_info *, rtx,
319 handler_info ***handlers));
321 /* Free the eh_nesting_info structure. */
323 void free_eh_nesting_info PARAMS ((eh_nesting_info *));
325 extern void init_eh PARAMS ((void));
327 /* Initialization for the per-function EH data. */
329 extern void init_eh_for_function PARAMS ((void));
331 /* Generate an exception label. Use instead of gen_label_rtx */
333 extern rtx gen_exception_label PARAMS ((void));
335 /* Adds an EH table entry for EH entry number N. Called from
336 final_scan_insn for NOTE_INSN_EH_REGION_BEG. */
338 extern void add_eh_table_entry PARAMS ((int n));
340 /* Start a catch clause, triggered by runtime value paramter. */
342 #ifdef TREE_CODE
343 extern void start_catch_handler PARAMS ((tree));
344 #endif
346 /* End an individual catch clause. */
348 extern void end_catch_handler PARAMS ((void));
350 /* Returns a non-zero value if we need to output an exception table. */
352 extern int exception_table_p PARAMS ((void));
354 /* Outputs the exception table if we have one. */
356 extern void output_exception_table PARAMS ((void));
357 extern void output_exception_table_data PARAMS ((void));
359 /* Free the exception table. */
361 extern void free_exception_table PARAMS((void));
363 /* Used by the ia64 unwind format to output data for an individual
364 function. */
366 extern void output_function_exception_table PARAMS((void));
368 /* Given a return address in ADDR, determine the address we should use
369 to find the corresponding EH region. */
371 extern rtx eh_outer_context PARAMS ((rtx addr));
373 /* Called at the start of a block of try statements for which there is
374 a supplied catch handler. */
376 extern void expand_start_try_stmts PARAMS ((void));
378 /* Called at the start of a block of catch statements. It terminates the
379 previous set of try statements. */
381 extern void expand_start_all_catch PARAMS ((void));
383 /* Called at the end of a block of catch statements. */
385 extern void expand_end_all_catch PARAMS ((void));
387 /* Begin a region that will contain entries created with
388 add_partial_entry. */
390 extern void begin_protect_partials PARAMS ((void));
392 #ifdef TREE_CODE
393 /* Create a new exception region and add the handler for the region
394 onto a list. These regions will be ended (and their handlers
395 emitted) when end_protect_partials is invoked. */
397 extern void add_partial_entry PARAMS ((tree handler));
398 #endif
400 /* End all of the pending exception regions that have handlers added with
401 push_protect_entry (). */
403 extern void end_protect_partials PARAMS ((void));
405 /* An internal throw. */
407 extern void expand_internal_throw PARAMS ((void));
409 /* Called from expand_exception_blocks and expand_end_catch_block to
410 expand and pending handlers. */
412 extern void expand_leftover_cleanups PARAMS ((void));
414 /* If necessary, emit insns to get EH context for the current
415 function. */
417 extern void emit_eh_context PARAMS ((void));
419 /* Builds a list of handler labels and puts them in the global
420 variable exception_handler_labels. */
422 extern void find_exception_handler_labels PARAMS ((void));
424 /* Determine if an arbitrary label is an exception label */
426 extern int is_exception_handler_label PARAMS ((int));
428 /* Performs sanity checking on the check_exception_handler_labels
429 list. */
431 extern void check_exception_handler_labels PARAMS ((void));
433 /* Keeps track of the label used as the context of a throw to rethrow an
434 exception to the outer exception region. */
436 extern struct label_node *outer_context_label_stack;
438 /* A list of labels used for exception handlers. It is created by
439 find_exception_handler_labels for the optimization passes. */
441 extern rtx exception_handler_labels;
443 /* Determine if the given INSN can throw an exception. */
445 extern int can_throw PARAMS ((rtx));
447 /* Return nonzero if nothing in this function can throw. */
449 extern int nothrow_function_p PARAMS ((void));
451 /* Performs optimizations for exception handling, such as removing
452 unnecessary exception regions. Invoked from jump_optimize (). */
454 extern void exception_optimize PARAMS ((void));
456 /* Return EH context (and set it up once per fn). */
457 extern rtx get_eh_context PARAMS ((void));
459 /* Get the dynamic handler chain. */
460 extern rtx get_dynamic_handler_chain PARAMS ((void));
462 /* Get the dynamic cleanup chain. */
463 extern rtx get_dynamic_cleanup_chain PARAMS ((void));
465 /* Throw an exception. */
467 extern void emit_throw PARAMS ((void));
469 /* Save away the current ehqueue. */
470 extern void push_ehqueue PARAMS ((void));
472 /* Restore a previously pushed ehqueue. */
473 extern void pop_ehqueue PARAMS ((void));
475 /* One to use setjmp/longjmp method of generating code. */
477 extern int exceptions_via_longjmp;
479 /* One to enable asynchronous exception support. */
481 extern int asynchronous_exceptions;
483 /* One to protect cleanup actions with a handler that calls
484 __terminate, zero otherwise. */
486 extern int protect_cleanup_actions_with_terminate;
488 #ifdef TREE_CODE
489 extern tree protect_with_terminate PARAMS ((tree));
490 #endif
492 extern void expand_fixup_region_start PARAMS ((void));
493 #ifdef TREE_CODE
494 extern void expand_fixup_region_end PARAMS ((tree));
495 #endif
497 /* Various hooks for the DWARF 2 __throw routine. */
499 void expand_builtin_unwind_init PARAMS ((void));
500 rtx expand_builtin_dwarf_fp_regnum PARAMS ((void));
501 #ifdef TREE_CODE
502 rtx expand_builtin_frob_return_addr PARAMS ((tree));
503 rtx expand_builtin_extract_return_addr PARAMS ((tree));
504 void expand_builtin_init_dwarf_reg_sizes PARAMS ((tree));
505 void expand_builtin_eh_return PARAMS ((tree, tree, tree));
506 #endif
507 void expand_eh_return PARAMS ((void));
510 /* Checking whether 2 instructions are within the same exception region. */
512 int in_same_eh_region PARAMS ((rtx, rtx));
513 void free_insn_eh_region PARAMS ((void));
514 void init_insn_eh_region PARAMS ((rtx, int));
516 #ifdef rtx
517 #undef rtx
518 #endif