[cfe-dev] Checking if function have been emitted
Piotr Padlewski via cfe-dev
cfe-dev at lists.llvm.org
Wed Jan 4 10:27:32 PST 2017
2017-01-04 19:12 GMT+01:00 John McCall <rjmccall at apple.com>:
> On Jan 4, 2017, at 4:41 AM, Piotr Padlewski <piotr.padlewski at gmail.com>
> wrote:
> 2017-01-03 16:42 GMT+01:00 John McCall <rjmccall at apple.com>:
>
>>
>> On Jan 3, 2017, at 7:23 AM, Piotr Padlewski <piotr.padlewski at gmail.com>
>> wrote:
>>
>> Maybe there is something I am missing, but I though vtables are being
>> generated at the end of translation unit.
>> If there is nothing clang emits after vtable (maybe except inline virtual
>> functions if they are reffered by vtable), then if there is a direct call
>> to inline function, the function has to be emitted before
>> vtables.
>>
>>
>> This is a fixed-point(-ish) problem: emitting a v-table can require more
>> virtual functions which can require more v-tables. So we just add stuff to
>> queues and drain all the queues in a loop.
>>
>> I would like to emit available_externally vtable only if all inline
>> virtual functions has been emitted.
>> It seems that I find function like virtual default destructor, that
>> should be emitted before vtables (because there is implicit destructor
>> call), but isDeclaration() return true for it.
>>
>>
>> You cannot rely on exact order like this in the normal emission code.
>> IRGen does not and will not guarantee it.
>>
>> You could make a separate pass after the lazy-emission loop.
>>
>> John.
>>
>> Thanks John, that would make sense. By 'separate pass' you mean do it in
> CodeGenModule::Release?
>
>
> Immediately after EmitDeferred(), yes. (But as a separate function,
> please.)
>
> John.
>
Of course. Thanks Mehdi and John!
>
>
> Piotr
>
>
>>
>> Test case like:
>>
>> struct A {
>> virtual void foo();
>> virtual ~A() {};
>> };
>>
>> void test() {
>> A a; // This will force emit of A's destructor.
>> }
>>
>>
>>
>>
>> 2017-01-03 3:55 GMT+01:00 Mehdi Amini <mehdi.amini at apple.com>:
>>
>>>
>>> > On Dec 30, 2016, at 10:38 AM, Piotr Padlewski via cfe-dev <
>>> cfe-dev at lists.llvm.org> wrote:
>>> >
>>> > Hi,
>>> > I would like to check if there is inline virtual function that was not
>>> emitted.
>>> >
>>> > I tried to do something like this based on
>>> CodeGenModule::GetOrCreateLLVMFunction:
>>> >
>>> > StringRef Name = CGM.getMangledName(VFunction);
>>> > auto *Entry = CGM.GetGlobalValue(Name);
>>> >
>>> > // If function doesn't exist or doesn't have a definition.
>>> > if (!Entry || Entry->isDeclaration())
>>> > return true;
>>> >
>>> > But Entry->isDeclaration() returns True for functions that I would
>>> expect to be emited.
>>> > What is the proper way of checking that?
>>>
>>> isDeclaration() only returns true for a function that does not have a
>>> body / hasn’t been materialized yet. Do you observe that it is not the case
>>> in practice? Or are you trying to look if a function will be emitted by
>>> clang but hasn’t already?
>>>
>>> —
>>> Mehdi
>>>
>>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170104/9c544755/attachment.html>
More information about the cfe-dev
mailing list