[LLVMdev] generating instructions with embedded ConstantExprs from within LLVM

Patrick Meredith pmeredit at uiuc.edu
Thu Jun 17 12:15:07 PDT 2004


How is this done?  Everything logical I have tried has failed, here was one attempt:

 Constant *C = (Constant*) ConstantArray::get(inst2string(I));  //fucnction defined elsewhere

//generates a correct Global string
   GlobalVariable *str = new GlobalVariable(C->getType(), true, 
     GlobalValue::InternalLinkage, 
      C,  mkStrName( strNumber++ ), &M);
 

   std::vector<Value*> params;  //params to a CallInst
   std::vector<Value*> indices;  //indices to gep
   indices.push_back((Value*) (ConstantInt::get(Type::IntTy, 0)));
   indices.push_back((Value*) (ConstantInt::get(Type::IntTy, 0)));
   Constant *gep = ConstantExpr::getGetElementPtr( (Constant*) str, indices);
   params.push_back((Value*) gep );

    CallInst *CI = new CallInst(printf, params, std::string(""), I);


  This resulted in a "no such type plane" assertion.  Currently I am doing this as two seperate instructions, which works, but slows down the rest of my pass.

~Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20040617/0d1d9b5c/attachment.html>


More information about the llvm-dev mailing list