X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fscripts%2Fgenerate_regalloc_if.pl;h=6043999f6236fb111849ce0bbef063c8ec64053a;hb=628ca4a71914f6655218ad5aa3c177d6dad8213a;hp=45c1054a777b851612596f85a4e199adaab8d547;hpb=0ecc82d4ade99a9561adc8ec3fc15e05a3386071;p=libfirm diff --git a/ir/be/scripts/generate_regalloc_if.pl b/ir/be/scripts/generate_regalloc_if.pl index 45c1054a7..6043999f6 100755 --- a/ir/be/scripts/generate_regalloc_if.pl +++ b/ir/be/scripts/generate_regalloc_if.pl @@ -1,13 +1,32 @@ #!/usr/bin/perl -w -# This script generates C code which emits assembler code for the -# assembler ir nodes. It takes a "emit" key from the node specification -# and substitutes lines starting with . with a corresponding fprintf(). +# +# Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. +# +# This file is part of libFirm. +# +# This file may be distributed and/or modified under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL included in the +# packaging of this file. +# +# Licensees holding valid libFirm Professional Edition licenses may use +# this file in accordance with the libFirm Commercial License. +# Agreement provided with the Software. +# +# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE. +# + +# This script generates C code which creates ands sets up functions and +# data structures for the register allocator. # Creation: 2005/11/14 # $Id$ use strict; use Data::Dumper; +use integer; my $specfile = $ARGV[0]; my $target_dir = $ARGV[1]; @@ -15,16 +34,18 @@ my $target_dir = $ARGV[1]; our $arch; our %reg_classes; our %nodes; +our %cpu; +our %flags = (); # include spec file my $return; -no strict "subs"; +use strict "subs"; unless ($return = do $specfile) { - warn "couldn't parse $specfile: $@" if $@; - warn "couldn't do $specfile: $!" unless defined $return; - warn "couldn't run $specfile" unless $return; + die "couldn't parse $specfile: $@" if $@; + die "couldn't do $specfile: $!" unless defined $return; + die "couldn't run $specfile" unless $return; } use strict "subs"; @@ -54,21 +75,33 @@ sub translate_reg_type { push(@types, "arch_register_type_ignore"); } + if ($t & 8) { + push(@types, "arch_register_type_joker"); + } + + if ($t & 16) { + push(@types, "arch_register_type_virtual"); + } + + if ($t & 32) { + push(@types, "arch_register_type_state"); + } + return join(" | ", @types); } } # stacks for output -my @obst_regtypes; # stack for the register type variables +my @obst_regtypes_def; # stack for the register type variables definitions +my @obst_regtypes_decl;# stack for the register type variables declarations my @obst_regclasses; # stack for the register class variables my @obst_classdef; # stack to define a name for a class index my @obst_regdef; # stack to define a name for a register index my @obst_reginit; # stack for the register type inits my @obst_req; # stack for the register requirements my @obst_limit_func; # stack for functions to return a subset of a register class -my @obst_defreq_head; # stack for prototypes of default requirement function my @obst_header_all; # stack for some extern struct defs needed for bearch_$arch include -my @obst_requirement_def; # stack for requirement name defines +my @obst_header_t; my $numregs; my $class_ptr; @@ -77,28 +110,19 @@ my $class_idx = 0; my $tmp; my %reg2class; +my %regclass2len; -# there is a default NONE requirement -$tmp = "/* Default NONE register requirements */\n"; -$tmp .= "const $arch\_register_req_t $arch\_default_req_none = {\n"; -$tmp .= " {\n"; -$tmp .= " arch_register_req_type_none, /* register type */\n"; -$tmp .= " NULL, /* register class */\n"; -$tmp .= " NULL, /* limit function */\n"; -$tmp .= " NULL, /* limit environment */\n"; -$tmp .= " NULL, /* node for same */\n"; -$tmp .= " NULL /* node for different */\n"; -$tmp .= " },\n"; -$tmp .= " 0, /* same pos */\n"; -$tmp .= " 0 /* different pos */\n"; -$tmp .= "};\n\n"; -push(@obst_req, $tmp); -push(@obst_header_all, "extern const $arch\_register_req_t $arch\_default_req_none;\n"); - -push(@obst_classdef, "#define N_CLASSES ".scalar(keys(%reg_classes))."\n"); +push(@obst_classdef, "enum reg_classes {\n"); my $class_mode; +# assure, the initialization is done only once +push(@obst_reginit, "\tstatic int run_once = 0;\n"); +push(@obst_reginit, "\n"); +push(@obst_reginit, "\tif (run_once)\n"); +push(@obst_reginit, "\t\treturn;\n"); +push(@obst_reginit, "\trun_once = 1;\n"); + # generate register type and class variable, init function and default requirements foreach my $class_name (keys(%reg_classes)) { my @class = @{ $reg_classes{"$class_name"} }; @@ -109,85 +133,70 @@ foreach my $class_name (keys(%reg_classes)) { $class_ptr = "&".$arch."_reg_classes[CLASS_".$class_name."]"; $class_mode = pop(@class)->{"mode"}; - push(@obst_regtypes, "#define $numregs ".($#class + 1)."\n"); - push(@obst_regtypes, "arch_register_t ".$class_name."_regs[$numregs];\n\n"); + push(@obst_regtypes_decl, "extern const arch_register_t ${class_name}_regs[$numregs];\n"); - push(@obst_classdef, "#define CLASS_$class_name $class_idx\n"); + push(@obst_classdef, "\tCLASS_$class_name = $class_idx,\n"); push(@obst_regclasses, "{ \"$class_name\", $numregs, NULL, ".$class_name."_regs }"); - # there is a default NORMAL requirement for each class - $tmp = "/* Default NORMAL register requirements for class $class_name */\n"; - $tmp .= "const $arch\_register_req_t $arch\_default_req_$class_name = {\n"; - $tmp .= " {\n"; - $tmp .= " arch_register_req_type_normal,\n"; - $tmp .= " $class_ptr,\n"; - $tmp .= " NULL, /* limit function */ \n"; - $tmp .= " NULL, /* limit environment */\n"; - $tmp .= " NULL, /* node for same */\n"; - $tmp .= " NULL /* node for different */\n"; - $tmp .= " },\n"; - $tmp .= " 0, /* same pos */\n"; - $tmp .= " 0 /* different pos */\n"; - $tmp .= "};\n\n"; - push(@obst_req, $tmp); - push(@obst_header_all, "extern const $arch\_register_req_t $arch\_default_req_$class_name;\n"); - my $idx = 0; - push(@obst_reginit, " /* Init of all registers in class '$class_name' */\n\n"); - push(@obst_reginit, " /* set largest possible mode for '$class_name' */\n"); - push(@obst_reginit, " $arch\_reg_classes[CLASS_".$class_name."].mode = $class_mode;\n\n"); + push(@obst_reginit, "\t/* set largest possible mode for '$class_name' */\n"); + push(@obst_reginit, "\t$arch\_reg_classes[CLASS_".$class_name."].mode = $class_mode;\n\n"); + push(@obst_regtypes_def, "const arch_register_t ${class_name}_regs[$numregs] = {\n"); + + push(@obst_regdef, "enum reg_${class_name}_indices {\n"); foreach (@class) { - # For each class we build for each of it's member registers a limit function - # which limits the class to this particular register. We also build the - # corresponding requirement structs. - # We need those functions to set register requirements on demand in transformation - # esp. for Call and RegParams where we can mix int and float parameters. - - my $limit_func_name = $arch."_limit_".$class_name."_".$_->{"name"}; - - # push the function prototype - $tmp = "void $limit_func_name(void *_unused, bitset_t *bs)"; - push(@obst_defreq_head, $tmp.";\n"); - - # push the function definition - $tmp .= " {\n"; - $tmp .= " bs = bitset_clear_all(bs);\n"; - $tmp .= " bitset_set(bs, REG_".uc($_->{"name"}).");\n"; # REGISTER to index assignment is done some lines down - $tmp .= "}\n\n"; - push(@obst_limit_func, $tmp); - - # push the default requirement struct - $tmp = "const $arch\_register_req_t $arch\_default_req_$class_name\_".$_->{"name"}." = {\n"; - $tmp .= " {\n"; - $tmp .= " arch_register_req_type_limited,\n"; - $tmp .= " $class_ptr,\n"; - $tmp .= " $limit_func_name,\n"; - $tmp .= " NULL, /* limit environment */\n"; - $tmp .= " NULL, /* node for same */\n"; - $tmp .= " NULL /* node for different */\n"; - $tmp .= " },\n"; - $tmp .= " 0, /* same pos */\n"; - $tmp .= " 0 /* different pos */\n"; - $tmp .= "};\n\n"; - push(@obst_req, $tmp); - push(@obst_header_all,"extern const $arch\_register_req_t $arch\_default_req_$class_name\_".$_->{"name"}.";\n"); + my $ucname = uc($_->{"name"}); + my $type = translate_reg_type($_->{"type"}); + # realname is name if not set by user + $_->{"realname"} = $_->{"name"} if (! exists($_->{"realname"})); + my $realname = $_->{realname}; + my $execunitvarname = get_execunit_variable_name($_->{"unit"}); + $reg2class{$_->{"name"}} = { "class" => $old_classname, "index" => $idx }; # remember reg to class for later use - push(@obst_regdef, "#define REG_".uc($_->{"name"})." $idx\n"); - push(@obst_reginit, " ".$class_name."_regs[$idx].name = \"".$_->{"name"}."\";\n"); - push(@obst_reginit, " ".$class_name."_regs[$idx].reg_class = $class_ptr;\n"); - push(@obst_reginit, " ".$class_name."_regs[$idx].index = $idx;\n"); - push(@obst_reginit, " ".$class_name."_regs[$idx].type = ".translate_reg_type($_->{"type"}).";\n"); - push(@obst_reginit, "\n"); + push(@obst_regdef, "\tREG_${ucname},\n"); + + push(@obst_regtypes_def, "\t{\n"); + push(@obst_regtypes_def, "\t\t\"$realname\",\n"); + push(@obst_regtypes_def, "\t\t$class_ptr,\n"); + push(@obst_regtypes_def, "\t\tREG_${ucname},\n"); + push(@obst_regtypes_def, "\t\t$type,\n"); + push(@obst_regtypes_def, "\t\t$execunitvarname\n"); + push(@obst_regtypes_def, "\t},\n"); + +# push(@obst_reginit, "\t${class_name}_regs[$idx].name = \"".$_->{"realname"}."\";\n"); +# push(@obst_reginit, "\t${class_name}_regs[$idx].reg_class = $class_ptr;\n"); +# push(@obst_reginit, "\t${class_name}_regs[$idx].index = $idx;\n"); +# push(@obst_reginit, "\t${class_name}_regs[$idx].type = ".translate_reg_type($_->{"type"}).";\n"); +# push(@obst_reginit, "\t${class_name}_regs[$idx].data = ".get_execunit_variable_name($_->{"unit"}).";\n"); +# push(@obst_reginit, "\n"); $idx++; } + push(@obst_regtypes_def, "};\n"); + + $regclass2len{$old_classname} = $idx; + push(@obst_regdef, "\t$numregs = $idx\n"); + push(@obst_regdef, "};\n\n"); $class_idx++; } +push(@obst_regdef, "enum flag_indices {\n"); +foreach my $flag (keys(%flags)) { + my %f = %{ $flags{$flag} }; + + push(@obst_regdef, "\tFLAG_$flag,\n"); +} +push(@obst_regdef, "\tFLAG_LAST\n"); +push(@obst_regdef, "};\n"); +push(@obst_regtypes_decl, "extern arch_flag_t ${arch}_flags[];\n"); + +push(@obst_classdef, "\tN_CLASSES = ".scalar(keys(%reg_classes))."\n"); +push(@obst_classdef, "};\n\n"); + # generate node-register constraints foreach my $op (keys(%nodes)) { - my %n = %{ $nodes{"$op"} }; + my %n = %{ $nodes{$op} }; next if (!exists($n{"reg_req"})); @@ -216,9 +225,6 @@ my $creation_time = localtime(time()); $tmp = uc($arch); print OUT<$target_h") || die("Could not open $target_h, reason: $!\n"); $creation_time = localtime(time()); print OUT<$target_c") || die("Could not open $target_c, reason: $!\n"); $creation_time = localtime(time()); @@ -295,18 +302,28 @@ print OUT< 0 ? 1 : 0); + for(my $i = 0; $i < $limitarraylen; $i++) { + my $limitarraypart = $limit_array[$i]; + if($first) { + $first = 0; + } else { + push(@obst_limit_func, ", "); + } + my $temp; + if($neg) { + $temp = "0xFFFFFFFF"; + } + foreach my $reg (@{$limitarraypart}) { + if($neg) { + $temp .= " & ~"; + } elsif(defined($temp)) { + $temp .= " | "; + } + $temp .= "BIT(REG_".uc(${reg}).")"; + } + if(defined($temp)) { + push(@obst_limit_func, "${temp}"); + } else { + push(@obst_limit_func, "0"); + } + } + push(@obst_limit_func, " };\n"); } return ($class, $has_limit, $same_pos, $different_pos); } + +### +# Gets the variable name for the execution unit assigned to this register. +### +sub get_execunit_variable_name { + my $unit = shift; + my $name = "NULL"; + my $uc_arch = uc($arch); + + if ($unit) { + my $found = 0; +SRCH: foreach my $cur_type (keys(%cpu)) { + foreach my $cur_unit (@{ $cpu{"$cur_type"} }) { + if ($unit eq $cur_unit) { + my $tp_name = "$arch\_execution_units_$cur_type"; + my $unit_name = "$uc_arch\_EXECUNIT_TP_$cur_type\_$unit"; + $name = "&".$tp_name."[".$unit_name."]"; + $found = 1; + last SRCH; + } + } + } + + if (! $found) { + print STDERR "Invalid execution unit $unit specified!\n"; + } + } + + return $name; +}