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__); Thx Alex
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-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell
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 > >