diff options
author | Alexandre Oliva <oliva@adacore.com> | 2020-12-02 22:10:32 -0300 |
---|---|---|
committer | Alexandre Oliva <oliva@gnu.org> | 2020-12-02 22:10:32 -0300 |
commit | c05ece92c6153289fd6055e31e791e59b8ac4121 (patch) | |
tree | d8447e11d060d4674ffc88230224b747084f654f /gcc/builtins.c | |
parent | 93d883c7734d92c021c624d82885d3a46532cf0b (diff) | |
download | gcc-c05ece92c6153289fd6055e31e791e59b8ac4121.zip gcc-c05ece92c6153289fd6055e31e791e59b8ac4121.tar.gz gcc-c05ece92c6153289fd6055e31e791e59b8ac4121.tar.bz2 |
introduce overridable clear_cache emitter
This patch introduces maybe_emit_call_builtin___clear_cache for the
builtin expander machinery and the trampoline initializers to use to
clear the instruction cache, removing a source of inconsistencies and
subtle errors in low-level machinery.
I've adjusted all trampoline_init implementations that used to issue
explicit calls to __clear_cache or similar to use this new primitive.
Specifically on vxworks targets, we needed to drop the __clear_cache
symbol in libgcc, for reasons related with linking that I didn't need
to understand, and we wanted to call cacheTextUpdate directly, despite
the different calling conventions: the second argument is a length
rather than the end address.
So I introduced a target hook to enable target OS-level overriding of
builtin __clear_cache call emission, retaining nearly (*) the same
logic to govern the decision on whether to emit a call (or nothing, or
a machine-dependent insn) but enabling a call to a target
system-defined function with different calling conventions to be
issued, without having to modify .md files of the various
architectures supported by the target system to introduce or modify
clear_cache insns.
(*) I write "nearly" mainly because, when not optimizing, we'd issue a
call regardless, but since the call may now be overridden, I added it
to the set of builtins that are not directly turned into calls when
not optimizing, following the normal expansion path instead. It
wouldn't be hard to skip the emission of cache-clearing insns when not
optimizing, but it didn't seem very important, especially for the new
uses from trampoline init.
Another difference that might be relevant is that now we expand
the begin and end arguments unconditionally. This might make a
difference if they have side effects. That's prettty much impossible
at expand time, but I thought I'd mention it.
I have NOT modified targets that did not issue cache-clearing calls in
trampoline init to use the new clear_cache-calling infrastructure even
if it would expand to nothing. I have considered doing so, to have
__builtin___clear_cache and trampoline init call cacheTextUpdate on
all vxworks targets, but decided not to, since on targets that don't
do any cache clearing, cacheTextUpdate ought to be a no-op, even
though rs6000 seems to use icbi and dcbf instructions in the function
called to initialize a trampoline, but AFAICT not in the __clear_cache
builtin. Hopefully target maintainers will have a look and take
advantage of this new piece of infrastructure to remove such
(apparent?) inconsistencies. Not rs6000 and other that call asm-coded
trampoline setup instructions, for sure, but they might wish to
introduce a CLEAR_INSN_CACHE macro or a clear_cache expander if they
don't have one.
for gcc/ChangeLog
* builtins.c (default_emit_call_builtin___clear_cache): New.
(maybe_emit_call_builtin___clear_cache): New.
(expand_builtin___clear_cache): Split into the above.
(expand_builtin): Do not issue clear_cache call any more.
* builtins.h (maybe_emit_call_builtin___clear_cache): Declare.
* config/aarch64/aarch64.c (aarch64_trampoline_init): Use
maybe_emit_call_builtin___clear_cache.
* config/arc/arc.c (arc_trampoline_init): Likewise.
* config/arm/arm.c (arm_trampoline_init): Likewise.
* config/c6x/c6x.c (c6x_initialize_trampoline): Likewise.
* config/csky/csky.c (csky_trampoline_init): Likewise.
* config/m68k/linux.h (FInALIZE_TRAMPOLINE): Likewise.
* config/tilegx/tilegx.c (tilegx_trampoline_init): Likewise.
* config/tilepro/tilepro.c (tilepro_trampoline_init): Ditto.
* config/vxworks.c: Include rtl.h, memmodel.h, and optabs.h.
(vxworks_emit_call_builtin___clear_cache): New.
* config/vxworks.h (CLEAR_INSN_CACHE): Drop.
(TARGET_EMIT_CALL_BUILTIN___CLEAR_CACHE): Define.
* target.def (trampoline_init): In the documentation, refer to
maybe_emit_call_builtin___clear_cache.
(emit_call_builtin___clear_cache): New.
* doc/tm.texi.in: Add new hook point.
(CLEAR_CACHE_INSN): Remove duplicate 'both'.
* doc/tm.texi: Rebuilt.
* targhooks.h (default_meit_call_builtin___clear_cache):
Declare.
* tree.h (BUILTIN_ASM_NAME_PTR): New.
for libgcc/ChangeLog
* config/t-vxworks (LIB2ADD): Drop.
* config/t-vxworks7 (LIB2ADD): Likewise.
* config/vxcache.c: Remove.
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 89 |
1 files changed, 58 insertions, 31 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 0f2c8c4..ecc12e6 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -7770,26 +7770,63 @@ expand_builtin_copysign (tree exp, rtx target, rtx subtarget) return expand_copysign (op0, op1, target); } -/* Expand a call to __builtin___clear_cache. */ +/* Emit a call to __builtin___clear_cache. */ -static rtx -expand_builtin___clear_cache (tree exp) +void +default_emit_call_builtin___clear_cache (rtx begin, rtx end) { - if (!targetm.code_for_clear_cache) + rtx callee = gen_rtx_SYMBOL_REF (Pmode, + BUILTIN_ASM_NAME_PTR + (BUILT_IN_CLEAR_CACHE)); + + emit_library_call (callee, + LCT_NORMAL, VOIDmode, + begin, ptr_mode, + end, ptr_mode); +} + +/* Emit a call to __builtin___clear_cache, unless the target specifies + it as do-nothing. This function can be used by trampoline + finalizers to duplicate the effects of expanding a call to the + clear_cache builtin. */ + +void +maybe_emit_call_builtin___clear_cache (rtx begin, rtx end) +{ + if (GET_MODE (begin) != ptr_mode || GET_MODE (end) != ptr_mode) { -#ifdef CLEAR_INSN_CACHE - /* There is no "clear_cache" insn, and __clear_cache() in libgcc - does something. Just do the default expansion to a call to - __clear_cache(). */ - return NULL_RTX; -#else + error ("both arguments to %<__builtin___clear_cache%> must be pointers"); + return; + } + + if (targetm.have_clear_cache ()) + { + /* We have a "clear_cache" insn, and it will handle everything. */ + class expand_operand ops[2]; + + create_address_operand (&ops[0], begin); + create_address_operand (&ops[1], end); + + if (maybe_expand_insn (targetm.code_for_clear_cache, 2, ops)) + return; + } + else + { +#ifndef CLEAR_INSN_CACHE /* There is no "clear_cache" insn, and __clear_cache() in libgcc does nothing. There is no need to call it. Do nothing. */ - return const0_rtx; + return; #endif /* CLEAR_INSN_CACHE */ } - /* We have a "clear_cache" insn, and it will handle everything. */ + targetm.calls.emit_call_builtin___clear_cache (begin, end); +} + +/* Expand a call to __builtin___clear_cache. */ + +static void +expand_builtin___clear_cache (tree exp) +{ tree begin, end; rtx begin_rtx, end_rtx; @@ -7799,25 +7836,16 @@ expand_builtin___clear_cache (tree exp) if (!validate_arglist (exp, POINTER_TYPE, POINTER_TYPE, VOID_TYPE)) { error ("both arguments to %<__builtin___clear_cache%> must be pointers"); - return const0_rtx; + return; } - if (targetm.have_clear_cache ()) - { - class expand_operand ops[2]; + begin = CALL_EXPR_ARG (exp, 0); + begin_rtx = expand_expr (begin, NULL_RTX, Pmode, EXPAND_NORMAL); - begin = CALL_EXPR_ARG (exp, 0); - begin_rtx = expand_expr (begin, NULL_RTX, Pmode, EXPAND_NORMAL); + end = CALL_EXPR_ARG (exp, 1); + end_rtx = expand_expr (end, NULL_RTX, Pmode, EXPAND_NORMAL); - end = CALL_EXPR_ARG (exp, 1); - end_rtx = expand_expr (end, NULL_RTX, Pmode, EXPAND_NORMAL); - - create_address_operand (&ops[0], begin_rtx); - create_address_operand (&ops[1], end_rtx); - if (maybe_expand_insn (targetm.code_for_clear_cache, 2, ops)) - return const0_rtx; - } - return const0_rtx; + maybe_emit_call_builtin___clear_cache (begin_rtx, end_rtx); } /* Given a trampoline address, make sure it satisfies TRAMPOLINE_ALIGNMENT. */ @@ -9507,6 +9535,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, && fcode != BUILT_IN_EXECLE && fcode != BUILT_IN_EXECVP && fcode != BUILT_IN_EXECVE + && fcode != BUILT_IN_CLEAR_CACHE && !ALLOCA_FUNCTION_CODE_P (fcode) && fcode != BUILT_IN_FREE) return expand_call (exp, target, ignore); @@ -9696,10 +9725,8 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, return expand_builtin_next_arg (); case BUILT_IN_CLEAR_CACHE: - target = expand_builtin___clear_cache (exp); - if (target) - return target; - break; + expand_builtin___clear_cache (exp); + return const0_rtx; case BUILT_IN_CLASSIFY_TYPE: return expand_builtin_classify_type (exp); |