[LLVMdev] instruction CE_GEP

Chris Lattner clattner at apple.com
Thu Aug 28 15:59:51 PDT 2008


On Aug 28, 2008, at 1:38 PM, Le Anh Quang wrote:

> Hi all,
>
> I have a question with the ”getelemptr” instruction.
> E.g.: I have some GEP instructions in my program.
> Some look like:
>
>  <INST_GEP op0=26 op1=64 op2=429/>
>> <INST_GEP op0=341 op1=64 op2=101 op3=499 op4=0/>
>
> The first instruction above in assembly file:
> %tmp60 = getelementptr [512 x i32]* @weights, i32 0, i32 %k.3.ph
> Ok, we see it all:
> Index of @weights in value list = 26
> Index of “i32 0” in value list = 64
> Index of “i32 %k.3.ph” in value list = 429
>
> But in the second instructions:
> %tmp67.1 = getelementptr [8 x [8 x i32]]* %inter, i32 0, i32 1, i32  
> %outc.0.reg2mem.0
> As the first one, we see:
> Index of %inter  in value list = 341
> Index of “i32 0” in value list = 64
> Index of “i32 1” in value list = 101
> Index of “i32 %outc.0.reg2mem.0” in value list = 499
>
> è What is the last one, “op4=0” ?
> And the index of the second instruction in value list is less than  
> 499.
>

The type of a value is only encoded for forward references.  Please  
see the source for the bitcode reader for more information.  Here's a  
snippet that is useful:

   /// getValueTypePair - Read a value/type pair out of the specified  
record from
   /// slot 'Slot'.  Increment Slot past the number of slots used in  
the record.
   /// Return true on failure.
   bool getValueTypePair(SmallVector<uint64_t, 64> &Record, unsigned  
&Slot,
                         unsigned InstNum, Value *&ResVal) {
     if (Slot == Record.size()) return true;
     unsigned ValNo = (unsigned)Record[Slot++];
     if (ValNo < InstNum) {
       // If this is not a forward reference, just return the value we  
already
       // have.
       ResVal = getFnValueByID(ValNo, 0);
       return ResVal == 0;
     } else if (Slot == Record.size()) {
       return true;
     }

     unsigned TypeNo = (unsigned)Record[Slot++];
     ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
     return ResVal == 0;
   }

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080828/88bb0852/attachment.html>


More information about the llvm-dev mailing list