Is there a way to get the sizeof a type? Say I've created a struct type without any explicit attribtues, and I want to call malloc() to allocate space for it. Can I get the size as an llvm::Constant* (or other llvm::Value*) given an llvm::StructType* or other llvm::Type*? TIA, -- Rick
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Rick Mann > Subject: [LLVMdev] Sizeof a type?> Is there a way to get the sizeof a type?Look at the methods of the DataLayout class. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
On Jan 19, 2013, at 22:32 , "Caldarale, Charles R" <Chuck.Caldarale at unisys.com> wrote:> Look at the methods of the DataLayout class.Thanks! I seem to be able to do this llvm::DataLayout* dl = new llvm::DataLayout(module()); uint64_t myStructSuze = dl->getTypeStoreSize(myStructType); Is that the correct usage? -- Rick
nkavv at physics.auth.gr
2013-Jan-20 11:00 UTC
[LLVMdev] Inconsistent label syntax in LLVM assembly
Hi all, i'm writing a TXL (http://www.txl.ca) grammar and a revamp of bison/flex grammar for LLVM. I've noticed an inconsistency regarding label naming conventions. For instance, the following is a segment of legit LLVM assembly (human-readable) IR: br i1 %38, label %17, label %39 ; <label>:39 ; preds = %._crit_edge ret void However, ";" is a comment-line character. How is this interpreted, as a meta-comment? (a semantically important comment)? Other branches appear using regular conventions: br i1 %exitcond, label %._crit_edge, label %.lr.ph ._crit_edge: ; preds = %.lr.ph, %.preheader So, naturally I have some questions: 1) What is the differences among the branch labels? Differences in the formation (e.g. emitted by different passes?) 2) How to normalize the appearance of branch labels? I.e. is it possible to not emit the strange ; <label>:39 like ones? 3) Why <label>:39 and not 39: ? 4) Why not prefixing all labels with <label>? Best regards Nikolaos Kavvadias
Hi Rick, On 20/01/13 06:23, Rick Mann wrote:> Is there a way to get the sizeof a type? Say I've created a struct type without any explicit attribtues, and I want to call malloc() to allocate space for it. Can I get the size as an llvm::Constant* (or other llvm::Value*) given an llvm::StructType* or other llvm::Type*?if you have DataLayout available, use the getTypeAllocSize method. If you don't have information about the target then you can use ConstantExpr::getSizeOf. The advantage of DataLayout is that it returns a number (eg: 8) while getSizeOf returns a mysterious expression (the optimizers will simplify it to a number, the same as getTypeAllocSize returns, if you provide them with DataLayout). Ciao, Duncan.
On Jan 20, 2013, at 3:21 , Duncan Sands <baldrick at free.fr> wrote:> if you have DataLayout available, use the getTypeAllocSize method. If you don't > have information about the target then you can use ConstantExpr::getSizeOf. The > advantage of DataLayout is that it returns a number (eg: 8) while getSizeOf > returns a mysterious expression (the optimizers will simplify it to a number, > the same as getTypeAllocSize returns, if you provide them with DataLayout).Thanks, Duncan. What's the difference between DataLayout::getTypeAllocSize and DataLayout::getTypeStoreSize? -- Rick