my $target_h_t = $target_dir."/gen_".$arch."_regalloc_if_t.h";
# helper function
-my @rt = ("arch_register_type_none",
- "arch_register_type_write_invariant",
- "arch_register_type_caller_saved",
- "arch_register_type_callee_saved",
- "arch_register_type_ignore");
+sub translate_reg_type {
+ my $t = shift;
+
+ if ($t == 0) {
+ return "arch_register_type_none";
+ }
+ else {
+ my @types;
+
+ if ($t & 1) {
+ push(@types, "arch_register_type_caller_save");
+ }
+
+ if ($t & 2) {
+ push(@types, "arch_register_type_callee_save");
+ }
+
+ if ($t & 4) {
+ push(@types, "arch_register_type_ignore");
+ }
+
+ return join(" | ", @types);
+ }
+}
# stacks for output
my @obst_regtypes; # stack for the register type variables
my @obst_limit_func; # stack for functions to return a subset of a register class
my @obst_defreq_head; # stack for prototypes of default requirement function
my @obst_header_all; # stack for some extern struct defs needed for bearch_$arch include
+my @obst_requirement_def; # stack for requirement name defines
my $numregs;
my $class_ptr;
$tmp = "/* Default NONE register requirements */\n";
$tmp .= "const $arch\_register_req_t $arch\_default_req_none = {\n";
$tmp .= " {\n";
-$tmp .= " arch_register_req_type_none,\n";
-$tmp .= " NULL,\n";
-$tmp .= " NULL,\n";
-$tmp .= " 0\n";
+$tmp .= " arch_register_req_type_none, /* register type */\n";
+$tmp .= " NULL, /* register class */\n";
+$tmp .= " NULL, /* limit function */\n";
+$tmp .= " NULL, /* limit environment */\n";
+$tmp .= " NULL, /* node for same */\n";
+$tmp .= " NULL /* node for different */\n";
$tmp .= " },\n";
-$tmp .= " 0\n";
+$tmp .= " 0, /* same pos */\n";
+$tmp .= " 0 /* different pos */\n";
$tmp .= "};\n\n";
push(@obst_req, $tmp);
-
-push(@obst_header_all, "extern arch_register_class_t $arch\_reg_classes[N_CLASSES];\n\n");
push(@obst_header_all, "extern const $arch\_register_req_t $arch\_default_req_none;\n");
push(@obst_classdef, "#define N_CLASSES ".scalar(keys(%reg_classes))."\n");
+my $class_mode;
+
# generate register type and class variable, init function and default requirements
foreach my $class_name (keys(%reg_classes)) {
my @class = @{ $reg_classes{"$class_name"} };
$class_name = $arch."_".$class_name;
$numregs = "N_".$class_name."_REGS";
$class_ptr = "&".$arch."_reg_classes[CLASS_".$class_name."]";
+ $class_mode = pop(@class)->{"mode"};
push(@obst_regtypes, "#define $numregs ".($#class + 1)."\n");
push(@obst_regtypes, "arch_register_t ".$class_name."_regs[$numregs];\n\n");
push(@obst_classdef, "#define CLASS_$class_name $class_idx\n");
- push(@obst_regclasses, "{ \"$class_name\", $numregs, ".$class_name."_regs }");
+ push(@obst_regclasses, "{ \"$class_name\", $numregs, NULL, ".$class_name."_regs }");
# there is a default NORMAL requirement for each class
$tmp = "/* Default NORMAL register requirements for class $class_name */\n";
$tmp .= " {\n";
$tmp .= " arch_register_req_type_normal,\n";
$tmp .= " $class_ptr,\n";
- $tmp .= " NULL,\n";
- $tmp .= " 0\n";
+ $tmp .= " NULL, /* limit function */ \n";
+ $tmp .= " NULL, /* limit environment */\n";
+ $tmp .= " NULL, /* node for same */\n";
+ $tmp .= " NULL /* node for different */\n";
$tmp .= " },\n";
- $tmp .= " 0\n";
+ $tmp .= " 0, /* same pos */\n";
+ $tmp .= " 0 /* different pos */\n";
$tmp .= "};\n\n";
push(@obst_req, $tmp);
-
- push(@obst_header_all, "\nextern const arch_register_req_t ia32_default_req_$class_name;\n");
+ push(@obst_header_all, "extern const $arch\_register_req_t $arch\_default_req_$class_name;\n");
my $idx = 0;
push(@obst_reginit, " /* Init of all registers in class '$class_name' */\n\n");
+ push(@obst_reginit, " /* set largest possible mode for '$class_name' */\n");
+ push(@obst_reginit, " $arch\_reg_classes[CLASS_".$class_name."].mode = $class_mode;\n\n");
foreach (@class) {
# For each class we build for each of it's member registers a limit function
# which limits the class to this particular register. We also build the
my $limit_func_name = $arch."_limit_".$class_name."_".$_->{"name"};
# push the function prototype
- $tmp = "int $limit_func_name(const ir_node *irn, int pos, bitset_t *bs)";
+ $tmp = "void $limit_func_name(void *_unused, bitset_t *bs)";
push(@obst_defreq_head, $tmp.";\n");
# push the function definition
$tmp .= " {\n";
$tmp .= " bs = bitset_clear_all(bs);\n";
$tmp .= " bitset_set(bs, REG_".uc($_->{"name"}).");\n"; # REGISTER to index assignment is done some lines down
- $tmp .= " return 1;\n";
$tmp .= "}\n\n";
push(@obst_limit_func, $tmp);
$tmp .= " arch_register_req_type_limited,\n";
$tmp .= " $class_ptr,\n";
$tmp .= " $limit_func_name,\n";
- $tmp .= " 0\n";
+ $tmp .= " NULL, /* limit environment */\n";
+ $tmp .= " NULL, /* node for same */\n";
+ $tmp .= " NULL /* node for different */\n";
$tmp .= " },\n";
- $tmp .= " 0\n";
+ $tmp .= " 0, /* same pos */\n";
+ $tmp .= " 0 /* different pos */\n";
$tmp .= "};\n\n";
push(@obst_req, $tmp);
-
- push(@obst_header_all, "extern const $arch\_register_req_t $arch\_default_req_$class_name\_".$_->{"name"}.";\n");
+ push(@obst_header_all,"extern const $arch\_register_req_t $arch\_default_req_$class_name\_".$_->{"name"}.";\n");
$reg2class{$_->{"name"}} = { "class" => $old_classname, "index" => $idx }; # remember reg to class for later use
push(@obst_regdef, "#define REG_".uc($_->{"name"})." $idx\n");
push(@obst_reginit, " ".$class_name."_regs[$idx].name = \"".$_->{"name"}."\";\n");
push(@obst_reginit, " ".$class_name."_regs[$idx].reg_class = $class_ptr;\n");
push(@obst_reginit, " ".$class_name."_regs[$idx].index = $idx;\n");
- push(@obst_reginit, " ".$class_name."_regs[$idx].type = ".$rt[$_->{"type"}].";\n\n");
+ push(@obst_reginit, " ".$class_name."_regs[$idx].type = ".translate_reg_type($_->{"type"}).";\n");
+ push(@obst_reginit, "\n");
$idx++;
}
$class_idx++;
}
-push(@obst_header_all, "\n/* node specific requirements */\n");
-
# generate node-register constraints
foreach my $op (keys(%nodes)) {
my %n = %{ $nodes{"$op"} };
* date: $creation_time
*/
-#include "../bearch.h"
-
EOF
-print OUT @obst_regdef, "\n";
-
-print OUT @obst_classdef, "\n";
-
-print OUT @obst_regtypes, "\n";
-
-print OUT @obst_defreq_head, "\n";
-
-print OUT "void ".$arch."_register_init(void);\n\n";
+print OUT @obst_requirement_def;
print OUT "\n#endif /* _GEN_$tmp\_REGALLOC_IF_T_H_ */\n";
* date: $creation_time
*/
-#include "gen_$arch\_regalloc_if_t.h"
+#include "../bearch.h"
+#include "$arch\_nodes_attr.h"
EOF
-print OUT @obst_header_all;
+print OUT @obst_regdef, "\n";
+
+print OUT @obst_classdef, "\n";
+
+print OUT @obst_regtypes, "\n";
+
+print OUT "extern arch_register_class_t $arch\_reg_classes[N_CLASSES];\n\n";
+
+print OUT "void ".$arch."_register_init(void *isa_ptr);\n\n";
+
+print OUT @obst_header_all, "\n";
+
+print OUT @obst_defreq_head, "\n";
print OUT "\n#endif /* _GEN_$tmp\_REGALLOC_IF_H_ */\n";
* date: $creation_time
*/
-#include "gen_$arch\_regalloc_if_t.h"
+#include "gen_$arch\_regalloc_if.h"
+#include "bearch_$arch\_t.h" /* we need this to put the caller saved registers into the isa set */
+#include "$arch\_map_regs.h"
+#include "irmode.h"
EOF
print OUT "arch_register_class_t $arch\_reg_classes[] = {\n ".join(",\n ", @obst_regclasses)."\n};\n\n";
-print OUT "void ".$arch."_register_init(void) {\n";
+print OUT "void ".$arch."_register_init(void *isa_ptr) {\n";
print OUT @obst_reginit;
print OUT "}\n\n";
print OUT @obst_limit_func;
+
print OUT @obst_req;
close(OUT);
my $class = undef;
my $tmp2 = "const $arch\_register_req_t _".$op."_reg_req_$inout\_$idx = ";
- my $tmp = "const $arch\_register_req_t *".$op."_reg_req_$inout\_$idx = ";
-
- push(@obst_header_all, "extern const $arch\_register_req_t *".$op."_reg_req_$inout\_$idx;\n");
+ my $tmp = "#define ".$op."_reg_req_$inout\_$idx ";
if ($reqs[$idx] eq "none") {
- $tmp .= "&$arch\_default_req_none;\n";
+ $tmp .= "&$arch\_default_req_none\n";
+ }
+ elsif ($reqs[$idx] =~ /^new_reg_(.*)$/) {
+ if (is_reg_class($1)) {
+ $tmp .= "&_".$op."_reg_req_$inout\_$idx\n";
+ $tmp2 .= "{\n";
+ $tmp2 .= " {\n";
+ $tmp2 .= " arch_register_req_type_should_be_different_from_all,\n";
+ $tmp2 .= " &$arch\_reg_classes[CLASS_$arch\_".$1."],\n";
+ $tmp2 .= " NULL, /* limit function */\n";
+ $tmp2 .= " NULL, /* limit environment */\n";
+ $tmp2 .= " NULL, /* same node */\n";
+ $tmp2 .= " NULL /* different node */\n";
+ $tmp2 .= " },\n";
+ $tmp2 .= " 0,\n";
+ $tmp2 .= " 0\n";
+ $tmp2 .= "};\n";
+
+ push(@obst_req, $tmp2."\n");
+ push(@obst_header_all, "extern const $arch\_register_req_t _".$op."_reg_req_$inout\_$idx;\n");
+ }
+ else {
+ print STDERR "Invalid register class '$1' given in OUT requirement $idx for '$op'.\n";
+ }
}
elsif (is_reg_class($reqs[$idx])) {
- $tmp .= "&$arch\_default_req_".$arch."_".$reqs[$idx].";\n";
+ $tmp .= "&$arch\_default_req_".$arch."_".$reqs[$idx]."\n";
}
else {
my @req_type_mask;
- my ($class, $has_limit, $pos, $same) = build_subset_class_func($n, $op, $idx, (($inout eq "in") ? 1 : 0), $reqs[$idx]);
+ my ($class, $has_limit, $same_pos, $different_pos) = build_subset_class_func($n, $op, $idx, (($inout eq "in") ? 1 : 0), $reqs[$idx]);
+
if (!defined($class)) {
die("Could not build subset for ".uc($inout)." requirements '$op' pos $idx ... exiting.\n");
}
+
if ($has_limit) {
push(@req_type_mask, "arch_register_req_type_limited");
}
- if (defined($pos)) {
- push(@req_type_mask, "arch_register_req_type_should_be_".($same ? "same" : "different"));
+ if (defined($same_pos)) {
+ push(@req_type_mask, "arch_register_req_type_should_be_same");
}
- $tmp .= "&_".$op."_reg_req_$inout\_$idx;\n";
- $tmp2 .= " {\n";
+ if (defined($different_pos)) {
+ push(@req_type_mask, "arch_register_req_type_should_be_different");
+ }
+
+ $tmp .= "&_".$op."_reg_req_$inout\_$idx\n";
+ $tmp2 .= "{\n";
$tmp2 .= " {\n";
$tmp2 .= " ".join(" | ", @req_type_mask).",\n";
$tmp2 .= " &$arch\_reg_classes[CLASS_$arch\_".$class."],\n";
- $tmp2 .= " ".(defined($class) ? "limit_reg_".$op."_$inout\_".$idx : "NULL").",\n";
- $tmp2 .= " NULL\n";
+ $tmp2 .= " ".($has_limit ? "limit_reg_".$op."_$inout\_".$idx : "NULL").",\n";
+ $tmp2 .= " NULL, /* limit environment */\n";
+ $tmp2 .= " NULL, /* same node */\n";
+ $tmp2 .= " NULL /* different node */\n";
$tmp2 .= " },\n";
- $tmp2 .= " ".(defined($pos) ? $pos : "0")."\n};\n";
+ $tmp2 .= " ".(defined($same_pos) ? $same_pos : "0").",\n";
+ $tmp2 .= " ".(defined($different_pos) ? $different_pos : "0")."\n";
+ $tmp2 .= "};\n";
- $tmp = $tmp2.$tmp;
+ push(@obst_req, $tmp2."\n");
+ push(@obst_header_all, "extern const $arch\_register_req_t _".$op."_reg_req_$inout\_$idx;\n");
}
- push(@obst_req, $tmp."\n");
+ push(@obst_requirement_def, $tmp);
}
}
###
sub get_reg_class {
my $reg = shift;
+ $reg = substr($reg, 1) if ($reg =~ /!.*/);
return $reg2class{"$reg"}{"class"} if (exists($reg2class{"$reg"}));
return undef;
}
# pos which corresponds to in/out reference position or undef
###
sub build_subset_class_func {
- my $neg = undef;
- my $class = undef;
+ my $neg = undef;
+ my $class = undef;
+ my $has_limit = 0;
+ my $same_pos = undef;
+ my $different_pos = undef;
my $temp;
- my $has_limit = 0;
+ my @temp_obst;
- # build function header
- my $n = shift;
- my $op = shift;
- my $idx = shift;
- my $in = shift;
- my $pos = undef;
- my $same = 1;
- my @temp_obst;
+ # build function header
+ my $n = shift;
+ my $op = shift;
+ my $idx = shift;
+ my $in = shift;
my $outin = $in ? "out" : "in";
my @regs = split(/ /, shift);
# set/unset registers
CHECK_REQS: foreach (@regs) {
if (/(!)?$outin\_r(\d+)/) {
- if (defined($pos)) {
- print STDERR "Multiple in/out references in one requirement not allowed.\n";
+ if (($1 && defined($different_pos)) || (!$1 && defined($same_pos))) {
+ print STDERR "Multiple in/out references of same type in one requirement not allowed.\n";
return (undef, undef, undef, undef);
}
- $same = 0 if ($1);
+
+ if ($1) {
+ $different_pos = $in ? -$2 : $2 - 1;
+ }
+ else {
+ $same_pos = $in ? -$2 : $2 - 1;
+ }
+
$class = $idx_class[$2 - 1];
- $pos = $in ? -$2 : $2 - 1;
next CHECK_REQS;
}
}
if ($has_limit == 1) {
+ push(@obst_header_all, "void limit_reg_".$op."_".($in ? "in" : "out")."_".$idx."(void *_unused, bitset_t *bs);\n");
+
push(@obst_limit_func, "/* limit the possible registers for ".($in ? "IN" : "OUT")." $idx at op $op */\n");
- push(@obst_limit_func, "int limit_reg_".$op."_".($in ? "in" : "out")."_".$idx."(const ir_node *irn, int pos, bitset_t *bs) {\n");
+ push(@obst_limit_func, "void limit_reg_".$op."_".($in ? "in" : "out")."_".$idx."(void *_unused, bitset_t *bs) {\n");
push(@obst_limit_func, @temp_obst);
- push(@obst_limit_func, "\n return ".($neg ? scalar(@{ $reg_classes{"$class"} }) - scalar(@regs) : scalar(@regs)).";\n");
push(@obst_limit_func, "}\n\n");
}
- return ($class, $has_limit, $pos, $same);
+ return ($class, $has_limit, $same_pos, $different_pos);
}