[LLVMdev] Privatize global variables

John Criswell criswell at illinois.edu
Sun Apr 8 07:02:29 PDT 2012


On 4/8/12 7:32 AM, Dmitry N. Mikushin wrote:
> Hi John,
>
>> The -internalize pass changes globals to have internal linkage.  Does this
>> not suffice for your needs?
> To my understanding, it does not. The -internalize pass performs:
>
> I->setLinkage(GlobalValue::InternalLinkage);
>
> which means it only changes the linkage mode, while global variables
> remain in place.

Correct, but the globals are invisible to other code that is linked into 
the program (it's akin to giving the globals the "static" keyword in C).

>   And we need to *replace* globals with local variables
> in main and arguments - in other functions.
As far as I know, there is no LLVM transform that does this.

Can you describe your visibility problem in more detail?  Apparently 
it's not just a problem of global symbols being visible at link-time.

-- John T.

>
> - D.
>
> 2012/4/8 John Criswell<criswell at illinois.edu>:
>> On 4/7/12 7:28 PM, Dmitry N. Mikushin wrote:
>>> Dear LLVM,
>>>
>>> To workaround the GPU modules visibility rules, we need to lower
>>> global variables into scope-variables of main entry and arguments in
>>> other functions. For example,
>>
>> The -internalize pass changes globals to have internal linkage.  Does this
>> not suffice for your needs?
>>
>> -- John T.
>>
>>> int foo = 0;
>>>
>>> int func() { return foo + 1; }
>>>
>>> int main() { return func(); }
>>>
>>> should become:
>>>
>>> int func(int* foo) { return *foo + 1; }
>>>
>>> int main() { int foo = 0; return func(&foo); }
>>>
>>> Is there a strong name/term for this in compiler theory?
>>> Do you know are there any related techniques already implemented in LLVM
>>> passes?
>>> I'd much appreciate all points that could help us to better understand
>>> the context.
>>>
>>> Thanks,
>>> - Dima.
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>




More information about the llvm-dev mailing list