Mercurial > hg > CbC > CbC_gcc
comparison gcc/calls.c @ 112:ab0bcb71f44d
merge gcc 7
author | mir3636 |
---|---|
date | Fri, 10 Nov 2017 19:46:38 +0900 |
parents | 04ced10e8804 4d6300120c29 |
children | 367f9f4f266e |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 112:ab0bcb71f44d |
---|---|
116 copy in smaller-sized pieces into pseudos. These are stored in a | 116 copy in smaller-sized pieces into pseudos. These are stored in a |
117 block pointed to by this field. The next field says how many | 117 block pointed to by this field. The next field says how many |
118 word-sized pseudos we made. */ | 118 word-sized pseudos we made. */ |
119 rtx *aligned_regs; | 119 rtx *aligned_regs; |
120 int n_aligned_regs; | 120 int n_aligned_regs; |
121 #ifndef noCbC | |
122 rtx exprs; | |
123 #endif | |
121 }; | 124 }; |
122 | 125 |
123 /* A vector of one char per byte of stack space. A byte if nonzero if | 126 /* A vector of one char per byte of stack space. A byte if nonzero if |
124 the corresponding stack location has been used. | 127 the corresponding stack location has been used. |
125 This vector is used to prevent a function call within an argument from | 128 This vector is used to prevent a function call within an argument from |
2753 value, GEN_INT (shift), value, 1, OPTAB_WIDEN)) | 2756 value, GEN_INT (shift), value, 1, OPTAB_WIDEN)) |
2754 gcc_unreachable (); | 2757 gcc_unreachable (); |
2755 return true; | 2758 return true; |
2756 } | 2759 } |
2757 | 2760 |
2761 #ifndef noCbC | |
2762 #include "cbc-tree.h" | |
2763 #endif | |
2764 | |
2758 /* If X is a likely-spilled register value, copy it to a pseudo | 2765 /* If X is a likely-spilled register value, copy it to a pseudo |
2759 register and return that register. Return X otherwise. */ | 2766 register and return that register. Return X otherwise. */ |
2760 | 2767 |
2761 static rtx | 2768 static rtx |
2762 avoid_likely_spilled_reg (rtx x) | 2769 avoid_likely_spilled_reg (rtx x) |
3289 /* Tail calls can make things harder to debug, and we've traditionally | 3296 /* Tail calls can make things harder to debug, and we've traditionally |
3290 pushed these optimizations into -O2. Don't try if we're already | 3297 pushed these optimizations into -O2. Don't try if we're already |
3291 expanding a call, as that means we're an argument. Don't try if | 3298 expanding a call, as that means we're an argument. Don't try if |
3292 there's cleanups, as we know there's code to follow the call. */ | 3299 there's cleanups, as we know there's code to follow the call. */ |
3293 | 3300 |
3301 // -O2オプションがないときも末尾最適化が行われるように(Code Segmentのみ) | |
3294 if (currently_expanding_call++ != 0 | 3302 if (currently_expanding_call++ != 0 |
3303 #ifndef noCbC | |
3304 || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) && !flag_optimize_sibling_calls) | |
3305 #else | |
3295 || !flag_optimize_sibling_calls | 3306 || !flag_optimize_sibling_calls |
3307 #endif | |
3296 || args_size.var | 3308 || args_size.var |
3297 || dbg_cnt (tail_call) == false) | 3309 || dbg_cnt (tail_call) == false) |
3298 try_tail_call = 0; | 3310 try_tail_call = 0; |
3299 | 3311 |
3300 /* If the user has marked the function as requiring tail-call | 3312 /* If the user has marked the function as requiring tail-call |
3301 optimization, attempt it. */ | 3313 optimization, attempt it. */ |
3302 if (must_tail_call) | 3314 if (must_tail_call) |
3303 try_tail_call = 1; | 3315 try_tail_call = 1; |
3304 | 3316 |
3305 /* Rest of purposes for tail call optimizations to fail. */ | 3317 /* Rest of purposes for tail call optimizations to fail. */ |
3318 <<<<<<< local | |
3306 if (try_tail_call) | 3319 if (try_tail_call) |
3307 try_tail_call = can_implement_as_sibling_call_p (exp, | 3320 try_tail_call = can_implement_as_sibling_call_p (exp, |
3308 structure_value_addr, | 3321 structure_value_addr, |
3309 funtype, | 3322 funtype, |
3310 reg_parm_stack_space, | 3323 reg_parm_stack_space, |
3311 fndecl, | 3324 fndecl, |
3312 flags, addr, args_size); | 3325 flags, addr, args_size); |
3326 ======= | |
3327 if ( | |
3328 #ifdef HAVE_sibcall_epilogue | |
3329 !HAVE_sibcall_epilogue | |
3330 #else | |
3331 1 | |
3332 #endif | |
3333 || !try_tail_call | |
3334 /* Doing sibling call optimization needs some work, since | |
3335 structure_value_addr can be allocated on the stack. | |
3336 It does not seem worth the effort since few optimizable | |
3337 sibling calls will return a structure. */ | |
3338 || structure_value_addr != NULL_RTX | |
3339 #ifdef REG_PARM_STACK_SPACE | |
3340 /* If outgoing reg parm stack space changes, we can not do sibcall. */ | |
3341 || (OUTGOING_REG_PARM_STACK_SPACE (funtype) | |
3342 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl))) | |
3343 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (fndecl)) | |
3344 #endif | |
3345 /* Check whether the target is able to optimize the call | |
3346 into a sibcall. */ | |
3347 || !targetm.function_ok_for_sibcall (fndecl, exp) | |
3348 /* Functions that do not return exactly once may not be sibcall | |
3349 optimized. */ | |
3350 || (flags & (ECF_RETURNS_TWICE | ECF_NORETURN)) | |
3351 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr))) | |
3352 /* If the called function is nested in the current one, it might access | |
3353 some of the caller's arguments, but could clobber them beforehand if | |
3354 the argument areas are shared. */ | |
3355 || (fndecl && decl_function_context (fndecl) == current_function_decl) | |
3356 /* If this function requires more stack slots than the current | |
3357 function, we cannot change it into a sibling call. | |
3358 crtl->args.pretend_args_size is not part of the | |
3359 stack allocated by our caller. */ | |
3360 || args_size.constant > (crtl->args.size | |
3361 - crtl->args.pretend_args_size) | |
3362 /* If the callee pops its own arguments, then it must pop exactly | |
3363 the same number of arguments as the current function. */ | |
3364 || (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant) | |
3365 != targetm.calls.return_pops_args (current_function_decl, | |
3366 TREE_TYPE (current_function_decl), | |
3367 crtl->args.size)) | |
3368 || !lang_hooks.decls.ok_for_sibcall (fndecl)) | |
3369 try_tail_call = 0; | |
3370 >>>>>>> other | |
3371 | |
3313 | 3372 |
3314 /* Check if caller and callee disagree in promotion of function | 3373 /* Check if caller and callee disagree in promotion of function |
3315 return value. */ | 3374 return value. */ |
3316 if (try_tail_call) | 3375 #ifndef noCbC |
3376 if (try_tail_call && (!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)))) | |
3377 #else | |
3378 if (try_tail_call) | |
3379 #endif | |
3317 { | 3380 { |
3318 machine_mode caller_mode, caller_promoted_mode; | 3381 machine_mode caller_mode, caller_promoted_mode; |
3319 machine_mode callee_mode, callee_promoted_mode; | 3382 machine_mode callee_mode, callee_promoted_mode; |
3320 int caller_unsignedp, callee_unsignedp; | 3383 int caller_unsignedp, callee_unsignedp; |
3321 tree caller_res = DECL_RESULT (current_function_decl); | 3384 tree caller_res = DECL_RESULT (current_function_decl); |
3355 else | 3418 else |
3356 preferred_stack_boundary = crtl->preferred_stack_boundary; | 3419 preferred_stack_boundary = crtl->preferred_stack_boundary; |
3357 | 3420 |
3358 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT; | 3421 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT; |
3359 | 3422 |
3423 #ifndef noCbC | |
3424 if ( fntype | |
3425 && CbC_IS_CbC_GOTO (exp) // it's better? than CALL_EXPR_TAILCALL() | |
3426 && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl)) | |
3427 ) | |
3428 { | |
3429 | |
3430 args_size.constant = CbC_PRETENDED_STACK_SIZE; | |
3431 // try_tail_callを矯正的に立たせて末尾最適化を必ずうように変更 | |
3432 // -> expand_cbc_gotは不要に。 | |
3433 /* return expand_cbc_goto(exp, target, fndecl, funtype, fntype, | |
3434 * addr, ignore, flags, num_actuals, args, &args_size, | |
3435 * args_so_far, | |
3436 * old_stack_level, reg_parm_stack_space, old_pending_adj, | |
3437 * preferred_stack_boundary, preferred_unit_stack_boundary, | |
3438 * structure_value_addr, old_inhibit_defer_pop); */ | |
3439 } | |
3440 else if ( CbC_IS_CbC_GOTO (exp) ) | |
3441 { | |
3442 // TODO: 関数からコードセグメントへの遷移 | |
3443 /* | |
3444 if (fndecl) | |
3445 { | |
3446 char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl)); | |
3447 warning(0, "no warning: code segment `%s' has been called from a function.", name_callee); | |
3448 } | |
3449 else | |
3450 { | |
3451 warning(0, "no warning: unnamed code segment has been called from a function."); | |
3452 } | |
3453 */ | |
3454 args_size.constant = CbC_PRETENDED_STACK_SIZE; | |
3455 } | |
3456 else if ( fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) ) | |
3457 { | |
3458 // 警告コードセグメントを関数呼び出し | |
3459 //char *name= IDENTIFIER_POINTER(DECL_NAME(fndecl)); | |
3460 //warning (0, "code segment `%s' has been \"called\" instead \"goto\".", name); | |
3461 } | |
3462 else if (CbC_IS_CODE_SEGMENT(TREE_TYPE (current_function_decl)) ) | |
3463 { | |
3464 // code segment内部からの関数呼び出し。なんも問題ない。 | |
3465 //warning (0, "no warning: normal call from a code segment."); | |
3466 } | |
3467 #endif | |
3468 | |
3469 // when tail call optimization flag was down, warn about them. | |
3470 // and flag it to force a tail call optimize. | |
3471 #ifndef noCbC | |
3472 if (fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) | |
3473 && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl)) | |
3474 && try_tail_call == 0) | |
3475 { | |
3476 location_t loc = EXPR_LOCATION (exp); | |
3477 char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl)); | |
3478 warning_at (loc, 0, "transition to code segment \"%s\" with CbC goto, but tail call optimization was cut.", | |
3479 name_callee); | |
3480 try_tail_call = 1; | |
3481 } | |
3482 #endif | |
3483 | |
3360 /* We want to make two insn chains; one for a sibling call, the other | 3484 /* We want to make two insn chains; one for a sibling call, the other |
3361 for a normal call. We will select one of the two chains after | 3485 for a normal call. We will select one of the two chains after |
3362 initial RTL generation is complete. */ | 3486 initial RTL generation is complete. */ |
3363 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++) | 3487 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++) |
3364 { | 3488 { |
3421 && targetm.stack_protect_runtime_enabled_p ()) | 3545 && targetm.stack_protect_runtime_enabled_p ()) |
3422 stack_protect_epilogue (); | 3546 stack_protect_epilogue (); |
3423 | 3547 |
3424 adjusted_args_size = args_size; | 3548 adjusted_args_size = args_size; |
3425 /* Compute the actual size of the argument block required. The variable | 3549 /* Compute the actual size of the argument block required. The variable |
3426 and constant sizes must be combined, the size may have to be rounded, | 3550 and constant sizes must be combined, the size may have to be rounded, |
3427 and there may be a minimum required size. When generating a sibcall | 3551 and there may be a minimum required size. When generating a sibcall |
3428 pattern, do not round up, since we'll be re-using whatever space our | 3552 pattern, do not round up, since we'll be re-using whatever space our |
3429 caller provided. */ | 3553 caller provided. */ |
3554 #ifndef noCbC | |
3555 if ( fntype && CbC_IS_CODE_SEGMENT(fntype) ) | |
3556 { | |
3557 unadjusted_args_size = args_size.constant; | |
3558 adjusted_args_size.constant = CbC_PRETENDED_STACK_SIZE; | |
3559 compute_argument_block_size (reg_parm_stack_space, | |
3560 &adjusted_args_size, | |
3561 fndecl, fntype, | |
3562 (pass == 0 ? 0 | |
3563 : preferred_stack_boundary)); | |
3564 } | |
3565 else | |
3566 #endif | |
3567 { | |
3430 unadjusted_args_size | 3568 unadjusted_args_size |
3431 = compute_argument_block_size (reg_parm_stack_space, | 3569 = compute_argument_block_size (reg_parm_stack_space, |
3432 &adjusted_args_size, | 3570 &adjusted_args_size, |
3433 fndecl, fntype, | 3571 fndecl, fntype, |
3434 (pass == 0 ? 0 | 3572 (pass == 0 ? 0 |
3435 : preferred_stack_boundary)); | 3573 : preferred_stack_boundary)); |
3574 } | |
3436 | 3575 |
3437 old_stack_allocated = stack_pointer_delta - pending_stack_adjust; | 3576 old_stack_allocated = stack_pointer_delta - pending_stack_adjust; |
3438 | 3577 |
3439 /* The argument block when performing a sibling call is the | 3578 /* The argument block when performing a sibling call is the |
3440 incoming argument block. */ | 3579 incoming argument block. */ |