fixed warnings
[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 "Fatal error: couldn't parse $specfile: $@" if $@;
47         die "Fatal error: couldn't do $specfile: $!"    unless defined $return;
48         die "Fatal error: 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 # generate register type and class variable, init function and default requirements
120 foreach my $class_name (keys(%reg_classes)) {
121         my @class         = @{ $reg_classes{"$class_name"} };
122         my $old_classname = $class_name;
123
124         $class_name = $arch."_".$class_name;
125         $numregs    = "N_".$class_name."_REGS";
126         $class_ptr  = "&".$arch."_reg_classes[CLASS_".$class_name."]";
127         $class_mode = pop(@class)->{"mode"};
128
129         push(@obst_regtypes_decl, "extern const arch_register_t ${class_name}_regs[$numregs];\n");
130
131         push(@obst_classdef, "\tCLASS_$class_name = $class_idx,\n");
132         push(@obst_regclasses, "{ \"$class_name\", $numregs, NULL, ".$class_name."_regs }");
133
134         my $idx = 0;
135         push(@obst_reginit, "\t/* set largest possible mode for '$class_name' */\n");
136         push(@obst_reginit, "\t$arch\_reg_classes[CLASS_".$class_name."].mode = $class_mode;\n\n");
137         push(@obst_regtypes_def, "const arch_register_t ${class_name}_regs[$numregs] = {\n");
138
139         push(@obst_regdef, "enum reg_${class_name}_indices {\n");
140         foreach (@class) {
141                 my $ucname = uc($_->{"name"});
142                 my $type = translate_reg_type($_->{"type"});
143                 # realname is name if not set by user
144                 $_->{"realname"} = $_->{"name"} if (! exists($_->{"realname"}));
145                 my $realname = $_->{realname};
146                 my $execunitvarname = get_execunit_variable_name($_->{"unit"});
147
148
149                 $reg2class{$_->{"name"}} = { "class" => $old_classname, "index" => $idx }; # remember reg to class for later use
150                 push(@obst_regdef, "\tREG_${ucname},\n");
151
152                 push(@obst_regtypes_def, "\t{\n");
153                 push(@obst_regtypes_def, "\t\t\"$realname\",\n");
154                 push(@obst_regtypes_def, "\t\t$class_ptr,\n");
155                 push(@obst_regtypes_def, "\t\tREG_${ucname},\n");
156                 push(@obst_regtypes_def, "\t\t$type,\n");
157                 push(@obst_regtypes_def, "\t\t$execunitvarname\n");
158                 push(@obst_regtypes_def, "\t},\n");
159
160 #               push(@obst_reginit, "\t${class_name}_regs[$idx].name      = \"".$_->{"realname"}."\";\n");
161 #               push(@obst_reginit, "\t${class_name}_regs[$idx].reg_class = $class_ptr;\n");
162 #               push(@obst_reginit, "\t${class_name}_regs[$idx].index     = $idx;\n");
163 #               push(@obst_reginit, "\t${class_name}_regs[$idx].type      = ".translate_reg_type($_->{"type"}).";\n");
164 #               push(@obst_reginit, "\t${class_name}_regs[$idx].data      = ".get_execunit_variable_name($_->{"unit"}).";\n");
165 #               push(@obst_reginit, "\n");
166                 $idx++;
167         }
168         push(@obst_regtypes_def, "};\n");
169
170         $regclass2len{$old_classname} = $idx;
171         push(@obst_regdef, "\t$numregs = $idx\n");
172         push(@obst_regdef, "};\n\n");
173
174         $class_idx++;
175 }
176
177 push(@obst_regdef, "enum flag_indices {\n");
178 foreach my $flag (keys(%flags)) {
179         my %f = %{ $flags{$flag} };
180
181         push(@obst_regdef, "\tFLAG_$flag,\n");
182 }
183 push(@obst_regdef, "\tFLAG_LAST\n");
184 push(@obst_regdef, "};\n");
185 push(@obst_regtypes_decl, "extern arch_flag_t ${arch}_flags[];\n");
186
187 push(@obst_classdef, "\tN_CLASSES = ".scalar(keys(%reg_classes))."\n");
188 push(@obst_classdef, "};\n\n");
189
190 # generate node-register constraints
191 foreach my $op (keys(%nodes)) {
192         my %n = %{ $nodes{$op} };
193
194         next if (!exists($n{"reg_req"}));
195
196         $op = $arch."_".$op;
197
198         push(@obst_req, "/* IN requirements for '$op' */\n");
199         # check for argument requirements
200         if (exists($n{"reg_req"}{"in"})) {
201                 generate_requirements(\%n, $op, "in");
202         }
203
204         push(@obst_req, "/* OUT requirements for '$op' */\n");
205         # check for result requirements
206         if (exists($n{"reg_req"}{"out"})) {
207                 generate_requirements(\%n, $op, "out");
208         }
209 }
210
211
212
213 # generate header _t (internal usage) file
214 open(OUT, ">$target_h_t") || die("Fatal error: Could not open $target_h_t, reason: $!\n");
215
216 my $creation_time = localtime(time());
217
218 $tmp = uc($arch);
219
220 print OUT<<EOF;
221 /**
222  * \@file
223  * \@brief    Generated register classes from spec.
224  * \@note     DO NOT EDIT THIS FILE, your changes will be lost.
225  *           Edit $specfile instead.
226  *           created by: $0 $specfile $target_dir
227  * \$date     $creation_time
228  */
229 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_T_H
230 #define FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_T_H
231
232 #include "gen_${arch}_regalloc_if.h"
233
234 EOF
235
236 print OUT @obst_header_t;
237
238 print OUT "\n#endif\n";
239
240
241 # generate header (external usage) file
242 open(OUT, ">$target_h") || die("Fatal error: Could not open $target_h, reason: $!\n");
243
244 $creation_time = localtime(time());
245
246 print OUT<<EOF;
247 /**
248  * \@file
249  * \@brief Contains additional external requirements defs for external includes.
250  * \@note   DO NOT EDIT THIS FILE, your changes will be lost.
251  *         Edit $specfile instead.
252  *         created by: $0 $specfile $target_dir
253  * \@date   $creation_time
254  */
255 #ifndef FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_H
256 #define FIRM_BE_${tmp}_GEN_${tmp}_REGALLOC_IF_H
257
258 #include "../bearch.h"
259 #include "${arch}_nodes_attr.h"
260
261 EOF
262
263 print OUT @obst_regdef, "\n";
264
265 print OUT @obst_classdef, "\n";
266
267 print OUT @obst_regtypes_decl, "\n";
268
269 print OUT "extern arch_register_class_t $arch\_reg_classes[N_CLASSES];\n\n";
270
271 print OUT "void ".$arch."_register_init(void);\n\n";
272
273 print OUT @obst_header_all, "\n";
274
275 print OUT "\n#endif\n";
276
277 close(OUT);
278
279
280
281 # generate c file
282 open(OUT, ">$target_c") || die("Fatal error: Could not open $target_c, reason: $!\n");
283
284 $creation_time = localtime(time());
285
286 print OUT<<EOF;
287 /**
288  * \@file
289  * \@brief  The generated interface for the register allocator.
290  *          Contains register classes and types and register constraints
291  *          for all nodes where constraints were given in spec.
292  * \@note    DO NOT EDIT THIS FILE, your changes will be lost.
293  *          Edit $specfile instead.
294  *          created by: $0 $specfile $target_dir
295  * \$date    $creation_time
296  */
297 #ifdef HAVE_CONFIG_H
298 #include "config.h"
299 #endif
300
301 #include "gen_${arch}_regalloc_if.h"
302 #include "gen_${arch}_machine.h"
303 #include "bearch_${arch}_t.h"
304 #include "${arch}_map_regs.h"
305 #include "irmode.h"
306
307 #ifdef BIT
308 #undef BIT
309 #endif
310 #define BIT(x)  (1 << (x % 32))
311
312 EOF
313
314 print OUT "arch_register_class_t ${arch}_reg_classes[] = {\n\t".join(",\n\t", @obst_regclasses)."\n};\n\n";
315
316 print OUT @obst_regtypes_def, "\n";
317
318 print OUT "void ${arch}_register_init(void) {\n";
319 print OUT @obst_reginit;
320 print OUT "}\n\n";
321
322 print OUT @obst_limit_func;
323
324 print OUT @obst_req;
325
326 close(OUT);
327
328 ###
329 # Remember the register class for each index in the given requirements.
330 # We need this information for requirements like "in_sX" or "out_dX"
331 # @return array of classes corresponding to the requirement for each index
332 ###
333 sub build_inout_idx_class {
334         my $n     = shift;
335         my $op    = shift;
336         my $inout = shift;
337         my @idx_class;
338
339         if (exists($n->{"reg_req"}{"$inout"})) {
340                 my @reqs = @{ $n->{"reg_req"}{"$inout"} };
341
342                 for (my $idx = 0; $idx <= $#reqs; $idx++) {
343                         my $class = undef;
344
345                         if ($reqs[$idx] eq "none") {
346                                 $class = "none";
347                         } elsif (is_reg_class($reqs[$idx])) {
348                                 $class = $reqs[$idx];
349                         } else {
350                                 my @regs = split(/ /, $reqs[$idx]);
351 GET_CLASS:              foreach my $reg (@regs) {
352                                         if ($reg =~ /!?(in|out)\_r\d+/ || $reg =~ /!in/) {
353                                                 $class = "UNKNOWN_CLASS";
354                                         }
355                                         else {
356                                                 $class = get_reg_class($reg);
357                                                 if (!defined $class) {
358                                                         die("Fatal error: Could not get ".uc($inout)." register class for '$op' pos $idx (reg $reg) ... exiting.\n");
359                                                 }
360                                                 else {
361                                                         last GET_CLASS;
362                                                 } # !defined class
363                                         } # if (reg =~ ...
364                                 } # foreach
365                         } # if
366
367                         push(@idx_class, $class);
368                 } # for
369         } # if
370
371         return @idx_class;
372 }
373
374 ###
375 # Generates the requirements for the given description
376 ###
377 sub generate_requirements {
378         my $n     = shift;
379         my $op    = shift;
380         my $inout = shift;
381
382         # get classes for the complementary direction
383         my $outin     = ($inout eq "in") ? "out" : "in";
384
385         my @reqs = @{ $n->{"reg_req"}{"$inout"} };
386
387         for (my $idx = 0; $idx <= $#reqs; $idx++) {
388                 my $class = undef;
389
390                 my $tmp2 = "const arch_register_req_t ${op}_reg_req_${inout}_${idx} = ";
391
392                 if ($reqs[$idx] eq "none") {
393                         $tmp2 .= "{\n";
394                         $tmp2 .= "\tarch_register_req_type_none,\n";
395                         $tmp2 .= "\tNULL,        /* regclass */\n";
396                         $tmp2 .= "\tNULL,        /* limit bitset */\n";
397                         $tmp2 .= "\t-1,          /* same pos */\n";
398                         $tmp2 .= "\t-1           /* different pos */\n";
399                         $tmp2 .= "};\n";
400
401                         push(@obst_req, $tmp2."\n");
402                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
403                 } elsif ($reqs[$idx] =~ /^new_reg_(.*)$/) {
404                         if (is_reg_class($1)) {
405                                 $tmp2 .= "{\n";
406                                 $tmp2 .= "\tarch_register_req_type_should_be_different_from_all,\n";
407                                 $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_$1],\n";
408                                 $tmp2 .= "\tNULL,        /* limit bitset */\n";
409                                 $tmp2 .= "\t-1,          /* same pos */\n";
410                                 $tmp2 .= "\t-1           /* different pos */\n";
411                                 $tmp2 .= "};\n";
412
413                                 push(@obst_req, $tmp2."\n");
414                                 push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
415                         } else {
416                                 print STDERR "Invalid register class '$1' given in OUT requirement $idx for '$op'.\n";
417                         }
418                 } elsif (is_reg_class($reqs[$idx])) {
419                         my $class = $reqs[$idx];
420                         $tmp2 .= "{\n";
421                         $tmp2 .= "\tarch_register_req_type_normal,\n";
422                         $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_${class}],\n";
423                         $tmp2 .= "\tNULL,        /* limit bitset */\n";
424                         $tmp2 .= "\t-1,          /* same pos */\n";
425                         $tmp2 .= "\t-1           /* different pos */\n";
426                         $tmp2 .= "};\n";
427
428                         push(@obst_req, $tmp2."\n");
429                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
430                 } else {
431                         my @req_type_mask;
432                         my ($class, $has_limit, $same_pos, $different_pos) = build_subset_class_func($n, $op, $idx, (($inout eq "in") ? 1 : 0), $reqs[$idx]);
433
434                         if (!defined($class)) {
435                                 die("Fatal error: Could not build subset for ".uc($inout)." requirements '$op' pos $idx ... exiting.\n");
436                         }
437
438                         if ($has_limit) {
439                                 push(@req_type_mask, "arch_register_req_type_limited");
440                         }
441                         if (defined($same_pos)) {
442                                 push(@req_type_mask, "arch_register_req_type_should_be_same");
443                         }
444                         if (defined($different_pos)) {
445                                 if ($different_pos == 666) {
446                                         push(@req_type_mask, "arch_register_req_type_should_be_different_from_all");
447                                         undef $different_pos;
448                                 } else {
449                                         push(@req_type_mask, "arch_register_req_type_should_be_different");
450                                 }
451                         }
452
453                         $tmp2 .= "{\n";
454                         $tmp2 .= "\t".join(" | ", @req_type_mask).",\n";
455                         $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_${class}],\n";
456                         $tmp2 .= "\t".($has_limit ? "limit_reg_${op}_${inout}_${idx}" : "NULL").",\n";
457                         $tmp2 .= "\t".(defined($same_pos) ? $same_pos : "-1").",\n";
458                         $tmp2 .= "\t".(defined($different_pos) ? $different_pos : "-1")."\n";
459                         $tmp2 .= "};\n";
460
461                         push(@obst_req, $tmp2."\n");
462                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
463                 }
464         }
465
466 }
467
468 ###
469 # Determines whether $name is a specified register class or not.
470 # @return 1 if name is register class, 0 otherwise
471 ###
472 sub is_reg_class {
473         my $name = shift;
474         return 1 if exists($reg_classes{"$name"});
475         return 0;
476 }
477
478 ###
479 # Returns the register class for a given register.
480 # @return class or undef
481 ###
482 sub get_reg_class {
483         my $reg = shift;
484         $reg = substr($reg, 1) if ($reg =~ /!.*/);
485         return $reg2class{"$reg"}{"class"} if (exists($reg2class{"$reg"}));
486         return undef;
487 }
488
489 ###
490 # Returns the index of a given register within it's register class.
491 # @return index or undef
492 ###
493 sub get_reg_index {
494         my $reg = shift;
495         return $reg2class{"$reg"}{"index"} if (exists($reg2class{"$reg"}));
496         return undef;
497 }
498
499 ###
500 # Generates the function for a given $op and a given IN-index
501 # which returns a subset of possible register from a register class
502 # @return classname from which the subset is derived or undef and
503 #         pos which corresponds to in/out reference position or undef
504 ###
505 sub build_subset_class_func {
506         my $neg           = undef;
507         my $class         = undef;
508         my $has_limit     = 0;
509         my $same_pos      = undef;
510         my $different_pos = undef;
511         my $temp;
512         my @obst_init;
513         my @obst_limits;
514         my @obst_ignore;
515         my @limit_array;
516
517         # build function header
518         my $n   = shift;
519         my $op  = shift;
520         my $idx = shift;
521         my $in  = shift;
522
523         my $outin = $in ? "out" : "in";
524         my @regs  = split(/ /, shift);
525
526         my @idx_class = build_inout_idx_class($n, $op, $outin);
527
528         # set/unset registers
529 CHECK_REQS: foreach (@regs) {
530                 if (/(!)?$outin\_r(\d+)/) {
531                         if (($1 && defined($different_pos)) || (!$1 && defined($same_pos))) {
532                                 print STDERR "Multiple in/out references of same type in one requirement not allowed.\n";
533                                 return (undef, undef, undef, undef);
534                         }
535
536                         if ($1) {
537                                 $different_pos = $in ? -$2 : $2 - 1;
538                         }
539                         else {
540                                 $same_pos = $in ? -$2 : $2 - 1;
541                         }
542
543                         $class = $idx_class[$2 - 1];
544                         next CHECK_REQS;
545                 }
546                 elsif (/!in/) {
547                         $class = $idx_class[0];
548                         return ($class, 0, undef, 666);
549                 }
550
551                 # check for negate
552                 if (substr($_, 0, 1) eq "!") {
553                         if (defined($neg) && $neg == 0) {
554                                 # we have seen a positiv constraint as first one but this one is negative
555                                 # this doesn't make sense
556                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
557                                 return (undef, undef, undef, undef);
558                         }
559
560                         if (!defined($neg)) {
561                                 $has_limit = 1;
562                         }
563
564                         $_   = substr($_, 1); # skip '!'
565                         $neg = 1;
566                 } else {
567                         if (defined($neg) && $neg == 1) {
568                                 # we have seen a negative constraint as first one but this one is positive
569                                 # this doesn't make sense
570                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
571                                 return (undef, undef, undef, undef);
572                         }
573
574                         $has_limit = 1;
575                         $neg = 0;
576                 }
577
578                 # check if register belongs to one of the given classes
579                 $temp = get_reg_class($_);
580                 if (!defined($temp)) {
581                         print STDERR "Unknown register '$_'!\n";
582                         return (undef, undef, undef, undef);
583                 }
584
585                 # set class
586                 if (!defined($class)) {
587                         $class = $temp;
588                 } elsif ($class ne $temp) {
589                         # all registers must belong to the same class
590                         print STDERR "Registerclass mismatch. '$_' is not member of class '$class'.\n";
591                         return (undef, undef, undef, undef);
592                 }
593
594                 # calculate position inside the initializer bitfield (only 32 bits per
595                 # element)
596                 my $regidx = get_reg_index($_);
597                 my $arrayp = $regidx / 32;
598                 push(@{$limit_array[$arrayp]}, $_);
599         }
600
601         # don't allow ignore regs in negative constraints
602         if($neg) {
603                 my @cur_class = @{ $reg_classes{"$class"} };
604                 for (my $idx = 0; $idx <= $#cur_class; $idx++) {
605                         if (defined($cur_class[$idx]{"type"}) && ($cur_class[$idx]{"type"} & 4)) {
606                                 my $reg = $cur_class[$idx]{"name"};
607                                 my $regix = get_reg_index($reg);
608                                 my $arrayp = $regix / 32;
609                                 push(@{$limit_array[$arrayp]}, $reg);
610                         }
611                 }
612         }
613
614         if ($has_limit == 1) {
615                 push(@obst_limit_func, "static const unsigned limit_reg_${op}_".($in ? "in" : "out")."_". ${idx} ."[] = { ");
616                 my $first = 1;
617                 my $limitbitsetlen = $regclass2len{$class};
618                 my $limitarraylen = $limitbitsetlen / 32 + ($limitbitsetlen % 32 > 0 ? 1 : 0);
619                 for(my $i = 0; $i < $limitarraylen; $i++) {
620                         my $limitarraypart = $limit_array[$i];
621                         if($first) {
622                                 $first = 0;
623                         } else {
624                                 push(@obst_limit_func, ", ");
625                         }
626                         my $temp;
627                         if($neg) {
628                                 $temp = "0xFFFFFFFF";
629                         }
630                         foreach my $reg (@{$limitarraypart}) {
631                                 if($neg) {
632                                         $temp .= " & ~";
633                                 } elsif(defined($temp)) {
634                                         $temp .= " | ";
635                                 }
636                                 $temp .= "BIT(REG_".uc(${reg}).")";
637                         }
638                         if(defined($temp)) {
639                                 push(@obst_limit_func, "${temp}");
640                         } else {
641                                 push(@obst_limit_func, "0");
642                         }
643                 }
644                 push(@obst_limit_func, " };\n");
645         }
646
647         return ($class, $has_limit, $same_pos, $different_pos);
648 }
649
650 ###
651 # Gets the variable name for the execution unit assigned to this register.
652 ###
653 sub get_execunit_variable_name {
654         my $unit    = shift;
655         my $name    = "NULL";
656         my $uc_arch = uc($arch);
657
658         if ($unit) {
659                 my $found = 0;
660 SRCH:   foreach my $cur_type (keys(%cpu)) {
661                         foreach my $cur_unit (@{ $cpu{"$cur_type"} }) {
662                                 if ($unit eq $cur_unit) {
663                                         my $tp_name   = "$arch\_execution_units_$cur_type";
664                                         my $unit_name = "$uc_arch\_EXECUNIT_TP_$cur_type\_$unit";
665                                         $name  = "&".$tp_name."[".$unit_name."]";
666                                         $found = 1;
667                                         last SRCH;
668                                 }
669                         }
670                 }
671
672                 if (! $found) {
673                         print STDERR "Invalid execution unit $unit specified!\n";
674                 }
675         }
676
677         return $name;
678 }