[LLVMdev] instruction CE_GEP

0 views
Skip to first unread message

Le Anh Quang

unread,
Aug 28, 2008, 4:38:24 PM8/28/08
to llv...@cs.uiuc.edu

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.

 

Thanks for any advice.

Quang

Chris Lattner

unread,
Aug 28, 2008, 6:59:51 PM8/28/08
to LLVM Developers Mailing List
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

Reply all
Reply to author
Forward
0 new messages