From faa02da978fa451faabf0b4bac58e6d4607b31c4 Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Fri, 29 Dec 2006 19:08:14 +0000 Subject: [PATCH] add register classes --- ChangeLog | 8 +++++ jit/jit-reg-class.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ jit/jit-reg-class.h | 57 ++++++++++++++++++++++++++++++++ jit/jit-rules-x86.c | 29 ++++++++++++++-- 4 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 jit/jit-reg-class.c create mode 100644 jit/jit-reg-class.h diff --git a/ChangeLog b/ChangeLog index 9853442..9baa196 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-12-30 Aleksey Demakov + + * jit/jit-reg-class.c, jit/jit-reg-class.h, jit/Makefile.am: add + register classes. + + * jit/jit-rules-x86.c (_jit_init_backend): initialize x86 register + classes. + 2006-12-20 Aleksey Demakov * jit/jit-thread.h, jit/jit-thread.c: add _jit_global_lock mutex. diff --git a/jit/jit-reg-class.c b/jit/jit-reg-class.c new file mode 100644 index 0000000..fe42838 --- /dev/null +++ b/jit/jit-reg-class.c @@ -0,0 +1,80 @@ +/* + * jit-reg-class.c - Register class routines for the JIT. + * + * Copyright (C) 2006 Southern Storm Software, Pty Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "jit-internal.h" +#include "jit-reg-class.h" +#include + +_jit_regclass_t * +_jit_regclass_create(const char *name, int flags, int num_regs, ...) +{ + _jit_regclass_t *regclass; + va_list args; + int reg; + + regclass = jit_malloc(sizeof(_jit_regclass_t) + sizeof(int) * (num_regs - 1)); + if(!regclass) + { + return 0; + } + regclass->name = name; + regclass->flags = flags; + regclass->num_regs = num_regs; + + va_start(args, num_regs); + for(reg = 0; reg < num_regs; reg++) + { + regclass->regs[reg] = va_arg(args, int); + } + va_end(args); + + return regclass; +} + +_jit_regclass_t * +_jit_regclass_combine(const char *name, int flags, + _jit_regclass_t *class1, + _jit_regclass_t *class2) +{ + _jit_regclass_t *regclass; + int num_regs; + + num_regs = class1->num_regs + class2->num_regs; + + regclass = jit_malloc(sizeof(_jit_regclass_t) + sizeof(int) * (num_regs - 1)); + if(!regclass) + { + return 0; + } + regclass->name = name; + regclass->flags = flags; + regclass->num_regs = num_regs; + + jit_memcpy(regclass->regs, class1->regs, sizeof(int) * class1->num_regs); + jit_memcpy(regclass->regs + class1->num_regs, class2->regs, sizeof(int) * class2->num_regs); + + return regclass; +} + +void +_jit_regclass_free(_jit_regclass_t *regclass) +{ + jit_free(regclass); +} diff --git a/jit/jit-reg-class.h b/jit/jit-reg-class.h new file mode 100644 index 0000000..bbadd3a --- /dev/null +++ b/jit/jit-reg-class.h @@ -0,0 +1,57 @@ +/* + * jit-reg-class.h - Register class routines for the JIT. + * + * Copyright (C) 2006 Southern Storm Software, Pty Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _JIT_REG_CLASS_H +#define _JIT_REG_CLASS_H + +#include "jit-rules.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Information about a register class. + */ +typedef struct +{ + const char *name; /* Name of the register class, for debugging */ + int flags; /* Register flags */ + int num_regs; /* The number of registers in the class */ + int regs[1]; /* JIT_REG_INFO index for each register */ + +} _jit_regclass_t; + +/* Create a register class. */ +_jit_regclass_t *_jit_regclass_create(const char *name, int flags, int num_regs, ...); + +/* Combine two register classes into another one. */ +_jit_regclass_t *_jit_regclass_combine(const char *name, int flags, + _jit_regclass_t *class1, + _jit_regclass_t *class2); + +/* Free a register class. */ +void _jit_regclass_free(_jit_regclass_t *regclass); + +#ifdef __cplusplus +}; +#endif + +#endif /* _JIT_REG_CLASS_H */ diff --git a/jit/jit-rules-x86.c b/jit/jit-rules-x86.c index 39b669d..3c6e48b 100644 --- a/jit/jit-rules-x86.c +++ b/jit/jit-rules-x86.c @@ -44,7 +44,7 @@ #define X86_REG_ESP 7 #define X86_REG_ST0 8 #define X86_REG_ST1 9 -#define X85_REG_ST2 10 +#define X86_REG_ST2 10 #define X86_REG_ST3 11 #define X86_REG_ST4 12 #define X86_REG_ST5 13 @@ -63,9 +63,34 @@ #define ROUND_STACK(size) \ (((size) + (sizeof(void *) - 1)) & ~(sizeof(void *) - 1)) +static _jit_regclass_t *x86_reg; +static _jit_regclass_t *x86_breg; +static _jit_regclass_t *x86_freg; +static _jit_regclass_t *x86_lreg; + void _jit_init_backend(void) { - /* Nothing to do here for the x86 */ + x86_reg = _jit_regclass_create( + "reg", JIT_REG_WORD, 6, + X86_REG_EAX, X86_REG_ECX, + X86_REG_EDX, X86_REG_EBX, + X86_REG_ESI, X86_REG_EDI); + + x86_breg = _jit_regclass_create( + "breg", JIT_REG_WORD, 4, + X86_REG_EAX, X86_REG_ECX, + X86_REG_EDX, X86_REG_EBX); + + x86_freg = _jit_regclass_create( + "freg", JIT_REG_X86_FLOAT | JIT_REG_IN_STACK, 8, + X86_REG_ST0, X86_REG_ST1, + X86_REG_ST2, X86_REG_ST3, + X86_REG_ST4, X86_REG_ST5, + X86_REG_ST6, X86_REG_ST7); + + x86_lreg = _jit_regclass_create( + "lreg", JIT_REG_LONG, 2, + X86_REG_EAX, X86_REG_ECX); } void _jit_gen_get_elf_info(jit_elf_info_t *info) -- 2.47.3