[cfe-commits] r60939 - in /cfe/trunk/lib/CodeGen: CodeGenFunction.cpp CodeGenFunction.h
Anders Carlsson
andersca at mac.com
Thu Dec 11 23:19:02 PST 2008
Author: andersca
Date: Fri Dec 12 01:19:02 2008
New Revision: 60939
URL: http://llvm.org/viewvc/llvm-project?rev=60939&view=rev
Log:
Add map of VLA types and their sizes
Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=60939&r1=60938&r2=60939&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Dec 12 01:19:02 2008
@@ -401,3 +401,30 @@
return AddrTyped;
}
+llvm::Value *CodeGenFunction::GetVLASize(const VariableArrayType *VAT)
+{
+ llvm::Value *&SizeEntry = VLASizeMap[VAT];
+
+ if (!SizeEntry) {
+ // Get the element size;
+ llvm::Value *ElemSize;
+
+ QualType ElemTy = VAT->getElementType();
+
+ if (const VariableArrayType *ElemVAT =
+ getContext().getAsVariableArrayType(ElemTy))
+ ElemSize = GetVLASize(ElemVAT);
+ else {
+ // FIXME: We use Int32Ty here because the alloca instruction takes a
+ // 32-bit integer. What should we do about overflow?
+ ElemSize = llvm::ConstantInt::get(llvm::Type::Int32Ty,
+ getContext().getTypeSize(ElemTy) / 8);
+ }
+
+ llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr());
+
+ SizeEntry = Builder.CreateMul(ElemSize, NumElements);
+ }
+
+ return SizeEntry;
+}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=60939&r1=60938&r2=60939&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Dec 12 01:19:02 2008
@@ -166,6 +166,11 @@
/// statement range in current switch instruction.
llvm::BasicBlock *CaseRangeBlock;
+ // VLASizeMap - This keeps track of the associated size for each VLA type
+ // FIXME: Maybe this could be a stack of maps that is pushed/popped as
+ // we enter/leave scopes.
+ llvm::DenseMap<const VariableArrayType*, llvm::Value*> VLASizeMap;
+
/// StackSaveValues - A stack(!) of stack save values. When a new scope is
/// entered, a null is pushed on this stack. If a VLA is emitted, then
/// the return value of llvm.stacksave() is stored at the top of this stack.
@@ -344,6 +349,10 @@
// instruction in LLVM instead once it works well enough.
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
+ // GetVLASize - Returns an LLVM value that corresponds to the size in bytes
+ // of a variable length array type.
+ llvm::Value *GetVLASize(const VariableArrayType *);
+
//===--------------------------------------------------------------------===//
// Declaration Emission
//===--------------------------------------------------------------------===//
More information about the cfe-commits
mailing list