[LLVMdev] StructType field names

Luke Dalessandro luked at cs.rochester.edu
Thu Mar 26 15:25:41 PDT 2009


Anthony Danalis wrote:
> Hello,
> 
> I'm trying to construct a string like "a[1][x].y" in an optimization  
> pass by digging deeper and deeper into a GetElementPtrInst.  I can  
> successfully deal with the array/pointer part, but when it comes to  
> the structure field name "y", I cannot figure out how to get anything  
> but the index into the structure.  Is there a way to do that, or is  
> this information discarded by llvm?

LLVM uses structural equivalence and uniqueing for types, so the 
information that you are looking for isn't really relevant. For example, 
if I have the following two types:

  struct A {
    int x, y;
  };

  struct B {
    int z, w;
  };

They'll both become something like:

  { int, int }

As you noticed, all the gep encodes is the offset into the type, so all 
you know is that the access is to the first/second field of the type. It 
wouldn't make sense to have a name for it because you wouldn't know if 
the first field was called "x" or "z" anyway. I could imagine some front 
end work that might embed information that you would need to reconstruct 
this, but I imagine it would take some doing.

Hope this helps,
Luke

> 
> thanks,
> Anthony
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list