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