removed unused header
[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  * Generated register classes from spec.
230  *
231  * 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 _GEN_${tmp}_REGALLOC_IF_T_H_
237 #define _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 /* _GEN_$tmp\_REGALLOC_IF_T_H_ */\n";
246
247
248
249 # generate header (external usage) file
250 open(OUT, ">$target_h") || die("Could not open $target_h, reason: $!\n");
251
252 $creation_time = localtime(time());
253
254 print OUT<<EOF;
255 /**
256  * Contains additional external requirements defs for external includes.
257  *
258  * DO NOT EDIT THIS FILE, your changes will be lost.
259  * Edit $specfile instead.
260  * created by: $0 $specfile $target_dir
261  * date:       $creation_time
262  */
263 #ifndef _GEN_${tmp}_REGALLOC_IF_H_
264 #define _GEN_${tmp}_REGALLOC_IF_H_
265
266 #include "../bearch.h"
267 #include "${arch}_nodes_attr.h"
268
269 EOF
270
271 print OUT @obst_regdef, "\n";
272
273 print OUT @obst_classdef, "\n";
274
275 print OUT @obst_regtypes_decl, "\n";
276
277 print OUT "extern arch_register_class_t $arch\_reg_classes[N_CLASSES];\n\n";
278
279 print OUT "void ".$arch."_register_init(void *isa_ptr);\n\n";
280
281 print OUT @obst_header_all, "\n";
282
283 print OUT "\n#endif /* _GEN_$tmp\_REGALLOC_IF_H_ */\n";
284
285 close(OUT);
286
287
288
289 # generate c file
290 open(OUT, ">$target_c") || die("Could not open $target_c, reason: $!\n");
291
292 $creation_time = localtime(time());
293
294 print OUT<<EOF;
295 /**
296  * 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  *
300  * DO NOT EDIT THIS FILE, your changes will be lost.
301  * Edit $specfile instead.
302  * created by: $0 $specfile $target_dir
303  * date:       $creation_time
304  */
305 #ifdef HAVE_CONFIG_H
306 #include "config.h"
307 #endif
308
309 #include "gen_${arch}_regalloc_if.h"
310 #include "gen_${arch}_machine.h"
311 #include "bearch_${arch}_t.h"
312 #include "${arch}_map_regs.h"
313 #include "irmode.h"
314
315 #ifdef BIT
316 #undef BIT
317 #endif
318 #define BIT(x)  (1 << (x % 32))
319
320 EOF
321
322 print OUT "arch_register_class_t ${arch}_reg_classes[] = {\n\t".join(",\n\t", @obst_regclasses)."\n};\n\n";
323
324 print OUT @obst_regtypes_def, "\n";
325
326 print OUT "void ${arch}_register_init(void *isa_ptr) {\n";
327 print OUT @obst_reginit;
328 print OUT "}\n\n";
329
330 print OUT @obst_limit_func;
331
332 print OUT @obst_req;
333
334 close(OUT);
335
336 ###
337 # Remember the register class for each index in the given requirements.
338 # We need this information for requirements like "in_sX" or "out_dX"
339 # @return array of classes corresponding to the requirement for each index
340 ###
341 sub build_inout_idx_class {
342         my $n     = shift;
343         my $op    = shift;
344         my $inout = shift;
345         my @idx_class;
346
347         if (exists($n->{"reg_req"}{"$inout"})) {
348                 my @reqs = @{ $n->{"reg_req"}{"$inout"} };
349
350                 for (my $idx = 0; $idx <= $#reqs; $idx++) {
351                         my $class = undef;
352
353                         if ($reqs[$idx] eq "none") {
354                                 $class = "none";
355                         } elsif (is_reg_class($reqs[$idx])) {
356                                 $class = $reqs[$idx];
357                         } else {
358                                 my @regs = split(/ /, $reqs[$idx]);
359 GET_CLASS:              foreach my $reg (@regs) {
360                                         if ($reg =~ /!?(in|out)\_r\d+/ || $reg =~ /!in/) {
361                                                 $class = "UNKNOWN_CLASS";
362                                         }
363                                         else {
364                                                 $class = get_reg_class($reg);
365                                                 if (!defined $class) {
366                                                         die("Could not get ".uc($inout)." register class for '$op' pos $idx (reg $reg) ... exiting.\n");
367                                                 }
368                                                 else {
369                                                         last GET_CLASS;
370                                                 } # !defined class
371                                         } # if (reg =~ ...
372                                 } # foreach
373                         } # if
374
375                         push(@idx_class, $class);
376                 } # for
377         } # if
378
379         return @idx_class;
380 }
381
382 ###
383 # Generates the requirements for the given description
384 ###
385 sub generate_requirements {
386         my $n     = shift;
387         my $op    = shift;
388         my $inout = shift;
389
390         # get classes for the complementary direction
391         my $outin     = ($inout eq "in") ? "out" : "in";
392
393         my @reqs = @{ $n->{"reg_req"}{"$inout"} };
394
395         for (my $idx = 0; $idx <= $#reqs; $idx++) {
396                 my $class = undef;
397
398                 my $tmp2 = "const arch_register_req_t ${op}_reg_req_${inout}_${idx} = ";
399
400                 if ($reqs[$idx] eq "none") {
401                         $tmp2 .= "{\n";
402                         $tmp2 .= "\tarch_register_req_type_none,\n";
403                         $tmp2 .= "\tNULL,        /* regclass */\n";
404                         $tmp2 .= "\tNULL,        /* limit bitset */\n";
405                         $tmp2 .= "\t-1,          /* same pos */\n";
406                         $tmp2 .= "\t-1           /* different pos */\n";
407                         $tmp2 .= "};\n";
408
409                         push(@obst_req, $tmp2."\n");
410                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
411                 } elsif ($reqs[$idx] =~ /^new_reg_(.*)$/) {
412                         if (is_reg_class($1)) {
413                                 $tmp2 .= "{\n";
414                                 $tmp2 .= "\tarch_register_req_type_should_be_different_from_all,\n";
415                                 $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_$1],\n";
416                                 $tmp2 .= "\tNULL,        /* limit bitset */\n";
417                                 $tmp2 .= "\t-1,          /* same pos */\n";
418                                 $tmp2 .= "\t-1           /* different pos */\n";
419                                 $tmp2 .= "};\n";
420
421                                 push(@obst_req, $tmp2."\n");
422                                 push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
423                         } else {
424                                 print STDERR "Invalid register class '$1' given in OUT requirement $idx for '$op'.\n";
425                         }
426                 } elsif (is_reg_class($reqs[$idx])) {
427                         my $class = $reqs[$idx];
428                         $tmp2 .= "{\n";
429                         $tmp2 .= "\tarch_register_req_type_normal,\n";
430                         $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_${class}],\n";
431                         $tmp2 .= "\tNULL,        /* limit bitset */\n";
432                         $tmp2 .= "\t-1,          /* same pos */\n";
433                         $tmp2 .= "\t-1           /* different pos */\n";
434                         $tmp2 .= "};\n";
435
436                         push(@obst_req, $tmp2."\n");
437                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
438                 } else {
439                         my @req_type_mask;
440                         my ($class, $has_limit, $same_pos, $different_pos) = build_subset_class_func($n, $op, $idx, (($inout eq "in") ? 1 : 0), $reqs[$idx]);
441
442                         if (!defined($class)) {
443                                 die("Could not build subset for ".uc($inout)." requirements '$op' pos $idx ... exiting.\n");
444                         }
445
446                         if ($has_limit) {
447                                 push(@req_type_mask, "arch_register_req_type_limited");
448                         }
449                         if (defined($same_pos)) {
450                                 push(@req_type_mask, "arch_register_req_type_should_be_same");
451                         }
452                         if (defined($different_pos)) {
453                                 if ($different_pos == 666) {
454                                         push(@req_type_mask, "arch_register_req_type_should_be_different_from_all");
455                                         undef $different_pos;
456                                 } else {
457                                         push(@req_type_mask, "arch_register_req_type_should_be_different");
458                                 }
459                         }
460
461                         $tmp2 .= "{\n";
462                         $tmp2 .= "\t".join(" | ", @req_type_mask).",\n";
463                         $tmp2 .= "\t&${arch}_reg_classes[CLASS_${arch}_${class}],\n";
464                         $tmp2 .= "\t".($has_limit ? "limit_reg_${op}_${inout}_${idx}" : "NULL").",\n";
465                         $tmp2 .= "\t".(defined($same_pos) ? $same_pos : "-1").",\n";
466                         $tmp2 .= "\t".(defined($different_pos) ? $different_pos : "-1")."\n";
467                         $tmp2 .= "};\n";
468
469                         push(@obst_req, $tmp2."\n");
470                         push(@obst_header_t, "extern const arch_register_req_t ${op}_reg_req_${inout}_${idx};\n");
471                 }
472         }
473
474 }
475
476 ###
477 # Determines whether $name is a specified register class or not.
478 # @return 1 if name is register class, 0 otherwise
479 ###
480 sub is_reg_class {
481         my $name = shift;
482         return 1 if exists($reg_classes{"$name"});
483         return 0;
484 }
485
486 ###
487 # Returns the register class for a given register.
488 # @return class or undef
489 ###
490 sub get_reg_class {
491         my $reg = shift;
492         $reg = substr($reg, 1) if ($reg =~ /!.*/);
493         return $reg2class{"$reg"}{"class"} if (exists($reg2class{"$reg"}));
494         return undef;
495 }
496
497 ###
498 # Returns the index of a given register within it's register class.
499 # @return index or undef
500 ###
501 sub get_reg_index {
502         my $reg = shift;
503         return $reg2class{"$reg"}{"index"} if (exists($reg2class{"$reg"}));
504         return undef;
505 }
506
507 ###
508 # Generates the function for a given $op and a given IN-index
509 # which returns a subset of possible register from a register class
510 # @return classname from which the subset is derived or undef and
511 #         pos which corresponds to in/out reference position or undef
512 ###
513 sub build_subset_class_func {
514         my $neg           = undef;
515         my $class         = undef;
516         my $has_limit     = 0;
517         my $same_pos      = undef;
518         my $different_pos = undef;
519         my $temp;
520         my @obst_init;
521         my @obst_limits;
522         my @obst_ignore;
523         my @limit_array;
524
525         # build function header
526         my $n   = shift;
527         my $op  = shift;
528         my $idx = shift;
529         my $in  = shift;
530
531         my $outin = $in ? "out" : "in";
532         my @regs  = split(/ /, shift);
533
534         my @idx_class = build_inout_idx_class($n, $op, $outin);
535
536         # set/unset registers
537 CHECK_REQS: foreach (@regs) {
538                 if (/(!)?$outin\_r(\d+)/) {
539                         if (($1 && defined($different_pos)) || (!$1 && defined($same_pos))) {
540                                 print STDERR "Multiple in/out references of same type in one requirement not allowed.\n";
541                                 return (undef, undef, undef, undef);
542                         }
543
544                         if ($1) {
545                                 $different_pos = $in ? -$2 : $2 - 1;
546                         }
547                         else {
548                                 $same_pos = $in ? -$2 : $2 - 1;
549                         }
550
551                         $class = $idx_class[$2 - 1];
552                         next CHECK_REQS;
553                 }
554                 elsif (/!in/) {
555                         $class = $idx_class[0];
556                         return ($class, 0, undef, 666);
557                 }
558
559                 # check for negate
560                 if (substr($_, 0, 1) eq "!") {
561                         if (defined($neg) && $neg == 0) {
562                                 # we have seen a positiv constraint as first one but this one is negative
563                                 # this doesn't make sense
564                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
565                                 return (undef, undef, undef, undef);
566                         }
567
568                         if (!defined($neg)) {
569                                 $has_limit = 1;
570                         }
571
572                         $_   = substr($_, 1); # skip '!'
573                         $neg = 1;
574                 } else {
575                         if (defined($neg) && $neg == 1) {
576                                 # we have seen a negative constraint as first one but this one is positive
577                                 # this doesn't make sense
578                                 print STDERR "Mixed positive and negative constraints for the same slot are not allowed.\n";
579                                 return (undef, undef, undef, undef);
580                         }
581
582                         $has_limit = 1;
583                         $neg = 0;
584                 }
585
586                 # check if register belongs to one of the given classes
587                 $temp = get_reg_class($_);
588                 if (!defined($temp)) {
589                         print STDERR "Unknown register '$_'!\n";
590                         return (undef, undef, undef, undef);
591                 }
592
593                 # set class
594                 if (!defined($class)) {
595                         $class = $temp;
596                 } elsif ($class ne $temp) {
597                         # all registers must belong to the same class
598                         print STDERR "Registerclass mismatch. '$_' is not member of class '$class'.\n";
599                         return (undef, undef, undef, undef);
600                 }
601
602                 # calculate position inside the initializer bitfield (only 32 bits per
603                 # element)
604                 my $regidx = get_reg_index($_);
605                 my $arrayp = $regidx / 32;
606                 push(@{$limit_array[$arrayp]}, $_);
607         }
608
609         # don't allow ignore regs in negative constraints
610         if($neg) {
611                 my @cur_class = @{ $reg_classes{"$class"} };
612                 for (my $idx = 0; $idx <= $#cur_class; $idx++) {
613                         if (defined($cur_class[$idx]{"type"}) && ($cur_class[$idx]{"type"} & 4)) {
614                                 my $reg = $cur_class[$idx]{"name"};
615                                 my $regix = get_reg_index($reg);
616                                 my $arrayp = $regix / 32;
617                                 push(@{$limit_array[$arrayp]}, $reg);
618                         }
619                 }
620         }
621
622         if ($has_limit == 1) {
623                 push(@obst_limit_func, "static const unsigned limit_reg_${op}_".($in ? "in" : "out")."_". ${idx} ."[] = { ");
624                 my $first = 1;
625                 my $limitbitsetlen = $regclass2len{$class};
626                 my $limitarraylen = $limitbitsetlen / 32 + ($limitbitsetlen % 32 > 0 ? 1 : 0);
627                 for(my $i = 0; $i < $limitarraylen; $i++) {
628                         my $limitarraypart = $limit_array[$i];
629                         if($first) {
630                                 $first = 0;
631                         } else {
632                                 push(@obst_limit_func, ", ");
633                         }
634                         my $temp;
635                         if($neg) {
636                                 $temp = "0xFFFFFFFF";
637                         }
638                         foreach my $reg (@{$limitarraypart}) {
639                                 if($neg) {
640                                         $temp .= " & ~";
641                                 } elsif(defined($temp)) {
642                                         $temp .= " | ";
643                                 }
644                                 $temp .= "BIT(REG_".uc(${reg}).")";
645                         }
646                         if(defined($temp)) {
647                                 push(@obst_limit_func, "${temp}");
648                         } else {
649                                 push(@obst_limit_func, "0");
650                         }
651                 }
652                 push(@obst_limit_func, " };\n");
653         }
654
655         return ($class, $has_limit, $same_pos, $different_pos);
656 }
657
658 ###
659 # Gets the variable name for the execution unit assigned to this register.
660 ###
661 sub get_execunit_variable_name {
662         my $unit    = shift;
663         my $name    = "NULL";
664         my $uc_arch = uc($arch);
665
666         if ($unit) {
667                 my $found = 0;
668 SRCH:   foreach my $cur_type (keys(%cpu)) {
669                         foreach my $cur_unit (@{ $cpu{"$cur_type"} }) {
670                                 if ($unit eq $cur_unit) {
671                                         my $tp_name   = "$arch\_execution_units_$cur_type";
672                                         my $unit_name = "$uc_arch\_EXECUNIT_TP_$cur_type\_$unit";
673                                         $name  = "&".$tp_name."[".$unit_name."]";
674                                         $found = 1;
675                                         last SRCH;
676                                 }
677                         }
678                 }
679
680                 if (! $found) {
681                         print STDERR "Invalid execution unit $unit specified!\n";
682                 }
683         }
684
685         return $name;
686 }