MIPS/compiler_rt: use synci to flush icache on r6
authorYunQiang Su <wzssyqa@gmail.com>
Tue, 8 Nov 2022 01:43:41 +0000 (17:43 -0800)
committerFangrui Song <i@maskray.me>
Tue, 8 Nov 2022 01:43:41 +0000 (17:43 -0800)
commit674a17e9bbe82e8c53952fd94dcd862b17cb2d2f
tree48ca76fec642afcf3677cff6aec03cbdaa5a295f
parent32a2af44e1e882f13d1cc2817f0a8d4d8b375d4d
MIPS/compiler_rt: use synci to flush icache on r6

syscall makes it failed to build on mips64 for mipsel:
```
compiler-rt/lib/builtins/clear_cache.c:97:3: error:
call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  syscall(__NR_cacheflush, start, (end_int - start_int), BCACHE);
```

In this patch, we use `rdhwr` to get synci_step.
If synci_step is zero, it means that the hardware will maintain the coherence. We need to do nothing.
Then for r6+, `synci` is required to keep icache global.
So we can use `synci` to flush icache.
The ISA documents ask a `sync` and a `jr.hb` after `synci`.

For pre-r6, we can use cacheflush libc function, which is same on Linux and FreeBSD.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D135565
compiler-rt/lib/builtins/clear_cache.c