00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <string.h>
00054 #include <stdlib.h>
00055 #include <stamp.h>
00056 #include "string_utils.h"
00057 #include "options.h"
00058 #include "option_seen.h"
00059 #include "option_names.h"
00060 #include "lang_defs.h"
00061 #include "errors.h"
00062 #include "opt_actions.h"
00063 #include "file_names.h"
00064 #include "get_options.h"
00065 #include "phases.h"
00066 #include "run.h"
00067 #include "version.h"
00068
00069 int endian = UNDEFINED;
00070
00071 void
00072 set_defaults (void)
00073 {
00074 int flag;
00075 #ifdef PSC_TO_OPEN64
00076
00077 char *open64_cc = getenv("OPEN64_CC");
00078 if (open64_cc != NULL && !is_toggled(ansi)) {
00079
00080 if (strcmp(open64_cc, "-ansi") == 0) {
00081 #endif
00082 toggle(&ansi,STRICT_ANSI);
00083 prepend_option_seen (O_ansi);
00084 }
00085 }
00086
00087
00088 if (xpg_flag && invoked_lang == L_f77 && option_was_seen(O_O)) {
00089 error("XPG compiles must specify explicit optlevel rather than -O");
00090 }
00091 {
00092
00093 char *ir_version_check = getenv("COMPILER_IR_VERSION_CHECK");
00094 if (ir_version_check != NULL) {
00095 if (strcmp(ir_version_check, "off") == 0) {
00096 flag = add_string_option(O_DEBUG_, "ir_version_check=off");
00097
00098 prepend_option_seen(flag);
00099 }
00100 }
00101 }
00102 if (endian == UNDEFINED) {
00103 #if defined(TARG_MIPS)
00104 #if !defined(TARG_SL)
00105
00106 toggle(&endian, ENDIAN_LITTLE);
00107 prepend_option_seen(O_EL);
00108 prepend_option_seen(O_mlittle_endian);
00109 #endif
00110 #else
00111 #ifdef LITTLE_ENDIAN_HOST
00112 toggle(&endian, ENDIAN_LITTLE);
00113 #else
00114 toggle(&endian, ENDIAN_BIG);
00115 prepend_option_seen(O_EB);
00116 #endif
00117 #endif
00118 }
00119
00120 prepend_option_seen(O_usegfe);
00121 prepend_option_seen(O_usef90);
00122
00123 if (ansi == UNDEFINED) {
00124 toggle(&ansi,EXTENDED_ANSI);
00125 }
00126
00127 prepend_option_seen(O_cpp_fortran90);
00128 prepend_option_seen(O_cpp_fortran77);
00129 prepend_option_seen(O_cpp_fortran);
00130 prepend_option_seen(O_cpp_assembly);
00131 prepend_option_seen(O_prelink);
00132 prepend_option_seen(O_demangle);
00133 #ifdef TARG_IA64
00134 if (shared == UNDEFINED) {
00135 if (abi == ABI_IA32) {
00136 toggle(&shared,NON_SHARED);
00137 } else {
00138 toggle (&shared, CALL_SHARED);
00139 prepend_option_seen(O_call_shared);
00140 }
00141 } else if (shared != CALL_SHARED) {
00142 flag = add_string_option(O_OPT_, "Olegacy=TRUE");
00143 add_option_seen (flag);
00144 }
00145 #else
00146 if (shared == UNDEFINED && abi == ABI_IA32) {
00147 toggle(&shared,NON_SHARED);
00148 }
00149 #endif
00150 if (!is_toggled(isstatic)) {
00151 toggle(&isstatic,1);
00152 prepend_option_seen(O_automatic);
00153 }
00154
00155 #ifdef KEY
00156
00157 if (!is_toggled(use_ftpp)) {
00158 toggle(&use_ftpp, 0);
00159 }
00160
00161
00162
00163 if (!is_toggled(gnu_major_version)) {
00164 toggle(&gnu_major_version, get_gcc_major_version());
00165 switch (gnu_major_version) {
00166 case 3:
00167 toggle(&gnu_minor_version, 3);
00168 break;
00169 case 4:
00170 toggle(&gnu_minor_version, 2);
00171 break;
00172 default:
00173 error("no support for GCC version %d", gnu_major_version);
00174 }
00175 }
00176 #endif
00177 #if defined(TARG_NVISA)
00178
00179 if (option_was_seen(O_multicore))
00180 last_phase=earliest_phase(P_bec,last_phase);
00181 else
00182 last_phase=earliest_phase(P_be,last_phase);
00183
00184
00185 flag = add_string_option(O_INLINE_, "all");
00186 prepend_option_seen (flag);
00187 toggle_inline_on();
00188
00189
00190 flag = add_string_option(O_LIST_,
00191 concat_strings("build_date=", build_date));
00192 add_option_seen (flag);
00193 #endif
00194 }
00195
00196
00197 static int
00198 get_olevel_flag (int olevel)
00199 {
00200 switch (olevel) {
00201 case 0: return O_O0;
00202 case 1: return O_O1;
00203 case 2: return O_O2;
00204 case 3: return O_O3;
00205 default: return O_Unrecognized;
00206 }
00207 }
00208
00209
00210 void
00211 turn_down_opt_level (int new_olevel, char *msg)
00212 {
00213 int flag;
00214 int new_flag;
00215 if (fullwarn) warning(msg);
00216 flag = get_olevel_flag(olevel);
00217 new_flag = get_olevel_flag(new_olevel);
00218 if (option_was_seen(O_O))
00219 replace_option_seen (O_O, new_flag);
00220 else if (option_was_seen(flag))
00221 replace_option_seen (flag, new_flag);
00222 else
00223 internal_error("driver didn't find -O flag");
00224 olevel = new_olevel;
00225 }
00226
00227 static void
00228 turn_off_ipa (char *msg)
00229 {
00230 int flag;
00231 warning (msg);
00232 ipa = FALSE;
00233
00234 FOREACH_OPTION_SEEN(flag) {
00235 if (flag == O_ipa)
00236 set_option_unseen(flag);
00237 else if (flag == O_IPA)
00238 set_option_unseen(flag);
00239 else if (is_derived_option (flag)
00240 && get_derived_parent(flag) == O_IPA_)
00241 set_option_unseen(flag);
00242 }
00243 }
00244
00245 void
00246 add_special_options (void)
00247 {
00248 int flag;
00249 buffer_t buf;
00250 char *s;
00251 boolean undefined_olevel_flag = FALSE;
00252
00253
00254
00255
00256
00257
00258 add_phase_for_option(O_MDupdate,P_f90_fe);
00259 add_phase_for_option(O_MDtarget,P_f90_fe);
00260 remove_phase_for_option(O_MDupdate,P_f90_cpp);
00261 remove_phase_for_option(O_MDtarget,P_f90_cpp);
00262
00263 add_phase_for_option(O_D, P_cppf90_fe);
00264 add_phase_for_option(O_U, P_cppf90_fe);
00265 add_phase_for_option(O_E, P_cppf90_fe);
00266 add_phase_for_option(O_P, P_cppf90_fe);
00267
00268 if (use_ftpp == TRUE) {
00269
00270
00271
00272 flag = add_string_option(O_D, "_LITTLE_ENDIAN");
00273 prepend_option_seen (flag);
00274 flag = add_string_option(O_D, "__LONG_MAX__=9223372036854775807L");
00275 prepend_option_seen (flag);
00276 prepend_option_seen (O_cpp_nonansi);
00277 if (keep_flag) {
00278 add_phase_for_option (O_keep, P_cppf90_fe);
00279 }
00280 }
00281
00282 if (option_was_seen(O_traditional)
00283 && !option_was_seen(O_traditional_cpp))
00284 {
00285
00286 add_phase_for_option(O_traditional, P_c_gfe);
00287 add_phase_for_option(O_traditional, P_cplus_gfe);
00288 #ifdef KEY
00289 add_phase_for_option(O_traditional, P_spin_cc1);
00290 add_phase_for_option(O_traditional, P_spin_cc1plus);
00291 #endif
00292 }
00293
00294 #if defined(TARG_IA32)
00295 flag = add_string_option(O_D, "__NO_MATH_INLINES");
00296 prepend_option_seen (flag);
00297 #endif
00298
00299 #ifdef KEY
00300
00301
00302 if (mpkind == NORMAL_MP &&
00303 gnu_major_version == 4 &&
00304 gnu_minor_version >= 2 &&
00305 (invoked_lang == L_cc ||
00306 invoked_lang == L_CC)) {
00307 set_option_unseen(O_mp);
00308 set_option_unseen(O_openmp);
00309 add_option_seen(O_fopenmp);
00310 }
00311 #endif
00312
00313 #ifndef KEY // Bug 4406.
00314 if (mpkind == CRAY_MP) {
00315 Process_Cray_Mp();
00316 }
00317 else if (mpkind == NORMAL_MP || auto_parallelize) {
00318 Process_Mp();
00319 }
00320 #endif
00321
00322 #ifndef KEY // Bug 7263.
00323 if (auto_parallelize && ipa) {
00324 flag = add_new_option("-IPA:array_summary");
00325 add_phase_for_option(flag, P_ipl);
00326 prepend_option_seen (flag);
00327 }
00328 #endif
00329
00330 if ((mpkind == NORMAL_MP
00331 #ifndef KEY
00332 || auto_parallelize
00333 #endif
00334 ) && !Disable_open_mp) {
00335 flag = add_string_option(O_D, "_OPENMP=199810");
00336 prepend_option_seen (flag);
00337 }
00338
00339 if (olevel == UNDEFINED) {
00340 olevel = default_olevel;
00341 if (olevel == UNDEFINED) {
00342
00343 olevel = 0;
00344 }
00345 flag = get_olevel_flag(olevel);
00346 prepend_option_seen (flag);
00347
00348 undefined_olevel_flag = TRUE;
00349 }
00350 if (!nostdinc) {
00351
00352 if (abi != ABI_I64 && abi != ABI_I32 && abi != ABI_IA32) {
00353 flag = add_string_option(O_I__,
00354 concat_strings(get_phase_dir(P_include),"/CC"));
00355 set_language_for_option (flag, L_CC);
00356 add_option_seen (flag);
00357 }
00358 }
00359 if (!is_toggled(gnum)) {
00360
00361 if (abi == ABI_RAG32) {
00362
00363 if (shared == NON_SHARED) {
00364 toggle(&gnum,8);
00365 } else {
00366 toggle(&gnum,0);
00367 }
00368 } else {
00369 toggle(&gnum,8);
00370 }
00371 sprintf(buf, "%d", gnum);
00372 flag = add_string_option(O_G__, buf);
00373 prepend_option_seen(flag);
00374 }
00375
00376
00377
00378
00379
00380
00381 if (undefined_olevel_flag == TRUE && glevel > 1 && ipa != TRUE) {
00382 turn_down_opt_level(0, "-g changes optimization to -O0 since no optimization level is specified");
00383 }
00384
00385 #ifdef KEY
00386
00387
00388
00389
00390
00391 if (olevel == 0 && inline_t == UNDEFINED)
00392 inline_t = FALSE;
00393 #endif
00394
00395 #ifdef KEY
00396
00397
00398
00399
00400
00401
00402
00403 if ((invoked_lang == L_f77 || invoked_lang == L_f90) &&
00404 (option_was_seen(O_g3))) {
00405 glevel = 2;
00406 replace_option_seen (O_g3, O_g2);
00407 }
00408 #else
00409 if (olevel >= 2 && glevel == 2) {
00410 glevel = 3;
00411 if (option_was_seen (O_g))
00412 replace_option_seen (O_g, O_g3);
00413 if (option_was_seen (O_g2))
00414 replace_option_seen (O_g2, O_g3);
00415 }
00416 #endif
00417
00418 if (option_was_seen(O_S) && ipa == TRUE) {
00419 turn_off_ipa ("-IPA -S combination not allowed, replaced with -S");
00420 }
00421 #ifdef IPA_PROFILING_O3_NOT_COEXIST
00422 if (instrumentation_invoked == TRUE) {
00423 if (ipa == TRUE) {
00424 inline_t = FALSE;
00425 turn_off_ipa ("-fb_create requires no -IPA");
00426 }
00427 if (olevel > 2)
00428 turn_down_opt_level (2, "-fb_create conflicts with -Ofast/-O3; changing to -O2");
00429 }
00430 #endif
00431 if (Gen_feedback && olevel > 0) {
00432 turn_down_opt_level(0, "-fbgen conflicts with -O; changing to -O0");
00433 }
00434 if (Gen_feedback && ipa == TRUE) {
00435 turn_off_ipa ("-IPA -fbgen combination not allowed, replaced with -fbgen");
00436 }
00437
00438 if (glevel > 1 && ipa == TRUE) {
00439 turn_off_ipa ("-IPA -g combination not allowed, replaced with -g");
00440 }
00441 if (ipa == TRUE) {
00442 #ifdef KEY // bug 8130
00443 if (option_was_seen (O_fprofile_arcs))
00444 error ("IPA not supported with -fprofile-arcs");
00445 if (option_was_seen (O_ftest_coverage))
00446 error ("IPA not supported with -ftest-coverage");
00447 #endif
00448 if (olevel <= 1)
00449 flag = add_string_option (O_PHASE_, "i");
00450 else
00451 flag = add_string_option (O_PHASE_, "p:i");
00452 } else {
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 if (source_kind == S_O)
00463 warning("compiles of WOPT-generated .O files will usually fail due to missing state information");
00464 if (olevel <= 1 || source_kind == S_O)
00465 flag = add_string_option(O_PHASE_, "c");
00466 else if (olevel == 2 || source_kind == S_N)
00467 flag = add_string_option(O_PHASE_, "w:c");
00468 else
00469 #ifdef TARG_NVISA
00470
00471 flag = add_string_option(O_PHASE_, "p:w:c");
00472 #else
00473 flag = add_string_option(O_PHASE_, "l:w:c");
00474 #endif
00475 }
00476 prepend_option_seen (flag);
00477
00478 if (abi == ABI_N32 || abi == ABI_64) {
00479 #ifndef KEY
00480 set_dsm_options ();
00481 #endif
00482 }
00483
00484 if (option_was_seen(O_ar) && outfile == NULL) {
00485 error("-ar option requires archive name to be specified with -o option");
00486 }
00487
00488 if (skip_as == UNDEFINED) {
00489 skip_as = FALSE;
00490 }
00491 if (skip_as == FALSE && ! keep_flag && last_phase != P_be) {
00492
00493
00494 flag = add_string_option(O_LIST_, "source=off:notes=off");
00495 prepend_option_seen (flag);
00496 }
00497
00498 if (option_was_seen(O_static) && invoked_lang == L_f90) {
00499
00500
00501
00502 warning("Under Linux, -static is a linker option for using static libraries; if you wanted to put local data in static area, use -static-data instead");
00503 }
00504 }
00505