[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c
Chris Lattner
lattner at cs.uiuc.edu
Wed Dec 7 11:35:22 PST 2005
Changes in directory llvm-gcc/gcc:
llvm-expand.c updated: 1.120 -> 1.121
---
Log message:
Minor simplification to the EH code: CleanupsCanThrow is always the inverse
of isExceptionEdge. Eliminate it in favor of !isExceptionEdge
---
Diffs of the changes: (+28 -41)
llvm-expand.c | 69 +++++++++++++++++++++++-----------------------------------
1 files changed, 28 insertions(+), 41 deletions(-)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.120 llvm-gcc/gcc/llvm-expand.c:1.121
--- llvm-gcc/gcc/llvm-expand.c:1.120 Sun Dec 4 22:49:21 2005
+++ llvm-gcc/gcc/llvm-expand.c Wed Dec 7 13:35:10 2005
@@ -48,7 +48,6 @@
static void llvm_expand_constructor(llvm_function *Fn, tree exp,
llvm_value *Dest, int isVolatile);
static void llvm_expand_goto_internal(llvm_function *Fn, llvm_basicblock *label,
- int CleanupsCanThrow,
int isExceptionEdge);
static llvm_constant *llvm_expand_constant_expr(tree exp, llvm_type *ReqType);
static llvm_constant *llvm_decode_string_constant(tree exp, unsigned Len,
@@ -638,10 +637,6 @@
/* The LLVM basic block that this is jumping to. */
llvm_basicblock *target_bb;
- /* Information about what happens if a cleanup expression throws an exception.
- See llvm_expand_goto_internal for information about this flag. */
- int CleanupsCanThrow : 1;
-
/* Information about whether this goto is part of an exception propagation.
* If so, cleanups which are only supposed to be run on exception exits are
* expanded.
@@ -770,9 +765,8 @@
void llvm_fixup_list_dump(llvm_function *Fn) {
llvm_goto_fixup *f = Fn->ExpandInfo->GotoFixupList;
for (; f; f = f->next) {
- fprintf(stderr, "Fixup [%p]: to bb %%%s cct: %s iee: %s cleanups: %p"
+ fprintf(stderr, "Fixup [%p]: to bb %%%s iee: %s cleanups: %p"
" containing_block: %p\n", (void*)f, D2V(f->target_bb)->Name,
- f->CleanupsCanThrow ? "Yes" : "No",
f->isExceptionEdge ? "Yes" : "No",
(void*)f->cleanup_list, (void*)f->containing_block);
}
@@ -784,13 +778,11 @@
*/
static llvm_basicblock *
llvm_get_existing_fixup(llvm_function *Fn, llvm_basicblock *BB,
- int CleanupsCanThrow, int isExceptionEdge,
- tree cleanups) {
+ int isExceptionEdge, tree cleanups) {
llvm_goto_fixup *fixup;
for (fixup = Fn->ExpandInfo->GotoFixupList; fixup; fixup = fixup->next)
if (fixup->target_bb == BB &&
fixup->cleanup_list == cleanups &&
- fixup->CleanupsCanThrow == CleanupsCanThrow &&
fixup->isExceptionEdge == isExceptionEdge) {
llvm_basicblock *FixupBrBlock = fixup->BranchBlock;
@@ -835,14 +827,14 @@
*/
static int llvm_expand_cleanups(llvm_function *Fn, tree *list,
llvm_instruction *TheBranch,
- int CleanupsCanThrow, int isExceptionEdge) {
+ int isExceptionEdge) {
int CleanupIsDead = 0;
tree OrigList = *list;
assert(TheBranch->Opcode == O_Br && TheBranch->NumOperands == 1 &&
"Cleanups only support for unconditional branches!");
- if (!CleanupsCanThrow)
+ if (isExceptionEdge)
Fn->ExpandInfo->ThrownExceptionsCallTerminate++;
while (*list) {
@@ -870,8 +862,8 @@
*/
llvm_basicblock *DestBB = V2BB(TheBranch->Operands[0]);
llvm_basicblock *Existing = llvm_get_existing_fixup(Fn, DestBB,
- CleanupsCanThrow,
- isExceptionEdge, *list);
+ isExceptionEdge,
+ *list);
if (Existing) {
TheBranch->Operands[0] = D2V(Existing);
CleanupIsDead = 1;
@@ -883,7 +875,7 @@
/* Restore input list to what it was when llvm_expand_cleanups was invoked */
*list = OrigList;
- if (!CleanupsCanThrow)
+ if (isExceptionEdge)
Fn->ExpandInfo->ThrownExceptionsCallTerminate--;
return CleanupIsDead;
@@ -931,7 +923,6 @@
DeleteThisFixup = llvm_expand_cleanups(Fn, &thisblock->x.block.cleanups,
f->BranchInst,
- f->CleanupsCanThrow,
f->isExceptionEdge);
thisblock->x.block.cleanups = SavedCleanups;
@@ -989,7 +980,7 @@
/* Now that we have handled this binding level for the goto, check to see
* if it became equal to an existing fixup.
*/
- LastBlock = llvm_get_existing_fixup(Fn, f->target_bb, f->CleanupsCanThrow,
+ LastBlock = llvm_get_existing_fixup(Fn, f->target_bb,
f->isExceptionEdge, newcleanups);
if (LastBlock) {
@@ -1164,7 +1155,7 @@
AfterBlock = llvm_basicblock_new("after_region");
if (!EndOfFunctionUnreachable(Fn))
- llvm_expand_goto_internal(Fn, AfterBlock, 1, 0);
+ llvm_expand_goto_internal(Fn, AfterBlock, 0);
}
/* Pop the current scope off of the stack... */
@@ -1249,7 +1240,7 @@
void llvm_emit_code_for_throw(llvm_function *Fn) {
llvm_basicblock *Dest = get_innermost_catch_block(Fn);
- llvm_expand_goto_internal(Fn, Dest, 0, 1);
+ llvm_expand_goto_internal(Fn, Dest, 1);
/* Start a new block so that if statements are emitted after the throw, that
* they will have the correct "current block".
@@ -1307,7 +1298,7 @@
/* Propagate control flow to a containing exception region or rethrow as
necessary */
- llvm_expand_goto_internal(Fn, get_innermost_catch_block(Fn), 0, 1);
+ llvm_expand_goto_internal(Fn, get_innermost_catch_block(Fn), 1);
llvm_emit_label(Fn, thisexcept.x.except.OutBlock);
} else {
@@ -1463,7 +1454,7 @@
/* If none of the handlers caught the exception, rethrow it by either
branching to an catch block we are nested in, or by rethrowing the
exception */
- llvm_expand_goto_internal(Fn, get_innermost_catch_block(Fn), 0, 1);
+ llvm_expand_goto_internal(Fn, get_innermost_catch_block(Fn), 1);
/* Continue emitting code after the try block */
llvm_emit_label(Fn, thisexcept.x.except.OutBlock);
@@ -1529,7 +1520,7 @@
/* If none of the handlers caught the exception, rethrow it by either
branching to an catch block we are nested in, or by rethrowing the
exception */
- llvm_expand_goto_internal(Fn, get_innermost_catch_block(Fn), 0, 1);
+ llvm_expand_goto_internal(Fn, get_innermost_catch_block(Fn), 1);
/* Continue emitting code after the try block */
llvm_emit_label(Fn, thisexcept.x.except.OutBlock);
@@ -1636,18 +1627,16 @@
* When the block containing the cleanup is exited, the end-of-block code
* inserts the cleanups as indicated by goto_fixups.
*
- * If it is illegal for inserted cleanups to throw any exceptions,
- * CleanupsCanThrow should be set to zero. This is an important case for
- * exception handling: when unwinding the stack due to an active exception, any
- * destructors which propagate exceptions should cause terminate to be called.
+ * If isExceptionEdge is true, cleanups which apply only to exceptions are
+ * expanded, otherwise they are not. Note that when isExceptionEdge is true,
+ * it is illegal for inserted cleanups to throw any exceptions. This is an
+ * important case for exception handling: when unwinding the stack due to an
+ * active exception, any destructors which propagate exceptions should cause
+ * terminate to be called.
* Thus, if a cleanup can throw an exception, it's exception destination goes to
* a designated terminate block.
- *
- * If isExceptionEdge is true, cleanups which apply only to exceptions are
- * expanded, otherwise they are not.
*/
static void llvm_expand_goto_internal(llvm_function *Fn, llvm_basicblock *BB,
- int CleanupsCanThrow,
int isExceptionEdge) {
/* Create the final branch we will be using */
llvm_instruction *Branch = create_uncond_branch(BB);
@@ -1688,8 +1677,7 @@
/* Okay, now we know that we need a fixup for this block. Scan to see if any
* identical fixups exist. If so, we can share the code between the branches.
*/
- ExistingFixupBlock = llvm_get_existing_fixup(Fn, BB, CleanupsCanThrow,
- isExceptionEdge,
+ ExistingFixupBlock = llvm_get_existing_fixup(Fn, BB, isExceptionEdge,
block->x.block.cleanups);
if (ExistingFixupBlock) {
/* Instead of jumping directly to BB, jump to fixup->BranchBlock
@@ -1705,7 +1693,6 @@
fixup->BranchBlock = BranchBlock;
fixup->BranchInst = Branch;
fixup->target_bb = BB;
- fixup->CleanupsCanThrow = CleanupsCanThrow;
fixup->isExceptionEdge = isExceptionEdge;
fixup->containing_block = block;
fixup->cleanup_list = block->x.block.cleanups;
@@ -1730,7 +1717,7 @@
Fn->ExpandInfo->CleanupBlock : Fn->ExpandInfo->ReturnBlock;
/* Simply goto the exit label now. */
- llvm_expand_goto_internal(Fn, EndLabel, 1, 0);
+ llvm_expand_goto_internal(Fn, EndLabel, 0);
/* Start a new block so that if statements are emitted after the return, that
* they will have the correct "current block".
@@ -1906,7 +1893,7 @@
return 0;
whichloop->x.loop.ContinueFound = 1;
- llvm_expand_goto_internal(Fn, whichloop->x.loop.continue_label, 1, 0);
+ llvm_expand_goto_internal(Fn, whichloop->x.loop.continue_label, 0);
/* Start a new block so that if statements are emitted after the continue,
* that they will have the correct "current block".
@@ -1947,7 +1934,7 @@
if (integer_nonzerop(cond)) /* No exit can happen */
return 1;
if (integer_zerop(cond)) { /* Exit is guaranteed to happen */
- llvm_expand_goto_internal(Fn, whichloop->x.loop.end_label, 1, 0);
+ llvm_expand_goto_internal(Fn, whichloop->x.loop.end_label, 0);
return 1;
}
@@ -1972,7 +1959,7 @@
llvm_expand_goto_internal only operates on unconditional branches. */
llvm_basicblock *ExitHelperBlock =llvm_basicblock_new("exit_loop_cleanups");
append_inst(Fn, create_cond_branch(Cond, ContBlock, ExitHelperBlock));
- llvm_expand_goto_internal(Fn, whichloop->x.loop.end_label, 1, 0);
+ llvm_expand_goto_internal(Fn, whichloop->x.loop.end_label, 0);
}
llvm_emit_label(Fn, ContBlock);
return 1;
@@ -1993,7 +1980,7 @@
for (n = Fn->ExpandInfo->InnermostScope; n; n = n->all)
if (n->exit_block) {
n->BreakFound = 1;
- llvm_expand_goto_internal(Fn, n->exit_block, 1, 0);
+ llvm_expand_goto_internal(Fn, n->exit_block, 0);
/* Start a new block so that if statements are emitted after the break,
* that they will have the correct "current block".
@@ -2217,7 +2204,7 @@
* There should be one collector block per cleanup level! Note that
* standard GCC gets this wrong as well.
*/
- llvm_expand_goto_internal(Fn, Fn->ExpandInfo->IndirectGotoBlock, 1, 0);
+ llvm_expand_goto_internal(Fn, Fn->ExpandInfo->IndirectGotoBlock, 0);
/* Start a new block so that if statements are emitted after the goto, that
* they will have the correct "current block".
@@ -2227,7 +2214,7 @@
}
TREE_USED(dest) = 1;
- llvm_expand_goto_internal(Fn, getLabelDeclBlock(dest), 1, 0);
+ llvm_expand_goto_internal(Fn, getLabelDeclBlock(dest), 0);
/* Start a new block so that if statements are emitted after the goto, that
* they will have the correct "current block".
@@ -3215,7 +3202,7 @@
Call->Operands[2] = D2V(CleanupDest);
append_inst(Fn, Call);
llvm_emit_label(Fn, CleanupDest);
- llvm_expand_goto_internal(Fn, ExceptBlock, 0, 1);
+ llvm_expand_goto_internal(Fn, ExceptBlock, 1);
}
llvm_emit_label(Fn, NormalDest);
}
More information about the llvm-commits
mailing list