[LLVMdev] Making it possible to clear the LLVMContext

Sean Silva chisophugis at gmail.com
Tue Jun 24 13:55:31 PDT 2014


On Tue, Jun 24, 2014 at 2:22 PM, Reid Kleckner <rnk at google.com> wrote:

> On Tue, Jun 24, 2014 at 9:17 AM, Mathias Fröhlich <
> Mathias.Froehlich at gmx.net> wrote:
>>
>> I can't comment on your solution.
>> But again the open source OpenGL driver stack is suffering from problems
>> connected to
>> LLVMContext.
>>
>> So our observation is, if we use several LLVMContexts within the program
>> execution
>> lifetime, LLVM accumulates memory that is only freed on destruction of the
>> managed singletons. It turns out that in SDNode::getValueTypeList(EVT)
>> the non simple
>> value types are cached and keyed by a llvm::Type value which in the end
>> refers to a
>> LLVMContext reference value. Which in turn leads to the llvm library
>> hogging memory
>> in this EVT std::set for each new LLVMContext.
>> For the OpenGL drivers using the global LLVMContext singleton leads to
>> serious
>> threadsafeness problems. One driver is just non OpenGL conformant
>> non thread safe because of that, some others just tolerate LLVM hogging
>> memory because of that. Even worse for the ones just tolerating hogging
>> memory, I could potentially think of possible ABA like problems with a
>> new LLVMContext or llvm::Type being malloced at the same address than a
>> previous already deleted
>> one but not knowing about the cached EVT's which appear to belong to this
>> context.
>>
>
> It looks like this bug is in SDNode::getValueTypeList().  This is a real
> bug that should be filed and fixed.
>

Doing some archaeology, it seems like the blame on that cache points at
r78610. The commit message is "Rename MVT to EVT, [...]", so it seems like
it goes back even further. Probably just a remnant of something ancient.
Anyone that was around back then have any insight into this?

-- Sean Silva


> That said I think you need to be careful since some of the llvm static
>> caches refer to
>> LLVMContext pointers and at least the one I mentioned above is not
>> cleared if either
>> a whole LLVMContext is cleared nor it is cleared by what you want to
>> achieve.
>>
>> Also for my interest:
>> Does anybody know of other statically cached object instances that are
>> tied to an
>> LLVMContext but not cleaned up when the referring LLVMContext is
>> destroyed?
>>
>
> Not that I know of.  Any global that points to a Type* is a potential bug
> and should probably be removed.
>
>
>> Greetings and thanks
>>
>> Mathias
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140624/dc51db2e/attachment.html>


More information about the llvm-dev mailing list