Commit a861ef58 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

be: Simplify initialisation and evaluation of asm constraints.

parent c893b2e8
...@@ -57,7 +57,7 @@ struct be_main_env_t { ...@@ -57,7 +57,7 @@ struct be_main_env_t {
ir_type *pic_symbols_type; ir_type *pic_symbols_type;
}; };
extern asm_constraint_flags_t asm_constraint_flags[256]; void be_set_constraint_support(asm_constraint_flags_t flags, char const *constraints);
void be_get_allocatable_regs(ir_graph const *irg, arch_register_class_t const *cls, unsigned *raw_bitset); void be_get_allocatable_regs(ir_graph const *irg, arch_register_class_t const *cls, unsigned *raw_bitset);
......
...@@ -107,22 +107,27 @@ static const lc_opt_table_entry_t be_main_options[] = { ...@@ -107,22 +107,27 @@ static const lc_opt_table_entry_t be_main_options[] = {
static be_module_list_entry_t *isa_ifs = NULL; static be_module_list_entry_t *isa_ifs = NULL;
static bool isa_initialized = false; static bool isa_initialized = false;
asm_constraint_flags_t asm_constraint_flags[256]; static asm_constraint_flags_t asm_constraint_flags[256];
void be_set_constraint_support(asm_constraint_flags_t const flags, char const *const constraints)
{
for (char const *i = constraints; *i != '\0'; ++i) {
asm_constraint_flags[(unsigned char)*i] = flags;
}
}
static void be_init_default_asm_constraint_flags(void) static void be_init_default_asm_constraint_flags(void)
{ {
/* list of constraints supported by gcc for any machine (or at least for (size_t i = 0; i != ARRAY_SIZE(asm_constraint_flags); ++i) {
asm_constraint_flags[i] = ASM_CONSTRAINT_FLAG_INVALID;
}
/* List of constraints supported by gcc for any machine (or at least
* recognized). Mark them as NO_SUPPORT so we can differentiate them * recognized). Mark them as NO_SUPPORT so we can differentiate them
* from INVALID. Backends should change the flags they support. */ * from INVALID. Backends should change the flags they support. */
static const unsigned char gcc_common_flags[] = { char const *const gcc_common_flags = "!%&0123456789<>?EFGHIJKLMNOPVXgimoprs";
'?', '!', '&', '%', 'i', 's', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', be_set_constraint_support(ASM_CONSTRAINT_FLAG_NO_SUPPORT, gcc_common_flags);
'M', 'N', 'O', 'P', 'm', 'o', 'r', 'V', '<', '>', 'p', 'g', 'X', /* Skip whitespace. */
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', be_set_constraint_support(ASM_CONSTRAINT_FLAG_NONE, "\t\n\r ");
};
for (size_t i = 0; i < ARRAY_SIZE(gcc_common_flags); ++i) {
unsigned char const c = gcc_common_flags[i];
asm_constraint_flags[c] = ASM_CONSTRAINT_FLAG_NO_SUPPORT;
}
} }
static void initialize_isa(void) static void initialize_isa(void)
...@@ -149,11 +154,6 @@ asm_constraint_flags_t be_parse_asm_constraints(const char *constraint) ...@@ -149,11 +154,6 @@ asm_constraint_flags_t be_parse_asm_constraints(const char *constraint)
asm_constraint_flags_t flags = ASM_CONSTRAINT_FLAG_NONE; asm_constraint_flags_t flags = ASM_CONSTRAINT_FLAG_NONE;
for (const char *c = constraint; *c != '\0'; ++c) { for (const char *c = constraint; *c != '\0'; ++c) {
switch (*c) { switch (*c) {
case ' ':
case '\t':
case '\n':
case '\r':
break;
case '=': case '=':
flags |= ASM_CONSTRAINT_FLAG_MODIFIER_WRITE; flags |= ASM_CONSTRAINT_FLAG_MODIFIER_WRITE;
flags |= ASM_CONSTRAINT_FLAG_MODIFIER_NO_READ; flags |= ASM_CONSTRAINT_FLAG_MODIFIER_NO_READ;
...@@ -162,11 +162,6 @@ asm_constraint_flags_t be_parse_asm_constraints(const char *constraint) ...@@ -162,11 +162,6 @@ asm_constraint_flags_t be_parse_asm_constraints(const char *constraint)
flags |= ASM_CONSTRAINT_FLAG_MODIFIER_READ; flags |= ASM_CONSTRAINT_FLAG_MODIFIER_READ;
flags |= ASM_CONSTRAINT_FLAG_MODIFIER_WRITE; flags |= ASM_CONSTRAINT_FLAG_MODIFIER_WRITE;
break; break;
case '&':
case '%':
/* not really supported by libFirm yet */
flags |= ASM_CONSTRAINT_FLAG_NO_SUPPORT;
break;
case '#': case '#':
/* text until comma is a comment */ /* text until comma is a comment */
while (*c != 0 && *c != ',') while (*c != 0 && *c != ',')
...@@ -176,16 +171,11 @@ asm_constraint_flags_t be_parse_asm_constraints(const char *constraint) ...@@ -176,16 +171,11 @@ asm_constraint_flags_t be_parse_asm_constraints(const char *constraint)
/* next character is a comment */ /* next character is a comment */
++c; ++c;
break; break;
default: {
asm_constraint_flags_t tflags = asm_constraint_flags[(int) *c]; default:
if (tflags != 0) { flags |= asm_constraint_flags[(unsigned char)*c];
flags |= tflags;
} else {
flags |= ASM_CONSTRAINT_FLAG_INVALID;
}
break; break;
} }
}
} }
if (( if ((
......
...@@ -1268,28 +1268,14 @@ extern const arch_isa_if_t ia32_isa_if; ...@@ -1268,28 +1268,14 @@ extern const arch_isa_if_t ia32_isa_if;
static void init_asm_constraints(void) static void init_asm_constraints(void)
{ {
static const unsigned char register_flags[] = { be_set_constraint_support(ASM_CONSTRAINT_FLAG_SUPPORTS_REGISTER, "0123456789ADQRSXYabcdflpqrtu");
'a', 'b', 'c', 'd', 'D', 'S', 'Q', 'q', 'A', 'l', 'R', 'r', 'p', 'f', be_set_constraint_support(ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE, "IJKLMNOin");
't', 'u', 'Y', 'X', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' be_set_constraint_support(ASM_CONSTRAINT_FLAG_SUPPORTS_MEMOP, "Vmo");
}; asm_constraint_flags_t const g =
for (size_t i = 0; i < ARRAY_SIZE(register_flags); ++i) { ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE |
unsigned char const c = register_flags[i]; ASM_CONSTRAINT_FLAG_SUPPORTS_MEMOP |
asm_constraint_flags[c] = ASM_CONSTRAINT_FLAG_SUPPORTS_REGISTER; ASM_CONSTRAINT_FLAG_SUPPORTS_REGISTER;
} be_set_constraint_support(g, "g");
static const unsigned char immediate_flags[] = {
'i', 'n', 'I', 'J', 'K', 'L', 'M', 'N', 'O'
};
for (size_t i = 0; i < ARRAY_SIZE(immediate_flags); ++i) {
unsigned char const c = immediate_flags[i];
asm_constraint_flags[c] = ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE;
}
asm_constraint_flags['g'] = ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE
| ASM_CONSTRAINT_FLAG_SUPPORTS_REGISTER
| ASM_CONSTRAINT_FLAG_SUPPORTS_MEMOP;
asm_constraint_flags['m'] = ASM_CONSTRAINT_FLAG_SUPPORTS_MEMOP;
asm_constraint_flags['o'] = ASM_CONSTRAINT_FLAG_SUPPORTS_MEMOP;
asm_constraint_flags['V'] = ASM_CONSTRAINT_FLAG_SUPPORTS_MEMOP;
} }
/** /**
......
...@@ -377,17 +377,8 @@ static arch_register_req_t const *make_register_req(ir_graph *const irg, ...@@ -377,17 +377,8 @@ static arch_register_req_t const *make_register_req(ir_graph *const irg,
void sparc_init_asm_constraints(void) void sparc_init_asm_constraints(void)
{ {
static unsigned char const register_flags[] = { be_set_constraint_support(ASM_CONSTRAINT_FLAG_SUPPORTS_REGISTER, "0123456789efr");
'r', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' be_set_constraint_support(ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE, "AI");
};
for (size_t i = 0; i < ARRAY_SIZE(register_flags); ++i) {
unsigned char const c = register_flags[i];
asm_constraint_flags[c] = ASM_CONSTRAINT_FLAG_SUPPORTS_REGISTER;
}
asm_constraint_flags['A'] = ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE;
asm_constraint_flags['I'] = ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE;
/* Note there are many more flags in gcc which we can't properly support /* Note there are many more flags in gcc which we can't properly support
* at the moment. see gcc/config/sparc/constraints.md */ * at the moment. see gcc/config/sparc/constraints.md */
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment