<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Thanks Nick,<div><br></div><div>Unfortunately, that is indeed <b>what I asked for</b> but <b>not</b> <b>what I really am looking for</b>. </div><div><br></div><div>My naive approach is to store symbol table entries as <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">Value* </span></font>objects so I can allocate global variables and alloca variables and place them into the symbol table and the rest of the code didn't need to know which kind they were, in general. Loads and Stores of these types (as well as other instructions) seem to work fine as long as the types being pointed to match the type of the value being stored.</div><div><br></div><div>So what I was really looking for, I suppose, was a <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">Value</span></font> class virtual member function something like <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">getLoadStoreType</span></font> or perhaps <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px;">getReferencedType</span></font> which returned the type as it would be used in a load or store. It appears that both load and store do handle the pointer dereferencing automatically for both types, i.e. <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">AllocaInst</span></font> and <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">GlobalVariable<font class="Apple-style-span" face="Arial"> both dereference the pointers automatically</font></span></font>.</div><div><br></div><div>I can cast the value I get from the symbol table to a <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">AllocaInst</span></font>, of course, in the case where it is one, but this requires a test for one and is just as messy as first getting the type and then testing it for being a <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">PointerType</span></font> and less general since a <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">GlobalVariable</span></font> also store its type as a <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">PointerType</span></font> which point to the actual type. They, unfortunately, do not share a common superclass other than <font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 12px; ">Value</span></font> itself.</div><div><br></div><div>- Curtis</div><div><br></div><div><br></div><div><div>On May 28, 2010, at 1:06 AM, Nick Lewycky wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Curtis Faith wrote:<br><blockquote type="cite">Is there a recommended way to retrieve the original type from an<br></blockquote><blockquote type="cite">AllocaInst object?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">For example, I am creating alloca instructions using the IRBuilder<br></blockquote><blockquote type="cite">interface like:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">alloca = builder.CreateAlloca( Type::getDoubleTy( context ), 0,<br></blockquote><blockquote type="cite">variableName.c_str() );<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">and I place the alloca into a symbol table.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Later when I am generating instructions for an assignment operation, I<br></blockquote><blockquote type="cite">want to check the type of the variable allocated with the CreateAlloca<br></blockquote><blockquote type="cite">instruction so I can see if I need to do type conversion before the<br></blockquote><blockquote type="cite">store instruction, However, I cannot simply use:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">alloca->getType()->isDoubleTy() etc.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">because this doesn't return true in the above case. The ID of the Ty<br></blockquote><blockquote type="cite">member of the VTy member of the alloca is PointerTyID instead of<br></blockquote><blockquote type="cite">DoubleTyID as the construction for AllocaInst::AllocaInst seems to<br></blockquote><blockquote type="cite">create a PointerType pointing to the original type.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I was hoping for a member function of the alloca that would return the<br></blockquote><blockquote type="cite">original type that was passed to CreateAlloca. I can test for a<br></blockquote><blockquote type="cite">PointerTyID and then perform a cast to PointerType and then call the<br></blockquote><blockquote type="cite">getElementType() function on the PointerType but that seems a bit messy.<br></blockquote><br>There's alloca->getAllocatedType() which merely calls getType()->getElementType() for you.<br><br><a href="http://llvm.org/doxygen/classllvm_1_1AllocaInst.html">http://llvm.org/doxygen/classllvm_1_1AllocaInst.html</a> .<br><br>Nick<br></div></blockquote></div><br></body></html>