Is there a way to get the size of a type in the IR assembly code? I know the size must be known since alloca and getelementptr both implicitly use it, but I don't see any way to get access to the size directly. I know my final compiler will have to get the size itself, but I'm just doing some simple tests directly in assembly now and am hoping there is an easy way to get the size of a structure. -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 259 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121111/fc79b8bd/attachment.sig>
Does this help? http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt On 11 Nov 2012, at 10:52, edA-qa mort-ora-y <eda-qa at disemia.com<mailto:eda-qa at disemia.com>> wrote: Is there a way to get the size of a type in the IR assembly code? I know the size must be known since alloca and getelementptr both implicitly use it, but I don't see any way to get access to the size directly. I know my final compiler will have to get the size itself, but I'm just doing some simple tests directly in assembly now and am hoping there is an easy way to get the size of a structure. -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121111/14ebb3c5/attachment.html>
On Sun, Nov 11, 2012 at 11:52 AM, edA-qa mort-ora-y <eda-qa at disemia.com> wrote:> Is there a way to get the size of a type in the IR assembly code? I know > the size must be known since alloca and getelementptr both implicitly > use it, but I don't see any way to get access to the size directly.You might want to look at the output of llvm::ConstantExpr::getSizeOf(Type*) (e.g. using dump()): http://llvm.org/docs/doxygen/html/classllvm_1_1ConstantExpr.html#a778163e6ec80716a12ab3282cb97f0d9 David
On 11/11/2012 4:52 AM, edA-qa mort-ora-y wrote:> Is there a way to get the size of a type in the IR assembly code? I know > the size must be known since alloca and getelementptr both implicitly > use it, but I don't see any way to get access to the size directly. > > I know my final compiler will have to get the size itself, but I'm just > doing some simple tests directly in assembly now and am hoping there is > an easy way to get the size of a structure.Look in DerivedTypes.h and see if you can find anything that will help you there. For structs you will need to account for padding and be careful about bitfields, but there should be functions to help you calculate a total size of a struct. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Yes, that is what I was looking for. I figured I could probably use getelementptr but seeing the example is really helpful. On 11/11/12 13:25, Richard Osborne wrote:> Does this help? > > http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt > > On 11 Nov 2012, at 10:52, edA-qa mort-ora-y <eda-qa at disemia.com > <mailto:eda-qa at disemia.com>> wrote: > >> Is there a way to get the size of a type in the IR assembly code? I know >> the size must be known since alloca and getelementptr both implicitly >> use it, but I don't see any way to get access to the size directly. >> >> I know my final compiler will have to get the size itself, but I'm just >> doing some simple tests directly in assembly now and am hoping there is >> an easy way to get the size of a structure. >> >> -- >> edA-qa mort-ora-y >> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >> Sign: Please digitally sign your emails. >> Encrypt: I'm also happy to receive encrypted mail. >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> >> http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 259 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121111/fc7d1560/attachment.sig>