[LLVMdev] llvm and flushing instruction cache

Owen Anderson resistor at mac.com
Sat Mar 6 23:24:13 PST 2010


On Mar 6, 2010, at 11:19 PM, Eli Friedman wrote:

> On Sat, Mar 6, 2010 at 10:34 PM, Shasank Chavan
> <shanko_chavano at hotmail.com> wrote:
>> Hi.  I have a very quick question.  Is the instruction cache flushed by the
>> llvm jit before code in memory is written to or executed?  I'm assuming so,
>> but I can't find where in the source code this is happening.  In particular
>> I searched for clflush, invd, and wbinvd instructions, but couldn't find
>> them.  And if it's not necessary to do this, can you please explain why?
>> (I'm assuming the target platform has a separate L1 i-cache).  Thanks.
> 
> On x86 in particular, explicitly flushing the instruction cache isn't
> necessary; the processor transparently handles modifications to cached
> code.

It handles modifications properly as long as the execution trace passes through a branch before hitting the modified code.  It's still possible to run into problems if you try to modify the currently executing basic block.

That said, it's correct that for the purposes of LLVM JIT (and most sane purposes I can imagine), you don't need to worry about flushing the icache on X86.

--Owen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100306/d5e5fc1e/attachment.bin>


More information about the llvm-dev mailing list