GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

  • gcc-4.1.0/gcc/opts.cにて定義
  • コンパイルオプションを解釈し,グローバルなフラグをいろいろ立てるなどの,最小限の処理を行う.

462 /* Parse command line options and set default flag values.  Do minimal
463    options processing.  */

引数[]

  • int argc
  • char **argv

実装[]

464 void
465 decode_options (unsigned int argc, const char **argv)
466 {
467   unsigned int i, lang_mask;
468 
469   /* Perform language-specific options initialization.  */
470   lang_mask = lang_hooks.init_options (argc, argv);
471 
472   lang_hooks.initialize_diagnostics (global_dc);
473 
474   /* Scan to see what optimization level has been specified.  That will
475      determine the default value of many flags.  */
476   for (i = 1; i < argc; i++)
477     {
478       if (!strcmp (argv[i], "-O"))
479         {
480           optimize = 1;
481           optimize_size = 0;
482         }
483       else if (argv[i][0] == '-' && argv[i][1] == 'O')
484         {
485           /* Handle -Os, -O2, -O3, -O69, ...  */
486           const char *p = &argv[i][2];
487 
488           if ((p[0] == 's') && (p[1] == 0))
489             {
490               optimize_size = 1;
491 
492               /* Optimizing for size forces optimize to be 2.  */
493               optimize = 2;
494             }
495           else
496             {
497               const int optimize_val = read_integral_parameter (p, p - 2, -1);
498               if (optimize_val != -1)
499                 {
500                   optimize = optimize_val;
501                   optimize_size = 0;
502                 }
503             }
504         }
505     }
506 
507   if (!optimize)
508     {
509       flag_merge_constants = 0;
510     }
511 
512   if (optimize >= 1)
513     {
514       flag_defer_pop = 1;
515 #ifdef DELAY_SLOTS
516       flag_delayed_branch = 1;
517 #endif
518 #ifdef CAN_DEBUG_WITHOUT_FP
519       flag_omit_frame_pointer = 1;
520 #endif
521       flag_guess_branch_prob = 1;
522       flag_cprop_registers = 1;
523       flag_loop_optimize = 1;
524       flag_if_conversion = 1;
525       flag_if_conversion2 = 1;
526       flag_ipa_pure_const = 1;
527       flag_ipa_reference = 1;
528       flag_tree_ccp = 1;
529       flag_tree_dce = 1;
530       flag_tree_dom = 1;
531       flag_tree_dse = 1;
532       flag_tree_ter = 1;
533       flag_tree_live_range_split = 1;
534       flag_tree_sra = 1;
535       flag_tree_copyrename = 1;
536       flag_tree_fre = 1;
537       flag_tree_copy_prop = 1;
538       flag_tree_sink = 1;
539       flag_tree_salias = 1;
540       flag_unit_at_a_time = 1;
541 
542       if (!optimize_size)
543         {
544           /* Loop header copying usually increases size of the code.  This used
545              not to be true, since quite often it is possible to verify that
546              the condition is satisfied in the first iteration and therefore
547              to eliminate it.  Jump threading handles these cases now.  */
548           flag_tree_ch = 1;
549         }
550     }
551 
552   if (optimize >= 2)
553     {
554       flag_thread_jumps = 1;
555       flag_crossjumping = 1;
556       flag_optimize_sibling_calls = 1;
557       flag_cse_follow_jumps = 1;
558       flag_cse_skip_blocks = 1;
559       flag_gcse = 1;
560       flag_expensive_optimizations = 1;
561       flag_ipa_type_escape = 1;
562       flag_strength_reduce = 1;
563       flag_rerun_cse_after_loop = 1;
564       flag_rerun_loop_opt = 1;
565       flag_caller_saves = 1;
566       flag_peephole2 = 1;
567 #ifdef INSN_SCHEDULING
568       flag_schedule_insns = 1;
569       flag_schedule_insns_after_reload = 1;
570 #endif
571       flag_regmove = 1;
572       flag_strict_aliasing = 1;
573       flag_delete_null_pointer_checks = 1;
574       flag_reorder_blocks = 1;
575       flag_reorder_functions = 1;
576       flag_tree_store_ccp = 1;
577       flag_tree_store_copy_prop = 1;
578       flag_tree_vrp = 1;
579 
580       if (!optimize_size)
581         {
582           /* PRE tends to generate bigger code.  */
583           flag_tree_pre = 1;
584         }
585     }
586 
587   if (optimize >= 3)
588     {
589       flag_inline_functions = 1;
590       flag_unswitch_loops = 1;
591       flag_gcse_after_reload = 1;
592     }
593 
594   if (optimize < 2 || optimize_size)
595     {
596       align_loops = 1;
597       align_jumps = 1;
598       align_labels = 1;
599       align_functions = 1;
600 
601       /* Don't reorder blocks when optimizing for size because extra
602          jump insns may be created; also barrier may create extra padding.
603 
604          More correctly we should have a block reordering mode that tried
605          to minimize the combined size of all the jumps.  This would more
606          or less automatically remove extra jumps, but would also try to
607          use more short jumps instead of long jumps.  */
608       flag_reorder_blocks = 0;
609       flag_reorder_blocks_and_partition = 0;
610     }
611 
612   if (optimize_size)
613     {
614       /* Inlining of very small functions usually reduces total size.  */
615       set_param_value ("max-inline-insns-single", 5);
616       set_param_value ("max-inline-insns-auto", 5);
617       flag_inline_functions = 1;
618 
619       /* We want to crossjump as much as possible.  */
620       set_param_value ("min-crossjump-insns", 1);
621     }
622 
623   /* Initialize whether `char' is signed.  */
624   flag_signed_char = DEFAULT_SIGNED_CHAR;
625   /* Set this to a special "uninitialized" value.  The actual default is set
626      after target options have been processed.  */
627   flag_short_enums = 2;
628 
629   /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
630      modify it.  */
631   target_flags = targetm.default_target_flags;
632 
633   /* Some tagets have ABI-specified unwind tables.  */
634   flag_unwind_tables = targetm.unwind_tables_default;
635 
636 #ifdef OPTIMIZATION_OPTIONS
637   /* Allow default optimizations to be specified on a per-machine basis.  */
638   OPTIMIZATION_OPTIONS (optimize, optimize_size);
639 #endif
640 
641   handle_options (argc, argv, lang_mask);
642 
643   if (flag_pie)
644     flag_pic = flag_pie;
645   if (flag_pic && !flag_pie)
646     flag_shlib = 1;
647 
648   if (flag_no_inline == 2)
649     flag_no_inline = 0;
650   else
651     flag_really_no_inline = flag_no_inline;
652 
653   /* Set flag_no_inline before the post_options () hook.  The C front
654      ends use it to determine tree inlining defaults.  FIXME: such
655      code should be lang-independent when all front ends use tree
656      inlining, in which case it, and this condition, should be moved
657      to the top of process_options() instead.  */
658   if (optimize == 0)
659     {
660       /* Inlining does not work if not optimizing,
661          so force it not to be done.  */
662       flag_no_inline = 1;
663       warn_inline = 0;
664 
665       /* The c_decode_option function and decode_option hook set
666          this to `2' if -Wall is used, so we can avoid giving out
667          lots of errors for people who don't realize what -Wall does.  */
668       if (warn_uninitialized == 1)
669         warning (OPT_Wuninitialized,
670                  "-Wuninitialized is not supported without -O");
671     }
672 
673   if (flag_really_no_inline == 2)
674     flag_really_no_inline = flag_no_inline;
675 
676   /* The optimization to partition hot and cold basic blocks into separate
677      sections of the .o and executable files does not work (currently)
678      with exception handling.  This is because there is no support for
679      generating unwind info.  If flag_exceptions is turned on we need to
680      turn off the partitioning optimization.  */
681 
682   if (flag_exceptions && flag_reorder_blocks_and_partition)
683     {
684       inform 
685             ("-freorder-blocks-and-partition does not work with exceptions");
686       flag_reorder_blocks_and_partition = 0;
687       flag_reorder_blocks = 1;
688     }
689 
690   /* If user requested unwind info, then turn off the partitioning
691      optimization.  */
692 
693   if (flag_unwind_tables && ! targetm.unwind_tables_default
694       && flag_reorder_blocks_and_partition)
695     {
696       inform ("-freorder-blocks-and-partition does not support unwind info");
697       flag_reorder_blocks_and_partition = 0;
698       flag_reorder_blocks = 1;
699     }
700 
701   /* If the target requested unwind info, then turn off the partitioning
702      optimization with a different message.  Likewise, if the target does not
703      support named sections.  */
704 
705   if (flag_reorder_blocks_and_partition
706       && (!targetm.have_named_sections
707           || (flag_unwind_tables && targetm.unwind_tables_default)))
708     {
709       inform 
710        ("-freorder-blocks-and-partition does not work on this architecture");
711       flag_reorder_blocks_and_partition = 0;
712       flag_reorder_blocks = 1;
713     }
714 }



リンク元

Advertisement