__builtin___clear_cache

Folks,

To implement this bug:

http://llvm.org/bugs/show_bug.cgi?id=19142

I need an LLVM intrinsic to communicate the need to lower the builtin
wither to noop or a call or even a sequence of instructions. I thought
about:

  void @llvm.clear_cache(i8 * begin, i8 * end)

to simulate precisely GCC's builtin:

  void __builtin___clear_cache (char *begin, char *end)

which will be, by default, nothing. On ARM and MIPS, it'll call __clear_cache.

Is that a good plan?

cheers,
--renato

How does this overlap with:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140310/thread.html#208333

Committed in r203674?

The bug mentions doing the mov r7 and svc, when the above code already does it, I’m somewhat confused.

How does this overlap with:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140310/thread.html#208333

The builtin was created to call __clear_cache() on platforms that need
it (like ARM and MIPS), but to be ignored on others (like x86_64).

This builtin should call __clear_cache() from whatever library is
available at the moment, so there is no overlap, just supporting the
GCC builtin to avoid calling a noop function when not needed.

The bug mentions doing the mov r7 and svc, when the above code already does
it, I'm somewhat confused.

That's an idea that might not be a good one. I was thinking if, in
some occasions, we could emit directly the instructions, but that will
have to deal with lower level stuff that we don't want on the
intrinsic level. GCC just emits a call to __clear_cache() and, at the
very least, we should do the same for now.

That optimisation might come later, at a much lower level, but I have
my doubts if that's relevant. We shouldn't be clearing the cache on a
hot loop anyway. :wink:

cheers,
--renato

The builtin was created to call __clear_cache() on platforms that need
it (like ARM and MIPS), but to be ignored on others (like x86_64).

This builtin should call __clear_cache() from whatever library is
available at the moment, so there is no overlap, just supporting the
GCC builtin to avoid calling a noop function when not needed.

I see, this makes sense. Agreed it's useful, thanks for explaining.

That's an idea that might not be a good one. I was thinking if, in
some occasions, we could emit directly the instructions, but that will
have to deal with lower level stuff that we don't want on the
intrinsic level. GCC just emits a call to __clear_cache() and, at the
very least, we should do the same for now.

That optimisation might come later, at a much lower level, but I have
my doubts if that's relevant. We shouldn't be clearing the cache on a
hot loop anyway. :wink:

Maybe a naive question, but it seems better to just use inlining instead of
reimplementing the same logic within LLVM. That requires static
linking/LTO, so it's not that workable.

You're absolutely right... Premature optimization is the root of all evil... :wink:

--renato

> Maybe a naive question, but it seems better to just use inlining instead
of
> reimplementing the same logic within LLVM. That requires static
linking/LTO,
> so it's not that workable.

You're absolutely right... Premature optimization is the root of all
evil... :wink:

svc will be quite expensive on its own! On A64 it'll be better though,
since IIRC it won't require a kernel assist.