[LLVMdev] RE: Question about Global Variable
Chris Lattner
sabre at nondot.org
Wed Feb 2 11:26:10 PST 2005
On Tue, 1 Feb 2005, Qiuyu Zhang wrote:
> the following IR code is the loop part code which is corresponding to the above C code
...
> %tmp.34 = getelementptr sbyte* %tmp.32, int %tmp.33 ; <sbyte*> [#uses=1]
>
> I am trying to construct all those IR instructions, for the first three, it is ok, as the following
> Value *ldAddr1 = new LoadInst(numidx, "idx_i", InsertPos);
>
> After this I need construct another getelementptr, and from the above IR code, the second getelementptr take the result of load as parameters. But there is no such prototype construction api for this case. The correct one should be as the following,
>
> GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
> const std::string &Name = "", Instruction *InsertBefore =0);
> GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx, // or Idx1, Idx2
> const std::string &Name, BasicBlock *InsertAtEnd);
>
> How could I create the fourth IR ? Thanks
You can use either of those two constructors, e.g. something like this:
std::vector<Value*> Idxs;
Idxs.push_back(ldAddr1);
Value *GEP2 = new GetElementPtrInst(ldAddr, "whatever", Idxs, InsertPos);
-Chris
--
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/
More information about the llvm-dev
mailing list