[LLVMdev] Question About Function Cloning

Tim Northover t.p.northover at gmail.com
Fri Oct 25 10:07:18 PDT 2013


> Though I can create two global integers, could anyone please tell me
> how do I create a pointer to a global variable (not an array) in the
> IR?  I know GetElementPtr can be used in case of array but what about
> I want a pointer to just an integer and call my function with it?

You should be able to just use the GlobalValue/GlobalVariable without
messing around with GetElementPtr (it'll already have type i32* or
whatever).

If you write "GV = Module->getOrCreateGlobal("whatever", MyType)" then
G will actually already have type "MyType *" as it were, and you
access the actual value by just loading and storing to GV. In your
case it should be directly usable in the CreateCall function.

Cheers.

Tim.



More information about the llvm-dev mailing list