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