John, you are right. I 'browsed' the doxygen's inheritance diagram. Shouldn't I then be able to cast Constant * to Value*? Plugging the retrieved Constant* (from ConstantExpr::getGetElementPtr) into Instruction->setOperand compiles, but gives me an assertion failure at runtime. I have no access to the code at the moment. I will gather more information possibly tomorrow. Thanks Alex John Criswell wrote:> On 3/17/15 8:40 PM, Alexander Poddey wrote: >> Hi all, >> >> extracting datafields of globals, the API code ends up in a Constant * >> >> >> Constant* const_ptr_103 = ConstantExpr::getGetElementPtr(gvar_struct_foo, >> const_ptr_103_indices); >> >> it can be used to initialize e.g. a new instruction like: >> >> StoreInst* void_119 = new StoreInst(const_float_102, const_ptr_103, >> false, label_entry_113); >> >> >> But how about replacing the operand of an already existing instruction >> using a Constant *? >> >> Instruction->setOperand(1,__needs_a_value*_here__); > > If you look at the inheritance tree, you'll see that an llvm::Constant > is a subclass of llvm::Value. Therefore, you can use an llvm::Constant > anywhere in which an llvm::Value is needed. > > To look at the inheritance tree, look at the LLVM doxygen documentation. > > Regards, > > John Criswell >> >> >> Thx >> Alex >> >> >> >> >> >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
It should work just fine WITHOUT a cast. I use this concept in several places in my compiler. If you hit an assert, it is likely for some other reason. -- Mats On 18 March 2015 at 17:35, Alexander Poddey <alexander.poddey at gmx.net> wrote:> John, you are right. > I 'browsed' the doxygen's inheritance diagram. > Shouldn't I then be able to cast Constant * to Value*? > > Plugging the retrieved Constant* (from ConstantExpr::getGetElementPtr) > into Instruction->setOperand compiles, but gives me an assertion failure at > runtime. > I have no access to the code at the moment. I will gather more information > possibly tomorrow. > > Thanks > Alex > > > > > John Criswell wrote: > >> On 3/17/15 8:40 PM, Alexander Poddey wrote: >>> Hi all, >>> >>> extracting datafields of globals, the API code ends up in a Constant * >>> >>> >>> Constant* const_ptr_103 = ConstantExpr::getGetElementPtr(gvar_struct_foo, >>> const_ptr_103_indices); >>> >>> it can be used to initialize e.g. a new instruction like: >>> >>> StoreInst* void_119 = new StoreInst(const_float_102, const_ptr_103, >>> false, label_entry_113); >>> >>> >>> But how about replacing the operand of an already existing instruction >>> using a Constant *? >>> >>> Instruction->setOperand(1,__needs_a_value*_here__); >> >> If you look at the inheritance tree, you'll see that an llvm::Constant >> is a subclass of llvm::Value. Therefore, you can use an llvm::Constant >> anywhere in which an llvm::Value is needed. >> >> To look at the inheritance tree, look at the LLVM doxygen documentation. >> >> Regards, >> >> John Criswell >>> >>> >>> Thx >>> Alex >>> >>> >>> >>> >>> >>> >>> >>> >>> _______________________________________________ >>> 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
Alex, Seeing your questions go by on the list, ISTM that you are focusing a lot on the CPPBackend, which tends to generate ugly code generators, and isn't particularly the best example to be following unless you're really stuck and the doxygen docs aren't helping... has anyone pointed you to the Kaleidoscope tutorial? http://llvm.org/docs/tutorial/LangImpl3.html Cheers, Jon On 3/18/15 11:35 AM, Alexander Poddey wrote:> John, you are right. > I 'browsed' the doxygen's inheritance diagram. > Shouldn't I then be able to cast Constant * to Value*? > > Plugging the retrieved Constant* (from ConstantExpr::getGetElementPtr) > into Instruction->setOperand compiles, but gives me an assertion failure at > runtime. > I have no access to the code at the moment. I will gather more information > possibly tomorrow. > > Thanks > Alex > > > > > John Criswell wrote: > >> On 3/17/15 8:40 PM, Alexander Poddey wrote: >>> Hi all, >>> >>> extracting datafields of globals, the API code ends up in a Constant * >>> >>> >>> Constant* const_ptr_103 = ConstantExpr::getGetElementPtr(gvar_struct_foo, >>> const_ptr_103_indices); >>> >>> it can be used to initialize e.g. a new instruction like: >>> >>> StoreInst* void_119 = new StoreInst(const_float_102, const_ptr_103, >>> false, label_entry_113); >>> >>> >>> But how about replacing the operand of an already existing instruction >>> using a Constant *? >>> >>> Instruction->setOperand(1,__needs_a_value*_here__); >> >> If you look at the inheritance tree, you'll see that an llvm::Constant >> is a subclass of llvm::Value. Therefore, you can use an llvm::Constant >> anywhere in which an llvm::Value is needed. >> >> To look at the inheritance tree, look at the LLVM doxygen documentation. >> >> Regards, >> >> John Criswell >>> >>> >>> Thx >>> Alex >>> >>> >>> >>> >>> >>> >>> >>> >>> _______________________________________________ >>> 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 >-- Jon Roelofs jonathan at codesourcery.com CodeSourcery / Mentor Embedded
On 3/18/15 1:35 PM, Alexander Poddey wrote:> John, you are right. > I 'browsed' the doxygen's inheritance diagram. > Shouldn't I then be able to cast Constant * to Value*?You should be able to, although, as others have pointed out, it is unnecessary.> > Plugging the retrieved Constant* (from ConstantExpr::getGetElementPtr) > into Instruction->setOperand compiles, but gives me an assertion failure at > runtime.What assertion did you get? It's hard to diagnose the problem without knowing what assertion you are seeing. Regards, John Criswell -- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell
Dear all, sorry for the delay. I found the reason for the assertin failure; I made a mistake and thought the function pointer for the call instruction would come first, then the argument, which is not correct. Therefore the types did not match. Its working well now. Thank you all for your suggestions! Alex Alexander Poddey wrote:> John, you are right. > I 'browsed' the doxygen's inheritance diagram. > Shouldn't I then be able to cast Constant * to Value*? > > Plugging the retrieved Constant* (from ConstantExpr::getGetElementPtr) > into Instruction->setOperand compiles, but gives me an assertion failure > at runtime. > I have no access to the code at the moment. I will gather more information > possibly tomorrow. > > Thanks > Alex > > > > > John Criswell wrote: > >> On 3/17/15 8:40 PM, Alexander Poddey wrote: >>> Hi all, >>> >>> extracting datafields of globals, the API code ends up in a Constant * >>> >>> >>> Constant* const_ptr_103 >>> ConstantExpr::getGetElementPtr(gvar_struct_foo, const_ptr_103_indices); >>> >>> it can be used to initialize e.g. a new instruction like: >>> >>> StoreInst* void_119 = new StoreInst(const_float_102, const_ptr_103, >>> false, label_entry_113); >>> >>> >>> But how about replacing the operand of an already existing instruction >>> using a Constant *? >>> >>> Instruction->setOperand(1,__needs_a_value*_here__); >> >> If you look at the inheritance tree, you'll see that an llvm::Constant >> is a subclass of llvm::Value. Therefore, you can use an llvm::Constant >> anywhere in which an llvm::Value is needed. >> >> To look at the inheritance tree, look at the LLVM doxygen documentation. >> >> Regards, >> >> John Criswell >>> >>> >>> Thx >>> Alex >>> >>> >>> >>> >>> >>> >>> >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >>
Hi Jon, yes, I read through the kaleidoscope at the beginning of my project, which is about manipulating IR code. Kaleidoscope example is nice, but naturally can not cover every possible situation. What I really like about the CPPBackend is, that I can code anything in c / c++ and see how this could be achieved in the API (e.g. accessing nested structs). I then use these code snippets as entry points to llvm source code browsing and seeing how I could use it for my needs. Is there a better way / better C++Api code generator I should use instead? Thanks Alex Jonathan Roelofs wrote:> Alex, > > Seeing your questions go by on the list, ISTM that you are focusing a > lot on the CPPBackend, which tends to generate ugly code generators, and > isn't particularly the best example to be following unless you're really > stuck and the doxygen docs aren't helping... has anyone pointed you to > the Kaleidoscope tutorial? http://llvm.org/docs/tutorial/LangImpl3.html > > > Cheers, > > Jon > > > On 3/18/15 11:35 AM, Alexander Poddey wrote: >> John, you are right. >> I 'browsed' the doxygen's inheritance diagram. >> Shouldn't I then be able to cast Constant * to Value*? >> >> Plugging the retrieved Constant* (from ConstantExpr::getGetElementPtr) >> into Instruction->setOperand compiles, but gives me an assertion failure >> at runtime. >> I have no access to the code at the moment. I will gather more >> information possibly tomorrow. >> >> Thanks >> Alex >> >> >> >> >> John Criswell wrote: >> >>> On 3/17/15 8:40 PM, Alexander Poddey wrote: >>>> Hi all, >>>> >>>> extracting datafields of globals, the API code ends up in a Constant * >>>> >>>> >>>> Constant* const_ptr_103 >>>> ConstantExpr::getGetElementPtr(gvar_struct_foo, const_ptr_103_indices); >>>> >>>> it can be used to initialize e.g. a new instruction like: >>>> >>>> StoreInst* void_119 = new StoreInst(const_float_102, const_ptr_103, >>>> false, label_entry_113); >>>> >>>> >>>> But how about replacing the operand of an already existing instruction >>>> using a Constant *? >>>> >>>> Instruction->setOperand(1,__needs_a_value*_here__); >>> >>> If you look at the inheritance tree, you'll see that an llvm::Constant >>> is a subclass of llvm::Value. Therefore, you can use an llvm::Constant >>> anywhere in which an llvm::Value is needed. >>> >>> To look at the inheritance tree, look at the LLVM doxygen documentation. >>> >>> Regards, >>> >>> John Criswell >>>> >>>> >>>> Thx >>>> Alex >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> 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 >> >