+
+/* Mapping to store proj numbers for registers */
+
+struct ia32_reg_projnum_assoc {
+ const arch_register_t *reg;
+ long proj_num;
+};
+
+int ia32_cmp_reg_projnum_assoc(const void *a, const void *b, size_t len) {
+ const struct ia32_reg_projnum_assoc *x = a;
+ const struct ia32_reg_projnum_assoc *y = b;
+
+ return !(x->reg == y->reg);
+}
+
+static struct ia32_reg_projnum_assoc *get_reg_projnum_assoc(const arch_register_t *reg, set *reg_set) {
+ struct ia32_reg_projnum_assoc templ;
+ unsigned int hash;
+
+ templ.reg = reg;
+ templ.proj_num = -1;
+ hash = HASH_PTR(reg);
+
+ return set_insert(reg_set, &templ, sizeof(templ), hash);
+}
+
+void ia32_set_reg_projnum(const arch_register_t *reg, long proj_num, set *reg_set) {
+ struct ia32_reg_projnum_assoc *assoc = get_reg_projnum_assoc(reg, reg_set);
+ assoc->proj_num = proj_num;
+}
+
+long ia32_get_reg_projnum(const arch_register_t *reg, set *reg_set) {
+ struct ia32_reg_projnum_assoc *assoc = get_reg_projnum_assoc(reg, reg_set);
+ return assoc->proj_num;
+}
+
+
+
+/**
+ * Check all parameters and determine the maximum number of parameters
+ * to pass in gp regs resp. in fp regs.
+ *
+ * @param n The number of parameters
+ * @param modes The list of the parameter modes
+ * @param n_int Holds the number of int parameters to be passed in regs after the call
+ * @param n_float Holds the number of float parameters to be passed in regs after the call
+ * @return The number of the last parameter to be passed in register
+ */
+int ia32_get_n_regparam_class(int n, ir_mode **modes, int *n_int, int *n_float) {
+ int i, finished = 0;
+
+ for (i = 0; i < n && !finished; i++) {
+ if (mode_is_int(modes[i])) {
+ *n_int = *n_int + 1;
+ }
+ else if (mode_is_float(modes[i])) {
+ *n_float = *n_float + 1;
+ }
+ else {
+ finished = 1;
+ }
+
+ /* test for maximum */
+ if (*n_int == maxnum_gpreg_args || *n_float == maxnum_fpreg_args) {
+ finished = 1;
+ }
+ }
+
+ return i - 1;
+}
+
+
+/**
+ * Returns the register for parameter nr.
+ *
+ * @param n The number of parameters
+ * @param modes The list of the parameter modes
+ * @param nr The number of the parameter to return the requirements for
+ * @param cc The calling convention
+ * @return The register
+ */
+const arch_register_t *ia32_get_RegParam_reg(int n, ir_mode **modes, long nr, unsigned cc) {
+ const arch_register_t **current_gpreg_param_reg;
+ const arch_register_t **current_fpreg_param_reg;
+ const arch_register_t *param_reg = NULL;
+ int n_gpregparam = 0;
+ int n_fpregparam = 0;
+ int i, done = 0;
+ int cur_gp_idx = 0;
+ int cur_fp_idx = 0;
+ int biggest_n = ia32_get_n_regparam_class(n, modes, &n_gpregparam, &n_fpregparam);
+
+ /* Check if parameter #nr is in range for passing in register */
+ if (nr <= biggest_n) {
+ current_gpreg_param_reg = gpreg_param_reg_std;
+ current_fpreg_param_reg = fpreg_param_reg_std;
+
+ if (cc & cc_this_call) {
+ current_gpreg_param_reg = gpreg_param_reg_this;
+ current_fpreg_param_reg = fpreg_param_reg_this;
+ }
+
+ /* loop over all parameters and determine whether its a int or float register parameter */
+ for (i = 0; i < nr && !done && (cc & cc_reg_param); i++) {
+ if (mode_is_int(modes[i]) && cur_gp_idx < maxnum_gpreg_args) {
+ /* param can be passed in general purpose register and we have some registers left */
+ cur_gp_idx++;
+ }
+ else if (mode_is_float(modes[i]) && cur_fp_idx < maxnum_fpreg_args) {
+ /* param can be passed in floating point register and we have some registers left */
+ assert(current_gpreg_param_reg[cur_fp_idx] && "'this' pointer cannot be passed as float");
+ cur_fp_idx++;
+ }
+ }
+
+ /* now: i == nr, that's the parameter requirement we want */
+ if (mode_is_int(modes[i]) && cur_gp_idx < maxnum_gpreg_args) {
+ /* parameter #nr can be passed in general purpose register */
+ param_reg = current_gpreg_param_reg[i];
+ }
+ else if (mode_is_float(modes[i]) && cur_fp_idx < maxnum_fpreg_args) {
+ /* parameter #nr can be passed in floating point register */
+ param_reg = current_fpreg_param_reg[i];
+ }
+ else {
+ assert(0 && "This should not happen!");
+ }
+ }
+
+ return param_reg;
+}
+
+
+