be_abi_put_ignore_regs returns now number of ignore registers as unsigned
[libfirm] / ir / be / scripts / generate_regalloc_if.pl
1 #!/usr/bin/perl -w
2
3 #
4 # Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
5 #
6 # This file is part of libFirm.
7 #
8 # This file may be distributed and/or modified under the terms of the
9 # GNU General Public License version 2 as published by the Free Software
10 # Foundation and appearing in the file LICENSE.GPL included in the
11 # packaging of this file.
12 #
13 # Licensees holding valid libFirm Professional Edition licenses may use
14 # this file in accordance with the libFirm Commercial License.
15 # Agreement provided with the Software.
16 #
17 # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE.
20 #
21
22 # This script generates C code which creates ands sets up functions and
23 # data structures for the register allocator.
24 # Creation: 2005/11/14
25 # $Id$
26
27 use strict;
28 use Data::Dumper;
29 use integer;
30
31 my $specfile   = $ARGV[0];
32 my $target_dir = $ARGV[1];
33
34 our $arch;
35 our %reg_classes;
36 our %nodes;
37 our %cpu;
38 our %flags = ();
39
40 # include spec file
41
42 my $return;
43
44 use strict "subs";
45 unless ($return = do $specfile) {
46         die "couldn't parse $specfile: $@" if $@;
47         die "couldn't do $specfile: $!"    unless defined $return;
48         die "couldn't run $specfile"       unless $return;
49 }
50 use strict "subs";
51
52 my $target_c   = $target_dir."/gen_".$arch."_regalloc_if.c";
53 my $target_h   = $target_dir."/gen_".$arch."_regalloc_if.h";
54 my $target_h_t = $target_dir."/gen_".$arch."_regalloc_if_t.h";
55
56 # helper function
57 sub translate_reg_type {
58         my $t = shift;
59
60         if ($t == 0) {
61                 return "arch_register_type_none";
62         }
63         else {
64                 my @types;
65
66                 if ($t & 1) {
67                         push(@types, "arch_register_type_caller_save");
68                 }
69
70                 if ($t & 2) {
71                         push(@types, "arch_register_type_callee_save");
72                 }
73
74                 if ($t & 4) {
75                         push(@types, "arch_register_type_ignore");
76                 }
77
78                 if ($t & 8) {
79                         push(@types, "arch_register_type_joker");
80                 }
81
82                 if ($t & 16) {
83                         push(@types, "arch_register_type_virtual");
84                 }
85
86                 if ($t & 32) {
87                         push(@types, "arch_register_type_state");
88                 }
89
90                 return join(" | ", @types);
91         }
92 }
93
94 # stacks for output
95 my @obst_regtypes_def; # stack for the register type variables definitions
96 my @obst_regtypes_decl;# stack for the register type variables declarations
97 my @obst_regclasses;   # stack for the register class variables
98 my @obst_classdef;     # stack to define a name for a class index
99 my @obst_regdef;       # stack to define a name for a register index
100 my @obst_reginit;      # stack for the register type inits
101 my @obst_req;          # stack for the register requirements
102 my @obst_limit_func;   # stack for functions to return a subset of a register class
103 my @obst_header_all;   # stack for some extern struct defs needed for bearch_$arch include
104 my @obst_header_t;
105
106 my $numregs;
107 my $class_ptr;
108 my $class_idx = 0;
109
110 my $tmp;
111
112 my %reg2class;
113 my %regclass2len;
114
115 push(@obst_classdef, "enum reg_classes {\n");
116
117 my $class_mode;
118
119 # assure, the initialization is done only once
120 push(@obst_reginit, "\tstatic int run_once = 0;\n");
121 push(@obst_reginit, "\n");
122 push(@obst_reginit, "\tif (run_once)\n");
123 push(@obst_reginit, "\t\treturn;\n");
124 push(@obst_reginit, "\trun_once = 1;\n");
125
126 # generate register type and class variable, init function and default requirements
127 foreach my $class_name (keys(%reg_classes)) {
128         my @class         = @{ $reg_classes{"$class_name"} };
129         my $old_classname = $class_name;
130
131         $class_name = $arch."_".$class_name;
132         $numregs    = "N_".$class_name."_REGS";
133         $class_ptr  = "&".$arch."_reg_classes[CLASS_".$class_name."]";
134         $class_mode = pop(@class)->{"mode"};
135
136         push(@obst_regtypes_decl, "extern const arch_register_t ${class_name}_regs[$numregs];\n");
137
138         push(@obst_classdef, "\tCLASS_$class_name = $class_idx,\n");
139         push(@obst_regclasses, "{ \"$class_name\", $numregs, NULL, ".$class_name."_regs }");
140
141         my $idx = 0;
142         push(@obst_reginit, "\t/* set largest possible mode for '$class_name' */\n");
143         push(@obst_reginit, "\t$arch\_reg_classes[CLASS_".$class_name."].mode = $class_mode;\n\n");
144         push(@obst_regtypes_def, "const arch_register_t ${class_name}_regs[$numregs] = {\n");
145
146         push(@obst_regdef, "enum reg_${class_name}_indices {\n");
147         foreach (@class) {
148                 my $ucname = uc($_->{"name"});
149                 my $type = translate_reg_type($_->{"type"});
150                 # realname is name if not set by user
151                 $_->{"realname"} = $_->{"name"} if (! exists($_->{"realname"}));
152                 my $realname = $_->{realname};
153                 my $execunitvarname = get_execunit_variable_name($_->{"unit"});
154
155
156                 $reg2class{$_->{"name"}} = { "class" => $old_classname, "index" => $idx }; # remember reg to class for later use
157                 push(@obst_regdef, "\tREG_${ucname},\n");
158
159                 push(@obst_regtypes_def, "\t{\n");
160                 push(@obst_regtypes_def, "\t\t\"$realname\",\n");
161                 push(@obst_regtypes_def, "\t\t$class_ptr,\n");
162                 push(@obst_regtypes_def, "\t\tREG_${ucname},\n");
163                 push(@obst_regtypes_def, "\t\t$type,\n");
164                 push(@obst_regtypes_def, "\t\t$execunitvarname\n");
165                 push(@obst_regtypes_def, "\t},\n");
166
167 #               push(@obst_reginit, "\t${class_name}_regs[$idx].name      = \"".$_->{"realname"}."\";\n");
168 #               push(@obst_reginit, "\t${class_name}_regs[$idx].reg_class = $class_ptr;\n");
169 #               push(@obst_reginit, "\t${class_name}_regs[$idx].index     = $idx;\n");
170 #               push(@obst_reginit, "\t${class_name}_regs[$idx].type      = ".translate_reg_type($_->{"type"}).";\n");
171 #               push(@obst_reginit, "\t${class_name}_regs[$idx].data      = ".get_execunit_variable_name($_->{"unit"}).";\n");
172 #               push(@obst_reginit, "\n");
173                 $idx++;
174         }
175         push(@obst_regtypes_def, "};\n");
176
177         $regclass2len{$old_classname} = $idx;
178         push(@obst_regdef, "\t$numregs = $idx\n");
179         push(@obst_regdef, "};\n\n");
180
181         $class_idx++;
182 }
183
184 push(@obst_regdef, "enum flag_indices {\n");
185 foreach my $flag (keys(%flags)) {
186         my %f = %{ $flags{$flag} };
187
188         push(@obst_regdef, "\tFLAG_$flag,\n");
189 }
190 push(@obst_regdef, "\tFLAG_LAST\n");
191 push(@obst_regdef, "};\n");
192 push(@obst_regtypes_decl, "extern arch_flag_t ${arch}_flags[];\n");
193
194 push(@obst_classdef, "\tN_CLASSES = ".scalar(keys(%reg_classes))."\n");
195 push(@obst_classdef, "};\n\n");
196
197 # generate node-register constraints
198 foreach my $op (keys(%nodes)) {
199         my %n = %{ $nodes{$op} };
200
201         next if (!exists($n{"reg_req"}));
202
203         $op = $arch."_".$op;
204
205         push(@obst_req, "/* IN requirements for '$op' */\n");
206         # check for argument requirements
207         if (exists($n{"reg_req"}{"in"})) {
208                 generate_requirements(\%n, $op, "in");
209         }
210
211         push(@obst_req, "/* OUT requirements for '$op' */\n");
212         # check for result requirements
213         if (exists($n{"reg_req"}{"out"})) {
214                 generate_requirements(\%n, $op, "out");
215         }
216 }
217
218
219
220 # generate header _t (internal usage) file
221 open(OUT, ">$target_h_t") || die("Could not open $target_h_t, reason: $!\n");
222
223 my $creation_time = localtime(time());
224
225 $tmp = uc($arch);
226
227 print OUT<<EOF;
228 /**
229  * \@file
230  * \@brief    Generated register classes from spec.
231  * \@note     DO NOT EDIT THIS FILE, your changes will be lost.
232  *           Edit $specfile instead.
233  *           created by: $0 $specfile $target_dir
234  * \$date     $creation_time
235  */
236 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_T_H
237 #define FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_T_H
238
239 #include "gen_${arch}_regalloc_if.h"
240
241 EOF
242
243 print OUT @obst_header_t;
244
245 print OUT "\n#endif\n";
246
247
248 # generate header (external usage) file
249 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
250
251 $creation_time = localtime(time());
252
253 print OUT<<EOF;
254 /**
255  * \@file
256  * \@brief Contains additional external requirements defs for external includes.
257  * \@note   DO NOT EDIT THIS FILE, your changes will be lost.
258  *         Edit $specfile instead.
259  *         created by: $0 $specfile $target_dir
260  * \@date   $creation_time
261  */
262 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_H
263 #define FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_H
264
265 #include "../bearch.h"
266 #include "${arch}_nodes_attr.h"
267
268 EOF
269
270 print OUT @obst_regdef, "\n";
271
272 print OUT @obst_classdef, "\n";
273
274 print OUT @obst_regtypes_decl, "\n";
275
276 print OUT "extern arch_register_class_t $arch\_reg_classes[N_CLASSES];\n\n";
277
278 print OUT "void ".$arch."_register_init(void *isa_ptr);\n\n";
279
280 print OUT @obst_header_all, "\n";
281
282 print OUT "\n#endif\n";
283
284 close(OUT);
285
286
287
288 # generate c file
289 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
290
291 $creation_time = localtime(time());
292
293 print OUT<<EOF;
294 /**
295  * \@file
296  * \@brief  The generated interface for the register allocator.
297  *          Contains register classes and types and register constraints
298  *          for all nodes where constraints were given in spec.
299  * \@note    DO NOT EDIT THIS FILE, your changes will be lost.
300  *          Edit $specfile instead.
301  *          created by: $0 $specfile $target_dir
302  * \$date    $creation_time
303  */
304 #ifdef HAVE_CONFIG_H
305 #include "config.h"
306 #endif
307
308 #include "gen_${arch}_regalloc_if.h"
309 #include "gen_${arch}_machine.h"
310 #include "bearch_${arch}_t.h"
311 #include "${arch}_map_regs.h"
312 #include "irmode.h"
313
314 #ifdef BIT
315 #undef BIT
316 #endif
317 #define BIT(x)  (1 << (x % 32))
318
319 EOF
320
321 print OUT "arch_register_class_t ${arch}_reg_classes[] = {\n\t".join(",\n\t", @obst_regclasses)."\n};\n\n";
322
323 print OUT @obst_regtypes_def, "\n";
324
325 print OUT "void ${arch}_register_init(void *isa_ptr) {\n";
326 print OUT @obst_reginit;
327 print OUT "}\n\n";
328
329 print OUT @obst_limit_func;
330
331 print OUT @obst_req;
332
333 close(OUT);
334
335 ###
336 # Remember the register class for each index in the given requirements.
337 # We need this information for requirements like "in_sX" or "out_dX"
338 # @return array of classes corresponding to the requirement for each index
339 ###
340 sub build_inout_idx_class {
341         my $n     = shift;
342         my $op    = shift;
343         my $inout = shift;
344         my @idx_class;
345
346         if (exists($n->{"reg_req"}{"$inout"})) {
347                 my @reqs = @{ $n->{"reg_req"}{"$inout"} };
348
349                 for (my $idx = 0; $idx <= $#reqs; $idx++) {
350                         my $class = undef;
351
352                         if ($reqs[$idx] eq "none") {
353                                 $class = "none";
354                         } elsif (is_reg_class($reqs[$idx])) {
355                                 $class = $reqs[$idx];
356                         } else {
357                                 my @regs = split(/ /, $reqs[$idx]);
358 GET_CLASS:              foreach my $reg (@regs) {
359                                         if ($reg =~ /!?(in|out)\_r\d+/ || $reg =~ /!in/) {
360                                                 $class = "UNKNOWN_CLASS";
361                                         }
362                                         else {
363                                                 $class = get_reg_class($reg);
364                                                 if (!defined $class) {
365                                                         die("Could not get ".uc($inout)." register class for '$op' pos $idx (reg $reg) ... exiting.\n");
366                                                 }
367                                                 else {
368                                                         last GET_CLASS;
369                                                 } # !defined class
370                                         } # if (reg =~ ...
371                                 } # foreach
372                         } # if
373
374                         push(@idx_class, $class);
375                 } # for
376         } # if
377
378         return @idx_class;
379 }
380
381 ###
382 # Generates the requirements for the given description
383 ###
384 sub generate_requirements {
385         my $n     = shift;
386         my $op    = shift;
387         my $inout = shift;
388
389         # get classes for the complementary direction
390         my $outin     = ($inout eq "in") ? "out" : "in";
391
392         my @reqs = @{ $n->{"reg_req"}{"$inout"} };
393
394         for (my $idx = 0; $idx <= $#reqs; $idx++) {
395                 my $class = undef;
396
397                 my $tmp2 = "const arch_register_req_t ${op}_reg_req_${inout}_${idx} = ";
398
399                 if ($reqs[$idx] eq "none") {
400                         $tmp2 .= "{\n";
401                         $tmp2 .= "\tarch_register_req_type_none,\n";
402                         $tmp2 .= "\tNULL,        /* regclass */\n";
403                         $tmp2 .= "\tNULL,        /* limit bitset */\n";
404                         $tmp2 .= "\t-1,          /* same pos */\n";
405                         $tmp2 .= "\t-1           /* different pos */\n";
406                         $tmp2 .= "};\n";
407
408                         push(@obst_req, $tmp2."\n");
409                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
410                 } elsif ($reqs[$idx] =~ /^new_reg_(.*)$/) {
411                         if (is_reg_class($1)) {
412                                 $tmp2 .= "{\n";
413                                 $tmp2 .= "\tarch_register_req_type_should_be_different_from_all,\n";
414                                 $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_$1],\n";
415                                 $tmp2 .= "\tNULL,        /* limit bitset */\n";
416                                 $tmp2 .= "\t-1,          /* same pos */\n";
417                                 $tmp2 .= "\t-1           /* different pos */\n";
418                                 $tmp2 .= "};\n";
419
420                                 push(@obst_req, $tmp2."\n");
421                                 push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
422                         } else {
423                                 print STDERR "Invalid register class '$1' given in OUT requirement $idx for '$op'.\n";
424                         }
425                 } elsif (is_reg_class($reqs[$idx])) {
426                         my $class = $reqs[$idx];
427                         $tmp2 .= "{\n";
428                         $tmp2 .= "\tarch_register_req_type_normal,\n";
429                         $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_${class}],\n";
430                         $tmp2 .= "\tNULL,        /* limit bitset */\n";
431                         $tmp2 .= "\t-1,          /* same pos */\n";
432                         $tmp2 .= "\t-1           /* different pos */\n";
433                         $tmp2 .= "};\n";
434
435                         push(@obst_req, $tmp2."\n");
436                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
437                 } else {
438                         my @req_type_mask;
439                         my ($class, $has_limit, $same_pos, $different_pos) = build_subset_class_func($n, $op, $idx, (($inout eq "in") ? 1 : 0), $reqs[$idx]);
440
441                         if (!defined($class)) {
442                                 die("Could not build subset for ".uc($inout)." requirements '$op' pos $idx ... exiting.\n");
443                         }
444
445                         if ($has_limit) {
446                                 push(@req_type_mask, "arch_register_req_type_limited");
447                         }
448                         if (defined($same_pos)) {
449                                 push(@req_type_mask, "arch_register_req_type_should_be_same");
450                         }
451                         if (defined($different_pos)) {
452                                 if ($different_pos == 666) {
453                                         push(@req_type_mask, "arch_register_req_type_should_be_different_from_all");
454                                         undef $different_pos;
455                                 } else {
456                                         push(@req_type_mask, "arch_register_req_type_should_be_different");
457                                 }
458                         }
459
460                         $tmp2 .= "{\n";
461                         $tmp2 .= "\t".join(" | ", @req_type_mask).",\n";
462                         $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_${class}],\n";
463                         $tmp2 .= "\t".($has_limit ? "limit_reg_${op}_${inout}_${idx}" : "NULL").",\n";
464                         $tmp2 .= "\t".(defined($same_pos) ? $same_pos : "-1").",\n";
465                         $tmp2 .= "\t".(defined($different_pos) ? $different_pos : "-1")."\n";
466                         $tmp2 .= "};\n";
467
468                         push(@obst_req, $tmp2."\n");
469                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
470                 }
471         }
472
473 }
474
475 ###
476 # Determines whether $name is a specified register class or not.
477 # @return 1 if name is register class, 0 otherwise
478 ###
479 sub is_reg_class {
480         my $name = shift;
481         return 1 if exists($reg_classes{"$name"});
482         return 0;
483 }
484
485 ###
486 # Returns the register class for a given register.
487 # @return class or undef
488 ###
489 sub get_reg_class {
490         my $reg = shift;
491         $reg = substr($reg, 1) if ($reg =~ /!.*/);
492         return $reg2class{"$reg"}{"class"} if (exists($reg2class{"$reg"}));
493         return undef;
494 }
495
496 ###
497 # Returns the index of a given register within it's register class.
498 # @return index or undef
499 ###
500 sub get_reg_index {
501         my $reg = shift;
502         return $reg2class{"$reg"}{"index"} if (exists($reg2class{"$reg"}));
503         return undef;
504 }
505
506 ###
507 # Generates the function for a given $op and a given IN-index
508 # which returns a subset of possible register from a register class
509 # @return classname from which the subset is derived or undef and
510 #         pos which corresponds to in/out reference position or undef
511 ###
512 sub build_subset_class_func {
513         my $neg           = undef;
514         my $class         = undef;
515         my $has_limit     = 0;
516         my $same_pos      = undef;
517         my $different_pos = undef;
518         my $temp;
519         my @obst_init;
520         my @obst_limits;
521         my @obst_ignore;
522         my @limit_array;
523
524         # build function header
525         my $n   = shift;
526         my $op  = shift;
527         my $idx = shift;
528         my $in  = shift;
529
530         my $outin = $in ? "out" : "in";
531         my @regs  = split(/ /, shift);
532
533         my @idx_class = build_inout_idx_class($n, $op, $outin);
534
535         # set/unset registers
536 CHECK_REQS: foreach (@regs) {
537                 if (/(!)?$outin\_r(\d+)/) {
538                         if (($1 && defined($different_pos)) || (!$1 && defined($same_pos))) {
539                                 print STDERR "Multiple in/out references of same type in one requirement not allowed.\n";
540                                 return (undef, undef, undef, undef);
541                         }
542
543                         if ($1) {
544                                 $different_pos = $in ? -$2 : $2 - 1;
545                         }
546                         else {
547                                 $same_pos = $in ? -$2 : $2 - 1;
548                         }
549
550                         $class = $idx_class[$2 - 1];
551                         next CHECK_REQS;
552                 }
553                 elsif (/!in/) {
554                         $class = $idx_class[0];
555                         return ($class, 0, undef, 666);
556                 }
557
558                 # check for negate
559                 if (substr($_, 0, 1) eq "!") {
560                         if (defined($neg) && $neg == 0) {
561                                 # we have seen a positiv constraint as first one but this one is negative
562                                 # this doesn't make sense
563                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
564                                 return (undef, undef, undef, undef);
565                         }
566
567                         if (!defined($neg)) {
568                                 $has_limit = 1;
569                         }
570
571                         $_   = substr($_, 1); # skip '!'
572                         $neg = 1;
573                 } else {
574                         if (defined($neg) && $neg == 1) {
575                                 # we have seen a negative constraint as first one but this one is positive
576                                 # this doesn't make sense
577                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
578                                 return (undef, undef, undef, undef);
579                         }
580
581                         $has_limit = 1;
582                         $neg = 0;
583                 }
584
585                 # check if register belongs to one of the given classes
586                 $temp = get_reg_class($_);
587                 if (!defined($temp)) {
588                         print STDERR "Unknown register '$_'!\n";
589                         return (undef, undef, undef, undef);
590                 }
591
592                 # set class
593                 if (!defined($class)) {
594                         $class = $temp;
595                 } elsif ($class ne $temp) {
596                         # all registers must belong to the same class
597                         print STDERR "Registerclass mismatch. '$_' is not member of class '$class'.\n";
598                         return (undef, undef, undef, undef);
599                 }
600
601                 # calculate position inside the initializer bitfield (only 32 bits per
602                 # element)
603                 my $regidx = get_reg_index($_);
604                 my $arrayp = $regidx / 32;
605                 push(@{$limit_array[$arrayp]}, $_);
606         }
607
608         # don't allow ignore regs in negative constraints
609         if($neg) {
610                 my @cur_class = @{ $reg_classes{"$class"} };
611                 for (my $idx = 0; $idx <= $#cur_class; $idx++) {
612                         if (defined($cur_class[$idx]{"type"}) && ($cur_class[$idx]{"type"} & 4)) {
613                                 my $reg = $cur_class[$idx]{"name"};
614                                 my $regix = get_reg_index($reg);
615                                 my $arrayp = $regix / 32;
616                                 push(@{$limit_array[$arrayp]}, $reg);
617                         }
618                 }
619         }
620
621         if ($has_limit == 1) {
622                 push(@obst_limit_func, "static const unsigned limit_reg_${op}_".($in ? "in" : "out")."_". ${idx} ."[] = { ");
623                 my $first = 1;
624                 my $limitbitsetlen = $regclass2len{$class};
625                 my $limitarraylen = $limitbitsetlen / 32 + ($limitbitsetlen % 32 > 0 ? 1 : 0);
626                 for(my $i = 0; $i < $limitarraylen; $i++) {
627                         my $limitarraypart = $limit_array[$i];
628                         if($first) {
629                                 $first = 0;
630                         } else {
631                                 push(@obst_limit_func, ", ");
632                         }
633                         my $temp;
634                         if($neg) {
635                                 $temp = "0xFFFFFFFF";
636                         }
637                         foreach my $reg (@{$limitarraypart}) {
638                                 if($neg) {
639                                         $temp .= " & ~";
640                                 } elsif(defined($temp)) {
641                                         $temp .= " | ";
642                                 }
643                                 $temp .= "BIT(REG_".uc(${reg}).")";
644                         }
645                         if(defined($temp)) {
646                                 push(@obst_limit_func, "${temp}");
647                         } else {
648                                 push(@obst_limit_func, "0");
649                         }
650                 }
651                 push(@obst_limit_func, " };\n");
652         }
653
654         return ($class, $has_limit, $same_pos, $different_pos);
655 }
656
657 ###
658 # Gets the variable name for the execution unit assigned to this register.
659 ###
660 sub get_execunit_variable_name {
661         my $unit    = shift;
662         my $name    = "NULL";
663         my $uc_arch = uc($arch);
664
665         if ($unit) {
666                 my $found = 0;
667 SRCH:   foreach my $cur_type (keys(%cpu)) {
668                         foreach my $cur_unit (@{ $cpu{"$cur_type"} }) {
669                                 if ($unit eq $cur_unit) {
670                                         my $tp_name   = "$arch\_execution_units_$cur_type";
671                                         my $unit_name = "$uc_arch\_EXECUNIT_TP_$cur_type\_$unit";
672                                         $name  = "&".$tp_name."[".$unit_name."]";
673                                         $found = 1;
674                                         last SRCH;
675                                 }
676                         }
677                 }
678
679                 if (! $found) {
680                         print STDERR "Invalid execution unit $unit specified!\n";
681                 }
682         }
683
684         return $name;
685 }