diff options
-rw-r--r-- | gcc/config/bpf/bpf.cc | 21 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/bpf/constant-calls-1.c (renamed from gcc/testsuite/gcc.target/bpf/constant-calls.c) | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/bpf/constant-calls-2.c | 16 |
3 files changed, 36 insertions, 2 deletions
diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 6a0e3bb..7e37e08 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -659,12 +659,15 @@ bpf_address_base_p (rtx x, bool strict) target machine for a memory operand of mode MODE. */ static bool -bpf_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED, +bpf_legitimate_address_p (machine_mode mode, rtx x, bool strict) { switch (GET_CODE (x)) { + case CONST_INT: + return (mode == FUNCTION_MODE); + case REG: return bpf_address_base_p (x, strict); @@ -1311,6 +1314,22 @@ bpf_core_walk (tree *tp, int *walk_subtrees, void *data) return NULL_TREE; } +/* Implement target hook small_register_classes_for_mode_p. */ + +static bool +bpf_small_register_classes_for_mode_p (machine_mode mode) +{ + if (TARGET_XBPF) + return 1; + else + /* Avoid putting function addresses in registers, as calling these + is not supported in eBPF. */ + return (mode != FUNCTION_MODE); +} + +#undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P +#define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P \ + bpf_small_register_classes_for_mode_p /* Implement TARGET_RESOLVE_OVERLOADED_BUILTIN (see gccint manual section Target Macros::Misc.). diff --git a/gcc/testsuite/gcc.target/bpf/constant-calls.c b/gcc/testsuite/gcc.target/bpf/constant-calls-1.c index 84612a9..6effc7d 100644 --- a/gcc/testsuite/gcc.target/bpf/constant-calls.c +++ b/gcc/testsuite/gcc.target/bpf/constant-calls-1.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-xfail-if "" { bpf-*-* } } */ typedef void *(*T)(void); f1 () diff --git a/gcc/testsuite/gcc.target/bpf/constant-calls-2.c b/gcc/testsuite/gcc.target/bpf/constant-calls-2.c new file mode 100644 index 0000000..836ab67 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/constant-calls-2.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c89 -O2" } */ + +static void * (*bpf_map_lookup_elem)(void *map, const void *key) = (void *) 666; + +int foo () +{ + char *ret; + + ret = bpf_map_lookup_elem (ret, ret); + if (ret) + return 0; + return 1; +} + +/* { dg-final { scan-assembler "call\t666" } } */ |