[LLVMdev] copy value of a global's data field to another global

Alexander Poddey alexander.poddey at gmx.net
Mon May 18 09:43:23 PDT 2015


Hi David,

what I actually want is the value (not llvm::value, but the number). In some 
cases I want to transfer e.g. one of the int values from the original 
global'S initializer to another int field of another (possibly also nested) 
global.
In constructing the new initializer, I need a ConstanInt* which I could get 
using ConstantInt::get if I could extract the integer value of the original 
global.

I can recursively crawl through the type of a global, use the resulting 
indexes to get the ConstantPointer*, but I'm not able to e.g. output the 
actual value.

So an example how to walk the global's structure and e.g. print the actual 
values to stdout would solve my problem...


Thank you!

Alexander


David Blaikie wrote:

> On Sun, May 17, 2015 at 9:39 PM, Alexander Poddey
> <alexander.poddey at gmx.net> wrote:
> 
>>
>>
>> getInitializer returns the complete initializer of the global.
>> My globals are complex nested structs, from which I want to extract e.g.
>> one
>> double datafield.
>>
>> Example:
>> From a struct Stuct having double,array(3xint),float fields, I could
>> extract
>> the second int value using the index sequence 0,1,1 with
>> getGetElementPtr. This gives me a constantPointer, but I would need to
>> get a constInt...
>>
> 
> You want a global with the same value - or a global that points into the
> subobject in the original global? If you want a separate global, I guess
> you'd need to walk the constant yourself rather than using GEP.
> 
> - David
> 
> 
>>
>> Alex
>>
>>
>> David Blaikie wrote:
>>
>> > On Sat, May 16, 2015 at 10:28 PM, Alexander Poddey
>> > <alexander.poddey at gmx.net
>> >> wrote:
>> >
>> >> Hi all,
>> >>
>> >> I can get access to the data stored in globals as follows:
>> >>
>> >> GlobalVariable* pGvarAct=_set_a_valid_global_;
>> >> const_ptr_indicesVec=_the_indexes_
>> >>
>> >> llvm::Constant* pConst;
>> >> pConst=ConstantExpr::getGetElementPtr(pGvarAct, const_ptr_indicesVec);
>> >>
>> >> and e.g. use this to repalece an argumrnt of an instruction like:
>> >>
>> >> I->setOperand(someArgumentIndex,pConst);
>> >>
>> >> However, getGetElementPtr returns a pointerType, which holds the
>> >> actual type
>> >> as sub_type.
>> >> This is a problem when I want to use the data from one global for the
>> >> initializer of another
>> >>
>> >>     pGvar->setInitializer(__NeedsAFloatTy_here__); //not pointerTy
>> >>
>> >> So what I'm trying to do is copy some data-fields of one global to
>> >> another. I know the 'index-trace' used in getGetElementPtr, but I need
>> >> the actual type, not 'covered' by a pointerType.
>> >>
>> >
>> > Perhaps you want getInitializer on the other GlobalVariable?
>> >
>> >
>> >>
>> >>
>> >> Thank You!
>> >> Alexander
>> >>
>> >>
>> >> _______________________________________________
>> >> 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
>>





More information about the llvm-dev mailing list