| File: | config/init/optimize.pm |
| Coverage: | 94.2% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2001-2010, Parrot Foundation. | ||||
| 2 | |||||
| 3 - 12 | =head1 NAME config/init/optimize.pm - Optimization =head1 DESCRIPTION Enables optimization by adding the appropriate flags for the local platform to the C<CCFLAGS>. Should this be part of config/inter/progs.pm ? XXX =cut | ||||
| 13 | |||||
| 14 | package init::optimize; | ||||
| 15 | |||||
| 16 | 2 2 2 | use strict; | |||
| 17 | 2 2 2 | use warnings; | |||
| 18 | |||||
| 19 | 2 2 2 | use base qw(Parrot::Configure::Step); | |||
| 20 | |||||
| 21 | sub _init { | ||||
| 22 | 8 | my $self = shift; | |||
| 23 | return { | ||||
| 24 | 8 | 'description', 'Enable optimization', | |||
| 25 | 'result', '', | ||||
| 26 | }; | ||||
| 27 | } | ||||
| 28 | |||||
| 29 | sub runstep { | ||||
| 30 | 8 | my ( $self, $conf ) = @_; | |||
| 31 | |||||
| 32 | 8 | $conf->debug("\n"); | |||
| 33 | |||||
| 34 | 8 | $conf->debug("(optimization options: init::optimize)\n"); | |||
| 35 | |||||
| 36 | # A plain --optimize means use perl5's $Config{optimize}. If an argument | ||||
| 37 | # is given, however, use that instead. | ||||
| 38 | 8 | my $request_optimize = $conf->options->get('optimize') || ''; | |||
| 39 | |||||
| 40 | 8 | if (! $request_optimize) { | |||
| 41 | 3 | $self->set_result('no'); | |||
| 42 | 3 | $conf->debug("(none requested) "); | |||
| 43 | 3 | return 1; | |||
| 44 | } | ||||
| 45 | |||||
| 46 | 5 | my $optimization_level; | |||
| 47 | 5 | if ( $request_optimize eq '1' ) { | |||
| 48 | # i.e., if command-line has '--optimize', | ||||
| 49 | # start with perl5's flags ... | ||||
| 50 | 4 | $optimization_level = $conf->data->get('optimize_provisional'); | |||
| 51 | |||||
| 52 | # ... but gcc 4.1 doesn't like -mcpu=xx, i.e. it's deprecated | ||||
| 53 | 4 | my $gccversion = $conf->data->get( 'gccversion' ); | |||
| 54 | 4 | if ( defined $gccversion and $gccversion > 3.3 ) { | |||
| 55 | 3 | $optimization_level =~ s/-mcpu=/-march=/; | |||
| 56 | } | ||||
| 57 | } | ||||
| 58 | else { | ||||
| 59 | # Otherwise, use the command-line verbatim, e.g. '--optimize=O3' | ||||
| 60 | 1 | $optimization_level = $request_optimize; | |||
| 61 | } | ||||
| 62 | |||||
| 63 | # save the options, however we got them. | ||||
| 64 | 5 | $conf->data->set( optimize => $optimization_level ); | |||
| 65 | 5 | $conf->debug("optimize options: ", $optimization_level, "\n"); | |||
| 66 | |||||
| 67 | # disable debug flags. | ||||
| 68 | 5 | $conf->data->set( cc_debug => '' ); | |||
| 69 | 5 | $conf->data->add( ' ', ccflags => "-DDISABLE_GC_DEBUG=1 -DNDEBUG" ); | |||
| 70 | |||||
| 71 | # TT #405 | ||||
| 72 | 5 | if ($conf->data->get('cpuarch') eq 'amd64') { | |||
| 73 | 0 | $conf->data->set('optimize::src/gc/system.c',''); | |||
| 74 | } | ||||
| 75 | 5 | $self->set_result('yes'); | |||
| 76 | |||||
| 77 | 5 | return 1; | |||
| 78 | } | ||||
| 79 | |||||
| 80 | 1; | ||||
| 81 | |||||
| 82 | # Local Variables: | ||||
| 83 | # mode: cperl | ||||
| 84 | # cperl-indent-level: 4 | ||||
| 85 | # fill-column: 100 | ||||
| 86 | # End: | ||||
| 87 | # vim: expandtab shiftwidth=4: | ||||