Alexander Poddey
2015-May-17 05:28 UTC
[LLVMdev] copy value of a global's data field to another global
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. Thank You! Alexander
David Blaikie
2015-May-17 12:58 UTC
[LLVMdev] copy value of a global's data field to another global
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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150517/a5548efc/attachment.html>
Alexander Poddey
2015-May-18 04:39 UTC
[LLVMdev] copy value of a global's data field to another global
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 extractthe 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... 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 >>
Possibly Parallel Threads
- [LLVMdev] copy value of a global's data field to another global
- [LLVMdev] numeric limits of llvm Types?
- [LLVMdev] RE: Question about Global Variable
- [LLVMdev] MergeFunctions: reduce complexity to O(log(N))
- [LLVMdev] MergeFunctions: reduce complexity to O(log(N))